From 778b5d49d1619125223260ad5363913b8a144edb Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 30 Oct 2014 08:08:48 +0100 Subject: mk-flash-layout: correctly detect JFFS2 on NAND devices Contrary to NOR devices, on NAND devices, the JFFS2 signature is written in the out-of-band area. So we have to make use of nanddump to dump the first page and the accompanying OOB data to look for the signature. We only do that on devices which appear as "empty" since it's the only situation where this can happen. --- scripts/mk-flash-layout | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/mk-flash-layout b/scripts/mk-flash-layout index 6017946..a7926d3 100644 --- a/scripts/mk-flash-layout +++ b/scripts/mk-flash-layout @@ -192,6 +192,20 @@ get_image_type() { TPLINK_ROOTFS_LEN=$(( 0x${141}${142}${143}${144} )) fi + # an "empty" MTD can be a JFFS2-formated NAND where the JFFS2 + # clean marker is on the OOB data. It can be either complete + # anywhere on the OOB data, or truncated to magic only on the + # last two bytes for small OOB blocks. + if [ -z "$vol" -a "$REPLY" = "empty" ]; then + set -- $(nanddump --oob -p --bb=padbad -l 1 /dev/mtd4 2>/dev/null |grep OOB|cut -f2 -d:) + if [ -n "$*" ]; then + set -- " $* " + if [ -z "${1##* 85 19 03 20 *}" -o -z "${1##* 19 85 20 03 *}" -o -z "${1##* 19 85 }" -o -z "${1##* 85 19 } " ]; then + REPLY="jffs2" + fi + fi + fi + # maintain a copy of the last known MTD block device if any if [ -z "$vol" ] && \ [ "$REPLY" = "fat" -o "$REPLY" = "jffs2" -o "$REPLY" = "ext2" ]; then -- 1.7.12.1