Skip to content

Commit

Permalink
refactor(core): remove residual usage of old flash api
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
TychoVrahe committed Oct 16, 2023
1 parent f7aec0a commit bb591d9
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions core/embed/extmod/modtrezorutils/modtrezorutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include "secret.h"
#endif

#define FW_HASHING_CHUNK_SIZE 1024

static void ui_progress(mp_obj_t ui_wait_callback, uint32_t current,
uint32_t total) {
if (mp_obj_is_callable(ui_wait_callback)) {
Expand Down Expand Up @@ -171,18 +173,18 @@ STATIC mp_obj_t mod_trezorutils_firmware_hash(size_t n_args,
ui_wait_callback = args[1];
}

uint16_t firmware_sectors = flash_total_sectors(&FIRMWARE_AREA);
uint32_t firmware_size = flash_area_get_size(&FIRMWARE_AREA);
uint32_t chunks = firmware_size / FW_HASHING_CHUNK_SIZE;

ui_progress(ui_wait_callback, 0, firmware_sectors);
for (int i = 0; i < firmware_sectors; i++) {
uint8_t sector = flash_get_sector_num(&FIRMWARE_AREA, i);
uint32_t size = flash_sector_size(sector);
const void *data = flash_get_address(sector, 0, size);
ui_progress(ui_wait_callback, 0, chunks);
for (int i = 0; i < chunks; i++) {
const void *data = flash_area_get_address(
&FIRMWARE_AREA, chunks * FW_HASHING_CHUNK_SIZE, FW_HASHING_CHUNK_SIZE);
if (data == NULL) {
mp_raise_msg(&mp_type_RuntimeError, "Failed to read firmware.");
}
blake2s_Update(&ctx, data, size);
ui_progress(ui_wait_callback, i + 1, firmware_sectors);
blake2s_Update(&ctx, data, FW_HASHING_CHUNK_SIZE);
ui_progress(ui_wait_callback, i + 1, chunks);
}

vstr_t vstr = {0};
Expand All @@ -206,9 +208,7 @@ STATIC mp_obj_t mod_trezorutils_firmware_vendor(void) {
return mp_obj_new_str_copy(&mp_type_str, (const uint8_t *)"EMULATOR", 8);
#else
vendor_header vhdr = {0};
uint32_t size = flash_sector_size(FIRMWARE_AREA.subarea[0].first_sector);
const void *data =
flash_get_address(FIRMWARE_AREA.subarea[0].first_sector, 0, size);
const void *data = flash_area_get_address(&FIRMWARE_AREA, 0, 0);
if (data == NULL || sectrue != read_vendor_header(data, &vhdr)) {
mp_raise_msg(&mp_type_RuntimeError, "Failed to read vendor header.");
}
Expand Down

0 comments on commit bb591d9

Please sign in to comment.