Amaury Pouly | 3c3e133 | 2017-01-04 16:26:07 +0100 | [diff] [blame] | 1 | #!/bin/bash |
Amaury Pouly | 44bb285 | 2016-11-11 15:40:56 +0100 | [diff] [blame] | 2 | # 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 Skochinsky | 03dd4b9 | 2017-04-03 15:13:46 +0200 | [diff] [blame^] | 7 | if [ -z "$NVP_LOG" ]; then |
| 8 | NVP_LOG=/dev/null |
| 9 | fi |
Amaury Pouly | 44bb285 | 2016-11-11 15:40:56 +0100 | [diff] [blame] | 10 | if [ "$#" -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 |
| 13 | fi |
| 14 | |
| 15 | FILE="$1" |
| 16 | IN_TGZ="0" |
| 17 | OUTPUT="$2" |
| 18 | |
| 19 | # for directories, list all files |
| 20 | if [ -d "$FILE" ]; then |
| 21 | LIST=`find "$FILE"` |
| 22 | else |
| 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 |
| 32 | fi |
| 33 | |
| 34 | # look for icx_nvp_emmc.ko |
| 35 | LIST=`echo "$LIST" | grep "icx[[:digit:]]*_nvp[[:alpha:]_]*.ko"` |
| 36 | LIST_CNT=`echo "$LIST" | wc -l` |
| 37 | if [ "$LIST" == "" ]; then |
| 38 | >&2 echo "No icx nvp file found" |
| 39 | exit 1 |
| 40 | elif [ "$LIST_CNT" != "1" ]; then |
| 41 | >&2 echo "Several matches for icx nvp:" |
| 42 | >&2 echo "$LIST" |
| 43 | exit 1 |
| 44 | else |
| 45 | FILE="$LIST" |
| 46 | fi |
| 47 | |
| 48 | # if file is in archive, we need to extract it |
| 49 | if [ "$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" |
| 58 | else |
| 59 | >&2 echo "Analyzing $FILE" |
| 60 | fi |
| 61 | |
Igor Skochinsky | 03dd4b9 | 2017-04-03 15:13:46 +0200 | [diff] [blame^] | 62 | ./nvptool -x "$FILE" -o "$OUTPUT" >"$NVP_LOG" |