u-boot.cfg file in U-boot - u-boot

I am understanding the U-boot build, it seems the selected config options in Kconfig are updated in u-boot.cfg file.
Can you guide to understand how it is created and the usage of this file(who will use this file).

The current U-Boot configuration options are stored in file .config.
You can create a default configuration my using one of the filenames in configs/, e.g.
make qemu_arm64_defconfig
To adjust the configuation use
make menuconfig
https://opensource.com/article/18/10/kbuild-and-kconfig has some more detail about the internals of the Kconfig system.

The u-boot.cfg file is produced when you build U-Boot. It is just there to let you see what config options were selected.
Normally you edit the configs/..._defconfig files to actually change the configuration of U-Boot for a board.

Related

How to use custom device tree source correctly in buildroot?

I made a copy of the dts from <linux>/board/arch/arm/boot/dts/imx28-evk.dts for using with my custom board. My custom device-tree is named imx28-custom.dts and is pointed in the Out of tree custom DTS menu entry (BR2_LINUX_KERNEL_CUSTOM_DTS_PATH) in the Buildroot config.
However u-boot is configured to use the existing MX28 board config. After building a kernel I have imx28-custom.dtb and zImage in the <buildroot>/output/images folder.
When the system boots, u-boot tells that imx28-evk.dtb is not found. Why was imx28-custom.dtb built but is not found by u-boot? Why u-boot doesn't find its own device-tree (imx28-evk.dtb) for itself and my custom device-tree for the kernel? I assumed that BR2_LINUX_KERNEL_CUSTOM_DTS_PATH relates only to the kernel. How can my custom device-tree be passed to the kernel if u-boot tries to use its own imx28-evk.dtb for this?
u-boot complaining about not finding the device-tree is related to the Linux kernel: when booting, u-boot loads the device-tree and kernel image from the storage to specified addresses in the memory and then passes control to the kernel. The default configuration for the i.MX28-EVK board is to pass the imx28-evk.dtb file.
The BR2_LINUX_KERNEL_CUSTOM_DTS_PATH only serves to include the custom device-tree in the files to build and install but does not configure u-boot to use it.
Which device-tree u-boot passes to the kernel is defined by u-boot's CONFIG_DEFAULT_FDT_FILE option (you can edit this by typing make uboot-menuconfig (see my note at the end) then going under Boot to set the Default fdt file). This option should be set to something like imx28-custom.dtb.
How to configure u-boot from Buildroot is described here and here to make them permanent.
In the case of the i.MX28-EVK, Buildroot uses the Legacy build system (which is to be used up to u-boot 2015.04, but the config uses 2020.04) which does not allow the use of the make uboot-menuconfig command. You should safely be able to change that. You need to set the Build system to Kconfig and set the Board defconfig to mx28evk.

Loading my own device driver as builtin in Yocto on my own meta layer

I wrote my own USB driver for hardware and I want to add this driver as builtin. I have seen this post where they create a recipe to set as module and not builtin.
http://wiki.kaeilos.com/index.php/Howto_build_a_kernel_module_out_of_the_kernel_tree
Can you please guys help me in creating a recipe to set the module as builtin.
Thanks for your time.
You can't have external modules built into Linux Kernel. So you need to place your driver into drivers/usb/ (based on the hardware type it needs to be placed in drivers/usb/host/ if it is host controller driver or drivers/usb/dwc* or drivers/usb/gadget/udc if it is gadget driver) of your Linux Kernel tree.
Then you need to add according configuration in Kconfig and Makefile in drivers/usb. Finally you need to enable this as build in driver in defconfig/.config for building.
In short,
Place your driver in drivers/usb
Add Kconfig and Makefile. For example, CONFIG_USB_HW_HCD
Add to defconfig as CONFIG_USB_HW_HCD=y. In Yocto you can specify the defconfig file as file://defconfig in your SRC_URI.
EDIT:
As you are using meta-intel directly, you can create patch and bbappend to it. To do it,
git clone "intel kernel repo"
Add driver as mentioned above. Copy to drivers/usb, add Kconfig, Makefile entry.
Add this driver to git repo using git add + git commit
Create patch using git format-patch
Create a .bbappend file and add this patch. You can place this .bbappend file in any of your custom layer or in meta-intel itself.
Add defconfig fragment also into the .bbappend file for your Linux Kernel.
This way you don't need to have separate repo of same Linux Kernel.
I hope your initial module will have module_init() and module_exit calls.
To make this usb module to be part of builtin kernel, very first thing is to modify you source code to remove module_init or module_exit calls add platform calls probe, init, etc./
Copy your source file to appropriate source directory like "driver/usb/*"
Add a entry in KCONFIG file with some description of that driver and also add rules for its dependencies
Add entry in Makefile for conditional compilation.
Configure your kernel using make menuconfig to enable your config tag and build your kernel

Configuration file in U-boot

Is there any config file in U-boot similar to config files(in arch/arm/configs/ for ARM) in Linux.
My doubht here is, while building U-boot it is taking CPUDIR(in the top Makefile) as "arch/arm/cpu/armv7". I am trying to understand from where it is taking the configuration as "arm" and "armv7".
If you see the U-Boot tree on the directory
/configs
you will have the board default configuration files.
I believe the header files in include/configs are what you're looking for. You'll need to determine which file is used for your board.
From http://www.stlinux.com/u-boot/modifying:
Configuration files
The important configuration information for U-Boot is defined in the file:
include/configs/<board>.h
For example, the Espresso board default configuration file is:
include/configs/espresso.h

linux kernel module compilation pre-requisites

I've just started to learn about linux kernel modules and the book I'm referring to says:
"For this [compilation] to work, the kernel source has to be suitably prepared; in particular it has to have a configuration file (.config in the main kernel source directory) and proper dependencies setup"
However, as far as I know (and have tried), the .config file is generated by the make menuconfig (or any of the equivalent make config commands) - and that doesn't seem to be enough for my module files to compile. What's the bare minimum I need to do in the kernel source directory?
make modules?
Yes, the .config file is generated using make *config.
Here are some of them:
make defconfig creates the default configuration for your architecture.
make config is the most primitive method, it prompts on every configuration.
make menuconfig is ncurses config menu. That's the one I prefer if I'm not editing .config file directly.
make gconfig is like menuconfig, but using gtk+.
Don't forget that make oldconfig should be called after modifying the .config file yourself.
Your current config might also be stored somewhere on your disk. For many linux versions, it's location is /boot/config-$(uname -r) If it exists, you can start with it. If not, your best bet is make defconfig, then editing the config file to suit your needs.
After configuration:
Before building modules, you might want to compile the kernel since your modules will not be used by the current kernel and even if you make your current kernel use those modules, it'll most probably cause a panic since symbol tables will not be in the order that your compiled modules assumes. make -jN is the most used method for compiling, N being twice your CPU core count. This also compiles modules, but creates .ko files for them, instead of embedding into the vmlinuz file.
After that, you can sudo make install to install your kernel. This usually wraps the kernel object you've just compiled into a suitable format and puts under /boot (it doesn't have to be /boot, actually).
Then you sudo make modules_install to copy the created .ko files into /lib/modules/$(uname -r). This builds all modules.
After doing that, you might prefer only building your own module, instead of all of them. When on the kernel tree root, you may make M=your_modules_relative_path to only build your module.
I don't know which book you're reading, but if you're building a module externally, you still have to perform the work above. After that, you may use LDD examples as a starting point for your makefiles.
See https://github.com/duxing2007/ldd3-examples-3.x

More than one post build scripts in buildroot

I am pretty new to buildroot and I wish to add more than 1 post-build scripts, as the documentation says:
3.3.1. Customizing the generated target filesystem
In the Buildroot configuration, you can specify the paths to one or more post-build scripts. These scripts are called in the given order, after Buildroot builds all the selected software, but before the rootfs images are assembled. The BR2_ROOTFS_POST_BUILD_SCRIPT allows you to specify the location of your post-build scripts
http://buildroot.uclibc.org/downloads/manual/manual.html#rootfs-custom
How can I specify more than one value in a buildroot setting?
See: buildroot Makefile, especially lines 782-784.
The string is passed to a shell's for loop. So a space separator should be used. Each script gets a TARGET_DIR parameter.
In fact, I am running Armadeus 5.2 which only includes Buildroot 2012.02, which does not allow more than 1 post build script. Buildroot 2013.02 does.
Current docs have made it clearer now:
To enable this feature, specify a space-separated list of post-build scripts in config option BR2_ROOTFS_POST_BUILD_SCRIPT
So space separated as Artless deduced from the source.

Resources