MichaIng / DietPi

Lightweight justice for your single-board computer!
https://dietpi.com/
GNU General Public License v2.0
4.9k stars 499 forks source link

Orange Pi Zero 3 | 1GB model shows up as a 2GB model after a reboot at random #7242

Open bigross8 opened 1 month ago

bigross8 commented 1 month ago

Creating a bug report/issue

Required Information

Steps to reproduce

  1. Check RAM size (either with free, htop or RAM usage in dietpi-banner
  2. Reboot and repeat

Expected behaviour

Show up as having 1GB of RAM on a 1GB model (919 MiB)

Actual behaviour

Intermittently shows up as having 2GB of RAM (1923 MiB)

Extra details

Randomly on a 6th reboot, the board thinks it has 2GB of RAM:

pwsh_cfM9kWSOkp

Then, I needed to reboot twice in order to show up with the correct amount of RAM:

pwsh_sSMyTcrZ3T

MichaIng commented 1 month ago

Many thanks for your report.

The RAM size is obtained by the bootloader. How old is your system/image, and in case did you flash the new bootloader build?

/boot/dietpi/func/dietpi-set_hardware flash-u-boot-mmc
reboot
bigross8 commented 1 month ago

I just got it running and set up today. I have not tried flashing the bootloader, I tried the commands you provided and rebooted. The board showed up with 2GB of RAM once again.

MichaIng commented 1 month ago

Do you have a USB-UART adapter, to check bootloader output via serial console? So far have not heard about issues with RAM size detection. There was a problem with 1.5 GB RAM detection in the past, requiring a dedicated bootloader build, but that has been solved months ago 🤔.

I just updated the bootloader package a few days ago. Our current image is shipped with 24.5.0 and you flashed 24.11.0, so both have the same issue for you, with 5 months between the two builds.

I'll also do some test reboots on my 2 GB models.

bigross8 commented 1 month ago

Yes I do have the adapter, this is the output:

U-Boot SPL 2024.01-armbian-2024.01-S866c-P667c-Ha9af-V5c1c-Bda0a-R448a (Oct 05 2024 - 02:23:53 +0000)
DRAM base address is defined as 0x40000000
DRAM has 16 b/raw, 10 b/col, 4 B/width, 1 #rank and 8 #bank
DRAM top address must be less than 0x80000000
DRAM: 2048 MiB
Trying to boot from MMC1
NOTICE:  BL31: v2.10.2(debug):armbian
NOTICE:  BL31: Built : 02:22:56, Oct  5 2024
NOTICE:  BL31: Detected Allwinner H616 SoC (1823)
NOTICE:  BL31: Found U-Boot DTB at 0x4a0b2eb8, model: OrangePi Zero3
INFO:    ARM GICv2 driver initialized
INFO:    Configuring SPC Controller
INFO:    PMIC: Probing AXP305 on RSB
ERROR:   RSB: set run-time address: 0x10003
INFO:    Could not init RSB: -65539
INFO:    BL31: Platform setup done
INFO:    BL31: Initializing runtime services
INFO:    BL31: cortex_a53: CPU workaround for erratum 855873 was applied
INFO:    BL31: cortex_a53: CPU workaround for erratum 1530924 was applied
INFO:    PSCI: Suspend is unavailable
INFO:    BL31: Preparing for EL3 exit to normal world
INFO:    Entry point address = 0x4a000000
INFO:    SPSR = 0x3c9
INFO:    Changed devicetree.
ns16550_serial serial@5000000: pinctrl_select_state_full: uclass_get_device_by_phandle_id: err=-19

U-Boot 2024.01-armbian-2024.01-S866c-P667c-Ha9af-V5c1c-Bda0a-R448a (Oct 05 2024 - 02:23:53 +0000) Allwinner Technology

CPU:   Allwinner H616 (SUN50I)
Model: OrangePi Zero3
DRAM:  2 GiB
Core:  57 devices, 25 uclasses, devicetree: separate
WDT:   Not starting watchdog@30090a0
MMC:   mmc@4020000: 0
Loading Environment from FAT... Unable to use mmc 0:1...
In:    serial@5000000
Out:   serial@5000000
Err:   serial@5000000
Allwinner mUSB OTG (Peripheral)
Net:   Unsupported value 13, using default (13)
Unsupported value 13, using default (13)
eth0: ethernet@5020000using musb-hdrc, OUT ep1out IN ep1in STATUS ep2in
MAC de:ad:be:ef:00:01
HOST MAC de:ad:be:ef:00:00
RNDIS ready
, eth1: usb_ether
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found
scanning bus usb@5200400 for devices... 1 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
Autoboot in 1 seconds, press <Space> to stop
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot/boot.scr
2765 bytes read in 2 ms (1.3 MiB/s)
## Executing script at 4fc00000
327 bytes read in 1 ms (319.3 KiB/s)
23443464 bytes read in 969 ms (23.1 MiB/s)
30496581 bytes read in 1260 ms (23.1 MiB/s)
35795 bytes read in 5 ms (6.8 MiB/s)
Working FDT set to 4fa00000
Moving Image from 0x40080000 to 0x40200000, end=418f0000
## Loading init Ramdisk from Legacy Image at 4ff00000 ...
   Image Name:   uInitrd
   Image Type:   AArch64 Linux RAMDisk Image (gzip compressed)
   Data Size:    30496517 Bytes = 29.1 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 4fa00000
   Booting using the fdt blob at 0x4fa00000
Working FDT set to 4fa00000
   Loading Ramdisk to 482ea000, end 49fff705 ... OK
   Loading Device Tree to 00000000482de000, end 00000000482e9bd2 ... OK
Working FDT set to 482de000

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]

...

After a reboot:

dietpi@zero3:~$ sudo reboot
Failed to connect to bus: No such file or directory
[   94.542072] systemd-shutdown[1]: Failed to set watchdog hardware timeout to 10min: Invalid argument
[   94.752471] reboot: Restarting system

U-Boot SPL 2024.01-armbian-2024.01-S866c-P667c-Ha9af-V5c1c-Bda0a-R448a (Oct 05 2024 - 02:23:53 +0000)
DRAM base address is defined as 0x40000000
DRAM has 15 b/raw, 10 b/col, 4 B/width, 1 #rank and 8 #bank
DRAM top address must be less than 0x40000000
DRAM: 1024 MiB
Trying to boot from MMC1
NOTICE:  BL31: v2.10.2(debug):armbian
NOTICE:  BL31: Built : 02:22:56, Oct  5 2024
NOTICE:  BL31: Detected Allwinner H616 SoC (1823)
NOTICE:  BL31: Found U-Boot DTB at 0x4a0b2eb8, model: OrangePi Zero3
INFO:    ARM GICv2 driver initialized
INFO:    Configuring SPC Controller
INFO:    PMIC: Probing AXP305 on RSB
ERROR:   RSB: set run-time address: 0x10003
INFO:    Could not init RSB: -65539
INFO:    BL31: Platform setup done
INFO:    BL31: Initializing runtime services
INFO:    BL31: cortex_a53: CPU workaround for erratum 855873 was applied
INFO:    BL31: cortex_a53: CPU workaround for erratum 1530924 was applied
INFO:    PSCI: Suspend is unavailable
INFO:    BL31: Preparing for EL3 exit to normal world
INFO:    Entry point address = 0x4a000000
INFO:    SPSR = 0x3c9
INFO:    Changed devicetree.
ns16550_serial serial@5000000: pinctrl_select_state_full: uclass_get_device_by_phandle_id: err=-19

U-Boot 2024.01-armbian-2024.01-S866c-P667c-Ha9af-V5c1c-Bda0a-R448a (Oct 05 2024 - 02:23:53 +0000) Allwinner Technology

CPU:   Allwinner H616 (SUN50I)
Model: OrangePi Zero3
DRAM:  1 GiB
Core:  57 devices, 25 uclasses, devicetree: separate
WDT:   Not starting watchdog@30090a0
MMC:   mmc@4020000: 0
Loading Environment from FAT... Unable to use mmc 0:1...
In:    serial@5000000
Out:   serial@5000000
Err:   serial@5000000
Allwinner mUSB OTG (Peripheral)
Net:   Unsupported value 13, using default (13)
Unsupported value 13, using default (13)
eth0: ethernet@5020000using musb-hdrc, OUT ep1out IN ep1in STATUS ep2in
MAC de:ad:be:ef:00:01
HOST MAC de:ad:be:ef:00:00
RNDIS ready
, eth1: usb_ether
starting USB...
Bus usb@5200000: USB EHCI 1.00
Bus usb@5200400: USB OHCI 1.0
scanning bus usb@5200000 for devices... 2 USB Device(s) found
scanning bus usb@5200400 for devices... 1 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
Autoboot in 1 seconds, press <Space> to stop
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot/boot.scr
2765 bytes read in 1 ms (2.6 MiB/s)
## Executing script at 4fc00000
327 bytes read in 1 ms (319.3 KiB/s)
23443464 bytes read in 969 ms (23.1 MiB/s)
30496581 bytes read in 1260 ms (23.1 MiB/s)
35795 bytes read in 5 ms (6.8 MiB/s)
Working FDT set to 4fa00000
Moving Image from 0x40080000 to 0x40200000, end=418f0000
## Loading init Ramdisk from Legacy Image at 4ff00000 ...
   Image Name:   uInitrd
   Image Type:   AArch64 Linux RAMDisk Image (gzip compressed)
   Data Size:    30496517 Bytes = 29.1 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
## Flattened Device Tree blob at 4fa00000
   Booting using the fdt blob at 0x4fa00000
Working FDT set to 4fa00000
   Loading Ramdisk to 482ea000, end 49fff705 ... OK
   Loading Device Tree to 00000000482de000, end 00000000482e9bd2 ... OK
Working FDT set to 482de000

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
...

I put these outputs into diffchecker and these are the lines that are different between them:

image

MichaIng commented 1 month ago

Thanks, well outlined the difference. Weird that it detects 16 b/raw sometimes, and 15 b/raw the other times, as this should be a static hardware value 🤔.

MichaIng commented 1 month ago

In general DRAM init code for this SoC is here: https://github.com/u-boot/u-boot/blob/master/arch/arm/mach-sunxi/dram_sun50i_h616.c

... ahh and now I find these messages in an Armbian patch: https://github.com/armbian/build/blob/main/patch/u-boot/u-boot-sunxi/opizero3-1.5GB-trim-from-u-boot-v2024.01.patch

The upper part is needed to detect and assign 1.5 GB RAM correctly. The bottom part however ... ah, it just adds debugging messages. The issue hence is config->rows which is not related to that patch, but wrong in the first place.

The values are derived here: https://github.com/u-boot/u-boot/blob/master/arch/arm/mach-sunxi/dram_sun50i_h616.c#L1363 I do not 100% understand the code, but it generally loops through a possible number of bits per column and row, derives the memory address/offset that would match the begin of RAM, and tests whether this is really the case, by writing and comparing values to the two addresses. This actually seems to be a correct method to me. The only value we do not see in logs, which could affect the outcome, is config->bus_full_width, which can be 0 or 1. If it should be 1 but is sometimes falsely detected as 0, it would lead to rows being detected as 1 bit larger, indeed. However, it would also make columns 1 bit larger, which is not the case. ... ah and u8 width = config->bus_full_width ? 4 : 2; => as the width is reported to be 4 in both your logs, bus_full_width must be 1 in both cases.

Here is the two functions which test whether the two addresses are the same: https://github.com/u-boot/u-boot/blob/master/arch/arm/mach-sunxi/dram_helpers.c#L28-L64 I do not see how this can fail either. Maybe if writing to both addresses fails, and both their values initially were different. But I guess the whole SPL would the fail.

MichaIng commented 1 month ago

I mailed the author of the U-Boot patch, in the hope he might have some idea how this can go randomly wrong.

vickash commented 1 month ago

@MichaIng thanks for mentioning. Will keep an eye on this thread. If there's anything I can test on my Zero 2W to help, let me know.