Skip to content

Commit b754ecb

Browse files
committed
Replicate the wormhole in the bootloader and make it jump to the application if it's open and the enumeration mode is anything but EnumerationMode_Bootloader.
1 parent cbc16f4 commit b754ecb

5 files changed

Lines changed: 60 additions & 2 deletions

File tree

src/bootloader/src/bl_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "property/property.h"
4545
#include "utilities/vector_table_info.h"
4646
#include "utilities/fsl_rtos_abstraction.h"
47+
#include "bootloader/wormhole.h"
4748
#if BL_FEATURE_CRC_CHECK
4849
#include "bootloader/bl_app_crc_check.h"
4950
#endif
@@ -321,7 +322,7 @@ static peripheral_descriptor_t const *get_active_peripheral(void)
321322
{
322323
if (is_direct_boot())
323324
{
324-
if (RCM->SRS0 & RCM_SRS0_POR_MASK) {
325+
if (RCM->SRS0 & RCM_SRS0_POR_MASK || (IS_WORMHOLE_OPEN && Wormhole.enumerationMode != EnumerationMode_Bootloader)) {
325326
jump_to_application(applicationAddress, stackPointer);
326327
}
327328
}

src/bootloader/src/wormhole.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "bootloader/wormhole.h"
2+
3+
wormhole_t __attribute__ ((used, section (".noinit"))) Wormhole;

src/bootloader/wormhole.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef __WORMHOLE_H__
2+
#define __WORMHOLE_H__
3+
4+
// Includes:
5+
6+
#include <stdint.h>
7+
8+
// Macros:
9+
10+
#define WORMHOLE_MAGIC_NUMBER 0x3b04cd9e94521f9a
11+
#define IS_WORMHOLE_OPEN (Wormhole.magicNumber == WORMHOLE_MAGIC_NUMBER)
12+
13+
// Typedefs:
14+
15+
typedef enum {
16+
EnumerationMode_Bootloader,
17+
EnumerationMode_BusPal,
18+
EnumerationMode_NormalKeyboard,
19+
EnumerationMode_CompatibleKeyboard,
20+
} enumeration_mode_t;
21+
22+
typedef struct {
23+
uint64_t magicNumber;
24+
uint8_t enumerationMode;
25+
uint16_t timeoutMs;
26+
} wormhole_t;
27+
28+
// Variables:
29+
30+
extern wormhole_t __attribute__ ((section (".noinit"))) Wormhole;
31+
32+
#endif

targets/MK22F51212/kds/freedom_bootloader/.project

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@
215215
<type>2</type>
216216
<locationURI>virtual:/virtual</locationURI>
217217
</link>
218+
<link>
219+
<name>src/bootloader/wormhole.h</name>
220+
<type>1</type>
221+
<locationURI>PARENT-4-PROJECT_LOC/src/bootloader/wormhole.h</locationURI>
222+
</link>
218223
<link>
219224
<name>src/crc/crc16.h</name>
220225
<type>1</type>
@@ -445,6 +450,11 @@
445450
<type>1</type>
446451
<locationURI>PARENT-4-PROJECT_LOC/src/bootloader/src/usb_hid_msc_peripheral_interface.c</locationURI>
447452
</link>
453+
<link>
454+
<name>src/bootloader/src/wormhole.c</name>
455+
<type>1</type>
456+
<locationURI>PARENT-4-PROJECT_LOC/src/bootloader/src/wormhole.c</locationURI>
457+
</link>
448458
<link>
449459
<name>src/crc/src/crc16.c</name>
450460
<type>1</type>

targets/common/linker/kds/MK22F51212/MK22FN512xxx12_application_0x0000.ld

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ MEMORY
6161
m_interrupts (RX) : ORIGIN = 0x00000000, LENGTH = 0x00000400
6262
m_flash_config (RX) : ORIGIN = 0x00000400, LENGTH = 0x00000010
6363
m_text (RX) : ORIGIN = 0x00000410, LENGTH = 0x0007FBF0
64-
m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x00020000
64+
m_data (RW) : ORIGIN = 0x1FFF0000, LENGTH = 0x0001FF00
65+
m_noinit (RW) : ORIGIN = 0x2000FF00, LENGTH = 0x00000100
6566
}
6667

6768
/* Define output sections */
@@ -255,5 +256,16 @@ SECTIONS
255256
.ARM.attributes 0 : { *(.ARM.attributes) }
256257

257258
ASSERT(__StackLimit >= __HeapLimit, "region m_data_2 overflowed with stack and heap")
259+
260+
.noinit (NOLOAD):
261+
{
262+
. = ALIGN(4);
263+
_noinit = .;
264+
265+
*(.noinit .noinit.*)
266+
267+
. = ALIGN(4) ;
268+
_end_noinit = .;
269+
} > m_noinit
258270
}
259271

0 commit comments

Comments
 (0)