Re: head -r538966 on OrangePi+ 2ed: boot loader crashes when USB drive is present at power-on/boot: its a misaligned access by code from -r354746

From: Mark Millard <marklmi_at_yahoo.com>
Date: Thu, 19 Mar 2020 10:16:49 -0700
On 2020-Mar-19, at 02:00, Toomas Soome <tsoome_at_me.com> wrote:

> I think this should fix it. We need to create copy of dos partition array, so we will get proper alignment. 
> 
> 
> tsoome_at_freebsd-2:/usr/src % svn diff stand/common/part.c
> Index: stand/common/part.c
> ===================================================================
> --- stand/common/part.c	(revision 359099)
> +++ stand/common/part.c	(working copy)
> _at__at_ -654,6 +654,7 _at__at_
>  	int has_ext;
>  #endif
>  	table = NULL;
> +	dp = NULL;
>  	buf = malloc(sectorsize);
>  	if (buf == NULL)
>  		return (NULL);
> _at__at_ -708,7 +709,11 _at__at_
>  		goto out;
>  	}
>  	/* Check that we have PMBR. Also do some validation. */
> -	dp = (struct dos_partition *)(buf + DOSPARTOFF);
> +	dp = malloc(NDOSPART * sizeof(struct dos_partition));
> +	if (dp == NULL)
> +		goto out;
> +	bcopy(buf + DOSPARTOFF, dp, NDOSPART * sizeof(struct dos_partition));
> +
>  	/*
>  	 * In mac we can have PMBR partition in hybrid MBR;
>  	 * that is, MBR partition which has DOSPTYP_PMBR entry defined as
> _at__at_ -770,6 +775,7 _at__at_
>  #endif /* LOADER_MBR_SUPPORT */
>  #endif /* LOADER_MBR_SUPPORT || LOADER_GPT_SUPPORT */
>  out:
> +	free(dp);
>  	free(buf);
>  	return (table);
>  }
> tsoome_at_freebsd-2:/usr/src %

That is working for me: the OPi+2e now boots with the
USB drive plugged in ahead of time, without manual
intervention to assign loaderdev :

FreeBSD/armv7 U-Boot loader, Revision 1.3

DRAM: 2048MB
Number of U-Boot devices: 2
U-Boot env: loaderdev not set, will probe all devices.
Found U-Boot device: disk
  Probing all <unknown> devices...
  Checking unit=0 slice=<auto> partition=<auto>... good.
Booting from disk0p1:
Loading /boot/defaults/loader.conf
Loading /boot/device.hints
Loading /boot/loader.conf
Loading /boot/loader.conf.local
Loading kernel...
/boot/kernel/kernel text=0x90b3fc data=0xa85a8 data=0x0+0x200000 syms=[0x4+0xa1660+0x4+0x113e7c]
Loading configured modules...
/boot/kernel/umodem.ko text=0x1520 text=0xf10 data=0x234+0x4 syms=[0x4+0xe70+0x4+0xa74]
loading required module 'ucom'
/boot/kernel/ucom.ko text=0x1714 text=0x2c7c data=0x484+0x838 syms=[0x4+0x13e0+0x4+0xbac]
/boot/entropy size=0x1000

Hit [Enter] to boot immediately, or any other key for command prompt.
. . .

Thanks!

> . . .


===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)
Received on Thu Mar 19 2020 - 16:17:00 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:23 UTC