blob: ee2be93516b3049e013e90349aec86569e17fa91 [file] [log] [blame]
Amaury Pouly3c3e1332017-01-04 16:26:07 +01001#!/bin/bash
Amaury Pouly44bb2852016-11-11 15:40:56 +01002# 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#
9if [ "$#" -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
12fi
13
14FILE="$1"
15IN_TGZ="0"
16FILTER="$2"
17
18# for directories, list all files
19if [ -d "$FILE" ]; then
20 LIST=`find "$FILE"`
21else
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
31fi
32
33# apply user filter
34if [ "$FILTER" != "" ]; then
35 LIST=`echo "$LIST" | grep "$FILTER"`
36fi
37# if file contains icx_nvp_emmc.h, we want that
38if [ "`echo "$LIST" | grep "icx_nvp_emmc.h" | wc -l`" = "1" ]; then
39 LIST=`echo "$LIST" | grep "icx_nvp_emmc.h"`
40else
41 LIST=`echo "$LIST" | grep 'icx[[:digit:]]*_nvp[[:alpha:]_]*.h'`
42fi
43LIST_CNT=`echo "$LIST" | wc -l`
44if [ "$LIST_CNT" = "0" ]; then
45 >&2 echo "No icx nvp file found"
46 exit 1
47elif [ "$LIST_CNT" != "1" ]; then
48 >&2 echo "Several matches for icx nvp:"
49 >&2 echo "$LIST"
50 exit 1
51else
52 FILE="$LIST"
53fi
54
55# if file is in archive, we need to extract it
56if [ "$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"
65else
66 >&2 echo "Analyzing $FILE"
67fi
68
Igor Skochinsky03dd4b92017-04-03 15:13:46 +020069# 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 Pouly44bb2852016-11-11 15:40:56 +010072cat "$FILE" | awk ' \
73BEGIN { \
Igor Skochinsky03dd4b92017-04-03 15:13:46 +020074 expr = "#define[[:space:]]+ICX[[:digit:]]*_NVP_NODE_([[:alnum:]]+)[[:space:]]+(ICX_NVP_NODE_BASE[[:space:]]*\"|\"/dev.*_nvp/)([[:digit:]]+)\"";
Amaury Pouly44bb2852016-11-11 15:40:56 +010075} \
76{ \
77 if($0 ~ expr) \
78 { \
Igor Skochinsky03dd4b92017-04-03 15:13:46 +020079 print(tolower(gensub(expr, "\\1,\\3", "g", $0)));
Amaury Pouly44bb2852016-11-11 15:40:56 +010080 } \
81}'