1

I am starting with Yocto Project.

I wish to control GPIOs of BeagleBone Black with the image built with Yocto. Please help me. I simply find it hard to arrange the puzzles. Believe me I have "googled", but did not find something to glue the practical steps and understand the concepts.

I figure out it is something related to meta-yocto-bsp or I should build a BSP layer from scratch with the Boot modified for this.

Practically, I want to fire an LED when powering on the board,leave it on during the boot process and switch it to flash mode after the Operating System has been loaded.

I got some up and running knowledge of Yocto. Built several types of images, included an app in a Linux Image, did modifications to images.

I understood the notion of GPIOs and controlled these by

echo 48 > /sys/class/gpio/export
echo 'out' > /sys/class/gpio/gpio48/direction

toggle the GPIOs

echo 1 >  /sys/class/gpio/gpio48/value
echo 0 > /sys/class/gpio/gpio48/value

But I do not know how to modify the U-boot to set up the GPIO in Yocto Project before baking the actual Linux Image.

Thank you very much for your help.

George

George
  • 653
  • 6
  • 18

1 Answers1

1

I haven't worked on a beaglebone board but the basic process should be the same for U-Boot. There should be a c file for your board somewhere in the board/ subdirectory of the U-Boot git folder.

That board file will have a board_init function, (also an early init and a late init).

In one of those init functions, you can write to the GPIOs by using a gpio_request that looks something like:

gpio_request( SOME_MACRO(gpio_bank_num, gpio_num), "gpio name");
gpio_direction( SOME_MACRO(gpio_bank_num, gpio_num), 1); / 1 is O/P

where you can get the bank number, gpio number and name from the device tree file. And then rebuild u-boot and that should be it. Once the OS is loaded you can use the echo commands to the /sys/class/gpio directories as you wrote, to flash the led. You will have to work out how the gpio number (eg in your example 48) maps to a bank and number in the device tree. Obviously there is a lot of work to do but hope that's helpful.

secret squirrel
  • 802
  • 9
  • 13
  • Thank you for the quick answer. Let me clear this out. Please confirm or correct my understanding. I need to learn about U-boot. Clone the U-boot from its repository, modify it somehow and build U-boot with the new modifications. The build is to be done with BitBake? Next, as the Operating System loads I shall code the flash of the LED in a shell script file and appeal it somehow at startup. How shall I start the shell script automatically? Thank you again. – George Aug 10 '20 at 18:46
  • yup, actually u boot is quite easy, if you find the board init code and have the device tree file. im sure there are already gpio pins set there which you can use as examples. if your your yocto build has a u-boot/.../git/../.. structure, you can change the source and bit bake with yocto, or write a bb append. in Linux, you can use systemd to start a script when the os is loaded. – secret squirrel Aug 10 '20 at 19:57
  • use deviceTree, U-Boot should have all that and can handle "overlays" which are snippets that extend the base file. – TBR Aug 11 '20 at 07:07
  • My yocto build does not have the "u-boot/.../git/../..". I am using dunfell 3.1.1. What kind of image recipe should I use and which modifications to get this structure of Yocto build directory to allow me to set U-boot before baking the image? – George Aug 11 '20 at 07:19
  • oh, well you need to find the recipes folder where u-boot is -- the "meta-" folder. THen you can get the name of the recipe for u-boot, like u-boot-beaglebone or something (or use virtual/bootloader, maybe it works instead of recipe name)..if you get that far, there is a REALLY useful guide how to patch the source, i.e. create a patch file that you can add as a bb append, here: https://wiki.yoctoproject.org/wiki/TipsAndTricks/Patching_the_source_for_a_recipe. You run devtool modify , details in the link – secret squirrel Aug 11 '20 at 13:19
  • do you want to fire on the 4 user leds that are by default provided by the bbb? – apex Aug 13 '20 at 12:27
  • For the part " switch it to flash mode after the Operating System has been loaded." You may refer to this post create a .service file, mentioned the script that you like to execute. Than in the .sh file, mention the binary(the binary consist of functionalities for user led to switch to flash mode ) you like to execute https://stackoverflow.com/questions/40431674/post-install-script-on-yocto-built-linux, i thing for our case we no need to stop the service like the examples does. – KJ L Sep 01 '20 at 05:51