diff options
Diffstat (limited to 'utils/nwztools/database/nvp/parse_nvp_header.sh')
-rwxr-xr-x | utils/nwztools/database/nvp/parse_nvp_header.sh | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/utils/nwztools/database/nvp/parse_nvp_header.sh b/utils/nwztools/database/nvp/parse_nvp_header.sh new file mode 100755 index 0000000000..853df93557 --- /dev/null +++ b/utils/nwztools/database/nvp/parse_nvp_header.sh | |||
@@ -0,0 +1,77 @@ | |||
1 | # usage | ||
2 | # parse_header.sh /path/to/icx_nvp.h | ||
3 | # parse_header.sh /path/to/linux/source [file] | ||
4 | # parse_header.sh /path/to/linux.tgz [file] | ||
5 | # the optional argument is an additional filter when there are several matches | ||
6 | # and is an argument to grep | ||
7 | # | ||
8 | if [ "$#" -lt 1 ]; then | ||
9 | >&2 echo "usage: parse_header.sh /path/to/icx_nvp.h|/path/to/kernel/source|/path/to/kernel.tgz [filter]" | ||
10 | exit 1 | ||
11 | fi | ||
12 | |||
13 | FILE="$1" | ||
14 | IN_TGZ="0" | ||
15 | FILTER="$2" | ||
16 | |||
17 | # for directories, list all files | ||
18 | if [ -d "$FILE" ]; then | ||
19 | LIST=`find "$FILE"` | ||
20 | else | ||
21 | # otherwise try un unpack it using tar, to see if it's an archive | ||
22 | LIST=`tar -tzf "$FILE"` | ||
23 | if [ "$?" == 0 ]; then | ||
24 | IN_TGZ="1" | ||
25 | TGZ="$FILE" | ||
26 | else | ||
27 | # assume the input is just the right file | ||
28 | LIST="$FILE" | ||
29 | fi | ||
30 | fi | ||
31 | |||
32 | # apply user filter | ||
33 | if [ "$FILTER" != "" ]; then | ||
34 | LIST=`echo "$LIST" | grep "$FILTER"` | ||
35 | fi | ||
36 | # if file contains icx_nvp_emmc.h, we want that | ||
37 | if [ "`echo "$LIST" | grep "icx_nvp_emmc.h" | wc -l`" = "1" ]; then | ||
38 | LIST=`echo "$LIST" | grep "icx_nvp_emmc.h"` | ||
39 | else | ||
40 | LIST=`echo "$LIST" | grep 'icx[[:digit:]]*_nvp[[:alpha:]_]*.h'` | ||
41 | fi | ||
42 | LIST_CNT=`echo "$LIST" | wc -l` | ||
43 | if [ "$LIST_CNT" = "0" ]; then | ||
44 | >&2 echo "No icx nvp file found" | ||
45 | exit 1 | ||
46 | elif [ "$LIST_CNT" != "1" ]; then | ||
47 | >&2 echo "Several matches for icx nvp:" | ||
48 | >&2 echo "$LIST" | ||
49 | exit 1 | ||
50 | else | ||
51 | FILE="$LIST" | ||
52 | fi | ||
53 | |||
54 | # if file is in archive, we need to extract it | ||
55 | if [ "$IN_TGZ" = "1" ]; then | ||
56 | >&2 echo "Extracting $FILE from $TGZ" | ||
57 | TMP=`mktemp` | ||
58 | tar -Ozxf "$TGZ" "$FILE" > $TMP | ||
59 | if [ "$?" != 0 ]; then | ||
60 | >&2 echo "Extraction failed" | ||
61 | exit 1 | ||
62 | fi | ||
63 | FILE="$TMP" | ||
64 | else | ||
65 | >&2 echo "Analyzing $FILE" | ||
66 | fi | ||
67 | |||
68 | cat "$FILE" | awk ' \ | ||
69 | BEGIN { \ | ||
70 | expr = "#define[[:space:]]+ICX_NVP_NODE_([[:alnum:]]+)[[:space:]]+ICX_NVP_NODE_BASE[[:space:]]*\"([[:digit:]]+)\""; \ | ||
71 | } \ | ||
72 | { \ | ||
73 | if($0 ~ expr) \ | ||
74 | { \ | ||
75 | print(tolower(gensub(expr, "\\1,\\2", "g", $0))); | ||
76 | } \ | ||
77 | }' | ||