linux4sam / at91bootstrap

Second level bootloader for Microchip SoC (aka AT91)
https://www.linux4sam.org/linux4sam/bin/view/Linux4SAM/AT91Bootstrap4
112 stars 232 forks source link

SAMA5D2 at91Bootstrap 4.0.1: SDHC no card inserted #154

Closed UltimateRiggsy closed 2 years ago

UltimateRiggsy commented 2 years ago

I'm having a problem getting a proper defconfig for the 4.0.1 at91bootstrap. I have a board based on the acme roadrunner berta that works fine with the 3.9.1(and earlier) at91bootstrap, but am trying to move to linux4sam-2021.10, and have an issue with it recognizing SDHC1 on boot:

On boot, my output is:

AT91Bootstrap 4.0.1 (2022-06-09 21:11:36)

SD/MMC: Image: Read file zImage to 0x22000000 MMC: ADMA supported SDHC: Error: No Card Inserted *** FATFS: f_open, filename: [zImage]: error SD/MMC: Failed to load image

For AT91Bootstrap 3.9.1, the defconfig is simple, and contrib/board/acme/sama5d2_roadrunner_defconfig contains:

CONFIG_SAMA5D2_ROADRUNNER=y CONFIG_RAM_256MB=y CONFIG_DDR3=y CONFIG_SDCARD=y CONFIG_SDHC1=y CONFIG_LOAD_LINUX=y CONFIG_OVERRIDE_CMDLINE=y CONFIG_LINUX_KERNEL_ARG_STRING="mem=256M console=ttyS0,115200 root=/dev/mmcblk0p 2 rootfstype=ext4 rw rootwait consoleblank=0" CONFIG_IMAGE_NAME="zImage" CONFIG_DEBUG=y

For AT91Bootstrap 4.0.1( maybe it's not for 4.0.1?), acme has a copy of the defconfig file I'm using on their website here:

https://www.acmesystems.it/www/roadrunner_compile_kernel_5_4/acme-roadrunner_defconfig

I tried to create a stripped down defconfig file, taking into account info from issue 126 from edgar-bonet, but get the same results.

Any thoughts of what to try or change appreciated. I've tried a bunch of things, primarily trying slightly different settings in the defconfig to see if I can affect the problem somehow, but it's largely resulted in jiggling the handle

ehristev commented 2 years ago

Hi,

Is it possible that your bootstrap is actually searching for SDHC0 (which has no card inserted) , hence you getting this error ? And it is not searching SDHC1 which you wanted to happen ? Can you check in menuconfig if SDHC1 is selected ? (in the acme defconfig I do not see SDHC1=y ) @edgar-bonet maybe can have a look here ?

Eugen

UltimateRiggsy commented 2 years ago

HI Eugen,

Thanks for your reply.

After fighting with this a bit, I think that one of the issues I was having is related to settings not getting picked up properly in my buildroot.

I think you are correct that it was not using the settings that I thought it was using (from the config file).

I've pulled the at91bootstrap out to be built separately for the time being.

It's still not working given the file from acme. To be specific, placing the above linked file in the configs directory and running

make acme-roadrunner_defconfig

It appears to get some of the config correct, but falls down when configuring flash memory, and leaves it setup for uboot.

But at least if I make changes via menuconfig, they are reflected when the bootloader runs. I think the rest is trying to understand how the previous settings map to new settings, to try and get a working .config.

So I'm getting different error messages, which somehow feels like progress ;)

My current config(I stripped all lines including the pound sign, as it bolds them here on github):

(trying to use the code hashtags, but github is somehow not interpreting them?) ` CONFIG_HAVE_DOT_CONFIG=y CONFIG_LOAD_AND_JUMP=y CONFIG_LOAD_SW=y CONFIG_JUMP_TO_SW=y CONFIG_SAMA5D2=y CONFIG_SPI_BUS_MAX=1 CONFIG_SPI_IOSET_MAX=3 CONFIG_QSPI_BUS_MAX=1 CONFIG_QSPI_IOSET_MAX=3 CONFIG_DEVICENAME="sama5d2" CONFIG_TWI_IOSET=y CONFIG_TWI_IOSET_MAX=4 CONFIG_FLEXCOM_TWI_IOSET=y CONFIG_FLEXCOM_TWI_IOSET_MAX=3

CONFIG_CRYSTAL_12_000MHZ=y CONFIG_MAINOSC_MEASUREMENT=y

CONFIG_SCLK=y CONFIG_ALLOW_CRYSTAL_12_000MHZ=y CONFIG_ALLOW_CRYSTAL_24_000MHZ=y CONFIG_CPU_CLK_498MHZ=y CONFIG_ALLOW_CPU_CLK_492MHZ=y CONFIG_ALLOW_CPU_CLK_498MHZ=y CONFIG_BUS_SPEED_166MHZ=y CONFIG_SUPPORT_BUS_SPEED_116MHZ=y CONFIG_SUPPORT_BUS_SPEED_164MHZ=y CONFIG_SUPPORT_BUS_SPEED_166MHZ=y

CONFIG_CONSOLE_INDEX=1 CONFIG_DEBUG=y CONFIG_DEBUG_VERY_LOUD=y CONFIG_HW_DISPLAY_BANNER=y CONFIG_HW_BANNER="\"\n\nAT91Bootstrap \" AT91BOOTSTRAP_VERSION \" (\" COMPILE_TIME \")\n\n\"" CONFIG_LINK_ADDR="0x200000" CONFIG_TOP_OF_MEMORY="0x210000" CONFIG_CPU_HAS_TRUSTZONE=y CONFIG_CPU_V7=y CONFIG_CORE_CORTEX_A5=y CONFIG_CPU_HAS_DDRC=y CONFIG_CPU_HAS_SCKC=y CONFIG_CPU_HAS_H32MXDIV=y CONFIG_CPU_HAS_SDHC0=y CONFIG_CPU_HAS_SDHC1=y CONFIG_CPU_HAS_SPI=y CONFIG_CPU_HAS_SPI_IOSET=y CONFIG_CPU_HAS_QSPI=y CONFIG_CPU_HAS_QSPI_IOSET=y CONFIG_CPU_HAS_L2CC=y CONFIG_CPU_HAS_PMECC=y CONFIG_CPU_HAS_TWI0=y CONFIG_CPU_HAS_TWI1=y CONFIG_CPU_HAS_AES=y CONFIG_CPU_HAS_PIO4=y CONFIG_FLEXCOM=y CONFIG_CPU_HAS_FLEXCOM0=y CONFIG_CPU_HAS_FLEXCOM1=y CONFIG_CPU_HAS_FLEXCOM2=y CONFIG_CPU_HAS_FLEXCOM3=y CONFIG_CPU_HAS_FLEXCOM4=y

CONFIG_DDRC=y CONFIG_BANK_4=y CONFIG_DDR_SET_BY_JEDEC=y CONFIG_DDR3=y CONFIG_DBW_16=y CONFIG_DDR_2_GBIT=y CONFIG_CAS_5=y CONFIG_DDR_SPEED_800=y CONFIG_REF_WIN_32=y CONFIG_REF_2048=y

CONFIG_SDCARD=y CONFIG_MEMORY="sdcard"

CONFIG_SDHC=y CONFIG_SDHC1=y CONFIG_FATFS=y CONFIG_ALLOW_BOOT_FROM_DATAFLASH_CS0=y CONFIG_ALLOW_BOOT_FROM_DATAFLASH_CS1=y CONFIG_ALLOW_BOOT_FROM_DATAFLASH_CS2=y CONFIG_ALLOW_BOOT_FROM_DATAFLASH_CS3=y CONFIG_BOOTSTRAP_MAXSIZE="65536" CONFIG_PROJECT="sdcard" CONFIG_LOAD_LINUX=y CONFIG_LINUX_IMAGE=y

CONFIG_OVERRIDE_CMDLINE=y CONFIG_LINUX_KERNEL_ARG_STRING="CONFIG_ARG_CONSOLE CONFIG_ARG_MTD CONFIG_ARG_ROOT CONFIG_ARG_ROOTFSTYPE CONFIG_ARG_DELAY CONFIG_ARG_CMA CONFIG_ARG_RW CONFIG_ARG_ROOTWAIT" CONFIG_ARG_CMA="cma=256m" CONFIG_ARG_CONSOLE="console=ttyS0,115200" CONFIG_ARG_DELAY=" rootdelay=2" CONFIG_ARG_MEMTEST="" CONFIG_ARG_MTD="" CONFIG_ARG_PRINTK="" CONFIG_ARG_ROOT=" root=/dev/mmcblk0p2" CONFIG_ARG_ROOTFSTYPE=" rootfstype=ext4" CONFIG_ARG_ROOTWAIT=" rootwait" CONFIG_ARG_RW=" rw" CONFIG_JUMP_ADDR="0x22000000"

CONFIG_OF_LIBFDT=y CONFIG_OF_OVERRIDE_DTB_NAME="acme-roadrunner.dtb" CONFIG_OF_ADDRESS="0x21000000" CONFIG_IMAGE_NAME="zImage" CONFIG_MACH_TYPE="9999" CONFIG_DISABLE_WATCHDOG=y

CONFIG_MATRIX=y CONFIG_REDIRECT_ALL_INTS_AIC=y

CONFIG_BOARD_QUIRK_NONE=y

CONFIG_PIT=y CONFIG_WDT=y CONFIG_RSTC=y CONFIG_USART=y CONFIG_PIO=y CONFIG_PMC_COMMON=y CONFIG_PMC_V1=y CONFIG_PMC_PERIPH_CLK_SAM9X5=y CONFIG_PMC_GENERIC_CLK=y CONFIG_PMC_UTMI_CLK=y CONFIG_PMC_PLL_CLK=y CONFIG_PMC_MCK_CLK=y CONFIG_SFRBU=y

`

My current output is (moved to 4.0.3, because why not if I'm building it separately, pick up any bug fixes, etc.):

AT91Bootstrap 4.0.3 (2022-06-14 10:04:03)

All interrupts redirected to AIC SD/MMC: Image: Read file zImage to 0x22000000 MMC: ADMA supported SDHC: Error: No Card Inserted *** FATFS: f_open, filename: [zImage]: error SD/MMC: Failed to load image

Is this indicating that it is finding and loading zImage (the first time), and then is subsequently having a problem, perhaps inside or post zImage, or just duplicate messages from different levels because I upped the debug verbosity?

Regards

Jon

ehristev commented 2 years ago

I see that you are getting 'No Card Inserted', meaning that you are likely to try to read from the wrong SDHC instance ? Other variant is that you are not having the proper pinctrl initialized. Can you go to menuconfig and see which CONFIG_SDHC is set ?

ehristev commented 2 years ago

In your config it appears fine: CONFIG_SDHC and CONFIG_SDHC1 Can you look in the generated .config, it should be something similar to this:

#                                                                                
# SD Card Configuration                                                          
#                                                                                
CONFIG_SDHC=y                                                                    
# CONFIG_SDHC0 is not set                                                        
CONFIG_SDHC1=y         

Note that # CONFIG_SDHC0 is not set must be there, even if it appears to be a comment

UltimateRiggsy commented 2 years ago

Hi Eugen,

Thank you for your suggestions. CONFIG_SDHC1=y is set, with the other lines still there as comments

Here is a link to my complete .config file.
https://shinybox.com/peekaboo/at91bootstrap_config

This one was created using menuconfig from scratch, and gives me the same output results on boot. And just to confirm, similar config settings on the 3.9.1 at91bootstrap work correctly. I'm going through the two menuconfigs side by side looking for differences, but have yet to find anything.

AT91Bootstrap 4.0.3 (2022-06-15 08:21:59)

All interrupts redirected to AIC SD/MMC: Image: Read file zImage to 0x22000000 MMC: ADMA supported SDHC: Error: No Card Inserted *** FATFS: f_open, filename: [zImage]: error SD/MMC: Failed to load image

ehristev commented 2 years ago

Hi,

In acme board in at91bootstrap-3.x

https://github.com/linux4sam/at91bootstrap/blob/at91bootstrap-3.x/contrib/board/acme/sama5d2_roadrunner/sama5d2_roadrunner.c#L804

I see a pull down enabled on CD pin. Could you try to do this change in bootstrap-4.x and see if this changes anything ?

Eugen

UltimateRiggsy commented 2 years ago

Hi Eugen,

I was able to try your suggestion this morning, and it does indeed solve my at91bootstap problem.

The bootloader is able to see the SD card, load the dtb, and seems to hang when loading the kernel. (the last bit there is something for me to figure out ;) )

AT91Bootstrap 4.0.3 (2022-06-15 08:47:44)

All interrupts redirected to AIC SD/MMC: Image: Read file zImage to 0x22000000 MMC: ADMA supported mmc_verify_operating_condition SDHC: Timeout waiting for command complete SD: Card Capacity: High or Extended sd card identified with CID = 0x3534457 0x44313647 0x801ca8b2 0x830149ff sdcard_identification success SD: Specification Version 3.0X SD/MMC: dt blob: Read file sama5d2.dtb to 0x21000000 KERNEL: try as zImage: magic=0x16f2818

KERNEL: Booting zImage ... DT: Using device tree in place at 0x21000000

KERNEL: Starting linux kernel ..., machid: 0xffffffff

The only follow up question would be, given the new framework with the 4.x at91bootstrap, what would be the strategy for proper implementation of a change like this, given the context of the at91bootstrap as part of buildroot? A patch file to make the change?

Thanks so much for your help with this, very much appreciated.

Regards

Jon

ehristev commented 2 years ago

Hi,

I am glad this solves your problem. We cannot directly change this in sama5d2.c because all sama5d2 boards use it. To make it work, do something similar with a Quirk. Have a look at e.g. CONFIG_BOARD_QUIRK_SAMA5D2_XULT . Create something like CONFIG_BOARD_QUIRK_SAMA5D2_SDMMC1_CD_PD and then in the code, if this is selected, have the pull-down enabled, and default otherwise. Then, in your board defconfig, select this symbol CONFIG_BOARD_QUIRK_SAMA5D2_SDMMC1_CD_PD . You can also send the board defconfig as a separate patch and I can merge it to the main tree .

Eugen

UltimateRiggsy commented 2 years ago

I thought I was done with the bootloadr, but apparently I'm just a step further.

It appears to be recognizing the SD card (per the output in my last message above), but appears to be hanging when trying to load the kernel(I've tried with a couple different sd images, and they all behave the same):

KERNEL: Booting zImage ... DT: Using device tree in place at 0x21000000

KERNEL: Starting linux kernel ..., machid: 0xffffffff

I'm going through the 3.9.1 acme code to see if there are other differences that may need to be applied in some fashion to the 4.0.1 at91bootloader. Any thoughts on other things to check appreciated.

(I guess as consolation, I downloaded the kernel 5.4 image from the acme site, and they appear to still be using the 3.9.1 at91bootloader, so perhaps they are as stuck as I am).

Regards

Jon

ehristev commented 2 years ago

Hi,

What comes to my mind is the fact that the bootloader could not prepare correctly the setup for kernel booting. Try to enable DEBUG_LL in the kernel, and change the bootargs to have early console and early printk, make sure that DEBUG_LL console is correctly set for your platform. From the output of the early console you could figure out where is the problem. The same kernel image boots with 3.9.1 ? This way we can understand if the bootloader is the culprit here.

Eugen

ehristev commented 2 years ago

Could you open another issue if your kernel has problems booting ? As we solved the sdcard problem, it would be easier to track problems if we would continue in another , new thread. Thanks!

ssekar15 commented 1 year ago

@ehristev @UltimateRiggsy Is there any followup issue for this? I'm stuck at the last point here kernel is not booting (guess there some ddr3 setting issue)

The same kernel image boots with 3.9.1 ? This way we can understand if the bootloader is the culprit here. yes 3.9.1 works fine