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_header.sh /path/to/icx_nvp.h |
| 4 | # parse_header.sh /path/to/linux/source [file] |
| 5 | # parse_header.sh /path/to/linux.tgz [file] |
| 6 | # the optional argument is an additional filter when there are several matches |
| 7 | # and is an argument to grep |
| 8 | # |
| 9 | if [ "$#" -lt 1 ]; then |
| 10 | >&2 echo "usage: parse_header.sh /path/to/icx_nvp.h|/path/to/kernel/source|/path/to/kernel.tgz [filter]" |
| 11 | exit 1 |
| 12 | fi |
| 13 | |
| 14 | FILE="$1" |
| 15 | IN_TGZ="0" |
| 16 | FILTER="$2" |
| 17 | |
| 18 | # for directories, list all files |
| 19 | if [ -d "$FILE" ]; then |
| 20 | LIST=`find "$FILE"` |
| 21 | else |
| 22 | # otherwise try un unpack it using tar, to see if it's an archive |
| 23 | LIST=`tar -tzf "$FILE"` |
| 24 | if [ "$?" == 0 ]; then |
| 25 | IN_TGZ="1" |
| 26 | TGZ="$FILE" |
| 27 | else |
| 28 | # assume the input is just the right file |
| 29 | LIST="$FILE" |
| 30 | fi |
| 31 | fi |
| 32 | |
| 33 | # apply user filter |
| 34 | if [ "$FILTER" != "" ]; then |
| 35 | LIST=`echo "$LIST" | grep "$FILTER"` |
| 36 | fi |
| 37 | # if file contains icx_nvp_emmc.h, we want that |
| 38 | if [ "`echo "$LIST" | grep "icx_nvp_emmc.h" | wc -l`" = "1" ]; then |
| 39 | LIST=`echo "$LIST" | grep "icx_nvp_emmc.h"` |
| 40 | else |
| 41 | LIST=`echo "$LIST" | grep 'icx[[:digit:]]*_nvp[[:alpha:]_]*.h'` |
| 42 | fi |
| 43 | LIST_CNT=`echo "$LIST" | wc -l` |
| 44 | if [ "$LIST_CNT" = "0" ]; then |
| 45 | >&2 echo "No icx nvp file found" |
| 46 | exit 1 |
| 47 | elif [ "$LIST_CNT" != "1" ]; then |
| 48 | >&2 echo "Several matches for icx nvp:" |
| 49 | >&2 echo "$LIST" |
| 50 | exit 1 |
| 51 | else |
| 52 | FILE="$LIST" |
| 53 | fi |
| 54 | |
| 55 | # if file is in archive, we need to extract it |
| 56 | if [ "$IN_TGZ" = "1" ]; then |
| 57 | >&2 echo "Extracting $FILE from $TGZ" |
| 58 | TMP=`mktemp` |
| 59 | tar -Ozxf "$TGZ" "$FILE" > $TMP |
| 60 | if [ "$?" != 0 ]; then |
| 61 | >&2 echo "Extraction failed" |
| 62 | exit 1 |
| 63 | fi |
| 64 | FILE="$TMP" |
| 65 | else |
| 66 | >&2 echo "Analyzing $FILE" |
| 67 | fi |
| 68 | |
Igor Skochinsky | 03dd4b9 | 2017-04-03 15:13:46 +0200 | [diff] [blame^] | 69 | # old format: #define ICX1087_NVP_NODE_APP "/dev/icx1087_nvp/0" |
| 70 | # new format: #define ICX_NVP_NODE_APP ICX_NVP_NODE_BASE "0" |
| 71 | |
Amaury Pouly | 44bb285 | 2016-11-11 15:40:56 +0100 | [diff] [blame] | 72 | cat "$FILE" | awk ' \ |
| 73 | BEGIN { \ |
Igor Skochinsky | 03dd4b9 | 2017-04-03 15:13:46 +0200 | [diff] [blame^] | 74 | expr = "#define[[:space:]]+ICX[[:digit:]]*_NVP_NODE_([[:alnum:]]+)[[:space:]]+(ICX_NVP_NODE_BASE[[:space:]]*\"|\"/dev.*_nvp/)([[:digit:]]+)\""; |
Amaury Pouly | 44bb285 | 2016-11-11 15:40:56 +0100 | [diff] [blame] | 75 | } \ |
| 76 | { \ |
| 77 | if($0 ~ expr) \ |
| 78 | { \ |
Igor Skochinsky | 03dd4b9 | 2017-04-03 15:13:46 +0200 | [diff] [blame^] | 79 | print(tolower(gensub(expr, "\\1,\\3", "g", $0))); |
Amaury Pouly | 44bb285 | 2016-11-11 15:40:56 +0100 | [diff] [blame] | 80 | } \ |
| 81 | }' |