From owner-freebsd-arm@freebsd.org Sun Dec 24 01:36:00 2017 Return-Path: Delivered-To: freebsd-arm@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D5666E8B1F5 for ; Sun, 24 Dec 2017 01:36:00 +0000 (UTC) (envelope-from markmi@dsl-only.net) Received: from asp.reflexion.net (outbound-mail-210-95.reflexion.net [208.70.210.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 919C712ED for ; Sun, 24 Dec 2017 01:35:59 +0000 (UTC) (envelope-from markmi@dsl-only.net) Received: (qmail 22203 invoked from network); 23 Dec 2017 22:49:13 -0000 Received: from unknown (HELO rtc-sm-01.app.dca.reflexion.local) (10.81.150.1) by 0 (rfx-qmail) with SMTP; 23 Dec 2017 22:49:13 -0000 Received: by rtc-sm-01.app.dca.reflexion.local (Reflexion email security v8.40.3) with SMTP; Sat, 23 Dec 2017 17:49:13 -0500 (EST) Received: (qmail 14159 invoked from network); 23 Dec 2017 22:49:12 -0000 Received: from unknown (HELO iron2.pdx.net) (69.64.224.71) by 0 (rfx-qmail) with (AES256-SHA encrypted) SMTP; 23 Dec 2017 22:49:12 -0000 Received: from [192.168.1.25] (c-76-115-7-162.hsd1.or.comcast.net [76.115.7.162]) by iron2.pdx.net (Postfix) with ESMTPSA id 348B2EC8171; Sat, 23 Dec 2017 14:49:12 -0800 (PST) From: Mark Millard Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: UEFI booting survey [and compared ubldr.bin booting behavior] Date: Sat, 23 Dec 2017 14:49:11 -0800 References: <60C20606-853E-43AE-9F90-44C65026A098@dsl-only.net> <2822699E-DDD5-4604-8567-974AE30659A3@dsl-only.net> <6EFC9D27-02B8-4441-9B9B-E380EFECED78@dsl-only.net> To: Warner Losh , FreeBSD Current , freebsd-arm@freebsd.org In-Reply-To: <6EFC9D27-02B8-4441-9B9B-E380EFECED78@dsl-only.net> Message-Id: <6F3E827F-CACD-4117-80DA-BC9A59604760@dsl-only.net> X-Mailer: Apple Mail (2.3273) X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Dec 2017 01:36:01 -0000 [Just adding notes about what ubldr.bin does with and without loaderdev being specified (correctly). Overall it does not appear to me that the ubldr.bin based contexts can fully avoid the "systems with multiple partitions that might be right" issue.] On 2017-Dec-20, at 2:47 AM, Mark Millard wrote: > On 2017-Dec-19, at 9:10 PM, Warner Losh wrote: >=20 >> On Tue, Dec 19, 2017 at 9:06 PM, Mark Millard wrote: >> [The usdcard in my rpi2 example does not contain any kernel files, >> nor any dtb files. Only the USB SSD stick does. The kernel and dtb >> do not come from the usdcard. This is what I'm not sure if it is >> generally supported or not.] >>=20 >> On 2017-Dec-19, at 7:26 PM, Warner Losh wrote: >>=20 >>> On Dec 19, 2017 4:26 PM, "Mark Millard" = wrote: >>>>=20 >>>>> . . . >>>>> It sounds different then the results I get with ubldr.bin >>>>> on a rpi2 V1.1 . With the usdcard having a UFS / with >>>>> basically only: >>>>>=20 >>>>> /etc/fstab (redirecting to a USB SSD stick) >>>>> /boot/* (with /boot/kernel/ empty and /boot/dtb/ empty) >>>>>=20 >>>>> the result is that all 3 of the following come from the >>>>> USB SSD stick based on the "/" line from the /etc/fstab >>>>> from the usdcard: >>>>>=20 >>>>> /boot/kernel >>>>> /boot/dtb/bcm2836-rpi-2-b.dtb >>>>> / (mounted root file system) >>>>>=20 >>>>> In other words: it appears that for ubldr.bin on >>>>> a rpi2 V1.1 /etc/fstab is read and used before >>>>> finding the kernel that is to be loaded. (It or >>>>> another /etc/fstab may be read again later.) >>>>>=20 >>>>> It is read. It is literally only used to set the root for = userland. That is all. Nothing else. >>>>>=20 >>>>> /usr/src/stand/common/boot.c does show an explicit >>>>> attempt to find a /etc/fstab: >>>>>=20 >>>>> # grep -r /etc/fstab /usr/src/stand/ >>>>> . . . >>>>> /usr/src/stand/common/boot.c: * Try to find the /etc/fstab file on = the filesystem (rootdev), >>>>> /usr/src/stand/common/boot.c: sprintf(lbuf, "%s/etc/fstab", = rootdev); >>>>> . . . >>>>>=20 >>>>> That is from getrootmount(char *rootdev): >>>>>=20 >>>>> int >>>>> getrootmount(char *rootdev) >>>>> { >>>>> char lbuf[128], *cp, *ep, *dev, *fstyp, *options; >>>>> int fd, error; >>>>>=20 >>>>> if (getenv("vfs.root.mountfrom") !=3D NULL) >>>>> return(0); >>>>>=20 >>>>> So if you set vfs.root.mountfrom in /boot/loader.conf, we don't = read rootdev:/etc/fstab for the value to set vfs.root.mountfrom to. >>>>>=20 >>>>> error =3D 1; >>>>> sprintf(lbuf, "%s/etc/fstab", rootdev); >>>>> if ((fd =3D open(lbuf, O_RDONLY)) < 0) >>>>> goto notfound; >>>>> . . . >>>>>=20 >>>>> Supporting detail for the example rpi2 >>>>> boot context: >>>>>=20 >>>>> With /mnt being the / from the usdcard: >>>>>=20 >>>>> # find /mnt -print | more >>>>> /mnt >>>>> /mnt/.snap >>>>> /mnt/boot >>>>> /mnt/boot/defaults >>>>> /mnt/boot/defaults/loader.conf >>>>> /mnt/boot/dtb >>>>> /mnt/boot/firmware >>>>> /mnt/boot/kernel >>>>> /mnt/boot/modules >>>>> /mnt/boot/zfs >>>>> /mnt/boot/msdos >>>>> /mnt/boot/entropy >>>>> /mnt/boot/menu.rc.sample >>>>> /mnt/boot/ubldr >>>>> /mnt/boot/ubldr.bin >>>>> /mnt/boot/brand-fbsd.4th >>>>> /mnt/boot/logo-beastie.4th >>>>> /mnt/boot/logo-beastiebw.4th >>>>> /mnt/boot/logo-fbsdbw.4th >>>>> /mnt/boot/logo-orb.4th >>>>> /mnt/boot/logo-orbbw.4th >>>>> /mnt/boot/loader.conf >>>>> /mnt/boot/loader.efi >>>>> /mnt/boot/boot1.efi >>>>> /mnt/boot/boot1.efifat >>>>> /mnt/boot/beastie.4th >>>>> /mnt/boot/brand.4th >>>>> /mnt/boot/color.4th >>>>> /mnt/boot/check-password.4th >>>>> /mnt/boot/delay.4th >>>>> /mnt/boot/frames.4th >>>>> /mnt/boot/loader.4th >>>>> /mnt/boot/loader.help >>>>> /mnt/boot/menu.4th >>>>> /mnt/boot/menu-commands.4th >>>>> /mnt/boot/menusets.4th >>>>> /mnt/boot/screen.4th >>>>> /mnt/boot/shortcuts.4th >>>>> /mnt/boot/support.4th >>>>> /mnt/boot/version.4th >>>>> /mnt/boot/loader.rc >>>>> /mnt/boot/efi.4th >>>>> /mnt/boot/pcibios.4th >>>>> /mnt/boot/menu.rc >>>>> /mnt/etc >>>>> /mnt/etc/fstab >>>>> /mnt/COPYRIGHT >>>>> /mnt/lost+found >>>>>=20 >>>>> # more /mnt/etc/fstab >>>>> /dev/da0p1 / ufs rw,noatime 1 1 >>>>> /dev/da0p2 none swap sw 0 0 >>>>>=20 >>>>> May be this is somehow special to the rpi2 or to >>>>> ubldr.bin operation. (I've never managed to identify >>>>> accidents from deliberately working status in this >>>>> area.) >>>>>=20 >>>> So you load /boot/loader and the kernel from the sdcard. >>>=20 >>> No: There are no kernel files on the usdcard. See the complete >>> file list of its only UFS partition above. No dtb files either. >>>=20 >>> [On a rpi2 ubldr.bin is copied to the msdosfs, where it >>> is actually put to use.] >>=20 >> OK. Looks like the uboot code has the same bogus 'let's search = everything' code that I'm removing from the UEFI case. >=20 > Could be. My case was so limited that it does not show if > the search would continue if multiple USB drives were > present vs. stopping at the first even if the files would > not be found there (for example). >=20 >> Still doesn't get anything from /etc/fstab. It can't. There's no = translation code in the boot loader to try to guess. It just does a = bruit force plow through all the devices and hopes for the best. >=20 > Just FYI, the /usr/src/stand/common/boot.c comments say about > the /etc/fstab use: >=20 > * Try to find the /etc/fstab file on the filesystem (rootdev), > * which should be be the root filesystem, and parse it to find > * out what the kernel ought to think the root filesystem is. > * > * If we're successful, set vfs.root.mountfrom to : > * so that the kernel can tell both which VFS and which node to use > * to mount the device. If this variable's already set, don't > * overwrite it. > . . . > /* Build the : and save it in = vfs.root.mountfrom */ >=20 > This would fit with your description: finding any > kernel, as you have described, and then feeding it > the : text to find other things. >=20 > [I have not yet identified the code that goes looking > around for the first /boot/kernel/kernel that it > can find that appears to be some form of kernel.] >=20 >>>> /etc/fstab on the card points to the usb drive for /. >>>=20 >>> True. And that is were the kernel and dtb come from, >>> not the usdcard. >>=20 >> Right, but that's not how ubldr finds them. >=20 > If the kernel loads the dtb file, it might use the > : that it was given to find > /boot/dtb/ to look up the dtb file? >=20 > (That would still leave an arbitrary kernel being > loaded first if more than one is around.) >=20 >>> For reference loader.config has: >>>=20 >>> # more /mnt/boot/loader.conf >>> geom_label_load=3D"YES" # File system labels (see = glabel(8)) >>> # >>> kern.cam.boot_delay=3D"10000" >>> vfs.mountroot.timeout=3D"10" >>> dumpdev=3D"/dev/da0p2" >>>=20 >>> (So no vfs.root.mountfrom .) >>=20 >> What does config.txt have? >=20 > The rpi2 CONFIG.TXT on the msdosfs has: >=20 > # more /media/CONFIG.TXT > init_uart_clock=3D3000000 > enable_uart=3D1 > kernel=3Du-boot.bin > kernel7=3Du-boot.bin >=20 > (Unchanged by me: simply copied over from > the sysutils materials for the rpi2.) >=20 >>>> This is all standard loader behavior. >>>=20 >>> I'm not sure avoiding the kernel and dtb being on the usdcard >>> is standard-supported behavior. It might be a lucky, >>> limited-context accident rather than a general property as a >>> technique. >=20 > Looks like not-desired in its current form. >=20 >>>> It won't change. In your case, you aren't even using UEFI, so it = doubly won't change. >>>=20 >>> I also have access to an rpi3 and a pine64+ 2GB, which are >>> UEFI based. But I'd not yet tried a similar configuration >>> to what I'd recently done on the rpi2 V1.1 . >>>=20 >>> The list notices made me unsure if I should even try. It >>> is this part that I'm trying to figure out, both for now >>> and for after the changes. >>=20 >> You should try, but you may need one additional line to explicitly = declare things. >>=20 >>>> UEFI has more direct ways of doing this, but this setup would work = there because it is explicit. It doesn't depend on the current boot1.efi = behavior... >>>=20 >>> The lack of depending on the "random order" status may well >>> be true. >>>=20 >>> But I'm still not sure if the the lack of a kernel and dtb >>> file on the usdcard puts the technique out of bounds for >>> the rpi2 and pine64+ 2GB. >=20 > [That last rpi2 should have been a rpi3.] >=20 >> I think this is more of the same bogus random order behavior that's = making your stuff word accidentally. Since ubldr is being phased out, I = have no plans to change it. >=20 >> But as someone that deploys systems with multiple partitions that = might be right, I hate random :( >=20 > Understandable. >=20 >> Warner >=20 > Thanks much. I understand a bit more now. >=20 >>> Warner >>>>=20 >>>>>> (For my particular interest the context uses UFS, not >>>>>> ZFS.) >>>>>>=20 >>>>>>> What is being deleted is one final step: "otherwise use the = first UFS partition on any drive in a random order that's usable." which = used to be at the end of the boot1.efi psuedo code. It's my belief that = no such installations actually use this due to the random factor today = (plug in a new USB drive and it might take over). If my belief is wrong, = it's my belief that efibootmgr will solve it, and failing that, the = fallback mechanism (for platforms that use u-boot + EFI where UEFI = variables don't work) will allow the two or three people that are doing = this today. >>>>>>=20 >>>>>=20 >>>=20 Looking at the ubldr.bin code it appears that the only way to avoid the ubldr.bin "find first in some order" is to have set loaderdev to indicate where to get the loader scripts and kernel from. Otherwise it will do the general probing, for example: . . . FreeBSD/armv7 U-Boot loader, Revision 1.2 DRAM: 948MB Number of U-Boot devices: 3 U-Boot env: loaderdev not set, will probe all devices. Found U-Boot device: disk Probing all disk devices... Checking unit=3D0 slice=3D partition=3D... good. Booting from disk0p1: . . . Matches up with: . . . device_types[] =3D { { "disk", DEV_TYP_STOR }, { "ide", DEV_TYP_STOR | DT_STOR_IDE }, { "mmc", DEV_TYP_STOR | DT_STOR_MMC }, { "sata", DEV_TYP_STOR | DT_STOR_SATA }, { "scsi", DEV_TYP_STOR | DT_STOR_SCSI }, { "usb", DEV_TYP_STOR | DT_STOR_USB }, { "net", DEV_TYP_NET } }; . . . /* * Parse a device string into type, unit, slice and partition numbers. A * returned value of -1 for type indicates a search should be done for = the * first loadable device, otherwise a returned value of -1 for unit * indicates a search should be done for the first loadable device of = the * given type. * =20 * The returned values for slice and partition are interpreted by * disk_open(). =20 * * Valid device strings: For device types: * * DEV_TYP_STOR, DEV_TYP_NET * DEV_TYP_STOR, DEV_TYP_NET * : DEV_TYP_STOR, DEV_TYP_NET * : DEV_TYP_STOR * :. DEV_TYP_STOR * :. DEV_TYP_STOR * * For valid type names, see the device_types array, above. * =20 * Slice numbers are 1-based. 0 is a wildcard. */ =20 static void get_load_device(int *type, int *unit, int *slice, int *partition) { char *devstr; const char *p; char *endp; =20 *type =3D -1; *unit =3D -1; *slice =3D 0; *partition =3D -1; =20 devstr =3D ub_env_get("loaderdev"); if (devstr =3D=3D NULL) { printf("U-Boot env: loaderdev not set, will probe all = devices.\n"); return; } printf("U-Boot env: loaderdev=3D'%s'\n", devstr); . . . It appears that loaderdev's notation depends on the : having a stable interpretation if it is to avoid picking different things based on what combination of other devices happen to be plugged in at the time. Stablility require binding, say, a unit 0 to a specific place even when the place was not populated. (Unlikely?) This suggests that notation is specific to each device type. But I'm not aware of a place to go look up a device type and get a definition for how will be bound to plugged in devices. It is not clear to me what happens with in the notation when the : identifies something with just, say, gpt partitioning. (No slice layer.) Listing 0 (the slice wildcard) could match a device with some non-gpt structure. An explicit, say, 1 could as well but would also have no slice to refer to for gpt partitioning. Overall it does not appear to me that the ubldr.bin based contexts can fully avoid the "systems with multiple partitions that might be right" issue when what is connected can change from boot to boot: There just is not the right kind of context for avoiding the issue. Still an explicit loaderdev use in some styles of usage could make mismatches less likely. =3D=3D=3D Mark Millard markmi at dsl-only.net