Skip to content

Commit 135c959

Browse files
authored
Merge pull request arduino#69 from arduino/bootloader-info-update
Fix incorrect bootloader version check
2 parents bad8e6d + a7f758c commit 135c959

File tree

2 files changed

+56
-24
lines changed

2 files changed

+56
-24
lines changed

libraries/Portenta_System/examples/PortentaH7_getBootloaderInfo/PortentaH7_getBootloaderInfo.ino

+3-4
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ String getUSBSpeed(uint8_t flag) {
3030
String getClockSource(uint8_t flag) {
3131
switch (flag){
3232
case 0x8:
33-
return "External clock (ST Link MCO)";
33+
return "External oscillator";
3434
case 0x4:
35-
return "External xtal (X3 on board - not provided by default)";
35+
return "External crystal";
3636
case 0x2:
37-
return "HSI internal clock";
37+
return "Internal clock";
3838
default:
3939
return "N/A";
4040
}
41-
4241
}
4342

4443
void loop() {

libraries/Portenta_System/examples/PortentaH7_updateBootloader/PortentaH7_updateBootloader.ino

+53-20
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,39 @@
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(currentBootloaderVersion));
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 if(availableBootloaderVersion < currentBootloaderVersion){
33+
Serial.println("\nA newer bootloader version is already installed: v" + String(currentBootloaderVersion));
34+
Serial.println("Do you want to downgrade the bootloader to v" + String(availableBootloaderVersion) + "? Y/[n]");
35+
} else {
36+
Serial.println("\nThe latest version of the bootloader is already installed (v" + String(currentBootloaderVersion) + ").");
37+
Serial.println("Do you want to update the bootloader anyway? Y/[n]");
2738
}
28-
Serial.println("Update bootloader? Y/[n]");
39+
2940
bool confirmation = false;
3041
while (confirmation == false) {
3142
if (Serial.available()) {
@@ -47,8 +58,31 @@ void setup() {
4758
}
4859
}
4960

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

5488
flash.init();
@@ -99,6 +133,5 @@ void applyUpdate(uint32_t address)
99133
}
100134

101135
void loop() {
102-
// put your main code here, to run repeatedly:
103136
delay(1000);
104137
}

0 commit comments

Comments
 (0)