I have progressed in my knowhow. I modified my example a bit to test a theory I had.
PRINTF("input 'y' to switch firmware to run!\r\n");
PRINTF("input other char to stay in the current firmware!\r\n");
ch = GETCHAR();
PUTCHAR(ch);
PRINTF("\r\n");
for(uint32_t i=0;i<0x1000;i++);
if(ch == 'y')
{
LPUART_Deinit(BOARD_DEBUG_UART_BASEADDR);
if(firmware_index)
{
bl_firmware_switch(0);
}
else
{
bl_firmware_switch(1);
}
}
else if(ch == '0' || ch == '1')
{
int target = ch - '0';
PRINTF("forcing reboot from image %d\r\n", target);
for(uint32_t i=0;i<0x1000;i++);
LPUART_Deinit(BOARD_DEBUG_UART_BASEADDR);
bl_firmware_switch(target);
}
this example is inspired (or adapted) from AN12255's example. The changes I made are that, in addition to 'y' (which starts the "other" image), you can press '0' or '1' to force the start of the images indicated by the character.
I wrote this FW in both slot 0 and 1. In slot 0 it has image version 2 (0xFFFD0002), while in slot 1 it has 1 (0xFFFE0001). So the one to start must always be slot 0.
Effectively at reset slot 0 starts, and the "jumps" from one slot to another are consistent:
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
please input char for switching firmware, current count: 1
HADDRSTART 0
HADDREND 0
HADDROFFSET 0
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
y
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
y
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
please input char for switching firmware, current count: 1
HADDRSTART 0
HADDREND 0
HADDROFFSET 0
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
y
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
y
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
please input char for switching firmware, current count: 1
HADDRSTART 0
HADDREND 0
HADDROFFSET 0
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
1
forcing reboot from image 1
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
1
forcing reboot from image 1
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
0
forcing reboot from image 0
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
please input char for switching firmware, current count: 1
HADDRSTART 0
HADDREND 0
HADDROFFSET 0
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
0
forcing reboot from image 0
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
please input char for switching firmware, current count: 1
HADDRSTART 0
HADDREND 0
HADDROFFSET 0
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
if I swap the version numbers though (slot 1 <- 0xFFFE0001, slot 2 <- 0xFFFD0002), a strange thing happens. On reset slot 1 starts, as I expected, but it looks like the slot indexes are reversed:
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
please input char for switching firmware, current count: 1
HADDRSTART 0
HADDREND 0
HADDROFFSET 0
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
y
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
y
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
please input char for switching firmware, current count: 1
HADDRSTART 0
HADDREND 0
HADDROFFSET 0
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
1
forcing reboot from image 1
************ Hello world! This is firmware index 1
welcome to run firmware 1!
y
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
please input char for switching firmware, current count: 1
HADDRSTART 0
HADDREND 0
HADDROFFSET 0
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
y
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
y
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
y
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
y
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
0
forcing reboot from image 0
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
0
forcing reboot from image 0
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
1
forcing reboot from image 1
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
please input char for switching firmware, current count: 1
HADDRSTART 0
HADDREND 0
HADDROFFSET 0
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
1
forcing reboot from image 1
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
please input char for switching firmware, current count: 1
HADDRSTART 0
HADDREND 0
HADDROFFSET 0
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
0
forcing reboot from image 0
************ Hello world! This is firmware index 1
welcome to run firmware 1!
please input char for switching firmware, current count: 1
HADDRSTART 30000001
HADDREND 30200000
HADDROFFSET 200000
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
1
forcing reboot from image 1
@@@@@@@@@@@@ Hello world! This is firmware image 0
Firmware 0 start to run!
please input char for switching firmware, current count: 1
HADDRSTART 0
HADDREND 0
HADDROFFSET 0
input 'y' to switch firmware to run!
input other char to stay in the current firmware!
Can you explain this strange behavior? Or maybe you can point me to cove this feature/behavior is documented?
regards
Max