Skip to content

Commit b2cc0f5

Browse files
committed
Kinetis KL26 port
1 parent 8c7b864 commit b2cc0f5

9 files changed

Lines changed: 729 additions & 0 deletions

File tree

arch.mk

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,24 @@ ifeq ($(TARGET),kinetis)
775775
endif
776776
endif
777777

778+
ifeq ($(TARGET),kinetis_kl26)
779+
CORTEX_M0=1
780+
CFLAGS+=\
781+
-I$(MCUXPRESSO_DRIVERS) \
782+
-I$(MCUXPRESSO_DRIVERS)/drivers \
783+
-I$(MCUXPRESSO_CMSIS)/Include \
784+
-I$(MCUXPRESSO_CMSIS)/Core/Include
785+
CFLAGS+=\
786+
-DCPU_$(MCUXPRESSO_CPU) -DDEBUG_CONSOLE_ASSERT_DISABLE=1 -DNVM_FLASH_WRITEONCE=1
787+
CFLAGS+=-Wno-old-style-declaration
788+
OBJS+=\
789+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_clock.o \
790+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_flash.o
791+
ifeq ($(DEBUG_UART),1)
792+
OBJS+=$(MCUXPRESSO_DRIVERS)/drivers/fsl_lpsci.o
793+
endif
794+
endif
795+
778796
ifeq ($(TARGET),mcxa)
779797
CORTEX_M33=1
780798
CFLAGS+=\
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
ARCH?=ARM
2+
TARGET?=kinetis_kl26
3+
SIGN?=LMS
4+
HASH?=SHA256
5+
6+
LMS_LEVELS=1
7+
LMS_HEIGHT=20
8+
LMS_WINTERNITZ=8
9+
IMAGE_SIGNATURE_SIZE=1776
10+
# Keytools (sign.c) forces header_sz >= 2 * sig_sz for LMS, so the minimum
11+
# is 3552; round up to the next power of two.
12+
IMAGE_HEADER_SIZE=4096
13+
14+
MCUXSDK?=0
15+
MCUXPRESSO?=$(PWD)/../NXP/SDK_2_2_0_FRDM-KL26Z
16+
MCUXPRESSO_CMSIS?=$(MCUXPRESSO)/CMSIS
17+
MCUXPRESSO_CPU?=MKL26Z128VLH4
18+
MCUXPRESSO_DRIVERS?=$(MCUXPRESSO)/devices/MKL26Z4
19+
DEBUG?=0
20+
VTOR?=1
21+
CORTEX_M0?=1
22+
NO_ASM?=0
23+
EXT_FLASH?=0
24+
SPI_FLASH?=0
25+
ALLOW_DOWNGRADE?=0
26+
NVM_FLASH_WRITEONCE?=1
27+
WOLFBOOT_VERSION?=0
28+
V?=0
29+
SPMATH?=1
30+
RAM_CODE?=0
31+
DUALBANK_SWAP?=0
32+
PKA?=0
33+
DEBUG_UART?=1
34+
35+
# Cortex-M0+ doesn't support unaligned word accesses. WOLFSSL_USE_ALIGN
36+
# routes word-sized hash operations through byte-safe code paths when the
37+
# buffers (e.g. LMS internal hash state) aren't 4-byte aligned.
38+
CFLAGS_EXTRA+=-DWOLFSSL_USE_ALIGN
39+
40+
# Logical sector = 4 KL26 hardware sectors (1KB each). Required because
41+
# IMAGE_HEADER_SIZE (4096) must be <= WOLFBOOT_SECTOR_SIZE.
42+
WOLFBOOT_SECTOR_SIZE?=0x1000
43+
44+
# 128KB flash, 16KB SRAM
45+
# 32KB bootloader, 44KB boot/update partitions, 4KB swap at last logical sector
46+
WOLFBOOT_PARTITION_SIZE?=0xB000
47+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x8000
48+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x13000
49+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x1F000
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ARCH?=ARM
2+
TARGET?=kinetis_kl26
3+
SIGN?=ECC256
4+
HASH?=SHA256
5+
MCUXSDK?=0
6+
MCUXPRESSO?=$(PWD)/../NXP/SDK_2_2_0_FRDM-KL26Z
7+
MCUXPRESSO_CMSIS?=$(MCUXPRESSO)/CMSIS
8+
MCUXPRESSO_CPU?=MKL26Z128VLH4
9+
MCUXPRESSO_DRIVERS?=$(MCUXPRESSO)/devices/MKL26Z4
10+
DEBUG?=0
11+
VTOR?=1
12+
CORTEX_M0?=1
13+
NO_ASM?=0
14+
EXT_FLASH?=0
15+
SPI_FLASH?=0
16+
ALLOW_DOWNGRADE?=0
17+
NVM_FLASH_WRITEONCE?=1
18+
WOLFBOOT_VERSION?=0
19+
V?=0
20+
SPMATH?=1
21+
RAM_CODE?=0
22+
DUALBANK_SWAP?=0
23+
PKA?=0
24+
DEBUG_UART?=1
25+
26+
# Cortex-M0+ doesn't support unaligned word accesses. WOLFSSL_USE_ALIGN
27+
# routes word-sized hash operations through byte-safe code paths when the
28+
# input/output buffers aren't 4-byte aligned.
29+
CFLAGS_EXTRA+=-DWOLFSSL_USE_ALIGN
30+
31+
# 1KB sectors, 4-byte flash write unit
32+
WOLFBOOT_SECTOR_SIZE?=0x400
33+
34+
# 128KB flash, 16KB SRAM
35+
# 24KB bootloader, 48KB boot/update partitions, 1KB swap at last sector
36+
WOLFBOOT_PARTITION_SIZE?=0xC000
37+
WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x6000
38+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x12000
39+
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x1FC00

docs/Targets.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This README describes configuration of supported targets.
2020
* [Nordic nRF54L15](#nordic-nrf54l15)
2121
* [NXP iMX-RT](#nxp-imx-rt)
2222
* [NXP Kinetis](#nxp-kinetis)
23+
* [NXP Kinetis KL26Z](#nxp-kinetis-kl26z)
2324
* [NXP LPC546xx](#nxp-lpc546xx)
2425
* [NXP LPC540xx / LPC54S0xx (SPIFI boot)](#nxp-lpc540xx--lpc54s0xx-spifi-boot)
2526
* [NXP LPC55S69](#nxp-lpc55s69)
@@ -4259,6 +4260,155 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0xff000
42594260
```
42604261

42614262

4263+
## NXP Kinetis KL26Z
4264+
4265+
NXP MKL26Z128 is a Cortex-M0+ microcontroller running at 48MHz with 128 KB
4266+
flash and 16 KB SRAM. The support has been tested using the FRDM-KL26Z board
4267+
with the onboard OpenSDA debugger reflashed to Segger J-Link firmware.
4268+
4269+
The TARGET is `kinetis_kl26`, separate from the `kinetis` target used for
4270+
K64/K82 because the KL26 silicon ships a different flash driver family
4271+
(legacy `fsl_flash.c`, no FTFx cache, no SYSMPU) and a different memory map.
4272+
4273+
Two example configurations are provided:
4274+
4275+
- `config/examples/kinetis-kl26.config` &mdash; **ECC256** with SHA-256.
4276+
- `config/examples/kinetis-kl26-lms.config` &mdash; **LMS** post-quantum
4277+
signatures (parameters L=1, H=20, W=8, SHA-256).
4278+
4279+
Both produce a working bootloader for the FRDM-KL26Z; pick the one matching
4280+
your signature scheme. The two configs use different partition layouts (the
4281+
LMS variant trades a larger bootloader region and partition header for the
4282+
bigger PQ signature), so the addresses in the steps below differ between
4283+
them.
4284+
4285+
This requires the legacy NXP MCUXpresso SDK 2.2 for FRDM-KL26Z, generated and
4286+
downloaded from the [MCUXpresso SDK Builder](https://mcuxpresso.nxp.com/)
4287+
(select the board, then build and download the SDK package). The extracted
4288+
archive should be placed into `../NXP/SDK_2_2_0_FRDM-KL26Z` by default (see
4289+
.config or set with `MCUXPRESSO`).
4290+
4291+
### KL26Z: Configuring and compiling
4292+
4293+
Copy one of the example configuration files and build with make:
4294+
4295+
```sh
4296+
# ECC256 variant
4297+
cp config/examples/kinetis-kl26.config .config
4298+
4299+
# LMS variant
4300+
cp config/examples/kinetis-kl26-lms.config .config
4301+
4302+
make
4303+
```
4304+
4305+
### KL26Z: Loading the firmware
4306+
4307+
The FRDM-KL26Z board ships with the PEMicro OpenSDA firmware on the K20 debug
4308+
chip. Reflash it once with Segger's board-specific J-Link OpenSDA build:
4309+
4310+
- Download the firmware from
4311+
[Segger's J-Link OpenSDA Board-Specific Firmwares page](https://www.segger.com/downloads/jlink/#JLinkOpenSDABoardSpecificFirmwares).
4312+
- Hold the reset button while plugging in USB so the OpenSDA chip enters its
4313+
bootloader mode (the volume should mount as `BOOTLOADER`).
4314+
- Drop the downloaded firmware file onto the `BOOTLOADER` volume.
4315+
- Replug; the device now enumerates as a Segger J-Link.
4316+
4317+
Use JLinkExe to upload the initial firmware:
4318+
`JLinkExe -if swd -Device MKL26Z128xxx4`
4319+
4320+
At the J-Link prompt, type:
4321+
4322+
```
4323+
unlock kinetis
4324+
loadbin factory.bin 0
4325+
r
4326+
g
4327+
```
4328+
4329+
The `unlock kinetis` step is required after any chip-erase: a blank Kinetis
4330+
flash configuration field reads `0xFF` at offset `0x40C`, which secures the
4331+
chip on next reset and locks out SWD. `unlock kinetis` issues a mass-erase
4332+
through the MDM-AP backdoor that bypasses the secured state.
4333+
4334+
Reset or power cycle the board.
4335+
4336+
Once wolfBoot has performed validation of the partition and booted the v1
4337+
test app, the onboard RGB LED will light up blue.
4338+
4339+
### KL26Z: Testing firmware update
4340+
4341+
1) Sign the test-app as v2 passing appropriate parameters:
4342+
4343+
For the ECC256 variant:
4344+
4345+
```sh
4346+
tools/keytools/sign --ecc256 --sha256 \
4347+
test-app/image.bin wolfboot_signing_private_key.der 2
4348+
```
4349+
4350+
For the LMS variant:
4351+
4352+
```sh
4353+
IMAGE_HEADER_SIZE=4096 \
4354+
LMS_LEVELS=1 LMS_HEIGHT=20 LMS_WINTERNITZ=8 \
4355+
IMAGE_SIGNATURE_SIZE=1776 \
4356+
tools/keytools/sign --lms --sha256 \
4357+
test-app/image.bin wolfboot_signing_private_key.der 2
4358+
```
4359+
4360+
Either command produces `test-app/image_v2_signed.bin`.
4361+
4362+
2) Create a bin footer with the wolfBoot trailer "pBOOT" to manually trigger
4363+
an update:
4364+
4365+
```sh
4366+
echo -n "pBOOT" > trigger_magic.bin
4367+
```
4368+
4369+
3) Assemble the update partition image. The trigger offset is
4370+
`WOLFBOOT_PARTITION_SIZE - 5`.
4371+
4372+
For the ECC256 variant (partition size `0xC000`):
4373+
4374+
```sh
4375+
./tools/bin-assemble/bin-assemble \
4376+
update.bin \
4377+
0x0 test-app/image_v2_signed.bin \
4378+
0xBFFB trigger_magic.bin
4379+
```
4380+
4381+
For the LMS variant (partition size `0xB000`):
4382+
4383+
```sh
4384+
./tools/bin-assemble/bin-assemble \
4385+
update.bin \
4386+
0x0 test-app/image_v2_signed.bin \
4387+
0xAFFB trigger_magic.bin
4388+
```
4389+
4390+
4) Flash `update.bin` to the update partition base address and reset. On the
4391+
next boot wolfBoot will perform the update and launch version 2. The test app
4392+
will then light up the onboard LED green instead of blue.
4393+
4394+
- ECC256 variant: `loadbin update.bin 0x12000`
4395+
- LMS variant: `loadbin update.bin 0x13000`
4396+
4397+
### KL26Z: Debugging
4398+
4399+
To debug with JLink:
4400+
4401+
In one terminal: `JLinkGDBServer -if swd -Device MKL26Z128xxx4 -port 3333`
4402+
4403+
In another terminal use `gdb`:
4404+
4405+
```
4406+
b main
4407+
mon reset
4408+
c
4409+
```
4410+
4411+
42624412
## NXP QorIQ P1021 PPC
42634413

42644414
The NXP QorIQ P1021 is a PPC e500v2 based processor (two cores). This has been tested with a NAND boot source.

0 commit comments

Comments
 (0)