Class to wrap a flash algo This class is intended to provide easy access to the information provided by a flash algorithm, such as symbols and the flash algorithm itself.
| 49 | |
| 50 | |
| 51 | class PackFlashAlgo(object): |
| 52 | """ |
| 53 | Class to wrap a flash algo |
| 54 | |
| 55 | This class is intended to provide easy access to the information |
| 56 | provided by a flash algorithm, such as symbols and the flash |
| 57 | algorithm itself. |
| 58 | """ |
| 59 | |
| 60 | REQUIRED_SYMBOLS = set([ |
| 61 | "Init", |
| 62 | "UnInit", |
| 63 | "EraseSector", |
| 64 | "ProgramPage", |
| 65 | ]) |
| 66 | |
| 67 | EXTRA_SYMBOLS = set([ |
| 68 | "BlankCheck", |
| 69 | "EraseChip", |
| 70 | "Verify", |
| 71 | ]) |
| 72 | |
| 73 | def __init__(self, data): |
| 74 | """Construct a PackFlashAlgorithm from an ElfFileSimple""" |
| 75 | self.elf = ElfFileSimple(data) |
| 76 | self.flash_info = PackFlashInfo(self.elf) |
| 77 | |
| 78 | self.flash_start = self.flash_info.start |
| 79 | self.flash_size = self.flash_info.size |
| 80 | self.page_size = self.flash_info.page_size |
| 81 | self.sector_sizes = self.flash_info.sector_info_list |
| 82 | |
| 83 | symbols = {} |
| 84 | symbols.update(_extract_symbols(self.elf, self.REQUIRED_SYMBOLS)) |
| 85 | symbols.update(_extract_symbols(self.elf, self.EXTRA_SYMBOLS, |
| 86 | default=0xFFFFFFFF)) |
| 87 | self.symbols = symbols |
| 88 | |
| 89 | sections_to_find = ( |
| 90 | ("PrgCode", "SHT_PROGBITS"), |
| 91 | ("PrgData", "SHT_PROGBITS"), |
| 92 | ("PrgData", "SHT_NOBITS"), |
| 93 | ) |
| 94 | |
| 95 | ro_rw_zi = _find_sections(self.elf, sections_to_find) |
| 96 | ro_rw_zi = _algo_fill_zi_if_missing(ro_rw_zi) |
| 97 | error_msg = _algo_check_for_section_problems(ro_rw_zi) |
| 98 | if error_msg is not None: |
| 99 | raise Exception(error_msg) |
| 100 | |
| 101 | sect_ro, sect_rw, sect_zi = ro_rw_zi |
| 102 | self.ro_start = sect_ro["sh_addr"] |
| 103 | self.ro_size = sect_ro["sh_size"] |
| 104 | self.rw_start = sect_rw["sh_addr"] |
| 105 | self.rw_size = sect_rw["sh_size"] |
| 106 | self.zi_start = sect_zi["sh_addr"] |
| 107 | self.zi_size = sect_zi["sh_size"] |
| 108 |
no outgoing calls
no test coverage detected