-
Notifications
You must be signed in to change notification settings - Fork 7
Add scripts to generate fresh vmlinux.h #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| name: vmlinux.h | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| gen-headers: | ||
| name: Generate vmlinux.h | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
|
|
||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Download Linux source | ||
| shell: bash | ||
| run: ./scripts/download-latest-linux-release.sh | ||
|
|
||
| - name: Install dependencies | ||
| shell: bash | ||
| run: | | ||
| ./scripts/install-dependencies.sh | ||
| ./scripts/install-pahole.sh | ||
| ./scripts/install-bpftool.sh | ||
|
|
||
| - name: x86_64/vmlinux.h | ||
| shell: bash | ||
| run: ./scripts/gen-vmlinux-header.sh x86_64 | ||
|
|
||
| - name: aarch64/vmlinux.h | ||
| shell: bash | ||
| run: ./scripts/gen-vmlinux-header.sh aarch64 | ||
|
|
||
| - name: arm/vmlinux.h | ||
| shell: bash | ||
| run: ./scripts/gen-vmlinux-header.sh arm | ||
|
|
||
| - name: loongarch64/vmlinux.h | ||
| shell: bash | ||
| run: ./scripts/gen-vmlinux-header.sh loongarch64 | ||
|
|
||
| - name: ppc64le/vmlinux.h | ||
| shell: bash | ||
| run: ./scripts/gen-vmlinux-header.sh ppc64le | ||
|
|
||
| - name: riscv64/vmlinux.h | ||
| shell: bash | ||
| run: ./scripts/gen-vmlinux-header.sh riscv64 | ||
|
|
||
| - name: s390x/vmlinux.h | ||
| shell: bash | ||
| run: ./scripts/gen-vmlinux-header.sh s390x | ||
|
|
||
| - name: Upload headers | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: vmlinux.h | ||
| if-no-files-found: error | ||
| path: ./vmlinux.h |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_64BIT=y |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| CONFIG_BPF=y | ||
| CONFIG_BPF_EVENTS=y | ||
| CONFIG_BPF_JIT=y | ||
| CONFIG_BPF_SYSCALL=y | ||
| CONFIG_DEBUG_INFO=y | ||
| CONFIG_DEBUG_INFO_BTF=y | ||
| CONFIG_DEBUG_INFO_DWARF4=y | ||
| CONFIG_FPROBE=y | ||
| CONFIG_FTRACE=y | ||
| CONFIG_FUNCTION_TRACER=y | ||
| CONFIG_KPROBES=y | ||
| CONFIG_KPROBE_EVENTS=y | ||
| CONFIG_MMU=y | ||
| CONFIG_MODULES=y | ||
| CONFIG_PERF_EVENTS=y | ||
| CONFIG_TRACEPOINTS=y | ||
| CONFIG_TRACING=y | ||
| CONFIG_UPROBE_EVENTS=y |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_64BIT=y |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_64BIT=y |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_64BIT=y |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_64BIT=y |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_64BIT=y |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -eux | ||
|
|
||
| sudo apt install -y curl jq tar xz-utils | ||
|
|
||
| url=$(curl -s https://www.kernel.org/releases.json \ | ||
| | jq -r '.releases[] | select(.moniker == "mainline") | .source') | ||
|
|
||
| curl -LO "$url" | ||
| tar -xf $(basename "$url") | ||
|
|
||
| dir=$(basename "$url" | sed 's/\.tar\.[gx]z$//') | ||
| mv $dir linux | ||
|
|
||
| rm $(basename "$url") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| #!/bin/bash | ||
|
|
||
| usage () { | ||
| echo "USAGE: ./gen-vmlinux-headers.sh <arch> [<linux-repo-path> <kconfig-path>]" | ||
| exit 1 | ||
| } | ||
|
|
||
| set -eu | ||
|
|
||
| source $(dirname "$0")/helpers.sh | ||
|
|
||
| WORKSPACE=$(pwd) | ||
| BUILD_DIR="${BUILD_DIR:-$WORKSPACE/build}" | ||
| GCC_VERSION=${GCC_VERSION:-"13"} | ||
| OUTPUT_DIR="${OUTPUT_DIR:-$WORKSPACE/vmlinux.h}" | ||
|
|
||
| TARGET_ARCH=$1 | ||
| LINUX_REPO=${2:-$WORKSPACE/linux} | ||
| KCONFIG=${3:-} | ||
|
|
||
| if [ -z "${TARGET_ARCH}" ]; then | ||
| echo "Error: Target architecture is not set" | ||
| usage | ||
| fi | ||
|
|
||
| if [ ! -d "${LINUX_REPO}" ]; then | ||
| echo "Error: Linux repo path is not found, LINUX_REPO=$LINUX_REPO" | ||
| usage | ||
| fi | ||
|
|
||
| if [ ! -f "${KCONFIG}" ]; then | ||
| KCONFIG=$(mktemp /tmp/kconfig.XXXX) | ||
| cp $WORKSPACE/kconfigs/config.common $KCONFIG | ||
| arch_conf="$WORKSPACE/kconfigs/config.${TARGET_ARCH}" | ||
| if [ -f "$arch_conf" ]; then | ||
| cat "$arch_conf" >> $KCONFIG | ||
| fi | ||
| echo "==== Using KCONFIG=$KCONFIG for kernel build" | ||
| cat $KCONFIG | ||
| echo "==== end of KCONFIG=$KCONFIG" | ||
| fi | ||
|
|
||
| mkdir -p "$BUILD_DIR" | ||
| LINUX_REPO=$(realpath "$LINUX_REPO") | ||
| KCONFIG=$(realpath "$KCONFIG") | ||
|
|
||
| # Install the cross-compiler | ||
| if [ "${TARGET_ARCH}" != "x86_64" ]; then | ||
| compiler_id=$(arch_compiler_id "$TARGET_ARCH") | ||
| sudo apt install -y \ | ||
| "gcc-${GCC_VERSION}-${compiler_id}" \ | ||
| "binutils-${compiler_id}" | ||
| sudo update-alternatives --install \ | ||
| /usr/bin/${compiler_id}-gcc \ | ||
| ${compiler_id}-gcc \ | ||
| /usr/bin/${compiler_id}-gcc-${GCC_VERSION} 100 | ||
| sudo update-alternatives --set \ | ||
| ${compiler_id}-gcc \ | ||
| /usr/bin/${compiler_id}-gcc-${GCC_VERSION} | ||
| fi | ||
|
|
||
| build_arch(){ | ||
| local arch="$1" | ||
| local kbuild_output="$(realpath $BUILD_DIR/$arch)" | ||
| mkdir -p "$kbuild_output" | ||
| local arch_slug=$(arch_slug "$arch") | ||
| local compiler_id=$(arch_compiler_id "$arch") | ||
|
|
||
| echo "Building $arch ($arch_slug) into $kbuild_output..." | ||
| ( | ||
| cd "$LINUX_REPO" | ||
| make O="$kbuild_output" \ | ||
| ARCH=$arch_slug CROSS_COMPILE="${compiler_id}-" \ | ||
| tinyconfig | ||
| "$LINUX_REPO/scripts/kconfig/merge_config.sh" -m \ | ||
| -O "$kbuild_output" \ | ||
| "$kbuild_output/.config" "${KCONFIG}" | ||
| make O="$kbuild_output" \ | ||
| ARCH=$arch_slug CROSS_COMPILE="${compiler_id}-" \ | ||
| olddefconfig | ||
|
|
||
| make O="$kbuild_output" \ | ||
| ARCH=$arch_slug CROSS_COMPILE="${compiler_id}-" \ | ||
| -j$(nproc) all | ||
|
|
||
| mkdir -p "$OUTPUT_DIR/$arch" | ||
| bpftool btf dump file "$kbuild_output/vmlinux" format c \ | ||
| > "$OUTPUT_DIR/$arch/vmlinux.h" | ||
| ) | ||
| } | ||
|
|
||
| build_arch $TARGET_ARCH | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/bin/bash | ||
|
|
||
| arch_slug() { | ||
| printf "$arch" \ | ||
| | sed 's/x86_64/x86/' \ | ||
| | sed 's/i686/x86/' \ | ||
| | sed 's/aarch64/arm64/' \ | ||
| | sed 's/ppc64le/powerpc/' \ | ||
| | sed 's/riscv64/riscv/' \ | ||
| | sed 's/s390x/s390/' \ | ||
| | sed 's/loongarch64/loongarch/' | ||
| } | ||
|
|
||
| arch_compiler_id() { | ||
| local arch="$1" | ||
| case "$arch" in | ||
| arm) | ||
| echo "arm-linux-gnueabi" | ||
| ;; | ||
| ppc64le) | ||
| echo "powerpc64le-linux-gnu" | ||
| ;; | ||
| *) | ||
| echo "${arch}-linux-gnu" | ||
| ;; | ||
| esac | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -eux | ||
|
|
||
| LINUX_REPO=${1:-"./linux"} | ||
|
|
||
| if [ ! -d "${LINUX_REPO}" ]; then | ||
| echo "Error: Linux repo path is not found, LINUX_REPO=$LINUX_REPO" | ||
| exit 1 | ||
| fi | ||
|
|
||
| sudo apt install -y llvm libcap-dev libbfd-dev zlib1g-dev | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we install all dependencies in If we install dependencies here,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is to make
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know whether it is necessary for tzdata only. |
||
|
|
||
| cd "$LINUX_REPO/tools/bpf/bpftool" | ||
| make -j$(nproc) | ||
| sudo make install | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -eu | ||
|
|
||
| # Assume Ubuntu/Debian x86_64 | ||
|
|
||
| sudo apt update -y | ||
| DEBIAN_FRONTEND=noninteractive sudo -E apt install -y tzdata | ||
| sudo apt install -y bc bison build-essential elfutils flex libdw-dev libelf-dev make ncurses-dev python3-docutils zstd | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -eux | ||
|
|
||
| PAHOLE_ORIGIN=${PAHOLE_ORIGIN:-https://git.kernel.org/pub/scm/devel/pahole/pahole.git} | ||
| PAHOLE_REVISION=${PAHOLE_REVISION:-next} | ||
|
|
||
| sudo apt -y install cmake git libdw-dev libelf-dev | ||
|
|
||
| WORKSPACE=$(mktemp -d -t pahole.XXXXXX) | ||
| pushd "$WORKSPACE" | ||
| git clone ${PAHOLE_ORIGIN} \ | ||
| --branch "${PAHOLE_REVISION}" \ | ||
| --depth=1 \ | ||
| --single-branch | ||
| cd pahole | ||
| mkdir -p build | ||
| cmake -B=build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr | ||
| make -C build -j$(nproc) | ||
| sudo make -C build install | ||
| popd | ||
| rm -rf "$WORKSPACE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes that the script can be run in project root only ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, well realisticly this is the way it's going to run almost always. There are other assumptions, like the location of
kconfigsrelative toworkspace.I don't think it's worth it right now to rewrite the script to be location agnostic.