Bug#680900: flash-kernel: support for local overrides of db settings
On Mon, 2012-07-09 at 01:47 +0100, Ian Campbell wrote:
> I'll also attach the patches shortly.
Attached.
Ian.
>From a347fdef1c79fb1cfd75a8fc6f7f778dddbbadd1 Mon Sep 17 00:00:00 2001
From: Ian Campbell <ian.campbell@citrix.com>
Date: Sun, 8 Jul 2012 21:28:04 +0000
Subject: [PATCH 1/2] Turn code which reads machine db into a function
No functional change yet.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
functions | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/functions b/functions
index df00a86..a132b8b 100644
--- a/functions
+++ b/functions
@@ -19,11 +19,14 @@
# USA.
BOOTSCRIPTS_DIR="${FK_CHECKOUT:-$FK_DIR}/bootscript"
-MACHINE_DB="$(cat "${FK_CHECKOUT:-$FK_DIR}/db/"*.db)"
PROC_CPUINFO="${FK_PROC_CPUINFO:-/proc/cpuinfo}"
PROC_DTMODEL="${FK_PROC_DRMODEL:-/proc/device-tree/model}"
PROC_MTD="/proc/mtd"
+read_machine_db() {
+ cat "${FK_CHECKOUT:-$FK_DIR}/db/"*.db
+}
+MACHINE_DB="$(read_machine_db)"
error() {
echo "$@" >&2
--
1.7.9.1
>From c355495ef7052ac2c309dfe45eff4d657d3aff16 Mon Sep 17 00:00:00 2001
From: Ian Campbell <ian.campbell@citrix.com>
Date: Sun, 8 Jul 2012 22:49:21 +0000
Subject: [PATCH 2/2] Add capability to read /etc/flash-kernel/db to override
db entries.
---
README | 4 ++++
debian/changelog | 3 ++-
debian/flash-kernel.install | 1 +
etc/db | 7 +++++++
functions | 3 +++
test_functions | 26 ++++++++++++++++++++++++++
6 files changed, 43 insertions(+), 1 deletions(-)
create mode 100644 etc/db
diff --git a/README b/README
index 81b65d2..dd76db0 100644
--- a/README
+++ b/README
@@ -77,6 +77,10 @@ RFC 2822 data or Debian control data, i.e. header: value pairs,
with definitions separated by an empty line. Comments starting with a
pound are ignored.
+/etc/flash-kernel/db is parsed first and allows for local override of any
+field. Note that you must include the "Machine" field here as well as the
+field(s) to be overridden
+
The supported fields are:
* Machine: (required) value of the "Hardware:" line in /proc/cpuinfo and
diff --git a/debian/changelog b/debian/changelog
index 5fd4f99..9edf023 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,7 @@
flash-kernel (3.2~exp.1) UNRELEASED; urgency=low
- *
+ [ Ian Campbell ]
+ * Add capability to read /etc/flash-kernel/db to override db entries.
-- Hector Oron <zumbi@debian.org> Sun, 08 Jul 2012 03:09:46 +0200
diff --git a/debian/flash-kernel.install b/debian/flash-kernel.install
index 7191f6d..e223277 100644
--- a/debian/flash-kernel.install
+++ b/debian/flash-kernel.install
@@ -1,6 +1,7 @@
initramfs-hook/flash-kernel etc/initramfs/post-update.d
kernel-hook/zz-flash-kernel etc/kernel/postinst.d
kernel-hook/zz-flash-kernel etc/kernel/postrm.d
+etc/db etc/flash-kernel
flash-kernel usr/sbin
initramfs-tools usr/share
bootscript usr/share/flash-kernel
diff --git a/etc/db b/etc/db
new file mode 100644
index 0000000..62422a9
--- /dev/null
+++ b/etc/db
@@ -0,0 +1,7 @@
+# To override fields include the Machine field and the fields you wish to
+# override.
+#
+# e.g. to override Boot-Device on the Dreamplug to sdb rather than sda
+#
+#Machine: Globalscale Technologies Dreamplug
+#Boot-Device: /dev/sdb1
diff --git a/functions b/functions
index a132b8b..fc96dd0 100644
--- a/functions
+++ b/functions
@@ -24,6 +24,9 @@ PROC_DTMODEL="${FK_PROC_DRMODEL:-/proc/device-tree/model}"
PROC_MTD="/proc/mtd"
read_machine_db() {
+ if [ -f "${FK_ETC_DB:-/etc/flash-kernel/db}" ] ; then
+ cat "${FK_ETC_DB:-/etc/flash-kernel/db}"
+ fi
cat "${FK_CHECKOUT:-$FK_DIR}/db/"*.db
}
MACHINE_DB="$(read_machine_db)"
diff --git a/test_functions b/test_functions
index 6f3fbe8..be29f29 100755
--- a/test_functions
+++ b/test_functions
@@ -239,6 +239,32 @@ test_get_machine_field() {
}
add_test test_get_machine_field
+test_etc_db() {
+ get_tempfile
+ mock_etc_db="$last_tempfile"
+ cat >"$mock_etc_db" <<EOF
+Machine: Marvell SheevaPlug Reference Board
+Kernel-Flavors: Dummy
+EOF
+
+ (
+ FK_ETC_DB="$mock_etc_db"
+ . "$functions"
+ machine="Marvell SheevaPlug Reference Board"
+ kflavors=$(get_machine_field "$machine" "Kernel-Flavors")
+ if [ "$kflavors" != "Dummy" ] ; then
+ echo "Expected Kernel-Flavors field to be overridden to Dummy but got $kflavors" >&2
+ exit 1
+ fi
+ kaddress=$(get_machine_field "$machine" "U-Boot-Kernel-Address")
+ if [ "$kaddress" != "0x00008000" ] ; then
+ echo "Expected U-Boot-Kernel-Address to be 0x00008000 but got $kaddress" >&2
+ exit 1
+ fi
+ )
+}
+add_test test_etc_db
+
test_machine_uses_flash() {
(
. "$functions"
--
1.7.9.1
Reply to: