|
30 | 30 | #include "wolfboot/wolfboot.h" |
31 | 31 | #include "target.h" |
32 | 32 | #include "printf.h" |
33 | | -#include "keystore.h" |
34 | 33 |
|
35 | 34 | #include "../hal/mpfs250.h" |
36 | 35 |
|
37 | | -static uint8_t boot_part_state = IMG_STATE_NEW; |
38 | | -static uint8_t update_part_state = IMG_STATE_NEW; |
39 | | - |
40 | | -const char part_state_names[6][16] = { |
41 | | - "NEW", |
42 | | - "UPDATING", |
43 | | - "FFLAGS", |
44 | | - "TESTING", |
45 | | - "CONFIRMED", |
46 | | - "[Invalid state]" |
47 | | -}; |
48 | | - |
49 | | -static const char *part_state_name(uint8_t state) |
50 | | -{ |
51 | | - switch(state) { |
52 | | - case IMG_STATE_NEW: |
53 | | - return part_state_names[0]; |
54 | | - case IMG_STATE_UPDATING: |
55 | | - return part_state_names[1]; |
56 | | - case IMG_STATE_FINAL_FLAGS: |
57 | | - return part_state_names[2]; |
58 | | - case IMG_STATE_TESTING: |
59 | | - return part_state_names[3]; |
60 | | - case IMG_STATE_SUCCESS: |
61 | | - return part_state_names[4]; |
62 | | - default: |
63 | | - return part_state_names[5]; |
64 | | - } |
65 | | -} |
66 | | - |
67 | | -static int print_info(void) |
68 | | -{ |
69 | | - int i, j; |
70 | | - uint32_t cur_fw_version, update_fw_version; |
71 | | - uint32_t n_keys; |
72 | | - uint16_t hdrSz; |
73 | | - |
74 | | - cur_fw_version = wolfBoot_current_firmware_version(); |
75 | | - update_fw_version = wolfBoot_update_firmware_version(); |
76 | | - |
77 | | - wolfBoot_get_partition_state(PART_BOOT, &boot_part_state); |
78 | | - wolfBoot_get_partition_state(PART_UPDATE, &update_part_state); |
79 | | - |
80 | | - wolfBoot_printf("\r\n"); |
81 | | - wolfBoot_printf("System information\r\n"); |
82 | | - wolfBoot_printf("====================================\r\n"); |
83 | | - wolfBoot_printf("Firmware version : 0x%lx\r\n", wolfBoot_current_firmware_version()); |
84 | | - wolfBoot_printf("Current firmware state: %s\r\n", part_state_name(boot_part_state)); |
85 | | - if (update_fw_version != 0) { |
86 | | - if (update_part_state == IMG_STATE_UPDATING) |
87 | | - wolfBoot_printf("Candidate firmware version : 0x%lx\r\n", update_fw_version); |
88 | | - else |
89 | | - wolfBoot_printf("Backup firmware version : 0x%lx\r\n", update_fw_version); |
90 | | - wolfBoot_printf("Update state: %s\r\n", part_state_name(update_part_state)); |
91 | | - if (update_fw_version > cur_fw_version) { |
92 | | - wolfBoot_printf("'reboot' to initiate update.\r\n"); |
93 | | - } else { |
94 | | - wolfBoot_printf("Update image older than current.\r\n"); |
95 | | - } |
96 | | - } else { |
97 | | - wolfBoot_printf("No image in update partition.\r\n"); |
98 | | - } |
99 | | - |
100 | | - wolfBoot_printf("\r\n"); |
101 | | - wolfBoot_printf("Bootloader OTP keystore information\r\n"); |
102 | | - wolfBoot_printf("====================================\r\n"); |
103 | | - n_keys = keystore_num_pubkeys(); |
104 | | - wolfBoot_printf("Number of public keys: %lu\r\n", n_keys); |
105 | | - for (i = 0; i < n_keys; i++) { |
106 | | - uint32_t size = keystore_get_size(i); |
107 | | - uint32_t type = keystore_get_key_type(i); |
108 | | - uint32_t mask = keystore_get_mask(i); |
109 | | - uint8_t *keybuf = keystore_get_buffer(i); |
110 | | - |
111 | | - wolfBoot_printf("\r\n"); |
112 | | - wolfBoot_printf(" Public Key #%d: size %lu, type %lx, mask %08lx\r\n", i, |
113 | | - size, type, mask); |
114 | | - wolfBoot_printf(" ====================================\r\n "); |
115 | | - for (j = 0; j < size; j++) { |
116 | | - wolfBoot_printf("%02X ", keybuf[j]); |
117 | | - if (j % 16 == 15) { |
118 | | - wolfBoot_printf("\r\n "); |
119 | | - } |
120 | | - } |
121 | | - wolfBoot_printf("\r\n"); |
122 | | - } |
123 | | - return 0; |
124 | | -} |
125 | 36 |
|
126 | 37 | void main(void) |
127 | 38 | { |
128 | | - uint32_t app_version; |
129 | | - |
130 | 39 | hal_init(); |
131 | 40 |
|
132 | | - app_version = wolfBoot_current_firmware_version(); |
133 | | - |
134 | 41 | wolfBoot_printf("========================\r\n"); |
135 | 42 | wolfBoot_printf("PolarFire SoC MPFS250 wolfBoot demo Application\r\n"); |
136 | 43 | wolfBoot_printf("Copyright 2025 wolfSSL Inc\r\n"); |
137 | 44 | wolfBoot_printf("GPL v3\r\n"); |
138 | | - wolfBoot_printf("Version : 0x%lx\r\n", app_version); |
139 | 45 | wolfBoot_printf("========================\r\n"); |
140 | 46 |
|
141 | | - print_info(); |
142 | | - |
143 | | - if (app_version > 1) { |
144 | | - if (boot_part_state == IMG_STATE_TESTING) { |
145 | | - wolfBoot_printf("Booting new firmware, marking successful boot\n"); |
146 | | - |
147 | | - /* Mark successful boot, so update won't be rolled back */ |
148 | | - wolfBoot_success(); |
149 | | - } |
150 | | - } |
151 | | - |
152 | 47 | /* TODO: Add application-specific code here */ |
153 | 48 |
|
154 | 49 | while(1) { |
|
0 commit comments