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


 
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: selfbg on December 09, 2019, 10:52:40 AM
Hi,

Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: dpierleo on December 09, 2019, 05:20:20 PM
Hi selfbg,

thank you for your help.

1. I am able to see the device under /sys/class/backlight directory so everything works well.

2. I can export four GPIO I need (PI06, PI07, PI14, PI15) but I cannot export PI10 and PI11. I receive a message "busy" when I am trying to export them. I think it is because PI10 and PI11 are used in EVB for green and yellow leds that I do not need in my custom board. Is there any way to disable a20-som204-evb:green and a20-som204-evb:yello by a new overlay?

3. I made all you told me and I edit my custom overlay lcd-olinuxino-7.dts as follows:

/dts-v1/;
/plugin/;

/ {
 compatible = "allwinner,sun7i-a20";
 description = "Enable LCD-OLinuXino-7";

 fragment@0 {
 target = <&i2c2>;
 __overlay__ {
 status = "okay";

 ft5x@38 {
 compatible = "edt,edt-ft5306";
 reg = <0x38>;
 touchscreen-size-x = <800>;
 touchscreen-size-y = <480>;

 interrupt-parent = <&pio>;
 interrupts = <7 7 2>;

 touchscreen-inverted-x;
 touchscreen-inverted-y;

 irq-gpios = <&pio 7 2 0>;
 wake-gpios = <&pio 8 1 1>;
 };
 };
 };
};

But when I execute command:

armbian-add-overlay lcd-olinuxino-7.dts
I receive the following error:

Compiling the overlay
dtc: livetree.c:521: get_node_by_phandle: Assertion `(phandle != 0) && (phandle != -1)' failed.
/usr/sbin/armbian-add-overlay: line 81:  3366 Aborted                dtc -@ -q -I dts -O dtb -o ${temp_dir}/${fname}.dtbo $1
Error compiling the overlay

Where is the error?

Thank you in advance for your help
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: dpierleo on December 16, 2019, 05:43:42 PM
Hi,

can anyone help me with my previous post?

I use sun7i-a20-olimex-som204-evb-emmc.dtb and I would like to modify some feature using overlay:

1) I would like to use PI10 and PI11 as GPIO.

2) I would like to use capacitive touch screen with ft5x_ts driver.

Issue in point 1:

in device tree source sun7i-a20-olimex-som204-evb.dts (inherited by sun7i-a20-olimex-som204-evb-emmc.dtb) I can see:

leds {
 compatible = "gpio-leds";

 stat {
 label = "a20-som204-evb:green:stat";
 gpios = <&pio 8 0 GPIO_ACTIVE_HIGH>;
 default-state = "on";
 };

 led1 {
 label = "a20-som204-evb:green:led1";
 gpios = <&pio 8 10 GPIO_ACTIVE_HIGH>;
 default-state = "on";
 };

 led2 {
 label = "a20-som204-evb:yellow:led2";
 gpios = <&pio 8 11 GPIO_ACTIVE_HIGH>;
 default-state = "on";
 };
 };

Could I remove led1 and led2 using an overlay? How? In this way I could use PI10 and PI11 as GPIO.

Issue in point 2:

I edited my custom overlay lcd-olinuxino-7.dts as follows:

/dts-v1/;
/plugin/;

/ {
 compatible = "allwinner,sun7i-a20";
 description = "Enable LCD-OLinuXino-7";

 fragment@0 {
 target = <&i2c2>;
 __overlay__ {
 status = "okay";

 ft5x@38 {
 compatible = "edt,edt-ft5306";
 reg = <0x38>;
 touchscreen-size-x = <800>;
 touchscreen-size-y = <480>;

 interrupt-parent = <&pio>;
 interrupts = <7 7 2>;

 touchscreen-inverted-x;
 touchscreen-inverted-y;

 irq-gpios = <&pio 7 2 0>;
 wake-gpios = <&pio 8 1 1>;
 };
 };
 };
};

But when I execute command:

armbian-add-overlay lcd-olinuxino-7.dts
I receive the following error:

Compiling the overlay
dtc: livetree.c:521: get_node_by_phandle: Assertion `(phandle != 0) && (phandle != -1)' failed.
/usr/sbin/armbian-add-overlay: line 81:  3366 Aborted                dtc -@ -q -I dts -O dtb -o ${temp_dir}/${fname}.dtbo $1
Error compiling the overlay

I believe if I solve these two issues, I can reach my final goal.

Please, could anyone help me?

Thank you in advance
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: selfbg on December 20, 2019, 12:00:07 PM
Quote from: dpierleo on December 16, 2019, 05:43:42 PM1) I would like to use PI10 and PI11 as GPIO.

You can do this without the overlay. Do the following as root:

echo leds >  /sys/bus/platform/drivers/leds-gpio/unbindThis will release the gpio control.

The export and use them (See here (https://www.kernel.org/doc/Documentation/gpio/sysfs.txt)):
# Export PI10
echo 266 > /sys/class/gpio/export

# Export PI11
echo 267 > /sys/class/gpio/export

Optionally if you want to use them only as outputs, you can also toggle the by:
echo 1 > /sys/class/leds/a20-som204-evb\:green\:led1/brightness
echo 0 > /sys/class/leds/a20-som204-evb\:green\:led1/brightness

echo 1 > /sys/class/leds/a20-som204-evb\:green\:led2/brightness
echo 0 > /sys/class/leds/a20-som204-evb\:green\:led2/brightness

The DTS overlays doesn't support deletion of nodes. (For now).

Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: selfbg on December 20, 2019, 12:57:20 PM
Quote from: dpierleo on December 16, 2019, 05:43:42 PM2) I would like to use capacitive touch screen with ft5x_ts driver.


Guess this is some dtc bug. Try updating it:
wget http://ftp.debian.org/debian/pool/main/d/device-tree-compiler/libfdt1_1.5.1-1_armhf.deb
dpkg -i libfdt1_1.5.1-1_armhf.deb

wget http://ftp.debian.org/debian/pool/main/d/device-tree-compiler/device-tree-compiler_1.5.1-1_armhf.deb
dpkg -i device-tree-compiler_1.5.1-1_armhf.deb
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: dpierleo on January 03, 2020, 01:20:21 PM
Hi selfbg,

thank you so much for your support.

Quote from: selfbg on December 20, 2019, 12:57:20 PMGuess this is some dtc bug. Try updating it

The point (2) is now ok. With updated version of dtc, the overlay is compiled well. I am about to try system with the right capacitive display.

For the point (1) I have three questions:

(a) During the boot process, where can I put the commands to unbind leds and to export pins that you suggested to me? In the rc.local? I guess that it is important to run these commands as soon as possible because otherwise we could have a moment of conflict where PI10 and PI11 are set as output (because the device tree sets those pins as leds) and the other device is also output on the same nodes.

(b) Can I unbind only some leds (not all)?

If I do:

echo leds >  /sys/bus/platform/drivers/leds-gpio/unbind
all three leds are unbound. How can I unbind only two of the three leds?
I tried changing "leds" with the name of single led but that does not work (single led is unrecognized).

(c) basically I would like to obtain the same thing I obtained with following FEX code:

[gpio_para]
gpio_used = 1
gpio_num = 17
gpio_pin_1 = port:PH00<0><default><default><default>
gpio_pin_2 = port:PI02<0><default><default><default>
gpio_pin_3 = port:PG00<0><default><default><default>
gpio_pin_4 = port:PG01<0><default><default><default>
gpio_pin_5 = port:PG02<0><default><default><default>
gpio_pin_6 = port:PG03<0><default><default><default>
gpio_pin_7 = port:PG04<0><default><default><default>
gpio_pin_8 = port:PG05<0><default><default><default>
gpio_pin_9 = port:PI10<0><default><default><default>
gpio_pin_10 = port:PI11<0><default><default><default>
gpio_pin_11 = port:PI12<0><default><default><default>
gpio_pin_12 = port:PI13<0><default><default><default>
gpio_pin_13 = port:PB05<0><default><default><default>
gpio_pin_14 = port:PB10<0><default><default><default>
gpio_pin_15 = port:PI14<0><default><default><default>
gpio_pin_16 = port:PI06<0><default><default><default>
gpio_pin_17 = port:PI07<0><default><default><default>

What do I have to do to reach the same result in device tree environment?


Thank you in advance for your help.

Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: JohnS on January 03, 2020, 03:41:32 PM
If you _never_ want certain pins to be outputs you need to be sure they power on OK, then uboot leaves them OK and your kernel never sets them as outputs.

If there would be bad enough results of even a glitch then change the hardware.

John
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: dpierleo on January 09, 2020, 12:58:52 PM
Thank you JohnS for your answer.

Unfortunately some pin like PI10 and PI11 are used as leds in evaluation board so they are set output and on when kernel starts. And I cannot change my hardware. The solution is only change device tree to have PI10 and PI11 not configured as leds. This is impossible using overlay (how selfbg explained to me in a previous post). I am still looking for a solution.

Thanks
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: dpierleo on January 09, 2020, 01:23:51 PM
Hi selfbg.

I tried to release pins PI10 and PI11 as you suggested to me:

echo leds >  /sys/bus/platform/drivers/leds-gpio/unbind
But I can add this line only in my rc.local file to automate the release.
It is too late!
My leds (so signal in pins PI10 and PI11) remain on for some seconds (from kernel start until the execution of rc.local) and those pins are connected to output in other device, so this condition is very dangerous for the hardware.

I simply need to change device tree to remove PI10 and PI11 reference (because you told me that it is not possible to do it using overlays) and to have those pins as input gpio.

When I used fex, I could use following lines in fex:

[gpio_para]
gpio_used = 1
gpio_num = 17
...
gpio_pin_9 = port:PI10<0><default><default><default>
gpio_pin_10 = port:PI11<0><default><default><default>
...

(1) How can I obtain the same thing with device tree?

(2) If necessary is it possible to recompile sun7i-a20-olimex-som204-evb-emmc.dts to remove lines about those leds? How can I recompile device tree? Which github path? What config and compile options to obtain the same dtb I found in last image Armbian_5.92.4_Olinuxino-a20_Ubuntu_bionic_next_5.2.21_desktop.img?

Thank you in advance
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: JohnS on January 09, 2020, 03:45:16 PM
You need hardware which is OK in all cases, including software fault.

It sounds like you absolutely need to fix the hardware.

This is completely normal in many use cases.

John
Title: Re: [A20-SOM204] Boot from eMMC using bootloader in SPI Flash and legacy kernel
Post by: dpierleo on January 09, 2020, 04:33:12 PM
Hi JohnS,

Thank you for your answer. But I would like to keep the focus on my question.
 
In the evaluation board, the pins PI10 and PI11 are correctly set as output and the system drives two leds with those pins.

In my custom board, the pins PI10 and PI11 must be set as inputs.

I simply need to change the device tree file, in order to obtain this different behaviour: at power-up moving directly from reset to input mode of those pins (reset --> input) and NOT reset --> output --> input.