blob: 941d716732e453124df31b8c67b186d08be39e99 [file] [edit]
#!/bin/bash
# Copyright 2026 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -euxo pipefail
PREFIX="$1"
DEPS="$2"
export PATH="$DEPS/bin:$PATH"
# A commit 97169cd6d95b3 made the cpio tool depend on `copy_file_range`,
# which is not available in the older system headers we have in 3pp.
# Revert that commit to avoid build failures.
#
# NOTE: 3pp *sometimes* does not checkout the code as a git
# Repository, so we can't reliably use the `git revert` command. Instead,
# we apply the patch in reverse.
patch -p1 -R <<'EOF'
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index ea4b9b5fed01..aa73afd3756c 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -354,6 +354,7 @@ static int cpio_mkfile(const char *name, const char *location,
int namesize;
unsigned int i;
uint32_t csum = 0;
+ ssize_t this_read;
mode |= S_IFREG;
@@ -429,9 +430,19 @@ static int cpio_mkfile(const char *name, const char *location,
push_pad(padlen(offset, 4)) < 0)
goto error;
+ if (size) {
+ this_read = copy_file_range(file, NULL, outfd, NULL, size, 0);
+ if (this_read > 0) {
+ if (this_read > size)
+ goto error;
+ offset += this_read;
+ size -= this_read;
+ }
+ /* short or failed copy falls back to read/write... */
+ }
+
while (size) {
unsigned char filebuf[65536];
- ssize_t this_read;
size_t this_size = MIN(size, sizeof(filebuf));
this_read = read(file, filebuf, this_size);
EOF
# Some ARM relocation definitions in the system header "elf.h" are missing,
# again due to the 3pp infra being old.
# Patch modpost.c to manually define them to avoid build errors.
sed -i.bak '/#include <elf.h>/a \
\
/* Manual definitions for ARM relocations */\
#define R_ARM_CALL 28\
#define R_ARM_JUMP24 29\
#define R_ARM_MOVW_ABS_NC 43\
#define R_ARM_MOVT_ABS 44\
#define R_ARM_THM_JUMP24 30\
#define R_ARM_THM_MOVW_ABS_NC 47\
#define R_ARM_THM_MOVT_ABS 48\
#define R_ARM_THM_JUMP19 51\
' scripts/mod/modpost.c
# Generate default config
make defconfig
# Disable objtool dependent options.
# the 3pp infra does not provide `libelf-dev` package, which is required by objtool.
# We can't entirely disable objtool using only the scripts/config tool, so we directly
# patch the Kconfig file.
sed -i 's/select HAVE_OBJTOOL/# select HAVE_OBJTOOL/' arch/x86/Kconfig
./scripts/config --disable DEBUG_INFO_BTF
./scripts/config --disable DEBUG_INFO_BTF_MODULES
./scripts/config --disable UNWINDER_ORC
./scripts/config --enable UNWINDER_FRAME_POINTER
./scripts/config --disable X86_KERNEL_IBT
./scripts/config --disable MITIGATION_RETPOLINE
./scripts/config --disable MITIGATION_RETHUNK
./scripts/config --disable MITIGATION_SLS
./scripts/config --disable JUMP_LABEL
# Fix missing STACK_FRAME_NON_STANDARD_FP definition by commenting it out
# This is needed because the macro is defined in OBJTOOL headers, but we
# disable OBJTOOL.
sed -i 's/^STACK_FRAME_NON_STANDARD_FP/# &/' arch/x86/kernel/ftrace_64.S
# Disable options to avoid pulling in OpenSSL as a dependency.
./scripts/config --set-str SYSTEM_TRUSTED_KEYS ""
./scripts/config --set-str SYSTEM_REVOCATION_KEYS ""
./scripts/config --disable MODULE_SIG
./scripts/config --disable KEXEC_SIG
./scripts/config --enable EXPERT
./scripts/config --enable CFG80211_CERTIFICATION_ONUS
./scripts/config --disable CFG80211_REQUIRE_SIGNED_REGDB
./scripts/config --disable SYSTEM_TRUSTED_KEYRING
./scripts/config --disable SYSTEM_REVOCATION_LIST
# Options to bundle the config into the bzImage to make future
# investigation easier.
./scripts/config --enable IKCONFIG
./scripts/config --enable IKCONFIG_PROC
# Enable options required by the sestarnix tests
## Enable Android Binder
./scripts/config --enable ANDROID_BINDER_IPC
./scripts/config --enable ANDROID_BINDERFS
./scripts/config --set-str ANDROID_BINDER_DEVICES "binder"
## Enable TUN/TAP
./scripts/config --enable TUN
./scripts/config --set-val TAP m
## Enable BPF
./scripts/config --enable BPF_SYSCALL
./scripts/config --enable BPF_JIT
./scripts/config --enable BPF_JIT_DEFAULT_ON
./scripts/config --enable BPF_UNPRIV_DEFAULT_OFF
./scripts/config --enable BPF_LSM
## Enable userfaultfd
./scripts/config --enable USERFAULTFD
## Enable FUSE
./scripts/config --enable FUSE_FS
## Enable OverlayFS
./scripts/config --enable OVERLAY_FS
## Enable ftrace
./scripts/config --enable EVENT_TRACING
./scripts/config --enable FTRACE_SYSCALLS
./scripts/config --enable FTRACE
./scripts/config --enable FUNCTION_TRACE_ARGS
./scripts/config --enable FUNCTION_TRACER
./scripts/config --enable HAVE_FUNCTION_GRAPH_TRACER
# Build
make olddefconfig
make -j$(nproc) bzImage
# Install
mkdir -p "$PREFIX"
cp arch/x86/boot/bzImage "$PREFIX/bzImage"