[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: flash-kernel: handle DTBs in vendor subdir



On Sat, 2016-07-30 at 16:52 -0700, Martin Michlmayr wrote:
> DTBs on arm64 are stored as vendor/dtb rather than everything in one
> directory.

I looked at this a while back but it seems I never completed it, or at
least never pushed it :-(.

I've attached the two patches I had sitting in my branch here, they
look sensible but I honestly can't remember what state they are in.

AFAICT the main difference is that they preserve the directory layout
rather than collapsing it. Not sure there is any particular reason to
favour either way of doing it so feel free to either ignore or pickup
these patches.

One thing my patches handles which I'm not sure yours does is the pre-
subdir-transition versions on ARM64, which my commit log says happened
in v3.19-rc1. That might be important for backports and/or upgrades.

Ian.
From 3e9d1e6ea1b52ed282a14ecbdd0616be3f2079ee Mon Sep 17 00:00:00 2001
From: Ian Campbell <ijc@debian.org>
Date: Sun, 28 Feb 2016 12:38:53 +0000
Subject: [PATCH 2/2] Search for DTBs in parent directories

If DTB-Id contains a subdirectory then as well as looking in the named location
also look in the parent directories.

This ensures that where DTBs have been moved by the kernel from the top level
into a subdirectory (as happened for arm64 in v3.19-rc1 when e.g.
apm-mustang.dtb moved to apm/apm-mustang.dtb) that flash-kernel can work with
both old and new kernels.

We search fully in /etc/flash-kernel/dtbs before looking in /usr/lib, so e.g.
we will find /etc/flash-kernel/dtbs/DTB before finding /usr/lib/.../DIR/DTB.
---
 README    |  7 ++++---
 functions | 31 +++++++++++++++++++++++++------
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/README b/README
index 25a6d32..7b9356e 100644
--- a/README
+++ b/README
@@ -117,9 +117,10 @@ The supported fields are:
 
 * DTB-Id: (optional) specifies the name of the DTB file for this device,
   relative to the kernel package DTB dir or /etc/flash-kernel/dtbs. May
-  include a subdirectory. If the value begins with a `!' then the field is a
-  script which should be run.  The script must produce the DTB filename (and
-  nothing else) on stdout.
+  include a subdirectory, if the DTB is not found in the named subdirectory
+  then the parent directories will be searched. If the value begins with a `!'
+  then the field is a script which should be run.  The script must produce the
+  DTB filename (and nothing else) on stdout.
 
 * DTB-Append: (optional) when yes the DTB specified by DTB-Id will be appended
   to the kernel image.
diff --git a/functions b/functions
index 7cf1753..cb8dd70 100644
--- a/functions
+++ b/functions
@@ -552,17 +552,36 @@ android_flash() {
 	echo "done." >&2
 }
 
+search_for_dtb_file_in_prefix() {
+	local prefix=$1
+	local dtbdir=$(dirname "$dtb_name")
+	local dtbfile=$(basename "$dtb_name")
+
+	while true ; do
+		if [ "x$dtbdir" = "x." ] ; then
+			dtbdir=""
+		fi
+		if [ -e "$prefix/$dtbdir/$dtbfile" ] ; then
+			echo "$prefix/$dtbdir/$dtbfile"
+			return 0
+		fi
+		# We've run out of dir prefixes to strip
+		if [ "x$dtbdir" = "x" ] ; then
+			break;
+		fi
+		dtbdir=$(dirname "$dtbdir")
+	done
+	return 1
+}
+
 find_dtb_file() {
 	case "$dtb_name" in
 	/*)
 		echo "$dtb_name"
 		;;
 	*)
-		if [ -e "/etc/flash-kernel/dtbs/$dtb_name" ] ; then
-			echo "/etc/flash-kernel/dtbs/$dtb_name"
-		else
-			echo "/usr/lib/linux-image-$kvers/$dtb_name"
-		fi
+		search_for_dtb_file_in_prefix "/etc/flash-kernel/dtbs" ||
+		search_for_dtb_file_in_prefix "/usr/lib/linux-image-$kvers"
 		;;
 	esac
 }
@@ -604,7 +623,7 @@ handle_dtb() {
 		fi
 	else
 		if [ -e $dtb ]; then
-			echo "Installing $dtb_name into /boot/dtbs/$kvers/$dtb_name" >&2
+			echo "Installing $dtb into /boot/dtbs/$kvers/$dtb_name" >&2
 			mkdir -p /boot/dtbs/$kvers/$dtbdir
 			cp "$dtb" "/boot/dtbs/$kvers/$dtb_name.new"
 			backup_and_install \
-- 
2.8.1

From 5e16bdd278dbc10a1970a0db6c756158dc677c64 Mon Sep 17 00:00:00 2001
From: Ian Campbell <ijc@debian.org>
Date: Sun, 28 Feb 2016 12:14:55 +0000
Subject: [PATCH 1/2] Handle DTB-Id with a subdirectory

In v3.19-rc1 Linux arm64 moved all DTB files into per-vendor subdirectories and
the Debian kernel package has followed suite.

Update the entry for Mustang (the only arm64 platform in the current
flash-kernel database) to add the apm/ prefix and adjust the code which
installs and removes the dtb to cope with subdirectories in this context.
---
 README           | 8 +++++---
 db/all.db        | 2 +-
 debian/changelog | 6 ++++++
 functions        | 8 +++++++-
 4 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/README b/README
index 02ba3fd..25a6d32 100644
--- a/README
+++ b/README
@@ -115,9 +115,11 @@ The supported fields are:
   This option is ignored if a DTB is to be appended, via either DTB-Append or
   DTB-Append-From.
 
-* DTB-Id: (optional) specifies the name of the DTB file for this device. If
-  the value begins with a `!' then the field is a script which should be run.
-  The script must produce the DTB filename (and nothing else) on stdout.
+* DTB-Id: (optional) specifies the name of the DTB file for this device,
+  relative to the kernel package DTB dir or /etc/flash-kernel/dtbs. May
+  include a subdirectory. If the value begins with a `!' then the field is a
+  script which should be run.  The script must produce the DTB filename (and
+  nothing else) on stdout.
 
 * DTB-Append: (optional) when yes the DTB specified by DTB-Id will be appended
   to the kernel image.
diff --git a/db/all.db b/db/all.db
index 645a8a8..065f7ff 100644
--- a/db/all.db
+++ b/db/all.db
@@ -37,7 +37,7 @@ Boot-Kernel-Path: /boot/uImage
 Boot-Initrd-Path: /boot/uInitrd
 Boot-Script-Path: /boot/boot.scr
 Required-Packages: u-boot-tools
-DTB-Id: apm-mustang.dtb
+DTB-Id: apm/apm-mustang.dtb
 
 Machine: Auxtek t003 A10s hdmi tv-stick
 Kernel-Flavors: armmp
diff --git a/debian/changelog b/debian/changelog
index 1b92171..71e5196 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+flash-kernel (3.61) UNRELEASED; urgency=medium
+
+  * Handle DTBs in subdirectories.
+
+ -- Ian Campbell <ijc@debian.org>  Sat, 27 Feb 2016 13:14:05 +0000
+
 flash-kernel (3.60) unstable; urgency=medium
 
   [ Karsten Merker ]
diff --git a/functions b/functions
index 3829828..7cf1753 100644
--- a/functions
+++ b/functions
@@ -573,6 +573,7 @@ handle_dtb() {
 	fi
 
 	local dtb=$(find_dtb_file)
+	local dtbdir=$(dirname "$dtb_name")
 	if [ "x$FK_KERNEL_HOOK_SCRIPT" = "xpostrm.d" ] ; then
 		rm -f "/boot/dtbs/$kvers/$dtb_name"
 
@@ -590,6 +591,11 @@ handle_dtb() {
 			esac
 		fi
 
+		# Remove any subdir which we created
+		while [ "x$dtbdir" != "x." ] && [ -d /boot/dtbs/$kvers/$dtbdir ] ; do
+			rmdir --ignore-fail-on-non-empty /boot/dtbs/$kvers/$dtbdir
+			dtbdir=$(dirname "$dtbdir")
+		done
 		if [ -d /boot/dtbs/$kvers ] ; then
 			rmdir --ignore-fail-on-non-empty /boot/dtbs/$kvers
 		fi
@@ -599,7 +605,7 @@ handle_dtb() {
 	else
 		if [ -e $dtb ]; then
 			echo "Installing $dtb_name into /boot/dtbs/$kvers/$dtb_name" >&2
-			mkdir -p /boot/dtbs/$kvers/
+			mkdir -p /boot/dtbs/$kvers/$dtbdir
 			cp "$dtb" "/boot/dtbs/$kvers/$dtb_name.new"
 			backup_and_install \
 				"/boot/dtbs/$kvers/$dtb_name.new" \
-- 
2.8.1


Reply to: