/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} --- README | 5 +++- debian/control | 3 ++- debian/default/flash-kernel.in | 1 + debian/flash-kernel-installer.postinst.in | 20 ++++++++++++++ debian/flash-kernel.config | 8 ++++++ debian/flash-kernel.install | 1 + debian/flash-kernel.postinst | 43 ++++++++++++++++++++++++++++--- debian/flash-kernel.postrm | 22 ++++++++++++++++ debian/flash-kernel.templates.in | 5 ++++ debian/rules | 12 +++++++-- functions | 6 +++++ 11 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 debian/default/flash-kernel.in mode change 100755 => 100644 debian/flash-kernel-installer.postinst.in create mode 100644 debian/flash-kernel.config create mode 100644 debian/flash-kernel.postrm create mode 100644 debian/flash-kernel.templates.in diff --git a/README b/README index 6865a17..99e63a2 100644 --- a/README +++ b/README @@ -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. diff --git a/debian/control b/debian/control index 835f28f..8ba0400 100644 --- a/debian/control +++ b/debian/control @@ -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 diff --git a/debian/default/flash-kernel.in b/debian/default/flash-kernel.in new file mode 100644 index 0000000..347d8ac --- /dev/null +++ b/debian/default/flash-kernel.in @@ -0,0 +1 @@ +LINUX_KERNEL_CMDLINE="@DEFAULT_CMDLINE@" diff --git a/debian/flash-kernel-installer.postinst.in b/debian/flash-kernel-installer.postinst.in old mode 100755 new mode 100644 index 9017ac3..134da41 --- a/debian/flash-kernel-installer.postinst.in +++ b/debian/flash-kernel-installer.postinst.in @@ -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 @@ -100,6 +104,22 @@ fi trap - EXIT HUP INT QUIT TERM mv /target/tmp/flash-kernel.$$ /target/usr/sbin/flash-kernel +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" | in-target debconf-set-selections + # We need the udev /dev which has the MTD devices mount -o bind /dev /target/dev if ! in-target flash-kernel; then diff --git a/debian/flash-kernel.config b/debian/flash-kernel.config new file mode 100644 index 0000000..c39f93f --- /dev/null +++ b/debian/flash-kernel.config @@ -0,0 +1,8 @@ +#!/bin/sh + +set -e + +. /usr/share/debconf/confmodule + +db_input medium flash-kernel/linux_cmdline || /bin/true +db_go diff --git a/debian/flash-kernel.install b/debian/flash-kernel.install index 5d3aebd..ee1bf9d 100644 --- a/debian/flash-kernel.install +++ b/debian/flash-kernel.install @@ -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 diff --git a/debian/flash-kernel.postinst b/debian/flash-kernel.postinst index 1700373..14976b1 100755 --- a/debian/flash-kernel.postinst +++ b/debian/flash-kernel.postinst @@ -2,8 +2,45 @@ 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# diff --git a/debian/flash-kernel.postrm b/debian/flash-kernel.postrm new file mode 100644 index 0000000..2e172e6 --- /dev/null +++ b/debian/flash-kernel.postrm @@ -0,0 +1,22 @@ +#!/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 diff --git a/debian/flash-kernel.templates.in b/debian/flash-kernel.templates.in new file mode 100644 index 0000000..12b81b3 --- /dev/null +++ b/debian/flash-kernel.templates.in @@ -0,0 +1,5 @@ +Template: flash-kernel/linux_cmdline +Type: string +Default: @DEFAULT_CMDLINE@ +_Description: Linux default command line: + The following string will be used as Linux parameters diff --git a/debian/rules b/debian/rules index 904ff03..f001996 100755 --- a/debian/rules +++ b/debian/rules @@ -1,9 +1,17 @@ #! /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 diff --git a/functions b/functions index 9213145..fc10684 100644 --- a/functions +++ b/functions @@ -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 -- 2.0.0 -- To UNSUBSCRIBE, email to debian-boot-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/1401414889-16498-3-git-send-email-da...@debian.org