Skip to content

Commit d5ee24b

Browse files
authored
Small file fixes (#254)
* Fix rounding bug for load/save/verify small files Want to round up size/100, as a non-zero size should always give a non-zero chunk size * Allow zero fill when checking checksum Otherwise fails as unmapped for small files
1 parent 48ce1b5 commit d5ee24b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

main.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ template <typename T> struct range_map {
339339
// Calculate chunk size for load/save/verify
340340
// Returns size/100 rounded up to FLASH_SECTOR_ERASE_SIZE
341341
uint32_t calculate_chunk_size(uint32_t size) {
342-
return ((size/100 + FLASH_SECTOR_ERASE_SIZE - 1) & ~(FLASH_SECTOR_ERASE_SIZE - 1));
342+
return (((size + (100 - 1))/100 + FLASH_SECTOR_ERASE_SIZE - 1) & ~(FLASH_SECTOR_ERASE_SIZE - 1));
343343
}
344344

345345

@@ -1811,24 +1811,24 @@ struct memory_access {
18111811

18121812
virtual uint32_t get_binary_start() = 0;
18131813

1814-
uint32_t read_int(uint32_t addr) {
1814+
uint32_t read_int(uint32_t addr, bool zero_fill = false) {
18151815
assert(!(addr & 3u));
18161816
uint32_t rc;
1817-
read(addr, (uint8_t *)&rc, 4);
1817+
read(addr, (uint8_t *)&rc, 4, zero_fill);
18181818
return rc;
18191819
}
18201820

1821-
uint32_t read_short(uint32_t addr) {
1821+
uint32_t read_short(uint32_t addr, bool zero_fill = false) {
18221822
assert(!(addr & 1u));
18231823
uint16_t rc;
1824-
read(addr, (uint8_t *)&rc, 2);
1824+
read(addr, (uint8_t *)&rc, 2, zero_fill);
18251825
return rc;
18261826
}
18271827

18281828
// read a vector of types that have a raw_type_mapping
1829-
template <typename T> void read_raw(uint32_t addr, T &v) {
1829+
template <typename T> void read_raw(uint32_t addr, T &v, bool zero_fill = false) {
18301830
typename raw_type_mapping<T>::access_type& check = v; // ugly check that we aren't trying to read into something we shouldn't
1831-
read(addr, (uint8_t *)&v, sizeof(typename raw_type_mapping<T>::access_type));
1831+
read(addr, (uint8_t *)&v, sizeof(typename raw_type_mapping<T>::access_type), zero_fill);
18321832
}
18331833

18341834
// read a vector of types that have a raw_type_mapping
@@ -4008,8 +4008,8 @@ uint32_t get_access_family_id(memory_access &file_access) {
40084008
// No block, so RP2040 or absolute
40094009
if (file_access.get_binary_start() == FLASH_START) {
40104010
vector<uint8_t> checksum_data = {};
4011-
file_access.read_into_vector(FLASH_START, 252, checksum_data);
4012-
uint32_t checksum = file_access.read_int(FLASH_START + 252);
4011+
file_access.read_into_vector(FLASH_START, 252, checksum_data, true);
4012+
uint32_t checksum = file_access.read_int(FLASH_START + 252, true);
40134013
if (checksum == calc_checksum(checksum_data)) {
40144014
// Checksum is correct, so RP2040
40154015
DEBUG_LOG("Detected family ID %s due to boot2 checksum\n", family_name(RP2040_FAMILY_ID).c_str());

0 commit comments

Comments
 (0)