Sunday, October 22, 2017

OrangePI Zero overlay and uboot/armbian

The Armbian has good documentation about how to use device overlays for their uboot scripts.  I wanted to dive a little deeper and understand some of the basics and still use buildroot.

Boot process of uboot, there is a file on the FAT partition boot.src, this is a binary file generated by mkimage.  The source file is in board/orangepi/orangepi-zero boot.sh:
setenv fdt_high ffffffff
setenv load_addr "0x44000000"
echo "Boot script loaded from ${devtype}"

setenv bootargs console=ttyS0,115200 earlyprintk root=/dev/mmcblk0p2 rootwait

fatload mmc 0 $kernel_addr_r zImage
fatload mmc 0 $fdt_addr_r sun8i-h2-plus-orangepi-zero.dtb
fdt addr ${fdt_addr_r}
fdt resize 65536
setenv processorName sun8i-h3-
setenv overlays i2c0  spi-spidev
for overlay_file in ${overlays}; do
    echo " looking for  ${processorName}${overlay_file}.dtbo"
    if fatload mmc 0 ${load_addr} ${processorName}${overlay_file}.dtbo; then
        echo "Applying user provided DT overlay ${overlay_file}.dtbo"
        fdt apply ${load_addr} || setenv overlay_error "true"
    fi
done


bootz $kernel_addr_r - $fdt_addr_r

So, what happens is the device tree overlays are merged in uboot with the dtb file loaded for the board using fdt command line tools.  This allows to change the board dtb without always recompiling it.

Post any questions you have.   So, spi and i2c are now using device tree overlays.

Here is the overlay for SPI:
/dts-v1/;
/plugin/;

/ {
    compatible = "allwinner,sun8i-h3";

    fragment@0 {
        target-path = "/aliases";
        __overlay__ {
            spi0 = "/soc/spi@01c68000";
            spi1 = "/soc/spi@01c69000";
        };
    };

    fragment@1 {
        target = <&spi0>;
        __overlay__ {

            #address-cells = <1>;
            #size-cells = <0>;
            status = "disabled";

            spidev@1 {
                compatible = "linux,spidev";
                reg = <0>;
                spi-max-frequency = <1000000>;
            };
        };
    };

    fragment@2 {
        target = <&spi1>;
        __overlay__ {

            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";

            spidev@2 {
                compatible = "linux,spidev";
                reg = <0>;
                spi-max-frequency = <25000000>;
            };
        };
    };
};


so, this completes the task of using overlays.  Next DHCP and zeroconfig.

Also, have a modification to EEM USB handler, to improve performance.  Also, thinking of adding a way to use several packets at once based on the size of the packet.





7 comments:

  1. Hi, i'm getting the error:
    U-Boot SPL 2019.04 (Sep 17 2019 - 12:13:22 +0500)
    DRAM: 1024 MiB
    Trying to boot from MMC1


    U-Boot 2019.04 (Sep 17 2019 - 12:13:22 +0500) Allwinner Technology

    CPU: Allwinner H3 (SUN8I 1680)
    Model: Xunlong Orange Pi PC Plus
    DRAM: 1 GiB
    MMC: Device 'mmc@1c11000': seq 1 is in use by 'mmc@1c10000'
    mmc@1c0f000: 0, mmc@1c10000: 2, mmc@1c11000: 1
    Loading Environment from FAT... Unable to use mmc 1:1... In: serial
    Out: vidconsole
    Err: vidconsole
    Net: phy interface0
    eth0: ethernet@1c30000
    starting USB...
    USB0: USB EHCI 1.00
    USB1: USB OHCI 1.0
    USB2: USB EHCI 1.00
    USB3: USB OHCI 1.0
    USB4: USB EHCI 1.00
    USB5: USB OHCI 1.0
    USB6: USB EHCI 1.00
    USB7: USB OHCI 1.0
    scanning bus 0 for devices... 1 USB Device(s) found
    scanning bus 1 for devices... 1 USB Device(s) found
    scanning bus 2 for devices... 1 USB Device(s) found
    scanning bus 3 for devices... 1 USB Device(s) found
    scanning bus 4 for devices... 1 USB Device(s) found
    scanning bus 5 for devices... 2 USB Device(s) found
    scanning bus 6 for devices... 1 USB Device(s) found
    scanning bus 7 for devices... 1 USB Device(s) found
    scanning usb for storage devices... 0 Storage Device(s) found
    Hit any key to stop autoboot: 0
    switch to partitions #0, OK
    mmc0 is current device
    Scanning mmc 0:1...
    Found U-Boot script /boot.scr
    784 bytes read in 3 ms (254.9 KiB/s)
    ## Executing script at 43100000
    Boot script loaded from mmc
    4140136 bytes read in 189 ms (20.9 MiB/s)
    15803 bytes read in 3 ms (5 MiB/s)
    780 bytes read in 3 ms (253.9 KiB/s)
    Applying user provided DT overlay spi-spidev.dtbo
    failed on fdt_overlay_apply(): FDT_ERR_NOTFOUND
    base fdt does did not have a /__symbols__ node
    make sure you've compiled with -@
    ERROR: Did not find a cmdline Flattened Device Tree
    Could not find a valid device tree
    SCRIPT FAILED: continuing...
    15803 bytes read in 3 ms (5 MiB/s)
    switch to partitions #0, OK
    mmc1(part 0) is current device

    ReplyDelete
  2. it's my boot.scr:
    setenv fdt_high ffffffff
    setenv load_addr "0x44000000"
    echo "Boot script loaded from ${devtype}"

    setenv bootargs console=ttyS0,115200 earlyprintk root=/dev/mmcblk0p2 rootwait

    fatload mmc 0 $kernel_addr_r zImage
    fatload mmc 0 $fdt_addr_r sun8i-h3-orangepi-pc-plus.dtb
    fdt addr ${fdt_addr_r}
    fdt resize 65536

    setenv processorName sun8i-h3-
    setenv overlays spi-spidev

    for overlay_file in ${overlays}; do
    if fatload mmc 0 ${load_addr} ${processorName}${overlay_file}.dtbo; then
    echo "Applying user provided DT overlay ${overlay_file}.dtbo"
    fdt apply ${load_addr} || setenv overlay_error "true"
    else
    echo "unable to load"
    fi
    done

    bootz $kernel_addr_r - $fdt_addr_r

    ReplyDelete
  3. I don't know how solve this problem,it's my genimage.cfg:
    # Minimal SD card image for the OrangePi PC Plus
    #
    image boot.vfat {
    vfat {
    files = {
    "zImage",
    "sun8i-h3-orangepi-pc-plus.dtb",
    "sun8i-h3-spi-spidev.dtbo",
    "boot.scr"
    }
    }
    size = 10M
    }

    image sdcard.img {
    hdimage {
    }

    partition u-boot {
    in-partition-table = "no"
    image = "u-boot-sunxi-with-spl.bin"
    offset = 8192
    size = 1040384 # 1MB - 8192
    }

    partition boot {
    partition-type = 0xC
    bootable = "true"
    image = "boot.vfat"
    }

    partition rootfs {
    partition-type = 0x83
    image = "rootfs.ext4"
    size = 512M
    }
    }

    ReplyDelete
  4. Can anybody help me?

    ReplyDelete
  5. I solved my problem. Thank you!!!

    ReplyDelete