[PATCH master v2 1/2] ARM: MXS: fix breakage for non-DT boards

Sascha Hauer sha at pengutronix.de
Tue Oct 11 03:53:18 PDT 2022


On Tue, Oct 11, 2022 at 12:33:17PM +0200, Ahmad Fatoum wrote:
> boarddata, the third argument passed from barebox PBL to barebox proper,
> is usually either a pointer to an optionally compressed flattened device tree
> or a machien type integer casted to a pointer.
> 
> In order to support device trees located in the first 8192 bytes of
> address space, barebox has been trying to dereference boarddata, before
> falling back to treating it as integer.
> 
> This resulted in breakage as boarddata may be an integer not divisible
> by 4 and thus an unaligned exception would occur.
> 
> The already existing barebox_arm_boarddata mechanism sidesteps this
> issue: With it, the machine type integer is not passed as is, but the
> address of a suitably aligned structure that contains it is passed
> instead.
> 
> Searching for MACH_TYPE in arch/arm/boards shows 5 boards to be
> affected in-tree, which are all fixed with this commit.
> 
> Fixes: 390bc7834ffc ("ARM: start: check for machine type last")
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> v1 -> v2:
>   - Do full relocation instead of get_runtime_offset(). This is
>     required, because GCC[1] generated a pc-relative reference
>     to boarddata as it's in the same translation unit and as
>     such get_runtime_offset() being added was wrong.
>     Instead of relying on compiler whims, we instead set up
>     a full C environment and play it safe.
>   -  s/MACHINE_TYPE/MACH_TYPE/ (Bastian)
> 
> [1]: OSELAS.Toolchain-2021.07.0/arm-v7a-linux-gnueabihf/gcc-11.1.1
> ---
>  arch/arm/boards/chumby_falconwing/lowlevel.c     | 11 ++++++++++-
>  arch/arm/boards/crystalfontz-cfa10036/lowlevel.c | 11 ++++++++++-
>  arch/arm/boards/freescale-mx23-evk/lowlevel.c    | 11 ++++++++++-
>  arch/arm/boards/imx233-olinuxino/lowlevel.c      | 10 +++++++++-
>  arch/arm/boards/karo-tx28/lowlevel.c             | 10 +++++++++-
>  5 files changed, 48 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm/boards/chumby_falconwing/lowlevel.c b/arch/arm/boards/chumby_falconwing/lowlevel.c
> index 091dd1955260..d2059c8f7808 100644
> --- a/arch/arm/boards/chumby_falconwing/lowlevel.c
> +++ b/arch/arm/boards/chumby_falconwing/lowlevel.c
> @@ -7,8 +7,17 @@
>  #include <mach/imx23-regs.h>
>  #include <generated/mach-types.h>
>  
> +static struct barebox_arm_boarddata boarddata = {
> +	.magic = BAREBOX_ARM_BOARDDATA_MAGIC,
> +	.machine = MACH_TYPE_CHUMBY,
> +};
> +
>  ENTRY_FUNCTION(start_chumby_falconwing, r0, r1, r2)
>  {
>  	arm_cpu_lowlevel_init();
> -	barebox_arm_entry(IMX_MEMORY_BASE, SZ_64M, (void *)MACH_TYPE_CHUMBY);
> +
> +	relocate_to_current_adr();
> +	setup_c();
> +
> +	barebox_arm_entry(IMX_MEMORY_BASE, SZ_64M, &boarddata);

Please jump to an explicitly non inlined function after setup_c() to
make sure we access &boarddata in a proper C environment. Otherwise we
do not know if the pointer is dereferenced before or after setup_c().

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 |



More information about the barebox mailing list