From be280fa4a8c851d774cf4581972bc99329c43e6b Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Tue, 24 May 2016 17:14:28 +0200 Subject: non-working code to upload an application and jump to it Committing my work in progress in case someone else wants to help. --- projects/cli-test/cli-test.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'projects/cli-test/cli-test.c') diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c index 41d7365..30623a4 100644 --- a/projects/cli-test/cli-test.c +++ b/projects/cli-test/cli-test.c @@ -39,6 +39,7 @@ #include "stm-keystore.h" #include "stm-sdram.h" #include "mgmt-cli.h" +#include "mgmt-dfu.h" #include "test_sdram.h" #include @@ -420,6 +421,7 @@ main() configure_cli_fpga(&cli); configure_cli_test(&cli); configure_cli_misc(&cli); + configure_cli_dfu(&cli); led_off(LED_RED); led_on(LED_GREEN); -- cgit v1.2.3 From 2529fb514c10513b52b283472ed6edd26f5d0fc4 Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Wed, 25 May 2016 22:46:40 +0200 Subject: More DFU code. This might actually work. The applications to be uploaded using 'dfu upload' have to have another FLASH defined in their linker script. Have to recompile some firmware tomorrow and test if this actually works. --- projects/cli-test/cli-test.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'projects/cli-test/cli-test.c') diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c index 30623a4..1a8c6b7 100644 --- a/projects/cli-test/cli-test.c +++ b/projects/cli-test/cli-test.c @@ -410,6 +410,9 @@ main() { static struct cli_def cli; + /* This is simulating the bootloader from the cli-test. */ + check_early_dfu_jump(); + stm_init(); led_on(LED_RED); -- cgit v1.2.3 From 684b0c04b0eb81a8b587fe89d093a4499d960c28 Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Thu, 26 May 2016 13:26:18 +0200 Subject: Implement a bootloader. This bootloader is now the application at 0x08000000 (FLASH start), which the STM32 will execute upon reset. The other applications are now loaded at 0x08030000 (128 KB into the flash) and will never get started unless the bootloader has been programmed into flash too. --- projects/cli-test/cli-test.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'projects/cli-test/cli-test.c') diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c index 1a8c6b7..30623a4 100644 --- a/projects/cli-test/cli-test.c +++ b/projects/cli-test/cli-test.c @@ -410,9 +410,6 @@ main() { static struct cli_def cli; - /* This is simulating the bootloader from the cli-test. */ - check_early_dfu_jump(); - stm_init(); led_on(LED_RED); -- cgit v1.2.3 From 92ce4da1158aabd1a45d3a5044a5e5fd7bac3c41 Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Fri, 27 May 2016 15:56:16 +0200 Subject: DFU working - but no signature validation for now. --- projects/cli-test/cli-test.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'projects/cli-test/cli-test.c') diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c index 30623a4..84c268b 100644 --- a/projects/cli-test/cli-test.c +++ b/projects/cli-test/cli-test.c @@ -397,7 +397,7 @@ void configure_cli_test(struct cli_def *cli) cli_command_node(test, sdram, "Run SDRAM tests"); } -void configure_cli_misc(struct cli_def *cli) +static void configure_cli_misc(struct cli_def *cli) { /* filetransfer */ cli_command_root_node(filetransfer, "Test file transfering"); @@ -405,11 +405,32 @@ void configure_cli_misc(struct cli_def *cli) cli_command_root_node(reboot, "Reboot the STM32"); } +typedef void (*pFunction)(void); + +/* This is it's own function to make it more convenient to set a breakpoint at it in gdb */ +void do_early_dfu_jump(void) +{ + pFunction loaded_app = (pFunction) *dfu_code_ptr; + /* Set the stack pointer to the correct one for the firmware */ + __set_MSP(*dfu_msp_ptr); + /* Set the Vector Table Offset Register */ + SCB->VTOR = (uint32_t) dfu_firmware; + loaded_app(); + while (1); +} + + int main() { static struct cli_def cli; + /* Check if we've just rebooted in order to jump to the firmware. */ + if (*dfu_control == HARDWARE_EARLY_DFU_JUMP) { + *dfu_control = 0; + do_early_dfu_jump(); + } + stm_init(); led_on(LED_RED); -- cgit v1.2.3