Skip to content
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

sw: Fix RAM boot detection #331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/BOOT-SEQUENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The timeout must be given in the third (4-byte little-endian) word of the progra

During development, it may be inconvenient to load a program onto SPI flash. Or maybe you want to run something that doesn't modify the contents of SPI. This is possible with `RAM boot`.

If the DFU bootloader encounters the magic number `0x17ab0f23` within the first 56 bytes, then it will enable *RAM boot* mode. In this mode, the SPI flash won't be erased, and the program will be loaded to RAM.
If the DFU bootloader encounters the magic number `0x17ab0f23` within the first 60 bytes, then it will enable *RAM boot* mode. In this mode, the SPI flash won't be erased, and the program will be loaded to RAM.

Note that the value following the magic number indicates the offset where the program will be loaded to. This should be somewhere in RAM. `0x10002000` is a good value, and is guaranteed to not interfere with Foboot itself.

Expand Down
8 changes: 4 additions & 4 deletions sw/src/dfu.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ bool dfu_download(unsigned blockNum, unsigned blockLength,
// Check to see if we're writing to RAM instead of SPI flash
if ((blockNum == 0) && (packetOffset == 0) && (packetLength > 0)) {
unsigned int i = 0;
unsigned int max_check = packetLength;
unsigned int max_check = packetLength / 4;
if (max_check > sizeof(dfu_buffer))
max_check = sizeof(dfu_buffer);
for (i = 0; i < (max_check/4)-1; i++) {
if (dfu_buffer[i/4] == RAM_BOOT_SENTINAL) {
ram_mode = dfu_buffer[(i/4)+1];
for (i = 0; i < max_check-1; i++) {
if (dfu_buffer[i] == RAM_BOOT_SENTINAL) {
ram_mode = dfu_buffer[i+1];
break;
}
}
Expand Down