Esempio n. 1
0
    def get_debug_firmware_id_string(self):
        """Gets firmware id in string.

        Returns:
            int: The firmware ID string from our debug information.
        """
        # Read the address via get_var_strict; this will fetch the value
        # from chipdata as well, but we can ignore it.
        chip_str = self.chipdata.get_var_strict('$_build_identifier_string')
        rawstr = self.debuginfo.get_dm_const(chip_str.address, chip_str.size)

        decoded_str = ""
        for chars in rawstr:
            if Arch.addr_per_word == 4:
                # The raw string is encoded with four chars per word
                string = cu.get_string_from_word(Arch.addr_per_word, chars)
                stop_decoding = False
                for char in string:
                    if char != '\0':
                        decoded_str += char
                    else:
                        stop_decoding = True
                        break
                if stop_decoding:
                    break
            else:
                # The raw string is encoded with two chars per word
                upper_part = (chars & 0xFF00) >> 8
                lower_part = chars & 0x00FF
                # strip the null terminator.
                if upper_part != 0:
                    decoded_str += chr(upper_part)
                else:
                    break
                if lower_part != 0:
                    decoded_str += chr(lower_part)
                else:
                    break

        return decoded_str.strip()  # Strip any leading/trailing whitespace
Esempio n. 2
0
    def get_firmware_id_string(self):
        """Returns the firmware ID string."""
        unpacked_string = False
        # Find the address of the string in memory
        id_string_addr = self._get_slt_entry(3)
        if id_string_addr is None:
            # maybe it's not packed in this slt
            id_string_addr = self._get_slt_entry(2)
            if id_string_addr is None:
                # Can't find it in the slt return None
                return None
            unpacked_string = True
        # parse the null terminated string
        last = build_string = ""
        # There is no reason for the build string to contain
        # any non ASCII character but do it like this to avoid
        # breaking support for Python 2.7
        try:
            char = unichr
        except NameError:
            char = chr
        while last != "\0":
            word = self.get_data(id_string_addr)
            if unpacked_string:
                if Arch.addr_per_word == 4:
                    # Two char per word
                    build_string += char(word & 0x00FFFF)
                    if build_string[-1] == "\0":
                        break
                    last = char((word & 0xFFFF0000) >> 16)
                    build_string += last
                else:
                    # Only one char per word
                    last = char(word)
                    build_string += last
            else:
                # Four chars per word
                if Arch.addr_per_word == 4:
                    string = cu.get_string_from_word(Arch.addr_per_word, word)
                    stop_decoding = False
                    for char in string:
                        if char != '\0':
                            build_string += char
                        else:
                            stop_decoding = True
                            break
                    last = string[3:]

                    if stop_decoding:
                        break
                else:
                    # Two chars per word
                    build_string += char((word & 0xFF00) >> 8)
                    if build_string[-1] == "\0":
                        break
                    last = char(word & 0x00FF)
                    build_string += last
            # Move to the next word in the string
            id_string_addr += Arch.addr_per_word

        # remove the \0 we don't want the terminator
        if build_string[-1] == "\0":
            build_string = build_string[:-1]

        return build_string.strip()
Esempio n. 3
0
    def get_firmware_id_string(self):
        """
        @brief Returns the firmware ID string
        @param[in] self Pointer to the current object
        """
        unpacked_string = False
        # Find the address of the string in memory
        id_string_addr = self._get_slt_entry(3)
        if id_string_addr is None:
            # maybe it's not packed in this slt
            id_string_addr = self._get_slt_entry(2)
            if id_string_addr is None:
                # Can't find it in the slt return None
                return None
            unpacked_string = True
        # parse the null terminated string
        last = build_string = ""
        while last != "\0":
            word = self.get_data(id_string_addr)
            if unpacked_string:
                if Arch.addr_per_word == 4:
                    # Two char per word
                    build_string += unichr(word & 0x00FFFF)
                    if build_string[-1] == "\0":
                        break
                    last = unichr((word & 0xFFFF0000) >> 16)
                    build_string += last
                else:
                    # Only one char per word
                    last = unichr(word)
                    build_string += last
            else:
                # Four chars per word
                if Arch.addr_per_word == 4:
                    string = cu.get_string_from_word(Arch.addr_per_word, word)
                    stop_decoding = False
                    for char in string:
                        if char != '\0':
                            build_string += char
                        else:
                            stop_decoding = True
                            break
                    last = string[3:]

                    if stop_decoding:
                        break
                else:
                    # Two chars per word
                    build_string += unichr((word & 0xFF00) >> 8)
                    if build_string[-1] == "\0":
                        break
                    last = unichr(word & 0x00FF)
                    build_string += last
            # Move to the next word in the string
            id_string_addr += Arch.addr_per_word

        # remove the \0 we don't want the terminator
        if build_string[-1] == "\0":
            build_string = build_string[:-1]

        return build_string.strip()