Skip to content

Commit dc6cfaa

Browse files
mattia-moffadanielinux
authored andcommitted
Kinetis KL26 port
1 parent 6ff19bf commit dc6cfaa

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
@@ -786,6 +786,24 @@ ifeq ($(TARGET),kinetis)
786786
endif
787787
endif
788788

789+
ifeq ($(TARGET),kinetis_kl26)
790+
CORTEX_M0=1
791+
CFLAGS+=\
792+
-I$(MCUXPRESSO_DRIVERS) \
793+
-I$(MCUXPRESSO_DRIVERS)/drivers \
794+
-I$(MCUXPRESSO_CMSIS)/Include \
795+
-I$(MCUXPRESSO_CMSIS)/Core/Include
796+
CFLAGS+=\
797+
-DCPU_$(MCUXPRESSO_CPU) -DDEBUG_CONSOLE_ASSERT_DISABLE=1 -DNVM_FLASH_WRITEONCE=1
798+
CFLAGS+=-Wno-old-style-declaration
799+
OBJS+=\
800+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_clock.o \
801+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_flash.o
802+
ifeq ($(DEBUG_UART),1)
803+
OBJS+=$(MCUXPRESSO_DRIVERS)/drivers/fsl_lpsci.o
804+
endif
805+
endif
806+
789807
ifeq ($(TARGET),mcxa)
790808
CORTEX_M33=1
791809
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)
@@ -4623,6 +4624,155 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0xff000
46234624
```
46244625
46254626
4627+
## NXP Kinetis KL26Z
4628+
4629+
NXP MKL26Z128 is a Cortex-M0+ microcontroller running at 48MHz with 128 KB
4630+
flash and 16 KB SRAM. The support has been tested using the FRDM-KL26Z board
4631+
with the onboard OpenSDA debugger reflashed to Segger J-Link firmware.
4632+
4633+
The TARGET is `kinetis_kl26`, separate from the `kinetis` target used for
4634+
K64/K82 because the KL26 silicon ships a different flash driver family
4635+
(legacy `fsl_flash.c`, no FTFx cache, no SYSMPU) and a different memory map.
4636+
4637+
Two example configurations are provided:
4638+
4639+
- `config/examples/kinetis-kl26.config` &mdash; **ECC256** with SHA-256.
4640+
- `config/examples/kinetis-kl26-lms.config` &mdash; **LMS** post-quantum
4641+
signatures (parameters L=1, H=20, W=8, SHA-256).
4642+
4643+
Both produce a working bootloader for the FRDM-KL26Z; pick the one matching
4644+
your signature scheme. The two configs use different partition layouts (the
4645+
LMS variant trades a larger bootloader region and partition header for the
4646+
bigger PQ signature), so the addresses in the steps below differ between
4647+
them.
4648+
4649+
This requires the legacy NXP MCUXpresso SDK 2.2 for FRDM-KL26Z, generated and
4650+
downloaded from the [MCUXpresso SDK Builder](https://mcuxpresso.nxp.com/)
4651+
(select the board, then build and download the SDK package). The extracted
4652+
archive should be placed into `../NXP/SDK_2_2_0_FRDM-KL26Z` by default (see
4653+
.config or set with `MCUXPRESSO`).
4654+
4655+
### KL26Z: Configuring and compiling
4656+
4657+
Copy one of the example configuration files and build with make:
4658+
4659+
```sh
4660+
# ECC256 variant
4661+
cp config/examples/kinetis-kl26.config .config
4662+
4663+
# LMS variant
4664+
cp config/examples/kinetis-kl26-lms.config .config
4665+
4666+
make
4667+
```
4668+
4669+
### KL26Z: Loading the firmware
4670+
4671+
The FRDM-KL26Z board ships with the PEMicro OpenSDA firmware on the K20 debug
4672+
chip. Reflash it once with Segger's board-specific J-Link OpenSDA build:
4673+
4674+
- Download the firmware from
4675+
[Segger's J-Link OpenSDA Board-Specific Firmwares page](https://www.segger.com/downloads/jlink/#JLinkOpenSDABoardSpecificFirmwares).
4676+
- Hold the reset button while plugging in USB so the OpenSDA chip enters its
4677+
bootloader mode (the volume should mount as `BOOTLOADER`).
4678+
- Drop the downloaded firmware file onto the `BOOTLOADER` volume.
4679+
- Replug; the device now enumerates as a Segger J-Link.
4680+
4681+
Use JLinkExe to upload the initial firmware:
4682+
`JLinkExe -if swd -Device MKL26Z128xxx4`
4683+
4684+
At the J-Link prompt, type:
4685+
4686+
```
4687+
unlock kinetis
4688+
loadbin factory.bin 0
4689+
r
4690+
g
4691+
```
4692+
4693+
The `unlock kinetis` step is required after any chip-erase: a blank Kinetis
4694+
flash configuration field reads `0xFF` at offset `0x40C`, which secures the
4695+
chip on next reset and locks out SWD. `unlock kinetis` issues a mass-erase
4696+
through the MDM-AP backdoor that bypasses the secured state.
4697+
4698+
Reset or power cycle the board.
4699+
4700+
Once wolfBoot has performed validation of the partition and booted the v1
4701+
test app, the onboard RGB LED will light up blue.
4702+
4703+
### KL26Z: Testing firmware update
4704+
4705+
1) Sign the test-app as v2 passing appropriate parameters:
4706+
4707+
For the ECC256 variant:
4708+
4709+
```sh
4710+
tools/keytools/sign --ecc256 --sha256 \
4711+
test-app/image.bin wolfboot_signing_private_key.der 2
4712+
```
4713+
4714+
For the LMS variant:
4715+
4716+
```sh
4717+
IMAGE_HEADER_SIZE=4096 \
4718+
LMS_LEVELS=1 LMS_HEIGHT=20 LMS_WINTERNITZ=8 \
4719+
IMAGE_SIGNATURE_SIZE=1776 \
4720+
tools/keytools/sign --lms --sha256 \
4721+
test-app/image.bin wolfboot_signing_private_key.der 2
4722+
```
4723+
4724+
Either command produces `test-app/image_v2_signed.bin`.
4725+
4726+
2) Create a bin footer with the wolfBoot trailer "pBOOT" to manually trigger
4727+
an update:
4728+
4729+
```sh
4730+
echo -n "pBOOT" > trigger_magic.bin
4731+
```
4732+
4733+
3) Assemble the update partition image. The trigger offset is
4734+
`WOLFBOOT_PARTITION_SIZE - 5`.
4735+
4736+
For the ECC256 variant (partition size `0xC000`):
4737+
4738+
```sh
4739+
./tools/bin-assemble/bin-assemble \
4740+
update.bin \
4741+
0x0 test-app/image_v2_signed.bin \
4742+
0xBFFB trigger_magic.bin
4743+
```
4744+
4745+
For the LMS variant (partition size `0xB000`):
4746+
4747+
```sh
4748+
./tools/bin-assemble/bin-assemble \
4749+
update.bin \
4750+
0x0 test-app/image_v2_signed.bin \
4751+
0xAFFB trigger_magic.bin
4752+
```
4753+
4754+
4) Flash `update.bin` to the update partition base address and reset. On the
4755+
next boot wolfBoot will perform the update and launch version 2. The test app
4756+
will then light up the onboard LED green instead of blue.
4757+
4758+
- ECC256 variant: `loadbin update.bin 0x12000`
4759+
- LMS variant: `loadbin update.bin 0x13000`
4760+
4761+
### KL26Z: Debugging
4762+
4763+
To debug with JLink:
4764+
4765+
In one terminal: `JLinkGDBServer -if swd -Device MKL26Z128xxx4 -port 3333`
4766+
4767+
In another terminal use `gdb`:
4768+
4769+
```
4770+
b main
4771+
mon reset
4772+
c
4773+
```
4774+
4775+
46264776
## NXP QorIQ P1021 PPC
46274777
46284778
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)