Skip to content

Commit 2a69231

Browse files
committed
feat(flash): Show sector role during CRC checking
This matches the NOR flash partition table in https://github.com/mindboards/ev3sources/blob/78ebaf5b6f8fe31cc17aa5dce0f8e4916a4fc072/extra/linux-03.20.00.13/arch/arm/mach-davinci/board-da850-evm.c#L245 and the scripts in the firmware.
1 parent ff9d1c9 commit 2a69231

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

src/bl_install.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ static int bootloader_send(FILE *fp, int length, u32* pCrc32);
4747
*/
4848
static int bootloader_checksum(int offset, int length, u32 *pCrc32);
4949

50+
/**
51+
* @brief Describe the role of the current sector
52+
* @param Sector number
53+
* @retval String describing the role of the sector
54+
*/
55+
static const char *sector_explanation(u32 sector_number);
56+
57+
/**
58+
* @brief Check whether the given sector is modified by the brick itself
59+
* @param Sector number
60+
* @retval True if the sector CRC can change, false otherwise
61+
*/
62+
static bool sector_is_mutable(u32 sector_number);
63+
5064
/**
5165
* @brief Install new firmware binary to the internal flash.
5266
* @param fp Firmware file to download to the brick.
@@ -258,6 +272,8 @@ int bootloader_crc(FILE *fp, u32 starting_sector, u32 num_sectors, bool verbose)
258272
// Compares the remote and local CRCs of each sector, showing the results of each.
259273
printf("Sector CRC comparison:\n");
260274
bool all_ok = true;
275+
const char *last_area = NULL;
276+
261277
for (u32 sector = starting_sector; sector < starting_sector + num_sectors; sector++) {
262278
u32 local_sector_crc32 = crc32(0, firmware + sector * FLASH_SECTOR_SIZE, FLASH_SECTOR_SIZE);
263279
u32 remote_sector_crc32 = 0;
@@ -266,6 +282,12 @@ int bootloader_crc(FILE *fp, u32 starting_sector, u32 num_sectors, bool verbose)
266282
bool this_ok = remote_sector_crc32 == local_sector_crc32;
267283
all_ok = all_ok && this_ok;
268284

285+
const char *area = sector_explanation(sector);
286+
if (area != last_area) { // static string literals can be compared by pointers
287+
printf("* %s%s\n", area, sector_is_mutable(sector) ? "; CRC mismatch is expected here" : "");
288+
last_area = area;
289+
}
290+
269291
if (sector_err == ERR_UNK) {
270292
printf("Sector %3d: Remote CRC = %08X, local CRC = %08X%s\n", sector, remote_sector_crc32,
271293
local_sector_crc32, this_ok ? "" : " ERR");
@@ -298,6 +320,36 @@ int bootloader_crc(FILE *fp, u32 starting_sector, u32 num_sectors, bool verbose)
298320
return err;
299321
}
300322

323+
static const char *sector_explanation(u32 sector_number)
324+
{
325+
const char *explanation = "unknown";
326+
if (sector_number < 0x04) { // 0x000000 - 0x03FFFF
327+
explanation = "U-Boot";
328+
} else if (sector_number == 0x04) { // 0x040000 - 0x04FFFF
329+
explanation = "U-Boot environment";
330+
} else if (sector_number < 0x25) { // 0x050000 - 0x24FFFF
331+
explanation = "Linux kernel";
332+
} else if (sector_number < 0xCB) { // 0x250000 - 0xCAFFFF
333+
explanation = "Root file system";
334+
} else if (sector_number < 0xFA) { // 0xCB0000 - 0xF9FFFF
335+
explanation = "User data";
336+
}
337+
return explanation;
338+
}
339+
340+
static bool sector_is_mutable(u32 sector_number)
341+
{
342+
bool mutable = false;
343+
if (sector_number == 4) {
344+
// U-Boot environment
345+
mutable = true;
346+
} else if (sector_number >= 0xCB) {
347+
// User data
348+
mutable = true;
349+
}
350+
return mutable;
351+
}
352+
301353
static int bootloader_checksum(int offset, int length, u32 *pCrc32)
302354
{
303355
*pCrc32 = 0;

0 commit comments

Comments
 (0)