Skip to content

Commit

Permalink
put firmware headers on during the build
Browse files Browse the repository at this point in the history
  • Loading branch information
keepkeyjon committed Apr 30, 2019
1 parent 5042b0b commit 87b9ebb
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 15 deletions.
3 changes: 2 additions & 1 deletion tools/blupdater/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ if(NOT ${KK_EMULATOR})
main.c
startup.s
../bootloader/bl_mpu.c
../bootloader/isr.s)
../bootloader/isr.s
header.s)

include_directories(
${CMAKE_SOURCE_DIR}/include
Expand Down
17 changes: 10 additions & 7 deletions tools/blupdater/blupdater.ld
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MEMORY
{
/* blupdater ROM */
rom (rx) : ORIGIN = 0x08060100, LENGTH = 0x00100000 - 0x00060100
rom (rx) : ORIGIN = 0x08060000, LENGTH = 0x00100000 - 0x00060000

/* ram shared by bootloader and firmware, contains msp (blupdater does not use psp) */
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x0001FF00
Expand All @@ -14,6 +14,12 @@ MEMORY
comram (rwx) : ORIGIN = 0x2001FF00, LENGTH = 0x100
}

SECTIONS
{
.header : ALIGN(4) {
KEEP(*(.header));
} >rom AT >rom
}
INCLUDE libopencm3_stm32f2.ld

SECTIONS
Expand All @@ -35,7 +41,7 @@ _comram_end = ORIGIN(comram) + LENGTH(comram);
/* potential bootloader/firmware isr vector changes. */

/* this is the msp for the blupdater. Make stacks 8-byte aligned. */
_stack = _ram_end - 24;
_stack = _ram_end - 24;
__stack_chk_guard = _ram_end - 24;

/* statics needed for the blupdater */
Expand All @@ -51,13 +57,10 @@ _mmhusr_isr = _comram_end - 24;
_param_3 = _comram_end - 20;
_param_2 = _comram_end - 16;
_param_1 = _comram_end - 12;
_timerusr_isr = _comram_end - 8;
_timerusr_isr = _comram_end - 8;
_buttonusr_isr = _comram_end - 4;


_data_size = SIZEOF(.data);





_codelen = SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.ARM.exidx) + SIZEOF(.version);
18 changes: 18 additions & 0 deletions tools/blupdater/header.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.syntax unified

.section .header, "a"

.type g_header, %object
.size g_header, .-g_header

g_header:
.byte 'K','P','K','Y'
.word _codelen
.byte 0 // sigindex1
.byte 0 // sigindex2
.byte 0 // sigindex3
.byte 3 // flags: Preserve | UpdateAfter
. = . + 52 // reserved
. = . + 64 // sig1
. = . + 64 // sig2
. = . + 64 // sig3
3 changes: 2 additions & 1 deletion tools/firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ if(NOT ${KK_EMULATOR})
keepkey_main.c
startup.s
../bootloader/bl_mpu.c
../bootloader/isr.s)
../bootloader/isr.s
header.s)

include_directories(
${CMAKE_SOURCE_DIR}/include
Expand Down
18 changes: 18 additions & 0 deletions tools/firmware/header.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.syntax unified

.section .header, "a"

.type g_header, %object
.size g_header, .-g_header

g_header:
.byte 'K','P','K','Y'
.word _codelen
.byte 0 // sigindex1
.byte 0 // sigindex2
.byte 0 // sigindex3
.byte 1 // flags: Preserve
. = . + 52 // reserved
. = . + 64 // sig1
. = . + 64 // sig2
. = . + 64 // sig3
17 changes: 11 additions & 6 deletions tools/firmware/keepkey.ld
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MEMORY
{
/* Firmware ROM */
rom (rx) : ORIGIN = 0x08060100, LENGTH = 0x00100000 - 0x00060100
rom (rx) : ORIGIN = 0x08060000, LENGTH = 0x00100000 - 0x00060000

/* ram shared by bootloader and firmware, contains psp */
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x1F800
Expand All @@ -24,6 +24,10 @@ SECTIONS
*(confidential)
ASSERT ((SIZEOF(.confidential) <= 32K), "Error: Confidential section too large");
} >ram

.header : ALIGN(4) {
KEEP(*(.header));
} >rom AT >rom
}

INCLUDE libopencm3_stm32f2.ld
Expand All @@ -40,29 +44,30 @@ _ram_end = ORIGIN(ram) + LENGTH(ram);
_bram_end = ORIGIN(bram) + LENGTH(bram);
_comram_end = ORIGIN(comram) + LENGTH(comram);


/* The following bootloader references can be removed after intermediate releases are completed */
/* protected bootloader statics */
_debug_1 = _bram_end - 16;
_uisr = _bram_end - 12;
button_sp_ctx = _bram_end - 8;
timer_sp_ctx = _bram_end - 4;
timer_sp_ctx = _bram_end - 4;

/* this is a reference to the msp*/
_mspstack = _bram_end - 24;
_mspstack = _bram_end - 24;

/* this is the psp. Make stacks 8-byte aligned. */
_stack = _ram_end - 8;
__stack_chk_guard = _ram_end - 8;
__stack_chk_guard = _ram_end - 8;

/* common block vars to be accessed by both bootloader and firmware */

_mmhusr_isr = _comram_end - 24;
_param_3 = _comram_end - 20;
_param_2 = _comram_end - 16;
_param_1 = _comram_end - 12;
_timerusr_isr = _comram_end - 8;
_timerusr_isr = _comram_end - 8;
_buttonusr_isr = _comram_end - 4;


_data_size = SIZEOF(.data);

_codelen = SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.ARM.exidx) + SIZEOF(.version);

0 comments on commit 87b9ebb

Please sign in to comment.