-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Soft 468 jumping back to bootloader #459
base: master
Are you sure you want to change the base?
Changes from 7 commits
cab2401
f1ce7d0
6d48397
b0a8848
069f19b
d52dd55
2f6df6a
d7782c6
4ec7d10
8b21f0d
0687368
b582454
3be0a3a
a91053c
3837dd3
adf3c2c
718f7f8
d3d5bd5
8289d59
ad43709
6b5dbae
f3a9b4b
4be0005
b502b92
f379df3
450b243
426d9e3
d75fa56
eaf6cd0
3a84088
47f14b9
fa7f236
f0c9869
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
// Jump to the bootloade at the beginning of flash memory | ||
void jump_to_bootloader(void); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
#include "flash.h" | ||
#include "interrupt.h" | ||
#include "jump_to_application.h" | ||
#include "jump_to_bootloader.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the next steps for this module is that we want to jump from the bootloader to the application when we receive a datagram message while in an application. This will be in can_fsm.c, in the
So there are a couple of parts to doing this:
|
||
#include "log.h" | ||
#include "ping.h" | ||
#include "query.h" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "jump_to_bootloader.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jump_to_application, jump_to_bootloader, and jump shouldn't be duplicated between the bootloader project and the ms-bootloader libraries, they should only appear in ms-bootloader. So remove the copies in the bootloader project / move all the functionality to ms-bootloader. |
||
|
||
#include <stdint.h> | ||
#include <stdnoreturn.h> | ||
#include <string.h> | ||
|
||
#include "bootloader_mcu.h" | ||
#include "stm32f0xx_misc.h" | ||
#include "stm32f0xx_syscfg.h" | ||
|
||
static noreturn __attribute__((naked)) void prv_perform_jump(uint32_t sp, uint32_t pc) { | ||
__asm( | ||
"msr msp, %[sp] \n" // reset the main stack pointer (msp) to sp | ||
"bx %[pc] \n" // jump to pc | ||
|
||
// this bizarre syntax associates the "sp" and "pc" in asm with the sp and pc parameters | ||
// see http://www.ethernut.de/en/documents/arm-inline-asm.html | ||
: | ||
: [sp] "r"(sp), [pc] "r"(pc)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to factor this function out from this and jump_to_application.c into an ms-common (or ms-bootloader) library called |
||
|
||
void jump_to_bootloader(void) { | ||
// Disable all interrupts so their is no interference when working with vector tables | ||
__disable_irq(); | ||
|
||
// Reset the vector table to bootloader's vector table | ||
SYSCFG_MemoryRemapConfig( | ||
SYSCFG_MemoryRemap_SRAM); // change where the vector table is stored to beginning of flash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will set the vector table to the beginning of SRAM (which is where it is already since we're in the application) - you'll need to use |
||
|
||
// story memory location of bootloader starting point at the beginning of flash? | ||
uint32_t *bootloader_in_flash = BOOTLOADER_DEFAULT_LOCATION; | ||
// setting the stack pointer to the bootloader location now | ||
uint32_t initial_sp = bootloader_in_flash[0]; | ||
uint32_t reset_handler_pc = bootloader_in_flash[1]; | ||
|
||
// re-enable interrupts | ||
__enable_irq(); | ||
// jump to bootloader | ||
prv_perform_jump(initial_sp, reset_handler_pc); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
BOOTLOADER_START
might be a clearer name for this, especially since we'll likely never have the bootloader at a different location (so not "default").