From patchwork Wed Apr 8 08:09:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 237388 List-Id: U-Boot discussion From: sr at denx.de (Stefan Roese) Date: Wed, 8 Apr 2020 10:09:35 +0200 Subject: [PATCH 19/26 v6] spl: spl_nor: Copy image header to local struct In-Reply-To: <20200408080942.7694-1-sr@denx.de> References: <20200408080942.7694-1-sr@denx.de> Message-ID: <20200408080942.7694-20-sr@denx.de> From: Weijie Gao The image header may be unaligned causing a crash, e.g. on the MT76x8 platform. This patch copies the header to a local struct to fix this potential issue. Signed-off-by: Weijie Gao Signed-off-by: Stefan Roese Cc: Weijie Gao Cc: Simon Goldschmidt Reviewed-by: Simon Goldschmidt --- Changes in v6: - New patch common/spl/spl_nor.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/spl/spl_nor.c b/common/spl/spl_nor.c index b1e79b9ded..cb8e06fe1f 100644 --- a/common/spl/spl_nor.c +++ b/common/spl/spl_nor.c @@ -27,6 +27,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image, int ret; __maybe_unused const struct image_header *header; __maybe_unused struct spl_load_info load; + struct image_header hdr; + uintptr_t dataptr; /* * Loading of the payload to SDRAM is done with skipping of @@ -112,9 +114,12 @@ static int spl_nor_load_image(struct spl_image_info *spl_image, if (ret) return ret; + /* Payload image may not be aligned, so copy it for safety */ + memcpy(&hdr, (void *)spl_nor_get_uboot_base(), sizeof(hdr)); + dataptr = spl_nor_get_uboot_base() + sizeof(struct image_header); + memcpy((void *)(unsigned long)spl_image->load_addr, - (void *)(spl_nor_get_uboot_base() + sizeof(struct image_header)), - spl_image->size); + (void *)dataptr, spl_image->size); return 0; }