Skip to content

Commit 4d1bf5d

Browse files
committed
Draft support for MCX W71
1 parent 71346b8 commit 4d1bf5d

File tree

6 files changed

+405
-0
lines changed

6 files changed

+405
-0
lines changed

arch.mk

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,40 @@ ifeq ($(TARGET),mcxa)
638638
endif
639639
endif
640640

641+
ifeq ($(TARGET),mcxw)
642+
CORTEX_M33=1
643+
CFLAGS+=\
644+
-I$(MCUXPRESSO_DRIVERS) \
645+
-I$(MCUXPRESSO_DRIVERS)/drivers \
646+
-I$(MCUXPRESSO_DRIVERS)/periph2 \
647+
-I$(MCUXPRESSO)/drivers \
648+
-I$(MCUXPRESSO)/drivers/common \
649+
-I$(MCUXPRESSO_CMSIS)/Include \
650+
-I$(MCUXPRESSO_CMSIS)/Core/Include
651+
CFLAGS+=-DCPU_$(MCUXPRESSO_CPU) -DDEBUG_CONSOLE_ASSERT_DISABLE=1
652+
CFLAGS+=-DWOLFSSL_SP_NO_UMAAL
653+
CFLAGS+=-Wno-old-style-declaration
654+
CFLAGS+=-mcpu=cortex-m33 -DCORTEX_M33 -U__ARM_FEATURE_DSP
655+
LDFLAGS+=-mcpu=cortex-m33
656+
OBJS+=\
657+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_clock.o \
658+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_spc.o \
659+
$(MCUXPRESSO_DRIVERS)/project_template/clock_config.o \
660+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_ccm32k.o \
661+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_romapi.o
662+
663+
ifeq ($(MCUXSDK),1)
664+
CFLAGS+=\
665+
-I$(MCUXPRESSO)/drivers/flash \
666+
-I$(MCUXPRESSO)/drivers/sysmpu \
667+
-I$(MCUXPRESSO)/drivers/ltc \
668+
-I$(MCUXPRESSO)/drivers/port \
669+
-I$(MCUXPRESSO)/drivers/gpio
670+
671+
else
672+
endif
673+
endif
674+
641675
ifeq ($(TARGET),imx_rt)
642676
CFLAGS+=\
643677
-I$(MCUXPRESSO_DRIVERS) \

hal/mcxw.c

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/* mcxw.c
2+
*
3+
* Stubs for custom HAL implementation. Defines the
4+
* functions used by wolfboot for a specific target.
5+
*
6+
* Copyright (C) 2025 wolfSSL Inc.
7+
*
8+
* This file is part of wolfBoot.
9+
*
10+
* wolfBoot is free software; you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation; either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* wolfBoot is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program; if not, write to the Free Software
22+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
23+
*/
24+
25+
#include <stdint.h>
26+
#include <target.h>
27+
#include "image.h"
28+
/* FSL includes */
29+
#include "fsl_common.h"
30+
31+
/* Clock + RAM voltage settings */
32+
#include "fsl_clock.h"
33+
#include "fsl_spc.h"
34+
35+
/* Flash driver */
36+
#include "fsl_device_registers.h"
37+
#include "fsl_lpspi_flash.h"
38+
#include "fsl_k4_flash.h"
39+
40+
/*!< Core clock frequency: 48000000Hz */
41+
#define BOARD_BOOTCLOCKRUN_CORE_CLOCK 48000000U
42+
static flash_config_t pflash;
43+
static uint32_t pflash_sector_size = WOLFBOOT_SECTOR_SIZE;
44+
45+
uint32_t SystemCoreClock;
46+
47+
48+
#ifdef __WOLFBOOT
49+
50+
extern void BOARD_BootClockRUN(void);
51+
52+
53+
54+
/* Assert hook needed by Kinetis SDK */
55+
void __assert_func(const char *a, int b, const char *c, const char *d)
56+
{
57+
while(1)
58+
;
59+
}
60+
61+
62+
void hal_prepare_boot(void)
63+
{
64+
65+
}
66+
67+
#endif
68+
69+
void hal_init(void)
70+
{
71+
#ifdef __WOLFBOOT
72+
/* Clock setting */
73+
BOARD_BootClockRUN();
74+
#endif
75+
76+
/* Flash driver init */
77+
flash_config_t pflash;
78+
/* Clear the FLASH configuration structure */
79+
memset(&pflash, 0, sizeof(pflash));
80+
/* FLASH driver init */
81+
FLASH_Init(&pflash);
82+
FLASH_GetProperty(&pflash, kFLASH_PropertyPflash0SectorSize,
83+
&pflash_sector_size);
84+
}
85+
86+
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
87+
{
88+
int ret;
89+
int w = 0;
90+
const uint8_t empty_qword[16] = {
91+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
92+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
93+
};
94+
95+
while (len > 0) {
96+
if ((len < 16) || address & 0x0F) {
97+
uint8_t aligned_qword[16];
98+
uint32_t address_align = address - (address & 0x0F);
99+
uint32_t start_off = address - address_align;
100+
int i;
101+
102+
memcpy(aligned_qword, (void*)address_align, 16);
103+
for (i = start_off; ((i < 16) && (i < len + (int)start_off)); i++) {
104+
aligned_qword[i] = data[w++];
105+
}
106+
if (memcmp(aligned_qword, empty_qword, 16) != 0) {
107+
ret = FLASH_Program(&pflash, FLASH, address_align, aligned_qword, 16);
108+
if (ret != kStatus_Success)
109+
return -1;
110+
}
111+
address += i;
112+
len -= i;
113+
}
114+
else {
115+
uint32_t len_align = len - (len & 0x0F);
116+
ret = FLASH_Program(&pflash, FLASH, address, (uint8_t*)data + w, len_align);
117+
if (ret != kStatus_Success)
118+
return -1;
119+
len -= len_align;
120+
address += len_align;
121+
}
122+
}
123+
return 0;
124+
}
125+
126+
void RAMFUNCTION hal_flash_unlock(void)
127+
{
128+
}
129+
130+
void RAMFUNCTION hal_flash_lock(void)
131+
{
132+
}
133+
134+
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
135+
{
136+
status_t result;
137+
if (address % pflash_sector_size)
138+
address -= address % pflash_sector_size;
139+
while (len > 0) {
140+
result = FLASH_Erase(&pflash, FLASH, address, pflash_sector_size,
141+
kFLASH_ApiEraseKey);
142+
if (kStatus_FLASH_Success != result)
143+
return -1;
144+
145+
/* Verify sector if it's been erased. */
146+
result = FLASH_VerifyEraseSector(&pflash, FLASH, address,
147+
pflash_sector_size);
148+
if (kStatus_FLASH_Success != result)
149+
return -1;
150+
len -= pflash_sector_size;
151+
}
152+
return 0;
153+
}
154+

hal/mcxw.ld

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
MEMORY
2+
{
3+
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = @BOOTLOADER_PARTITION_SIZE@
4+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 24K
5+
}
6+
7+
SECTIONS
8+
{
9+
10+
.text :
11+
{
12+
_start_text = .;
13+
KEEP(*(.isr_vector))
14+
. = 0x200;
15+
*(.keystore*)
16+
*(.text*)
17+
*(.rodata*)
18+
*(.init*)
19+
*(.fini*)
20+
. = ALIGN(4);
21+
_end_text = .;
22+
} > FLASH
23+
24+
.edidx :
25+
{
26+
. = ALIGN(4);
27+
*(.ARM.exidx*)
28+
} > FLASH
29+
30+
_stored_data = .;
31+
32+
.data : AT (_stored_data)
33+
{
34+
_start_data = .;
35+
KEEP(*(.data*))
36+
. = ALIGN(4);
37+
_end_data = .;
38+
} > RAM
39+
40+
.bss (NOLOAD) :
41+
{
42+
_start_bss = .;
43+
__bss_start__ = .;
44+
*(.bss*)
45+
*(COMMON)
46+
. = ALIGN(4);
47+
_end_bss = .;
48+
__bss_end__ = .;
49+
_end = .;
50+
} > RAM
51+
. = ALIGN(4);
52+
}
53+
54+
END_STACK = ORIGIN(RAM) + LENGTH(RAM);

test-app/ARM-mcxw.ld

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
MEMORY
2+
{
3+
FLASH (rx) : ORIGIN = @WOLFBOOT_TEST_APP_ADDRESS@, LENGTH = @WOLFBOOT_TEST_APP_SIZE@
4+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 24K
5+
}
6+
7+
SECTIONS
8+
{
9+
.text :
10+
{
11+
_start_text = .;
12+
KEEP(*(.isr_vector))
13+
*(.init)
14+
*(.fini)
15+
*(.text*)
16+
KEEP(*(.rodata*))
17+
. = ALIGN(4);
18+
_end_text = .;
19+
} > FLASH
20+
21+
.ARM :
22+
{
23+
__exidx_start = .;
24+
*(.ARM.exidx*)
25+
__exidx_end = .;
26+
} > FLASH
27+
28+
_stored_data = .;
29+
30+
.data : AT (_stored_data)
31+
{
32+
_start_data = .;
33+
KEEP(*(.data*))
34+
. = ALIGN(4);
35+
KEEP(*(.ramcode))
36+
. = ALIGN(4);
37+
_end_data = .;
38+
} > RAM
39+
40+
.bss :
41+
{
42+
_start_bss = .;
43+
*(.bss*)
44+
*(COMMON)
45+
. = ALIGN(4);
46+
_end_bss = .;
47+
_end = .;
48+
} > RAM
49+
}
50+
51+
_wolfboot_partition_boot_address = @WOLFBOOT_PARTITION_BOOT_ADDRESS@;
52+
_wolfboot_partition_size = @WOLFBOOT_PARTITION_SIZE@;
53+
_wolfboot_partition_update_address = @WOLFBOOT_PARTITION_UPDATE_ADDRESS@;
54+
_wolfboot_partition_swap_address = @WOLFBOOT_PARTITION_SWAP_ADDRESS@;
55+
56+
PROVIDE(_start_heap = _end);
57+
PROVIDE(_end_stack = ORIGIN(RAM) + LENGTH(RAM));

test-app/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ ifeq ($(TARGET),mcxa)
302302
APP_OBJS+=$(MCUXPRESSO_DRIVERS)/drivers/fsl_spc.o
303303
endif
304304

305+
ifeq ($(TARGET),mcxw)
306+
LSCRIPT_TEMPLATE=ARM-mcxw.ld
307+
APP_OBJS+=$(MCUXPRESSO_DRIVERS)/drivers/fsl_clock.o
308+
APP_OBJS+=$(MCUXPRESSO_DRIVERS)/drivers/fsl_gpio.o
309+
APP_OBJS+=$(MCUXPRESSO_DRIVERS)/drivers/fsl_spc.o
310+
APP_OBJS+=$(MCUXPRESSO_DRIVERS)/project_template/clock_config.o
311+
APP_OBJS+=$(MCUXPRESSO_DRIVERS)/drivers/fsl_ccm32k.o
312+
APP_OBJS+=$(MCUXPRESSO_DRIVERS)/drivers/fsl_romapi.o
313+
endif
314+
305315
ifeq ($(TARGET),imx_rt)
306316
LDFLAGS+=\
307317
-mcpu=cortex-m7 -Wall --specs=nosys.specs -fno-common -ffunction-sections -fdata-sections \

0 commit comments

Comments
 (0)