blob: 8fc4367a8feed9e9dbcde521bc128894a8e01ee5 [file] [log] [blame]
Amaury Pouly3c3e1332017-01-04 16:26:07 +01001#!/bin/bash
Amaury Pouly44bb2852016-11-11 15:40:56 +01002# usage
3# parse_nodes.sh /path/to/icx_nvp_emmc.ko output_file
4# parse_nodes.sh /path/to/rootfs/dir output_file
5# parse_nodes.sh /path/to/rootfs.tgz output_file
6#
Igor Skochinsky03dd4b92017-04-03 15:13:46 +02007if [ -z "$NVP_LOG" ]; then
8 NVP_LOG=/dev/null
9fi
Amaury Pouly44bb2852016-11-11 15:40:56 +010010if [ "$#" -lt 2 ]; then
11 >&2 echo "usage: parse_header.sh /path/to/icx_nvp.ko|/path/to/rootfs/dir|/path/to/rootfs.tgz output_file"
12 exit 1
13fi
14
15FILE="$1"
16IN_TGZ="0"
17OUTPUT="$2"
18
19# for directories, list all files
20if [ -d "$FILE" ]; then
21 LIST=`find "$FILE"`
22else
23 # otherwise try un unpack it using tar, to see if it's an archive
24 LIST=`tar -tzf "$FILE"`
25 if [ "$?" == 0 ]; then
26 IN_TGZ="1"
27 TGZ="$FILE"
28 else
29 # assume the input is just the right file
30 LIST="$FILE"
31 fi
32fi
33
34# look for icx_nvp_emmc.ko
35LIST=`echo "$LIST" | grep "icx[[:digit:]]*_nvp[[:alpha:]_]*.ko"`
36LIST_CNT=`echo "$LIST" | wc -l`
37if [ "$LIST" == "" ]; then
38 >&2 echo "No icx nvp file found"
39 exit 1
40elif [ "$LIST_CNT" != "1" ]; then
41 >&2 echo "Several matches for icx nvp:"
42 >&2 echo "$LIST"
43 exit 1
44else
45 FILE="$LIST"
46fi
47
48# if file is in archive, we need to extract it
49if [ "$IN_TGZ" = "1" ]; then
50 >&2 echo "Extracting $FILE from $TGZ"
51 TMP=`mktemp`
52 tar -Ozxf "$TGZ" "$FILE" > $TMP
53 if [ "$?" != 0 ]; then
54 >&2 echo "Extraction failed"
55 exit 1
56 fi
57 FILE="$TMP"
58else
59 >&2 echo "Analyzing $FILE"
60fi
61
Igor Skochinsky03dd4b92017-04-03 15:13:46 +020062./nvptool -x "$FILE" -o "$OUTPUT" >"$NVP_LOG"