File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,5 +18,10 @@ USEMODULE += boards_common_silabs
1818USEMODULE += silabs_aem
1919USEMODULE += silabs_bc
2020
21+ # configure riotboot slots
22+ export RIOTBOOT_SLOT0_SIZE ?= 0x4000
23+ export RIOTBOOT_SLOT1_SIZE ?= 0x1e000
24+ export RIOTBOOT_SLOT2_SIZE ?= 0x1e000
25+
2126# include board common
2227include $(RIOTBOARD)/common/silabs/Makefile.include
Original file line number Diff line number Diff line change @@ -18,5 +18,10 @@ USEMODULE += boards_common_silabs
1818USEMODULE += silabs_aem
1919USEMODULE += silabs_bc
2020
21+ # configure riotboot slots
22+ export RIOTBOOT_SLOT0_SIZE ?= 0x4000
23+ export RIOTBOOT_SLOT1_SIZE ?= 0x7e000
24+ export RIOTBOOT_SLOT2_SIZE ?= 0x7e000
25+
2126# include board common
2227include $(RIOTBOARD)/common/silabs/Makefile.include
Original file line number Diff line number Diff line change 5050#define EMU_EM4INIT EMU_EM4INIT_DEFAULT
5151#endif
5252
53+ #ifndef BOOTLOADER
54+
5355#ifdef _SILICON_LABS_32B_SERIES_1
5456/**
5557 * @brief Initialize integrated DC-DC regulator
@@ -149,14 +151,20 @@ static void pm_init(void)
149151#endif
150152}
151153
154+ #endif
155+
152156void cpu_init (void )
153157{
158+ #ifndef BOOTLOADER
154159 /* apply errata that may be applicable (see em_chip.h) */
155160 CHIP_Init ();
161+ #endif
156162
157163 /* initialize the Cortex-M core */
158164 cortexm_init ();
159165
166+ #ifndef BOOTLOADER
167+
160168#ifdef _SILICON_LABS_32B_SERIES_1
161169 /* initialize dc-dc */
162170 dcdc_init ();
@@ -165,9 +173,11 @@ void cpu_init(void)
165173 /* initialize clock sources and generic clocks */
166174 clk_init ();
167175
176+
168177 /* initialize power management interface */
169178 pm_init ();
170179
171180 /* trigger static peripheral initialization */
172181 periph_init ();
182+ #endif
173183}
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ BOARD ?= samr21-xpro
44
55USEMODULE += firmware
66
7- CFLAGS += -DNDEBUG -DLOG_LEVEL=LOG_NONE
7+ CFLAGS += -DNDEBUG -DLOG_LEVEL=LOG_NONE -DBOOTLOADER
88DISABLE_MODULE += auto_init
99
1010RIOTBASE ?= $(CURDIR ) /../..
Original file line number Diff line number Diff line change 2020 * @}
2121 */
2222
23+ #include <stdio.h>
24+
2325#include "firmware.h"
2426#include "cpu.h"
2527#include "panic.h"
@@ -29,26 +31,40 @@ void kernel_init(void)
2931 uint32_t version = 0 ;
3032 uint32_t slot = 0 ;
3133
34+ puts ("Booting" );
35+
3236 /* skip slot 0 (which points to the bootloader) */
3337 for (unsigned i = 1 ; i < firmware_num_slots ; i ++ ) {
3438 firmware_metadata_t * slot_metadata = firmware_get_metadata (i );
35- if (firmware_validate_metadata_checksum (slot_metadata )) {
39+
40+ uint32_t start = firmware_get_image_startaddr (i );
41+ printf ("start is %08lx\n" , start );
42+
43+ //if (firmware_validate_metadata_checksum(slot_metadata)) {
44+ // puts("broken");
3645 /* skip slot if metadata broken */
37- continue ;
38- }
46+ // continue;
47+ //}*/
3948 if (slot_metadata -> start_addr != firmware_get_image_startaddr (i )) {
49+ puts ("mism" );
4050 continue ;
4151 }
52+
4253 if (!slot || slot_metadata -> version > version ) {
4354 version = slot_metadata -> version ;
4455 slot = i ;
56+ break ;
4557 }
4658 }
4759
60+ printf ("Booting slot %ld\n" , slot );
61+
4862 if (slot ) {
4963 firmware_jump_to_slot (slot );
5064 }
5165
66+ puts ("trouble" );
67+
5268 /* serious trouble! */
5369 while (1 ) {}
5470}
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ int verify(int argc, char *argv[])
3636 return 1 ;
3737 }
3838
39- int res = firmware_simple_validate_signature (& metadata , pubkey ) ? 1 : 0 ;
39+ int res = firmware_simple_validate (& metadata , pubkey ) ? 1 : 0 ;
4040 if (res ) {
4141 printf ("signature check failed\n" );
4242 return -1 ;
Original file line number Diff line number Diff line change @@ -7,6 +7,12 @@ BOARD ?= native
77# This has to be the absolute path to the RIOT base directory:
88RIOTBASE ?= $(CURDIR ) /../..
99
10+ # Signature verification needs quite a lot of stack
11+ CFLAGS += "-DTHREAD_STACKSIZE_MAIN=((6*THREAD_STACKSIZE_DEFAULT)+THREAD_EXTRA_STACKSIZE_PRINTF)"
12+
13+ USEMODULE += ota_coap
14+ USEMODULE += firmware
15+
1016# Comment this out to disable code in RIOT that does safety checking
1117# which is not needed in a production environment but helps in the
1218# development process:
Original file line number Diff line number Diff line change 2121
2222#include <stdio.h>
2323
24+ #include "firmware.h"
25+ #include "firmware/simple.h"
26+
2427int main (void )
2528{
29+ /* print some information about the running image */
30+ unsigned current_slot = firmware_current_slot ();
31+ firmware_metadata_t * metadata = firmware_get_metadata (current_slot );
32+
33+ printf ("firmware: running from slot %u\n" , current_slot );
34+ firmware_simple_print ((firmware_simple_t * )metadata );
35+
36+
2637 puts ("Hello World!" );
2738
2839 printf ("You are running RIOT on a(n) %s board.\n" , RIOT_BOARD );
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ $(BINDIR)/$(APPLICATION)-slot2.elf: OFFSET=$(SLOT2_OFFSET)
3737$(BINDIR ) /$(APPLICATION ) -slot2.elf : LENGTH=$(SLOT2_LENGTH )
3838
3939# signing targets
40- $(BINDIR ) /$(APPLICATION ) -% .bin :
40+ $(BINDIR ) /$(APPLICATION ) -slot1 .bin :
4141 @echo " creating $@ ..."
4242 $(Q ) $(OBJCOPY ) -Obinary $< $@ .tmp
4343 $(Q ) $(FIRMWARE_TOOL ) sign $@ .tmp $(APP_VER ) $(APP_ID ) $(OFFSET ) $(RIOTBOOT_SECKEY ) - > $@
Original file line number Diff line number Diff line change 3131#else
3232#include <stdio.h>
3333#define LOG_INFO (...) printf(__VA_ARGS__)
34+ #define LOG_WARNING (...) printf(__VA_ARGS__)
3435#endif
3536
3637#include "firmware.h"
3738#include "firmware/simple.h"
3839
40+ #ifdef RIOT_VERSION
3941static inline size_t min (size_t a , size_t b )
4042{
4143 return a <= b ? a : b ;
4244}
45+ #endif
4346
4447void firmware_simple_print (firmware_simple_t * simple )
4548{
@@ -68,6 +71,7 @@ void firmware_simple_print(firmware_simple_t *simple)
6871 }
6972}
7073
74+ #ifdef RIOT_VERSION
7175int firmware_simple_validate_size (firmware_simple_update_t * simple )
7276{
7377 if (simple -> m .metadata .size <= firmware_flashwrite_slotsize (& simple -> writer )) {
@@ -77,6 +81,7 @@ int firmware_simple_validate_size(firmware_simple_update_t *simple)
7781 return -1 ;
7882 }
7983}
84+ #endif
8085
8186int firmware_simple_validate (firmware_simple_t * simple , const unsigned char * pk )
8287{
You can’t perform that action at this time.
0 commit comments