-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmkosi.build
More file actions
executable file
·68 lines (57 loc) · 2.23 KB
/
Copy pathmkosi.build
File metadata and controls
executable file
·68 lines (57 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
set -euo pipefail
# Configuration
KERNEL_VERSION="${KERNEL_VERSION:-6.15.8}"
KERNEL_REPO="https://github.com/gregkh/linux"
BASE_CONFIG="$SRCDIR/kernel/kernel-yocto.config"
echo "Building kernel $KERNEL_VERSION with snippets: ${KERNEL_CONFIG_SNIPPETS:-none}"
# Generate final config
config_file=$(mktemp)
cp "$BASE_CONFIG" "$config_file"
if [[ -n "${KERNEL_CONFIG_SNIPPETS:-}" ]]; then
IFS=',' read -ra snippets <<< "$KERNEL_CONFIG_SNIPPETS"
for snippet in "${snippets[@]}"; do
snippet_file="$SRCDIR/$snippet"
if [[ -f "$snippet_file" ]]; then
cat "$snippet_file" >> "$config_file" || true
fi
done
fi
for snippets_var in "${!KERNEL_CONFIG_SNIPPETS_@}"; do
IFS=',' read -ra snippets <<< "${!snippets_var}"
for snippet in "${snippets[@]}"; do
snippet_file="$SRCDIR/$snippet"
if [[ -f "$snippet_file" ]]; then
cat "$snippet_file" >> "$config_file" || true
fi
done
done
# Calculate cache key and paths
config_hash=$(sha256sum "$config_file" | cut -d' ' -f1 | cut -c1-12)
cache_dir="$BUILDDIR/kernel-${KERNEL_VERSION}-${config_hash}"
kernel_file="$cache_dir/bzImage"
# Use cached kernel if available
if [[ -f "$kernel_file" ]]; then
echo "Using cached kernel: $kernel_file"
else
echo "Building kernel from source..."
build_dir="$BUILDROOT/build/kernel-${KERNEL_VERSION}"
# Clone if needed
[[ ! -d "$build_dir" ]] && git clone --depth 1 --branch "v${KERNEL_VERSION}" "$KERNEL_REPO" "$build_dir"
# Build kernel
cd "$build_dir"
cp "$config_file" .config
export KBUILD_BUILD_TIMESTAMP="$(date -u -d @$(git log -1 --pretty=%ct))"
export KBUILD_BUILD_USER="mkosi" KBUILD_BUILD_HOST="mkosi-builder"
mkosi-chroot --chdir "/build/kernel-${KERNEL_VERSION}" make olddefconfig
mkosi-chroot --chdir "/build/kernel-${KERNEL_VERSION}" make -j "$(nproc 2>/dev/null || echo 2)" bzImage ARCH=x86_64 CONFIG_EFI_STUB=y
# Cache result
mkdir -p "$cache_dir"
cp arch/x86_64/boot/bzImage "$cache_dir/"
cp .config "$cache_dir/config"
fi
# Install kernel
mkdir -p "$DESTDIR/usr/lib/modules/$KERNEL_VERSION"
cp "$kernel_file" "$DESTDIR/usr/lib/modules/$KERNEL_VERSION/vmlinuz"
rm -f "$config_file"
echo "Kernel installed successfully"