Bug#976723: flash-kernel: Add Option to boot kirkwood-qnap from USB.
Package: flash-kernel
Version: 3.103
Severity: normal
Dear Maintainer,
I have done some changes to boot kirkwood-qnap from USB if a prepared USB drive is found,
so we are able to run bullseye on this devices.
I have test in on TS-2019P+.
Patch is attachted.
-- System Information:
Debian Release: bullseye/sid
APT prefers testing
APT policy: (500, 'testing')
Architecture: armel (armv5tel)
Kernel: Linux 5.9.0-4-marvell
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages flash-kernel depends on:
ii debconf [debconf-2.0] 1.5.74
ii devio 1.2-1.2+b1
ii initramfs-tools 0.139
ii linux-base 4.6
ii mtd-utils 1:2.1.2-1
ii ucf 3.0043
Versions of packages flash-kernel recommends:
ii u-boot-tools 2020.10+dfsg-1+b1
flash-kernel suggests no packages.
-- Configuration Files:
/etc/kernel/postinst.d/zz-flash-kernel changed [not included]
-- debconf information excluded
diff --git a/functions b/functions
index a5a61e0..ef2d1b8 100644
--- a/functions
+++ b/functions
@@ -3,6 +3,7 @@
# Copyright (C) 2011 Loïc Minier <lool@dooz.org>
# Copyright (C) 2011 Julian Andres Klode <jak@debian.org>
# Copyright (C) 2013-2016 Ian Campbell <ijc@debian.org>
+# Copyright (C) 2020 Sebastian Fiedler <sf@unix-solution.de>
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -24,6 +25,7 @@ FK_ETC_MACHINE="${FK_ETC_MACHINE:-/etc/flash-kernel/machine}"
PROC_CPUINFO="${FK_PROC_CPUINFO:-/proc/cpuinfo}"
PROC_DTMODEL="${FK_PROC_DTMODEL:-/proc/device-tree/model}"
PROC_MTD="/proc/mtd"
+USB_DEV=$(lsblk -pr --fs -o NAME,LABEL | awk '/QNAPUSBBOOT/ {print $1}')
read_machine_db() {
if [ -f "${FK_ETC_DB:-/etc/flash-kernel/db}" ]; then
@@ -106,6 +108,10 @@ check_mtd_size() {
local actual_size="$3"
local what="$4"
+ if [ x$USB_DEV != x ] && [ $what = kernel ]; then
+ actual_size=4194300
+ fi
+
if [ $required_size -gt $actual_size ]; then
case $what in
initrd)
@@ -119,6 +125,20 @@ check_mtd_size() {
) >&2
;;
esac
+ if [ $(get_machine_field "$machine" "DTB-Id") = "!kirkwood-qnap" ] && [ x$USB_DEV = x ];then
+ echo
+ echo "kirkwood-qnap found."
+ echo "You can try too load Kernel and initrd from USB drive. Prepare a FAT32 partition with"
+ echo "disklabel 'QNAPUSBBOOT' connect it to the device and then run flash-kernel $kvers"
+ echo
+ echo "WARNING: Not all USB drives are detect by the bootloader. If it is so the device won't start"
+ echo "and you need a serial console to fix it."
+ echo "If you can mount the USB drive there it does NOT indicate the the bootloader will found it."
+ echo "You also need fw_setenv to set the bootargs and bootcmd of u-boot."
+ echo
+ echo "DO IT AT YOUR OWN RISK"
+ echo
+ fi
error "Not enough space for $what in MTD '$mtd_name' (need $required_size but is actually $actual_size)."
fi
}
@@ -397,10 +417,17 @@ flash_kernel() {
use=" (using $kreqsize/$kmtdsize bytes)"
fi
- printf "Flashing kernel$use... " >&2
gen_kernel "$input_file" "$tmpdir/flash_kernel.raw" "$machine_id" || error "failed."
- write_mtd "$tmpdir/flash_kernel.raw" "$output_mtd" || error "failed."
- echo "done." >&2
+ if [ x$USB_DEV != x ]; then
+ printf "Flashing kernel$use to $boot_device... " >&2
+ cp "$tmpdir/flash_kernel.raw" $boot_mnt_dir/kernel || error "failed."
+ echo "done." >&2
+ set_qnap_bootargs
+ else
+ printf "Flashing kernel$use... " >&2
+ write_mtd "$tmpdir/flash_kernel.raw" "$output_mtd" || error "failed."
+ echo "done." >&2
+ fi
}
flash_initrd() {
@@ -413,13 +440,23 @@ flash_initrd() {
use=" (using $ireqsize/$imtdsize bytes)"
fi
- printf "Flashing initramfs$use... " >&2
- {
- cat "$input_file"
- if [ "$pad" -gt 0 ]; then
- dd if=/dev/zero bs="$pad" count=1 2>/dev/null
- fi
- } | write_mtd "-" "$output_mtd" || error "failed."
+ if [ x$USB_DEV != x ]; then
+ printf "Flashing initramfs$use to $boot_device... " >&2
+ {
+ cat "$input_file"
+ if [ "$pad" -gt 0 ]; then
+ dd if=/dev/zero bs="$pad" count=1 2>/dev/null
+ fi
+ } > $boot_mnt_dir/initrd
+ else
+ printf "Flashing initramfs$use... " >&2
+ {
+ cat "$input_file"
+ if [ "$pad" -gt 0 ]; then
+ dd if=/dev/zero bs="$pad" count=1 2>/dev/null
+ fi
+ } | write_mtd "-" "$output_mtd" || error "failed."
+ fi
echo "done." >&2
}
@@ -665,6 +702,18 @@ handle_dtb() {
fi
}
+set_qnap_bootargs (){
+ if [ -f /usr/bin/fw_setenv ] && [ -f /usr/bin/fw_printenv ]; then
+ if [ "x$(fw_printenv | awk -F '=' '/usb start/ {print $1}')" != "xbootcmd" ]; then
+ printf "Set Bootloader to load files from USB...\n"
+ fw_setenv bootargs "console=ttyS0,115200n8 root=/dev/ram rw initrd=0xc00000,0x1500000 ramdisk=34816" >/dev/null || error "failed."
+ fw_setenv bootcmd "uart1 0x68;usb start;fatload usb 0:1 0xc00000 initrd;fatload usb 0:1 0x800000 kernel;bootm 0x800000" >/dev/null || error "failed."
+ fi
+ else
+ error "\nCouldn't find fw_setenv and/or fw_printenv.\nInstall it and run flash-kernel $kvers."
+ fi
+}
+
main() {
force="no"
if [ "x$1" = "x--force" ]; then
@@ -833,6 +882,10 @@ boot_dtb_path_version="$(get_machine_field "$machine" "Boot-DTB-Path-Version")"
boot_multi_path="$(get_machine_field "$machine" "Boot-Multi-Path")" || :
android_boot_device="$(get_machine_field "$machine" "Android-Boot-Device")" || :
+if [ x$USB_DEV != x ]; then
+ boot_device=$USB_DEV
+fi
+
if [ -n "$dtb_append_from" ]; then
if dtb_append_required; then
dtb_append="yes"
Reply to: