Simple make recipe for nand devices

I came up with this recipe for the gl-b3000 but it turned out i couldn't use it due to uboot and bootscript related issues. It should work as a generic recipe for most nand devices .. any device ubi capable.

[target].mk

$(call Device/UbiFit)
...
IMAGES := factory.bin
IMAGE/factory.bin = append-ubi | append-metadata
...

platform.sh

...
do_ubi_upgrade() {
	echo -n "ubi: Removing Metadata Trailer from the UBI Volume ... "

	local metadata=$(fwtool -q -t -i /dev/null "$1")
	if [ -s $1 ]; then
		echo "[ OK ]"
		echo "ubi-meta: Successfully Removed Metadata from UBI Volume"
		echo "ubi: Proceeding with sysupgrade .."
		nand_do_upgrade "$1"
		return
	fi
	echo "[ FAILED ] !!"
	echo "ubi-meta: Cannot remove Metadata, the Files is Empty !!"
	echo "ERROR: Failed to Remove Metadata Trailer from UBI Volume !!"
	echo "ubi: Terminating sysupgrade .."
	exit 1
}

...

platform_do_upgrade() {
	case "$(board_name)" in
	<boardname>)

		...

        type="$(identify_magic_long $(get_magic_long "$1"))"
		case "$type" in
		ubi)
			do_ubi_upgrade $1
			;;

        ...

this is part of a full blown solution for my device so i will need to be reconsidered when implimenting for your own device. But aside from the wordy example, all that is really needed, is to strip the metadata before passing the image to "nand_do_upgrade".

this is done in one line ..

local metadata=$(fwtool -q -t -i /dev/null "$1")

everything else is at your discretion as to how you want to implement it .

just to recap the necessary parts ...
[target].mk

$(call Device/UbiFit)

IMAGES := factory.bin
IMAGE/factory.bin = append-ubi | append-metadata

platform.sh

local metadata=$(fwtool -q -t -i /dev/null "$1")

I'd hate to see it go to waste

2 Likes