Topic: U-Boot and SATA woes

Right now (to my understanding), U-Boot's SPL at the start of the SD card loads the u-boot.img on the /boot partition of the SD card which chooses a kernel to load from /boot and boots that with the rootfs on the SD card or SATA disk depending on the eeprom.

This means the SATA drive can't run its own boot arguments, its own kernel or it's own U-Boot. When porting a distro on that doesn't use systemd as it's loader and messing with kernels that needed a newer U-Boot, this was problematic. It seems right now the best way to do this is to hack things in to a uEnv.txt file.

It'd be nice to be able to run the SPL on SATA, or have the main SPL load U-Boot off of the SATA (though I'm not sure if it'd be stable.) I'm not sure if that's actually going to happen.

As a compromise,. would it be a good idea to allow sourcing a custom U-Boot script from the SATA drive when not using recovery mode? If this is a good idea, I could try writing a patch.

Re: U-Boot and SATA woes

SATA support is, at least in theory, enabled in the U-Boot image that's shipped.  I don't recall if it works or not, as I never really tested it.  If you'd like to write a patch, that'd be great.

SPL SATA support would be a little bit harrier, but you could definitely do it.  One dirty secret is that the SPL is limited to about 48 kB, but in reality it can be more like 148 kB.  The smaller limit is because i.MX6DL ("Dual Lite") parts have half the RAM, topping out at 128 kB, and the SPL should be able to run on either one.  There's a section in novena_spl.c that checks where you're currently booting from and loads u-boot.img from that source, so you could extend that to include SATA support.

Then you could boot entirely off of SATA by shorting the "P_SATA" pin on the mainboard.

We do something similar in the factory, by booting off of an external SD card and shorting P_EXT.

3 (edited by Jookia 2015-04-30 21:09:15)

Re: U-Boot and SATA woes

As a progress update to anyone reading, I've heard from Xobs on IRC that I may be able to use another i.MX6 U-Boot loader patch for the SPL, so that's now on my list.

In the mean time I've created this uEnv.txt that should be put in /boot. It loads another uEnv off of the first SATA partition and runs its finalhook:

# Chainload an environment from a SATA device.
# Designed so people can hopefully use the same scripts regardless of device.
satafinalhook=\
  if test "${rootdev}" = "PARTUUID=4e6f7653-03"; then \
    setenv bootsrc "sata"; \
    setenv finalhook; \
    sata init; \
    if run loadbootenv; then \
      echo "Loaded environment from ${bootenv}"; \
      run importbootenv; \
    else; \
      echo "To override sata boot, create a file on the SATA drive called ${bootenv}"; \
    fi; \
    if test -n $finalhook; then \
      echo "Running sata finalhook ..."; \
      env run finalhook; \
    else; \
      echo "To hook late boot process, add a variable called finalhook"; \
    fi; \
  fi
finalhook=run satafinalhook

So for NixOS I just have this:

initrd_addr_r=0x10ff0000
finalhook=\
        load ${bootsrc} ${bootdev} ${kernel_addr_r} nixos-kernel; \
        load ${bootsrc} ${bootdev} ${initrd_addr_r} nixos-initrd; \
        load ${bootsrc} ${bootdev} ${fdt_addr_r} novena.dtb; \
        setenv bootargs init=/nix/store/qxjcssc1j44hynfvy18r5f2wdzx0knz2-nixos-15.05.git.41e1e29/init rootwait rw root=/dev/sda4 console=${consdev}

Which should work on MMC, SD and eventually SATA SPLs.

As side note from hacking with uEnvs, if you break your uEnv you can run this in the recovery console while holding recovery again to get back to Debian:

setenv bootenv; setenv finalhook; run novena_boot

Debian as a BIOS much?