Get READONLY and PRESERVED flags
Change-Id: I895b2d8ae696ae7eb2e712a8fcc50a357b8fa975
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/generate-squashfs b/generate-squashfs
index f9d9d6d..0eff0ce 100755
--- a/generate-squashfs
+++ b/generate-squashfs
@@ -12,6 +12,8 @@
-h, --help Display this help text and exit.
'
+let ffs_entry_size=128
+let miscflags_offset=112
outfile=`pwd`"/pnor.xz.squashfs"
declare -a partitions=()
tocfile="pnor.toc"
@@ -43,6 +45,12 @@
scratch_dir=`mktemp -d` || exit 1
echo "Parsing PNOR TOC..."
+
+# Needed to get the READONLY and PRESERVED flags
+# TODO: Get READONLY and PRESERVED flags from pflash instead.
+pflash_cmd="pflash --partition=part --read=${scratch_dir}/part -F ${pnorfile}"
+${pflash_cmd} || exit 1
+
{
while read line; do
if [[ $line == "ID="* ]]; then
@@ -57,12 +65,23 @@
flags+=",${flag//[\[\]]/}"
done
+ id=${fields[0]##*=}
+ offset=$((${ffs_entry_size} * 10#${id} + ${miscflags_offset}))
+ miscflags=0x$(xxd -p -l 0x1 -seek ${offset} ${scratch_dir}/part)
+ if ((miscflags & 0x80)); then
+ flags+=",PRESERVED"
+ fi
+ if ((miscflags & 0x40)); then
+ flags+=",READONLY"
+ fi
+
# Need the partition ID, name, start location, end location, and flags
- echo "partition${fields[0]##*=}=${fields[1]},${fields[2]/../,}${flags}"
+ echo "partition${id}=${fields[1]},${fields[2]/../,}${flags}"
+
# Save the partition name
partitions+=(${fields[1]})
fi
- done < <(pflash --info -F ${pnorfile})
+ done < <(pflash --info -F ${pnorfile} | grep -v -i "part")
} > ${scratch_dir}/${tocfile}
for partition in "${partitions[@]}"; do