2727#include "printf.h"
2828#include "wolfboot/wolfboot.h"
2929
30+
3031/* Helper function to convert partition ID to string */
3132static const char * partition_name (uint8_t part )
3233{
@@ -41,52 +42,95 @@ static const char* partition_name(uint8_t part)
4142}
4243
4344/* Helper function to convert state value to string */
44- static const char * state_name (uint8_t state )
45+ static const char * partition_state_name (uint8_t state )
4546{
4647 switch (state ) {
4748 case IMG_STATE_NEW :
4849 return "NEW" ;
4950 case IMG_STATE_UPDATING :
5051 return "UPDATING" ;
52+ case IMG_STATE_FINAL_FLAGS :
53+ return "FFLAGS" ;
54+ case IMG_STATE_TESTING :
55+ return "TESTING" ;
5156 case IMG_STATE_SUCCESS :
5257 return "SUCCESS" ;
5358 default :
5459 return "UNKNOWN" ;
5560 }
5661}
5762
58- /* Print partition state */
59- static int cmd_get_state ( uint8_t part )
63+ /* Print all partition states */
64+ static int cmd_get_all_states ( void )
6065{
61- uint8_t state ;
62- int ret ;
66+ uint32_t cur_fw_version , update_fw_version ;
67+ uint16_t hdrSz ;
68+ uint8_t boot_part_state = IMG_STATE_NEW , update_part_state = IMG_STATE_NEW ;
6369
64- ret = wolfBoot_get_partition_state (part , & state );
65- if (ret != 0 ) {
66- wolfBoot_printf ("Error: Failed to get state for %s partition (error: %d)\n" ,
67- partition_name (part ), ret );
68- return -1 ;
70+ cur_fw_version = wolfBoot_current_firmware_version ();
71+ update_fw_version = wolfBoot_update_firmware_version ();
72+
73+ wolfBoot_get_partition_state (PART_BOOT , & boot_part_state );
74+ wolfBoot_get_partition_state (PART_UPDATE , & update_part_state );
75+
76+ wolfBoot_printf ("\n" );
77+ wolfBoot_printf ("System information\n" );
78+ wolfBoot_printf ("====================================\n" );
79+ wolfBoot_printf ("Firmware version : 0x%lx\n" ,
80+ (unsigned long )wolfBoot_current_firmware_version ());
81+ wolfBoot_printf ("Current firmware state: %s\n" ,
82+ partition_state_name (boot_part_state ));
83+ if (update_fw_version != 0 ) {
84+ if (update_part_state == IMG_STATE_UPDATING ) {
85+ wolfBoot_printf ("Candidate firmware version : 0x%lx\n" ,
86+ (unsigned long )update_fw_version );
87+ } else {
88+ wolfBoot_printf ("Backup firmware version : 0x%lx\n" ,
89+ (unsigned long )update_fw_version );
90+ }
91+ wolfBoot_printf ("Update state: %s\n" ,
92+ partition_state_name (update_part_state ));
93+ if (update_fw_version > cur_fw_version ) {
94+ wolfBoot_printf ("'reboot' to initiate update.\n" );
95+ } else {
96+ wolfBoot_printf ("Update image older than current.\n" );
97+ }
98+ } else {
99+ wolfBoot_printf ("No image in update partition.\n" );
69100 }
70101
71- wolfBoot_printf ("%s partition state: %s (0x%02X)\n" ,
72- partition_name (part ), state_name (state ), state );
73102 return 0 ;
74103}
75104
76- /* Print all partition states */
77- static int cmd_get_all_states (void )
105+ static int cmd_get_keystore (void )
78106{
79- int ret = 0 ;
80-
81- wolfBoot_printf ("=== Partition States ===\n" );
107+ int i , j ;
108+ uint32_t n_keys ;
82109
83- if (cmd_get_state (PART_BOOT ) != 0 )
84- ret = -1 ;
85-
86- if (cmd_get_state (PART_UPDATE ) != 0 )
87- ret = -1 ;
110+ wolfBoot_printf ("\n" );
111+ wolfBoot_printf ("Bootloader keystore information\n" );
112+ wolfBoot_printf ("====================================\n" );
113+ n_keys = keystore_num_pubkeys ();
114+ wolfBoot_printf ("Number of public keys: %lu\n" , (unsigned long )n_keys );
115+ for (i = 0 ; i < (int )n_keys ; i ++ ) {
116+ uint32_t size = keystore_get_size (i );
117+ uint32_t type = keystore_get_key_type (i );
118+ uint32_t mask = keystore_get_mask (i );
119+ uint8_t * keybuf = keystore_get_buffer (i );
88120
89- return ret ;
121+ wolfBoot_printf ("\n" );
122+ wolfBoot_printf (" Public Key #%d: size %lu, type %lx, mask %08lx\n" , i ,
123+ (unsigned long )size , (unsigned long )type , (unsigned long )mask );
124+ wolfBoot_printf (" ====================================\n " );
125+ for (j = 0 ; j < (int )size ; j ++ ) {
126+ wolfBoot_printf ("%02X " , keybuf [j ]);
127+ if (j % 16 == 15 ) {
128+ wolfBoot_printf ("\n " );
129+ }
130+ }
131+ wolfBoot_printf ("\n" );
132+ }
133+ return 0 ;
90134}
91135
92136/* Trigger an update */
@@ -114,8 +158,7 @@ static void print_usage(const char* prog_name)
114158 wolfBoot_printf ("\nUsage: %s <command> [options]\n\n" , prog_name );
115159 wolfBoot_printf ("Commands:\n" );
116160 wolfBoot_printf (" status - Show state of all partitions\n" );
117- wolfBoot_printf (" get-boot - Get BOOT partition state\n" );
118- wolfBoot_printf (" get-update - Get UPDATE partition state\n" );
161+ wolfBoot_printf (" keystore - Show keystore information\n" );
119162 wolfBoot_printf (" update-trigger - Trigger an update (sets UPDATE partition to UPDATING)\n" );
120163 wolfBoot_printf (" success - Mark BOOT partition as SUCCESS\n" );
121164 wolfBoot_printf (" verify-boot - Verify integrity and authenticity of BOOT partition\n" );
@@ -140,24 +183,27 @@ static int cmd_verify(uint8_t part)
140183
141184 ret = wolfBoot_open_image (& img , part );
142185 if (ret < 0 ) {
143- wolfBoot_printf ("Error: Failed to open image header for %s partition (error: %d)\n" ,
186+ wolfBoot_printf ("Failed to open image header for %s partition (error: %d)\n" ,
144187 partition_name (part ), ret );
145188 return -1 ;
146189 }
147190
148191 ret = wolfBoot_verify_integrity (& img );
149192 if (ret < 0 ) {
150- wolfBoot_printf ("Integrity check failed for %s partition\n" , partition_name (part ));
193+ wolfBoot_printf ("Integrity check failed for %s partition\n" ,
194+ partition_name (part ));
151195 return -1 ;
152196 }
153197
154198 ret = wolfBoot_verify_authenticity (& img );
155199 if (ret < 0 ) {
156- wolfBoot_printf ("Authenticity check failed for %s partition\n" , partition_name (part ));
200+ wolfBoot_printf ("Authenticity check failed for %s partition\n" ,
201+ partition_name (part ));
157202 return -1 ;
158203 }
159204
160- wolfBoot_printf ("%s partition: Integrity and authenticity verified.\n" , partition_name (part ));
205+ wolfBoot_printf ("%s partition: Integrity and authenticity verified.\n" ,
206+ partition_name (part ));
161207 return ret ;
162208}
163209
@@ -183,11 +229,8 @@ int main(int argc, const char* argv[])
183229 if (strcmp (command , "status" ) == 0 ) {
184230 ret = cmd_get_all_states ();
185231 }
186- else if (strcmp (command , "get-boot" ) == 0 ) {
187- ret = cmd_get_state (PART_BOOT );
188- }
189- else if (strcmp (command , "get-update" ) == 0 ) {
190- ret = cmd_get_state (PART_UPDATE );
232+ else if (strcmp (command , "keystore" ) == 0 ) {
233+ ret = cmd_get_keystore ();
191234 }
192235 else if (strcmp (command , "update-trigger" ) == 0 ) {
193236 ret = cmd_update_trigger ();
0 commit comments