Skip to content

Commit 5ecd2f7

Browse files
committed
Cleaned up TLV example and simulator output. Moved wolfBoot_find_header to the public header.
1 parent 440ebb9 commit 5ecd2f7

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

docs/firmware_image.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,16 @@ From the bootloader code, we can then retrieve the value of the custom field usi
8080
uint32_t value;
8181
uint8_t* ptr = NULL;
8282
uint16_t tlv = 0x34;
83-
uint8_t* imageHdr = (uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS; /* WOLFBOOT_PARTITION_UPDATE_ADDRESS */
83+
uint8_t* imageHdr = (uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS + IMAGE_HEADER_OFFSET;
8484
uint16_t size = wolfBoot_find_header(imageHdr, tlv, &ptr);
85-
if (size != sizeof(uint32_t) || ptr == NULL) {
86-
/* Error: the field is not present or has the wrong size */
85+
if (size > 0 && ptr != NULL) {
86+
/* Found field and ptr points to value 0xAABBCCDD */
87+
memcpy(&value, ptr, size);
88+
printf("TLV 0x%x=0x%x\n", tlv, value);
89+
}
90+
else {
91+
/* Error: the field is not found */
8792
}
88-
89-
/* From here, the value 0xAABBCCDD is at ptr */
90-
memcpy(&value, ptr, size);
91-
printf("TLV 0x%x=0x%x\n", tlv, value);
9293
```
9394

9495
### Image signing tool

include/image.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,6 @@ int wolfBoot_set_update_sector_flag(uint16_t sector, uint8_t newflag);
565565
uint8_t* wolfBoot_peek_image(struct wolfBoot_image *img, uint32_t offset,
566566
uint32_t* sz);
567567

568-
569-
/* Defined in libwolfboot */
570-
uint16_t wolfBoot_find_header(uint8_t *haystack, uint16_t type, uint8_t **ptr);
571-
572568
/* get header type for image */
573569
uint16_t wolfBoot_get_header(struct wolfBoot_image *img, uint16_t type, uint8_t **ptr);
574570

include/wolfboot/wolfboot.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ uint32_t wolfBoot_get_blob_version(uint8_t *blob);
275275
uint16_t wolfBoot_get_blob_type(uint8_t *blob);
276276
uint32_t wolfBoot_get_blob_diffbase_version(uint8_t *blob);
277277

278+
uint16_t wolfBoot_find_header(uint8_t *haystack, uint16_t type, uint8_t **ptr);
279+
278280
/* Get partition ID from manifest header */
279281
static inline uint8_t wolfBoot_get_blob_partition_id(uint8_t *blob) {
280282
return wolfBoot_get_blob_type(blob) & HDR_IMG_TYPE_PART_MASK;

test-app/app_sim.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ int do_cmd(const char *cmd)
7171
exit(0);
7272
}
7373
if (strncmp(cmd, "get_tlv",7) == 0) {
74-
uint8_t* imageHdr = (uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS;
74+
/* boot partition and skip the image header offset (8 bytes) */
75+
uint8_t* imageHdr = (uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS + IMAGE_HEADER_OFFSET;
7576
uint8_t* ptr = NULL;
7677
uint16_t tlv = 0x34; /* default */
7778
int size;
@@ -82,20 +83,18 @@ int do_cmd(const char *cmd)
8283
tlvStr += strlen("get_tlv=");
8384
tlv = (uint16_t)atoi(tlvStr);
8485
}
85-
printf("Get TLV %04x\r\n", tlv);
8686

87-
size = wolfBoot_find_header(imageHdr + IMAGE_HEADER_OFFSET, tlv, &ptr);
87+
size = wolfBoot_find_header(imageHdr, tlv, &ptr);
8888
if (size > 0 && ptr != NULL) {
8989
/* From here, the value 0xAABBCCDD is at ptr */
90-
printf("TLV 0x%x: found. Size: %d\n", tlv, size);
90+
printf("TLV 0x%x: found (size %d):\n", tlv, size);
9191
for (i=0; i<size; i++) {
9292
printf("%02X", ptr[i]);
9393
}
9494
printf("\n");
9595
return 0;
9696
} else {
97-
printf("TLV: not found!\r\n");
98-
return -1;
97+
printf("TLV 0x%x: not found!\r\n", tlv);
9998
}
10099
}
101100
/* wrong command */

0 commit comments

Comments
 (0)