ericbaril72 / SAMD21-SDBootloader

Code Publishing
6 stars 2 forks source link

How can we compile this into a .bin bootloader ? #1

Closed deladriere closed 5 years ago

ericbaril72 commented 7 years ago

Not a trivial job ... Start With the original SD_MMC bootloader for SAMD20 in Atmel Studio. Check that you can compile it 'as-is' then replace the originals with those. Re-compile

Let me know what is missing ... I'll add them.

I worked on this last year and currently investigating other bootloading mecanisms. Since I am not expert in 'Github' with AtmelStudio and the 'solution explorer' thing, I didn't push for a complete package.

Let me know what you are trying to achieve, I may be able to assist or point you in a better approach as I had to do a lot of leg work when not a lot of people work on bootloaders .... They only want to do a 3-steps approach. 1-- Click-here for complete toolchain installation ( Mac / Linux & windows support ) 2-- Click-here for compilation ( All Errors fully managed ) 3-- Click-here for ANY Device updating ( with and without external debuggers )

;-)

deladriere commented 7 years ago

Thanks for your explanations! Beeing on Mac I am not using Atmel Studio but I use the Atmel-ICE programmer. My first idea was to find a compiled .bin of your bootloader so I could flash my board with it using the Arduino IDE. I have a custom Feather M0 board with an SD card and the CS pin on pin 10 I would like the board to be able to boot from the SD card and distribute my code as .bin to copy on the SD card.

ericbaril72 commented 7 years ago

are you using the same pin mappings for SPI as the feather M0 WINC1500 from Adafruit ? My app uses Wifi to send and receive files. I download the latest firmware and call a reset.

pin A3 (pa4) is in INPUT mode ( in case I want to force bootloading -- pin is read but not IF'ed ) . pin A0 (pa2 ) for selecting between 2 file names on bootup. Reading HIGH --> uses /MDL.bin Reading LOW --> uses /fd.bin ( factory default ) backup in case you sent the wrong file ... Never happened to me !!!!

pin 10 ( Arduino for CS )

I could send you the .bin.

Uses close to 32kB of Flash .... make sure the new app you compile has APP_START_ADDRESS at 0x004000

Eric

On Thu, Jun 29, 2017 at 2:27 PM deladriere notifications@github.com wrote:

Thanks for your explanations! Beeing on Mac I am not using Atmel Studio but I use the Atmel-ICE programmer. My first idea was to find a compiled .bin of your bootloader so I could flash my board with it using the Arduino IDE. I have a custom Feather M0 board with an SD card and the CS pin on pin 10 I would like the board to be able to boot from the SD card and distribute my code as .bin to copy on the SD card.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/ericbaril72/SAMD21-SDBootloader/issues/1#issuecomment-312054686, or mute the thread https://github.com/notifications/unsubscribe-auth/AMpZxisCvOcSh-V5EUONCXTRfb6nEPZYks5sI-ypgaJpZM4OJoKx .

deladriere commented 7 years ago

SPI are on same pins ! MOSI : PB10 MISO: PA12 SCK: PB11 CS: PA18 (Arduino 10) but what about : APP_START_ADDRESS at 0x004000 : I don't know where to set this in the Arduino IDE

ericbaril72 commented 7 years ago

in the "FEATHER" hardware librairie (C:\Users...XYZ...\AppData\Local\Arduino15\packages\adafruit\hardware\samd\1.0.13) the is a file called -->boards.txt

[image: image.png] It tells the linker which file to use .... in this case, I switch between 3 versions ...

make a copy of your original file, rename it so that it clearly tells you which address you are using

and inside, change this line: using 0x8000 ( 32kB ) [image: image.png]

I'll Add the binary on github

Eric On Thu, Jun 29, 2017 at 3:09 PM deladriere notifications@github.com wrote:

SPI are on same pins ! MOSI : PB10 MISO: PA12 SCK: PB11 CS: PA18 (Arduino 10) but what about : APP_START_ADDRESS at 0x004000 : I don't know where to set this in the Arduino IDE

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/ericbaril72/SAMD21-SDBootloader/issues/1#issuecomment-312070253, or mute the thread https://github.com/notifications/unsubscribe-auth/AMpZxri-HjDYWv35slQbW2b2J5O5RT5uks5sI_ZHgaJpZM4OJoKx .

deladriere commented 7 years ago

Hi Eric I can't see the images ...

ericbaril72 commented 7 years ago

In /build.

I added the .bin and the .elf in github.

Sent from my mobile

Le 29 juin 2017 à 16:13, deladriere notifications@github.com a écrit :

Hi Eric I can't see the images ...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

deladriere commented 7 years ago

Thanks I see the .bin in /build but not the [image: image.png] you are referring too so I don't understand which lines to change in the boards.txt

deladriere commented 7 years ago

Hi Eric Sorry to insist: could you post your boards.txt so I can understand what to change in it? thanks a lot

ericbaril72 commented 7 years ago

Salut,

--> please contact me when you read this answer. I may have a better solution for you. so far, it works AWESOME. but may not work for your application. What is your platform and how do you plan on updating the SD card with new firmware ?

regarding this bootloader: 1st: Were you able to program the Binary into the chip ? many pre-programmed device have their Flash-bootloader memory area protected. you will need to disable protection. ( Bootprot fuse )

2nd: were you able to locate the board.txt file ? you need to look into it and get accustomed to the tags you see in there. Trust me, I often do not select the proper linker file and end-up having the bootloader flashing with the wrongly linked binaries which end-up not working. I HIGHLY SUGGEST you start with a simple "BLINK" binary at first.

this line in the boards.txt points to the linker file you want to use. --> adafruit_feather_m0.build.ldscript=/variant/(arduinoboardname)/linker_scripts/gcc/flash_with_bootloader.ld

in the "/linker_scripts/gcc/" directory, make a copy of the linker file and rename it to something meaningfull ( mine are named with the Start address name as I have multiple start address depending on the bootloader I used )

Edit your new linker file and change the FLASH start address and Length ( total - start_address )

MEMORY { FLASH (rx) : ORIGIN = 0x00000000+0x4000, LENGTH = 0x00040000-0x4000 / First 32KB used by bootloader / RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 }

ericbaril72 commented 7 years ago

try this: UF2 bootloader ( fits in the same 8kB as the current Feather M0 bootloader) no need to change the start address of your futur Arduino Sketches

it is backward compatible with the original BOSSAC bootloader. You can still upload new code using the Arduino IDE.

BUT .... the Cool part : When in bootloader mode ( double-tap reset / or not programmed ), the LED will slowly Dim & Brighten

the BOARD will show up in Windows as a new drive (USB memory Card). Drag&Drop the ".uf2" file on the drive and VOILA ! it programs and reboots to your app. Converting from .bin to .uf2 is a simple python Script

Let me know if it worked for you.

uf2_bootloader.zip

deladriere commented 7 years ago

Hi Eric

I tested the UF2 process: It works like a charm !!!! Thank you sooo much! I can see the "FEATHERBOOT" drive on my Mac and drag the new.UF2 works! (blinking)

are you using this one https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-circuitpython/uf2-bootloader

or did you develop your own ? (I just tried the Feather MO v1.22 Update.uf2 and its seem to work too

What I love: 👍

How can I make my own uf2 ? like described here ? : https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-circuitpython/uf2-bootloader

ericbaril72 commented 7 years ago

Yes, that is the one ! It does require a PC connected to the SAMD to do the update which most people do with their projects. You could have used BOSSAC to do the programming but requires special software.

My bootloader does not expose MSC on the USB ... so you do need to program the SD card differently.

In my perticular case, I use the Feather WINC1500 + SD card. So the file gets downloaded via Wifi instead and stored on the SD. then my bootloader searches for the .BIN file and does the update.

I would like to add MSC to my bootloader but still need to better understand FAT first. unfortunatly, becoming a FAT expert is not the goal of my project ! ;-)

If you ever meet/talk to someone who needs OTA (over-the-air) or SD update, point him here. Maybe the next guy will have the missing piece to my puzzle.

So far, mine works well BUT I wish it could be better.

Good to hear you have found your way !

Salut Eric

deladriere commented 7 years ago

Hi Eric Thank you so much for providing the uf2_bootloader.zip : really convenient to let us test this tool It just opened a new world for updating boards.

I tried to compile it too from https://github.com/Microsoft/uf2-samd21 but I don't (yet) have all the tool needed I would like to try the single reset option because reaching the reset button for a double click is not soo easy (the board in placed in a box) could you try to compile it with the single reset on as described here https://makecode.com/blog/one-chip-to-flash-them-all

In single-reset mode, when the board is first connected to a computer (as opposed to a battery) it stays in bootloader mode, until flashed, or until reset is hit again. If reset is hit in application mode, the board immediately enters the bootloader mode.

I guess you "just" need to update this line from uf2.h

// If enabled, bootloader will start on power-on and every reset. A second reset
// will start the app. This only happens if the app says it wants that (see SINGLE_RESET() below).
// If disabled here or by the app, the bootloader will only start with double-click of the reset
// button.
#define USE_SINGLE_RESET 1

merci beaucoup!

ericbaril72 commented 7 years ago

I won't be able to do it 'till I return mid next-week but if I recall, Arduino has a banzai(); function that erases the flash. You could use that to stay in bootloader until then . Make sure to activate WD or I can't promise about the outcome.

Sent from my mobile

Le 7 juil. 2017 à 01:53, deladriere notifications@github.com a écrit :

Hi Eric Thank you so much for providing the uf2_bootloader.zip : really convenient to let us test this tool It just opened a new world for updating boards.

I tried to compile it too from https://github.com/Microsoft/uf2-samd21 but I don't (yet) have all the tool needed I would like to try the single reset option because reaching the reset button for a double click is not soo easy (the board in placed in a box) could you try to compile it with the single reset on as described here https://makecode.com/blog/one-chip-to-flash-them-all

In single-reset mode, when the board is first connected to a computer (as opposed to a battery) it stays in bootloader mode, until flashed, or until reset is hit again. If reset is hit in application mode, the board immediately enters the bootloader mode.

I guess you "just" need to update this line from uf2.h

// If enabled, bootloader will start on power-on and every reset. A second reset // will start the app. This only happens if the app says it wants that (see SINGLE_RESET() below). // If disabled here or by the app, the bootloader will only start with double-click of the reset // button.

define USE_SINGLE_RESET 1

merci beaucoup!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

rutvikna commented 6 years ago

Hi Eric,

I am working on a SAMD21 board. I tried the SAM-BA and wanted to try out the microsoft uf2 bootloader and also your project. Is it possible for you to send me the zip file containing the .bin for UF2 Bootloader.

Thanks, Rutvik

ericbaril72 commented 6 years ago

The zip is in the thread @ july 4th comment pre-compiled with an attached blink.uf2 test program. I used it again today and was like magic.

you may need to "uninstall" the driver from your PC if you don't see the drive showing up. after uninstall the driver, simply disconnect / re-connect the SAMD21 and it will re-install and show both the serial port AND the MSC drive. Drag-and-drop --> voila ! magic

FrankRahlic commented 6 years ago

Eric, I went to compile the SD card bootloader today and it looks like I am missing the uart dependancy. I have asf-standalone-archive-3.36.2.65 but it seems none of the "common" source files work when I try to include them in the project. I get a recipe for target error which believe is probably because of a different version of the usart.h. Do you know what version of asf you compiled on? I can get the SAMD20 project that is included in the asf to compile easily but replacing the files from github breaks it (it's in the spi_master_bootloader). For what it's worth I really like the bootloader that was precompiled, I just want to change a few things for my application. If you have the whole project folder that would be awesome. Thanks!

ericbaril72 commented 6 years ago

rhinoballs, I will have a hard time packaging the whole project as I have done some changes to my ASF setup since then ... can you try compiling without the "Serial" ?

Those dependancies are giving me a headacke because I try to do both Arduino framework AND ASF and started back in the days when the Arduino IDE was using an older/different CMSIS then ASF.

don't dodge the "dependancies" fixing or you'll always have issues with AS

frippe75 commented 6 years ago

Hi Eric,

Also trying to compile your bootloader, which I think is awesome work on your part!

Trying to write a Makefile to get it to compile but I cant work out the details. I downloded the latest asf-standalone-archive and placed it under ./ASF

Then I started with the Makefile from Adafruit SAMD core github repo. And added alot of includes to satisfy each error as I worked through them. The ASF has multiple header files sometimes under ./drivers and sometimes specific to sam d21. But I think I'm failing to understand the whole process.

I'm not pin compliant with the feather m0 so I really need to compile it :-)

Any chance you could send me a few pointers? Thanks! Fredrik

ericbaril72 commented 6 years ago

Since then, the UF2 bootloader has shown up. Have you checked into it ?

Samd21-Usb as a memory device to your PC, drag and drop your binary ( converted to uf2 format ) and Voila !

If the stand-alone samd21 is your goal, you can start with the makefile of UF2.

I just migrated over to the d51 and will get back to my bootloader only next month. Since I now have access to ++flash, I may drop the FAT and do memory to memory bootloader.

Let me know if the uf2 fits your needs, it may Affect the futur of the sd-bootloader.

Éric

Sent from my mobile

Le 16 juin 2018 à 13:39, frippe75 notifications@github.com a écrit :

Hi Eric,

Also trying to compile your bootloader, which I think is awesome work on your part!

Trying to write a Makefile to get it to compile but I cant work out the details. I downloded the latest asf-standalone-archive and placed it under ./ASF

Then I started with the Makefile from Adafruit SAMD core github repo. And added alot of includes to satisfy each error as I worked through them. The ASF has multiple header files sometimes under ./drivers and sometimes specific to sam d21. But I think I'm failing to understand the whole process.

I'm not pin compliant with the feather m0 so I really need to compile it :-)

Any chance you could send me a few pointers? Thanks! Fredrik

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

frippe75 commented 6 years ago

[frta@fedora24 SAMD21-SDBootloader]$ /home/frta/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc -mthumb -mcpu=cortex-m0plus -w -Wall -c -std=gnu99 -ffunction-sections -fdata-sections -nostdlib -nostartfiles --param max-inline-insns-single=500 -Os -DDEBUG=0 -D__SAMD21G18A__ memories_initialization_sam0.c -o build/memories_initialization_sam0.o -I ./ASF/sam0/utils/ -I ./ASF/common/utils/ -I./ASF/sam0/utils/preprocessor/ -I ./ASF/sam0/utils/header_files/ -I. -I ./ASF/sam0/utils/cmsis/samd21/include/ -I./ASF/thirdparty/CMSIS/Include/ -I./ASF/sam0/utils/cmsis/samd21/source/ -I./ASF/common/services/delay/ -I./ASF/common/services/clock/ -I./config

Getting: In file included from ./ASF/common/services/delay/delay.h:43:0, from asf.h:60, from memories_initialization_sam0.c:44: ./ASF/common/services/clock/sysclk.h:40:24: fatal error: conf_clock.h: No such file or directory

include "conf_clock.h"

Alot of conf_clock.h to chose from. Not sure what to do in the config directory there is a conf_clocks.h

frippe75 commented 6 years ago

Just realized you answered my question. Thanks! No the UF2 does not fit my needs since I will be updating the device offsite using something like a ZigBee. So wirelessly at least. Like the drag and drop for other usecases though! Will try the makefile you suggested!

frippe75 commented 6 years ago

[frta@fedora21 SAMD21-SDBootloader]$ find . -name port.h ./ASF/sam0/utils/cmsis/samd21/include/component/port.h ./ASF/sam0/utils/cmsis/samd21/include/instance/port.h

Unable to find the port.h include. Would that be component or instance?

frippe75 commented 6 years ago

I kind of gave up. Tried installing Atmel Studio. Opened up the samd21 example which compiled without an issue. Looked at the services and ASF components and launched a new project and added the same. Then moved in the code from this github repo. No success. complaining on missing samd21.h even though i setup a board with the d21.... Too bad you didn't saved the project setup. Tried exporting the samd20 Makefile and reworked it. I think my issue is that Atmel has the files structured in a way that does not match what's get layed out in the project directory. Making it hard to move files into place manually.

So my option now is to make my board more pin comliant with the feather and take it from there. Just feels like a longer route than changing the SPI pin mapping and recompiling :-)

ericbaril72 commented 6 years ago

You are darn right about AS when you get into the “makefile” stuff. It’s a bit of a pain.

Even with the project, it may not have worked as I changed a lot of stuff back then and didn’t quite master it.

When trying the UF2 bootloader, it compiled and worked right away on Ubuntu. And the makefile is way easier to read.

I am not yet going back on the sd-bootloader as of yet but will be within the next month. Éric

Sent from my mobile

Le 17 juin 2018 à 14:20, frippe75 notifications@github.com a écrit :

I kind of gave up. Tried installing Atmel Studio. Opened up the samd21 example which compiled without an issue. Looked at the services and ASF components and launched a new project and added the same. Then moved in the code from this github repo. No success. complaining on missing samd21.h even though i setup a board with the d21.... Too bad you didn't saved the project setup. Tried exporting the samd20 Makefile and reworked it. I think my issue is that Atmel has the files structured in a way that does not match what's get layed out in the project directory. Making it hard to move files into place manually.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

frippe75 commented 6 years ago

Ohh. Finally was able to compile your modified bootloader... With and without serial. Only thing is that your precompiled (../build/..) one turns on my led (PA06) but the one I compiled using your conf-files does not. Will try to figure that one out but thinking you might have some insights to that?

I have my LED0_PIN defined in user_board.h and it's set to PIN_PA06 (which is the value 6). Checked it via "Goto implementation".

Thanks! Fredrik