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.

AM4376: U-boot GPIO detection

Part Number: AM4376


Using AM4376 with u-boot-2018.01 from ti git.

I'm trying to get u-boot to detect a button depressed during startup to load a different recovery image. On our board, the button is on GPIO3_15, is there any code that illustrates how this can be done? Something like recovery mode in cellphones, where if the button is depressed for 5 seconds while starting up then load recovery, else go to regular image.

Thanks! 

  • Hi Arun,

    Arun Cherian said:
    I'm trying to get u-boot to detect a button depressed during startup to load a different recovery image

    If you want to keep U-Boot consistent, and then decide based on button press what image to load, you could develop a solution based on U-Boot ENV "scripting" by reading a GPIO (look at CONFIG_CMD_GPIO), and based on the result of that read updating what Kernel image / DTB / rootfs you load for example.

    Or you could intercept the button press in your U-Boot platform code by directly accessing the GPIO API (like shown here: https://e2e.ti.com/support/processors/f/791/p/854767/3165430#3165430), and based on that direct your boot flow.

    If you have some more specific requirements I might be able to point to a more tailored solution.

    Regards, Andreas

  • Thanks for your reply Andreas. 

    More details - I have a custom board based on the AM4376, with an eMMC that has two partitions. The first partition will have the MLO, and u-boot.img along with an RTOS .img file. The second partition will have Arago Linux.

    By default, the RTOS image will boot. But recovery/update mode is entered while the system is booted with the button on GPIO3_15 depressed for 5 seconds or more from boot. Then the Arago image boots and opens a WebUI from which the user can upload a new RTOS .img which will replace the one in the first partition. A subsequent reboot with the button not depressed will boot the new RTOS .img.

    What would the recommended approach be? The timing part of the button press, can that be done via scripting? 

    Regards,

    Arun

  • Hi Arun,

    in "RTOS mode", how do you load that image? From U-Boot too?

    if so, the approach I recommended with checking GPIO status via 'if gpio input' like shown below, and booting either image based on that, should work well:

    include/configs/omap3_beagle.h: "userbutton=if gpio input 173; then " \
    include/configs/omap3_beagle.h-                 "run userbutton_xm; " \
    include/configs/omap3_beagle.h-         "else " \
    include/configs/omap3_beagle.h-                 "run userbutton_nonxm; " \
    include/configs/omap3_beagle.h-         "fi;\0" \
    

    Arun Cherian said:
    The timing part of the button press, can that be done via scripting? 

    I would probably not have any extra timing functionality other than what you get inherently through the boot process and the fact that you'd check the GPIO status only after a few seconds into the boot process (once U-Boot is up). So you could tell the end user, hold down GPIO3_15, press reset, release reset, all while keeping GPIO3_15 pressed for a total of 5s or something like that. This should always allow your script to "catch" the GPIO state it wants. If you want additional delays, you could use U-Boot's 'sleep' command as part of your ENV script. You could even check GPIO3_15 multiple times in sequence such as CHECK -> SLEEP 1s -> CHECK -> SLEEP 1s [if GPIO still active] -> CHECK -> SLEEP ... etc This way you would ensure recovery mode is only entered when the user has actually held down the button for a while, and not because the user accidentally hit the button in the "wrong moment" during boot. Just some ideas.

    Regards, Andreas

  • Thanks Andreas, this works.