Program to update the D7A modem's firmware.
Dependencies: modem_ref_helper DebouncedInterrupt
Diff: main.cpp
- Revision:
- 9:bd53ca2aece5
- Parent:
- 8:914b7aff5554
- Child:
- 10:a568511d470d
--- a/main.cpp Thu Nov 10 17:18:42 2016 +0000 +++ b/main.cpp Thu Nov 10 17:55:05 2016 +0000 @@ -66,6 +66,7 @@ { d7a_revision_t rev; cup_cfg_t cup_cfg; + uint32_t cup_offset; // Start & initialize DBG_OPEN(); @@ -95,21 +96,25 @@ hw_errors += check_parameter("Device ID... ", rev.device_id, CUP_DEV_ID); hw_errors += check_parameter("Hardware version... ", rev.hw_version, CUP_HW_ID); fw_errors += check_parameter("Firmware id... ", rev.fw_version.id, CUP_FW_ID); - + if (version_old != version_new) { fw_errors += check_parameter("Firmware version major...", rev.fw_version.major, CUP_TARGET_FW_MAJOR); fw_errors += check_parameter("Firmware version minor...", rev.fw_version.minor, CUP_TARGET_FW_MINOR); - PRINT("Checking Available CUP space... "); - if (CUP_DATA_SIZE > cup_cfg.key) + PRINT("Checking CUP Slack... "); + + cup_offset = (CUP_CODE_SIZE > cup_cfg.src_offset)? CUP_CODE_SIZE - cup_cfg.src_offset : 0; + + int32_t cup_slack = cup_cfg.key - cup_offset - CUP_DATA_SIZE; + if (cup_slack < 0) { - PRINT("Failed. (0x%08X < 0x%08X)\r\n", cup_cfg.key, CUP_DATA_SIZE); + PRINT("Failed. (%d bytes short)\r\n", -cup_slack); fw_errors++; } else { - PRINT("OK. (0x%08X)\r\n", cup_cfg.key); + PRINT("OK. (%d bytes)\r\n", cup_slack); } } @@ -122,8 +127,15 @@ if (fw_errors) { + PRINT("You are trying to upgrade from v%d.%d.%d to v%d.%d.%d.\r\n", + rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch, + CUP_FW_MAJOR, CUP_FW_MINOR, CUP_FW_PATCH); PRINT("Please, check that you chose the right Revision in mbed revision tree.\r\n"); - PRINT("You can only upgrade to another patch 4.5.x --> 4.5.y\r\nor to the next minor 4.5.x --> 4.6.0\r\n"); + PRINT("You can only upgrade to another patch %d.%d.x --> %d.%d.y\r\nor to the next minor %d.%d.x --> %d.%d.0\r\n", + rev.fw_version.major, rev.fw_version.minor, + rev.fw_version.major, rev.fw_version.minor, + rev.fw_version.major, rev.fw_version.minor, + rev.fw_version.major, rev.fw_version.minor+1); } errors = hw_errors + fw_errors; @@ -134,13 +146,16 @@ } else if (version_old == version_new) { - PRINT("Your modem is up to date! (v%d.%d.%d)\r\n", rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch); + PRINT("Your modem is up to date! (v%d.%d.%d)\r\n", + rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch); } else { if (version_old > version_new) { - PRINT("/!\\ Your modem is at a more recent version /!\\\r\n/!\\ Are you sure you want to downgrade? /!\\\r\n"); + PRINT("/!\\ Your modem is at a more recent version (v%d.%d.%d)/!\\\r\n/!\\ Are you sure you want to downgrade to v%d.%d.%d /!\\\r\n", + rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch, + CUP_FW_MAJOR, CUP_FW_MINOR, CUP_FW_PATCH); PRINT("PRESS USER BUTTON TO CONFIRM...\r\n"); button_user.wait(); PRINT("\r\nDowngrading firmware: v%d.%d.%d --> v%d.%d.%d\r\n", @@ -157,7 +172,7 @@ } button_user.wait(); - cup_start_update(cup_cfg.src_offset, cup_cfg.key); + cup_start_update(cup_offset); } // Set main task to lowest priority