1

I have a problem: my device (an Atmel SAMA5D27 Xplained board) won't boot after my attempt to flash a new device tree.

Here's what I did (details are at the end of this message):

  1. I downloaded the Linux4SAM source tree from Github (tag linux4sam_5.3). I used this tag since that is the one that was installed when I got the device.
  2. I made changes to the file arch/arm/boot/dts/at91-sama5d2_xplained.dts to enable the SPI1 device (and disable the SDMMC1 device since it is conflicting with the SPI1 pins). I saved the file in the same directory as at91-sama5d2_xplained_custom.dts and modified the Makefile accordingly.
  3. I compiled (from the root directory of the source tree) with the following command: $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs. A new DTB was generated.
  4. I verified the size of the DTB file with the file command, which told be the DTB is 30796 bytes.
  5. I flashed the DTB to the devices with the SAM-BA utility, which was successful, but reported that 30976 bytes were flashed.
  6. I rebooted the device, which got stuck in the U-boot environment. This was to be expected, since the DTB got changed. I updated the bootcmd to reflect the new size of the DTB (30796 = 0x784c), but it still won't boot.

Here's the result from printenv after my update (which I saved with saveenv):

=> printenv
bootargs=console=ttyS0,115200 root=/dev/mmcblk0p1 rw rootfstype=ext4 rootwait
bootcmd=sf probe 0; sf read 0x21000000 0x70000 0x784c; sf read 0x22000000 0x7c000 0x3636a8; bootz 0x22000000 - 0x21000000
bootdelay=1
ethact=gmac0
ethaddr=fc:c2:3d:02:f4:e9
stderr=serial
stdin=serial
stdout=serial

Environment size: 309/8188 bytes

Note that I only updated the size in the first sf read command of bootcmd. It used to read sf read 0x21000000 0x70000 0x77c8, which corresponds to the size of the DTB that I get from the original at91-sama5d2_xplained.dts file.

Here's the error that I got:

SF: Detected AT25DF321 with page size 256 Bytes, erase size 4 KiB, total 4 MiB
device 0 offset 0x70000, size 0x784c
SF: 30796 bytes @ 0x70000 Read: OK
device 0 offset 0x7c000, size 0x3636a8
SF: 3552936 bytes @ 0x7c000 Read: OK
Kernel image @ 0x22000000 [ 0x000000 - 0x3636a8 ]
ERROR: Did not find a cmdline Flattened Device Tree
Could not find a valid device tree

Naturally, my question is: what did I do wrong?

I have some hypotheses, which I tried:

  1. I got the size wrong: I tried to use 0x7900 in the bootcmd (corresponding to the 30976 bytes that SAM-BA reported), but this didn't help.
  2. I flashed to the wrong address: I'm not entirely sure what the address 0x21000000 is in sf read in bootcmd, but from the example files that were provided with SAM-BA I inferred that 0x70000 was correct. Changing 0x21000000 to 0x0 doesn't help. Changing the SAM-BA write command to write at 0x21070000 results in an error that it cannot write past the end of memory.
  3. My DTB is wrong. I don't think I'm doing particularly strange things in my DTS file, and since it compiles I assume it is at least in a format that should be readable.

Any help/advice/pointers/etc. is very much appreciated, as I now have an unbootable device... I'm also worried that if I flashed to the wrong address, I broke all kinds of stuff that I'm not aware of.


Details

DTS file:

/dts-v1/;
#include "at91-sama5d2_xplained_common.dtsi"

/ {
    model = "Atmel SAMA5D2 Xplained";
    compatible = "atmel,sama5d2-xplained", "atmel,sama5d2", "atmel,sama5";

    ahb {
        sdmmc1: sdio-host@b0000000 {        
            status = "disabled"; /* conflict with spi1 */
        };

        apb {
            can0: can@f8054000 {
                status = "okay";
            };

            can1: can@fc050000 {
                status = "okay";
            };

            spi1: spi@fc000000 {
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_spi1_default>;
                status = "okay";
            };

            pinctrl@fc038000 {
                pinctrl_spi1_default: spi1_default {
                    pinmux = <PIN_PA22__SPI1_SPCK>,
                         <PIN_PA23__SPI1_MOSI>,
                         <PIN_PA24__SPI1_MISO>,
                         <PIN_PA25__SPI1_NPCS0>;
                    bias-disable;
                };
            };           
        };
    };
};

Compilation of the DTB:

$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
make[1]: 'include/generated/mach-types.h' is up to date.
  CHK     include/generated/bounds.h
  CHK     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  DTC     arch/arm/boot/dts/at91-sama5d2_xplained_custom.dtb

Verification of the DTB file size:

$ file arch/arm/boot/dts/at91-sama5d2_xplained_custom.dtb
arch/arm/boot/dts/at91-sama5d2_xplained_custom.dtb: Device Tree Blob version 17, size=30796, boot CPU=0, string block size=1692, DT structure block size=29048

SAM-BA flash command output:

# sam-ba -p serial:ttyACM0:115200 -b sama5d2-xplained -a serialflash -c write:at91-sama5d2_xplained_custom.dtb:0x70000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 4194304 bytes.
Executing command 'write:at91-sama5d2_xplained_custom.dtb:0x70000'
Added 180 bytes of padding to align to page size
Wrote 30976 bytes at address 0x00070000 (100.00%)
Connection closed.

SAM-BA trying to write past the end of memory:

# sam-ba -p serial:ttyACM0:115200 -b sama5d2-xplained -a serialflash -c write:at91-sama5d2_xplained_custom.dtb:0x21070000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 4194304 bytes.
Executing command 'write:at91-sama5d2_xplained_custom.dtb:0x21070000'
Added 180 bytes of padding to align to page size
Error: Command 'write:at91-sama5d2_xplained_custom.dtb:0x21070000': Cannot write past end of memory, only -549912576 bytes remaining at offset 0x21070000 (requested 30976 bytes)
Connection closed.
1

User error.

I found that SAM-BA also has a verification method:

# sam-ba -p serial:ttyACM0:115200 -b sama5d2-xplained -a serialflash -c verify:at91-sama5d2_xplained_custom.dtb:0x70000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 4194304 bytes.
Executing command 'verify:at91-sama5d2_xplained_custom.dtb:0x70000'
Added 180 bytes of padding to align to page size
Error: Command 'verify:at91-sama5d2_xplained_custom.dtb:0x70000': Failed verification. First error at file offset 0x00000000
Connection closed.

Not good. It turns out that step 5 was missing a very essential step: first you need to erase the flash memory before writing it (I had no idea; I apparently have always used tools that took care of this for me):

# sam-ba -p serial:ttyACM0:115200 -b sama5d2-xplained -a serialflash -c erase:0x70000:0x8000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 4194304 bytes.
Executing command 'erase:0x70000:0x8000'
Erased 32768 bytes at address 0x00070000 (100.00%)
Connection closed.

# sam-ba -p serial:ttyACM0:115200 -b sama5d2-xplained -a serialflash -c write:at91-sama5d2_xplained_custom.dtb:0x70000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 4194304 bytes.
Executing command 'write:at91-sama5d2_xplained_custom.dtb:0x70000'
Added 180 bytes of padding to align to page size
Wrote 30976 bytes at address 0x00070000 (100.00%)
Connection closed.

# sam-ba -p serial:ttyACM0:115200 -b sama5d2-xplained -a serialflash -c verify:at91-sama5d2_xplained_custom.dtb:0x70000
Opening serial port 'ttyACM0'
Connection opened.
Detected memory size is 4194304 bytes.
Executing command 'verify:at91-sama5d2_xplained_custom.dtb:0x70000'
Added 180 bytes of padding to align to page size
Verified 30976 bytes at address 0x00070000 (100.00%)
Connection closed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.