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

Add Second Stage Bootloader (SBU) for MKRNB 1500 #549

Merged
merged 6 commits into from
Jul 22, 2020

Conversation

giulcioffi
Copy link
Contributor

@giulcioffi giulcioffi commented Jul 16, 2020

SBU is a Second Stage bootloader for board MKRNB 1500 which uses Sara-R410M module. It follows the implementation of SSU for MKRGSM 1400, but using the power-on/off & reset sequences proper of Sara-R410M module (MKRNB/#47).
It exploits the File System APIs in library MKRNB to perform file operations from the module.
An example is provided to test how a file is loaded into the Sara module and then retrieved at the boot and flashed to be executed.

  1. Compile SBUBoot
  2. Go to /SBU/extras/SBUBoot and run ./build.sh
  3. Upload the example SBU_Usage.ino and follow the instructions written there.
  4. Upload the example SBU_LoadBinary.ino.
    • the binary of SBU_Usage will be loaded onto the Sara Module in a file called UPDATE.BIN
    • after a successful download, the file UPDATE.OK will be created and stored in the module
    • a system reboot is triggered
    • SBU checks if UPDATE.OK is present. If it finds it, it starts reading UPDATE.BIN and writing it into the flash by chunks of 512 bytes.
    • the flashed binary of SBU_Usage.ino is executed

Copy link
Contributor

@aentinger aentinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍, let's take out the debugging statements and we should be golden.


constexpr size_t blockSize = 512;
fileUtils.begin();
Serial1.begin(115200);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi 👋 Please eliminate all Serial output and re-build for a new binary header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now they should be all gone :)

update_success = true;
}
if (update_success) {
fileUtils.deleteFiles();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question ;) Will fileUtils.deleteFiles() any files? Like also ones that the user is storing on the MKR NB 1500 modem? That's quite a realistic possibility given the fact that we provide that capability to the user via NBFileUtils.

uint32_t read_bytes = 0;

if (updateSize > SBU_SIZE) {
updateSize = updateSize - SBU_SIZE - SBU_START;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Morning @giulcioffi ☕ 👋 I don't think this is quite right. The reason for this is that the first 0x2000 bytes of the MCU flash are occupied by the bootloader (the default bootloader, not the SBU) but those 0x2000 bytes of default bootloader are not included in the binary generated when compiling your Arduino sketch. Therefore I think it very likely that with the code like this you're skipping the last 0x2000 bytes of the actual application.

-updateSize = updateSize - SBU_SIZE - SBU_START;
+updateSize = updateSize - SBU_SIZE;

For reference compare to SSU.

@@ -254,7 +254,7 @@ void initVariant() {

// put SARA modem in reset on start to conserve power if it's not used
pinMode(SARA_RESETN, OUTPUT);
digitalWrite(SARA_RESETN, HIGH);
digitalWrite(SARA_RESETN, LOW);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @giulcioffi ☕ So we are still putting the SARA in reset here. Is that still necessary given the changes in arduino-libraries/MKRNB#55 ? Cheers, Alex - Otherwise great PR ;) let's hash this one out in Slack and then we should be able to merge it in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All cleared ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants