Commit 6dd3f0e7 authored by Dann Frazier's avatar Dann Frazier

Add kernel commandline configuration support

/etc/default/flash-kernel is added with a LINUX_KERNEL_CMDLINE variable
that can optional be used in u-boot bootscripts. This command line is
generated using the distribution default (defaults for Debian and Ubuntu
are provided), and will incorporate any user-provided commandline arguments
provided at install time. This setting is configured via debconf, so can
be overridden in expert mode by the user.

Most of this logic is heavily leveraged from grub2's packaging.

Bootscripts can incorporate this setting by adding the @@LINUX_KERNEL_CMDLINE@@
macro. For example, a simple such bootscript might look like:

setenv bootargs '@@LINUX_KERNEL_CMDLINE@@'
ext4load scsi 0 ${kernel_addr_r} vmlinuz
ext4load scsi 0 ${ramdisk_addr_r} initrd.gz
bootz ${kernel_addr_r} ${ramdisk_addr_r}
parent 0307e53c
......@@ -165,10 +165,13 @@ The supported fields are:
Configuration
- - - - - - -
Two configuration files are currently supported:
Configuration files currently supported:
* /etc/flash-kernel/machine allows skipping the machine auto-detection from
/proc/cpuinfo or /proc/dtmodel and forcing a specific Machine.
* /etc/flash-kernel/db allows overriding / adding fields from the Machine
database (but it doesn't allow removing fields or entries).
* /etc/default/flash-kernel currently contains a single variable,
LINUX_KERNEL_CMDLINE, which should be used by bootscripts to set kernel
options.
flash-kernel (3.20) UNRELEASED; urgency=medium
* Add kernel commandline configuration support
-- dann frazier <dannf@debian.org> Fri, 30 May 2014 09:53:35 -0600
flash-kernel (3.19) unstable; urgency=low
* Support kernel flavours with a hyphen in (e.g. armmp-lpae).
......
......@@ -16,7 +16,8 @@ Architecture: armel armhf
Depends: ${misc:Depends},
devio,
initramfs-tools (>= 0.92f),
linux-base (>= 3.2)
linux-base (>= 3.2),
ucf
Suggests: u-boot-tools
Description: utility to make certain embedded devices bootable
flash-kernel is a script which will put the kernel and initramfs in
......
LINUX_KERNEL_CMDLINE="@DEFAULT_CMDLINE@"
......@@ -24,6 +24,10 @@ findfs () {
mount | grep "on /target${1%/} " | tail -n1 | cut -d' ' -f1
}
tac () {
sed '1!G;h;$!d'
}
get_machine
if machine_uses_flash "$machine"; then
......@@ -42,6 +46,23 @@ if [ -e /target/etc/default/fsck ]; then
sed -i -e "s/^#FSCKFIX=no$/FSCKFIX=yes/" -e "s/^FSCKFIX=no$/FSCKFIX=yes/" /target/etc/default/fsck || true
fi
def_params="@DEFAULT_CMDLINE@"
# reverse them so we prefix them in the right order
rev_def_params="$(echo $def_params | tr ' ' '\n' | tac)"
user_params=$(user-params) || true
kopt_params="$user_params"
for d_param in $rev_def_params; do
# Don't add redundant default params
if echo $kopt_params | tr ' ' '\n' | grep -q "^${d_param}$"; then
continue
else
kopt_params="$d_param${kopt_params:+ $kopt_params}"
fi
done
echo flash-kernel flash-kernel/linux_cmdline string $kopt_params | \
chroot /target debconf-set-selections
if ! apt-install flash-kernel; then
error "apt-install flash-kernel failed"
fi
......
#!/bin/sh
set -e
. /usr/share/debconf/confmodule
db_input medium flash-kernel/linux_cmdline || /bin/true
db_go
......@@ -7,3 +7,4 @@ initramfs-tools usr/share
bootscript usr/share/flash-kernel
db usr/share/flash-kernel
functions usr/share/flash-kernel
debian/default usr/share/flash-kernel
......@@ -2,8 +2,47 @@
set -e
if [ "$1" = "triggered" ]; then
FLASH_KERNEL_NOTRIGGER=y flash-kernel
fi
# cargo-culted from grub
merge_debconf_into_conf() {
local tmpfile; tmpfile="$1"
local setting; setting="$2"
local template; template="$3"
db_get "$template"
local value; value="$(echo "$RET" | sed -e 's,[$`"\],\\&,g')"
if grep -q "^${setting}=" "$tmpfile"; then
value="$(echo "$value" | sed -e 's,[\@],\\&,g')"
sed -i -re "s@^(${setting}=).*@\1\"${value}\"@" "$tmpfile"
else
echo >> "$tmpfile"
echo "${setting}=\"${value}\"" >> "$tmpfile"
fi
}
case "$1" in
configure)
. /usr/share/debconf/confmodule
tmp_default_fk="$(mktemp -t flash-kernel.XXXXXXXXXX)"
trap "rm -f ${tmp_default_fk}" EXIT
cp -p /usr/share/flash-kernel/default/flash-kernel \
${tmp_default_fk}
merge_debconf_into_conf "$tmp_default_fk" \
LINUX_KERNEL_CMDLINE flash-kernel/linux_cmdline
ucf --three-way --debconf-ok ${tmp_default_fk} \
/etc/default/flash-kernel
ucfr flash-kernel /etc/default/flash-kernel
;;
triggered)
FLASH_KERNEL_NOTRIGGER=y flash-kernel
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
#!/bin/sh
set -e
case "$1" in
purge)
rm -f /etc/default/flash-kernel
if which ucf >/dev/null ; then
ucf --purge /etc/default/flash-kernel
fi
if which ucfr >/dev/null ; then
ucfr --purge flash-kernel \
/etc/default/flash-kernel || true
fi
;;
remove|upgrade|failed-upgrade|abort-upgrade|abort-install)
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
Template: flash-kernel/linux_cmdline
Type: string
Default: @DEFAULT_CMDLINE@
_Description: Linux default command line:
The following string will be used as Linux parameters
#! /usr/bin/make -f
AUTOGEN_DEB_FILES := flash-kernel-installer.postinst
AUTOGEN_DEB_FILES := flash-kernel.templates flash-kernel-installer.postinst default/flash-kernel
ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
DEFAULT_CMDLINE := quiet splash
else
DEFAULT_CMDLINE := quiet
endif
override_dh_auto_install:
for i in $(AUTOGEN_DEB_FILES); do \
cat < debian/$$i.in > debian/$$i; \
sed "s/@DEFAULT_CMDLINE@/$(DEFAULT_CMDLINE)/" \
< debian/$$i.in > debian/$$i; \
done
dh_auto_install
......
......@@ -252,6 +252,11 @@ flash_initrd() {
echo "done." >&2
}
get_kernel_cmdline() {
. /etc/default/flash-kernel
echo "$LINUX_KERNEL_CMDLINE"
}
mkimage_kernel() {
local kaddr="$1"
local epoint="$2"
......@@ -287,6 +292,7 @@ mkimage_script() {
printf "Generating boot script u-boot image... " >&2
sed -e "s/@@KERNEL_VERSION@@/$kvers/g" \
-e "s/@@LINUX_KERNEL_CMDLINE@@/$(get_kernel_cmdline)/g" \
< $sdata > $tdata
mkimage -A arm -O linux -T script -C none -a "$saddr" -e "$saddr" \
-n "$sdesc" -d "$tdata" "$script" >&2 1>/dev/null
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment