Bug 230804 - [loader] dtb overlays seems to corrupt the kernel env
Summary: [loader] dtb overlays seems to corrupt the kernel env
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: CURRENT
Hardware: arm64 Any
: --- Affects Only Me
Assignee: Kyle Evans
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-21 17:42 UTC by Emmanuel Vadot
Modified: 2018-08-25 15:31 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Emmanuel Vadot freebsd_committer freebsd_triage 2018-08-21 17:42:08 UTC
When using multiple overlays it seems that it corrupts the kenv.

Using the latest pine64 image with a dtb loaded by u-boot from the FAT partition (otherwise we can't use the overlays) and some overlays I got :

Hit [Enter] to boot immediately, or any other key for command prompt.
Booting [/boot/kernel/kernel]...
Using DTB provided by EFI at 0x47ff9000.
Loading DTB overlays: 'sun50i-a64-sid,sun50i-a64-ths,sun50i-a64-timer'
/boot/dtb/overlays/sun50i-a64-sid.dtbo size=0x1fd
/boot/dtb/overlays/sun50i-a64-ths.dtbo size=0x3e8
/boot/dtb/overlays/sun50i-a64-timer.dtbo size=0x175
applying DTB overlay '/boot/dtb/overlays/sun50i-a64-sid.dtbo'
applying DTB overlay '/boot/dtb/overlays/sun50i-a64-ths.dtbo'
applying DTB overlay '/boot/dtb/overlays/sun50i-a64-timer.dtbo'
EHCI failed to shut down host controller.
---<<BOOT>>---
KDB: debugger backends: ddb
KDB: current backend: ddb
Copyright (c) 1992-2018 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
        The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 12.0-ALPHA2 #1291 r338074+327bec90b971(aw_timer)-dirty: Tue Aug 21 18:42:59 CEST 2018
    manu@skull.home.blih.net:/usr/home/manu/Work/freebsd/obj/usr/home/manu/Work/freebsd/freebsd.git/arm64.aarch64/sys/GENERIC arm64
FreeBSD clang version 6.0.1 (tags/RELEASE_601/final 335540) (based on LLVM 6.0.1)
WARNING: WITNESS option enabled, expect reduced performance.
VT: init without driver.
WARNING: malformed static env value, ignoring interrupts
WARNING: malformed static env value, ignoring clocks
WARNING: malformed static env value, ignoring clock-names
WARNING: malformed static env value, ignoring resets
WARNING: malformed static env value, ignoring reset-names
WARNING: malformed static env value, ignoring #thermal-sensor-cells
WARNING: malformed static env value, ignoring status
WARNING: malformed static env value, ignoring nvmem-cells
WARNING: malformed static env value, ignoring nvmem-cell-names
WARNING: malformed static env value, ignoring phandle
WARNING: malformed static env value, ignoring ths
WARNING: malformed static env value, ignoring ccu
WARNING: malformed static env value, ignoring ths_calib
WARNING: malformed static env value, ignoring
KLD file umodem.ko is missing dependencies


kenv doesn't show anything and the kernel doesn't know the root filesystem, resulting in prompting to mountroot.

The dtb : https://people.freebsd.org/~manu/sun50i-a64-pine64-plus.dtb
The overlays : 
https://people.freebsd.org/~manu/sun50i-a64-sid.dtbo
https://people.freebsd.org/~manu/sun50i-a64-ths.dtbo
https://people.freebsd.org/~manu/sun50i-a64-timer.dtbo

loader.conf:
# Configure USB OTG; see usb_template(4).
hw.usb.template=3
umodem_load="YES"
# Multiple console (serial+efi gop) enabled.
boot_multicons="YES"
boot_serial="YES"
fdt_overlays="sun50i-a64-sid,sun50i-a64-ths,sun50i-a64-timer"

If I remove sun50i-a64-timer kenv doesn't looks corrupts but still :
Booting [/boot/kernel/kernel]...
Using DTB provided by EFI at 0x47ff9000.
Loading DTB overlays: 'sun50i-a64-sid,sun50i-a64-ths'
/boot/dtb/overlays/sun50i-a64-sid.dtbo size=0x1fd
/boot/dtb/overlays/sun50i-a64-ths.dtbo size=0x3e8
applying DTB overlay '/boot/dtb/overlays/sun50i-a64-sid.dtbo'
applying DTB overlay '/boot/dtb/overlays/sun50i-a64-ths.dtbo'
EHCI failed to shut down host controller.
---<<BOOT>>---
KDB: debugger backends: ddb
KDB: current backend: ddb
Copyright (c) 1992-2018 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
        The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 12.0-ALPHA2 #1291 r338074+327bec90b971(aw_timer)-dirty: Tue Aug 21 18:42:59 CEST 2018
    manu@skull.home.blih.net:/usr/home/manu/Work/freebsd/obj/usr/home/manu/Work/freebsd/freebsd.git/arm64.aarch64/sys/GENERIC arm64
FreeBSD clang version 6.0.1 (tags/RELEASE_601/final 335540) (based on LLVM 6.0.1)
WARNING: WITNESS option enabled, expect reduced performance.
VT: init without driver.
WARNING: malformed static env value, ignoring interrupts
WARNING: malformed static env value, ignoring clocks
WARNING: malformed static env value, ignoring clock-names
WARNING: malformed static env value, ignoring resets
WARNING: malformed static env value, ignoring reset-names
WARNING: malformed static env value, ignoring #thermal-sensor-cells
WARNING: malformed static env value, ignoring status
WARNING: malformed static env value, ignoring nvmem-cells
WARNING: malformed static env value, ignoring nvmem-cell-names
WARNING: malformed static env value, ignoring phandle
WARNING: malformed static env value, ignoring ths
WARNING: malformed static env value, ignoring ccu
WARNING: malformed static env value, ignoring ths_calib
KLD file umodem.ko is missing dependencies
Comment 1 Mark Millard 2018-08-21 18:05:09 UTC
I'm confused by:

Booting [/boot/kernel/kernel]...
Using DTB provided by EFI at 0x47ff9000.

vs. the reference to:

The dtb : https://people.freebsd.org/~manu/sun50i-a64-pine64-plus.dtb

Should the "Using" notice indicate the sun50i-a64-pine64-plus.dtb
instead?
Comment 2 Emmanuel Vadot freebsd_committer freebsd_triage 2018-08-21 18:15:18 UTC
(In reply to Mark Millard from comment #1)

Quoting myself from the bug report :
Using the latest pine64 image with a dtb loaded by u-boot from the FAT partition (otherwise we can't use the overlays) and some overlays I got :
Comment 3 Kyle Evans freebsd_committer freebsd_triage 2018-08-22 02:49:06 UTC
Ok, I've got the image setup and will give it a shot tomorrow. To be clear, I:

1.) Grabbed the 12.0 ALPHA1 Pine64 snapshot from 2018-Aug-10 03:50,
2.) Threw your exact dtb onto FAT partition,
3.) Threw your overlays into place,
4.) Copied your loader.conf verbatim
Comment 4 commit-hook freebsd_committer freebsd_triage 2018-08-23 13:39:15 UTC
A commit references this bug:

Author: kevans
Date: Thu Aug 23 13:38:38 UTC 2018
New revision: 338250
URL: https://svnweb.freebsd.org/changeset/base/338250

Log:
  efiloader: Setup FDT in autoload to fix overlays clobbering kenv

  manu found in the noted PR that overlays seemed to be clobbering the kenv
  and killing the boot. Further inspection revealed that one can `fdt ls` at
  the loader prompt for a successful boot, but autoboot breaks it.

  In the autoboot case, first setup of FDT is happening in the middle of
  bi_load, which triggers loading of the DTBO from /boot.

  This is bad, bad, bad. Files in the loader are loaded somewhere in the
  middle of the address space one after another. bi_load starts building the
  needed kernel bootinfo immediately after the highest-addr loaded file. File
  loads in the middle of bi_load suddenly clobber bootinfo and everything goes
  off the rails.

  The solution to this is to use take advantage of arch_autoload to setup FDT
  in efiloader compiled with LOADER_FDT_SUPPORT. This matches how it works in
  ubldr land, and is how it should have worked when overlay support was added
  to efiloader since fdt_setup_fdtp now has the potential to load files
  (courtesy of fdt_platform_load_dtb).

  PR:		230804
  Discussed with:	imp
  MFC after:	1 week
  Differential Revision:	https://reviews.freebsd.org/D16858

Changes:
  head/stand/efi/loader/autoload.c
Comment 5 Henri Hennebert 2018-08-25 11:54:10 UTC
FreeBSD nakiska.lab.bel 12.0-ALPHA3 FreeBSD 12.0-ALPHA3 #0 r338306

Using DTB provided by EFI at 0x47ff9000.
Loading DTB overlays: 'sun50i-a64-sid,sun50i-a64-ths,sun50i-a64-timer'
/boot/dtb/overlays/sun50i-a64-sid.dtbo size=0x1fd
/boot/dtb/overlays/sun50i-a64-ths.dtbo size=0x3e8
/boot/dtb/overlays/sun50i-a64-timer.dtbo size=0x175
applying DTB overlay '/boot/dtb/overlays/sun50i-a64-sid.dtbo'
applying DTB overlay '/boot/dtb/overlays/sun50i-a64-ths.dtbo'
applying DTB overlay '/boot/dtb/overlays/sun50i-a64-timer.dtbo'

and boot completed without problem