Skip to content

Commit a6e9cc6

Browse files
committed
Added test application, fixed hal
1 parent 33cab9e commit a6e9cc6

File tree

4 files changed

+195
-20
lines changed

4 files changed

+195
-20
lines changed

hal/mcxw.c

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434

3535
/* Flash driver */
3636
#include "fsl_device_registers.h"
37-
#include "fsl_flash_api.h"
3837
#include "fsl_lpspi_flash.h"
39-
#include "fsl_ccm32k.h"
38+
#include "fsl_k4_flash.h"
4039

4140
/*!< Core clock frequency: 48000000Hz */
4241
#define BOARD_BOOTCLOCKRUN_CORE_CLOCK 48000000U
4342
static flash_config_t pflash;
43+
static uint32_t pflash_sector_size = WOLFBOOT_SECTOR_SIZE;
4444

4545
uint32_t SystemCoreClock;
4646

@@ -58,30 +58,33 @@ void __assert_func(const char *a, int b, const char *c, const char *d)
5858
;
5959
}
6060

61+
62+
void hal_prepare_boot(void)
63+
{
64+
65+
}
66+
67+
#endif
68+
6169
void hal_init(void)
6270
{
71+
#ifdef __WOLFBOOT
6372
/* Clock setting */
6473
BOARD_BootClockRUN();
74+
#endif
6575

6676
/* Flash driver init */
6777
flash_config_t pflash;
68-
6978
/* Clear the FLASH configuration structure */
7079
memset(&pflash, 0, sizeof(pflash));
7180
/* FLASH driver init */
7281
FLASH_Init(&pflash);
82+
FLASH_GetProperty(&pflash, kFLASH_PropertyPflash0SectorSize,
83+
&pflash_sector_size);
7384
}
7485

75-
void hal_prepare_boot(void)
76-
{
77-
78-
}
79-
80-
#endif
81-
8286
int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
8387
{
84-
#if 0
8588
int ret;
8689
int w = 0;
8790
const uint8_t empty_qword[16] = {
@@ -101,7 +104,7 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
101104
aligned_qword[i] = data[w++];
102105
}
103106
if (memcmp(aligned_qword, empty_qword, 16) != 0) {
104-
ret = FLASH_Program(&pflash, address_align, aligned_qword, 16);
107+
ret = FLASH_Program(&pflash, FLASH, address_align, aligned_qword, 16);
105108
if (ret != kStatus_Success)
106109
return -1;
107110
}
@@ -110,14 +113,13 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
110113
}
111114
else {
112115
uint32_t len_align = len - (len & 0x0F);
113-
ret = FLASH_Program(&pflash, address, (uint8_t*)data + w, len_align);
116+
ret = FLASH_Program(&pflash, FLASH, address, (uint8_t*)data + w, len_align);
114117
if (ret != kStatus_Success)
115118
return -1;
116119
len -= len_align;
117120
address += len_align;
118121
}
119122
}
120-
#endif
121123
return 0;
122124
}
123125

@@ -131,12 +133,22 @@ void RAMFUNCTION hal_flash_lock(void)
131133

132134
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
133135
{
134-
#if 0
135-
while ((address % 4) != 0)
136-
address --;
137-
if (FLASH_VerifyEraseSector(&pflash, address, len, kFLASH_ApiEraseKey) != kStatus_Success)
138-
return -1;
139-
#endif
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+
}
140152
return 0;
141153
}
142154

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 \

test-app/app_mcxw.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* app_mcxa.c
2+
*
3+
* Test bare-metal boot-led-on application
4+
*
5+
* Copyright (C) 2024 wolfSSL Inc.
6+
*
7+
* This file is part of wolfBoot.
8+
*
9+
* wolfBoot is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation; either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* wolfBoot is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program; if not, write to the Free Software
21+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
22+
*/
23+
24+
25+
#include <stdlib.h>
26+
#include <stdint.h>
27+
#include <string.h>
28+
#include "fsl_common.h"
29+
#include "fsl_port.h"
30+
#include "fsl_gpio.h"
31+
#include "fsl_clock.h"
32+
33+
#include "wolfboot/wolfboot.h"
34+
#include "target.h"
35+
36+
extern void hal_init(void);
37+
38+
/* init gpio for port 3 */
39+
void gpio_portA_init(int pin)
40+
{
41+
const port_pin_config_t GPIO_OUT_LED = {
42+
(uint16_t)kPORT_PullDisable,
43+
(uint16_t)kPORT_LowPullResistor,
44+
(uint16_t)kPORT_FastSlewRate,
45+
(uint16_t)kPORT_PassiveFilterDisable,
46+
(uint16_t)kPORT_OpenDrainDisable,
47+
(uint16_t)kPORT_LowDriveStrength,
48+
(uint16_t)kPORT_NormalDriveStrength,
49+
(uint16_t)kPORT_MuxAsGpio,
50+
(uint16_t)kPORT_UnlockRegister
51+
};
52+
53+
const gpio_pin_config_t GPIO_OUT_LED_config = {
54+
.pinDirection = kGPIO_DigitalOutput,
55+
.outputLogic = 0U
56+
};
57+
58+
59+
/* Initialize GPIO functionality on pin */
60+
GPIO_PinInit(GPIOA, pin, &GPIO_OUT_LED_config);
61+
PORT_SetPinConfig(PORTA, pin, &GPIO_OUT_LED);
62+
GPIO_PinWrite(GPIOA, pin, 1);
63+
}
64+
65+
void main(void)
66+
{
67+
int i = 0;
68+
uint8_t* bootPart = (uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS;
69+
uint32_t bootVer = wolfBoot_get_blob_version(bootPart);
70+
/* Enable GPIO port clocks */
71+
CLOCK_EnableClock(kCLOCK_GpioA);
72+
CLOCK_EnableClock(kCLOCK_PortA);
73+
CLOCK_EnableClock(kCLOCK_PortC);
74+
gpio_portA_init(18);
75+
gpio_portA_init(19);
76+
gpio_portA_init(20);
77+
78+
hal_init();
79+
if (bootVer == 1) {
80+
GPIO_PinWrite(GPIOA, 20, 0);
81+
wolfBoot_update_trigger();
82+
}
83+
else {
84+
/* Green LED GPIOA port A pin 19 */
85+
GPIO_PinWrite(GPIOA, 19, 0);
86+
/* mark boot successful */
87+
wolfBoot_success();
88+
}
89+
90+
91+
92+
/* busy wait */
93+
while (1) {
94+
__WFI();
95+
}
96+
}

0 commit comments

Comments
 (0)