forked from wolfSSL/wolfBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_lpc55s69.c
More file actions
215 lines (188 loc) · 5.79 KB
/
app_lpc55s69.c
File metadata and controls
215 lines (188 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/* app_lpc55s69.c
*
* Copyright (C) 2026 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include <stdint.h>
#include "fsl_clock.h"
#include "fsl_gpio.h"
#include "fsl_iocon.h"
#include "target.h"
#include "wolfboot/wolfboot.h"
#include "printf.h"
#define RED_LED 6
#define GREEN_LED 7
#define BLUE_LED 4
extern void hal_init(void);
#define IOCON_PIO_FUNC0 0x00u /*!<@brief Selects pin function 0 */
#define IOCON_PIO_MODE_PULLUP 0x20u /*!<@brief Selects pull-up function */
#define IOCON_PIO_SLEW_STANDARD 0x00u /*!<@brief Standard mode, output slew rate control is enabled */
#define IOCON_PIO_INV_DI 0x00u /*!<@brief Input function is not inverted */
#define IOCON_PIO_DIGITAL_EN 0x0100u /*!<@brief Enables digital function */
#define IOCON_PIO_OPENDRAIN_DI 0x00u /*!<@brief Open drain is disabled */
static void leds_init(void)
{
#ifndef TZEN
CLOCK_EnableClock(kCLOCK_Iocon);
CLOCK_EnableClock(kCLOCK_Gpio1);
#endif
/* red output off */
GPIO->SET[1] = 1UL << RED_LED;
GPIO->DIR[1] |= 1UL << RED_LED;
/* green output off */
GPIO->SET[1] = 1UL << GREEN_LED;
GPIO->DIR[1] |= 1UL << GREEN_LED;
/* blue output off */
GPIO->SET[1] = 1UL << BLUE_LED;
GPIO->DIR[1] |= 1UL << BLUE_LED;
const uint32_t LED_PINMUX_CONFIG = (/* Pin is configured as PIO */
IOCON_PIO_FUNC0 |
/* Selects pull-up function */
IOCON_PIO_MODE_PULLUP |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW_STANDARD |
/* Input function is not inverted */
IOCON_PIO_INV_DI |
/* Enables digital function */
IOCON_PIO_DIGITAL_EN |
/* Open drain is disabled */
IOCON_PIO_OPENDRAIN_DI);
IOCON_PinMuxSet(IOCON, 1, RED_LED, LED_PINMUX_CONFIG);
IOCON_PinMuxSet(IOCON, 1, GREEN_LED, LED_PINMUX_CONFIG);
IOCON_PinMuxSet(IOCON, 1, BLUE_LED, LED_PINMUX_CONFIG);
}
static void check_parts(
uint32_t *pboot_ver, uint32_t *pupdate_ver,
uint8_t *pboot_state, uint8_t *pupdate_state
)
{
#ifdef WOLFCRYPT_SECURE_MODE
*pboot_ver = wolfBoot_nsc_current_firmware_version();
*pupdate_ver = wolfBoot_nsc_update_firmware_version();
if (wolfBoot_nsc_get_partition_state(PART_BOOT, pboot_state) != 0)
*pboot_state = IMG_STATE_NEW;
if (wolfBoot_nsc_get_partition_state(PART_UPDATE, pupdate_state) != 0)
*pupdate_state = IMG_STATE_NEW;
#else
*pboot_ver = wolfBoot_current_firmware_version();
*pupdate_ver = wolfBoot_update_firmware_version();
if (wolfBoot_get_partition_state(PART_BOOT, pboot_state) != 0)
*pboot_state = IMG_STATE_NEW;
if (wolfBoot_get_partition_state(PART_UPDATE, pupdate_state) != 0)
*pupdate_state = IMG_STATE_NEW;
#endif
wolfBoot_printf(" boot: ver=0x%lx state=0x%02x\n", *pboot_ver, *pboot_state);
wolfBoot_printf(" update: ver=0x%lx state=0x%02x\n", *pupdate_ver, *pupdate_state);
}
void main(void)
{
uint32_t boot_ver, update_ver;
uint8_t boot_state, update_state;
hal_init();
leds_init();
check_parts(&boot_ver, &update_ver, &boot_state, &update_state);
if (
boot_ver != 0 &&
(boot_state == IMG_STATE_TESTING || boot_state == IMG_STATE_NEW)
)
{
#ifdef WOLFCRYPT_SECURE_MODE
wolfBoot_printf("Calling wolfBoot_nsc_success()\n");
wolfBoot_nsc_success();
#else
wolfBoot_printf("Calling wolfBoot_success()\n");
wolfBoot_success();
#endif
check_parts(&boot_ver, &update_ver, &boot_state, &update_state);
}
if (boot_ver == 1)
{
/* blue on */
GPIO_PinWrite(GPIO, 1, BLUE_LED, 0);
if (update_ver != 0) {
wolfBoot_printf("Update detected, version: 0x%lx\n", update_ver);
wolfBoot_printf("Triggering update...\n");
#ifdef WOLFCRYPT_SECURE_MODE
wolfBoot_nsc_update_trigger();
#else
wolfBoot_update_trigger();
#endif
check_parts(&boot_ver, &update_ver, &boot_state, &update_state);
wolfBoot_printf("...done. Reboot to apply.\n");
}
}
else {
/* green on */
GPIO_PinWrite(GPIO, 1, GREEN_LED, 0);
}
while (1) {
__asm__ volatile ("wfi");
}
}
#include "sys/stat.h"
int _getpid(void)
{
return 1;
}
int _kill(int pid, int sig)
{
(void)pid;
(void)sig;
return -1;
}
void _exit(int status)
{
_kill(status, -1);
while (1) {}
}
int _read(int file, char *ptr, int len)
{
(void)file;
(void)ptr;
(void)len;
return -1;
}
int _write(int file, char *ptr, int len)
{
(void)file;
(void)ptr;
return len;
}
int _close(int file)
{
(void)file;
return -1;
}
int _isatty(int file)
{
(void)file;
return 1;
}
int _lseek(int file, int ptr, int dir)
{
(void)file;
(void)ptr;
(void)dir;
return 0;
}
int _fstat(int file, struct stat *st)
{
(void)file;
st->st_mode = S_IFCHR;
return 0;
}