From: Sascha Hauer <sha@pengutronix.de>
To: Thaison Phan <tsphan42@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] Patch to fix bootm barebox load address alignment to acomodate ADRP instruction
Date: Thu, 8 Feb 2024 08:30:32 +0100 [thread overview]
Message-ID: <ZcSDGHbcInKvmR-x@pengutronix.de> (raw)
In-Reply-To: <CAFPn3sTc_3q04koG_oPnqTmhGnejxtiva+B5KwYsCdC3czCmKw@mail.gmail.com>
Hi Thaison,
On Tue, Feb 06, 2024 at 09:37:47PM -0500, Thaison Phan wrote:
> Hi,
>
> The aarch64 bootm image handler for barebox can choose a load address
> that is not 4KB aligned. This can result in unexpected behavior with
> the ADRP instruction that is available in 64 bit ARM architectures.
> ADRP forms a PC-relative address to a 4KB page where the bottom 12
> bits of the current PC will be masked out. When the load address of
> the barebox image is not 4KB aligned ADRP can end up forming an
> address that starts from an invalid page of memory or the wrong page
> of memory that was expected to be formed. The following patch aligns
> the load address for the next barebox image to be 4KB aligned to
> accommodate the ADRP instruction.
>
> Thanks,
> Thaison
>
> ---
> arch/arm/lib64/armlinux.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/lib64/armlinux.c b/arch/arm/lib64/armlinux.c
> index 8382ffdf1b..d66963dae5 100644
> --- a/arch/arm/lib64/armlinux.c
> +++ b/arch/arm/lib64/armlinux.c
> @@ -43,6 +43,8 @@ static struct image_handler aarch64_fit_handler = {
> .filetype = filetype_oftree,
> };
>
> +#define ADRP_PAGE_MASK 0x1000
> +
> static int do_bootm_barebox(struct image_data *data)
> {
> void (*fn)(unsigned long x0, unsigned long x1, unsigned long x2,
> @@ -55,7 +57,7 @@ static int do_bootm_barebox(struct image_data *data)
> if (ret)
> goto out;
>
> - barebox = start;
> + barebox = ALIGN(start, ADRP_PAGE_MASK);
I'd suggest using PAGE_ALIGN here.
While I agree that the barebox image must be page aligned to be
correctly started, I wonder how it can happen that the address returned
from memory_bank_first_find_space() is not page aligned. Normally this
should be the start address of your DRAM. How comes this address is not
aligned in your case?
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2024-02-08 7:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-07 2:37 [PATCH] Patch to fix bootm barebox load address alignment to acomodate ADRP instruction Thaison Phan
2024-02-08 7:30 ` Sascha Hauer [this message]
2024-02-09 1:44 ` Thaison Phan
2024-03-01 9:25 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZcSDGHbcInKvmR-x@pengutronix.de \
--to=sha@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=tsphan42@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.