Skip to content
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

Add kernel opts linter and enable a bunch of network/crypto options #5

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ git push origin v3.1
```

The CI jobs will then build your release and make it available at `https://github.com/panda-re/linux_builder/releases/download/<TAG-NAME>/kernels-latest.tar.gz`

## Modifying configs
If you'd like to add a given option or set of options to all configs, you can do something like:

```sh
# write your configs into delta.txt
for f in $(cat delta.txt); do for t in $(ls config.*); do echo $f>>$t; done; done
# Run linter as shown below
git commit -a
```

## Linting configs
Before commiting any config update you MUST lint your change by running `./build.sh configonly`. You can specify architectures to lint by listing them as additional arguments, e.g., `./build.sh configonly armel mipel`.
67 changes: 48 additions & 19 deletions _in_container_build.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
#!/bin/bash

set -eux
set -eu

# We want to build linux for each of our targets using the config files. Linux is in /app/linux
# while our configs are at config.[arch]. We need to set the ARCH and CROSS_COMPILE variables
# and put the binaries in /app/binaries

TARGET_LIST=${1:-"armel mipsel mipseb mips64eb"}
# If our first argument is configonly we'll only update the defconfigs
CONFIGONLY=false
if [ $# -gt 0 ] && [ "$1" == "configonly" ]; then
CONFIGONLY=true
shift
fi

# Arguments are a list of architectures.
# If none are set, we'll use our defaults
if [ $# -eq 0 ]; then
TARGET_LIST="armel mipseb mipsel mips64eb"
else
TARGET_LIST=$@
fi

echo "Configonly: $CONFIGONLY"
echo "Target_list: $TARGET_LIST"

# Set this to update defconfigs instead of building kernel

mkdir -p /kernels

get_cc() {
Expand Down Expand Up @@ -52,24 +71,34 @@ for TARGET in $TARGET_LIST; do
# Actually build
echo "Building kernel for $TARGET"
make -C /app/linux ARCH=${short_arch} CROSS_COMPILE=$(get_cc $TARGET) O=/tmp/build/${TARGET}/ olddefconfig
make -C /app/linux ARCH=${short_arch} CROSS_COMPILE=$(get_cc $TARGET) O=/tmp/build/${TARGET}/ $BUILD_TARGETS -j$(nproc)

# Copy out zImage (if present) and vmlinux (always)
if [ -f "/tmp/build/${TARGET}/arch/${short_arch}/boot/zImage" ]; then
cp "/tmp/build/${TARGET}/arch/${short_arch}/boot/zImage" /kernels/zImage.${TARGET}
# If updating configs, lint them with kernel first! This sorts, removes default options and duplicates.
if $CONFIGONLY; then
echo "Updating $TARGET config in place"
make -C /app/linux ARCH=${short_arch} CROSS_COMPILE=$(get_cc $TARGET) O=/tmp/build/${TARGET}/ savedefconfig
cp /tmp/build/${TARGET}/defconfig /app/config.${TARGET}
echo "Finished update for config.${TARGET}"
else
make -C /app/linux ARCH=${short_arch} CROSS_COMPILE=$(get_cc $TARGET) O=/tmp/build/${TARGET}/ $BUILD_TARGETS -j$(nproc)

# Copy out zImage (if present) and vmlinux (always)
if [ -f "/tmp/build/${TARGET}/arch/${short_arch}/boot/zImage" ]; then
cp "/tmp/build/${TARGET}/arch/${short_arch}/boot/zImage" /kernels/zImage.${TARGET}
fi
cp "/tmp/build/${TARGET}/vmlinux" /kernels/vmlinux.${TARGET}

# Generate OSI profile
echo "[${TARGET}]" >> /kernels/osi.config
/panda/panda/plugins/osi_linux/utils/kernelinfo_gdb/run.sh \
/kernels/vmlinux.${TARGET} /tmp/panda_profile.${TARGET}
cat /tmp/panda_profile.${TARGET} >> /kernels/osi.config

/dwarf2json/dwarf2json linux --elf /kernels/vmlinux.${TARGET} \
| xz - > /kernels/vmlinux.${TARGET}.json.xz
fi
cp "/tmp/build/${TARGET}/vmlinux" /kernels/vmlinux.${TARGET}

# Generate OSI profile
echo "[${TARGET}]" >> /kernels/osi.config
/panda/panda/plugins/osi_linux/utils/kernelinfo_gdb/run.sh \
/kernels/vmlinux.${TARGET} /tmp/panda_profile.${TARGET}
cat /tmp/panda_profile.${TARGET} >> /kernels/osi.config

/dwarf2json/dwarf2json linux --elf /kernels/vmlinux.${TARGET} \
| xz - > /kernels/vmlinux.${TARGET}.json.xz

done

echo "Built by linux_builder on $(date)" > /kernels/README.txt
tar cvfz /app/kernels-latest.tar.gz /kernels
if ! $CONFIGONLY; then
echo "Built by linux_builder on $(date)" > /kernels/README.txt
tar cvfz /app/kernels-latest.tar.gz /kernels
fi
19 changes: 18 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
#!/bin/bash

# USAGE ./build.sh [configonly] [targetlist]
# configonly: optional string, if passed as first argument, we'll only
# update the defconfigs instead of building the kernel.
# If no targets are listed, we'll build for all

# Example: ./build.sh configonly armel mipseb mipsel mips64eb
# ./build.sh armel
# ./build.sh

# Is first argument present and configonly?
CONFIGONLY=""
if [ $# -gt 0 ] && [ "$1" == "configonly" ]; then
CONFIGONLY="$1"
shift
fi

# Now consume target list or use default
TARGETLIST=${1:-"armel mipseb mipsel mips64eb"}

set -eu

docker build -t pandare/kernel_builder .
docker run --rm -v $PWD:/app pandare/kernel_builder bash /app/_in_container_build.sh $TARGETLIST
docker run --rm -v $PWD:/app pandare/kernel_builder bash /app/_in_container_build.sh $CONFIGONLY $TARGETLIST
Loading
Loading