From 3edb55143defd1bf3a53838359605c1222b9dd53 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
Date: Tue, 14 Apr 2015 20:50:59 +0000
Subject: [PATCH] bcm53xx: add (disabled) support for upgrading kernel during
 sysupgrade
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

SVN-Revision: 45445
---
 .../bcm53xx/base-files/lib/upgrade/platform.sh  | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh b/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh
index 876da4d6f8..034fb8e6b8 100644
--- a/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/bcm53xx/base-files/lib/upgrade/platform.sh
@@ -150,6 +150,23 @@ platform_pre_upgrade() {
 
 	echo "Provided firmware contains kernel and UBI image, but flashing it is unsupported yet"
 	exit 1
+
+	# Prepare TRX file with just a kernel that will replace current one
+	local linux_length=$(grep "\"linux\"" /proc/mtd | sed "s/mtd[0-9]*:[ \t]*\([^ \t]*\).*/\1/")
+	[ -z "$linux_length" ] && {
+		echo "Unable to find \"linux\" partition size"
+		exit 1
+	}
+	linux_length=$((0x$linux_length + 28))
+	rm -f /tmp/null.bin
+	rm -f /tmp/kernel.trx
+	touch /tmp/null.bin
+	otrx create /tmp/kernel.trx \
+		-f $dir/kernel -b $linux_length \
+		-f /tmp/null.bin
+
+	# Flash
+	mtd write /tmp/kernel.trx firmware
 }
 
 platform_do_upgrade() {
-- 
2.30.2