Skip to content

Commit b6aa0f9

Browse files
committed
Fix incorrect version check
1 parent 7698eda commit b6aa0f9

File tree

1 file changed

+51
-21
lines changed

1 file changed

+51
-21
lines changed

libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino

+51-21
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,36 @@
44
#define BOOTLOADER_ADDR (0x8000000)
55
mbed::FlashIAP flash;
66

7-
uint8_t* bootloader_data = (uint8_t*)(0x801F000);
7+
uint32_t bootloader_data_offset = 0x1F000;
8+
uint8_t* bootloader_data = (uint8_t*)(BOOTLOADER_ADDR + bootloader_data_offset);
89

9-
void setup() {
10-
// put your setup code here, to run once:
10+
void setup() {
1111
Serial.begin(115200);
1212
while (!Serial) {}
1313

14-
Serial.println("Validation: " + String(bootloader_data[0], HEX));
15-
Serial.println("BL version: " + String(bootloader_data[1]));
16-
Serial.println("Clock source: " + String(bootloader_data[2]));
17-
Serial.println("USB Speed: " + String(bootloader_data[3]));
18-
Serial.println("Ethernet: " + String(bootloader_data[4]));
19-
Serial.println("Wifi: " + String(bootloader_data[5]));
20-
Serial.println("RAM size: " + String(bootloader_data[6]));
21-
Serial.println("QSPI size: " + String(bootloader_data[7]));
22-
Serial.println("Video: " + String(bootloader_data[8]));
23-
Serial.println("Crypto: " + String(bootloader_data[9]));
24-
25-
if (bootloader_data[1] < 15) {
26-
Serial.println("New bootloader version available");
14+
uint8_t currentBootloaderVersion = bootloader_data[1];
15+
uint8_t availableBootloaderVersion = (envie_bootloader_mbed_bin + bootloader_data_offset)[1];
16+
17+
Serial.println("Magic Number (validation): " + String(bootloader_data[0], HEX));
18+
Serial.println("Bootloader version: " + String(bootloader_data[1]));
19+
Serial.println("Clock source: " + getClockSource(bootloader_data[2]));
20+
Serial.println("USB Speed: " + getUSBSpeed(bootloader_data[3]));
21+
Serial.println("Has Ethernet: " + String(bootloader_data[4] == 1 ? "Yes" : "No"));
22+
Serial.println("Has WiFi module: " + String(bootloader_data[5] == 1 ? "Yes" : "No"));
23+
Serial.println("RAM size: " + String(bootloader_data[6]) + " MB");
24+
Serial.println("QSPI size: " + String(bootloader_data[7]) + " MB");
25+
Serial.println("Has Video output: " + String(bootloader_data[8] == 1 ? "Yes" : "No"));
26+
Serial.println("Has Crypto chip: " + String(bootloader_data[9] == 1 ? "Yes" : "No"));
27+
28+
if (availableBootloaderVersion > currentBootloaderVersion) {
29+
Serial.print("\nA new bootloader version is available: v" + String(availableBootloaderVersion));
30+
Serial.println(" (Your version: v" + String(currentBootloaderVersion) + ")");
31+
Serial.println("Do you want to update the bootloader? Y/[n]");
32+
} else {
33+
Serial.println("The latest version of the bootloader is already installed (v" + String(availableBootloaderVersion) + ").");
34+
Serial.println("Do you want to update the bootloader anyway? Y/[n]");
2735
}
28-
Serial.println("Update bootloader? Y/[n]");
36+
2937
bool confirmation = false;
3038
while (confirmation == false) {
3139
if (Serial.available()) {
@@ -47,8 +55,31 @@ void setup() {
4755
}
4856
}
4957

50-
void applyUpdate(uint32_t address)
51-
{
58+
String getUSBSpeed(uint8_t flag) {
59+
switch (flag){
60+
case 1:
61+
return "USB 2.0/Hi-Speed (480 Mbps)";
62+
case 2:
63+
return "USB 1.1/Full-Speed (12 Mbps)";
64+
default:
65+
return "N/A";
66+
}
67+
}
68+
69+
String getClockSource(uint8_t flag) {
70+
switch (flag){
71+
case 0x8:
72+
return "External oscillator";
73+
case 0x4:
74+
return "External crystal";
75+
case 0x2:
76+
return "Internal clock";
77+
default:
78+
return "N/A";
79+
}
80+
}
81+
82+
void applyUpdate(uint32_t address) {
5283
long len = envie_bootloader_mbed_bin_len;
5384

5485
flash.init();
@@ -99,6 +130,5 @@ void applyUpdate(uint32_t address)
99130
}
100131

101132
void loop() {
102-
// put your main code here, to run repeatedly:
103133
delay(1000);
104-
}
134+
}

0 commit comments

Comments
 (0)