Here is a patch to do that (works only for the GTA02 for now).
From 10351531703fd014d460f67aa331873060cc062f Mon Sep 17 00:00:00 2001 From: Thibaut Girka <t...@sitedethib.com> Date: Sun, 15 Aug 2010 13:38:33 +0200 Subject: [PATCH 3/9] flash-kernel-installer: add uboot-installer
--- packages/flash-kernel/check.d/_numbers | 1 + packages/flash-kernel/check.d/ext2_boot | 64 +++++++++ packages/flash-kernel/debian/control | 2 +- .../debian/flash-kernel-installer.di-numbers | 1 + .../debian/flash-kernel-installer.install | 1 + .../debian/flash-kernel-installer.postinst | 1 + .../debian/flash-kernel-installer.templates | 71 ++++++++++ packages/flash-kernel/debian/rules | 2 +- packages/flash-kernel/uboot-installer | 146 ++++++++++++++++++++ 9 files changed, 287 insertions(+), 2 deletions(-) create mode 100644 packages/flash-kernel/check.d/_numbers create mode 100755 packages/flash-kernel/check.d/ext2_boot create mode 100644 packages/flash-kernel/debian/flash-kernel-installer.di-numbers create mode 100644 packages/flash-kernel/debian/flash-kernel-installer.install create mode 100644 packages/flash-kernel/uboot-installer diff --git a/packages/flash-kernel/check.d/_numbers b/packages/flash-kernel/check.d/_numbers new file mode 100644 index 0000000..18d7600 --- /dev/null +++ b/packages/flash-kernel/check.d/_numbers @@ -0,0 +1 @@ +05 ext2_boot diff --git a/packages/flash-kernel/check.d/ext2_boot b/packages/flash-kernel/check.d/ext2_boot new file mode 100755 index 0000000..7109543 --- /dev/null +++ b/packages/flash-kernel/check.d/ext2_boot @@ -0,0 +1,64 @@ +#!/bin/sh +# Check that the boot partition is of type ext2, and that it is marked as +# bootable. Used for Openmoko FreeRunner (GTA02). + +machine=$(sed '/^Hardware/ {s/^Hardware\s*:\s*//;p}' /proc/cpuinfo) +case "$machine" in + "GTA02") + ;; + *) + exit 0 + ;; +esac + +. /lib/partman/lib/base.sh + +for dev in $DEVICES/*; do + [ -d "$dev" ] || continue + cd $dev + open_dialog PARTITIONS + while { read_line num id size type fs path name; [ "$id" ]; }; do + [ "$fs" != free ] || continue + [ -f $id/method ] || continue + [ -f $id/acting_filesystem ] || continue + [ -f $id/mountpoint ] || continue + mountpoint=$(cat $id/mountpoint) + filesystem=$(cat $id/acting_filesystem) + if [ "$mountpoint" = / ]; then + root_fs=$filesystem + root_type=$type + root_path=$path + if [ -f $id/bootable ]; then + root_bootable=yes + fi + elif [ "$mountpoint" = /boot ]; then + boot_fs=$filesystem + boot_type=$type + boot_path=$path + if [ -f $id/bootable ]; then + boot_bootable=yes + fi + fi + done + close_dialog +done + +# If no separate boot partition exists root acts as boot +if [ -z "$boot_path" ]; then + boot_fs=$root_fs + boot_type=$root_type + boot_path=$root_path + boot_bootable=$root_bootable +fi + +# We require an ext2 filesystem to boot +if [ "$boot_fs" != ext2 ]; then + db_set flash-kernel-installer/uboot/boot_not_ext2 true + db_input critical flash-kernel-installer/uboot/boot_not_ext2 || true + db_go || true + db_get flash-kernel-installer/uboot/boot_not_ext2 + if [ "$RET" = true ]; then + exit 1 + fi +fi + diff --git a/packages/flash-kernel/debian/control b/packages/flash-kernel/debian/control index ce959a2..7d1fc1a 100644 --- a/packages/flash-kernel/debian/control +++ b/packages/flash-kernel/debian/control @@ -3,7 +3,7 @@ Section: utils Priority: optional Maintainer: Debian Install System Team <debian-boot@lists.debian.org> Uploaders: Martin Michlmayr <t...@cyrius.com>, Wouter Verhelst <wou...@debian.org> -Build-Depends: debhelper (>= 7.3.10) +Build-Depends: debhelper (>= 7.3.10), dh-di Standards-Version: 3.7.2 Vcs-Svn: svn://svn.debian.org/d-i/trunk/packages/flash-kernel diff --git a/packages/flash-kernel/debian/flash-kernel-installer.di-numbers b/packages/flash-kernel/debian/flash-kernel-installer.di-numbers new file mode 100644 index 0000000..0110b8d --- /dev/null +++ b/packages/flash-kernel/debian/flash-kernel-installer.di-numbers @@ -0,0 +1 @@ +check.d lib/partman diff --git a/packages/flash-kernel/debian/flash-kernel-installer.install b/packages/flash-kernel/debian/flash-kernel-installer.install new file mode 100644 index 0000000..cd38ae6 --- /dev/null +++ b/packages/flash-kernel/debian/flash-kernel-installer.install @@ -0,0 +1 @@ +uboot-installer usr/share/flash-kernel-installer diff --git a/packages/flash-kernel/debian/flash-kernel-installer.postinst b/packages/flash-kernel/debian/flash-kernel-installer.postinst index 22bc6d1..164e464 100755 --- a/packages/flash-kernel/debian/flash-kernel-installer.postinst +++ b/packages/flash-kernel/debian/flash-kernel-installer.postinst @@ -5,6 +5,7 @@ set -e . /usr/share/debconf/confmodule +. /usr/share/flash-kernel-installer/uboot-installer log() { logger -t flash-kernel-installer "$@" diff --git a/packages/flash-kernel/debian/flash-kernel-installer.templates b/packages/flash-kernel/debian/flash-kernel-installer.templates index f51246a..09cdfad 100644 --- a/packages/flash-kernel/debian/flash-kernel-installer.templates +++ b/packages/flash-kernel/debian/flash-kernel-installer.templates @@ -34,6 +34,77 @@ Type: text # :sl4: _Description: Generating boot image on disk... +Template: flash-kernel-installer/uboot/env_not_readable +Type: boolean +Default: true +# This item is a question which asks if we should proceed if reading +# the U-Boot environment failed. +# :sl4: +_Description: U-Boot environment is not readable, continue anyway? + Reading the U-Boot environment failed, meaning that the U-Boot environment + is corrupted, there is a problem with the uboot-envtools package, + or accessing the U-Boot environment is not supported on your device. + The U-Boot environment won't be automatically modified, but the installer + can give you instructions to do it manually. + +Template: flash-kernel-installer/uboot/no_menu_left +Type: boolean +Default: true +# This item is a question which asks if we should proceed even though +# there is no menu left to store the old boot command from the U-Boot +# environment. +# :sl4: +_Description: No menu left to store old boot command, continue anyway? + +Template: flash-kernel-installer/uboot/apply_changes +Type: boolean +Default: true +# This item is a question that asks if ${CHANGES} should be written to the +# U-Boot environment, while showing the ${CHANGES} and simple instructions +# on how to manually edit the U-Boot environment. +# :sl4: +_Description: Apply changes? + The following changes to your U-Boot env are needed to run Debian: + . + ${CHANGES} + . + You can apply them now or apply them manually, typing the commands listed + above in your U-Boot shell, followed by 'saveenv'. + +Template: flash-kernel-installer/uboot/show_changes +Type: note +# This item is a question that shows ${CHANGES} that should be made to the +# U-Boot environment, as well as simple instructions on how to manually edit it. +# :sl4: +_Description: Manual intervention needed + The following changes to your U-Boot env are needed to run Debian: + . + ${CHANGES} + . + Writing them automatically doesn't seem to be supported, + you have to apply them manually. To do so, type the commands + listed above in your U-Boot shell, followed by 'saveenv'. + +Template: flash-kernel-installer/uboot/fw_setenv_failed +Type: +# This item is a notification shown when failure to write changes to the +# U-Boot environment occur. +# :sl4: +_Description: Failure while writing changes to the U-Boot environment + +Template: flash-kernel-installer/uboot/boot_not_ext2 +Type: boolean +Default: true +# :sl2: +_Description: Go back to the menu and correct this problem? + Your boot partition has not been configured with the ext2 file system. + This is needed by your device in order to boot. Please go back and use + the ext2 file system. + . + If you do not go back to the partitioning menu and correct this error, + the partition will be used as is. This means that you may not be able to + boot your devic. + Template: debian-installer/flash-kernel-installer/title Type: text # Main menu item diff --git a/packages/flash-kernel/debian/rules b/packages/flash-kernel/debian/rules index 78c7615..37850fb 100755 --- a/packages/flash-kernel/debian/rules +++ b/packages/flash-kernel/debian/rules @@ -1,3 +1,3 @@ #! /usr/bin/make -f %: - dh $@ + dh --with d-i $@ diff --git a/packages/flash-kernel/uboot-installer b/packages/flash-kernel/uboot-installer new file mode 100644 index 0000000..0aa1e92 --- /dev/null +++ b/packages/flash-kernel/uboot-installer @@ -0,0 +1,146 @@ +#!/bin/sh + +# This file contains code used to modify the U-Boot bootloader environment. + +. /usr/share/debconf/confmodule + +setenv() { + local name="$1" + local value="$2" + + command="fw_setenv $name '$value'" + if [ -z "$env_changes" ]; then + env_changes="$command" + else + env_changes="$env_changes\n$command" + fi +} + +modify_uboot_env() { + local rootfs="$1" + local bootfs="$2" + + local boot_img="/uImage.bin" # assume /boot is on separate partition + + # If /boot and / is on the same partition add boot directory to path + if [ -z "$bootfs" ]; then + bootfs="$rootfs" + boot_img="/boot/uImage.bin" + fi + + local boot_part=$(echo $bootfs | sed 's/.*[^0-9]\([0-9][0-9]*\)/\1/') + + # Bind target's /dev to d-i's + #TODO: is the trap ok? + mount -o bind /dev/ /target/dev/ || true + trap "umount /target/dev" HUP INT QUIT KILL PIPE TERM EXIT + + # Modify U-Boot environment on flash + uimage_address=0x32000000 + + # Backup the current env, if it fails, abort + # fw_printenv doesn't return an error code if reading fails, so, we have to + # grep for 'Warning: Bad CRC' on stderr... + #TODO: if readable, do the actual backup + env_readable=true + if ! in-target fw_printenv || \ + in-target sh -c "fw_printenv 2>&1 | grep -q 'Warning: Bad CRC'"; then + env_readable=false + #FIXME: check if everything is ok? (test, verify error code and priority) + db_input critical flash-kernel-installer/uboot/env_not_readable || [ $? -eq 30 ] + db_go || return 10 + db_get flash-kernel-installer/uboot/env_not_readable + if [ "$RET" != true ]; then + return 1 + fi + fi + + # Compute new bootcmd + #TODO: mmc is not the only subsystem, we have to handle more... + # Parse $bootfs for that + bootcmd="setenv bootargs \${mtdparts} \ + console=ttySAC0,115200 \ + console=tty0 \ + root=$rootfs \ + rootwait \ + ro \ + quiet; \ + mmcinit; \ + ext2load mmc :$boot_part $uimage_address $boot_img; \ + bootm $uimage_address" + + # Read old bootcmd + if $env_readable; then + oldbootcmd="$(in-target --pass-stdout fw_printenv -n bootcmd)" || true + else + # If env is not readable, fw_printenv will give us default env + oldbootcmd="" + fi + + # If Debian is already installed, don't do anything + if [ "$(echo $bootcmd)" = "$oldbootcmd" ]; then + return 0 + fi + + # Save oldbootcmd and save new bootcmd + if [ -n "$oldbootcmd" ]; then + setenv oldbootcmd "$oldbootcmd" + fi + setenv bootcmd "$bootcmd" + + # If no menu command contains 'run oldbootcmd', add it + #TODO: disable this for systems without bootmenu + if ! in-target --pass-stdout fw_printenv | grep -q ': run oldbootcmd'; then + # Add a menu to run the backed up bootcmd, at the end of the menu list + menu=9 + while [ $menu -ge 1 ]; do + if ! in-target fw_printenv -n menu_$menu; then + setenv menu_$menu 'Run old boot command: run oldbootcmd' + break + fi + menu=$(($menu - 1)) + done + + if [ $menu -eq 0 ]; then + #FIXME: check if everything is ok? (test, verify error code and priority) + db_input high flash-kernel-installer/uboot/no_menu_left || [ $? -eq 30 ] + db_go || return 10 + db_get flash-kernel-installer/uboot/no_menu_left + if [ "$RET" != true ]; then + return 1 + fi + fi + fi + + # Show changes and, if uboot-envtools works, ask user if they should be + # applied. + #TODO: how to display that?! "${...}" Find something else than ugly hack! + #FIXME: check if everything is ok? (test, verify error code and priority) + # No db_capb escape, cdebconf doesn't handle that yet + CHANGES="$(echo -e $env_changes | sed s/^fw_// | sed 's/${/$${!}{/g' )" + if $env_readable; then + db_subst flash-kernel-installer/uboot/apply_changes CHANGES "$CHANGES" + db_input high flash-kernel-installer/uboot/apply_changes || [ $? -eq 30 ] + db_go || return 10 + db_get flash-kernel-installer/uboot/apply_changes + if [ "$RET" != true ]; then + return 0 + fi + else + db_subst flash-kernel-installer/uboot/show_changes CHANGES "$CHANGES" + db_input critical flash-kernel-installer/uboot/show_changes || [ $? -eq 30 ] + db_go || return 10 + return 0 + fi + + # If yes, apply changes. If it fails, revert backup + if ! in-target sh -c "$(echo -e $env_changes)"; then + #TODO: revert backup + db_input critical flash-kernel-installer/uboot/fw_setenv_failed || true + db_go || true + db_progress STOP + return 1 + fi + + # Done! +} -- 1.7.1
signature.asc
Description: This is a digitally signed message part