This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA4VEN-Q1: Linux kernel crashes after readl call occurs panic

Part Number: TDA4VEN-Q1

Tool/software:

Tool/software:

Hi, experts

I added a piece of code to the kernel source code ti-processor-sdk-linux-adas-j722s-evm-10_00_00_08/board-support/ti-linux-kernel-6.6.32+git-ti/init/main.c as follows

#define MMC1_CTL_REG 0x0FA00024
/* return 1 use sd card file system */
static int use_sdcard_filesystem(void)
{
	int ret;
	void __iomem *mmc1_ctl_reg;
	unsigned int val;

	mmc1_ctl_reg = ioremap(MMC1_CTL_REG, 4);
	val = readl(mmc1_ctl_reg);
	ret = val & CARD_DETECT;

	iounmap(mmc1_ctl_reg);

	return ret;
}

The function of this code is to detect whether the sd card is inserted or not.

The strange thing is that I compiled that code into a module using insmod to load the module and no panic occurs, what is the reason for that?

 

board: custom board

sdk: 10_00_00_08

Best Regards,

Bing

  • Hi,

    Please share the crash log? From the code it appears that you might be crashing while you read the register.|
    Either ioremap has failed or reading that has failed. Is the module turned on before this access?
    Why can't you do this in the sdhci driver?

    - Keerthy

  • Hi Keerthy,

    Please share the crash log?

    [    0.000000] ------------[ cut here ]------------
    [    0.000000] WARNING: CPU: 0 PID: 0 at mm/ioremap.c:23 generic_ioremap_prot+0xc8/0x104
    [    0.000000] Modules linked in:
    [    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 6.6.32 #57
    [    0.000000] Hardware name: Texas Instruments J722S EVM (DT)
    [    0.000000] pstate: 800000c5 (Nzcv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
    [    0.000000] pc : generic_ioremap_prot+0xc8/0x104
    [    0.000000] lr : generic_ioremap_prot+0x28/0x104
    [    0.000000] sp : ffff8000812a3dd0
    [    0.000000] x29: ffff8000812a3dd0 x28: 00000000810360ac x27: 0000000000000000
    [    0.000000] x26: 0000000000000000 x25: 0000000000000000 x24: ffff8000813df000
    [    0.000000] x23: 0068000000000f13 x22: 0068000000000713 x21: ffff8000800ae5a0
    [    0.000000] x20: 000000000fa00024 x19: 0000000000000004 x18: 0000000000000006
    [    0.000000] x17: 000000000000002f x16: 00000000fdc612e0 x15: ffff8000812a3870
    [    0.000000] x14: 000000000000000a x13: ffff8000812bea50 x12: 00000000000000d8
    [    0.000000] x11: 0000000000000048 x10: ffff800081316a50 x9 : ffff8000812bea50
    [    0.000000] x8 : 00000000ffffefff x7 : 0000000000000018 x6 : ffff80008140e638
    [    0.000000] x5 : ffff80008140e638 x4 : 0000000000000000 x3 : 0000000000000000
    [    0.000000] x2 : 0068000000000713 x1 : 0000000000000004 x0 : 0000000000000000
    [    0.000000] Call trace:
    [    0.000000]  generic_ioremap_prot+0xc8/0x104
    [    0.000000]  ioremap_prot+0x50/0x78
    [    0.000000]  start_kernel+0xac/0x6f0
    [    0.000000]  __primary_switched+0xbc/0xc4
    [    0.000000] ---[ end trace 0000000000000000 ]---
    [    0.000000] +++++++++++++
    [    0.000000] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
    [    0.000000] Mem abort info:
    [    0.000000]   ESR = 0x0000000096000004
    [    0.000000]   EC = 0x25: DABT (current EL), IL = 32 bits
    [    0.000000]   SET = 0, FnV = 0
    [    0.000000]   EA = 0, S1PTW = 0
    [    0.000000]   FSC = 0x04: level 0 translation fault
    [    0.000000] Data abort info:
    [    0.000000]   ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000
    [    0.000000]   CM = 0, WnR = 0, TnD = 0, TagAccess = 0
    [    0.000000]   GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
    [    0.000000] [0000000000000000] user address but active_mm is swapper
    [    0.000000] Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP
    [    0.000000] Modules linked in:
    [    0.000000] CPU: 0 PID: 0 Comm: swapper Tainted: G        W          6.6.32 #57
    [    0.000000] Hardware name: Texas Instruments J722S EVM (DT)
    [    0.000000] pstate: 600000c5 (nZCv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
    [    0.000000] pc : readl+0x0/0x18
    [    0.000000] lr : start_kernel+0xc4/0x6f0
    [    0.000000] sp : ffff8000812a3e40
    [    0.000000] x29: ffff8000812a3e40 x28: 00000000810360ac x27: 0000000000000000
    [    0.000000] x26: 0000000000000000 x25: 0000000000000000 x24: ffff8000813df000
    [    0.000000] x23: 0068000000000f13 x22: ffff8000812a9940 x21: 0068000000000713
    [    0.000000] x20: 0000000000000e12 x19: 0000000000000000 x18: 0000000000000006
    [    0.000000] x17: 000000000000002f x16: 00000000fdc612e0 x15: ffff8000812a3870
    [    0.000000] x14: 0000000000000000 x13: ffff8000812bea50 x12: 0000000000000126
    [    0.000000] x11: 0000000000000062 x10: ffff800081316a50 x9 : ffff8000812bea50
    [    0.000000] x8 : 00000000ffffefff x7 : ffff800081316a50 x6 : 80000000fffff000
    [    0.000000] x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000000
    [    0.000000] x2 : 0000000000000000 x1 : ffff8000812b2b40 x0 : 0000000000000000
    [    0.000000] Call trace:
    [    0.000000]  readl+0x0/0x18
    [    0.000000]  __primary_switched+0xbc/0xc4
    [    0.000000] Code: d53cd040 d53cd040 d53cd040 d53cd040 (b9400000) 
    [    0.000000] ---[ end trace 0000000000000000 ]---
    [    0.000000] Kernel panic - not syncing: Attempted to kill the idle task!
    [    0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---
    

    Is the module turned on before this access?

    Which module are you referring to?

    Why can't you do this in the sdhci driver?

    Because I want to determine which part of the root filesystem to use depending on whether or not I insert an sd card, whether I use mmcblk1p2 or mmcblk0p2 or mmcblk0p3.I have booted successfully by referring to that link J722S MCU+ SDK: SBL SD HLOS, but found that the root filesystem selection is fixed in the device tree, such as root=/dev/mmcblk1p2,so I want to implement dynamic selection of the root filesystem.

    Best Regards,

    Bing

  • Hi bing,

    Just for more clarity :

    The extra code that you added was failing/crashing when added to i-processor-sdk-linux-adas-j722s-evm-10_00_00_08/board-support/ti-linux-kernel-6.6.32+git-ti/init/main.c .

    However , when you made the same code to a module and did insmod and booted,it did not crash.

    Am I right Bing ? Please correct me if I am wrong.

    Regards

    Gokul

  • Hi Gokul,

    Am I right Bing ? Please correct me if I am wrong.

    Yeah, you're right.

    Best Regards,

    Bing

  • Hi Bing,

    The function of this code is to detect whether the sd card is inserted or not.

    The strange thing is that I compiled that code into a module using insmod to load the module and no panic occurs, what is the reason for that?

    The reason for this is because, when the code is added to the init function,the host controller of the sd card is not yet probed by its driver.Hence ,the MMCSD registers have not been initialized.

    However,in the case of a module,since it is done when the kernel boots up,the sd card registers are already memory mapped by the sdhci driver of the sd card.

  • Hi Gokul,

    the sd card registers are already memory mapped by the sdhci driver of the sd card.

    How does the sdhci driver map the sd card registers? Can I use a similar method in main.c to map and then go to read the registers and finally unmap them?

    Best Regards,

    Bing

  • Hi bing,

    How does the sdhci driver map the sd card registers? Can I use a similar method in main.c to map and then go to read the registers and finally unmap them?

    In order to memory map ,first the sd card must be probed,so that the device registers are initialized and this probing is done in the sdhci driver.Just mapping wouldn't solve the problem.

    Regards

    Gokul

  • Hi Gokul,

    My understanding is that I only need to port part of the sdhci driver part of the code to achieve my needs, can you help assist in achieving my needs?

    Best Regards,

    Bing

  • Hi Gokul,

    If there is a problem with my understanding, please let me know and I will drop this feature.

    Best Regards,

    Bing

  • Hi bing,

    My understanding is that I only need to port part of the sdhci driver part of the code to achieve my needs, can you help assist in achieving my needs?

    The issue is that even if you port a part of the driver code,there might be other dependencies.

    For eg : Before the sd card is probed,all its dependencies like the voltage regulator,pins etc are probed,by the linux kernel.

    Hence,porting a part of the code wont work.

    Best Regards

    Gokul 

  • Hi Gokul,

    Thank you for your reply.

    Best Regards,

    Bing