Esempio n. 1
0
 def create_empty_fatfs(self) -> Any:
     sectors_count = self.state.size // self.state.sector_size
     volume_uuid = generate_4bytes_random()
     return (
         FATFS.BOOT_SECTOR_HEADER.build(
             dict(BS_OEMName=pad_string(self.state.oem_name, size=FATFS.MAX_OEM_NAME_SIZE),
                  BPB_BytsPerSec=self.state.sectors_per_cluster * self.state.sector_size,
                  BPB_SecPerClus=self.state.sectors_per_cluster,
                  BPB_RsvdSecCnt=self.state.reserved_sectors_cnt,
                  BPB_NumFATs=self.state.fat_tables_cnt,
                  BPB_RootEntCnt=self.state.entries_root_count,
                  BPB_TotSec16=0x00 if self.state.fatfs_type == FATFSState.FAT32 else sectors_count,
                  BPB_Media=self.state.media_type,
                  BPB_FATSz16=self.state.sectors_per_fat_cnt,
                  BPB_SecPerTrk=self.state.sec_per_track,
                  BPB_NumHeads=self.state.num_heads,
                  BPB_HiddSec=self.state.hidden_sectors,
                  BPB_TotSec32=sectors_count if self.state.fatfs_type == FATFSState.FAT32 else 0x00,
                  BS_VolID=volume_uuid,
                  BS_VolLab=pad_string(self.state.volume_label, size=FATFS.MAX_VOL_LAB_SIZE),
                  BS_FilSysType=pad_string(self.state.file_sys_type, size=FATFS.MAX_FS_TYPE_SIZE)
                  )
         )
         + (self.state.sector_size - FATFS.BOOT_HEADER_SIZE) * b'\x00'
         + self.state.sectors_per_fat_cnt * self.state.fat_tables_cnt * self.state.sector_size * b'\x00'
         + self.state.root_dir_sectors_cnt * self.state.sector_size * b'\x00'
         + self.state.data_sectors * self.state.sector_size * b'\xff'
     )
Esempio n. 2
0
 def _add_state_sectors(self) -> None:
     wl_state_data = WLFATFS.WL_STATE_T_DATA.build(
         dict(
             pos=0,
             max_pos=self.plain_fat_sectors + WLFATFS.DUMMY_SECTORS_COUNT,
             move_count=0,
             access_count=0,
             max_count=self._update_rate,
             block_size=self.sector_size,
             version=self._version,
             device_id=self._device_id or generate_4bytes_random(),
         ))
     crc = crc32(list(wl_state_data), WLFATFS.UINT32_MAX)
     wl_state_crc = Int32ul.build(crc)
     wl_state = wl_state_data + wl_state_crc
     self.fatfs_binary_image += WLFATFS.WL_STATE_COPY_COUNT * (
         (wl_state +
          (self.sector_size - WLFATFS.WL_STATE_HEADER_SIZE) * b'\xff') +
         (self.wl_state_sectors - 1) * self.sector_size * b'\xff')