Monday, August 21, 2023

User interface test verification part 25

DIGGING INTO POSSIBILITY THAT THIS IS A DEVICE TREE ISSUE

Before I begin hacking the code to the preloader (SPL) to give me clues about what is going wrong, I focused on the idea that the most likely cause is a failure to copy itself to RAM and load u-boot code. Most comments I found through extensive google searches pin this on errors in the device tree blob, so that was my focus for a couple of days.

The process of  building the device tree blob is not simple. There is a submitted file provided with the distribution of U-boot that presumably the maker of the board or a code contributor has provided. This is massaged in various ways to produce two device tree blobs, one for U-boot and a stripped down small one for SPL due to size limitations in the initial storage used for preloader execution. 

The initial source for the board is merged with various other source files to build up a device tree source. This is because a specific board has unique features but also shares a lot with every board built using the same SoC chip, in my case Cyclone 5, and in common with every Altera/Intel based SoC board regardless of the chip type. 

The C preprocessor will merge all those common elements with the board specific details to form the first source file. The device tree compiler dtc is then run to convert the source format dts file to a binary blob format dtb. This watches for a number of warnings as it processes the source file. 

All further processing is done on the binary format files thus harder to observe without converting the dtb back to dts format temporarily for inspections. 

The dtb file is combined with the compiled U-boot code in the next few commands. We then copy the dtb file to the directory where we will build the preloader (spl) and skinny it up.  A few passes through a tool called fdtgrep do the trick. The first pass drops everything that is not tagged with special markers u-boot,dm-pre-reloc and u-boot,dm-spl but also some special sections like chosen that are used to direct serial console messages. The second pass does more exclusion of specific properties within entries to further reduce the size of the resulting dtb file. 

The files are moved various places, the dtb files appended to binary files and then the specific bootable images are created using the mkimage tool.  Eventually we end up with four copies of the preloader (including its small dtb) then the U-boot binary with its larger dtb, forming the data to be copied into a special partition on the SD card from which the Cyclone 5 chip will boot. 

Something is going wrong in this process, perhaps, resulting in a dtb that doesn't give the preloader the data it needs to at initial DRAM, copy code and emit the first output to the serial console. We don't yet know if this is a missing or incorrect element in the dtb, a dtb that is so large it exceeds the limited SRAM space on the Cyclone 5 chip into which the preloader must fit, or something entirely different. 

Below is the extract of the make process that builds the device tree blob from the initial source and then uses it to create the SPL and U-boot images:

  mkdir -p arch/arm/dts/ ;
  
     (cat arch/arm/dts/socfpga_cyclone5_de10_nano.dts; ) > arch/arm/dts/.socfpga_cyclone5_de10_nano.dtb.pre.tmp;
     
     cc -E -Wp,-MD,arch/arm/dts/.socfpga_cyclone5_de10_nano.dtb.d.pre.tmp -nostdinc -Iinclude     -I./arch/arm/include -include/
      ./include/linux/kconfig.h -I./arch/arm/dts -I./arch/arm/dts/include -I./include -D__ASSEMBLY__\
       -undef -D__DTS__ -x assembler-with-cpp -o arch/arm/dts/.socfpga_cyclone5_de10_nano.dtb.dts.tmp arch/arm/dts/.socfpga_cyclone5_de10_nano.dtb.pre.tmp ;
       
      ./scripts/dtc/dtc -O dtb 
      -o arch/arm/dts/socfpga_cyclone5_de10_nano.dtb 
      -b 0 
      -i arch/arm/dts/ 
      -Wno-unit_address_vs_reg 
      -Wno-unit_address_format\
       -Wno-avoid_unnecessary_addr_size 
       -Wno-alias_paths 
       -Wno-graph_child_address 
       -Wno-graph_port 
       -Wno-unique_unit_address 
       -Wno-simple_bus_reg\
        -Wno-pci_device_reg 
        -Wno-pci_bridge 
        -Wno-pci_device_bus_num  
        -a 0x8 
        -Wno-unit_address_vs_reg 
        -Wno-unit_address_format 
        -Wno-avoid_unnecessary_addr_size\
         -Wno-alias_paths 
         -Wno-graph_child_address 
         -Wno-graph_port 
         -Wno-unique_unit_address 
         -Wno-simple_bus_reg 
         -Wno-pci_device_reg\
          -Wno-pci_bridge 
          -Wno-pci_device_bus_num  
          -d arch/arm/dts/.socfpga_cyclone5_de10_nano.dtb.d.dtc.tmp 
          arch/arm/dts/.socfpga_cyclone5_de10_nano.dtb.dts.tmp 
          ||
           (echo "Check /home/carl/Documents/quartus/Virtual2315Cartridge/software/u-boot-socfpga/arch/arm/dts/.socfpga_cyclone5_de10_nano.dtb.pre.tmp for errors" && false) ;
            sed "s:arch/arm/dts/.socfpga_cyclone5_de10_nano.dtb.pre.tmp:arch/arm/dts/socfpga_cyclone5_de10_nano.dts:"\
            arch/arm/dts/.socfpga_cyclone5_de10_nano.dtb.d.pre.tmp 
            arch/arm/dts/.socfpga_cyclone5_de10_nano.dtb.d.dtc.tmp 
            > arch/arm/dts/.socfpga_cyclone5_de10_nano.dtb.d
            
  cat arch/arm/dts/socfpga_cyclone5_de10_nano.dtb > dts/dt.dtb
  
  cat u-boot-nodtb.bin dts/dt.dtb > u-boot-dtb.bin
  
  cp u-boot-dtb.bin u-boot.bin
  
mkdir -p spl/dts/

          ./tools/fdtgrep -b u-boot,dm-pre-reloc -b u-boot,dm-spl -RT dts/dt.dtb -n /chosen -n /config -O dtb 
              |
          ./tools/fdtgrep -r -O dtb - -o spl/dts/dt-spl.dtb -P u-boot,dm-pre-reloc -P u-boot,dm-spl -P u-boot,dm-tpl -P u-boot,dm-vpl/
             -P pinctrl-0 -P pinctrl-names -P clocks -P clock-names -P interrupt-parent -P interrupts
             
  cp spl/dts/dt-spl.dtb spl/u-boot-spl.dtb
  
  cat spl/u-boot-spl-nodtb.bin spl/u-boot-spl-pad.bin spl/u-boot-spl.dtb > spl/u-boot-spl-dtb.bin
  
  cp spl/u-boot-spl-dtb.bin spl/u-boot-spl.bin
  
  arm-none-eabi-objdump -t spl/u-boot-spl > spl/u-boot-spl.sym
  
  ./tools/mkimage -T socfpgaimage -d spl/u-boot-spl.bin spl/u-boot-spl.sfp >/dev/null  && cat /dev/null
  
  ./tools/mkimage -A arm -T firmware -C none -O u-boot -a 0x01000040 -e 0x01000040 -n "U-Boot 2022.10-24689-gfdfea6b32f-dirty for de10-nano board" -d u-boot.bin u-boot.img >/dev/null  && cat /dev/null
  
  cp dts/dt.dtb u-boot.dtb
  
  ./tools/mkimage -A arm -T firmware -C none -O u-boot -a 0x01000040 -e 0x01000040 -n "U-Boot 2022.10-24689-gfdfea6b32f-dirty for de10-nano board"\
   -d u-boot.bin u-boot-dtb.img >/dev/null  && cat /dev/null
   
  arm-none-eabi-objcopy -I binary -O binary --gap-fill=0x0 --pad-to=0x10000 spl/u-boot-spl.sfp spl/u-boot-spl.sfp 
    && cat spl/u-boot-spl.sfp spl/u-boot-spl.sfp spl/u-boot-spl.sfp spl/u-boot-spl.sfp > spl/u-boot-splx4.sfp ;
  
   cat spl/u-boot-splx4.sfp u-boot.img > u-boot-with-spl.sfp 
   || rm -f u-boot-with-spl.sfp
   
  ./scripts/check-config.sh u-boot.cfg ./scripts/config_whitelist.txt .
  
  ./scripts/check-of.sh .config ./scripts/of_allowlist.txt

No comments:

Post a Comment