Detect gpio status in cboot

I want to switch the boot partition(emmc <-> nvme ssd) when the gpio value is low in cboot.

How do I get the gpio status and choose the boot partition in cboot?

The information as below.
Jetpack version : R32.4.4
Jetson device : Xavier NX, AGX Xavier, Nano

Thank you.

hello manny_wang,

please download L4T sources via download center, you may check the header file for the APIs to check GPIO status.
for example,
$L4T_Sources/r32.4.4/Linux_for_Tegra/source/public/cboot/bootloader/partner/t18x/cboot/include/dev/gpio.h

Hi JerryChang,

Thank you for your reply.

But I get the compile error as below when I include the “/dev/gpio.h” and use the apis.


/home/nvidia/Workspace/NVIDIA/SDKManager/SDK/JetPack_4.4.1_Linux_JETSON_XAVIER_NX/Linux_for_Tegra/cboot/bootloader/partner/t18x/cboot/top/main.c:74: undefined reference to `gpio_config’

/home/nvidia/Workspace/NVIDIA/SDKManager/SDK/JetPack_4.4.1_Linux_JETSON_XAVIER_NX/Linux_for_Tegra/cboot/bootloader/partner/t18x/cboot/top/main.c:76: undefined reference to `gpio_get’


Is it the static library?

If it does, I need to write the library name into Makefile, right?

hello manny_wang,

could you please try to include below header file for testing,
$L4T_Sources/r32.4.4/Linux_for_Tegra/source/public/cboot/bootloader/partner/common/include/drivers/tegrabl_gpio.h

please use this GPIO API for reading a GPIO pin state in CBoot.
for example,

static inline tegrabl_error_t gpio_read(struct gpio_driver *drv, uint32_t gpio_num, gpio_pin_state_t *state){...}

Hi JerryChang,

Which one is correct?

$L4T_Sources/r32.4.4/Linux_for_Tegra/source/public/cboot/bootloader/partner/t18x/cboot/include/dev/gpio.h

or

$L4T_Sources/r32.4.4/Linux_for_Tegra/source/public/cboot/bootloader/partner/common/include/drivers/tegrabl_gpio.h

thanks.

$L4T_Sources/r32.4.4/Linux_for_Tegra/source/public/cboot/bootloader/partner/common/include/drivers/tegrabl_gpio.h

Hi JerryChang,

I call the “tegrabl_gpio_driver_get” api in main.c file, and I get the panic error as below on boot.


[0001.791] [MANNY]tegrabl_gpio_driver_get…
[0001.795]
[0001.796] -----------------------------------------------
[0001.801] Synchronous Exception: DATA ABORT (FAR: ffffffffffffffec)
[0001.807] -----------------------------------------------
[0001.813] PAR_ELX: 0x809
[0001.815]
[0001.816] ESR 0x96000004: ec 0x25, il 0x1, iss 0x4
[0001.821] -----------------------------------------------
[0001.826] [Stack Trace]
[0001.828]
[0001.830] => pc:0xA0622218, sp:0xA068CD80
[0001.833] => pc:0xA060F358, sp:0xA068CFB0
[0001.837] => pc:0xA060018C, sp:0xA068CFC0
[0001.841] -----------------------------------------------
[0001.846] iframe 0xa068cc90:
[0001.849] x0 0x 0 x1 0x a068cff8 x2 0xffffffffffffffe8 x3 0x a068dc88
[0001.858] x4 0x 0 x5 0x a068cdc0 x6 0x 20 x7 0x 7
[0001.867] x8 0x 0 x9 0x a x10 0x aafff60f x11 0x a0600010
[0001.876] x12 0x 0 x13 0x 0 x14 0x 0 x15 0x 3c0
[0001.885] x16 0x 0 x17 0x 0 x18 0x a600000 x19 0x a066a688
[0001.895] x20 0x 0 x21 0x 0 x22 0x a0600190 x23 0x 0
[0001.904] x24 0x 0 x25 0x 0 x26 0x 0 x27 0x 0
[0001.913] x28 0x 0 x29 0x a068cfb0 lr 0x a060f35c sp 0x a068cd80
[0001.922] elr 0x a0622218
[0001.925] spsr 0x 200002c9
[0001.928] -----------------------------------------------
[0001.933] panic (caller 0xa0601238): die
[0001.937] HALT: spinning forever…

how do i fix the problem? and what is the root cause?

hello manny_wang,

you may check you’re assign correct pin numbers.
this tegrabl_gpio_driver_get() API will retrieve a handle to a GPIO driver from its chip_id number.

Hi JerryChang,

The pin number’s value is 446.

The signal name is “I2C0_DOUT”(Pin# 193) in the ODM document.

There will get the error code, not the panic when I use the incorrect number, right?

hello manny_wang,

according to pinmux spreadsheets. the signal name is I2S0_DOUT for pin# 193, it is GPIO3_PT.06.
you may also refer to Xavier NX’s GPIO definition,
for example,
$L4T_Sources/r32.4.4/Linux_for_Tegra/source/public/kernel/nvidia/include/dt-bindings/gpio/tegra194-gpio.h


you’re correct this pin number is 446 form kernel side, which coming from ( (19 * 8) + 6) + 288 = 446.
however, you should note that there’re GPIO allocation ranges for kernel.
for example, you may found the kernel init messages to register these GPIO within the range.

[    0.875748] gpiochip_setup_dev: registered GPIOs 288 to 511 on device: gpiochip0 (tegra-gpio)

according to Boot Flow, since you’re going to check the GPIO state in CBoot.
could you please revise the pin number as (19 * 8) + 6 = 158, for verification.
thanks

Hi JerryChang,

Before revise the pin number, I want to check the error message.

It happened panic when i use the " tegrabl_gpio_driver_get".

Maybe the root cause is NOT the pin number, right?

hello manny_wang,

ideally, it should return TEGRABL_ERR_NOT_FOUND if you’re assign incorrect pin number.
thanks

Hi JerryChang,

So, why do I get the panic?

The API can NOT use in lk_main function?

had you tried to revise the pin number as (19 * 8) + 6 = 158, for verification ?

Yes, I try it.

But the panic still happened when I use the “tegrabl_gpio_driver_get”.

hello manny_wang,

FYI,
it turns out CBoot can’t load NVMe, because it doesn’t have the NVMe driver.

Hi JerryChang,

OK. But I still want to know what is the root cause of panic issue.

Could you just tell me why do I get the panic when I use the “tegrabl_gpio_driver_get” API in lk_main function in main.c.

can you share the panic log?

putty.log (55.4 KB)

There is no update from you for a period, assuming this is not an issue any more.
Hence we are closing this topic. If need further support, please open a new one.
Thanks

can you share the change you made.
this is not kernel panic. this cboot panic.