Skip to content

Commit

Permalink
Merge pull request #532 from danielinux/sign-delta-base-from-header
Browse files Browse the repository at this point in the history
Sign tool: use manifest header to retrieve base version
  • Loading branch information
dgarske authored Dec 30, 2024
2 parents b8a23b1 + afcdefa commit 4a6d309
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions tools/keytools/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,13 +1743,13 @@ static int base_diff(const char *f_base, uint8_t *pubkey, uint32_t pubkey_sz, in
int r;
uint32_t patch_sz, patch_inv_sz;
uint32_t patch_inv_off;
uint32_t delta_base_version = 0;
char *base_ver_p, *base_ver_e;
uint32_t *delta_base_version = NULL;
uint16_t delta_base_version_sz = 0;
WB_DIFF_CTX diff_ctx;
int ret = -1;
int io_sz;
uint8_t *base_hash = NULL;
uint32_t base_hash_sz = 0;
uint16_t base_hash_sz = 0;
uint32_t wolfboot_sector_size = 0;
uint32_t blksz;

Expand Down Expand Up @@ -1804,24 +1804,12 @@ static int base_diff(const char *f_base, uint8_t *pubkey, uint32_t pubkey_sz, in
#endif

/* Check base image version */
base_ver_p = strstr(f_base, "_v");
if (base_ver_p) {
base_ver_p += 2;
base_ver_e = strchr(base_ver_p, '_');
if (base_ver_e) {
long long retval;
retval = strtoll(base_ver_p, NULL, 10);
if (retval < 0)
delta_base_version = 0;
else
delta_base_version = (uint32_t)(retval&0xFFFFFFFF);
}
}
if (delta_base_version == 0) {
delta_base_version_sz = sign_tool_find_header((uint8_t *)base + 8, HDR_VERSION, (void *)&delta_base_version);
if ((delta_base_version_sz != sizeof(uint32_t)) || (*delta_base_version == 0)) {
printf("Could not read firmware version from base file %s\n", f_base);
goto cleanup;
} else {
printf("Delta base version: %u\n", delta_base_version);
printf("Delta base version: %u\n", *delta_base_version);
}

/* Retrieve the hash digest of the base image */
Expand Down Expand Up @@ -1986,7 +1974,7 @@ static int base_diff(const char *f_base, uint8_t *pubkey, uint32_t pubkey_sz, in
/* Create delta file, with header, from the resulting patch */

ret = make_header_delta(pubkey, pubkey_sz, wolfboot_delta_file, CMD.output_diff_file,
delta_base_version, patch_sz, patch_inv_off, patch_inv_sz, base_hash, base_hash_sz);
*delta_base_version, patch_sz, patch_inv_off, patch_inv_sz, base_hash, base_hash_sz);

cleanup:
if (dest) {
Expand Down

0 comments on commit 4a6d309

Please sign in to comment.