How to build uImage? - linux-kernel

I have zImage and kernel source. I did
make zImage
to generate the zImage.
When I flash this, the board won't boot up.
So how do I convert this to uImage which u-boot reads properly?
Thanks!

Install u-boot-tools. The command depends on your distribution. If you are using Debian/Ubuntu, it should look like
sudo apt-get install u-boot-tools
See U-Boot documentation on tool installation
make uImage
mkimage -A <arch> -O linux -T kernel -C none -a <load-address> -e <entry-point> -n "Linux kernel" -d arch/arm/boot/zImage uImage
or in the kernel source
make uImage

Related

Add DTB to u-boot uImage during Yocto build

I have a manual process for compiling a Linux kernel for an embedded ARM device. I use the CONFIG_APPENDED_DTB=y option, append my DTB file to the zImage file, then convert to uImage:
cat arch/arm/boot/zImage ./arch/arm/boot/dts/lpc3250-phy3250.dtb > arch/arm/boot/zImage-dtb
mkimage -A arm -O linux -C none -T kernel -a 0x80008000 -e 0x80008000 -n 'Linux' \
-d arch/arm/boot/zImage-dtb arch/arm/boot/uImage
I'm attempting to migrate to Yocto. How can I implement the same process? I can set KERNEL_IMAGETYPE = "zImage" but I'm not sure how to postprocess the zImage file.
Note that my version of u-boot is fixed and quite old, so I am not currently considering migrating to other formats such as FIT.
I am a newcomer to Yocto, so expository answers are especially welcome.

How to build raspbian with custom kernel 5.10 (PREEMPT RT)

I am trying to enable PREEMPT RT (Fully preemptive model) in Linux kernel 5.10. However, I get a black screen when booting from the custom kernel image and I have no clue why that happens. Any help is greatly appreciated. Here are all my steps:
All below files are available at https://github.com/remusmp/rpi-rt-kernel. Just clone and run make.
I build with docker. Here is my Dockerfile:
FROM ubuntu:20.04
ENV TZ=Europe/Copenhagen
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update
RUN apt-get install -y git make gcc bison flex libssl-dev bc ncurses-dev kmod
RUN apt-get install -y crossbuild-essential-arm64
RUN apt-get install -y wget zip unzip fdisk nano
WORKDIR /rpi-kernel
RUN git clone https://github.com/raspberrypi/linux.git -b rpi-5.10.y --depth=1
RUN wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/5.10/patch-5.10.59-rt52.patch.gz
WORKDIR /rpi-kernel/linux/
ENV KERNEL=kernel8
ENV ARCH=arm64
ENV CROSS_COMPILE=aarch64-linux-gnu-
RUN gzip -cd ../patch-5.10.59-rt52.patch.gz | patch -p1 --verbose
RUN make bcm2711_defconfig
ADD .config ./
RUN make Image modules dtbs
WORKDIR /raspios
RUN apt -y install
RUN wget https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2021-05-28/2021-05-07-raspios-buster-armhf-lite.zip
RUN unzip 2021-05-07-raspios-buster-armhf-lite.zip && rm 2021-05-07-raspios-buster-armhf-lite.zip
RUN mkdir /raspios/mnt && mkdir /raspios/mnt/disk && mkdir /raspios/mnt/boot
ADD build.sh ./
ADD config.txt ./
Script build.sh:
#!/bin/sh
mount -t ext4 -o loop,offset=$((532480*512)) 2021-05-07-raspios-buster-armhf-lite.img /raspios/mnt/disk
mount -t vfat -o loop,offset=$((8192*512)),sizelimit=$((524288*512)) 2021-05-07-raspios-buster-armhf-lite.img /raspios/mnt/boot
cd /rpi-kernel/linux/
make INSTALL_MOD_PATH=/raspios/mnt/disk modules_install
make INSTALL_DTBS_PATH=/raspios/mnt/boot dtbs_install
cd -
cp /rpi-kernel/linux/arch/arm64/boot/Image /raspios/mnt/boot/$KERNEL\_rt.img
cp /rpi-kernel/linux/arch/arm64/boot/dts/broadcom/*.dtb /raspios/mnt/boot/
cp /rpi-kernel/linux/arch/arm64/boot/dts/overlays/*.dtb* /raspios/mnt/boot/overlays/
cp /rpi-kernel/linux/arch/arm64/boot/dts/overlays/README /raspios/mnt/boot/overlays/
cp /raspios/config.txt /raspios/mnt/boot/
touch /raspios/mnt/boot/ssh
umount /raspios/mnt/disk
umount /raspios/mnt/boot
zip 2021-05-07-raspios-buster-armhf-lite.zip 2021-05-07-raspios-buster-armhf-lite.img
I got a custom .config file, which I copied from the container after running make menuconfig and enabling Fully PREEMPT RT. I had to disable KVM first in order for Full PREEMPT RT option to show up but that is ok for my use case. This is the only customization I do to the kernel, nothing else.
The outcome is a zipped sd card image that I then decompress and dd to an sdcard with command:
sudo dd if=2021-05-07-raspios-buster-armhf-lite.img of=/dev/mmcblk0 bs=1M status=progress
Am I missing something in the above process or where should I look to get a working custom Linux kernel image? I followed the guide on https://www.raspberrypi.org/documentation/computers/linux_kernel.html and it works fine if I set the vanilla kernel8.img in config.txt but my custom kernel with preempt rt enabled doesn't work.
Many thanks!
It almost worked. I was missing:
arm_64bit=1
in config.txt.

How can I use systemtap(stap) in the centos container in docker for mac

When I use stap, it tell me this error as the image,how can i fix it.
Really don't know why this question has been downvotted once. When i get concern, downvotter are one of the reason i always hesitate to ask thing on stackoverflow...
So, got the same concern with a container under ubuntu and it is how i fix it : try to launch an ubuntu bash on docker (not centos but the step should be similar)
docker run -it --cap-add sys_admin ubuntu bash
Then install some library and systemtap
apt-get update
apt-get --yes install build-essential cmake bc curl diffutils git kmod libcurl4-openssl-dev wget
apt-get --yes install systemtap systemtap-sdt-dev
Now install the kernel headers (will take time)
export KERNELVER=$(uname -r | cut -d '-' -f 1)
export KERNELDIR=/linux-$KERNELVER
cd /
curl -o linux-${KERNELVER}.tar.gz https://www.kernel.org/pub/linux/kernel/v4.x/linux-${KERNELVER}.tar.gz
tar zxf linux-${KERNELVER}.tar.gz
cd linux-${KERNELVER}
zcat /proc/1/root/proc/config.gz > .config
make all
make modules_prepare
make headers_install
make modules_install
Now run stap -l 'syscall.*'. It should work and display :
...
syscall.waitpid
syscall.write
syscall.writev
This is taken from : https://github.com/fdebonneval/mobydig/blob/master/resources/build

linker option while building vmlinux

I am understanding how vmlinux will create with the help of link-vmlinux.sh script, I could see it is passing -p option to the linker while building vmlinux, but I couldn't see any option named -p when executed linker with --help.
#arm-linux-gnueabihf-ld -EL -p --no-undefined -X --build-id -o vmlinux
Can you please tel me what is the use of '-p' option in the above command.
I reckon it prints the program headers object file format uses also known as
segments.The program headers describe how the program should be loaded into memory. You can print them out by using the objdump program with the -p option.
Did you try arm-linux-gnueabihf-ld --help ?

Installing readline 6.0 on OS X

I'm trying to install readline 6 from source but run into an error during 'make install'.
Here is the end of the output after executing 'sudo make install'
( cd shlib ; make DESTDIR= install )
/bin/sh ../support/mkdirs /usr/local/lib
/bin/sh ../support/shlib-install -O darwin9.7.0 -d /usr/local/lib -b /usr/local/bin -i "/usr/bin/install -c -m 644" libhistory.6.0.dylib
/bin/sh ../support/shlib-install -O darwin9.7.0 -d /usr/local/lib -b /usr/local/bin -i "/usr/bin/install -c -m 644" libreadline.6.0.dylib
install: you may need to run ldconfig
I know that ldconfig isn't installed by default on OS X, and I read somewhere that it shouldn't be needed to fix this issue. I believe it has something to do with dynamic libraries, but I haven't been able to find out how to fix the issue, anyone have any insight?
FYI, I'm running OS X on an intel 2.4ghz macbook
thanks
P.S. I also applied the 3 available readline 6 patches before running configure and make
Actually, this isn't an error at all... it's just a notice message at the end of the install. It get this too, and my readline 6 is happily installed.
If you check /usr/local/lib and see readline there, you're done :-) No need to run any equivalent of ldconfig.
$ ls /usr/local/lib | grep readline
libreadline.6.0.dylib
libreadline.6.dylib
libreadline.a
libreadline.dylib

Resources