Skip to content

Commit

Permalink
Reducing RAM overhead for OS upgrade/recovery
Browse files Browse the repository at this point in the history
Reducing RAM overhead for OS upgrade/recovery
  • Loading branch information
Catherine Garabedian authored Jun 20, 2019
2 parents 65f5426 + 422543e commit 595ec31
Show file tree
Hide file tree
Showing 8 changed files with 500 additions and 277 deletions.
105 changes: 83 additions & 22 deletions common/image-fit.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,55 @@ int fit_image_get_data(const void *fit, int noffset,
return 0;
}

/**
* Get 'data-offset' property from a given image node.
*
* @fit: pointer to the FIT image header
* @noffset: component image node offset
* @data_offset: holds the data-offset property
*
* returns:
* 0, on success
* -ENOENT if the property could not be found
*/
int fit_image_get_data_offset(const void *fit, int noffset, int *data_offset)
{
const fdt32_t *val;

val = fdt_getprop(fit, noffset, FIT_DATA_OFFSET_PROP, NULL);
if (!val)
return -ENOENT;

*data_offset = fdt32_to_cpu(*val);

return 0;
}

/**
* Get 'data-size' property from a given image node.
*
* @fit: pointer to the FIT image header
* @noffset: component image node offset
* @data_size: holds the data-size property
*
* returns:
* 0, on success
* -ENOENT if the property could not be found
*/
int fit_image_get_data_size(const void *fit, int noffset, int *data_size)
{
const fdt32_t *val;

val = fdt_getprop(fit, noffset, FIT_DATA_SIZE_PROP, NULL);
if (!val)
return -ENOENT;

*data_size = fdt32_to_cpu(*val);

return 0;
}


/**
* fit_image_hash_get_algo - get hash algorithm name
* @fit: pointer to the FIT format image header
Expand Down Expand Up @@ -989,34 +1038,14 @@ static int fit_image_check_hash(const void *fit, int noffset, const void *data,
return 0;
}

/**
* fit_image_verify - verify data integrity
* @fit: pointer to the FIT format image header
* @image_noffset: component image node offset
*
* fit_image_verify() goes over component image hash nodes,
* re-calculates each data hash and compares with the value stored in hash
* node.
*
* returns:
* 1, if all hashes are valid
* 0, otherwise (or on error)
*/
int fit_image_verify(const void *fit, int image_noffset)
int fit_image_verify_with_data(const void *fit, int image_noffset,
const void *data, size_t size)
{
const void *data;
size_t size;
int noffset = 0;
char *err_msg = "";
int verify_all = 1;
int ret;

/* Get image data and data length */
if (fit_image_get_data(fit, image_noffset, &data, &size)) {
err_msg = "Can't get image data/size";
goto error;
}

/* Verify all required signatures */
if (IMAGE_ENABLE_VERIFY &&
fit_image_verify_required_sigs(fit, image_noffset, data, size,
Expand Down Expand Up @@ -1073,6 +1102,38 @@ int fit_image_verify(const void *fit, int image_noffset)
return 0;
}

/**
* fit_image_verify - verify data integrity
* @fit: pointer to the FIT format image header
* @image_noffset: component image node offset
*
* fit_image_verify() goes over component image hash nodes,
* re-calculates each data hash and compares with the value stored in hash
* node.
*
* returns:
* 1, if all hashes are valid
* 0, otherwise (or on error)
*/
int fit_image_verify(const void *fit, int image_noffset)
{
const void *data;
size_t size;
int noffset = 0;
char *err_msg = "";

/* Get image data and data length */
if (fit_image_get_data(fit, image_noffset, &data, &size)) {
err_msg = "Can't get image data/size";
printf("error!\n%s for '%s' hash node in '%s' image node\n",
err_msg, fit_get_name(fit, noffset, NULL),
fit_get_name(fit, image_noffset, NULL));
return 0;
}

return fit_image_verify_with_data(fit, image_noffset, data, size);
}

/**
* fit_all_image_verify - verify data integrity for all images
* @fit: pointer to the FIT format image header
Expand Down
8 changes: 4 additions & 4 deletions common/spl/spl_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int spl_load_image_ext(struct blk_desc *block_dev,
puts("spl: ext4fs_open failed\n");
goto end;
}
err = ext4fs_read((char *)header, sizeof(struct image_header), &actlen);
err = ext4fs_read((char *)header, 0, sizeof(struct image_header), &actlen);
if (err < 0) {
puts("spl: ext4fs_read failed\n");
goto end;
Expand All @@ -54,7 +54,7 @@ int spl_load_image_ext(struct blk_desc *block_dev,
goto end;
}

err = ext4fs_read((char *)spl_image.load_addr, filelen, &actlen);
err = ext4fs_read((char *)spl_image.load_addr, 0, filelen, &actlen);

end:
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Expand Down Expand Up @@ -96,7 +96,7 @@ int spl_load_image_ext_os(struct blk_desc *block_dev, int partition)
puts("spl: ext4fs_open failed\n");
goto defaults;
}
err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen);
err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, filelen, &actlen);
if (err < 0) {
printf("spl: error reading image %s, err - %d, falling back to default\n",
file, err);
Expand Down Expand Up @@ -125,7 +125,7 @@ int spl_load_image_ext_os(struct blk_desc *block_dev, int partition)
if (err < 0)
puts("spl: ext4fs_open failed\n");

err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen);
err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, filelen, &actlen);
if (err < 0) {
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
printf("%s: error reading image %s, err - %d\n",
Expand Down
Loading

0 comments on commit 595ec31

Please sign in to comment.