From 9f209a8372db0addaef6250b5f7aacd307ef15ed Mon Sep 17 00:00:00 2001 From: Andrei Kholodnyi Date: Sat, 9 Apr 2022 23:33:01 +0200 Subject: [PATCH 1/2] get linux sources from git add two actions; build latest, and build stable remove dbg kernel package --- .config-fragment | 2 +- .github/workflows/build-latest.yml | 8 ++ .github/workflows/build-stable.yaml | 15 +++ .github/workflows/rpi4-kernel-build.yml | 146 ++++++++++++++---------- Dockerfile | 125 ++++++++++---------- README.md | 31 +++-- getpatch.sh | 19 +-- 7 files changed, 199 insertions(+), 147 deletions(-) create mode 100644 .github/workflows/build-latest.yml create mode 100644 .github/workflows/build-stable.yaml diff --git a/.config-fragment b/.config-fragment index 576a6c9..2aa1acf 100644 --- a/.config-fragment +++ b/.config-fragment @@ -22,4 +22,4 @@ CONFIG_EVENT_TRACING=y CONFIG_PERF_EVENTS=y # CONFIG_KRETPROBES is not set # CONFIG_KALLSYMS_ALL is not set - +CONFIG_DEBUG_INFO=n diff --git a/.github/workflows/build-latest.yml b/.github/workflows/build-latest.yml new file mode 100644 index 0000000..00e857d --- /dev/null +++ b/.github/workflows/build-latest.yml @@ -0,0 +1,8 @@ +name: 'Build latest' + +on: + workflow_dispatch: + +jobs: + call-rpi4-kernel-build: + uses: ./.github/workflows/rpi4-kernel-build.yml diff --git a/.github/workflows/build-stable.yaml b/.github/workflows/build-stable.yaml new file mode 100644 index 0000000..6ad9081 --- /dev/null +++ b/.github/workflows/build-stable.yaml @@ -0,0 +1,15 @@ +name: 'Build stable' + +on: + workflow_dispatch: + inputs: + uname_r: + description: 'raspi release in a form of <5.4.0-1058-raspi>' + required: true + default: '5.4.0-1058-raspi' + type: string +jobs: + call-rpi4-kernel-build: + uses: ./.github/workflows/rpi4-kernel-build.yml + with: + uname_r: ${{ github.event.inputs.uname_r }} diff --git a/.github/workflows/rpi4-kernel-build.yml b/.github/workflows/rpi4-kernel-build.yml index 01dbc60..75826f2 100644 --- a/.github/workflows/rpi4-kernel-build.yml +++ b/.github/workflows/rpi4-kernel-build.yml @@ -1,31 +1,46 @@ -# This is a workflow for the RPI4 RT kernel build. It is based on the Dockerfile located in the repo -# Workflow can be started -# - manually -# - after modification of the kernel config fragment file ('.config-fragment') -# The build takes 1.5 hours and artifacts are available under workflow +# This is a callable workflow for the RPI4 RT kernel build. It is based on the Dockerfile located in the repo +# Workflow can be started from another workflow +# The build takes 1.5 hours and artifacts are available under workflow artifacts # - kernel .deb packages # TODO: # - use Dockerfile instead -# - add input parameters # - create Docker image and push it to the packages -# - create kernel build action name: 'RPI4 RT Kernel build' # Controls when the workflow will run on: - # Trigger the workflow on push or pull request, - # but only for the master branch - push: - branches: - - master - pull_request: - branches: - - master - - # Allows you to run this workflow manually from the Actions tab - # manual start works on the default branch only - workflow_dispatch: + workflow_call: + inputs: + uname_r: + description: 'raspi release in a form of <5.4.0-1058-raspi>' + default: '' + required: false + type: string + rt_patch: + description: 'RT patch in a form of <5.4.177-rt69>' + default: '' + required: false + type: string + kernel_version: + description: 'Raspi kernel version' + default: '5.4.0' + required: false + type: string + ubuntu_version: + description: 'Ubuntu version' + default: 'focal' + required: false + type: string + lttng_version: + description: 'LTTNG version' + default: '2.12' + required: false + type: string +env: + ARCH: arm64 + triple: aarch64-linux-gnu + KERNEL_DIR: linux-raspi # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -65,13 +80,12 @@ jobs: - name: Install deps run: | + sudo apt-get update sudo apt-get install -q -y tzdata apt-utils lsb-release software-properties-common + sudo rm -rf /var/lib/apt/lists/* - - name: Setup arm64 repos + - name: Setup ARCH repos run: | - # these should be input params - ARCH=arm64 - triple=aarch64-linux-gnu sudo apt-get update sudo apt-get install -q -y gcc-${triple} sudo dpkg --add-architecture ${ARCH} @@ -80,85 +94,99 @@ jobs: sudo add-apt-repository -n -s "deb [arch=$ARCH] http://ports.ubuntu.com/ubuntu-ports $(lsb_release -s -c)-updates main universe restricted" sudo rm -rf /var/lib/apt/lists/* + - name: Install extra packages needed for the patch handling + run: | + sudo apt-get update + sudo apt-get install -q -y wget curl gzip + sudo rm -rf /var/lib/apt/lists/* + - name: Setup uname_r run: | - sudo apt-get update - if test -z $UNAME_R; then UNAME_R=`apt-cache search -n linux-buildinfo-.*-raspi | sort | tail -n 1 | cut -d '-' -f 3-5`; fi \ - && echo $UNAME_R > $HOME/uname_r \ - && sudo rm -rf /var/lib/apt/lists/* + UNAME_R=${{ inputs.uname_r }} + if test -z $UNAME_R; then UNAME_R=`curl -s http://ports.ubuntu.com/pool/main/l/linux-raspi/ | grep linux-buildinfo | grep -o -P '(?<=l)' | grep ${ARCH} | grep ${{ inputs.kernel_version }} | sort | tail -n 1 | cut -d '-' -f 3-4`-raspi; fi \ + && echo $UNAME_R > $HOME/uname_r - name: Install build deps run: | sudo apt-get update - sudo apt-get build-dep -q -y linux linux-image-`cat $HOME/uname_r` + sudo apt-get build-dep -q -y linux sudo apt-get install -q -y \ libncurses-dev flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf fakeroot sudo rm -rf /var/lib/apt/lists/* - - name: Install buildinfo + - name: Install linux sources run: | - # install buildinfo to retrieve `raspi` kernel config - sudo apt-get update - sudo apt-get install -q -y linux-buildinfo-`cat $HOME/uname_r` - sudo rm -rf /var/lib/apt/lists/* + mkdir $HOME/linux_build && cd $HOME/linux_build \ + && time git clone -b master --single-branch https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux-raspi/+git/${{ inputs.ubuntu_version }} ${KERNEL_DIR} \ + && cd ${KERNEL_DIR} \ + && git fetch --tag - - name: Install extra packages needed for the patch handling + - name: checkout necessary tag run: | - sudo apt-get update - sudo apt-get install -q -y wget curl gzip - sudo rm -rf /var/lib/apt/lists/* + cd $HOME/linux_build/${KERNEL_DIR} \ + && git tag -l *`cat $HOME/uname_r | cut -d '-' -f 2`* | tail -1 > $HOME/linux_build/tag \ + && git checkout `cat $HOME/linux_build/tag` - - name: Install linux sources + - name: Retrieve buildinfo run: | - sudo apt-get update - mkdir $HOME/linux_build && cd $HOME/linux_build - apt-get source linux-image-`cat $HOME/uname_r` - sudo rm -rf /var/lib/apt/lists/* + # install buildinfo to retrieve `raspi` kernel config + cd $HOME \ + && wget http://ports.ubuntu.com/pool/main/l/linux-raspi/linux-buildinfo-${{ inputs.kernel_version }}-`cat $HOME/uname_r | cut -d '-' -f 2`-raspi_${{ inputs.kernel_version }}-`cat $HOME/linux_build/tag | cut -d '-' -f 4`_${ARCH}.deb \ + && dpkg -X *.deb $HOME - name: Get the nearest RT patch to the kernel SUBLEVEL run: | - cd $HOME/linux_build - cd `ls -d */` - if test -z $RT_PATCH; then $GITHUB_WORKSPACE/getpatch.sh `make kernelversion | cut -d '.' -f 3` > $HOME/rt_patch; else echo $RT_PATCH > $HOME/rt_patch; fi + cd $HOME/linux_build/${KERNEL_DIR} + RT_PATCH=${{ inputs.rt_patch }} + if test -z $RT_PATCH; then $GITHUB_WORKSPACE/getpatch.sh `make kernelversion` > $HOME/rt_patch; else echo $RT_PATCH > $HOME/rt_patch; fi - name: Download and unzip RT patch, the closest to the RPI kernel version run: | cd $HOME/linux_build - wget http://cdn.kernel.org/pub/linux/kernel/projects/rt/5.4/older/patch-`cat $HOME/rt_patch`.patch.gz \ + wget http://cdn.kernel.org/pub/linux/kernel/projects/rt/`echo ${{ inputs.kernel_version }} | cut -d '.' -f 1-2`/older/patch-`cat $HOME/rt_patch`.patch.gz \ && gunzip patch-`cat $HOME/rt_patch`.patch.gz + - name: Download lttng source for use later + run: | + cd $HOME + sudo apt-add-repository -s -y ppa:lttng/stable-${{ inputs.lttng_version }} \ + && sudo apt-get update \ + && apt-get source -y -q lttng-modules-dkms + + - name: run lttng built-in script to configure RT kernel + run: | + cd $HOME \ + && cd `ls -d lttng-*/` \ + && ./scripts/built-in.sh ${HOME}/linux_build/${KERNEL_DIR} + - name: Patch raspi kernel, do not fail if some patches are skipped run: | - cd $HOME/linux_build - cd `ls -d */` \ + cd $HOME/linux_build/${KERNEL_DIR} \ && OUT="$(patch -p1 --forward < ../patch-`cat $HOME/rt_patch`.patch)" || echo "${OUT}" | grep "Skipping patch" -q || (echo "$OUT" && false); - name: Setup build environment run: | - cd $HOME/linux_build - cd `ls -d */` \ + cd $HOME/linux_build/${KERNEL_DIR} \ && export $(dpkg-architecture -a${ARCH}) \ && export CROSS_COMPILE=${triple}- \ + && fakeroot debian/rules clean \ && LANG=C fakeroot debian/rules printenv - name: Config RT kernel and merge config fragment run: | - cd $HOME/linux_build - cd `ls -d */` \ - && cp /usr/lib/linux/`cat $HOME/uname_r`/config .config \ - && ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- ./scripts/kconfig/merge_config.sh .config $GITHUB_WORKSPACE/.config-fragment + cd $HOME/linux_build/${KERNEL_DIR} \ + && cp $HOME/usr/lib/linux/`cat $HOME/uname_r`/config .config \ + && ARCH=${ARCH} CROSS_COMPILE=${triple}- ./scripts/kconfig/merge_config.sh .config $GITHUB_WORKSPACE/.config-fragment - name: Clean debian/rules run: | - cd $HOME/linux_build - cd `ls -d */` \ + cd $HOME/linux_build/${KERNEL_DIR} \ && fakeroot debian/rules clean - name: Build kernel run: | - cd $HOME/linux_build - cd `ls -d */` \ - && make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- LOCALVERSION=-raspi -j `nproc` deb-pkg + cd $HOME/linux_build/${KERNEL_DIR} \ + && make ARCH=${ARCH} CROSS_COMPILE=${triple}- LOCALVERSION=-raspi -j `nproc` bindeb-pkg - uses: actions/upload-artifact@v2 with: diff --git a/Dockerfile b/Dockerfile index b585951..414f889 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,24 @@ # docker image to build an RT kernel for the RPI4 based on Ubuntu 20.04 RPI4 image # -# it finds and takes the latest raspi image and the closest to it RT patch -# if the build arguments defined it will build a corresponding version instead +# By default it finds and takes the latest raspi image and the RT_PREEMPT patch closest to it +# if the build arguments defined it will build the corresponding version instead # $ docker build [--build-arg UNAME_R=] [--build-arg RT_PATCH=] -t rtwg-image . # -# where is in a form of 5.4.0-1034-raspi, -# see https://packages.ubuntu.com/search?suite=default§ion=all&arch=any&keywords=linux-image-5.4&searchon=names -# and is in a form of 5.4.106-rt54, +# where is in a form of 5.4.0-1058-raspi, +# see http://ports.ubuntu.com/pool/main/l/linux-raspi/ +# and is in a form of 5.4.177-rt69, # see http://cdn.kernel.org/pub/linux/kernel/projects/rt/5.4/older # # $ docker run -it rtwg-image bash # # and then inside the docker -# $ $HOME/linux_build && cd `ls -d */` -# $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j `nproc` deb-pkg +# $ cd $HOME/linux_build/linux-raspi +# $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- LOCALVERSION=-raspi -j `nproc` bindeb-pkg # -# user ~/linux_build/linux-raspi-5.4.0 $ ls -la ../*.deb -# -rw-r--r-- 1 user user 11430676 May 17 14:40 ../linux-headers-5.4.101-rt53_5.4.101-rt53-1_arm64.deb -# -rw-r--r-- 1 user user 487338132 May 17 14:40 ../linux-image-5.4.101-rt53-dbg_5.4.101-rt53-1_arm64.deb -# -rw-r--r-- 1 user user 39355940 May 17 14:40 ../linux-image-5.4.101-rt53_5.4.101-rt53-1_arm64.deb -# -rw-r--r-- 1 user user 1055272 May 17 14:40 ../linux-libc-dev_5.4.101-rt53-1_arm64.deb +# user ~/linux_build/linux-raspi $ ls -la ../*.deb +# -rw-r--r-- 1 user user 11442412 Apr 8 13:20 ../linux-headers-5.4.174-rt69-raspi_5.4.174-rt69-raspi-1_arm64.deb +# -rw-r--r-- 1 user user 40261364 Apr 8 13:21 ../linux-image-5.4.174-rt69-raspi_5.4.174-rt69-raspi-1_arm64.deb +# -rw-r--r-- 1 user user 1055452 Apr 8 13:20 ../linux-libc-dev_5.4.174-rt69-raspi-1_arm64.deb # # copy deb packages to the host, or directly to the RPI4 target # $ scp ../*.deb @172.17.0.1:/home//. @@ -39,7 +38,10 @@ ARG ARCH=arm64 ARG UNAME_R ARG RT_PATCH ARG triple=aarch64-linux-gnu -ARG LTTNG=2.12 +ARG KERNEL_VERSION=5.4.0 +ARG UBUNTU_VERSION=focal +ARG LTTNG_VERSION=2.12 +ARG KERNEL_DIR=linux-raspi # setup arch RUN apt-get update && apt-get install -q -y \ @@ -54,27 +56,13 @@ RUN apt-get update && apt-get install -q -y \ ENV LANG C.UTF-8 ENV LC_ALL C.UTF-8 -# find the latest UNAME_R and store it locally for the later usage -# Example: -# apt-cache search -n linux-buildinfo-.*-raspi | sort | tail -n 1 | cut -d '-' -f 3-5 -# 5.4.0-1034-raspi -# if $UNAME_R is set via --build-arg, take it -RUN apt-get update \ - && if test -z $UNAME_R; then UNAME_R=`apt-cache search -n linux-buildinfo-.*-raspi | sort | tail -n 1 | cut -d '-' -f 3-5`; fi \ - && echo $UNAME_R > /uname_r \ - && rm -rf /var/lib/apt/lists/* - # install build deps -RUN apt-get update && apt-get build-dep -q -y linux linux-image-`cat /uname_r` \ +RUN apt-get update && apt-get build-dep -q -y linux \ && apt-get install -q -y \ libncurses-dev flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf \ fakeroot \ && rm -rf /var/lib/apt/lists/* -# install buildinfo to retieve `raspi` kernel config -RUN apt-get update && apt-get install -q -y linux-buildinfo-`cat /uname_r` \ - && rm -rf /var/lib/apt/lists/* - # setup user RUN apt-get update && apt-get install -q -y sudo \ && useradd -m -d /home/user -s /bin/bash user \ @@ -84,68 +72,81 @@ RUN apt-get update && apt-get install -q -y sudo \ && rm -rf /var/lib/apt/lists/* # install extra packages needed for the patch handling -RUN apt-get update && apt-get install -q -y wget curl gzip \ +RUN apt-get update && apt-get install -q -y wget curl gzip git time \ && rm -rf /var/lib/apt/lists/* USER user -WORKDIR /home/user/linux_build -# install linux sources -RUN sudo apt-get update \ - && sudo chown user:user /home/user/linux_build \ - && apt-get source linux-image-`cat /uname_r` \ - && sudo rm -rf /var/lib/apt/lists/* +# find the latest UNAME_R and store it locally for the later usage +# if $UNAME_R is set via --build-arg, take it +RUN if test -z $UNAME_R; then UNAME_R=`curl -s http://ports.ubuntu.com/pool/main/l/linux-raspi/ | grep linux-buildinfo | grep -o -P '(?<=l)' | grep ${ARCH} | grep ${KERNEL_VERSION} | sort | tail -n 1 | cut -d '-' -f 3-4`-raspi; fi \ + && echo $UNAME_R > /home/user/uname_r + +# install linux sources from git +RUN mkdir /home/user/linux_build \ + && cd /home/user/linux_build \ + && time git clone -b master --single-branch https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux-raspi/+git/${UBUNTU_VERSION} ${KERNEL_DIR} \ + && cd ${KERNEL_DIR} \ + && git fetch --tag + +# checkout necessary tag +RUN cd /home/user/linux_build/${KERNEL_DIR} \ + && git tag -l *`cat /home/user/uname_r | cut -d '-' -f 2`* | tail -1 > /home/user/linux_build/tag \ + && git checkout `cat /home/user/linux_build/tag` + +# install buildinfo to retieve `raspi` kernel config +RUN cd /home/user \ + && wget http://ports.ubuntu.com/pool/main/l/linux-raspi/linux-buildinfo-${KERNEL_VERSION}-`cat /home/user/uname_r | cut -d '-' -f 2`-raspi_${KERNEL_VERSION}-`cat /home/user/linux_build/tag | cut -d '-' -f 4`_${ARCH}.deb \ + && dpkg -X *.deb /home/user/ # install lttng dependencies RUN sudo apt-get update \ - && sudo apt-get install -y libuuid1 libpopt0 liburcu6 libxml2 numactl + && sudo apt-get install -y libuuid1 libpopt0 liburcu6 libxml2 numactl -COPY ./getpatch.sh /getpatch.sh +COPY ./getpatch.sh /home/user/. # get the nearest RT patch to the kernel SUBLEVEL -# Example: -# ./getpatch.sh 101 -# 5.4.102-rt53 # if $RT_PATCH is set via --build-arg, take it -# get kernel SUBLEVEL via -# $ make kernelversion -RUN cd `ls -d */` \ - && if test -z $RT_PATCH; then /getpatch.sh `make kernelversion | cut -d '.' -f 3` > $HOME/rt_patch; else echo $RT_PATCH > $HOME/rt_patch; fi +RUN cd /home/user/linux_build/${KERNEL_DIR} \ + && if test -z $RT_PATCH; then /home/user/getpatch.sh `make kernelversion` > /home/user/rt_patch; else echo $RT_PATCH > /home/user/rt_patch; fi -# download and unzip RT patch, the closest to the RPI kernel version -RUN wget http://cdn.kernel.org/pub/linux/kernel/projects/rt/5.4/older/patch-`cat $HOME/rt_patch`.patch.gz \ - && gunzip patch-`cat $HOME/rt_patch`.patch.gz +# download and unzip RT patch +RUN cd /home/user/linux_build \ + && wget http://cdn.kernel.org/pub/linux/kernel/projects/rt/`echo ${KERNEL_VERSION} | cut -d '.' -f 1-2`/older/patch-`cat /home/user/rt_patch`.patch.gz \ + && gunzip patch-`cat /home/user/rt_patch`.patch.gz # download lttng source for use later # TODO(flynneva): make script to auto-determine which version to get? -RUN cd $HOME \ - && sudo apt-add-repository ppa:lttng/stable-${LTTNG} \ - && sudo apt-get update \ - && apt-get source lttng-modules-dkms +RUN cd /home/user/ \ + && sudo apt-add-repository ppa:lttng/stable-${LTTNG_VERSION} \ + && sudo apt-get update \ + && apt-get source lttng-modules-dkms + +WORKDIR /home/user # run lttng built-in script to configure RT kernel RUN set -x \ - && export KERNEL_DIR=`ls -d */` \ - && cd $HOME \ - && cd `ls -d lttng-*/` \ - && ./scripts/built-in.sh ${HOME}/linux_build/${KERNEL_DIR} + cd /home/user \ + && cd `ls -d lttng-modules-*` \ + && ./scripts/built-in.sh ${HOME}/linux_build/${KERNEL_DIR} -# patch `raspi` kernel, do not fail if some patches are skipped -RUN cd `ls -d */` \ +# patch kernel, do not fail if some patches are skipped +RUN cd /home/user/linux_build/${KERNEL_DIR} \ && OUT="$(patch -p1 --forward < ../patch-`cat $HOME/rt_patch`.patch)" || echo "${OUT}" | grep "Skipping patch" -q || (echo "$OUT" && false); # setup build environment -RUN cd `ls -d */` \ +RUN cd /home/user/linux_build/${KERNEL_DIR} \ && export $(dpkg-architecture -a${ARCH}) \ && export CROSS_COMPILE=${triple}- \ + && fakeroot debian/rules clean \ && LANG=C fakeroot debian/rules printenv -COPY ./.config-fragment . +COPY ./.config-fragment /home/user/linux_build/. # config RT kernel and merge config fragment -RUN cd `ls -d */` \ - && cp /usr/lib/linux/`cat /uname_r`/config .config \ +RUN cd /home/user/linux_build/${KERNEL_DIR} \ + && cp /home/user/usr/lib/linux/`cat /home/user/uname_r`/config .config \ && ARCH=${ARCH} CROSS_COMPILE=${triple}- ./scripts/kconfig/merge_config.sh .config $HOME/linux_build/.config-fragment -RUN cd `ls -d */` \ +RUN cd /home/user/linux_build/${KERNEL_DIR} \ && fakeroot debian/rules clean diff --git a/README.md b/README.md index b1f975f..2afd89e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ## Introduction -This README describes necessary steps to build and install ```RT_PREEMPT``` Linux kernel for the Raspberry Pi4 board. RT Kernel is a part of the ROS2 real-time system setup. Raspberry Pi4 is a reference board used by the ROS 2 real-time community for the development. RT Kernel is configured as described in [Kernel configuration section](#kernel-configuration). Kernel is built automatically by the Github action, and the artifacts are located under the [```RPI4 RT Kernel build```](https://github.com/ros-realtime/linux-real-time-kernel-builder/actions/workflows/rpi4-kernel-build.yml). Please follow [installation instructions](#deploy-new-kernel-on-raspberry-pi4) to deploy a new kernel to the RPI4 board. +This README describes necessary steps to build and install ```RT_PREEMPT``` Linux kernel for the Raspberry Pi4 board. RT Kernel is a part of the ROS2 real-time system setup. Raspberry Pi4 is a reference board used by the ROS 2 real-time community for the development. RT Kernel is configured as described in [Kernel configuration section](#kernel-configuration). Kernel is built automatically by the Github action, and the artifacts are located under the [```build stable```](https://github.com/razr/linux-real-time-kernel-builder/actions/workflows/build-stable.yaml). Please follow [installation instructions](#deploy-new-kernel-on-raspberry-pi4) to deploy a new kernel to the RPI4 board. ## Raspberry Pi 4 RT Linux kernel @@ -16,7 +16,7 @@ RT Kernel is configured using configuration parameters from the [](.config-fragm ### Using GUI -Go to the ```Action``` tab, find the latest ```RPI4 RT Kernel build```, go inside the latest workflow run, download, and unzip artifacts called ```RPI4 RT Kernel deb packages```. This archive contains four debian packages. Follow [instructions](#deploy-new-kernel-on-raspberry-pi4) to deploy them on the RPI4. +Go to the ```Action``` tab, find the ```Build stable```, go inside the latest workflow run, download, and unzip artifacts called ```RPI4 RT Kernel deb packages```. This archive contains three debian packages. Follow [instructions](#deploy-new-kernel-on-raspberry-pi4) to deploy them on the RPI4. ### Using command line @@ -61,13 +61,13 @@ cd linux-real-time-kernel-builder ``` ```bash -docker build [--build-arg UNAME_R=] [--build-arg RT_PATCH=] -t rtwg-image . +docker build [--no-cache] [--build-arg UNAME_R=] [--build-arg RT_PATCH=] -t rtwg-image . ``` where: -* `````` is in a form of ```5.4.0-1034-raspi```, see [Ubuntu raspi Linux kernels](https://packages.ubuntu.com/search?suite=default§ion=all&arch=any&keywords=linux-image-5.4&searchon=names) -* `````` is in a form of ```5.4.106-rt54```, see [RT patches](http://cdn.kernel.org/pub/linux/kernel/projects/rt/5.4/older) +* `````` is in a form of ```5.4.0-1058-raspi```, see [Ubuntu raspi Linux kernels](http://ports.ubuntu.com/pool/main/l/linux-raspi) +* `````` is in a form of ```5.4.177-rt69```, see [RT patches](http://cdn.kernel.org/pub/linux/kernel/projects/rt/5.4/older) ```bash docker run -t -i rtwg-image bash @@ -94,25 +94,24 @@ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig Alternatively, you can modify ```.config-fragment``` and then merge your changes in the ```.config``` by running ```bash -cd $HOME/linux_build/linux-raspi-* +cd $HOME/linux_build/linux-raspi ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- ./scripts/kconfig/merge_config.sh .config $HOME/linux_build/.config-fragment ``` ### Kernel build ```bash -cd $HOME/linux_build/linux-raspi-* -make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j `nproc` deb-pkg +cd $HOME/linux_build/linux-raspi +make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- LOCALVERSION=-raspi -j `nproc` bindeb-pkg ``` You need 16GB free disk space to build it, it takes a while, and the results are located: ```bash -raspi ~/linux_build/linux-raspi-5.4.0 $ ls -la ../*.deb --rw-r--r-- 1 user user 11430676 May 17 14:40 ../linux-headers-5.4.101-rt53_5.4.101-rt53-1_arm64.deb --rw-r--r-- 1 user user 487338132 May 17 14:40 ../linux-image-5.4.101-rt53-dbg_5.4.101-rt53-1_arm64.deb --rw-r--r-- 1 user user 39355940 May 17 14:40 ../linux-image-5.4.101-rt53_5.4.101-rt53-1_arm64.deb --rw-r--r-- 1 user user 1055272 May 17 14:40 ../linux-libc-dev_5.4.101-rt53-1_arm64.deb +raspi:~/linux_build/linux-raspi $ ls -la ../*.deb +-rw-r--r-- 1 user user 11442412 Apr 8 13:20 ../linux-headers-5.4.174-rt69-raspi_5.4.174-rt69-raspi-1_arm64.deb +-rw-r--r-- 1 user user 40261364 Apr 8 13:21 ../linux-image-5.4.174-rt69-raspi_5.4.174-rt69-raspi-1_arm64.deb +-rw-r--r-- 1 user user 1055452 Apr 8 13:20 ../linux-libc-dev_5.4.174-rt69-raspi-1_arm64.deb ``` ## Deploy new kernel on Raspberry Pi4 @@ -152,7 +151,7 @@ Assumed you have already copied all ```*.deb``` kernel packages to your ```$HOME ```bash cd $HOME -sudo dpkg -i *.deb +sudo dpkg -i linux-image-*.deb sudo reboot ``` @@ -161,7 +160,7 @@ After reboot you should see a new RT kernel installed ```bash ubuntu@ubuntu:~$ uname -a -Linux ubuntu 5.4.101-rt53 #1 SMP PREEMPT_RT Mon May 17 12:10:16 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux +Linux ubuntu 5.4.174-rt69-raspi #1 SMP PREEMPT_RT Mon Apr 8 14:10:16 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux ``` ## Intel UP2 board RT kernel build @@ -177,7 +176,7 @@ As this repository is within the `ros-realtime` organization it can be assumed t ## References * [ROS Real-Time Working group documentation](https://ros-realtime.github.io/Guides/Real-Time-Operating-System-Setup/Real-Time-Linux/rt_linux_index.html) -* [Ubuntu raspi linux images](https://packages.ubuntu.com/search?suite=default§ion=all&arch=any&keywords=linux-image-5.4&searchon=names) +* [Ubuntu raspi linux images](http://ports.ubuntu.com/pool/main/l/linux-raspi) * [RT patches](http://cdn.kernel.org/pub/linux/kernel/projects/rt/5.4/older) * [Download Ubuntu raspi image](https://ubuntu.com/download/raspberry-pi/thank-you?version=20.04&architecture=arm64+raspi) * [Building Realtime ```RT_PREEMPT``` kernel for ROS 2](https://index.ros.org/doc/ros2/Tutorials/Building-Realtime-rt_preempt-kernel-for-ROS-2/) diff --git a/getpatch.sh b/getpatch.sh index acf8e30..2a210c1 100755 --- a/getpatch.sh +++ b/getpatch.sh @@ -1,15 +1,17 @@ #!/bin/bash -# first argument is a kernel sublevel number -# Example: Kernel version 5.4.101, SUBLEVEL number is 101 -sublevel=101 +# first argument is a kernel version, script takes sublevel and calculates the nearest patch to the provided SUBLEVEL +# Kernel version 5.4.174, SUBLEVEL number is 174 +major_minor=5.4 +sublevel=174 if [ $# -ne 0 ]; then - sublevel=$1 + major_minor=`echo $1 | cut -d '.' -f 1-2` + sublevel=`echo $1 | cut -d '.' -f 3` fi # Retrieve a list of ```patch.gz``` patches, and sort them -# assumed patched are in form of patch-5.4.5-rt3.patch.gz -patch_list=`curl -s http://cdn.kernel.org/pub/linux/kernel/projects/rt/5.4/older/ | grep patch.gz | cut -d '"' -f 2 | sort -V` +# assumed patched are in form of patch-5.4.177-rt69.patch.gz +patch_list=`curl -s http://cdn.kernel.org/pub/linux/kernel/projects/rt/$major_minor/older/ | grep patch.gz | cut -d '"' -f 2 | sort -V` # go through the list and take the nearest patch to the provided SUBLEVEL number which is equal or greater sl=$sublevel @@ -21,6 +23,5 @@ do fi done -# check whether there are several RT patches with the same SUBLEVEL number exist, and take the latest -echo "$patch_list" | tr ' ' '\n' | grep patch-5.4.$sl | tail -n 1 | cut -d '-' -f 2-3 | cut -d '.' -f 1-3 - +# check whether there are several RT patches exist with the same SUBLEVEL number, and take the latest +echo "$patch_list" | tr ' ' '\n' | grep patch-$major_minor.$sl | tail -n 1 | cut -d '-' -f 2-3 | cut -d '.' -f 1-3 From 6ea1202063de9fe20343dc858cc2bf53e2c20fdc Mon Sep 17 00:00:00 2001 From: Andrei Kholodnyi Date: Tue, 24 May 2022 14:18:45 +0200 Subject: [PATCH 2/2] remove WORKDIR --- Dockerfile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 414f889..3ed156b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -103,7 +103,7 @@ RUN cd /home/user \ RUN sudo apt-get update \ && sudo apt-get install -y libuuid1 libpopt0 liburcu6 libxml2 numactl -COPY ./getpatch.sh /home/user/. +COPY ./getpatch.sh /home/user/ # get the nearest RT patch to the kernel SUBLEVEL # if $RT_PATCH is set via --build-arg, take it @@ -122,12 +122,9 @@ RUN cd /home/user/ \ && sudo apt-get update \ && apt-get source lttng-modules-dkms -WORKDIR /home/user - # run lttng built-in script to configure RT kernel RUN set -x \ - cd /home/user \ - && cd `ls -d lttng-modules-*` \ + && cd `ls -d /home/user/lttng-modules-*` \ && ./scripts/built-in.sh ${HOME}/linux_build/${KERNEL_DIR} # patch kernel, do not fail if some patches are skipped