Skip to content
Draft
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
16 changes: 15 additions & 1 deletion firecracker/fc-kernels/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,21 @@ Then add the version to `kernel_versions.txt` and build.

## Flavours

A flavour is the same upstream tree and patches built under a different config, named `<version>-<flavour>`: `6.1.158-android` is `6.1.158` with binder, DMA-BUF heaps, Android's networking options, a small patch that answers Android's ashmem ioctls on memfd files instead of an ashmem driver, and PSI (pressure stall information) on by default, so a sandbox can run Android in a container. The other configs build PSI in but leave it off unless the guest cmdline says `psi=1`; Android's low-memory killer daemon needs `/proc/pressure`, and without it the UI never comes up. `build.sh` takes the upstream tag and the `patches/` directory from the stem (`6.1.158`) and everything else — the config, the output directory, and so the published name a template selects — from the full name. Seed a flavour's config from its stem's and settle it the same way as a new version (`sudo env CONFIG_ONLY=1 ./build.sh 6.1.158-android`, per architecture). A flavour is a sibling of its stem, not a patch release: the weekly bump neither seeds from it nor bumps it. A flavour may also carry patches of its own under `patches/<version>-<flavour>/`; they apply after the stem's, and a change there rebuilds only that flavour.
A flavour is the same upstream tree and patches built under a different config, named `<stem>-<flavour>`: `6.1.190-android` is `6.1.190` with binder, DMA-BUF heaps, Android's networking options, a small patch that answers Android's ashmem ioctls on memfd files instead of an ashmem driver, and PSI (pressure stall information) on by default, so a sandbox can run Android in a container. The other configs build PSI in but leave it off unless the guest cmdline says `psi=1`; Android's low-memory killer daemon needs `/proc/pressure`, and without it the UI never comes up. `build.sh` takes the upstream tag and `patches/<stem>/` from the stem and everything else (the config, the output directory, and so the published name a template selects) from the full name.

A flavour is defined once, for every stem: `flavours/<arch>/<flavour>.config` holds only the lines it changes in a stem's config, and `patches/<flavour>/` the patches it carries on top of the stem's. When `patches/<stem>-<flavour>/` holds patches, they replace `patches/<flavour>/` for that one build, for a stem the shared patches no longer apply to. `scripts/flavour_fragment.py` derives a fragment from a flavoured config and the config it was seeded from; each fragment's header says which pair it came from.

What builds is still one full, resolved config per pin, `configs/<arch>/<stem>-<flavour>.config`, reviewed and committed like any other. When that file does not exist yet, `CONFIG_ONLY=1` seeds it from `configs/<arch>/<stem>.config` with the fragment appended (Kconfig takes a symbol's last assignment, so the fragment wins), resolves it with `olddefconfig` as for any version, and fails without writing it if any fragment line did not survive unchanged: `olddefconfig` quietly turns off a symbol whose dependencies the tree no longer meets, which would ship the flavour without what it exists for. A config that exists is re-settled like any version, and the fragment is checked again. A build never seeds.

So when the bump adds a stem, it adds `<stem>-android` next to it and seeds it the same way, per architecture on that architecture's machine:

```sh
sudo env CONFIG_ONLY=1 ./build.sh 6.1.190-android
sudo env CONFIG_ONLY=1 ./build.sh 6.1.190-android arm64
sudo chown -R "$(id -u):$(id -g)" configs
```

A fragment line that does not survive is a flavour change to review, not a line to drop. A stem is never seeded from a flavour, and older flavoured pins (`6.1.158-android`) keep building from their own committed configs. To change the flavour itself, edit the fragment and re-seed the newest flavoured config (remove it and run `CONFIG_ONLY=1` again).

## New kernel in E2B's infra
_Note: these steps should give you a new kernel on your self-hosted E2B using https://github.com/e2b-dev/infra_
Expand Down
77 changes: 71 additions & 6 deletions firecracker/fc-kernels/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ set -euo pipefail
#
# arch is one of: x86_64 (default), arm64 (kernel-style names).
# A version may carry a flavour, 6.1.158-android: the upstream tag and the patches
# come from its stem (6.1.158), the config and the output from the full name.
# come from its stem (6.1.158), the config and the output from the full name. The
# flavour's own patches (patches/android/) apply after the stem's.
# Output: builds/vmlinux-<version>/<output_arch>/vmlinux.bin where
# <output_arch> is the Go/OCI name (amd64/arm64) used by the orchestrator.
#
Expand All @@ -20,6 +21,11 @@ set -euo pipefail
# than silently taking upstream defaults at build time. It needs an explicit
# version — it overwrites the config it reads, and doing that to every pinned
# version at once is never what anyone means.
#
# A flavour on a stem it has no config for yet, 6.1.190-android, is seeded from
# the stem's config plus flavours/<arch>/<flavour>.config, and CONFIG_ONLY=1
# fails unless every line of that fragment survives olddefconfig unchanged. A
# build never seeds: it reads the committed config like any other version.

HOST_ARCH="$(uname -m)"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
Expand Down Expand Up @@ -78,6 +84,34 @@ version_stem() {
echo "${1%%-*}"
}

# The flavour a pin is built under: android for 6.1.158-android, empty for 6.1.158.
version_flavour() {
[[ "$1" != *-* ]] || echo "${1#*-}"
}

# The lines of a flavour fragment the resolved config does not carry, each with
# the value it resolved to. A symbol the config leaves out is n, as Kconfig reads
# it: olddefconfig drops "is not set" for a symbol whose dependencies are off.
fragment_lost() {
local fragment="$1" config="$2"
awk '
{
if (match($0, /^CONFIG_[A-Za-z0-9_]+=/)) {
sym = substr($0, 1, RLENGTH - 1); val = substr($0, RLENGTH + 1)
} else if ($0 ~ /^# CONFIG_[A-Za-z0-9_]+ is not set$/) {
sym = $2; val = "n"
} else {
next
}
}
FILENAME == ARGV[1] { have[sym] = val; next }
{
got = (sym in have) ? have[sym] : "n"
if (got != val) print " " $0 " (resolved to " got ")"
}
' "$config" "$fragment"
}

# The salt Kconfig carries into the vmlinux as an ELF note, naming what the
# binary was built from. It is a plain string symbol, so olddefconfig keeps
# whatever the config it reads says: a config seeded from another version names
Expand Down Expand Up @@ -123,10 +157,21 @@ build_version() {

echo "Starting build for kernel version: $version (${target_arch})"

cp "$SCRIPT_DIR/configs/${target_arch}/${version}.config" .config

local stem tag=""
local stem flavour fragment="" tag=""
stem="$(version_stem "$version")"
flavour="$(version_flavour "$version")"
[ -z "$flavour" ] || fragment="$SCRIPT_DIR/flavours/${target_arch}/${flavour}.config"
[ -f "$fragment" ] || fragment=""

if [[ "${CONFIG_ONLY:-}" == "1" && -n "$fragment" && ! -f "$SCRIPT_DIR/configs/${target_arch}/${version}.config" ]]; then
# Kconfig takes the last assignment of a symbol, so the fragment wins
# wherever it and the stem's config disagree.
echo "Seeding $version from configs/${target_arch}/${stem}.config and flavours/${target_arch}/${flavour}.config"
cat "$SCRIPT_DIR/configs/${target_arch}/${stem}.config" "$fragment" >.config
else
cp "$SCRIPT_DIR/configs/${target_arch}/${version}.config" .config
fi

# get_tag greps, so no match is a non-zero exit, not just empty output.
tag="$(get_tag "$stem")" || true
if [ -z "$tag" ]; then
Expand All @@ -139,8 +184,16 @@ build_version() {
git clean -fdq

apply_patches "$stem"
# A flavour may carry patches of its own, applied after its stem's.
[ "$version" = "$stem" ] || apply_patches "$version"
# A flavour may carry patches of its own, applied after its stem's: those in
# patches/<flavour>/, which every stem shares, unless patches/<version>/ holds
# a set for this stem alone, for when the shared one no longer applies.
if [ -n "$flavour" ]; then
if compgen -G "$SCRIPT_DIR/patches/$version/*.patch" >/dev/null; then
apply_patches "$version"
else
apply_patches "$flavour"
fi
fi

local make_opts="" cross=""
if [[ "$target_arch" == "arm64" ]]; then
Expand All @@ -165,6 +218,18 @@ build_version() {
make $make_opts olddefconfig

if [[ "${CONFIG_ONLY:-}" == "1" ]]; then
# olddefconfig quietly overrides a value whose dependencies the tree does not
# meet, which would ship the flavour without what it exists for.
if [ -n "$fragment" ]; then
local lost
lost="$(fragment_lost "$fragment" .config)"
if [ -n "$lost" ]; then
echo "The $version tree does not keep these flavours/${target_arch}/${flavour}.config lines:" >&2
echo "$lost" >&2
return 1
fi
echo "Every flavours/${target_arch}/${flavour}.config line survived on $version"
fi
echo "Writing the resolved config back to configs/${target_arch}/${version}.config"
cp .config "$SCRIPT_DIR/configs/${target_arch}/${version}.config"
return 0
Expand Down
Loading