diff mbox series

[v2,1/4] board_f.c: Insure gd->new_bootstage alignment

Message ID 20200122135243.17683-2-patrick.delaunay@st.com
State Superseded
Headers show
Series Insure 16 alignment of reserved memory in board_f.c | expand

Commit Message

Patrick Delaunay Jan. 22, 2020, 1:52 p.m. UTC
From: Patrice Chotard <patrice.chotard at st.com>

In reserve_bootstage(), in case size is odd, gd->new_bootstage
is not aligned. In bootstage_relocate(), the platform hangs when
getting access to data->record[i].name.
To avoid this issue, make gd->new_bootstage 16 byte aligned.

To insure that new_bootstage is 16 byte aligned (at least needed for
x86_64 and ARMv8) and new_bootstage starts down to get enough space,
ALIGN_DOWN macro is used.

Fixes: ac9cd4805c8b ("bootstage: Correct relocation algorithm")

Signed-off-by: Patrice Chotard <patrice.chotard at st.com>
Reviewed-by: Vikas MANOCHA <vikas.manocha at st.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay at st.com>
Tested-by: Patrick Delaunay <patrick.delaunay at st.com>
Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
---

Changes in v2:
- import: [U-Boot,v3] board_f.c: Insure gd->new_bootstage alignment

 common/board_f.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Stephen Warren Jan. 22, 2020, 4:53 p.m. UTC | #1
On 1/22/20 6:52 AM, Patrick Delaunay wrote:
> From: Patrice Chotard <patrice.chotard at st.com>
> 
> In reserve_bootstage(), in case size is odd, gd->new_bootstage
> is not aligned. In bootstage_relocate(), the platform hangs when
> getting access to data->record[i].name.
> To avoid this issue, make gd->new_bootstage 16 byte aligned.
> 
> To insure that new_bootstage is 16 byte aligned (at least needed for
> x86_64 and ARMv8) and new_bootstage starts down to get enough space,
> ALIGN_DOWN macro is used.

> diff --git a/common/board_f.c b/common/board_f.c
> index d66afb37ca..e21f533634 100644
> --- a/common/board_f.c
> +++ b/common/board_f.c
> @@ -562,6 +562,11 @@ static int reserve_bootstage(void)
>   	int size = bootstage_get_size();
>   
>   	gd->start_addr_sp -= size;
> +	/*
> +	 * Insure that start_addr_sp is aligned down to reserve enough

Nit: Ensure not insure (a pet peeve of mine!)

> +	 * space for new_bootstage
> +	 */
> +	gd->start_addr_sp = ALIGN_DOWN(gd->start_addr_sp, 16);
>   	gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
>   	debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
>   	      gd->start_addr_sp);
>
Simon Glass Jan. 30, 2020, 2:17 a.m. UTC | #2
On Wed, 22 Jan 2020 at 06:52, Patrick Delaunay <patrick.delaunay at st.com> wrote:
>
> From: Patrice Chotard <patrice.chotard at st.com>
>
> In reserve_bootstage(), in case size is odd, gd->new_bootstage
> is not aligned. In bootstage_relocate(), the platform hangs when
> getting access to data->record[i].name.
> To avoid this issue, make gd->new_bootstage 16 byte aligned.
>
> To insure that new_bootstage is 16 byte aligned (at least needed for
> x86_64 and ARMv8) and new_bootstage starts down to get enough space,
> ALIGN_DOWN macro is used.
>
> Fixes: ac9cd4805c8b ("bootstage: Correct relocation algorithm")
>
> Signed-off-by: Patrice Chotard <patrice.chotard at st.com>
> Reviewed-by: Vikas MANOCHA <vikas.manocha at st.com>
> Reviewed-by: Patrick Delaunay <patrick.delaunay at st.com>
> Tested-by: Patrick Delaunay <patrick.delaunay at st.com>
> Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
> ---
>
> Changes in v2:
> - import: [U-Boot,v3] board_f.c: Insure gd->new_bootstage alignment
>
>  common/board_f.c | 5 +++++
>  1 file changed, 5 insertions(+)

Ensure as Stephen says

With that fixed:

Reviewed-by: Simon Glass <sjg at chromium.org>
diff mbox series

Patch

diff --git a/common/board_f.c b/common/board_f.c
index d66afb37ca..e21f533634 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -562,6 +562,11 @@  static int reserve_bootstage(void)
 	int size = bootstage_get_size();
 
 	gd->start_addr_sp -= size;
+	/*
+	 * Insure that start_addr_sp is aligned down to reserve enough
+	 * space for new_bootstage
+	 */
+	gd->start_addr_sp = ALIGN_DOWN(gd->start_addr_sp, 16);
 	gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
 	debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
 	      gd->start_addr_sp);