aboutsummaryrefslogtreecommitdiff
path: root/common/spl/spl.c
diff options
context:
space:
mode:
authorSimon Goldschmidt <simon.k.r.goldschmidt@gmail.com>2019-02-10 21:34:37 +0100
committerTom Rini <trini@konsulko.com>2019-02-19 08:55:43 -0500
commitdae5c2dcdc2bc826a4ee0a58b08fd004b6259373 (patch)
treecce328236d6aca49467c14efe6d8e7e06849d5dd /common/spl/spl.c
parent8502fe84a4fc1eb5610b1dbb102ff11b02aee25f (diff)
downloadu-boot-dae5c2dcdc2bc826a4ee0a58b08fd004b6259373.zip
u-boot-dae5c2dcdc2bc826a4ee0a58b08fd004b6259373.tar.gz
u-boot-dae5c2dcdc2bc826a4ee0a58b08fd004b6259373.tar.bz2
spl: implement CRC check on U-Boot uImage
SPL currently does not check uImage CRCs when loading U-Boot. This patch adds checking the uImage CRC when SPL loads U-Boot. It does this by reusing the existing config option SPL_CRC32_SUPPORT to allow leaving out the CRC check on boards where the additional code size or boot time is a problem (adding the CRC check currently adds ~1.4 kByte to flash). The SPL_CRC32_SUPPORT config option now gets enabled by default if SPL support for legacy images is enabled to check the CRC on all boards that don't actively take countermeasures. Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/spl/spl.c')
-rw-r--r--common/spl/spl.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 35120b6..2e2af1b 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -239,6 +239,14 @@ int spl_parse_image_header(struct spl_image_info *spl_image,
#ifdef CONFIG_SPL_LEGACY_IMAGE_SUPPORT
u32 header_size = sizeof(struct image_header);
+#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
+ /* check uImage header CRC */
+ if (!image_check_hcrc(header)) {
+ puts("SPL: Image header CRC check failed!\n");
+ return -EINVAL;
+ }
+#endif
+
if (spl_image->flags & SPL_COPY_PAYLOAD_ONLY) {
/*
* On some system (e.g. powerpc), the load-address and
@@ -256,6 +264,13 @@ int spl_parse_image_header(struct spl_image_info *spl_image,
spl_image->size = image_get_data_size(header) +
header_size;
}
+#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
+ /* store uImage data length and CRC to check later */
+ spl_image->dcrc_data = image_get_load(header);
+ spl_image->dcrc_length = image_get_data_size(header);
+ spl_image->dcrc = image_get_dcrc(header);
+#endif
+
spl_image->os = image_get_os(header);
spl_image->name = image_get_name(header);
debug(SPL_TPL_PROMPT
@@ -495,12 +510,25 @@ static struct spl_image_loader *spl_ll_find_loader(uint boot_device)
static int spl_load_image(struct spl_image_info *spl_image,
struct spl_image_loader *loader)
{
+ int ret;
struct spl_boot_device bootdev;
bootdev.boot_device = loader->boot_device;
bootdev.boot_device_name = NULL;
- return loader->load_image(spl_image, &bootdev);
+ ret = loader->load_image(spl_image, &bootdev);
+#ifdef CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK
+ if (!ret && spl_image->dcrc_length) {
+ /* check data crc */
+ ulong dcrc = crc32_wd(0, (unsigned char *)spl_image->dcrc_data,
+ spl_image->dcrc_length, CHUNKSZ_CRC32);
+ if (dcrc != spl_image->dcrc) {
+ puts("SPL: Image data CRC check failed!\n");
+ ret = -EINVAL;
+ }
+ }
+#endif
+ return ret;
}
/**