Skip to content
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
34 changes: 25 additions & 9 deletions bin/omamobile
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,28 @@ cmd_initramfs_config() {
ls -l "$1"
}

# INITRAMFS_MODULES into the initramfs: each module's .ko from this build's
# modules directory $2 into $1, its name in $1/order (load order). A module
# the kernel has built in (listed in $2/modules.builtin, as sec_acpm and its
# mailbox are since #227) has nothing to load and is left out; a module that
# is neither is an error. $3...: the module names.
pack_initramfs_modules() {
local dest=$1 mdir=$2 m ko
shift 2
mkdir -p "$dest"
for m in "$@"; do
[[ $m =~ ^[a-z0-9_-]+$ ]] || die "INITRAMFS_MODULES: bad module name '$m'"
ko=$(find "$mdir" -name "$m.ko" | head -1)
if [[ -z $ko ]] && grep -q "/$m\.ko\$" "$mdir/modules.builtin" 2>/dev/null; then
say "INITRAMFS_MODULES: $m is built in"
continue
fi
[[ -n $ko ]] || die "INITRAMFS_MODULES: no $m.ko in $mdir"
cp "$ko" "$dest/"
echo "$m" >> "$dest/order"
done
}

cmd_initramfs() {
local dl="$WORK/downloads/alpine" stage="$KERNEL_OUT/initramfs" ver=3.24.2
local release=0
Expand Down Expand Up @@ -557,20 +579,14 @@ cmd_initramfs() {
# Modules the init loads before anything else (INITRAMFS_MODULES, in load
# order), from this kernel build's modules_install: the directory of this
# build's release, never an older one left in modules-staging
local m ko mdir rel
local mdir rel
if [[ -n ${DEV_INITRAMFS_MODULES:-} ]]; then
rel=$(cat "$KERNEL_OUT/include/config/kernel.release" 2>/dev/null) ||
die "INITRAMFS_MODULES needs a kernel build: omamobile kernel"
mdir=$KERNEL_OUT/modules-staging/lib/modules/$rel
[[ -d $mdir ]] || die "INITRAMFS_MODULES needs this build's modules ($rel): omamobile modules"
mkdir -p "$stage/lib/modules/omamobile"
for m in $DEV_INITRAMFS_MODULES; do
[[ $m =~ ^[a-z0-9_-]+$ ]] || die "INITRAMFS_MODULES: bad module name '$m'"
ko=$(find "$mdir" -name "$m.ko" | head -1)
[[ -n $ko ]] || die "INITRAMFS_MODULES: no $m.ko in $mdir"
cp "$ko" "$stage/lib/modules/omamobile/"
echo "$m" >> "$stage/lib/modules/omamobile/order"
done
# shellcheck disable=SC2086 # a list of plain module names, checked there
pack_initramfs_modules "$stage/lib/modules/omamobile" "$mdir" $DEV_INITRAMFS_MODULES
echo "$rel" > "$KERNEL_OUT/initramfs.release"
say "Initramfs modules ($rel): $DEV_INITRAMFS_MODULES"
fi
Expand Down
20 changes: 20 additions & 0 deletions tests/initramfs-steps
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,23 @@ pass "the USB switch writes only 0x09, only when open, only on its own board"

grep -q 'if \[ -f /etc/omamobile-fb-wait \]; then' "$init" || fail "the splash waits for fb0 only with the marker"
pass "the fb0 wait follows its marker"

# Pack time, INITRAMFS_MODULES: a .ko is packed in order, a module the
# kernel has built in is left out (nothing to load), a missing one stops.
pack() {
( die() { echo "die: $*"; exit 1; }
say() { echo "say: $*"; }
eval "$(sed -n '/^pack_initramfs_modules() {$/,/^}$/p' bin/omamobile)"
pack_initramfs_modules "$@" )
}
m=$t/mods
mkdir -p "$m/kernel/drivers/mfd"
: > "$m/kernel/drivers/mfd/max77759.ko"
printf 'kernel/drivers/mfd/sec-acpm.ko\nkernel/drivers/mailbox/exynos-mailbox.ko\n' > "$m/modules.builtin"
pack "$t/packed" "$m" exynos-mailbox sec-acpm max77759 > "$t/log" 2>&1 || { cat "$t/log"; fail "built-in modules are skipped"; }
[[ $(cat "$t/packed/order") == max77759 && -e $t/packed/max77759.ko && ! -e $t/packed/sec-acpm.ko ]] \
|| fail "only the .ko is packed and listed"
grep -q 'say: INITRAMFS_MODULES: sec-acpm is built in' "$t/log" || fail "a built-in module is reported"
pack "$t/packed2" "$m" max77759 nvmem-max77759 > "$t/log" 2>&1 && fail "a missing module stops the build"
grep -q "die: INITRAMFS_MODULES: no nvmem-max77759.ko" "$t/log" || fail "a missing module is named"
pass "INITRAMFS_MODULES: a built-in module is left out, a missing one stops the build"