Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => A20 => Topic started by: Titomax on November 07, 2019, 07:05:01 pm

Title: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: Titomax on November 07, 2019, 07:05:01 pm
Hi,
we are working with a board SOM204-A20 (A20-SOM204-1Ge16Gs16M-MC).
For some technical reasons, we need to work with an image Olimex legacy containing kernel 3.4.113. We cannot upgrade to a mainline release with kernel 4.

We have to boot from SPI Flash having kernel and filesystem installed in eMMC mounted onboard (as you suggest to have a boot without issues).

We followed instructions in file "migrate_to_SPI_eMMC_boot.txt", in particular instructions at point ii "How to change existing sunxi A20-OLinuXino image to boot from SPI with FS on eMMC (requires Linux machine)".

Quoteii. How to change existing sunxi A20-OLinuXino image to boot from SPI with FS on eMMC (requires Linux machine).
1. Download folder sunxi-sp-emmc with the files - emmc_FS_only.sh, emmc.sh, u-boot-sunxi-with-spl.bin, boot.cmd, boot.scr.
2. Copy your SD card image in this folder.
3. Perform update.sh on your linux image file
# ./update.sh your_image.img
The result will be a new tmp.img file
3. Write tmp.img file to the micro SD card
4. Mount the SD card
# mount /dev/sdX1 /mnt
where X is proper SD card device.
and copy boot.cmd and boot.scr files in first partition with:
# cp boot.* /mnt
# umount /dev/sdX1
5. Mount second partition
# mount /dev/sdX2 /mnt
and copy emmc_FS_only.sh, emmc.sh files in /root folder on second partition.
# cp emmc* /mnt/root
This is because we work with an image compiled by us from source code in branch "olinuxino" (at the moment image generated is called Armbian_5.92_Olimex-som204-a20_Ubuntu_xenial_default_3.4.113_desktop.img).

We managed to do point 1 and 2 but when we perform "update.sh" script on our compiled image file, we obtain a "tmp.img" not working. We cannot see any partition on it. In addition if we write "tmp.img" into a micro SD, we cannot see any partition in the card and so we cannot mount partition to copy boot.* files and emmc* files in the further point 4 and 5.

Is there an updated way to build an image, copy it on eMMC and make it bootable from SPI Flash?

Thank you



Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: selfbg on November 08, 2019, 09:20:51 am
Can you post the output from the update.sh command?
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: Titomax on November 08, 2019, 10:48:38 am
Hi selfbg,
thank you for the prompt reply.

We already analyzed the script "update.sh" and we found the error: when the built image has a single partition instead of two or more, the fdisk command seems to be used in a wrong way. When we build an image from the olimex-armbian GIT repository we obtain always a single partition and we always fall in the wrong script branch. 

Below you can see the output prints when we run the original "update.sh" script on our image. At the end we run "fdisk -l" on the new generated image and no partition is present inside.

******* PARTITION INFO OF STARTING IMAGE BUILT FROM OLIMEX GIT REPOSITORY *******************
root@olimex# fdisk -l Armbian_5.92_Olimex-som204-a20_Ubuntu_xenial_default_3.4.113_desktop.img

Disk Armbian_5.92_Olimex-som204-a20_Ubuntu_xenial_default_3.4.113_desktop.img: 2 GiB, 2071986176 bytes, 4046848 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe6bff4bd
Dispositivo                                                               Avvio Start    Fine Settori  Size Id Tipo
Armbian_5.92_Olimex-som204-a20_Ubuntu_xenial_default_3.4.113_desktop.img1        8192 4046847 4038656  1,9G 83 Linux


********* OUTPUTS FROM "update.sh" SCRIPT ***************************************************

root@olimex# ./update.sh Armbian_5.92_Olimex-som204-a20_Ubuntu_xenial_default_3.4.113_desktop.img

Processing: Armbian_5.92_Olimex-som204-a20_Ubuntu_xenial_default_3.4.113_desktop.img
--------------

Found 1 partitions
-----------------------------
1: 8192 4046847 4038656 83

Creating new file
-----------------

Make filesystem for partition 1
-------------------------------
mke2fs 1.44.1 (24-Mar-2018)
Discarding device blocks: fatto                           
Creazione del file system con 504576 4k blocchi e 126208 inode
Etichetta del file system=3c55b685-678b-4c64-939c-d3c9e816f8a3
Backup del superblocco salvati nei blocchi:
32768, 98304, 163840, 229376, 294912

Allocating group tables: fatto                           
Scrittura delle tavole degli inode: fatto                           
Creating journal (8192 blocks): fatto
Scrittura delle informazioni dei super-blocchi e dell'accounting del file system: fatto


Copy partitions
---------------
Copying partition 1: 83
  1,474,037,049  99%  106.67MB/s    0:00:13 (xfr#69051, to-chk=0/109757)   

Copy bootloader
---------------
1045+1 record dentro
1045+1 record fuori
1070896 bytes (1,1 MB, 1,0 MiB) copied, 0,00374842 s, 286 MB/s

******* PARTITION INFO OF GENERATED IMAGE **********************************************

root@olimex# fdisk -l tmp.img
Disk tmp.img: 2 GiB, 2071986176 bytes, 4046848 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

root@olimex#

We tried to fix the issue modifying the script but even if the generated image is now formally correct the boot doesn't start anyway.

Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: selfbg on November 08, 2019, 11:41:36 am
I guess is some issue with fdisk versions. However remove line 63 from update.sh and replace it with new line:

fdisk $NEW << __EOF__
n
p

$((${start[$i]} + $OFFSET))
$((${end[$i]} + $OFFSET))
t
${type[$i]}
w
__EOF__

fdisk $NEW << __EOF__
n
p

$((${start[$i]} + $OFFSET))

t
${type[$i]}
w
__EOF__
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: Titomax on November 08, 2019, 12:36:52 pm
Hi selfbg,
thanks again.
Yes, we have now a valid generated image with a single partition inside (as the original one) as you can see in the "fdisk -l tmp.img" output:

root@olimex# fdisk -l tmp.img
Disk tmp.img: 2 GiB, 2071986176 bytes, 4046848 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd583c1f3

Dispositivo Avvio Start    Fine Settori  Size Id Tipo
tmp.img1          10240 4046847 4036608  1,9G 83 Linux
root@olimex#


We anyway cannot go ahead because (as specified in the first post) in the instructions file "migrate_to_SPI_eMMC_boot.txt" at the steps 3, 4 and 5 we should mount two different partitions and copy some files into them...but we have only a single partition!

The result will be a new tmp.img file
3. Write tmp.img file to the micro SD card
4. Mount the SD card
# mount /dev/sdX1 /mnt
where X is proper SD card device.
and copy boot.cmd and boot.scr files in first partition with:
# cp boot.* /mnt
# umount /dev/sdX1
5. Mount second partition
# mount /dev/sdX2 /mnt
and copy emmc_FS_only.sh, emmc.sh files in /root folder on second partition.
# cp emmc* /mnt/root

Any other suggestion ?  ::)
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: selfbg on November 08, 2019, 03:53:42 pm
Try this:

mount /dev/sdx1 /mnt
cp boot.* /mnt/boot/
cp emmc* /mnt/root/

This should get you through these steps.
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: Titomax on November 08, 2019, 05:06:17 pm
Hi selfbg,
we made some steps more with your help.

We copied the files as you suggested all in the same partition of the prepared SD card.

Trying to boot leads us to the following result:

=> boot
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot/boot.scr
410 bytes read in 1 ms (400.4 KiB/s)
## Executing script at 43100000
** File not found script.bin **
47496 bytes read in 5 ms (9.1 MiB/s)
** File not found uImage **
** File not found boot/uImage **
Wrong Image Format for bootm command
ERROR: can't get kernel image!
SCRIPT FAILED: continuing...
NAND booting is temporary disabled.
scanning bus for devices...
SATA link 0 timeout.
AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode
flags: ncq stag pm led clo only pmp pio slum part ccc apst

Device 0: unknown device

Device 0: unknown device
ethernet@01c50000 Waiting for PHY auto negotiation to complete......... TIMEOUT !
Could not initialize PHY ethernet@01c50000
=>

What else are we missing ?  :'(
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: selfbg on November 11, 2019, 12:32:38 pm
The kernel image is missing.
Can you run this in the u-boot console and paste the output:
ext4ls mmc 0 /boot/
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: Titomax on November 11, 2019, 04:58:10 pm
Hi selfbg,
following the paste of the output:

=> ext4ls mmc 0 /boot/
<DIR>       4096 .
<DIR>       4096 ..
<SYM>         25 script.bin
<SYM>         21 uInitrd
<SYM>         21 zImage
<DIR>       4096 bin
<DIR>       4096 overlay-user
            1536 armbian_first_run.txt.template
         1987684 System.map-3.4.113-sun7i
             192 armbianEnv.txt
           99775 config-3.4.113-sun7i
            4882 boot-desktop.png
          230454 boot.bmp
             338 boot.cmd
             410 boot.scr
         5135878 initrd.img-3.4.113-sun7i
         5135942 uInitrd-3.4.113-sun7i
         5498616 vmlinuz-3.4.113-sun7i
=>

Our thoughts about the issue:
the system goes into the boot script "boot.scr" and looks for the location from which to load the uImage of the kernel. But it's wrong.

Please look at the "boot.cmd" that we find in the boot directory.

setenv bootm_boot_mode sec
setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait panic=10
load mmc ${mmc_bootdev}:1 0x43000000 script.bin || load mmc ${mmc_bootdev}:1 0x43000000 boot/script.bin
load mmc ${mmc_bootdev}:1 0x42000000 uImage || load mmc ${mmc_bootdev}:1 0x42000000 boot/uImage
setenv machid 10bb
bootm 0x42000000

As you can see the script search for an "uImage" kernel file instead of the "zImage" one present in the same directory.
We guess that "boot.cmd" and "boot.scr" we are using are wrong.
Can you suggest where we could find the correct files or how we could modify them ?

Thanks
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: Titomax on November 21, 2019, 11:55:36 am
Hi,
we weren't able to solve the last issue described so we decided to migrate from legacy kernel 3.4.113 to newer kernel 5.2.20.

Now we have the system correctly configured to boot from SPI and then to work from eMMC (it works) but we need to migrate from the old hardware management based on the "script.fex" file to the "device tree" approach.

Can anyone suggest a tutorial or a guide to help us in this activity ?

Thanks
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: LubOlimex on November 21, 2019, 01:54:36 pm
It can't be done automatically. You need to take care of each line, Use our overlays as a basis: https://github.com/OLIMEX/OLIMEX-sunxi-overlays

Other than that, what is the difference between your fex and the original unmodified fex? We might be able to give you advice if you are more specific what exactly doesn't work and what exactly you need to accomplish (e.g. which pin or which interface you need exposed, etc).
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: dpierleo on November 29, 2019, 12:20:03 pm
Hi,

I am a colleague of Titomax and we are working together at the same project.
First of all, thank you selfbg and LubOlimex for your help.

We are trying to follow all steps you showed us also in other thread.
We downloaded kernel and device tree sources using this command (we don't want to compile original device tree but we want to study its mechanism and code inside):

git clone --branch olimex https://github.com/olimex/build

We downloaded your overlays using this command:

https://github.com/OLIMEX/OLIMEX-sunxi-overlays

To implement an overlay in our som (i.e. that one for enabling uart4), we copied the relative dts file in som filesystem, then we executed:

armbian-add-overlay sun7i-a20-uart4.dts

Everything seems to work correctly after reboot.

After that we added also sun7i-a20-uart3.dts, sun7i-a20-spi2.dts. Also in this case everything seems to work but I'm trying to understand how it's possible given that in the file sun7i-a20-spi2.dts I see:

/dts-v1/;
/plugin/;

/ {
compatible = "allwinner,sun7i-a20";
description = "Enable SPI2 bus";

fragment@0 {
target-path = "/aliases";
__overlay__ {
spi2 = "/soc/spi@1c17000";
};
};

fragment@1 {
target = <&spi2>;
__overlay__ {
pinctrl-names = "default";
pinctrl-0 = <&spi2_pc_pins>, <&spi2_cs0_pc_pin>;
status = "okay";
};
};
};

without any definition of spi2_pc_pins and spi2_cs0_pc_pin. I checked also in original dts files sun7i-a20.dtsi, sun7i-a20-olimex-som204-evb.dts and sun7i-a20-olimex-som204-evb-emmc.dts and I didn't find any reference to labels spi2_pc_pins and spi2_cs0_pc_pin. So how can sun7i-a20-spi2.dts work correctly?

My second question is about a further step forward I have done: I added your overlay sun7i-a20-spi0.dts and my system crashed after that. The bootloader seems to load correctly all four overlays (without any error notifying) but stops after the words "Starting Kernel".

Could you help me please?

Thank you in advance
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: LubOlimex on November 29, 2019, 01:56:43 pm
SPI0 is used for the SPI flash. If you intend to use SPI flash or if you intend to boot from eMMC I would advise against using SPI0.

I recommend you this thread: https://www.olimex.com/forum/index.php?topic=7224.0
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: dpierleo on December 06, 2019, 04:28:48 pm
Hi,

thank you LubOlimex for your help.
I understood your explanation about use of SPI and I decided to keep SPI0 only for the SPI flash. So I removed overlay sun7i-a20-spi0.dts for our board.

Anyway we need other changes in device tree to customize our board:

[1] we need to drive PWM in pin PB02 but when we add the overlay from olimex sun7i-a20-pwm.dts, we get the system hanging without reaching the kernel boot (after "Uncompressing Linux... done, booting the kernel." the system does not boot) as you can see:

U-Boot SPL 2019.04-armbian (Oct 10 2019 - 08:33:04 +0300)
DRAM: 1024 MiB
CPU: 912000000Hz, AXI/AHB/APB: 3/2/2
EEPROM: Ready
Config: Valid
Trying to boot from sunxi SPI


U-Boot 2019.04-armbian (Oct 10 2019 - 08:33:04 +0300) Allwinner Technology

CPU:   Allwinner A20 (SUN7I)
Model: A20-SOM204-1Gs16Me16G-MC Rev.C
Serial:00007516
MAC:   30:1F:9A:D0:41:DC
I2C:   ready
DRAM:  1 GiB
SF: Detected w25q128 with page size 256 Bytes, erase size 4 KiB, total 16 MiB
NAND:  0 MiB
MMC:   mmc@1c0f000: 0, mmc@1c11000: 1, mmc@1c12000: 2
Loading Environment from SPI Flash... OK
Setting up a 800x480 lcd console (overscan 0x0)
In:    serial
Out:   vga
Err:   vga
Allwinner mUSB OTG (Peripheral)
Net:   eth0: ethernet@1c50000
starting USB...
USB0:   USB EHCI 1.00
USB1:   USB OHCI 1.0
USB2:   USB EHCI 1.00
USB3:   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 usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot:  0
switch to partitions #0, OK
mmc1(part 0) is current device
Scanning mmc 1:1...
Found U-Boot script /boot/boot.scr
3798 bytes read in 2 ms (1.8 MiB/s)
## Executing script at 43100000
U-boot loaded from SPI
MMC: no card present
Boot script loaded from mmc
279 bytes read in 1 ms (272.5 KiB/s)
8426421 bytes read in 468 ms (17.2 MiB/s)
7606120 bytes read in 423 ms (17.1 MiB/s)
Found mainline kernel configuration
37532 bytes read in 7 ms (5.1 MiB/s)
867 bytes read in 1 ms (846.7 KiB/s)
Applying user provided DT overlay sun7i-a20-uart4.dtbo
1031 bytes read in 1 ms (1006.8 KiB/s)
Applying user provided DT overlay sun7i-a20-uart3.dtbo
603 bytes read in 2 ms (293.9 KiB/s)
Applying user provided DT overlay sun7i-a20-spi2.dtbo
720 bytes read in 1 ms (703.1 KiB/s)
Applying user provided DT overlay sun7i-a20-pwm.dtbo
## Loading init Ramdisk from Legacy Image at 43200000 ...
   Image Name:   uInitrd
   Image Type:   ARM Linux RAMDisk Image (gzip compressed)
   Data Size:    8426357 Bytes = 8 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 43000000
   Booting using the fdt blob at 0x43000000
EHCI failed to shut down host controller.
   Loading Ramdisk to 497f6000, end 49fff375 ... OK
   Loading Device Tree to 49784000, end 497f5fff ... OK
Recovering the FDT blob...

Starting kernel ...

Uncompressing Linux... done, booting the kernel.


[2] we need to use PI10, PI11, PI14, PI15, PI06 and PI07 as GPIO. Is there any overlay to get this aim?

[3] we need to use our capacitive touch screen with ft5x_ts driver.
We executed in u-boot command following code to use our custom display (capacitive touch screen) with the driver ft5x_ts:

olinuxino monitor set LCD-OLinuXino-7
saveenv

With the fex system we disabled rtp and enabled ctp as follows:

[rtp_para]
rtp_used = 0
...
[ctp_para]
ctp_used = 1
ctp_name = "ft5x_ts"
ctp_twi_id = 2
ctp_twi_addr = 0x38
ctp_screen_max_x = 800
ctp_screen_max_y = 480
ctp_revert_x_flag = 1
ctp_revert_y_flag = 1
...

How can we make the same thing with device tree system? Is there any overlay to get this aim?

Thank you in advance for your help