summaryrefslogtreecommitdiff
path: root/utils/nwztools/database/nvp/parse_nvp_header.sh
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-11-11 15:40:56 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2016-11-11 16:07:14 +0100
commit44bb2856a59be53ef5ede154a39c54a59b1cc6d0 (patch)
treece343ecff309d6d0172ea56946a9ce679329b250 /utils/nwztools/database/nvp/parse_nvp_header.sh
parent19de536ce2f3c8066ca5be9b570f72e5c1e88342 (diff)
downloadrockbox-44bb2856a59be53ef5ede154a39c54a59b1cc6d0.tar.gz
rockbox-44bb2856a59be53ef5ede154a39c54a59b1cc6d0.zip
nwztools/database: add database of information on Sony NWZ linux players
There must be an evil genius in Sony's Walkman division. Someone who made sure that each model is close enough to the previous one so that little code is needed but different enough so that an educated guess is not enough. Each linux-based Sony player has a model ID (mid) which is a 32-bit integer. I was able to extract a list of all model IDs and the correspoding name of the player (see README). This gives us 1) a nice list of all players (because NWZ-A729 vs NWZ-A729B, really Sony?) 2) an easy way to find the name of player programatically. It seems that the lower 8-bit of the model ID gives the storage size but don't bet your life on it. The remaining bytes seem to follow some kind of pattern but there are exceptions. From this list, I was able to build a list of all Sony's series (up to quite recent one). The only safe way to build that is by hand, with a list of series, each series having a list of model IDs. The notion of series is very important because all models in a series share the same firmware. A very important concept on Sony's players is the NVP, an area of the flash that stores data associated with keys. The README contains more information but basically this is where is record the model ID, the destination, the boot flags, the firmware upgrade flags, the boot image, the DRM keys, and a lot of other stuff. Of course Sony decided to slightly tweak the index of the keys regularly over time which means that each series has a potentially different map, and we need this map to talk to the NVP driver. Fortunately, Sony distributes the kernel for all its players and they contain a kernel header with this information. I wrote a script to unpack kernel sources and parse this header, producing a bunch of nw-*.txt files, included in this commit. This map is very specific though: it maps Sony's 3-letter names (bti) to indexes (1). This is not very useful without the decription (bti = boot image) and its size (262144). This information is harder to come by, and is only stored in one place: if icx_nvp_emmc.ko drivers, found on the device. Fortunately, Sony distributes a number of firmware upgrade, that contain the rootfs, than once extracted contain this driver. The driver is a standard ELF files with symbols. I wrote a parsing tool (nvptool) that is able to extract this information from the drivers. Using that, I produced a bunch of nodes-nw*.txt files. A reasonable assumption is that nodes meaning and size do not change over time (bti is always the boot image and is always 262144 bytes), so by merging a few of those file, we can get a complete picture (note that some nodes that existed in older player do not exists anymore so we really need to merge several ones from different generations). The advantage of storing all this information in plain text files, is that it now makes it easy to parse it and produce whatever format we want to use it. I wrote a python script that parses all this mess and produces a C file and header with all this information (nwz_db.{c,h}). Change-Id: Id790581ddd527d64418fe9e4e4df8e0546117b80
Diffstat (limited to 'utils/nwztools/database/nvp/parse_nvp_header.sh')
-rwxr-xr-xutils/nwztools/database/nvp/parse_nvp_header.sh77
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#
8if [ "$#" -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
11fi
12
13FILE="$1"
14IN_TGZ="0"
15FILTER="$2"
16
17# for directories, list all files
18if [ -d "$FILE" ]; then
19 LIST=`find "$FILE"`
20else
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
30fi
31
32# apply user filter
33if [ "$FILTER" != "" ]; then
34 LIST=`echo "$LIST" | grep "$FILTER"`
35fi
36# if file contains icx_nvp_emmc.h, we want that
37if [ "`echo "$LIST" | grep "icx_nvp_emmc.h" | wc -l`" = "1" ]; then
38 LIST=`echo "$LIST" | grep "icx_nvp_emmc.h"`
39else
40 LIST=`echo "$LIST" | grep 'icx[[:digit:]]*_nvp[[:alpha:]_]*.h'`
41fi
42LIST_CNT=`echo "$LIST" | wc -l`
43if [ "$LIST_CNT" = "0" ]; then
44 >&2 echo "No icx nvp file found"
45 exit 1
46elif [ "$LIST_CNT" != "1" ]; then
47 >&2 echo "Several matches for icx nvp:"
48 >&2 echo "$LIST"
49 exit 1
50else
51 FILE="$LIST"
52fi
53
54# if file is in archive, we need to extract it
55if [ "$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"
64else
65 >&2 echo "Analyzing $FILE"
66fi
67
68cat "$FILE" | awk ' \
69BEGIN { \
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}'