forked from wolfSSL/wolfBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_renesas_rx.c
152 lines (131 loc) · 4.61 KB
/
app_renesas_rx.c
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
/* app_renesas_rx.c
*
* Test bare-metal application.
*
* Copyright (C) 2024 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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "hal.h"
#include "printf.h"
#include "wolfboot/wolfboot.h"
#include "target.h"
/* route stdout to UART */
int write(int fileno, char *buf, int count)
{
(void)fileno;
uart_write(buf, count);
return count;
}
static const char* state2str(uint8_t s)
{
switch (s) {
case IMG_STATE_NEW: return "New";
case IMG_STATE_UPDATING: return "Updating";
case IMG_STATE_TESTING: return "Testing";
case IMG_STATE_SUCCESS: return "Success";
default: return "Unknown";
}
}
static void printPart(uint8_t *part)
{
uint8_t *magic;
uint32_t ver;
uint8_t state;
#ifdef WOLFBOOT_DEBUG_PARTION
uint32_t *v;
int i;
#endif
magic = part;
printf("Magic: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
ver = wolfBoot_get_blob_version(part);
printf("Version: %02x\n", (uint8_t)ver);
state = *(part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t) - 1);
printf("Status: %02x (%s)\n", state, state2str(state));
magic = part + WOLFBOOT_PARTITION_SIZE - sizeof(uint32_t);
printf("Trailer Mgc: %c%c%c%c\n", magic[0], magic[1], magic[2], magic[3]);
#ifdef WOLFBOOT_DEBUG_PARTION
v = (uint32_t*)part;
for (i = 0; i < 0x100/4; i++) {
if(i % 4 == 0)
print("\n%08x: ", (uint32_t)v+i*4);
print("%08x ", v[i]);
}
#endif
}
static void printPartitions(void)
{
printf("\n=== Boot Partition[%08x] ===\n", WOLFBOOT_PARTITION_BOOT_ADDRESS);
printPart((uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS);
printf("\n=== Update Partition[%08x] ===\n", WOLFBOOT_PARTITION_UPDATE_ADDRESS);
printPart((uint8_t*)WOLFBOOT_PARTITION_UPDATE_ADDRESS);
}
int main(void)
{
uint8_t firmware_version = 0;
uart_init();
#if !defined(WOLFBOOT_RENESAS_TSIP)
printf("| ------------------------------------------------------------------- |\n");
printf("| Renesas RX User Application in BOOT partition started by wolfBoot |\n");
printf("| ------------------------------------------------------------------- |\n\n");
#elif defined(WOLFBOOT_RENESAS_TSIP_SRCVERSION)
printf("| ------------------------------------------------------------------------------- |\n");
printf("| Renesas RX w/ TSIP(SRC) User Application in BOOT partition started by wolfBoot |\n");
printf("| ------------------------------------------------------------------------------- |\n\n");
#else
printf("| ------------------------------------------------------------------------------- |\n");
printf("| Renesas RX w/ TSIP(LIB) User Application in BOOT partition started by wolfBoot |\n");
printf("| ------------------------------------------------------------------------------- |\n\n");
#endif
hal_init();
printPartitions();
/* The same as: wolfBoot_get_image_version(PART_BOOT); */
firmware_version = wolfBoot_current_firmware_version();
printf("\nCurrent Firmware Version: %d\n", firmware_version);
if (firmware_version >= 1) {
if (firmware_version == 1) {
printf("Hit any key to call wolfBoot_success the firmware.\n");
getchar();
wolfBoot_success();
printPartitions();
printf("\nHit any key to update the firmware.\n");
getchar();
wolfBoot_update_trigger();
printf("Firmware Update is triggered\n");
printPartitions();
}
else if (firmware_version == 2) {
printf("Hit any key to call wolfBoot_success the firmware.\n");
getchar();
wolfBoot_success();
printPartitions();
}
}
else {
printf("Invalid Firmware Version\n");
goto busy_idle;
}
busy_idle:
/* busy wait */
while (1)
;
return 0;
}