summaryrefslogtreecommitdiff
path: root/utils/nwztools/database/nvp
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
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')
-rw-r--r--utils/nwztools/database/nvp/Makefile26
-rw-r--r--utils/nwztools/database/nvp/README67
-rw-r--r--utils/nwztools/database/nvp/nodes-nwz-a10.txt89
-rw-r--r--utils/nwztools/database/nvp/nodes-nwz-a20.txt89
-rw-r--r--utils/nwztools/database/nvp/nodes-nwz-a820.txt0
-rw-r--r--utils/nwztools/database/nvp/nodes-nwz-a860.txt89
-rw-r--r--utils/nwztools/database/nvp/nodes-nwz-e450.txt78
-rw-r--r--utils/nwztools/database/nvp/nodes-nwz-e460.txt89
-rw-r--r--utils/nwztools/database/nvp/nodes-nwz-e580.txt88
-rw-r--r--utils/nwztools/database/nvp/nodes-nwz-zx100.txt89
-rw-r--r--utils/nwztools/database/nvp/nvptool.cpp754
-rw-r--r--utils/nwztools/database/nvp/nw-a30.txt92
-rw-r--r--utils/nwztools/database/nvp/nw-e060.txt90
-rw-r--r--utils/nwztools/database/nvp/nw-e080.txt89
-rw-r--r--utils/nwztools/database/nvp/nw-s780.txt89
-rw-r--r--utils/nwztools/database/nvp/nwz-a10.txt90
-rw-r--r--utils/nwztools/database/nvp/nwz-a20.txt90
-rw-r--r--utils/nwztools/database/nvp/nwz-a850.txt79
-rw-r--r--utils/nwztools/database/nvp/nwz-a860.txt90
-rw-r--r--utils/nwztools/database/nvp/nwz-e350.txt79
-rw-r--r--utils/nwztools/database/nvp/nwz-e450.txt79
-rw-r--r--utils/nwztools/database/nvp/nwz-e460.txt90
-rw-r--r--utils/nwztools/database/nvp/nwz-e470.txt87
-rw-r--r--utils/nwztools/database/nvp/nwz-e580.txt89
-rw-r--r--utils/nwztools/database/nvp/nwz-s760.txt90
-rw-r--r--utils/nwztools/database/nvp/nwz-zx100.txt90
-rw-r--r--utils/nwztools/database/nvp/nwz-zx2.txt90
-rwxr-xr-xutils/nwztools/database/nvp/parse_all_nvp_headers.sh33
-rwxr-xr-xutils/nwztools/database/nvp/parse_all_nvp_nodes.sh32
-rwxr-xr-xutils/nwztools/database/nvp/parse_nvp_header.sh77
-rwxr-xr-xutils/nwztools/database/nvp/parse_nvp_nodes.sh58
31 files changed, 3061 insertions, 0 deletions
diff --git a/utils/nwztools/database/nvp/Makefile b/utils/nwztools/database/nvp/Makefile
new file mode 100644
index 0000000000..d12bcb3451
--- /dev/null
+++ b/utils/nwztools/database/nvp/Makefile
@@ -0,0 +1,26 @@
1DEFINES=
2CC=gcc
3CXX=g++
4LD=g++
5PROFILE=
6CFLAGS=-g $(PROFILE) -std=c99 -W -Wall $(DEFINES) `xml2-config --cflags`
7CXXFLAGS=-g $(PROFILE) -W -Wall $(DEFINES) `xml2-config --cflags`
8LDFLAGS=$(PROFILE) `xml2-config --libs`
9BINS=nvptool
10
11all: $(BINS)
12
13%.o: %.c
14 $(CC) $(CFLAGS) -c -o $@ $<
15
16%.o: %.cpp
17 $(CXX) $(CXXFLAGS) -c -o $@ $<
18
19nvptool: nvptool.o
20 $(LD) -o $@ $^ $(LDFLAGS)
21
22clean:
23 rm -fr *.o
24
25veryclean:
26 rm -rf $(BINS)
diff --git a/utils/nwztools/database/nvp/README b/utils/nwztools/database/nvp/README
new file mode 100644
index 0000000000..cb403291c8
--- /dev/null
+++ b/utils/nwztools/database/nvp/README
@@ -0,0 +1,67 @@
1The NVP map varies a lot from players to players, it is inconceivable to build
2it by hand. The approach taken is to extract it from the kernel of each player.
3Since Sony provides the kernel of all players, it is 'only' a matter of
4downloading all of them. A bit of back story on the NVP: it is non-volatile
5area of the flash that is divided in regions and then "sectors" (unrelated to
6hard drive sectors). Each "sector" stores the data of a "node". The ABI
7between the NVP driver and the userspace is an index: the userspace gives the
8index of a node, and then drives looksup its table to see where it is and what
9is its size. The index map changes over time so Sony introduces standard "names"
10for its entries, those are 3-letters acronym (for example "fup" or "bti" or "shp")
11that have a corresponding index. For some reason, the driver also contains a
12description of the nodes, in english (so "bti" stands for "boot image").
13
14parse_nvp_header.sh
15===================
16
17This script is given a file name, a kernel directory or a kernel tgz and it will
18try to extract the mapping automatically. It produces a list of pairs
19 <node>,<name>
20where <node> is the index of the node (that's the only thing that is usable on
21a running device) and <name> is the standard name of the node. Note that is
22some kind of acronym (like 'fup') and the description needs to be generated
23separatly (see other section).
24
25parse_all_nvp_headers.sh
26========================
27
28This scripts expects a directory to have the following structure:
29 dir/
30 nwz-a10/
31 linux-kernel-*.tgz
32 nwz-e460/
33 linxu-kernel-*.tgz
34 ...
35Each sudirectory must the series name (as used in ../series.txt) and the kernel
36must be a tgz (end in .tgz and not .tar.gz) of the form linux-kernel-*.tgz. Usually
37the variable bit will be the version but some kernels have unknown versions. It
38will then run parse_nvp_header.sh on each of them and store the result in a
39file called <series name>.txt
40
41NOTE: the kernel can be symlinks to other files
42
43nvptool
44=======
45
46The kernel headers do no contain the description of the nvp node names.
47This one can be extract from the icx_nvp[_emmc].ko driver on target using complicated
48elf parsing done by nvptool. Technically nvptoo can find much more information
49like the node -> humanname mapping as well and the actual sector on the disk but
50since we can already extract it easily from the headers, we only extract description
51names from it.
52
53parse_all_nvp_nodes.sh
54======================
55
56This scripts expects a directory to have the following structure:
57 dir/
58 nwz-a10/
59 rootfs.tgz
60 nwz-e460/
61 rootfs.tgz
62 ...
63Each sudirectory must the series name (as used in ../series.txt) and the rootfs
64must be a tar. It will then extract the relevant icx_nvp driver from it and run
65nvptool on it to produce a file called nodes-<series name>.txt
66
67NOTE: the rootfs can be symlinks to other files
diff --git a/utils/nwztools/database/nvp/nodes-nwz-a10.txt b/utils/nwztools/database/nvp/nodes-nwz-a10.txt
new file mode 100644
index 0000000000..2beb185b6c
--- /dev/null
+++ b/utils/nwztools/database/nvp/nodes-nwz-a10.txt
@@ -0,0 +1,89 @@
11,4,system information
22,32,u-boot password
33,4,firmware update flag
44,4,beep ok flag
55,4,hold mode
66,16,rtc alarm
77,64,model id
88,5,product code
99,16,serial number
1010,8,update file name
1111,64,key and signature
1212,32,ship information
1313,4,test mode flag
1414,4,getty mode flag
1515,16,fm parameter
1616,64,sound driver parameter
1717,64,noise cancel driver parameter
1818,512,bluetooth pskey
1977,4,wifi protected setup
2085,4,battery calibration
2119,2048,bluetooth parameter
2220,512,btmw factory pair info
2321,512,btmw factory scdb
2422,4,btmw log mode flag
2578,4,application debug mode flag
2679,4,browser log mode flag
2780,4,time out to sleep
2881,4,europe vol regulation flag
2982,4,function information
3083,4,service id
3184,4,marlin key
3286,4,MSC only mode flag
3389,4,SD Card export flag
3423,704,aad/empr key
3524,160,aad icv
3625,520,empr icv
3726,4,key mode (debug/release)
3827,64,random data
3928,8224,slacker id file
4029,64,starfish id
4130,33024,marlin device key
4231,20,secure clock
4332,16,slacker time
4433,64,marlin time
4534,16384,EKB 0
4635,16384,EKB 1
4736,1024,EMPR 0
4837,1024,EMPR 1
4938,1024,EMPR 2
5039,1024,EMPR 3
5140,1024,EMPR 4
5241,1024,EMPR 5
5342,1024,EMPR 6
5443,1024,EMPR 7
5544,1024,EMPR 8
5645,1024,EMPR 9
5746,1024,EMPR 10
5847,1024,EMPR 11
5948,1024,EMPR 12
6049,1024,EMPR 13
6150,1024,EMPR 14
6251,1024,EMPR 15
6352,1024,EMPR 16
6453,1024,EMPR 17
6554,1024,EMPR 18
6655,1024,EMPR 19
6756,1024,EMPR 20
6857,1024,EMPR 21
6958,1024,EMPR 22
7059,1024,EMPR 23
7160,1024,EMPR 24
7261,1024,EMPR 25
7362,1024,EMPR 26
7463,1024,EMPR 27
7564,1024,EMPR 28
7665,1024,EMPR 29
7766,1024,EMPR 30
7867,1024,EMPR 31
7968,4,color variation
8069,4,speaker ship info
8170,8,middleware parameter
8271,4,quick shutdown flag
8372,262144,boot image
8473,262144,hold image
8574,262144,low battery image
8675,262144,update image
8776,262144,update error image
8887,262144,precharge image
8988,262144,dead battery image
diff --git a/utils/nwztools/database/nvp/nodes-nwz-a20.txt b/utils/nwztools/database/nvp/nodes-nwz-a20.txt
new file mode 100644
index 0000000000..2beb185b6c
--- /dev/null
+++ b/utils/nwztools/database/nvp/nodes-nwz-a20.txt
@@ -0,0 +1,89 @@
11,4,system information
22,32,u-boot password
33,4,firmware update flag
44,4,beep ok flag
55,4,hold mode
66,16,rtc alarm
77,64,model id
88,5,product code
99,16,serial number
1010,8,update file name
1111,64,key and signature
1212,32,ship information
1313,4,test mode flag
1414,4,getty mode flag
1515,16,fm parameter
1616,64,sound driver parameter
1717,64,noise cancel driver parameter
1818,512,bluetooth pskey
1977,4,wifi protected setup
2085,4,battery calibration
2119,2048,bluetooth parameter
2220,512,btmw factory pair info
2321,512,btmw factory scdb
2422,4,btmw log mode flag
2578,4,application debug mode flag
2679,4,browser log mode flag
2780,4,time out to sleep
2881,4,europe vol regulation flag
2982,4,function information
3083,4,service id
3184,4,marlin key
3286,4,MSC only mode flag
3389,4,SD Card export flag
3423,704,aad/empr key
3524,160,aad icv
3625,520,empr icv
3726,4,key mode (debug/release)
3827,64,random data
3928,8224,slacker id file
4029,64,starfish id
4130,33024,marlin device key
4231,20,secure clock
4332,16,slacker time
4433,64,marlin time
4534,16384,EKB 0
4635,16384,EKB 1
4736,1024,EMPR 0
4837,1024,EMPR 1
4938,1024,EMPR 2
5039,1024,EMPR 3
5140,1024,EMPR 4
5241,1024,EMPR 5
5342,1024,EMPR 6
5443,1024,EMPR 7
5544,1024,EMPR 8
5645,1024,EMPR 9
5746,1024,EMPR 10
5847,1024,EMPR 11
5948,1024,EMPR 12
6049,1024,EMPR 13
6150,1024,EMPR 14
6251,1024,EMPR 15
6352,1024,EMPR 16
6453,1024,EMPR 17
6554,1024,EMPR 18
6655,1024,EMPR 19
6756,1024,EMPR 20
6857,1024,EMPR 21
6958,1024,EMPR 22
7059,1024,EMPR 23
7160,1024,EMPR 24
7261,1024,EMPR 25
7362,1024,EMPR 26
7463,1024,EMPR 27
7564,1024,EMPR 28
7665,1024,EMPR 29
7766,1024,EMPR 30
7867,1024,EMPR 31
7968,4,color variation
8069,4,speaker ship info
8170,8,middleware parameter
8271,4,quick shutdown flag
8372,262144,boot image
8473,262144,hold image
8574,262144,low battery image
8675,262144,update image
8776,262144,update error image
8887,262144,precharge image
8988,262144,dead battery image
diff --git a/utils/nwztools/database/nvp/nodes-nwz-a820.txt b/utils/nwztools/database/nvp/nodes-nwz-a820.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/utils/nwztools/database/nvp/nodes-nwz-a820.txt
diff --git a/utils/nwztools/database/nvp/nodes-nwz-a860.txt b/utils/nwztools/database/nvp/nodes-nwz-a860.txt
new file mode 100644
index 0000000000..4a998d839a
--- /dev/null
+++ b/utils/nwztools/database/nvp/nodes-nwz-a860.txt
@@ -0,0 +1,89 @@
124,4,system information
223,32,u-boot password
39,4,firmware update flag
410,4,beep ok flag
534,16,rtc alarm
680,4,hold mode
716,64,model id
84,16,serial number
911,32,ship information
1068,4,color variation
1126,5,product code
1229,8,update file name
1332,64,key and signature
1417,4,test mode flag
1518,4,getty mode flag
1670,4,disable iptable flag
1730,64,sound driver parameter
1831,64,noise cancel driver parameter
1977,6,wifi mac address
2075,4,wifi protected setup
2182,16,fm parameter
2283,4,speaker ship info
2384,4,mass storage class mode
2425,4,exception monitor mode
2527,4,battery calibration
2686,512,bluetooth pskey
275,4096,application parameter
287,20,secure clock
2912,160,aad icv
3013,520,empr key
3176,16,slacker time
3221,4,key mode (debug/release)
3371,64,marlin time
3472,16384,marlin crl
3589,512,btmw factory pair info
3688,512,btmw factory scdb
3787,4,btmw log mode flag
3885,4,europe vol regulation flag
398,8,middleware parameter
4022,4,quick shutdown flag
4169,4,time out to sleep
4278,4,application debug mode flag
4379,4,browser log mode flag
443,704,aad key
4528,64,wmt key
4681,8224,slacker id file
4773,33024,marlin device key
4833,64,starfish id
4935,2048,bluetooth address
5014,16384,EKB 0
5115,16384,EKB 1
5274,24576,marlin user key
5336,1024,EMPR 0
5437,1024,EMPR 1
5538,1024,EMPR 2
5639,1024,EMPR 3
5740,1024,EMPR 4
5841,1024,EMPR 5
5942,1024,EMPR 6
6043,1024,EMPR 7
6144,1024,EMPR 8
6245,1024,EMPR 9
6346,1024,EMPR 10
6447,1024,EMPR 11
6548,1024,EMPR 12
6649,1024,EMPR 13
6750,1024,EMPR 14
6851,1024,EMPR 15
6952,1024,EMPR 16
7053,1024,EMPR 17
7154,1024,EMPR 18
7255,1024,EMPR 19
7356,1024,EMPR 20
7457,1024,EMPR 21
7558,1024,EMPR 22
7659,1024,EMPR 23
7760,1024,EMPR 24
7861,1024,EMPR 25
7962,1024,EMPR 26
8063,1024,EMPR 27
8164,1024,EMPR 28
8265,1024,EMPR 29
8366,1024,EMPR 30
8467,1024,EMPR 31
851,262144,boot image
862,262144,hold image
8720,262144,low battery image
8819,262144,update image
896,262144,update error image
diff --git a/utils/nwztools/database/nvp/nodes-nwz-e450.txt b/utils/nwztools/database/nvp/nodes-nwz-e450.txt
new file mode 100644
index 0000000000..438488acbc
--- /dev/null
+++ b/utils/nwztools/database/nvp/nodes-nwz-e450.txt
@@ -0,0 +1,78 @@
124,4,system information
223,32,u-boot password
39,4,firmware update flag
410,4,beep ok flag
534,16,rtc alarm
680,4,hold mode
716,64,model id
84,16,serial number
911,32,ship information
1068,4,color variation
1126,5,product code
1229,8,update file name
1332,64,key and signature
1417,4,test mode flag
1518,4,getty mode flag
1670,4,disable iptable flag
1730,64,sound driver parameter
1831,64,noise cancel driver parameter
1977,6,wifi mac address
2075,4,wifi protected setup
2182,16,fm parameter
2283,4,speaker ship info
2384,4,mass storage class mode
2425,4,exception monitor mode
255,4096,application parameter
2635,2048,bluetooth parameter
278,8,middleware parameter
2822,4,quick shutdown flag
2969,4,time out to sleep
3078,4,application debug mode flag
3179,4,browser log mode flag
327,20,secure clock
333,704,aad key
3412,160,aad icv
3513,520,empr key
3628,64,random data
3776,16,slacker time
3821,4,key mode (debug/release)
3981,8224,slacker id file
4014,16384,EKB 0
4115,16384,EKB 1
4236,1024,EMPR 0
4337,1024,EMPR 1
4438,1024,EMPR 2
4539,1024,EMPR 3
4640,1024,EMPR 4
4741,1024,EMPR 5
4842,1024,EMPR 6
4943,1024,EMPR 7
5044,1024,EMPR 8
5145,1024,EMPR 9
5246,1024,EMPR 10
5347,1024,EMPR 11
5448,1024,EMPR 12
5549,1024,EMPR 13
5650,1024,EMPR 14
5751,1024,EMPR 15
5852,1024,EMPR 16
5953,1024,EMPR 17
6054,1024,EMPR 18
6155,1024,EMPR 19
6256,1024,EMPR 20
6357,1024,EMPR 21
6458,1024,EMPR 22
6559,1024,EMPR 23
6660,1024,EMPR 24
6761,1024,EMPR 25
6862,1024,EMPR 26
6963,1024,EMPR 27
7064,1024,EMPR 28
7165,1024,EMPR 29
7266,1024,EMPR 30
7367,1024,EMPR 31
741,262144,boot image
752,262144,hold image
7620,262144,low battery image
7719,262144,update image
786,262144,update error image
diff --git a/utils/nwztools/database/nvp/nodes-nwz-e460.txt b/utils/nwztools/database/nvp/nodes-nwz-e460.txt
new file mode 100644
index 0000000000..4a998d839a
--- /dev/null
+++ b/utils/nwztools/database/nvp/nodes-nwz-e460.txt
@@ -0,0 +1,89 @@
124,4,system information
223,32,u-boot password
39,4,firmware update flag
410,4,beep ok flag
534,16,rtc alarm
680,4,hold mode
716,64,model id
84,16,serial number
911,32,ship information
1068,4,color variation
1126,5,product code
1229,8,update file name
1332,64,key and signature
1417,4,test mode flag
1518,4,getty mode flag
1670,4,disable iptable flag
1730,64,sound driver parameter
1831,64,noise cancel driver parameter
1977,6,wifi mac address
2075,4,wifi protected setup
2182,16,fm parameter
2283,4,speaker ship info
2384,4,mass storage class mode
2425,4,exception monitor mode
2527,4,battery calibration
2686,512,bluetooth pskey
275,4096,application parameter
287,20,secure clock
2912,160,aad icv
3013,520,empr key
3176,16,slacker time
3221,4,key mode (debug/release)
3371,64,marlin time
3472,16384,marlin crl
3589,512,btmw factory pair info
3688,512,btmw factory scdb
3787,4,btmw log mode flag
3885,4,europe vol regulation flag
398,8,middleware parameter
4022,4,quick shutdown flag
4169,4,time out to sleep
4278,4,application debug mode flag
4379,4,browser log mode flag
443,704,aad key
4528,64,wmt key
4681,8224,slacker id file
4773,33024,marlin device key
4833,64,starfish id
4935,2048,bluetooth address
5014,16384,EKB 0
5115,16384,EKB 1
5274,24576,marlin user key
5336,1024,EMPR 0
5437,1024,EMPR 1
5538,1024,EMPR 2
5639,1024,EMPR 3
5740,1024,EMPR 4
5841,1024,EMPR 5
5942,1024,EMPR 6
6043,1024,EMPR 7
6144,1024,EMPR 8
6245,1024,EMPR 9
6346,1024,EMPR 10
6447,1024,EMPR 11
6548,1024,EMPR 12
6649,1024,EMPR 13
6750,1024,EMPR 14
6851,1024,EMPR 15
6952,1024,EMPR 16
7053,1024,EMPR 17
7154,1024,EMPR 18
7255,1024,EMPR 19
7356,1024,EMPR 20
7457,1024,EMPR 21
7558,1024,EMPR 22
7659,1024,EMPR 23
7760,1024,EMPR 24
7861,1024,EMPR 25
7962,1024,EMPR 26
8063,1024,EMPR 27
8164,1024,EMPR 28
8265,1024,EMPR 29
8366,1024,EMPR 30
8467,1024,EMPR 31
851,262144,boot image
862,262144,hold image
8720,262144,low battery image
8819,262144,update image
896,262144,update error image
diff --git a/utils/nwztools/database/nvp/nodes-nwz-e580.txt b/utils/nwztools/database/nvp/nodes-nwz-e580.txt
new file mode 100644
index 0000000000..021cc9178d
--- /dev/null
+++ b/utils/nwztools/database/nvp/nodes-nwz-e580.txt
@@ -0,0 +1,88 @@
11,4,system information
22,32,u-boot password
33,4,firmware update flag
44,4,beep ok flag
55,4,hold mode
66,16,rtc alarm
77,64,model id
88,5,product code
99,16,serial number
1010,8,update file name
1111,64,key and signature
1212,32,ship information
1313,4,test mode flag
1414,4,getty mode flag
1515,16,fm parameter
1616,64,sound driver parameter
1717,64,noise cancel driver parameter
1818,512,bluetooth pskey
1977,4,wifi protected setup
2085,4,battery calibration
2119,2048,bluetooth parameter
2220,512,btmw factory pair info
2321,512,btmw factory scdb
2422,4,btmw log mode flag
2578,4,application debug mode flag
2679,4,browser log mode flag
2780,4,time out to sleep
2881,4,europe vol regulation flag
2982,4,function information
3083,4,service id
3184,4,marlin key
3286,4,MSC only mode flag
3323,704,aad/empr key
3424,160,aad icv
3525,520,empr icv
3626,4,key mode (debug/release)
3727,64,random data
3828,8224,slacker id file
3929,64,starfish id
4030,33024,marlin device key
4131,20,secure clock
4232,16,slacker time
4333,64,marlin time
4434,16384,EKB 0
4535,16384,EKB 1
4636,1024,EMPR 0
4737,1024,EMPR 1
4838,1024,EMPR 2
4939,1024,EMPR 3
5040,1024,EMPR 4
5141,1024,EMPR 5
5242,1024,EMPR 6
5343,1024,EMPR 7
5444,1024,EMPR 8
5545,1024,EMPR 9
5646,1024,EMPR 10
5747,1024,EMPR 11
5848,1024,EMPR 12
5949,1024,EMPR 13
6050,1024,EMPR 14
6151,1024,EMPR 15
6252,1024,EMPR 16
6353,1024,EMPR 17
6454,1024,EMPR 18
6555,1024,EMPR 19
6656,1024,EMPR 20
6757,1024,EMPR 21
6858,1024,EMPR 22
6959,1024,EMPR 23
7060,1024,EMPR 24
7161,1024,EMPR 25
7262,1024,EMPR 26
7363,1024,EMPR 27
7464,1024,EMPR 28
7565,1024,EMPR 29
7666,1024,EMPR 30
7767,1024,EMPR 31
7868,4,color variation
7969,4,speaker ship info
8070,8,middleware parameter
8171,4,quick shutdown flag
8272,262144,boot image
8373,262144,hold image
8474,262144,low battery image
8575,262144,update image
8676,262144,update error image
8787,262144,precharge image
8888,262144,dead battery image
diff --git a/utils/nwztools/database/nvp/nodes-nwz-zx100.txt b/utils/nwztools/database/nvp/nodes-nwz-zx100.txt
new file mode 100644
index 0000000000..2beb185b6c
--- /dev/null
+++ b/utils/nwztools/database/nvp/nodes-nwz-zx100.txt
@@ -0,0 +1,89 @@
11,4,system information
22,32,u-boot password
33,4,firmware update flag
44,4,beep ok flag
55,4,hold mode
66,16,rtc alarm
77,64,model id
88,5,product code
99,16,serial number
1010,8,update file name
1111,64,key and signature
1212,32,ship information
1313,4,test mode flag
1414,4,getty mode flag
1515,16,fm parameter
1616,64,sound driver parameter
1717,64,noise cancel driver parameter
1818,512,bluetooth pskey
1977,4,wifi protected setup
2085,4,battery calibration
2119,2048,bluetooth parameter
2220,512,btmw factory pair info
2321,512,btmw factory scdb
2422,4,btmw log mode flag
2578,4,application debug mode flag
2679,4,browser log mode flag
2780,4,time out to sleep
2881,4,europe vol regulation flag
2982,4,function information
3083,4,service id
3184,4,marlin key
3286,4,MSC only mode flag
3389,4,SD Card export flag
3423,704,aad/empr key
3524,160,aad icv
3625,520,empr icv
3726,4,key mode (debug/release)
3827,64,random data
3928,8224,slacker id file
4029,64,starfish id
4130,33024,marlin device key
4231,20,secure clock
4332,16,slacker time
4433,64,marlin time
4534,16384,EKB 0
4635,16384,EKB 1
4736,1024,EMPR 0
4837,1024,EMPR 1
4938,1024,EMPR 2
5039,1024,EMPR 3
5140,1024,EMPR 4
5241,1024,EMPR 5
5342,1024,EMPR 6
5443,1024,EMPR 7
5544,1024,EMPR 8
5645,1024,EMPR 9
5746,1024,EMPR 10
5847,1024,EMPR 11
5948,1024,EMPR 12
6049,1024,EMPR 13
6150,1024,EMPR 14
6251,1024,EMPR 15
6352,1024,EMPR 16
6453,1024,EMPR 17
6554,1024,EMPR 18
6655,1024,EMPR 19
6756,1024,EMPR 20
6857,1024,EMPR 21
6958,1024,EMPR 22
7059,1024,EMPR 23
7160,1024,EMPR 24
7261,1024,EMPR 25
7362,1024,EMPR 26
7463,1024,EMPR 27
7564,1024,EMPR 28
7665,1024,EMPR 29
7766,1024,EMPR 30
7867,1024,EMPR 31
7968,4,color variation
8069,4,speaker ship info
8170,8,middleware parameter
8271,4,quick shutdown flag
8372,262144,boot image
8473,262144,hold image
8574,262144,low battery image
8675,262144,update image
8776,262144,update error image
8887,262144,precharge image
8988,262144,dead battery image
diff --git a/utils/nwztools/database/nvp/nvptool.cpp b/utils/nwztools/database/nvp/nvptool.cpp
new file mode 100644
index 0000000000..1371e93b87
--- /dev/null
+++ b/utils/nwztools/database/nvp/nvptool.cpp
@@ -0,0 +1,754 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <cstdio>
23#include <stdint.h>
24#include <cstdlib>
25#include <cstring>
26#include <getopt.h>
27#include <cstdarg>
28#include <string>
29#include <fstream>
30#include <elf.h>
31
32bool g_verbose = false;
33bool g_unsafe = false;
34
35uint8_t *read_file(const std::string& path, size_t& size)
36{
37 std::ifstream fin(path.c_str(), std::ios::binary);
38 if(!fin)
39 {
40 printf("Error: cannot open '%s'\n", path.c_str());
41 return 0;
42 }
43 fin.seekg(0, std::ios::end);
44 size = fin.tellg();
45 fin.seekg(0, std::ios::beg);
46 uint8_t *buf = new uint8_t[size];
47 fin.read((char *)buf, size);
48 return buf;
49}
50
51bool write_file(const std::string& path, uint8_t *buf, size_t size)
52{
53 std::ofstream fout(path.c_str(), std::ios::binary);
54 if(!fout)
55 {
56 printf("Error: cannot open '%s'\n", path.c_str());
57 return false;
58 }
59 fout.write((char *)buf, size);
60 fout.close();
61 return true;
62}
63
64/* ELF code */
65uint8_t *g_elf_buf;
66size_t g_elf_size;
67Elf32_Shdr *g_elf_symtab;
68Elf32_Shdr *g_elf_symtab_strtab;
69Elf32_Shdr *g_elf_shstrtab;
70
71Elf32_Ehdr *elf_ehdr()
72{
73 return (Elf32_Ehdr *)g_elf_buf;
74}
75
76#define NTH_SHDR_OFF(n) \
77 (elf_ehdr()->e_shoff + elf_ehdr()->e_shentsize * (n))
78
79Elf32_Shdr *elf_shdr(size_t index)
80{
81 if(index >= elf_ehdr()->e_shnum)
82 {
83 printf("Warning: section index is out of bounds\n");
84 return nullptr;
85 }
86 return (Elf32_Shdr *)(g_elf_buf + NTH_SHDR_OFF(index));
87}
88
89size_t elf_shnum()
90{
91 return elf_ehdr()->e_shnum;
92}
93
94const char *elf_get_str(Elf32_Shdr *strtab, Elf32_Word index)
95{
96 /* sanity checks */
97 if(strtab->sh_type != SHT_STRTAB)
98 {
99 printf("Warning: string access to a non-string-table section\n");
100 return nullptr;
101 }
102 if(strtab->sh_offset + strtab->sh_size > g_elf_size)
103 {
104 printf("Warning: string table section does not fit in the file\n");
105 return nullptr;
106 }
107 if(index >= strtab->sh_size)
108 {
109 printf("Warning: string access to string table is out of bounds\n");
110 return nullptr;
111 }
112 char *buf = (char *)(g_elf_buf + strtab->sh_offset);
113 if(buf[strtab->sh_size - 1] != 0)
114 {
115 printf("Warning: string table is not zero terminated\n");
116 return nullptr;
117 }
118 return buf + index;
119}
120
121const char *elf_get_section_name(size_t index)
122{
123 Elf32_Shdr *shdr = elf_shdr(index);
124 return shdr ? elf_get_str(g_elf_shstrtab, shdr->sh_name) : nullptr;
125}
126
127const char *elf_get_symbol_name(Elf32_Sym *sym)
128{
129 if(ELF32_ST_TYPE(sym->st_info) == STT_SECTION)
130 return elf_get_section_name(sym->st_shndx);
131 else
132 return elf_get_str(g_elf_symtab_strtab, sym->st_name);
133}
134
135Elf32_Sym *elf_get_symbol_by_name(const char *name)
136{
137 Elf32_Sym *sym = (Elf32_Sym *)(g_elf_buf + g_elf_symtab->sh_offset);
138 size_t nr_syms = g_elf_symtab->sh_size / sizeof(Elf32_Sym);
139 for(size_t i = 0; i < nr_syms; i++)
140 {
141 const char *s = elf_get_symbol_name(&sym[i]);
142 if(s != nullptr && strcmp(name, s) == 0)
143 return &sym[i];
144 }
145 return nullptr;
146}
147
148Elf32_Sym *elf_get_symbol_by_address(size_t shndx, Elf32_Word address)
149{
150 Elf32_Sym *sym = (Elf32_Sym *)(g_elf_buf + g_elf_symtab->sh_offset);
151 size_t nr_syms = g_elf_symtab->sh_size / sizeof(Elf32_Sym);
152 for(size_t i = 0; i < nr_syms; i++)
153 {
154 if(sym[i].st_shndx == shndx && sym[i].st_value == address)
155 return &sym[i];
156 }
157 return nullptr;
158}
159
160Elf32_Sym *elf_get_symbol_by_index(size_t index)
161{
162 Elf32_Sym *sym = (Elf32_Sym *)(g_elf_buf + g_elf_symtab->sh_offset);
163 size_t nr_syms = g_elf_symtab->sh_size / sizeof(Elf32_Sym);
164 if(index >= nr_syms)
165 return nullptr;
166 return &sym[index];
167}
168
169void *elf_get_section_ptr(size_t shndx, Elf32_Word address, size_t size)
170{
171 Elf32_Shdr *shdr = elf_shdr(shndx);
172 if(shdr == nullptr)
173 return nullptr;
174 if(address + size > shdr->sh_size)
175 return nullptr;
176 if(shdr->sh_offset + shdr->sh_size > g_elf_size)
177 return nullptr;
178 return g_elf_buf + shdr->sh_offset + address;
179}
180
181/* make sure the string has a final zero in the section, optionally check characters
182 * are printable */
183const char *elf_get_string_ptr_safe(size_t shndx, Elf32_Word offset, bool want_print = true)
184{
185 Elf32_Shdr *shdr = elf_shdr(shndx);
186 if(shdr == nullptr)
187 return nullptr;
188 /* address must be in the section */
189 if(offset >= shdr->sh_size)
190 return nullptr;
191 /* determine maximum size */
192 size_t max_sz = shdr->sh_size - offset;
193 const char *ptr = (const char *)(g_elf_buf + shdr->sh_offset + offset);
194 for(size_t i = 0; i < max_sz; i++)
195 {
196 if(ptr[i] == 0) /* found final 0, everything is fine */
197 return ptr;
198 if(want_print && !isprint(ptr[i]))
199 return nullptr;
200 }
201 return nullptr;
202}
203
204size_t elf_find_reloc_section(size_t shndx)
205{
206 /* find the relocation section */
207 for(size_t i = 0; i < elf_ehdr()->e_shnum; i++)
208 {
209 Elf32_Shdr *shdr = elf_shdr(i);
210 if(shdr->sh_type != SHT_REL && shdr->sh_type != SHT_RELA)
211 continue;
212 if(shdr->sh_info != shndx)
213 continue;
214 return i;
215 }
216 return 0;
217}
218
219void *elf_get_symbol_ptr(Elf32_Sym *sym, size_t size)
220{
221 /* NOTE: also works for STT_SECTION since offset will be 0 */
222 return elf_get_section_ptr(sym->st_shndx, sym->st_value, size);
223}
224
225/* take the position of a 32-bit address in the section and apply relocation if
226 * any */
227void *elf_reloc_addr32(size_t shndx, Elf32_Word offset)
228{
229 /* read value */
230 uint32_t *val = (uint32_t *)elf_get_section_ptr(shndx, offset, 4);
231 if(val == nullptr)
232 return 0; /* invalid */
233 /* find reloc section if any */
234 size_t relshndx = elf_find_reloc_section(shndx);
235 if(relshndx == 0)
236 return g_elf_buf + *val; /* no relocation applies */
237 Elf32_Shdr *shdr = elf_shdr(relshndx);
238 /* find relocation that applies */
239 if(shdr->sh_type == SHT_RELA)
240 {
241 printf("Warning: unsupported RELA relocation type\n");
242 return 0;
243 }
244 Elf32_Rel *rel = (Elf32_Rel *)elf_get_section_ptr(relshndx, 0, shdr->sh_size);
245 if(rel == nullptr)
246 {
247 printf("Warning: invalid relocation section\n");
248 return 0;
249 }
250 size_t sym_count = shdr->sh_size / sizeof(Elf32_Rel);
251 for(size_t i = 0; i < sym_count; i++)
252 {
253 /* for relocatable files, r_offset is the offset in the section */
254 if(rel[i].r_offset != offset)
255 continue;
256 /* find symbol, ignore shdr->sh_link and assume it is g_elf_symtab
257 * since the file should have only one symbol table anyway */
258 Elf32_Sym *sym = elf_get_symbol_by_index(ELF32_R_SYM(rel[i].r_info));
259 /* found it! */
260 if(g_verbose)
261 {
262 printf("[section %zu (%s) offset %#x reloc val %#x type %d sym %d (%s)]\n",
263 shndx, elf_get_section_name(shndx), offset, *val,
264 ELF32_R_TYPE(rel[i].r_info), ELF32_R_SYM(rel[i].r_info),
265 sym ? elf_get_symbol_name(sym) : "<undef>");
266 }
267 /* apply reloc */
268 if(ELF32_R_TYPE(rel[i].r_info) == R_ARM_ABS32)
269 {
270 if(sym == nullptr)
271 {
272 printf("Warning: R_ARM_ABS32 reloc with invalid symbol reference\n");
273 return 0;
274 }
275 return *val + (uint8_t *)elf_get_symbol_ptr(sym, 0);
276 }
277 else
278 {
279 printf("Warning: unsupported relocation type %d\n", ELF32_R_TYPE(rel[i].r_info));
280 return 0;
281 }
282 }
283 /* no reloc applies */
284 if(g_verbose)
285 {
286 printf("[section %zu (%s) offset %#x no reloc found]\n", shndx,
287 elf_get_section_name(shndx), offset);
288 }
289 return g_elf_buf + *val; /* no relocation applies */
290}
291
292size_t elf_map_virt_addr(uint32_t address, Elf32_Word& out_off)
293{
294 /* for relocatable file, this is trivial */
295 for(size_t i = 0; i < elf_ehdr()->e_shnum; i++)
296 {
297 Elf32_Shdr *shdr = elf_shdr(i);
298 if(shdr->sh_offset <= address && address < shdr->sh_offset + shdr->sh_size)
299 {
300 out_off = address - shdr->sh_offset;
301 if(g_verbose)
302 {
303 printf("[map %#x to section %zi (%s) at %#x]\n", address, i,
304 elf_get_section_name(i), out_off);
305 }
306 return i;
307 }
308 }
309 return 0; /* section 0 is always invalid */
310}
311
312size_t elf_map_ptr(void *ptr, Elf32_Word& out_off)
313{
314 uint32_t addr = (uint32_t)((uint8_t *)ptr - g_elf_buf);
315 return elf_map_virt_addr(addr, out_off);
316}
317
318/* same as elf_reloc_addr32 but find section automatically from pointer */
319void *elf_reloc_addr32_ptr(uint32_t *val)
320{
321 Elf32_Word off;
322 size_t sec = elf_map_ptr((void *)val, off);
323 /* if it does not belong to any section, don't do anything */
324 if(sec == 0)
325 {
326 printf("Warning: reloc addr pointer not in any section\n");
327 return g_elf_buf + *val;
328 }
329 return elf_reloc_addr32(sec, off);
330}
331
332Elf32_Sym *elf_get_symbol_by_ptr(void *ptr)
333{
334 Elf32_Word off;
335 size_t sec = elf_map_ptr(ptr, off);
336 return sec ? elf_get_symbol_by_address(sec, off) : nullptr;
337}
338
339/* check if a string is safe */
340bool elf_is_str_ptr_safe(const char *str)
341{
342 Elf32_Word name_off;
343 /* find the section it belongs to */
344 size_t name_shndx = elf_map_ptr((void *)str, name_off);
345 if(name_shndx == 0)
346 return false;
347 /* check the string fit in the section */
348 return elf_get_string_ptr_safe(name_shndx, name_off) != nullptr;
349}
350
351bool elf_is_ptr_safe(void *ptr, size_t sz)
352{
353 Elf32_Word ptr_off;
354 /* find the section it belongs to */
355 size_t ptr_shndx = elf_map_ptr((void *)ptr, ptr_off);
356 if(ptr_shndx == 0)
357 return false;
358 /* check the string fit in the section */
359 return elf_get_section_ptr(ptr_shndx, ptr_off, sz) != nullptr;
360}
361
362bool elf_init()
363{
364 if(g_elf_size < sizeof(Elf32_Ehdr))
365 {
366 printf("Invalid ELF file: too small\n");
367 return false;
368 }
369 Elf32_Ehdr *ehdr = elf_ehdr();
370 if(ehdr->e_ident[EI_MAG0] != ELFMAG0 ||
371 ehdr->e_ident[EI_MAG1] != ELFMAG1 ||
372 ehdr->e_ident[EI_MAG2] != ELFMAG2 ||
373 ehdr->e_ident[EI_MAG3] != ELFMAG3)
374 {
375 printf("Invalid ELF file: invalid ident\n");
376 return false;
377 }
378 /* we only support relocatable files */
379 if(ehdr->e_type != ET_REL)
380 {
381 printf("Unsupported ELF file: this is not a relocatable file\n");
382 return false;
383 }
384 if(ehdr->e_ident[EI_CLASS] != ELFCLASS32 || ehdr->e_machine != EM_ARM)
385 {
386 printf("Unsupported ELF file: this is not a 32-bit ARM ELF file\n");
387 return false;
388 }
389 /* go through sections */
390 if(ehdr->e_shoff == 0)
391 {
392 printf("Invalid ELF file: no sections\n");
393 return false;
394 }
395 if(ehdr->e_shentsize < sizeof(Elf32_Shdr))
396 {
397 printf("Invalid ELF file: section entry size too small\n");
398 return false;
399 }
400 if(NTH_SHDR_OFF(ehdr->e_shnum) > g_elf_size)
401 {
402 printf("Invalid ELF file: sections header does not fit in the file\n");
403 return false;
404 }
405 for(size_t i = 0; i < ehdr->e_shnum; i++)
406 {
407 Elf32_Shdr *shdr = (Elf32_Shdr *)(g_elf_buf + NTH_SHDR_OFF(i));
408 if(shdr->sh_type == SHT_SYMTAB)
409 g_elf_symtab = shdr;
410 }
411 /* handle symbol table */
412 if(g_elf_symtab)
413 {
414 if(g_elf_symtab->sh_offset + g_elf_symtab->sh_size > g_elf_size)
415 {
416 printf("Invalid ELF file: symtab does not file in the file\n");
417 return false;
418 }
419 g_elf_symtab_strtab = elf_shdr(g_elf_symtab->sh_link);
420 if(g_elf_symtab_strtab == nullptr)
421 {
422 printf("Invalid ELF file: symtab's strtab is not valid\n");
423 }
424 if(g_elf_symtab_strtab->sh_type != SHT_STRTAB)
425 {
426 printf("Invalid ELF file: symtab's strtab is not a string table\n");
427 return false;
428 }
429 }
430 /* handle section string table */
431 if(ehdr->e_shstrndx != SHN_UNDEF)
432 {
433 g_elf_shstrtab = elf_shdr(ehdr->e_shstrndx);
434 if(g_elf_shstrtab == nullptr)
435 {
436 printf("Invalid ELF file: section string table is invalid\n");
437 return false;
438 }
439 }
440
441 return true;
442}
443
444/* main code */
445
446void usage()
447{
448 printf("usage: nvptool [options] inputs...\n");
449 printf("options:\n");
450 printf(" -h/--help Display help\n");
451 printf(" -x/--extract Extract nvp map from icx_nvp_emmc.ko\n");
452 printf(" -o/--output Set output file\n");
453 printf(" -v/--verbose Enable debug output\n");
454 printf(" -u/--unsafe Perform potentially unsafe operations\n");
455 exit(1);
456}
457
458struct zone_info_v1_t
459{
460 uint32_t node;
461 uint32_t start;
462 uint32_t count;
463 uint32_t size;
464 uint32_t semaphore[4]; /* a 16-byte structure, useless for us */
465 uint32_t name; /* pointer to string */
466} __attribute__((packed));
467
468struct zone_info_v2_t
469{
470 uint32_t node;
471 uint32_t start;
472 uint32_t count;
473 uint32_t size;
474 uint32_t semaphore[3]; /* a 12-byte structure, useless for us */
475 uint32_t name; /* pointer to string */
476} __attribute__((packed));
477
478struct area_info_v1_t
479{
480 uint32_t type; /* 1 = large, 2 = small */
481 uint32_t zoneinfo; /* pointer to zone_info_t[] */
482 uint32_t zonecount;
483 uint32_t semaphore[4]; /* a 16-byte structure, useless for us */
484 uint32_t name; /* pointer to string */
485} __attribute__((packed));
486
487struct area_info_v2_t
488{
489 uint32_t type; /* 1 = large, 2 = small */
490 uint32_t zoneinfo; /* pointer to zone_info_t[] */
491 uint32_t zonecount;
492 uint32_t semaphore[3]; /* a 16-byte structure, useless for us */
493 uint32_t name; /* pointer to string */
494} __attribute__((packed));
495
496int guess_version(void *area_info_ptr)
497{
498 /* the "semaphore" part is always filled with zeroes, so simply check if there
499 * are 3 or 4 of them */
500 area_info_v1_t *ai_v1 = (area_info_v1_t *)area_info_ptr;
501 if(ai_v1->semaphore[3] == 0)
502 return 1; /* v1: semaphore has 4 fields */
503 else
504 return 2; /* v2: semaphore has 3 fields */
505}
506
507int do_extract(const char *output, int argc, char **argv)
508{
509 if(argc != 1)
510 {
511 printf("You need to specify exactly one input file to extract from.\n");
512 return 3;
513 }
514 FILE *fout = NULL;
515 if(output)
516 {
517 fout = fopen(output, "w");
518 if(fout == NULL)
519 {
520 printf("Cannot open output file '%s'\n", output);
521 return 4;
522 }
523 }
524 /* read elf file */
525 g_elf_buf = read_file(argv[0], g_elf_size);
526 if(g_elf_buf == nullptr)
527 {
528 printf("Cannot open input file '%s'\n", argv[0]);
529 return 1;
530 }
531 if(!elf_init())
532 {
533 printf("This is not a valid ELF file\n");
534 return 1;
535 }
536 if(g_elf_symtab == nullptr)
537 {
538 printf("This ELF file does not have a symbol table\n");
539 return 1;
540 }
541 /* look for symbol 'AreaInfo' */
542 Elf32_Sym *sym_AreaInfo = elf_get_symbol_by_name("AreaInfo");
543 if(sym_AreaInfo == nullptr)
544 {
545 printf("Cannot find symbol 'AreaInfo'\n");
546 return 1;
547 }
548 printf("AreaInfo:\n");
549 if(g_verbose)
550 {
551 printf("[%u bytes at address %#x in section %u (%s)]\n",
552 (unsigned)sym_AreaInfo->st_size, (unsigned)sym_AreaInfo->st_value,
553 (unsigned)sym_AreaInfo->st_shndx, elf_get_section_name(sym_AreaInfo->st_shndx));
554 }
555 /* guess version */
556 int ver = guess_version(elf_get_symbol_ptr(sym_AreaInfo, sizeof(area_info_v1_t)));
557 if(g_verbose)
558 printf("[guessed version: %d]\n", ver);
559 size_t sizeof_area_info = (ver == 1) ? sizeof(area_info_v1_t) : sizeof(area_info_v2_t);
560 size_t sizeof_zone_info = (ver == 1) ? sizeof(zone_info_v1_t) : sizeof(zone_info_v2_t);
561 /* sanity check AreaInfo */
562 size_t area_count = sym_AreaInfo->st_size / sizeof_area_info;
563 if(!g_unsafe && (sym_AreaInfo->st_size % sizeof_area_info) != 0)
564 {
565 printf("AreaInfo size (%u) is a not a multiple of area_info_t size (%zu).\n",
566 (unsigned)sym_AreaInfo->st_size, sizeof_area_info);
567 printf("Use unsafe option to override this check\n");
568 return 1;
569 }
570 area_info_v1_t *AreaInfo_v1 = (area_info_v1_t *)elf_get_symbol_ptr(sym_AreaInfo,
571 sym_AreaInfo->st_size);
572 area_info_v2_t *AreaInfo_v2 = (area_info_v2_t *)AreaInfo_v1;
573 if(AreaInfo_v1 == nullptr)
574 {
575 printf("Symbol does not point to a valid address\n");
576 return 1;
577 }
578 for(size_t i = 0; i < area_count; i++)
579 {
580 uint32_t type;
581 uint32_t *zoneinfo_ptr;
582 uint32_t zonecount;
583 uint32_t *name_ptr;
584
585 if(ver == 1)
586 {
587 type = AreaInfo_v1[i].type;
588 zoneinfo_ptr = &AreaInfo_v1[i].zoneinfo;
589 zonecount = AreaInfo_v1[i].zonecount;
590 name_ptr = &AreaInfo_v1[i].name;
591 }
592 else
593 {
594 type = AreaInfo_v2[i].type;
595 zoneinfo_ptr = &AreaInfo_v2[i].zoneinfo;
596 zonecount = AreaInfo_v2[i].zonecount;
597 name_ptr = &AreaInfo_v2[i].name;
598 }
599
600 if(g_verbose)
601 {
602 printf(" [type=%u info=%#x count=%u name=%#x]\n", type, *zoneinfo_ptr,
603 zonecount, *name_ptr);
604 }
605 /* translate name address */
606 const char *name = (const char *)elf_reloc_addr32_ptr(name_ptr);
607 if(name == nullptr || !elf_is_str_ptr_safe(name))
608 {
609 printf(" Entry name is not a string\n");
610 continue;
611 }
612 /* skip reserved entries */
613 if(*zoneinfo_ptr == 0)
614 {
615 printf(" %s\n", name);
616 continue;
617 }
618 /* relocate the zoneinfo pointer */
619 void *Zone = elf_reloc_addr32_ptr(zoneinfo_ptr);;
620 if(Zone == nullptr)
621 {
622 printf(" %s\n", name);
623 printf(" Zone info pointer is not valid\n");
624 continue;
625 }
626 /* in safe mode, make sure the zone info pointer is a symbol */
627 Elf32_Sym *zoneinfo_sym = elf_get_symbol_by_ptr((void *)Zone);
628 const char *zoneinfo_sym_name = "<no symbol>";
629 if(zoneinfo_sym)
630 zoneinfo_sym_name = elf_get_symbol_name(zoneinfo_sym);
631 printf(" %s (%s)\n", name, zoneinfo_sym_name);
632 if(!g_unsafe && !zoneinfo_sym)
633 {
634 printf(" Zone info pointer does not correspond to any symbol.\n");
635 printf(" Use unsafe option to override this check\n");
636 continue;
637 }
638 /* if we have the symbol, make sure the claimed size match */
639 if(!g_unsafe && zoneinfo_sym)
640 {
641 if(zoneinfo_sym->st_size != sizeof_zone_info * zonecount)
642 {
643 printf(" Zone info symbol size (%u) does not match expected size (%zu)\n",
644 (unsigned)zoneinfo_sym->st_size, sizeof_zone_info * zonecount);
645 printf(" Use unsafe option to override this check\n");
646 continue;
647 }
648 }
649 /* sanity check */
650 if(!elf_is_ptr_safe((void *)Zone, sizeof_zone_info * zonecount))
651 {
652 printf(" Zone info pointer is not valid\n");
653 continue;
654 }
655 /* read zone */
656 zone_info_v1_t *Zone_v1 = (zone_info_v1_t *)Zone;
657 zone_info_v2_t *Zone_v2 = (zone_info_v2_t *)Zone;
658 for(size_t j = 0; j < zonecount; j++)
659 {
660 uint32_t node, start, count, size;
661 uint32_t *name_ptr;
662
663 if(ver == 1)
664 {
665 node = Zone_v1[j].node;
666 start = Zone_v1[j].start;
667 count = Zone_v1[j].count;
668 size = Zone_v1[j].size;
669 name_ptr = &Zone_v1[j].name;
670 }
671 else
672 {
673 node = Zone_v2[j].node;
674 start = Zone_v2[j].start;
675 count = Zone_v2[j].count;
676 size = Zone_v2[j].size;
677 name_ptr = &Zone_v2[j].name;
678 }
679
680 if(g_verbose)
681 {
682 printf(" [node=%u start=%#x count=%u size=%u name=%#x]\n",
683 node, start, count, size, *name_ptr);
684 }
685 /* translate name address */
686 const char *name = (const char *)elf_reloc_addr32_ptr(name_ptr);
687 if(name == nullptr || !elf_is_str_ptr_safe(name))
688 {
689 printf(" Entry name is not a string\n");
690 continue;
691 }
692 printf(" %s: node %03u, size %u\n", name, node, size);
693 if(fout)
694 fprintf(fout, "%u,%u,%s\n", node, size, name);
695 }
696 }
697 if(fout)
698 fclose(fout);
699 /* success */
700 return 0;
701}
702
703int main(int argc, char **argv)
704{
705 const char *output = NULL;
706 bool extract = false;
707
708 if(argc <= 1)
709 usage();
710
711 while(1)
712 {
713 static struct option long_options[] =
714 {
715 {"help", no_argument, 0, 'h'},
716 {"extract", no_argument, 0, 'x'},
717 {"output", required_argument, 0, 'o'},
718 {"verbose", no_argument, 0, 'v'},
719 {"unsafe", no_argument, 0, 'u'},
720 {0, 0, 0, 0}
721 };
722
723 int c = getopt_long(argc, argv, "hxo:vu", long_options, NULL);
724 if(c == -1)
725 break;
726 switch(c)
727 {
728 case -1:
729 break;
730 case 'h':
731 usage();
732 break;
733 case 'o':
734 output = optarg;
735 break;
736 case 'x':
737 extract = true;
738 break;
739 case 'v':
740 g_verbose = true;
741 break;
742 case 'u':
743 g_unsafe = true;
744 break;
745 default:
746 abort();
747 }
748 }
749
750 if(extract)
751 return do_extract(output, argc - optind, argv + optind);
752 printf("You need to specify an operation. Run nvptool -h for help\n");
753 return 1;
754}
diff --git a/utils/nwztools/database/nvp/nw-a30.txt b/utils/nwztools/database/nvp/nw-a30.txt
new file mode 100644
index 0000000000..dd058fb15e
--- /dev/null
+++ b/utils/nwztools/database/nvp/nw-a30.txt
@@ -0,0 +1,92 @@
1dbg,000
2syi,001
3ubp,002
4fup,003
5prk,004
6hld,005
7rtc,006
8mid,007
9pcd,008
10ser,009
11ufn,010
12kas,011
13shp,012
14tst,013
15gty,014
16fmp,015
17sdp,016
18ncp,017
19psk,018
20nvr,077
21she,084
22btc,085
23ins,089
24ctr,090
25sku,091
26bpr,019
27bfp,020
28bfd,021
29bml,022
30apd,078
31blf,079
32slp,080
33vrt,081
34fni,082
35sid,083
36mso,086
37cng,023
38lyr,024
39dbv,025
40fur,026
41ums,027
42skd,028
43ups,029
44mdk,030
45fvi,031
46mac,032
47fpi,033
48tr0,034
49tr1,035
50e00,036
51e01,037
52e02,038
53e03,039
54e04,040
55e05,041
56e06,042
57e07,043
58e08,044
59e09,045
60e10,046
61e11,047
62e12,048
63e13,049
64e14,050
65e15,051
66e16,052
67e17,053
68e18,054
69e19,055
70e20,056
71e21,057
72e22,058
73e23,059
74e24,060
75e25,061
76e26,062
77e27,063
78e28,064
79e29,065
80e30,066
81e31,067
82clv,068
83sps,069
84rbt,070
85edw,071
86bti,072
87hdi,073
88lbi,074
89fui,075
90eri,076
91pci,087
92dbi,088
diff --git a/utils/nwztools/database/nvp/nw-e060.txt b/utils/nwztools/database/nvp/nw-e060.txt
new file mode 100644
index 0000000000..f3b5e8738a
--- /dev/null
+++ b/utils/nwztools/database/nvp/nw-e060.txt
@@ -0,0 +1,90 @@
1dbg,000
2bti,001
3hdi,002
4cng,003
5ser,004
6app,005
7eri,006
8dcc,007
9mdl,008
10fup,009
11bok,010
12shp,011
13dba,012
14dbv,013
15tr0,014
16tr1,015
17mid,016
18tst,017
19gty,018
20fui,019
21lbi,020
22dor,021
23edw,022
24ubp,023
25syi,024
26exm,025
27pcd,026
28btc,027
29rnd,028
30ufn,029
31sdp,030
32ncp,031
33kas,032
34sfi,033
35rtc,034
36bpr,035
37e00,036
38e01,037
39e02,038
40e03,039
41e04,040
42e05,041
43e06,042
44e07,043
45e08,044
46e09,045
47e10,046
48e11,047
49e12,048
50e13,049
51e14,050
52e15,051
53e16,052
54e17,053
55e18,054
56e19,055
57e20,056
58e21,057
59e22,058
60e23,059
61e24,060
62e25,061
63e26,062
64e27,063
65e28,064
66e29,065
67e30,066
68e31,067
69clv,068
70slp,069
71ipt,070
72mtm,071
73mcr,072
74mdk,073
75muk,074
76pts,075
77skt,076
78mac,077
79apd,078
80blf,079
81hld,080
82skd,081
83fmp,082
84sps,083
85msc,084
86vrt,085
87psk,086
88bml,087
89bfd,088
90bfp,089
diff --git a/utils/nwztools/database/nvp/nw-e080.txt b/utils/nwztools/database/nvp/nw-e080.txt
new file mode 100644
index 0000000000..95d2025905
--- /dev/null
+++ b/utils/nwztools/database/nvp/nw-e080.txt
@@ -0,0 +1,89 @@
1dbg,000
2syi,001
3ubp,002
4fup,003
5bok,004
6hld,005
7rtc,006
8mid,007
9pcd,008
10ser,009
11ufn,010
12kas,011
13shp,012
14tst,013
15gty,014
16fmp,015
17sdp,016
18ncp,017
19psk,018
20pts,077
21bpr,019
22bfp,020
23bfd,021
24bml,022
25apd,078
26blf,079
27slp,080
28vrt,081
29fni,082
30sid,083
31mlk,084
32mso,086
33cng,023
34dba,024
35dbv,025
36dor,026
37rnd,027
38skd,028
39sfi,029
40mdk,030
41dcc,031
42skt,032
43mtm,033
44tr0,034
45tr1,035
46e00,036
47e01,037
48e02,038
49e03,039
50e04,040
51e05,041
52e06,042
53e07,043
54e08,044
55e09,045
56e10,046
57e11,047
58e12,048
59e13,049
60e14,050
61e15,051
62e16,052
63e17,053
64e18,054
65e19,055
66e20,056
67e21,057
68e22,058
69e23,059
70e24,060
71e25,061
72e26,062
73e27,063
74e28,064
75e29,065
76e30,066
77e31,067
78clv,068
79sps,069
80mdl,070
81edw,071
82bti,072
83hdi,073
84lbi,074
85fui,075
86eri,076
87btc,085
88pci,087
89dbi,088
diff --git a/utils/nwztools/database/nvp/nw-s780.txt b/utils/nwztools/database/nvp/nw-s780.txt
new file mode 100644
index 0000000000..95d2025905
--- /dev/null
+++ b/utils/nwztools/database/nvp/nw-s780.txt
@@ -0,0 +1,89 @@
1dbg,000
2syi,001
3ubp,002
4fup,003
5bok,004
6hld,005
7rtc,006
8mid,007
9pcd,008
10ser,009
11ufn,010
12kas,011
13shp,012
14tst,013
15gty,014
16fmp,015
17sdp,016
18ncp,017
19psk,018
20pts,077
21bpr,019
22bfp,020
23bfd,021
24bml,022
25apd,078
26blf,079
27slp,080
28vrt,081
29fni,082
30sid,083
31mlk,084
32mso,086
33cng,023
34dba,024
35dbv,025
36dor,026
37rnd,027
38skd,028
39sfi,029
40mdk,030
41dcc,031
42skt,032
43mtm,033
44tr0,034
45tr1,035
46e00,036
47e01,037
48e02,038
49e03,039
50e04,040
51e05,041
52e06,042
53e07,043
54e08,044
55e09,045
56e10,046
57e11,047
58e12,048
59e13,049
60e14,050
61e15,051
62e16,052
63e17,053
64e18,054
65e19,055
66e20,056
67e21,057
68e22,058
69e23,059
70e24,060
71e25,061
72e26,062
73e27,063
74e28,064
75e29,065
76e30,066
77e31,067
78clv,068
79sps,069
80mdl,070
81edw,071
82bti,072
83hdi,073
84lbi,074
85fui,075
86eri,076
87btc,085
88pci,087
89dbi,088
diff --git a/utils/nwztools/database/nvp/nwz-a10.txt b/utils/nwztools/database/nvp/nwz-a10.txt
new file mode 100644
index 0000000000..e7ed5a0bd4
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-a10.txt
@@ -0,0 +1,90 @@
1dbg,000
2syi,001
3ubp,002
4fup,003
5bok,004
6hld,005
7rtc,006
8mid,007
9pcd,008
10ser,009
11ufn,010
12kas,011
13shp,012
14tst,013
15gty,014
16fmp,015
17sdp,016
18ncp,017
19psk,018
20pts,077
21btc,085
22bpr,019
23bfp,020
24bfd,021
25bml,022
26apd,078
27blf,079
28slp,080
29vrt,081
30fni,082
31sid,083
32mlk,084
33mso,086
34sdc,089
35cng,023
36dba,024
37dbv,025
38dor,026
39rnd,027
40skd,028
41sfi,029
42mdk,030
43dcc,031
44skt,032
45mtm,033
46tr0,034
47tr1,035
48e00,036
49e01,037
50e02,038
51e03,039
52e04,040
53e05,041
54e06,042
55e07,043
56e08,044
57e09,045
58e10,046
59e11,047
60e12,048
61e13,049
62e14,050
63e15,051
64e16,052
65e17,053
66e18,054
67e19,055
68e20,056
69e21,057
70e22,058
71e23,059
72e24,060
73e25,061
74e26,062
75e27,063
76e28,064
77e29,065
78e30,066
79e31,067
80clv,068
81sps,069
82mdl,070
83edw,071
84bti,072
85hdi,073
86lbi,074
87fui,075
88eri,076
89pci,087
90dbi,088
diff --git a/utils/nwztools/database/nvp/nwz-a20.txt b/utils/nwztools/database/nvp/nwz-a20.txt
new file mode 100644
index 0000000000..e7ed5a0bd4
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-a20.txt
@@ -0,0 +1,90 @@
1dbg,000
2syi,001
3ubp,002
4fup,003
5bok,004
6hld,005
7rtc,006
8mid,007
9pcd,008
10ser,009
11ufn,010
12kas,011
13shp,012
14tst,013
15gty,014
16fmp,015
17sdp,016
18ncp,017
19psk,018
20pts,077
21btc,085
22bpr,019
23bfp,020
24bfd,021
25bml,022
26apd,078
27blf,079
28slp,080
29vrt,081
30fni,082
31sid,083
32mlk,084
33mso,086
34sdc,089
35cng,023
36dba,024
37dbv,025
38dor,026
39rnd,027
40skd,028
41sfi,029
42mdk,030
43dcc,031
44skt,032
45mtm,033
46tr0,034
47tr1,035
48e00,036
49e01,037
50e02,038
51e03,039
52e04,040
53e05,041
54e06,042
55e07,043
56e08,044
57e09,045
58e10,046
59e11,047
60e12,048
61e13,049
62e14,050
63e15,051
64e16,052
65e17,053
66e18,054
67e19,055
68e20,056
69e21,057
70e22,058
71e23,059
72e24,060
73e25,061
74e26,062
75e27,063
76e28,064
77e29,065
78e30,066
79e31,067
80clv,068
81sps,069
82mdl,070
83edw,071
84bti,072
85hdi,073
86lbi,074
87fui,075
88eri,076
89pci,087
90dbi,088
diff --git a/utils/nwztools/database/nvp/nwz-a850.txt b/utils/nwztools/database/nvp/nwz-a850.txt
new file mode 100644
index 0000000000..d5f5a05cc0
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-a850.txt
@@ -0,0 +1,79 @@
1dbg,000
2bti,001
3hdi,002
4cng,003
5ser,004
6app,005
7eri,006
8dcc,007
9mdl,008
10fup,009
11bok,010
12shp,011
13dba,012
14dbv,013
15tr0,014
16tr1,015
17mid,016
18tst,017
19gty,018
20fui,019
21lbi,020
22dor,021
23edw,022
24ubp,023
25syi,024
26exm,025
27pcd,026
28rnd,028
29ufn,029
30sdp,030
31ncp,031
32kas,032
33rtc,034
34bpr,035
35e00,036
36e01,037
37e02,038
38e03,039
39e04,040
40e05,041
41e06,042
42e07,043
43e08,044
44e09,045
45e10,046
46e11,047
47e12,048
48e13,049
49e14,050
50e15,051
51e16,052
52e17,053
53e18,054
54e19,055
55e20,056
56e21,057
57e22,058
58e23,059
59e24,060
60e25,061
61e26,062
62e27,063
63e28,064
64e29,065
65e30,066
66e31,067
67clv,068
68slp,069
69ipt,070
70pts,075
71skt,076
72mac,077
73apd,078
74blf,079
75hld,080
76skd,081
77fmp,082
78sps,083
79msc,084
diff --git a/utils/nwztools/database/nvp/nwz-a860.txt b/utils/nwztools/database/nvp/nwz-a860.txt
new file mode 100644
index 0000000000..f3b5e8738a
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-a860.txt
@@ -0,0 +1,90 @@
1dbg,000
2bti,001
3hdi,002
4cng,003
5ser,004
6app,005
7eri,006
8dcc,007
9mdl,008
10fup,009
11bok,010
12shp,011
13dba,012
14dbv,013
15tr0,014
16tr1,015
17mid,016
18tst,017
19gty,018
20fui,019
21lbi,020
22dor,021
23edw,022
24ubp,023
25syi,024
26exm,025
27pcd,026
28btc,027
29rnd,028
30ufn,029
31sdp,030
32ncp,031
33kas,032
34sfi,033
35rtc,034
36bpr,035
37e00,036
38e01,037
39e02,038
40e03,039
41e04,040
42e05,041
43e06,042
44e07,043
45e08,044
46e09,045
47e10,046
48e11,047
49e12,048
50e13,049
51e14,050
52e15,051
53e16,052
54e17,053
55e18,054
56e19,055
57e20,056
58e21,057
59e22,058
60e23,059
61e24,060
62e25,061
63e26,062
64e27,063
65e28,064
66e29,065
67e30,066
68e31,067
69clv,068
70slp,069
71ipt,070
72mtm,071
73mcr,072
74mdk,073
75muk,074
76pts,075
77skt,076
78mac,077
79apd,078
80blf,079
81hld,080
82skd,081
83fmp,082
84sps,083
85msc,084
86vrt,085
87psk,086
88bml,087
89bfd,088
90bfp,089
diff --git a/utils/nwztools/database/nvp/nwz-e350.txt b/utils/nwztools/database/nvp/nwz-e350.txt
new file mode 100644
index 0000000000..d5f5a05cc0
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-e350.txt
@@ -0,0 +1,79 @@
1dbg,000
2bti,001
3hdi,002
4cng,003
5ser,004
6app,005
7eri,006
8dcc,007
9mdl,008
10fup,009
11bok,010
12shp,011
13dba,012
14dbv,013
15tr0,014
16tr1,015
17mid,016
18tst,017
19gty,018
20fui,019
21lbi,020
22dor,021
23edw,022
24ubp,023
25syi,024
26exm,025
27pcd,026
28rnd,028
29ufn,029
30sdp,030
31ncp,031
32kas,032
33rtc,034
34bpr,035
35e00,036
36e01,037
37e02,038
38e03,039
39e04,040
40e05,041
41e06,042
42e07,043
43e08,044
44e09,045
45e10,046
46e11,047
47e12,048
48e13,049
49e14,050
50e15,051
51e16,052
52e17,053
53e18,054
54e19,055
55e20,056
56e21,057
57e22,058
58e23,059
59e24,060
60e25,061
61e26,062
62e27,063
63e28,064
64e29,065
65e30,066
66e31,067
67clv,068
68slp,069
69ipt,070
70pts,075
71skt,076
72mac,077
73apd,078
74blf,079
75hld,080
76skd,081
77fmp,082
78sps,083
79msc,084
diff --git a/utils/nwztools/database/nvp/nwz-e450.txt b/utils/nwztools/database/nvp/nwz-e450.txt
new file mode 100644
index 0000000000..d5f5a05cc0
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-e450.txt
@@ -0,0 +1,79 @@
1dbg,000
2bti,001
3hdi,002
4cng,003
5ser,004
6app,005
7eri,006
8dcc,007
9mdl,008
10fup,009
11bok,010
12shp,011
13dba,012
14dbv,013
15tr0,014
16tr1,015
17mid,016
18tst,017
19gty,018
20fui,019
21lbi,020
22dor,021
23edw,022
24ubp,023
25syi,024
26exm,025
27pcd,026
28rnd,028
29ufn,029
30sdp,030
31ncp,031
32kas,032
33rtc,034
34bpr,035
35e00,036
36e01,037
37e02,038
38e03,039
39e04,040
40e05,041
41e06,042
42e07,043
43e08,044
44e09,045
45e10,046
46e11,047
47e12,048
48e13,049
49e14,050
50e15,051
51e16,052
52e17,053
53e18,054
54e19,055
55e20,056
56e21,057
57e22,058
58e23,059
59e24,060
60e25,061
61e26,062
62e27,063
63e28,064
64e29,065
65e30,066
66e31,067
67clv,068
68slp,069
69ipt,070
70pts,075
71skt,076
72mac,077
73apd,078
74blf,079
75hld,080
76skd,081
77fmp,082
78sps,083
79msc,084
diff --git a/utils/nwztools/database/nvp/nwz-e460.txt b/utils/nwztools/database/nvp/nwz-e460.txt
new file mode 100644
index 0000000000..f3b5e8738a
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-e460.txt
@@ -0,0 +1,90 @@
1dbg,000
2bti,001
3hdi,002
4cng,003
5ser,004
6app,005
7eri,006
8dcc,007
9mdl,008
10fup,009
11bok,010
12shp,011
13dba,012
14dbv,013
15tr0,014
16tr1,015
17mid,016
18tst,017
19gty,018
20fui,019
21lbi,020
22dor,021
23edw,022
24ubp,023
25syi,024
26exm,025
27pcd,026
28btc,027
29rnd,028
30ufn,029
31sdp,030
32ncp,031
33kas,032
34sfi,033
35rtc,034
36bpr,035
37e00,036
38e01,037
39e02,038
40e03,039
41e04,040
42e05,041
43e06,042
44e07,043
45e08,044
46e09,045
47e10,046
48e11,047
49e12,048
50e13,049
51e14,050
52e15,051
53e16,052
54e17,053
55e18,054
56e19,055
57e20,056
58e21,057
59e22,058
60e23,059
61e24,060
62e25,061
63e26,062
64e27,063
65e28,064
66e29,065
67e30,066
68e31,067
69clv,068
70slp,069
71ipt,070
72mtm,071
73mcr,072
74mdk,073
75muk,074
76pts,075
77skt,076
78mac,077
79apd,078
80blf,079
81hld,080
82skd,081
83fmp,082
84sps,083
85msc,084
86vrt,085
87psk,086
88bml,087
89bfd,088
90bfp,089
diff --git a/utils/nwztools/database/nvp/nwz-e470.txt b/utils/nwztools/database/nvp/nwz-e470.txt
new file mode 100644
index 0000000000..d69cd3ac6b
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-e470.txt
@@ -0,0 +1,87 @@
1dbg,000
2syi,001
3ubp,002
4fup,003
5bok,004
6hld,005
7rtc,006
8mid,007
9pcd,008
10ser,009
11ufn,010
12kas,011
13shp,012
14tst,013
15gty,014
16fmp,015
17sdp,016
18ncp,017
19psk,018
20pts,077
21bpr,019
22bfp,020
23bfd,021
24bml,022
25apd,078
26blf,079
27slp,080
28vrt,081
29fni,082
30sid,083
31mlk,084
32mso,086
33cng,023
34dba,024
35dbv,025
36dor,026
37rnd,027
38skd,028
39sfi,029
40mdk,030
41dcc,031
42skt,032
43mtm,033
44tr0,034
45tr1,035
46e00,036
47e01,037
48e02,038
49e03,039
50e04,040
51e05,041
52e06,042
53e07,043
54e08,044
55e09,045
56e10,046
57e11,047
58e12,048
59e13,049
60e14,050
61e15,051
62e16,052
63e17,053
64e18,054
65e19,055
66e20,056
67e21,057
68e22,058
69e23,059
70e24,060
71e25,061
72e26,062
73e27,063
74e28,064
75e29,065
76e30,066
77e31,067
78clv,068
79sps,069
80mdl,070
81edw,071
82bti,072
83hdi,073
84lbi,074
85fui,075
86eri,076
87btc,085
diff --git a/utils/nwztools/database/nvp/nwz-e580.txt b/utils/nwztools/database/nvp/nwz-e580.txt
new file mode 100644
index 0000000000..95d2025905
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-e580.txt
@@ -0,0 +1,89 @@
1dbg,000
2syi,001
3ubp,002
4fup,003
5bok,004
6hld,005
7rtc,006
8mid,007
9pcd,008
10ser,009
11ufn,010
12kas,011
13shp,012
14tst,013
15gty,014
16fmp,015
17sdp,016
18ncp,017
19psk,018
20pts,077
21bpr,019
22bfp,020
23bfd,021
24bml,022
25apd,078
26blf,079
27slp,080
28vrt,081
29fni,082
30sid,083
31mlk,084
32mso,086
33cng,023
34dba,024
35dbv,025
36dor,026
37rnd,027
38skd,028
39sfi,029
40mdk,030
41dcc,031
42skt,032
43mtm,033
44tr0,034
45tr1,035
46e00,036
47e01,037
48e02,038
49e03,039
50e04,040
51e05,041
52e06,042
53e07,043
54e08,044
55e09,045
56e10,046
57e11,047
58e12,048
59e13,049
60e14,050
61e15,051
62e16,052
63e17,053
64e18,054
65e19,055
66e20,056
67e21,057
68e22,058
69e23,059
70e24,060
71e25,061
72e26,062
73e27,063
74e28,064
75e29,065
76e30,066
77e31,067
78clv,068
79sps,069
80mdl,070
81edw,071
82bti,072
83hdi,073
84lbi,074
85fui,075
86eri,076
87btc,085
88pci,087
89dbi,088
diff --git a/utils/nwztools/database/nvp/nwz-s760.txt b/utils/nwztools/database/nvp/nwz-s760.txt
new file mode 100644
index 0000000000..f3b5e8738a
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-s760.txt
@@ -0,0 +1,90 @@
1dbg,000
2bti,001
3hdi,002
4cng,003
5ser,004
6app,005
7eri,006
8dcc,007
9mdl,008
10fup,009
11bok,010
12shp,011
13dba,012
14dbv,013
15tr0,014
16tr1,015
17mid,016
18tst,017
19gty,018
20fui,019
21lbi,020
22dor,021
23edw,022
24ubp,023
25syi,024
26exm,025
27pcd,026
28btc,027
29rnd,028
30ufn,029
31sdp,030
32ncp,031
33kas,032
34sfi,033
35rtc,034
36bpr,035
37e00,036
38e01,037
39e02,038
40e03,039
41e04,040
42e05,041
43e06,042
44e07,043
45e08,044
46e09,045
47e10,046
48e11,047
49e12,048
50e13,049
51e14,050
52e15,051
53e16,052
54e17,053
55e18,054
56e19,055
57e20,056
58e21,057
59e22,058
60e23,059
61e24,060
62e25,061
63e26,062
64e27,063
65e28,064
66e29,065
67e30,066
68e31,067
69clv,068
70slp,069
71ipt,070
72mtm,071
73mcr,072
74mdk,073
75muk,074
76pts,075
77skt,076
78mac,077
79apd,078
80blf,079
81hld,080
82skd,081
83fmp,082
84sps,083
85msc,084
86vrt,085
87psk,086
88bml,087
89bfd,088
90bfp,089
diff --git a/utils/nwztools/database/nvp/nwz-zx100.txt b/utils/nwztools/database/nvp/nwz-zx100.txt
new file mode 100644
index 0000000000..e7ed5a0bd4
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-zx100.txt
@@ -0,0 +1,90 @@
1dbg,000
2syi,001
3ubp,002
4fup,003
5bok,004
6hld,005
7rtc,006
8mid,007
9pcd,008
10ser,009
11ufn,010
12kas,011
13shp,012
14tst,013
15gty,014
16fmp,015
17sdp,016
18ncp,017
19psk,018
20pts,077
21btc,085
22bpr,019
23bfp,020
24bfd,021
25bml,022
26apd,078
27blf,079
28slp,080
29vrt,081
30fni,082
31sid,083
32mlk,084
33mso,086
34sdc,089
35cng,023
36dba,024
37dbv,025
38dor,026
39rnd,027
40skd,028
41sfi,029
42mdk,030
43dcc,031
44skt,032
45mtm,033
46tr0,034
47tr1,035
48e00,036
49e01,037
50e02,038
51e03,039
52e04,040
53e05,041
54e06,042
55e07,043
56e08,044
57e09,045
58e10,046
59e11,047
60e12,048
61e13,049
62e14,050
63e15,051
64e16,052
65e17,053
66e18,054
67e19,055
68e20,056
69e21,057
70e22,058
71e23,059
72e24,060
73e25,061
74e26,062
75e27,063
76e28,064
77e29,065
78e30,066
79e31,067
80clv,068
81sps,069
82mdl,070
83edw,071
84bti,072
85hdi,073
86lbi,074
87fui,075
88eri,076
89pci,087
90dbi,088
diff --git a/utils/nwztools/database/nvp/nwz-zx2.txt b/utils/nwztools/database/nvp/nwz-zx2.txt
new file mode 100644
index 0000000000..ebc6c8d56d
--- /dev/null
+++ b/utils/nwztools/database/nvp/nwz-zx2.txt
@@ -0,0 +1,90 @@
1dbg,000
2bti,001
3hdi,002
4cng,003
5ser,004
6app,005
7eri,006
8dcc,007
9mdl,008
10fup,009
11bok,010
12shp,011
13dba,012
14dbv,013
15tr0,014
16tr1,015
17mid,016
18tst,017
19gty,018
20fui,019
21lbi,020
22dor,021
23edw,022
24ubp,023
25syi,024
26exm,025
27pcd,026
28cgp,027
29rnd,028
30ufn,029
31sdp,030
32ncp,031
33kas,032
34sfi,033
35rtc,034
36bpr,035
37e00,036
38e01,037
39e02,038
40e03,039
41e04,040
42e05,041
43e06,042
44e07,043
45e08,044
46e09,045
47e10,046
48e11,047
49e12,048
50e13,049
51e14,050
52e15,051
53e16,052
54e17,053
55e18,054
56e19,055
57e20,056
58e21,057
59e22,058
60e23,059
61e24,060
62e25,061
63e26,062
64e27,063
65e28,064
66e29,065
67e30,066
68e31,067
69clv,068
70slp,069
71ipt,070
72mtm,071
73mcr,072
74mdk,073
75muk,074
76pts,075
77skt,076
78mac,077
79apd,078
80blf,079
81hld,080
82skd,081
83fmp,082
84sps,083
85msc,084
86vrt,085
87psk,086
88bml,087
89bfd,088
90bfp,089
diff --git a/utils/nwztools/database/nvp/parse_all_nvp_headers.sh b/utils/nwztools/database/nvp/parse_all_nvp_headers.sh
new file mode 100755
index 0000000000..e84eaae8f5
--- /dev/null
+++ b/utils/nwztools/database/nvp/parse_all_nvp_headers.sh
@@ -0,0 +1,33 @@
1#
2# usage: parse_all_nvp_headers /path/to/directory
3#
4# the expected structure is:
5# nwz-*/<kernel>
6# nw-*/<kernel/
7# where <kernel> must be of the form
8# linux-kernel-*.tgz
9#
10if [ "$#" -lt 1 ]; then
11 >&2 echo "usage: parse_all_nvp_header.sh /path/to/directory"
12 exit 1
13fi
14
15# list interesting directories
16for dir in `find "$1" -maxdepth 1 -name "nw-*" -or -name "nwz-*"`
17do
18 # extract codename
19 codename=`basename "$dir"`
20 # only consider linux based targets
21 if [ -e "$dir/not_linux" ]; then
22 #echo "$codename: not linux based"
23 continue
24 fi
25 # check if we can find a kernel
26 kernel_tgz=`find "$dir" -maxdepth 1 -name "linux-kernel-*.tgz"`
27 if [ "$kernel_tgz" == "" ]; then
28 echo "$codename: no kernel found"
29 continue
30 fi
31 echo "$codename: found kernel `basename $kernel_tgz`"
32 ./parse_nvp_header.sh "$kernel_tgz" > "$codename.txt"
33done
diff --git a/utils/nwztools/database/nvp/parse_all_nvp_nodes.sh b/utils/nwztools/database/nvp/parse_all_nvp_nodes.sh
new file mode 100755
index 0000000000..3aae79deb0
--- /dev/null
+++ b/utils/nwztools/database/nvp/parse_all_nvp_nodes.sh
@@ -0,0 +1,32 @@
1#
2# usage: parse_all_nvp_nodes /path/to/directory
3#
4# the expected structure is:
5# nwz-*/rootfs.tar
6# nwz-*/rootfs.tar
7#
8if [ "$#" -lt 1 ]; then
9 >&2 echo "usage: parse_all_nvp_header.sh /path/to/directory"
10 exit 1
11fi
12
13# list interesting directories
14for dir in `find "$1" -maxdepth 1 -name "nw-*" -or -name "nwz-*"`
15do
16 # extract codename
17 codename=`basename "$dir"`
18 # only consider linux based targets
19 if [ -e "$dir/not_linux" ]; then
20 #echo "$codename: not linux based"
21 continue
22 fi
23 # check if we can find a rootfs
24 rootfs_tgz="$dir/rootfs.tgz"
25 if [ ! -e "$rootfs_tgz" ]; then
26 echo "$codename: no rootfs found"
27 continue
28 fi
29 echo "$codename: found rootfs `basename $rootfs_tgz`"
30 ./parse_nvp_nodes.sh "$rootfs_tgz" "nodes-$codename.txt"
31done
32
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}'
diff --git a/utils/nwztools/database/nvp/parse_nvp_nodes.sh b/utils/nwztools/database/nvp/parse_nvp_nodes.sh
new file mode 100755
index 0000000000..cf42504e32
--- /dev/null
+++ b/utils/nwztools/database/nvp/parse_nvp_nodes.sh
@@ -0,0 +1,58 @@
1# usage
2# parse_nodes.sh /path/to/icx_nvp_emmc.ko output_file
3# parse_nodes.sh /path/to/rootfs/dir output_file
4# parse_nodes.sh /path/to/rootfs.tgz output_file
5#
6if [ "$#" -lt 2 ]; then
7 >&2 echo "usage: parse_header.sh /path/to/icx_nvp.ko|/path/to/rootfs/dir|/path/to/rootfs.tgz output_file"
8 exit 1
9fi
10
11FILE="$1"
12IN_TGZ="0"
13OUTPUT="$2"
14
15# for directories, list all files
16if [ -d "$FILE" ]; then
17 LIST=`find "$FILE"`
18else
19 # otherwise try un unpack it using tar, to see if it's an archive
20 LIST=`tar -tzf "$FILE"`
21 if [ "$?" == 0 ]; then
22 IN_TGZ="1"
23 TGZ="$FILE"
24 else
25 # assume the input is just the right file
26 LIST="$FILE"
27 fi
28fi
29
30# look for icx_nvp_emmc.ko
31LIST=`echo "$LIST" | grep "icx[[:digit:]]*_nvp[[:alpha:]_]*.ko"`
32LIST_CNT=`echo "$LIST" | wc -l`
33if [ "$LIST" == "" ]; then
34 >&2 echo "No icx nvp file found"
35 exit 1
36elif [ "$LIST_CNT" != "1" ]; then
37 >&2 echo "Several matches for icx nvp:"
38 >&2 echo "$LIST"
39 exit 1
40else
41 FILE="$LIST"
42fi
43
44# if file is in archive, we need to extract it
45if [ "$IN_TGZ" = "1" ]; then
46 >&2 echo "Extracting $FILE from $TGZ"
47 TMP=`mktemp`
48 tar -Ozxf "$TGZ" "$FILE" > $TMP
49 if [ "$?" != 0 ]; then
50 >&2 echo "Extraction failed"
51 exit 1
52 fi
53 FILE="$TMP"
54else
55 >&2 echo "Analyzing $FILE"
56fi
57
58./nvptool -x "$FILE" -o "$OUTPUT" >/dev/null