flash-kernel with custom kernels

Pascal Bourguignon pjb at informatimago.com
Thu Oct 21 09:45:03 UTC 2021


Hello,


When we have custom kernels whose version don't match exactly the 
expected format:

     root at rpi4:~# linux-version list
     5.10.25-uwb+
     5.11.0-1017-raspi
     5.11.0-1019-raspi
     5.11.0-1021-raspi
     5.13.0-1008-raspi


flash-kernel fails with this error:

     Setting up flash-kernel (3.104ubuntu5)
     Using DTB: bcm2711-rpi-4-b.dtb
     Couldn't find DTB bcm2711-rpi-4-b.dtb on the following paths: 
/etc/flash-kernel/dtbs /usr/lib/linux-image- /lib/firmware//device-tree/
     Installing  into /boot/dtbs//./bcm2711-rpi-4-b.dtb
     cp: cannot stat '': No such file or directory
     dpkg: error processing package flash-kernel (--configure):
      installed flash-kernel package post-installation script subprocess 
returned error exit status 1


Here is a patch on /usr/share/flash-kernel/functions to better deal with 
this situation.


Note: is there a git repository where ubuntu flash-kernel is stored?
(It's quite different from the debian one, it seems)

-- 
__Pascal Bourguignon__
-------------- next part --------------
--- functions.old	2021-10-21 09:23:20.391736393 +0200
+++ functions.new	2021-10-20 17:31:06.441033565 +0200
@@ -27,6 +27,8 @@
 PROC_DTMODEL="${FK_PROC_DTMODEL:-/proc/device-tree/model}"
 PROC_MTD="/proc/mtd"
 
+kvers="none"
+
 read_machine_db() {
 	if [ -f "${FK_ETC_DB:-/etc/flash-kernel/db}" ]; then
 		cat "${FK_ETC_DB:-/etc/flash-kernel/db}"
@@ -244,6 +246,7 @@
 }
 
 get_dtb_name() {
+	local kvers="$1"
 	local field="$(get_machine_field "$machine" "DTB-Id")" || :
 	case "$field" in
 	!*)
@@ -734,6 +737,8 @@
 			# could use cur_flav=$(get_kfile_suffix "$cur_uname")
 			# but this is much faster.
 			cur_flav=${cur_uname#*-*-}
+			cur_flav=${cur_flav#*-}
+			cur_flav=${cur_flav%+}
 			for allowed_flav in "$@"; do
 				if [ "${cur_flav}" = "${allowed_flav}" ]; then
 					echo "$cur_uname"
@@ -745,6 +750,7 @@
 }
 
 find_dtb_file() {
+	local kvers="$1"
 	local dtb path
 	case "$dtb_dir" in
 	/*)
@@ -803,6 +809,7 @@
 }
 
 handle_dtb() {
+	local kvers="$1"
 	if [ "x$dtb_name" = "x" ]; then
 		return
 	fi
@@ -834,7 +841,7 @@
 			rmdir --ignore-fail-on-non-empty /boot/dtbs
 		fi
 	else
-		local dtb=$(find_dtb_file)
+		local dtb=$(find_dtb_file "$kvers")
 		echo "Installing $dtb into $dtbfile" >&2
 		mkdir -p "/boot/dtbs/$kvers/$dtb_dir"
 		cp "$dtb" "$dtbfile.new"
@@ -889,11 +896,11 @@
 
 kvers="$1"
 
-get_dtb_name
+get_dtb_name "$kvers"
 
 # Install/remove any DTB from postinst, regardless of version
 if [ -n "$kvers" ] ; then
-	handle_dtb
+	handle_dtb "$kvers"
 fi
 
 # if get_machine_field returns non-zero, then all flavors are allowed
@@ -902,6 +909,7 @@
 	kflavors="any"
 fi
 latest_version=$(linux-version list | include_only_flavors $kflavors | linux-version sort | tail -1)
+echo "latest_version=$latest_version kflavors=$kflavors"
 
 if [ -n "$kvers" ] && [ "$FK_KERNEL_HOOK_SCRIPT" = "postrm.d" ]; then
 	echo "flash-kernel: Kernel ${kvers} has been removed." >&2
@@ -930,7 +938,7 @@
 	fi
 	kvers="$latest_version"
 	# Make sure we install the DTB for $latest_version
-	handle_dtb
+	handle_dtb "$kvers"
 fi
 
 # accumulate multiple calls in a trigger to only run flash-kernel once; the
@@ -1126,7 +1134,7 @@
 		kernel="$kfile"
 		initrd="$ifile"
 		if [ "$dtb_append" = "yes" ]; then
-			dtb=$(find_dtb_file)
+			dtb=$(find_dtb_file "$kvers")
 			append_dtb "$kernel" "$dtb" "$tmpdir/kernel"
 			kernel="$tmpdir/kernel"
 		elif [ -n "$machine_id" ]; then
@@ -1154,7 +1162,7 @@
 		    # Write tmp file in same filesystem as final destination
 		    fit_tmp="$boot_fit_path".tmp
 		    mkimage_fit "$boot_its_file_name" "$fit_tmp" \
-				"$kfile" "$ifile" "$(find_dtb_file)"
+				"$kfile" "$ifile" "$(find_dtb_file "$kvers")"
 		    backup_and_install "$fit_tmp" "$boot_fit_path"
 		fi
 		if [ -n "$boot_device" ]; then
@@ -1219,7 +1227,7 @@
 			if [ "$boot_dtb_path_version" = "yes" ]; then
 				boot_dtb_path="${boot_dtb_path}-${kvers}"
 			fi
-			boot_dtb=$(find_dtb_file)
+			boot_dtb=$(find_dtb_file "$kvers")
 			dtb="$tmpdir/dtb"
 			cp "$boot_dtb" "$dtb"
 			backup_and_install "$dtb" "$boot_dtb_path"



More information about the Ubuntu-devel-discuss mailing list