Skip to content

Commit e9d65b3

Browse files
committed
Fixed TLV alignment for 8B fields
+ added sim "get_tlv" command
1 parent 01e22ed commit e9d65b3

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,18 @@ test-app/image.elf: wolfboot.elf
198198
$(Q)$(MAKE) -C test-app WOLFBOOT_ROOT="$(WOLFBOOT_ROOT)" image.elf
199199
$(Q)$(SIZE) test-app/image.elf
200200

201-
internal_flash.dd: $(BINASSEMBLE) wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin
202-
@echo "\t[MERGE] internal_flash.dd"
203-
$(Q)dd if=/dev/zero bs=1 count=$$(($(WOLFBOOT_SECTOR_SIZE))) > /tmp/swap
204-
$(Q)$(BINASSEMBLE) $@ \
201+
assemble_internal_flash.dd: FORCE
202+
$(Q)$(BINASSEMBLE) internal_flash.dd \
205203
0 wolfboot.bin \
206204
$$(($(WOLFBOOT_PARTITION_BOOT_ADDRESS) - $(ARCH_FLASH_OFFSET))) test-app/image_v1_signed.bin \
207205
$$(($(WOLFBOOT_PARTITION_UPDATE_ADDRESS)-$(ARCH_FLASH_OFFSET))) /tmp/swap \
208206
$$(($(WOLFBOOT_PARTITION_SWAP_ADDRESS)-$(ARCH_FLASH_OFFSET))) /tmp/swap
209207

208+
internal_flash.dd: $(BINASSEMBLE) wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin
209+
@echo "\t[MERGE] internal_flash.dd"
210+
$(Q)dd if=/dev/zero bs=1 count=$$(($(WOLFBOOT_SECTOR_SIZE))) > /tmp/swap
211+
make assemble_internal_flash.dd
212+
210213
factory.bin: $(BINASSEMBLE) wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin
211214
@echo "\t[MERGE] $@"
212215
$(Q)$(BINASSEMBLE) $@ \

test-app/app_sim.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,31 @@ int do_cmd(const char *cmd)
7070
if (strcmp(cmd, "reset") == 0) {
7171
exit(0);
7272
}
73+
if (strncmp(cmd, "get_tlv",7) == 0) {
74+
uint8_t* imageHdr = (uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS;
75+
uint8_t* ptr = NULL;
76+
uint16_t tlv = 0x34; /* default */
77+
int size;
78+
int i;
7379

80+
const char* tlvStr = strstr(cmd, "get_tlv=");
81+
if (tlvStr) {
82+
tlvStr += strlen("get_tlv=");
83+
tlv = (uint16_t)atoi(tlvStr);
84+
}
85+
printf("Get TLV %04x\r\n", tlv);
86+
87+
size = wolfBoot_find_header(imageHdr + IMAGE_HEADER_OFFSET, tlv, &ptr);
88+
if (size >= 0 && ptr != NULL) {
89+
/* From here, the value 0xAABBCCDD is at ptr */
90+
printf("TLV 0x%x:\n", tlv);
91+
for (i=0; i<size; i++) {
92+
printf(" 0x%02X ", ptr[i]);
93+
}
94+
printf("\n");
95+
}
96+
return 0;
97+
}
7498
/* wrong command */
7599
return -1;
76100
}

tools/keytools/sign.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,10 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
10851085
uint32_t i;
10861086
for (i = 0; i < CMD.custom_tlvs; i++) {
10871087
/* require 8-byte alignment */
1088-
while ((header_idx % 8) != 0)
1088+
/* The offset '4' takes into account 2B Tag + 2B Len, so that the
1089+
* Value starts at (addr % 8 == 0) position.
1090+
*/
1091+
while ((header_idx % 8) != 4)
10891092
header_idx++;
10901093

10911094
if (CMD.custom_tlv[i].buffer == NULL) {
@@ -1099,7 +1102,10 @@ static int make_header_ex(int is_diff, uint8_t *pubkey, uint32_t pubkey_sz,
10991102
}
11001103

11011104
/* Add padding bytes. Sha-3 val field requires 8-byte alignment */
1102-
while ((header_idx % 8) != 0)
1105+
/* The offset '4' takes into account 2B Tag + 2B Len, so that the Value
1106+
* starts at (addr % 8 == 0) position.
1107+
*/
1108+
while ((header_idx % 8) != 4)
11031109
header_idx++;
11041110

11051111
/* Calculate hashes */

0 commit comments

Comments
 (0)