From 15372179af10cdff8f04a2875f88d8804aa2a42e Mon Sep 17 00:00:00 2001 From: Sebastian Hunkeler Date: Sat, 10 Oct 2020 12:38:17 +0200 Subject: [PATCH 1/5] Add suggestions from PR #67 review --- .../PortentaH7_getBootloaderInfo.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Portenta_System/examples/PortentaH7_getBootloaderInfo/PortentaH7_getBootloaderInfo.ino b/libraries/Portenta_System/examples/PortentaH7_getBootloaderInfo/PortentaH7_getBootloaderInfo.ino index 4ae196baa..ae4e7e244 100644 --- a/libraries/Portenta_System/examples/PortentaH7_getBootloaderInfo/PortentaH7_getBootloaderInfo.ino +++ b/libraries/Portenta_System/examples/PortentaH7_getBootloaderInfo/PortentaH7_getBootloaderInfo.ino @@ -30,11 +30,11 @@ String getUSBSpeed(uint8_t flag) { String getClockSource(uint8_t flag) { switch (flag){ case 0x8: - return "External clock (ST Link MCO)"; + return "External oscillator"; case 0x4: - return "External xtal (X3 on board - not provided by default)"; + return "External crystal"; case 0x2: - return "HSI internal clock"; + return "Internal clock"; default: return "N/A"; } From 7698eda98a2a191476902e89303dbda277dab7ef Mon Sep 17 00:00:00 2001 From: Sebastian Hunkeler Date: Sat, 10 Oct 2020 13:05:20 +0200 Subject: [PATCH 2/5] Remove superfluous empty line --- .../PortentaH7_getBootloaderInfo.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/Portenta_System/examples/PortentaH7_getBootloaderInfo/PortentaH7_getBootloaderInfo.ino b/libraries/Portenta_System/examples/PortentaH7_getBootloaderInfo/PortentaH7_getBootloaderInfo.ino index ae4e7e244..11dc2ed3d 100644 --- a/libraries/Portenta_System/examples/PortentaH7_getBootloaderInfo/PortentaH7_getBootloaderInfo.ino +++ b/libraries/Portenta_System/examples/PortentaH7_getBootloaderInfo/PortentaH7_getBootloaderInfo.ino @@ -38,7 +38,6 @@ String getClockSource(uint8_t flag) { default: return "N/A"; } - } void loop() { From b6aa0f9e54c431a43119a4c63ed2014d16e29775 Mon Sep 17 00:00:00 2001 From: Sebastian Hunkeler Date: Sat, 10 Oct 2020 13:06:22 +0200 Subject: [PATCH 3/5] Fix incorrect version check --- .../PortentaH7_updateBootloader.ino | 72 +++++++++++++------ 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino b/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino index 7f0f6068b..b343b92c5 100644 --- a/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino +++ b/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino @@ -4,28 +4,36 @@ #define BOOTLOADER_ADDR (0x8000000) mbed::FlashIAP flash; -uint8_t* bootloader_data = (uint8_t*)(0x801F000); +uint32_t bootloader_data_offset = 0x1F000; +uint8_t* bootloader_data = (uint8_t*)(BOOTLOADER_ADDR + bootloader_data_offset); -void setup() { - // put your setup code here, to run once: +void setup() { Serial.begin(115200); while (!Serial) {} - Serial.println("Validation: " + String(bootloader_data[0], HEX)); - Serial.println("BL version: " + String(bootloader_data[1])); - Serial.println("Clock source: " + String(bootloader_data[2])); - Serial.println("USB Speed: " + String(bootloader_data[3])); - Serial.println("Ethernet: " + String(bootloader_data[4])); - Serial.println("Wifi: " + String(bootloader_data[5])); - Serial.println("RAM size: " + String(bootloader_data[6])); - Serial.println("QSPI size: " + String(bootloader_data[7])); - Serial.println("Video: " + String(bootloader_data[8])); - Serial.println("Crypto: " + String(bootloader_data[9])); - - if (bootloader_data[1] < 15) { - Serial.println("New bootloader version available"); + uint8_t currentBootloaderVersion = bootloader_data[1]; + uint8_t availableBootloaderVersion = (envie_bootloader_mbed_bin + bootloader_data_offset)[1]; + + Serial.println("Magic Number (validation): " + String(bootloader_data[0], HEX)); + Serial.println("Bootloader version: " + String(bootloader_data[1])); + Serial.println("Clock source: " + getClockSource(bootloader_data[2])); + Serial.println("USB Speed: " + getUSBSpeed(bootloader_data[3])); + Serial.println("Has Ethernet: " + String(bootloader_data[4] == 1 ? "Yes" : "No")); + Serial.println("Has WiFi module: " + String(bootloader_data[5] == 1 ? "Yes" : "No")); + Serial.println("RAM size: " + String(bootloader_data[6]) + " MB"); + Serial.println("QSPI size: " + String(bootloader_data[7]) + " MB"); + Serial.println("Has Video output: " + String(bootloader_data[8] == 1 ? "Yes" : "No")); + Serial.println("Has Crypto chip: " + String(bootloader_data[9] == 1 ? "Yes" : "No")); + + if (availableBootloaderVersion > currentBootloaderVersion) { + Serial.print("\nA new bootloader version is available: v" + String(availableBootloaderVersion)); + Serial.println(" (Your version: v" + String(currentBootloaderVersion) + ")"); + Serial.println("Do you want to update the bootloader? Y/[n]"); + } else { + Serial.println("The latest version of the bootloader is already installed (v" + String(availableBootloaderVersion) + ")."); + Serial.println("Do you want to update the bootloader anyway? Y/[n]"); } - Serial.println("Update bootloader? Y/[n]"); + bool confirmation = false; while (confirmation == false) { if (Serial.available()) { @@ -47,8 +55,31 @@ void setup() { } } -void applyUpdate(uint32_t address) -{ +String getUSBSpeed(uint8_t flag) { + switch (flag){ + case 1: + return "USB 2.0/Hi-Speed (480 Mbps)"; + case 2: + return "USB 1.1/Full-Speed (12 Mbps)"; + default: + return "N/A"; + } +} + +String getClockSource(uint8_t flag) { + switch (flag){ + case 0x8: + return "External oscillator"; + case 0x4: + return "External crystal"; + case 0x2: + return "Internal clock"; + default: + return "N/A"; + } +} + +void applyUpdate(uint32_t address) { long len = envie_bootloader_mbed_bin_len; flash.init(); @@ -99,6 +130,5 @@ void applyUpdate(uint32_t address) } void loop() { - // put your main code here, to run repeatedly: delay(1000); -} +} \ No newline at end of file From f7c8f589dba24d80f8e0f7e4ed3eb5af47126be8 Mon Sep 17 00:00:00 2001 From: Sebastian Hunkeler Date: Sat, 10 Oct 2020 13:16:05 +0200 Subject: [PATCH 4/5] Add case for downgrading BL --- .../PortentaH7_updateBootloader.ino | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino b/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino index b343b92c5..1adb3a9de 100644 --- a/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino +++ b/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino @@ -29,8 +29,11 @@ void setup() { Serial.print("\nA new bootloader version is available: v" + String(availableBootloaderVersion)); Serial.println(" (Your version: v" + String(currentBootloaderVersion) + ")"); Serial.println("Do you want to update the bootloader? Y/[n]"); + } else if(availableBootloaderVersion < currentBootloaderVersion){ + Serial.println("\nA newer bootloader version is already installed: v" + String(currentBootloaderVersion)); + Serial.println("Do you want to downgrade the bootloader to v" + String(availableBootloaderVersion) + "? Y/[n]"); } else { - Serial.println("The latest version of the bootloader is already installed (v" + String(availableBootloaderVersion) + ")."); + Serial.println("\nThe latest version of the bootloader is already installed (v" + String(currentBootloaderVersion) + ")."); Serial.println("Do you want to update the bootloader anyway? Y/[n]"); } @@ -131,4 +134,4 @@ void applyUpdate(uint32_t address) { void loop() { delay(1000); -} \ No newline at end of file +} From a7f758cd9fab9f643f34748cb24e1cdca9e671c0 Mon Sep 17 00:00:00 2001 From: Sebastian Hunkeler Date: Sat, 10 Oct 2020 15:51:38 +0200 Subject: [PATCH 5/5] Reuse variable for BL version --- .../PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino b/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino index 1adb3a9de..8b813129c 100644 --- a/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino +++ b/libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino @@ -15,7 +15,7 @@ void setup() { uint8_t availableBootloaderVersion = (envie_bootloader_mbed_bin + bootloader_data_offset)[1]; Serial.println("Magic Number (validation): " + String(bootloader_data[0], HEX)); - Serial.println("Bootloader version: " + String(bootloader_data[1])); + Serial.println("Bootloader version: " + String(currentBootloaderVersion)); Serial.println("Clock source: " + getClockSource(bootloader_data[2])); Serial.println("USB Speed: " + getUSBSpeed(bootloader_data[3])); Serial.println("Has Ethernet: " + String(bootloader_data[4] == 1 ? "Yes" : "No"));