Lines Matching refs:self
68 def __init__(self): argument
69 self.TAG_TO_NAME = {
72 self.bindesc_gen_tag(self.TYPE_STR, 0x800): 'APP_VERSION_STRING',
73 self.bindesc_gen_tag(self.TYPE_UINT, 0x801): 'APP_VERSION_MAJOR',
74 self.bindesc_gen_tag(self.TYPE_UINT, 0x802): 'APP_VERSION_MINOR',
75 self.bindesc_gen_tag(self.TYPE_UINT, 0x803): 'APP_VERSION_PATCHLEVEL',
76 self.bindesc_gen_tag(self.TYPE_UINT, 0x804): 'APP_VERSION_NUMBER',
77 self.bindesc_gen_tag(self.TYPE_STR, 0x805): 'APP_BUILD_VERSION',
78 self.bindesc_gen_tag(self.TYPE_STR, 0x900): 'KERNEL_VERSION_STRING',
79 self.bindesc_gen_tag(self.TYPE_UINT, 0x901): 'KERNEL_VERSION_MAJOR',
80 self.bindesc_gen_tag(self.TYPE_UINT, 0x902): 'KERNEL_VERSION_MINOR',
81 self.bindesc_gen_tag(self.TYPE_UINT, 0x903): 'KERNEL_VERSION_PATCHLEVEL',
82 self.bindesc_gen_tag(self.TYPE_UINT, 0x904): 'KERNEL_VERSION_NUMBER',
83 self.bindesc_gen_tag(self.TYPE_STR, 0x905): 'KERNEL_BUILD_VERSION',
84 self.bindesc_gen_tag(self.TYPE_UINT, 0xa00): 'BUILD_TIME_YEAR',
85 self.bindesc_gen_tag(self.TYPE_UINT, 0xa01): 'BUILD_TIME_MONTH',
86 self.bindesc_gen_tag(self.TYPE_UINT, 0xa02): 'BUILD_TIME_DAY',
87 self.bindesc_gen_tag(self.TYPE_UINT, 0xa03): 'BUILD_TIME_HOUR',
88 self.bindesc_gen_tag(self.TYPE_UINT, 0xa04): 'BUILD_TIME_MINUTE',
89 self.bindesc_gen_tag(self.TYPE_UINT, 0xa05): 'BUILD_TIME_SECOND',
90 self.bindesc_gen_tag(self.TYPE_UINT, 0xa06): 'BUILD_TIME_UNIX',
91 self.bindesc_gen_tag(self.TYPE_STR, 0xa07): 'BUILD_DATE_TIME_STRING',
92 self.bindesc_gen_tag(self.TYPE_STR, 0xa08): 'BUILD_DATE_STRING',
93 self.bindesc_gen_tag(self.TYPE_STR, 0xa09): 'BUILD_TIME_STRING',
94 self.bindesc_gen_tag(self.TYPE_STR, 0xb00): 'HOST_NAME',
95 self.bindesc_gen_tag(self.TYPE_STR, 0xb01): 'C_COMPILER_NAME',
96 self.bindesc_gen_tag(self.TYPE_STR, 0xb02): 'C_COMPILER_VERSION',
97 self.bindesc_gen_tag(self.TYPE_STR, 0xb03): 'CXX_COMPILER_NAME',
98 self.bindesc_gen_tag(self.TYPE_STR, 0xb04): 'CXX_COMPILER_VERSION',
100 self.NAME_TO_TAG = {v: k for k, v in self.TAG_TO_NAME.items()}
110 def do_add_parser(self, parser_adder): argument
111 parser = parser_adder.add_parser(self.name,
112 help=self.help,
113 description=self.description)
119 dump_parser.add_argument('--file-type', type=str, choices=self.EXTENSIONS, help='File type')
127 … search_parser.add_argument('--file-type', type=str, choices=self.EXTENSIONS, help='File type')
138 custom_search_parser.add_argument('--file-type', type=str, choices=self.EXTENSIONS,
149 get_offset_parser.add_argument('--file-type', type=str, choices=self.EXTENSIONS,
156 def dump(self, args): argument
157 image = self.get_image_data(args.file)
159 descriptors = self.parse_descriptors(image)
161 if tag in self.TAG_TO_NAME:
162 tag = self.TAG_TO_NAME[tag]
163 self.inf(f'{tag}', self.bindesc_repr(value))
165 def list(self, args): argument
166 for tag in self.TAG_TO_NAME.values():
167 self.inf(f'{tag}')
169 def common_search(self, args, search_term): argument
170 image = self.get_image_data(args.file)
172 descriptors = self.parse_descriptors(image)
176 self.inf(self.bindesc_repr(value))
178 self.die('Descriptor not found')
180 def search(self, args): argument
182 search_term = self.NAME_TO_TAG[args.descriptor]
184 self.die(f'Descriptor {args.descriptor} is invalid')
186 self.common_search(args, search_term)
188 def custom_search(self, args): argument
190 'STR': self.TYPE_STR,
191 'UINT': self.TYPE_UINT,
192 'BYTES': self.TYPE_BYTES
194 custom_tag = self.bindesc_gen_tag(custom_type, int(args.id, 16))
195 self.common_search(args, custom_tag)
197 def get_offset(self, args): argument
198 image = self.get_image_data(args.file)
200 magic = struct.pack('>Q' if self.is_big_endian else 'Q', self.MAGIC)
203 self.die('Could not find binary descriptor magic')
204 self.inf(f'{index} {hex(index)}')
206 def do_run(self, args, _): argument
211 self.is_big_endian = args.big_endian
212 self.file_type = self.guess_file_type(args)
213 subcmd = getattr(self, args.subcmd)
216 def get_image_data(self, file_name): argument
217 if self.file_type == 'bin':
221 if self.file_type == 'hex':
224 if self.file_type == 'uf2':
226 return convert_from_uf2(self, uf2_file.read())
228 if self.file_type == 'elf':
240 self.die('No "rom_start" or "text" section found')
242 self.die('Unknown file type')
244 def parse_descriptors(self, image): argument
245 magic = struct.pack('>Q' if self.is_big_endian else 'Q', self.MAGIC)
248 self.die('Could not find binary descriptor magic')
253 current_tag = self.bytes_to_short(image[index:index+2])
254 while current_tag != self.DESCRIPTORS_END:
256 length = self.bytes_to_short(image[index:index+2])
260 tag_type = self.bindesc_get_type(current_tag)
261 if tag_type == self.TYPE_STR:
263 elif tag_type == self.TYPE_UINT:
264 decoded_data = self.bytes_to_uint(data)
265 elif tag_type == self.TYPE_BYTES:
268 self.die(f'Unknown type for tag 0x{current_tag:04x}')
273 index = self.align(index, 4)
274 current_tag = self.bytes_to_short(image[index:index+2])
278 def guess_file_type(self, args): argument
287 for extension in self.EXTENSIONS:
310 def bytes_to_uint(self, b): argument
311 return struct.unpack('>I' if self.is_big_endian else 'I', b)[0]
313 def bytes_to_short(self, b): argument
314 return struct.unpack('>H' if self.is_big_endian else 'H', b)[0]