Hi All

Attached is a patch that enables flash-kernel to  write APEX to the
NSLU2 flash. It pads the mtdblock with 0xffs (so apex-env works), and
it also preserves any existing APEX configuration environment. I have
tested the patch with apex-1.4.15 and apex-1.5.6 (not yet in Debian).

Assuming that the APEX configuration environment starts at a fixed
offset from the end of the mtdblock, the script could be simplified by
not writing out as many 0xffs to mtdblock2. This method would preserve
the configuration environment. However, apex-env ensures that the
format of the configuration environment is current, which may or may
not be important in the future.

It may be useful to add command line parameters to flash-kernel, to
support only writing APEX or the kernel/initramfs to flash.
Alternatively, it may be useful to create a flash-apex script which
could then be called in the apex-nslu2 postinst script.

I am a relative novice when it comes to scripting, so please make
suggestions for improvements to the code. Once everybody is happy,
I'll commit this version of flash-kernel to SVN.

Gordon

--
Gordon Farquharson
Index: flash-kernel
===================================================================
--- flash-kernel	(revision 47126)
+++ flash-kernel	(working copy)
@@ -44,7 +44,12 @@
 	fi
 }
 
+apex_file=/boot/apex.flash
 
+if [ ! -e $apex_file ]; then
+	error "Can't find $apex_file"
+fi
+
 if [ -n "$1" ]; then
 	kvers="$1"
 	kfile=/boot/vmlinuz-$kvers
@@ -88,6 +93,10 @@
 		if [ -z "$mtdfis" ]; then
 			error "Cannot find mtd FIS directory"
 		fi
+		mtdloader=$(mtdblock Loader)
+		if [ -z "$mtdloader" ]; then
+			error "Cannot find mtd partition 'Loader'"
+		fi
 		mtdkernel=$(mtdblock Kernel)
 		if [ -z "$mtdkernel" ]; then
 			error "Cannot find mtd partition 'Kernel'"
@@ -96,6 +105,30 @@
 		if [ -z "$mtdramdisk" ]; then
 			error "Cannot find mtd partition 'Ramdisk'"
 		fi
+		lsize=$(wc -c $apex_file | awk '{print $1}')
+		mtdblocksize=131072
+		pad=$(expr $mtdblocksize - $lsize - 16)
+		# Store non default APEX configuration
+		tmp=$(tempfile)
+		apex-env printenv | egrep -v '\*=' > $tmp
+		printf "Flashing loader: " >&2
+		(
+			sercomm_header $mtdblocksize
+			nslu2_swap $apex_file
+			perl -e "print pack(\"C\", 0xff) x $pad"
+		) > "$mtdloader" || error "failed."
+		# Write the stored APEX configuration. For each line,
+		# remove whitespace from the start and the end of the
+		# line, and use all the characters, including
+		# whitespace, after '=' as the value.
+		while read line
+		do
+			key=$(echo $line | cut -d '=' -f1 | awk '{print $1}')
+			val=$(echo $line | awk '{$1=""; $2=""; print substr($0,3)}')
+			apex-env setenv "$key" "$val"
+		done < $tmp
+		rm $tmp
+		echo "done." >&2
 		# The following devio magic parses the FIS directory to
 		# obtain the size, offset and name of each partition.  This
 		# used used to obtain the offset of the Kernel partition.

Reply via email to