Add support for updating sketches from an SD card
Via 2nd stage boot code that checks SD card for UPDATE.bin
This commit is contained in:
parent
96745cd48d
commit
a15d190ada
16 changed files with 3776 additions and 3 deletions
|
|
@ -240,13 +240,13 @@ void SERCOM::enableSPI()
|
|||
|
||||
void SERCOM::disableSPI()
|
||||
{
|
||||
//Setting the enable bit to 0
|
||||
sercom->SPI.CTRLA.bit.ENABLE = 0;
|
||||
|
||||
while(sercom->SPI.SYNCBUSY.bit.ENABLE)
|
||||
{
|
||||
//Waiting then enable bit from SYNCBUSY is equal to 0;
|
||||
}
|
||||
|
||||
//Setting the enable bit to 0
|
||||
sercom->SPI.CTRLA.bit.ENABLE = 0;
|
||||
}
|
||||
|
||||
void SERCOM::setDataOrderSPI(SercomDataOrder dataOrder)
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@
|
|||
"packager": "arduino",
|
||||
"name": "CMSIS-Atmel",
|
||||
"version": "1.1.0"
|
||||
},
|
||||
{
|
||||
"packager": "arduino",
|
||||
"name": "arduinoOTA",
|
||||
"version": "1.1.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@
|
|||
"packager": "arduino",
|
||||
"name": "CMSIS-Atmel",
|
||||
"version": "1.1.0"
|
||||
},
|
||||
{
|
||||
"packager": "arduino",
|
||||
"name": "arduinoOTA",
|
||||
"version": "1.1.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
92
libraries/SDU/extras/SDUBoot/SDUBoot.ino
Normal file
92
libraries/SDU/extras/SDUBoot/SDUBoot.ino
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
Copyright (c) 2017 Arduino LLC. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <SD.h>
|
||||
#include <FlashStorage.h>
|
||||
|
||||
#define SDU_START 0x2000
|
||||
#define SDU_SIZE 0x4000
|
||||
|
||||
#define SKETCH_START (uint32_t*)(SDU_START + SDU_SIZE)
|
||||
|
||||
#ifndef SDCARD_SS_PIN
|
||||
#define SDCARD_SS_PIN 4
|
||||
#endif
|
||||
|
||||
#define UPDATE_FILE "UPDATE.BIN"
|
||||
|
||||
FlashClass flash;
|
||||
|
||||
// Initialize C library
|
||||
extern "C" void __libc_init_array(void);
|
||||
|
||||
int main() {
|
||||
init();
|
||||
|
||||
__libc_init_array();
|
||||
|
||||
delay(1);
|
||||
|
||||
if (SD.begin(SDCARD_SS_PIN) && SD.exists(UPDATE_FILE)) {
|
||||
File updateFile = SD.open(UPDATE_FILE);
|
||||
uint32_t updateSize = updateFile.size();
|
||||
bool updateFlashed = false;
|
||||
|
||||
if (updateSize > SDU_SIZE) {
|
||||
// skip the SDU section
|
||||
updateFile.seek(SDU_SIZE);
|
||||
updateSize -= SDU_SIZE;
|
||||
|
||||
uint32_t flashAddress = (uint32_t)SKETCH_START;
|
||||
|
||||
// erase the pages
|
||||
flash.erase((void*)flashAddress, updateSize);
|
||||
|
||||
uint8_t buffer[512];
|
||||
|
||||
// write the pages
|
||||
for (uint32_t i = 0; i < updateSize; i += sizeof(buffer)) {
|
||||
updateFile.read(buffer, sizeof(buffer));
|
||||
|
||||
flash.write((void*)flashAddress, buffer, sizeof(buffer));
|
||||
|
||||
flashAddress += sizeof(buffer);
|
||||
}
|
||||
|
||||
updateFlashed = true;
|
||||
}
|
||||
|
||||
updateFile.close();
|
||||
|
||||
if (updateFlashed) {
|
||||
SD.remove(UPDATE_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
// jump to the sketch
|
||||
__set_MSP(*SKETCH_START);
|
||||
|
||||
//Reset vector table address
|
||||
SCB->VTOR = ((uint32_t)(SKETCH_START) & SCB_VTOR_TBLOFF_Msk);
|
||||
|
||||
// address of Reset_Handler is written by the linker at the beginning of the .text section (see linker script)
|
||||
uint32_t resetHandlerAddress = (uint32_t) * (SKETCH_START + 1);
|
||||
// jump to reset handler
|
||||
asm("bx %0"::"r"(resetHandlerAddress));
|
||||
}
|
||||
|
||||
26
libraries/SDU/extras/SDUBoot/build.sh
Executable file
26
libraries/SDU/extras/SDUBoot/build.sh
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/sh -x
|
||||
|
||||
ARDUINO=arduino
|
||||
SKETCH_NAME="SDUBoot.ino"
|
||||
SKETCH="$PWD/$SKETCH_NAME"
|
||||
BUILD_PATH="$PWD/build"
|
||||
OUTPUT_PATH="../../src/boot"
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
ARDUINO="/Applications/Arduino.app/Contents/MacOS/Arduino"
|
||||
fi
|
||||
|
||||
buildSDUBootSketch() {
|
||||
BOARD=$1
|
||||
DESTINATION=$2
|
||||
|
||||
$ARDUINO --verify --board $BOARD --preserve-temp-files --pref build.path="$BUILD_PATH" $SKETCH
|
||||
cat "$BUILD_PATH/$SKETCH_NAME.bin" | xxd -i > $DESTINATION
|
||||
rm -rf "$BUILD_PATH"
|
||||
}
|
||||
|
||||
mkdir -p "$OUTPUT_PATH"
|
||||
|
||||
buildSDUBootSketch "arduino:samd:arduino_zero_edbg" "$OUTPUT_PATH/zero.h"
|
||||
buildSDUBootSketch "arduino:samd:mkr1000" "$OUTPUT_PATH/mkr1000.h"
|
||||
buildSDUBootSketch "arduino:samd:mkrzero" "$OUTPUT_PATH/mkrzero.h"
|
||||
19
libraries/SDU/keywords.txt
Normal file
19
libraries/SDU/keywords.txt
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#######################################
|
||||
# Syntax Coloring Map For SDU
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
SDU KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
reset KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
9
libraries/SDU/library.properties
Normal file
9
libraries/SDU/library.properties
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
name=SDU
|
||||
version=1.0.0
|
||||
author=Arduino
|
||||
maintainer=Arduino <info@arduino.cc>
|
||||
sentence=Update the sketch on your board from an SD card
|
||||
paragraph=Requires an SD card
|
||||
category=Other
|
||||
url=http://www.arduino.cc/en/Reference/SDU
|
||||
architectures=samd
|
||||
46
libraries/SDU/src/SDU.cpp
Normal file
46
libraries/SDU/src/SDU.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
Copyright (c) 2017 Arduino LLC. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "SDU.h"
|
||||
|
||||
__attribute__ ((section(".sketch_boot")))
|
||||
unsigned char sduBoot[0x4000] = {
|
||||
#if defined(ARDUINO_SAMD_ZERO)
|
||||
#include "boot/zero.h"
|
||||
#elif defined(ARDUINO_SAMD_MKR1000)
|
||||
#include "boot/mkr1000.h"
|
||||
#elif defined(ARDUINO_SAMD_MKRZERO)
|
||||
#include "boot/mkrzero.h"
|
||||
#else
|
||||
#error "Unsupported board!"
|
||||
#endif
|
||||
};
|
||||
|
||||
SDUClass::SDUClass() {
|
||||
}
|
||||
|
||||
void SDUClass::reset() {
|
||||
// Reset the device
|
||||
NVIC_SystemReset() ;
|
||||
|
||||
while (true);
|
||||
}
|
||||
|
||||
SDUClass SDU;
|
||||
31
libraries/SDU/src/SDU.h
Normal file
31
libraries/SDU/src/SDU.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
Copyright (c) 2017 Arduino LLC. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _SDU_H_INCLUDED
|
||||
#define _SDU_H_INCLUDED
|
||||
|
||||
class SDUClass {
|
||||
public:
|
||||
SDUClass();
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
extern SDUClass SDU;
|
||||
|
||||
#endif
|
||||
1192
libraries/SDU/src/boot/mkr1000.h
Normal file
1192
libraries/SDU/src/boot/mkr1000.h
Normal file
File diff suppressed because it is too large
Load diff
1192
libraries/SDU/src/boot/mkrzero.h
Normal file
1192
libraries/SDU/src/boot/mkrzero.h
Normal file
File diff suppressed because it is too large
Load diff
1141
libraries/SDU/src/boot/zero.h
Normal file
1141
libraries/SDU/src/boot/zero.h
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -141,6 +141,9 @@ tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.
|
|||
|
||||
tools.bossac_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
|
||||
|
||||
tools.bossac.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.bossac.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
#
|
||||
# OpenOCD sketch upload
|
||||
#
|
||||
|
|
@ -153,6 +156,9 @@ tools.openocd.upload.params.verbose=-d2
|
|||
tools.openocd.upload.params.quiet=-d0
|
||||
tools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{{build.path}/{build.project_name}.bin}} verify reset 0x2000; shutdown"
|
||||
|
||||
tools.openocd.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
|
||||
tools.openocd.upload.network_pattern={network_cmd} -address {serial.port} -port 65280 -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
|
||||
|
||||
# Program flashes the binary at 0x0000, so use the linker script without_bootloader
|
||||
tools.openocd.program.params.verbose=-d2
|
||||
tools.openocd.program.params.quiet=-d0
|
||||
|
|
|
|||
|
|
@ -67,6 +67,9 @@ SECTIONS
|
|||
{
|
||||
__text_start__ = .;
|
||||
|
||||
KEEP(*(.sketch_boot))
|
||||
|
||||
. = ALIGN(0x2000);
|
||||
KEEP(*(.isr_vector))
|
||||
*(.text*)
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,9 @@ SECTIONS
|
|||
{
|
||||
__text_start__ = .;
|
||||
|
||||
KEEP(*(.sketch_boot))
|
||||
|
||||
. = ALIGN(0x2000);
|
||||
KEEP(*(.isr_vector))
|
||||
*(.text*)
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,9 @@ SECTIONS
|
|||
{
|
||||
__text_start__ = .;
|
||||
|
||||
KEEP(*(.sketch_boot))
|
||||
|
||||
. = ALIGN(0x2000);
|
||||
KEEP(*(.isr_vector))
|
||||
*(.text*)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue