forked from skullbox305/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bootloaders/riotboot: add serial bootloader
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Default RIOT bootloader | ||
APPLICATION = riotboot_serial | ||
|
||
# Include serial bootloader functionality | ||
USEMODULE += riotboot_serial | ||
|
||
# RIOT codebase | ||
RIOTBASE ?= $(CURDIR)/../../ | ||
|
||
include $(RIOTBASE)/Makefile.include | ||
|
||
# limit riotboot bootloader size | ||
RIOTBOOT_SERIAL_LEN ?= $(RIOTBOOT_LEN) | ||
ROM_LEN := $(RIOTBOOT_SERIAL_LEN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
BOARD_INSUFFICIENT_MEMORY := \ | ||
phynode-kw41z \ | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (C) 2017 Kaspar Schleiser <[email protected]> | ||
* Inria | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup bootloaders | ||
* @{ | ||
* | ||
* @file | ||
* @brief Serial UART riot-based bootloader | ||
* | ||
* @author Kaspar Schleiser <[email protected]> | ||
* @author Francisco Acosta <[email protected]> | ||
* @author Benjamin Valentin <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include "cpu.h" | ||
#include "panic.h" | ||
#include "riotboot/slot.h" | ||
#include "riotboot/serial.h" | ||
|
||
static int _get_slot(void) | ||
{ | ||
uint32_t version = 0; | ||
int slot = -1; | ||
|
||
if (!IS_USED(MODULE_RIOTBOOT_SLOT)) { | ||
return -1; | ||
} | ||
|
||
for (unsigned i = 0; i < riotboot_slot_numof; i++) { | ||
const riotboot_hdr_t *riot_hdr = riotboot_slot_get_hdr(i); | ||
if (riotboot_slot_validate(i)) { | ||
/* skip slot if metadata broken */ | ||
continue; | ||
} | ||
if (riot_hdr->start_addr != riotboot_slot_get_image_startaddr(i)) { | ||
continue; | ||
} | ||
if (slot == -1 || riot_hdr->version > version) { | ||
version = riot_hdr->version; | ||
slot = i; | ||
} | ||
} | ||
|
||
return slot; | ||
} | ||
|
||
static void _boot_default(int slot) | ||
{ | ||
if (!IS_USED(MODULE_RIOTBOOT_SLOT)) { | ||
/* boot 'raw' firmware image */ | ||
cpu_jump_to_image(SLOT0_OFFSET); | ||
return; | ||
} | ||
|
||
if (slot == -1) { | ||
slot = _get_slot(); | ||
} | ||
|
||
if (slot != -1) { | ||
riotboot_slot_jump(slot); | ||
} | ||
} | ||
|
||
void kernel_init(void) | ||
{ | ||
int slot = -1; | ||
|
||
if (IS_USED(MODULE_RIOTBOOT_SERIAL)) { | ||
slot = riotboot_serial_loader(); | ||
} | ||
|
||
irq_disable(); | ||
_boot_default(slot); | ||
|
||
/* serious trouble! nothing to boot */ | ||
while (1) {} | ||
} | ||
|
||
NORETURN void core_panic(core_panic_t crash_code, const char *message) | ||
{ | ||
(void)crash_code; | ||
(void)message; | ||
while (1) {} | ||
} |