summaryrefslogtreecommitdiffstats
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.tar.bz2
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 @@
+DEFINES=
+CC=gcc
+CXX=g++
+LD=g++
+PROFILE=
+CFLAGS=-g $(PROFILE) -std=c99 -W -Wall $(DEFINES) `xml2-config --cflags`
+CXXFLAGS=-g $(PROFILE) -W -Wall $(DEFINES) `xml2-config --cflags`
+LDFLAGS=$(PROFILE) `xml2-config --libs`
+BINS=nvptool
+
+all: $(BINS)
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+%.o: %.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+nvptool: nvptool.o
+ $(LD) -o $@ $^ $(LDFLAGS)
+
+clean:
+ rm -fr *.o
+
+veryclean:
+ 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 @@
+The NVP map varies a lot from players to players, it is inconceivable to build
+it by hand. The approach taken is to extract it from the kernel of each player.
+Since Sony provides the kernel of all players, it is 'only' a matter of
+downloading all of them. A bit of back story on the NVP: it is non-volatile
+area of the flash that is divided in regions and then "sectors" (unrelated to
+hard drive sectors). Each "sector" stores the data of a "node". The ABI
+between the NVP driver and the userspace is an index: the userspace gives the
+index of a node, and then drives looksup its table to see where it is and what
+is its size. The index map changes over time so Sony introduces standard "names"
+for its entries, those are 3-letters acronym (for example "fup" or "bti" or "shp")
+that have a corresponding index. For some reason, the driver also contains a
+description of the nodes, in english (so "bti" stands for "boot image").
+
+parse_nvp_header.sh
+===================
+
+This script is given a file name, a kernel directory or a kernel tgz and it will
+try to extract the mapping automatically. It produces a list of pairs
+ <node>,<name>
+where <node> is the index of the node (that's the only thing that is usable on
+a running device) and <name> is the standard name of the node. Note that is
+some kind of acronym (like 'fup') and the description needs to be generated
+separatly (see other section).
+
+parse_all_nvp_headers.sh
+========================
+
+This scripts expects a directory to have the following structure:
+ dir/
+ nwz-a10/
+ linux-kernel-*.tgz
+ nwz-e460/
+ linxu-kernel-*.tgz
+ ...
+Each sudirectory must the series name (as used in ../series.txt) and the kernel
+must be a tgz (end in .tgz and not .tar.gz) of the form linux-kernel-*.tgz. Usually
+the variable bit will be the version but some kernels have unknown versions. It
+will then run parse_nvp_header.sh on each of them and store the result in a
+file called <series name>.txt
+
+NOTE: the kernel can be symlinks to other files
+
+nvptool
+=======
+
+The kernel headers do no contain the description of the nvp node names.
+This one can be extract from the icx_nvp[_emmc].ko driver on target using complicated
+elf parsing done by nvptool. Technically nvptoo can find much more information
+like the node -> humanname mapping as well and the actual sector on the disk but
+since we can already extract it easily from the headers, we only extract description
+names from it.
+
+parse_all_nvp_nodes.sh
+======================
+
+This scripts expects a directory to have the following structure:
+ dir/
+ nwz-a10/
+ rootfs.tgz
+ nwz-e460/
+ rootfs.tgz
+ ...
+Each sudirectory must the series name (as used in ../series.txt) and the rootfs
+must be a tar. It will then extract the relevant icx_nvp driver from it and run
+nvptool on it to produce a file called nodes-<series name>.txt
+
+NOTE: 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 @@
+1,4,system information
+2,32,u-boot password
+3,4,firmware update flag
+4,4,beep ok flag
+5,4,hold mode
+6,16,rtc alarm
+7,64,model id
+8,5,product code
+9,16,serial number
+10,8,update file name
+11,64,key and signature
+12,32,ship information
+13,4,test mode flag
+14,4,getty mode flag
+15,16,fm parameter
+16,64,sound driver parameter
+17,64,noise cancel driver parameter
+18,512,bluetooth pskey
+77,4,wifi protected setup
+85,4,battery calibration
+19,2048,bluetooth parameter
+20,512,btmw factory pair info
+21,512,btmw factory scdb
+22,4,btmw log mode flag
+78,4,application debug mode flag
+79,4,browser log mode flag
+80,4,time out to sleep
+81,4,europe vol regulation flag
+82,4,function information
+83,4,service id
+84,4,marlin key
+86,4,MSC only mode flag
+89,4,SD Card export flag
+23,704,aad/empr key
+24,160,aad icv
+25,520,empr icv
+26,4,key mode (debug/release)
+27,64,random data
+28,8224,slacker id file
+29,64,starfish id
+30,33024,marlin device key
+31,20,secure clock
+32,16,slacker time
+33,64,marlin time
+34,16384,EKB 0
+35,16384,EKB 1
+36,1024,EMPR 0
+37,1024,EMPR 1
+38,1024,EMPR 2
+39,1024,EMPR 3
+40,1024,EMPR 4
+41,1024,EMPR 5
+42,1024,EMPR 6
+43,1024,EMPR 7
+44,1024,EMPR 8
+45,1024,EMPR 9
+46,1024,EMPR 10
+47,1024,EMPR 11
+48,1024,EMPR 12
+49,1024,EMPR 13
+50,1024,EMPR 14
+51,1024,EMPR 15
+52,1024,EMPR 16
+53,1024,EMPR 17
+54,1024,EMPR 18
+55,1024,EMPR 19
+56,1024,EMPR 20
+57,1024,EMPR 21
+58,1024,EMPR 22
+59,1024,EMPR 23
+60,1024,EMPR 24
+61,1024,EMPR 25
+62,1024,EMPR 26
+63,1024,EMPR 27
+64,1024,EMPR 28
+65,1024,EMPR 29
+66,1024,EMPR 30
+67,1024,EMPR 31
+68,4,color variation
+69,4,speaker ship info
+70,8,middleware parameter
+71,4,quick shutdown flag
+72,262144,boot image
+73,262144,hold image
+74,262144,low battery image
+75,262144,update image
+76,262144,update error image
+87,262144,precharge image
+88,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 @@
+1,4,system information
+2,32,u-boot password
+3,4,firmware update flag
+4,4,beep ok flag
+5,4,hold mode
+6,16,rtc alarm
+7,64,model id
+8,5,product code
+9,16,serial number
+10,8,update file name
+11,64,key and signature
+12,32,ship information
+13,4,test mode flag
+14,4,getty mode flag
+15,16,fm parameter
+16,64,sound driver parameter
+17,64,noise cancel driver parameter
+18,512,bluetooth pskey
+77,4,wifi protected setup
+85,4,battery calibration
+19,2048,bluetooth parameter
+20,512,btmw factory pair info
+21,512,btmw factory scdb
+22,4,btmw log mode flag
+78,4,application debug mode flag
+79,4,browser log mode flag
+80,4,time out to sleep
+81,4,europe vol regulation flag
+82,4,function information
+83,4,service id
+84,4,marlin key
+86,4,MSC only mode flag
+89,4,SD Card export flag
+23,704,aad/empr key
+24,160,aad icv
+25,520,empr icv
+26,4,key mode (debug/release)
+27,64,random data
+28,8224,slacker id file
+29,64,starfish id
+30,33024,marlin device key
+31,20,secure clock
+32,16,slacker time
+33,64,marlin time
+34,16384,EKB 0
+35,16384,EKB 1
+36,1024,EMPR 0
+37,1024,EMPR 1
+38,1024,EMPR 2
+39,1024,EMPR 3
+40,1024,EMPR 4
+41,1024,EMPR 5
+42,1024,EMPR 6
+43,1024,EMPR 7
+44,1024,EMPR 8
+45,1024,EMPR 9
+46,1024,EMPR 10
+47,1024,EMPR 11
+48,1024,EMPR 12
+49,1024,EMPR 13
+50,1024,EMPR 14
+51,1024,EMPR 15
+52,1024,EMPR 16
+53,1024,EMPR 17
+54,1024,EMPR 18
+55,1024,EMPR 19
+56,1024,EMPR 20
+57,1024,EMPR 21
+58,1024,EMPR 22
+59,1024,EMPR 23
+60,1024,EMPR 24
+61,1024,EMPR 25
+62,1024,EMPR 26
+63,1024,EMPR 27
+64,1024,EMPR 28
+65,1024,EMPR 29
+66,1024,EMPR 30
+67,1024,EMPR 31
+68,4,color variation
+69,4,speaker ship info
+70,8,middleware parameter
+71,4,quick shutdown flag
+72,262144,boot image
+73,262144,hold image
+74,262144,low battery image
+75,262144,update image
+76,262144,update error image
+87,262144,precharge image
+88,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 @@
+24,4,system information
+23,32,u-boot password
+9,4,firmware update flag
+10,4,beep ok flag
+34,16,rtc alarm
+80,4,hold mode
+16,64,model id
+4,16,serial number
+11,32,ship information
+68,4,color variation
+26,5,product code
+29,8,update file name
+32,64,key and signature
+17,4,test mode flag
+18,4,getty mode flag
+70,4,disable iptable flag
+30,64,sound driver parameter
+31,64,noise cancel driver parameter
+77,6,wifi mac address
+75,4,wifi protected setup
+82,16,fm parameter
+83,4,speaker ship info
+84,4,mass storage class mode
+25,4,exception monitor mode
+27,4,battery calibration
+86,512,bluetooth pskey
+5,4096,application parameter
+7,20,secure clock
+12,160,aad icv
+13,520,empr key
+76,16,slacker time
+21,4,key mode (debug/release)
+71,64,marlin time
+72,16384,marlin crl
+89,512,btmw factory pair info
+88,512,btmw factory scdb
+87,4,btmw log mode flag
+85,4,europe vol regulation flag
+8,8,middleware parameter
+22,4,quick shutdown flag
+69,4,time out to sleep
+78,4,application debug mode flag
+79,4,browser log mode flag
+3,704,aad key
+28,64,wmt key
+81,8224,slacker id file
+73,33024,marlin device key
+33,64,starfish id
+35,2048,bluetooth address
+14,16384,EKB 0
+15,16384,EKB 1
+74,24576,marlin user key
+36,1024,EMPR 0
+37,1024,EMPR 1
+38,1024,EMPR 2
+39,1024,EMPR 3
+40,1024,EMPR 4
+41,1024,EMPR 5
+42,1024,EMPR 6
+43,1024,EMPR 7
+44,1024,EMPR 8
+45,1024,EMPR 9
+46,1024,EMPR 10
+47,1024,EMPR 11
+48,1024,EMPR 12
+49,1024,EMPR 13
+50,1024,EMPR 14
+51,1024,EMPR 15
+52,1024,EMPR 16
+53,1024,EMPR 17
+54,1024,EMPR 18
+55,1024,EMPR 19
+56,1024,EMPR 20
+57,1024,EMPR 21
+58,1024,EMPR 22
+59,1024,EMPR 23
+60,1024,EMPR 24
+61,1024,EMPR 25
+62,1024,EMPR 26
+63,1024,EMPR 27
+64,1024,EMPR 28
+65,1024,EMPR 29
+66,1024,EMPR 30
+67,1024,EMPR 31
+1,262144,boot image
+2,262144,hold image
+20,262144,low battery image
+19,262144,update image
+6,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 @@
+24,4,system information
+23,32,u-boot password
+9,4,firmware update flag
+10,4,beep ok flag
+34,16,rtc alarm
+80,4,hold mode
+16,64,model id
+4,16,serial number
+11,32,ship information
+68,4,color variation
+26,5,product code
+29,8,update file name
+32,64,key and signature
+17,4,test mode flag
+18,4,getty mode flag
+70,4,disable iptable flag
+30,64,sound driver parameter
+31,64,noise cancel driver parameter
+77,6,wifi mac address
+75,4,wifi protected setup
+82,16,fm parameter
+83,4,speaker ship info
+84,4,mass storage class mode
+25,4,exception monitor mode
+5,4096,application parameter
+35,2048,bluetooth parameter
+8,8,middleware parameter
+22,4,quick shutdown flag
+69,4,time out to sleep
+78,4,application debug mode flag
+79,4,browser log mode flag
+7,20,secure clock
+3,704,aad key
+12,160,aad icv
+13,520,empr key
+28,64,random data
+76,16,slacker time
+21,4,key mode (debug/release)
+81,8224,slacker id file
+14,16384,EKB 0
+15,16384,EKB 1
+36,1024,EMPR 0
+37,1024,EMPR 1
+38,1024,EMPR 2
+39,1024,EMPR 3
+40,1024,EMPR 4
+41,1024,EMPR 5
+42,1024,EMPR 6
+43,1024,EMPR 7
+44,1024,EMPR 8
+45,1024,EMPR 9
+46,1024,EMPR 10
+47,1024,EMPR 11
+48,1024,EMPR 12
+49,1024,EMPR 13
+50,1024,EMPR 14
+51,1024,EMPR 15
+52,1024,EMPR 16
+53,1024,EMPR 17
+54,1024,EMPR 18
+55,1024,EMPR 19
+56,1024,EMPR 20
+57,1024,EMPR 21
+58,1024,EMPR 22
+59,1024,EMPR 23
+60,1024,EMPR 24
+61,1024,EMPR 25
+62,1024,EMPR 26
+63,1024,EMPR 27
+64,1024,EMPR 28
+65,1024,EMPR 29
+66,1024,EMPR 30
+67,1024,EMPR 31
+1,262144,boot image
+2,262144,hold image
+20,262144,low battery image
+19,262144,update image
+6,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 @@
+24,4,system information
+23,32,u-boot password
+9,4,firmware update flag
+10,4,beep ok flag
+34,16,rtc alarm
+80,4,hold mode
+16,64,model id
+4,16,serial number
+11,32,ship information
+68,4,color variation
+26,5,product code
+29,8,update file name
+32,64,key and signature
+17,4,test mode flag
+18,4,getty mode flag
+70,4,disable iptable flag
+30,64,sound driver parameter
+31,64,noise cancel driver parameter
+77,6,wifi mac address
+75,4,wifi protected setup
+82,16,fm parameter
+83,4,speaker ship info
+84,4,mass storage class mode
+25,4,exception monitor mode
+27,4,battery calibration
+86,512,bluetooth pskey
+5,4096,application parameter
+7,20,secure clock
+12,160,aad icv
+13,520,empr key
+76,16,slacker time
+21,4,key mode (debug/release)
+71,64,marlin time
+72,16384,marlin crl
+89,512,btmw factory pair info
+88,512,btmw factory scdb
+87,4,btmw log mode flag
+85,4,europe vol regulation flag
+8,8,middleware parameter
+22,4,quick shutdown flag
+69,4,time out to sleep
+78,4,application debug mode flag
+79,4,browser log mode flag
+3,704,aad key
+28,64,wmt key
+81,8224,slacker id file
+73,33024,marlin device key
+33,64,starfish id
+35,2048,bluetooth address
+14,16384,EKB 0
+15,16384,EKB 1
+74,24576,marlin user key
+36,1024,EMPR 0
+37,1024,EMPR 1
+38,1024,EMPR 2
+39,1024,EMPR 3
+40,1024,EMPR 4
+41,1024,EMPR 5
+42,1024,EMPR 6
+43,1024,EMPR 7
+44,1024,EMPR 8
+45,1024,EMPR 9
+46,1024,EMPR 10
+47,1024,EMPR 11
+48,1024,EMPR 12
+49,1024,EMPR 13
+50,1024,EMPR 14
+51,1024,EMPR 15
+52,1024,EMPR 16
+53,1024,EMPR 17
+54,1024,EMPR 18
+55,1024,EMPR 19
+56,1024,EMPR 20
+57,1024,EMPR 21
+58,1024,EMPR 22
+59,1024,EMPR 23
+60,1024,EMPR 24
+61,1024,EMPR 25
+62,1024,EMPR 26
+63,1024,EMPR 27
+64,1024,EMPR 28
+65,1024,EMPR 29
+66,1024,EMPR 30
+67,1024,EMPR 31
+1,262144,boot image
+2,262144,hold image
+20,262144,low battery image
+19,262144,update image
+6,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 @@
+1,4,system information
+2,32,u-boot password
+3,4,firmware update flag
+4,4,beep ok flag
+5,4,hold mode
+6,16,rtc alarm
+7,64,model id
+8,5,product code
+9,16,serial number
+10,8,update file name
+11,64,key and signature
+12,32,ship information
+13,4,test mode flag
+14,4,getty mode flag
+15,16,fm parameter
+16,64,sound driver parameter
+17,64,noise cancel driver parameter
+18,512,bluetooth pskey
+77,4,wifi protected setup
+85,4,battery calibration
+19,2048,bluetooth parameter
+20,512,btmw factory pair info
+21,512,btmw factory scdb
+22,4,btmw log mode flag
+78,4,application debug mode flag
+79,4,browser log mode flag
+80,4,time out to sleep
+81,4,europe vol regulation flag
+82,4,function information
+83,4,service id
+84,4,marlin key
+86,4,MSC only mode flag
+23,704,aad/empr key
+24,160,aad icv
+25,520,empr icv
+26,4,key mode (debug/release)
+27,64,random data
+28,8224,slacker id file
+29,64,starfish id
+30,33024,marlin device key
+31,20,secure clock
+32,16,slacker time
+33,64,marlin time
+34,16384,EKB 0
+35,16384,EKB 1
+36,1024,EMPR 0
+37,1024,EMPR 1
+38,1024,EMPR 2
+39,1024,EMPR 3
+40,1024,EMPR 4
+41,1024,EMPR 5
+42,1024,EMPR 6
+43,1024,EMPR 7
+44,1024,EMPR 8
+45,1024,EMPR 9
+46,1024,EMPR 10
+47,1024,EMPR 11
+48,1024,EMPR 12
+49,1024,EMPR 13
+50,1024,EMPR 14
+51,1024,EMPR 15
+52,1024,EMPR 16
+53,1024,EMPR 17
+54,1024,EMPR 18
+55,1024,EMPR 19
+56,1024,EMPR 20
+57,1024,EMPR 21
+58,1024,EMPR 22
+59,1024,EMPR 23
+60,1024,EMPR 24
+61,1024,EMPR 25
+62,1024,EMPR 26
+63,1024,EMPR 27
+64,1024,EMPR 28
+65,1024,EMPR 29
+66,1024,EMPR 30
+67,1024,EMPR 31
+68,4,color variation
+69,4,speaker ship info
+70,8,middleware parameter
+71,4,quick shutdown flag
+72,262144,boot image
+73,262144,hold image
+74,262144,low battery image
+75,262144,update image
+76,262144,update error image
+87,262144,precharge image
+88,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 @@
+1,4,system information
+2,32,u-boot password
+3,4,firmware update flag
+4,4,beep ok flag
+5,4,hold mode
+6,16,rtc alarm
+7,64,model id
+8,5,product code
+9,16,serial number
+10,8,update file name
+11,64,key and signature
+12,32,ship information
+13,4,test mode flag
+14,4,getty mode flag
+15,16,fm parameter
+16,64,sound driver parameter
+17,64,noise cancel driver parameter
+18,512,bluetooth pskey
+77,4,wifi protected setup
+85,4,battery calibration
+19,2048,bluetooth parameter
+20,512,btmw factory pair info
+21,512,btmw factory scdb
+22,4,btmw log mode flag
+78,4,application debug mode flag
+79,4,browser log mode flag
+80,4,time out to sleep
+81,4,europe vol regulation flag
+82,4,function information
+83,4,service id
+84,4,marlin key
+86,4,MSC only mode flag
+89,4,SD Card export flag
+23,704,aad/empr key
+24,160,aad icv
+25,520,empr icv
+26,4,key mode (debug/release)
+27,64,random data
+28,8224,slacker id file
+29,64,starfish id
+30,33024,marlin device key
+31,20,secure clock
+32,16,slacker time
+33,64,marlin time
+34,16384,EKB 0
+35,16384,EKB 1
+36,1024,EMPR 0
+37,1024,EMPR 1
+38,1024,EMPR 2
+39,1024,EMPR 3
+40,1024,EMPR 4
+41,1024,EMPR 5
+42,1024,EMPR 6
+43,1024,EMPR 7
+44,1024,EMPR 8
+45,1024,EMPR 9
+46,1024,EMPR 10
+47,1024,EMPR 11
+48,1024,EMPR 12
+49,1024,EMPR 13
+50,1024,EMPR 14
+51,1024,EMPR 15
+52,1024,EMPR 16
+53,1024,EMPR 17
+54,1024,EMPR 18
+55,1024,EMPR 19
+56,1024,EMPR 20
+57,1024,EMPR 21
+58,1024,EMPR 22
+59,1024,EMPR 23
+60,1024,EMPR 24
+61,1024,EMPR 25
+62,1024,EMPR 26
+63,1024,EMPR 27
+64,1024,EMPR 28
+65,1024,EMPR 29
+66,1024,EMPR 30
+67,1024,EMPR 31
+68,4,color variation
+69,4,speaker ship info
+70,8,middleware parameter
+71,4,quick shutdown flag
+72,262144,boot image
+73,262144,hold image
+74,262144,low battery image
+75,262144,update image
+76,262144,update error image
+87,262144,precharge image
+88,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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2016 Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <cstdio>
+#include <stdint.h>
+#include <cstdlib>
+#include <cstring>
+#include <getopt.h>
+#include <cstdarg>
+#include <string>
+#include <fstream>
+#include <elf.h>
+
+bool g_verbose = false;
+bool g_unsafe = false;
+
+uint8_t *read_file(const std::string& path, size_t& size)
+{
+ std::ifstream fin(path.c_str(), std::ios::binary);
+ if(!fin)
+ {
+ printf("Error: cannot open '%s'\n", path.c_str());
+ return 0;
+ }
+ fin.seekg(0, std::ios::end);
+ size = fin.tellg();
+ fin.seekg(0, std::ios::beg);
+ uint8_t *buf = new uint8_t[size];
+ fin.read((char *)buf, size);
+ return buf;
+}
+
+bool write_file(const std::string& path, uint8_t *buf, size_t size)
+{
+ std::ofstream fout(path.c_str(), std::ios::binary);
+ if(!fout)
+ {
+ printf("Error: cannot open '%s'\n", path.c_str());
+ return false;
+ }
+ fout.write((char *)buf, size);
+ fout.close();
+ return true;
+}
+
+/* ELF code */
+uint8_t *g_elf_buf;
+size_t g_elf_size;
+Elf32_Shdr *g_elf_symtab;
+Elf32_Shdr *g_elf_symtab_strtab;
+Elf32_Shdr *g_elf_shstrtab;
+
+Elf32_Ehdr *elf_ehdr()
+{
+ return (Elf32_Ehdr *)g_elf_buf;
+}
+
+#define NTH_SHDR_OFF(n) \
+ (elf_ehdr()->e_shoff + elf_ehdr()->e_shentsize * (n))
+
+Elf32_Shdr *elf_shdr(size_t index)
+{
+ if(index >= elf_ehdr()->e_shnum)
+ {
+ printf("Warning: section index is out of bounds\n");
+ return nullptr;
+ }
+ return (Elf32_Shdr *)(g_elf_buf + NTH_SHDR_OFF(index));
+}
+
+size_t elf_shnum()
+{
+ return elf_ehdr()->e_shnum;
+}
+
+const char *elf_get_str(Elf32_Shdr *strtab, Elf32_Word index)
+{
+ /* sanity checks */
+ if(strtab->sh_type != SHT_STRTAB)
+ {
+ printf("Warning: string access to a non-string-table section\n");
+ return nullptr;
+ }
+ if(strtab->sh_offset + strtab->sh_size > g_elf_size)
+ {
+ printf("Warning: string table section does not fit in the file\n");
+ return nullptr;
+ }
+ if(index >= strtab->sh_size)
+ {
+ printf("Warning: string access to string table is out of bounds\n");
+ return nullptr;
+ }
+ char *buf = (char *)(g_elf_buf + strtab->sh_offset);
+ if(buf[strtab->sh_size - 1] != 0)
+ {
+ printf("Warning: string table is not zero terminated\n");
+ return nullptr;
+ }
+ return buf + index;
+}
+
+const char *elf_get_section_name(size_t index)
+{
+ Elf32_Shdr *shdr = elf_shdr(index);
+ return shdr ? elf_get_str(g_elf_shstrtab, shdr->sh_name) : nullptr;
+}
+
+const char *elf_get_symbol_name(Elf32_Sym *sym)
+{
+ if(ELF32_ST_TYPE(sym->st_info) == STT_SECTION)
+ return elf_get_section_name(sym->st_shndx);
+ else
+ return elf_get_str(g_elf_symtab_strtab, sym->st_name);
+}
+
+Elf32_Sym *elf_get_symbol_by_name(const char *name)
+{
+ Elf32_Sym *sym = (Elf32_Sym *)(g_elf_buf + g_elf_symtab->sh_offset);
+ size_t nr_syms = g_elf_symtab->sh_size / sizeof(Elf32_Sym);
+ for(size_t i = 0; i < nr_syms; i++)
+ {
+ const char *s = elf_get_symbol_name(&sym[i]);
+ if(s != nullptr && strcmp(name, s) == 0)
+ return &sym[i];
+ }
+ return nullptr;
+}
+
+Elf32_Sym *elf_get_symbol_by_address(size_t shndx, Elf32_Word address)
+{
+ Elf32_Sym *sym = (Elf32_Sym *)(g_elf_buf + g_elf_symtab->sh_offset);
+ size_t nr_syms = g_elf_symtab->sh_size / sizeof(Elf32_Sym);
+ for(size_t i = 0; i < nr_syms; i++)
+ {
+ if(sym[i].st_shndx == shndx && sym[i].st_value == address)
+ return &sym[i];
+ }
+ return nullptr;
+}
+
+Elf32_Sym *elf_get_symbol_by_index(size_t index)
+{
+ Elf32_Sym *sym = (Elf32_Sym *)(g_elf_buf + g_elf_symtab->sh_offset);
+ size_t nr_syms = g_elf_symtab->sh_size / sizeof(Elf32_Sym);
+ if(index >= nr_syms)
+ return nullptr;
+ return &sym[index];
+}
+
+void *elf_get_section_ptr(size_t shndx, Elf32_Word address, size_t size)
+{
+ Elf32_Shdr *shdr = elf_shdr(shndx);
+ if(shdr == nullptr)
+ return nullptr;
+ if(address + size > shdr->sh_size)
+ return nullptr;
+ if(shdr->sh_offset + shdr->sh_size > g_elf_size)
+ return nullptr;
+ return g_elf_buf + shdr->sh_offset + address;
+}
+
+/* make sure the string has a final zero in the section, optionally check characters
+ * are printable */
+const char *elf_get_string_ptr_safe(size_t shndx, Elf32_Word offset, bool want_print = true)
+{
+ Elf32_Shdr *shdr = elf_shdr(shndx);
+ if(shdr == nullptr)
+ return nullptr;
+ /* address must be in the section */
+ if(offset >= shdr->sh_size)
+ return nullptr;
+ /* determine maximum size */
+ size_t max_sz = shdr->sh_size - offset;
+ const char *ptr = (const char *)(g_elf_buf + shdr->sh_offset + offset);
+ for(size_t i = 0; i < max_sz; i++)
+ {
+ if(ptr[i] == 0) /* found final 0, everything is fine */
+ return ptr;
+ if(want_print && !isprint(ptr[i]))
+ return nullptr;
+ }
+ return nullptr;
+}
+
+size_t elf_find_reloc_section(size_t shndx)
+{
+ /* find the relocation section */
+ for(size_t i = 0; i < elf_ehdr()->e_shnum; i++)
+ {
+ Elf32_Shdr *shdr = elf_shdr(i);
+ if(shdr->sh_type != SHT_REL && shdr->sh_type != SHT_RELA)
+ continue;
+ if(shdr->sh_info != shndx)
+ continue;
+ return i;
+ }
+ return 0;
+}
+
+void *elf_get_symbol_ptr(Elf32_Sym *sym, size_t size)
+{
+ /* NOTE: also works for STT_SECTION since offset will be 0 */
+ return elf_get_section_ptr(sym->st_shndx, sym->st_value, size);
+}
+
+/* take the position of a 32-bit address in the section and apply relocation if
+ * any */
+void *elf_reloc_addr32(size_t shndx, Elf32_Word offset)
+{
+ /* read value */
+ uint32_t *val = (uint32_t *)elf_get_section_ptr(shndx, offset, 4);
+ if(val == nullptr)
+ return 0; /* invalid */
+ /* find reloc section if any */
+ size_t relshndx = elf_find_reloc_section(shndx);
+ if(relshndx == 0)
+ return g_elf_buf + *val; /* no relocation applies */
+ Elf32_Shdr *shdr = elf_shdr(relshndx);
+ /* find relocation that applies */
+ if(shdr->sh_type == SHT_RELA)
+ {
+ printf("Warning: unsupported RELA relocation type\n");
+ return 0;
+ }
+ Elf32_Rel *rel = (Elf32_Rel *)elf_get_section_ptr(relshndx, 0, shdr->sh_size);
+ if(rel == nullptr)
+ {
+ printf("Warning: invalid relocation section\n");
+ return 0;
+ }
+ size_t sym_count = shdr->sh_size / sizeof(Elf32_Rel);
+ for(size_t i = 0; i < sym_count; i++)
+ {
+ /* for relocatable files, r_offset is the offset in the section */
+ if(rel[i].r_offset != offset)
+ continue;
+ /* find symbol, ignore shdr->sh_link and assume it is g_elf_symtab
+ * since the file should have only one symbol table anyway */
+ Elf32_Sym *sym = elf_get_symbol_by_index(ELF32_R_SYM(rel[i].r_info));
+ /* found it! */
+ if(g_verbose)
+ {
+ printf("[section %zu (%s) offset %#x reloc val %#x type %d sym %d (%s)]\n",
+ shndx, elf_get_section_name(shndx), offset, *val,
+ ELF32_R_TYPE(rel[i].r_info), ELF32_R_SYM(rel[i].r_info),
+ sym ? elf_get_symbol_name(sym) : "<undef>");
+ }
+ /* apply reloc */
+ if(ELF32_R_TYPE(rel[i].r_info) == R_ARM_ABS32)
+ {
+ if(sym == nullptr)
+ {
+ printf("Warning: R_ARM_ABS32 reloc with invalid symbol reference\n");
+ return 0;
+ }
+ return *val + (uint8_t *)elf_get_symbol_ptr(sym, 0);
+ }
+ else
+ {
+ printf("Warning: unsupported relocation type %d\n", ELF32_R_TYPE(rel[i].r_info));
+ return 0;
+ }
+ }
+ /* no reloc applies */
+ if(g_verbose)
+ {
+ printf("[section %zu (%s) offset %#x no reloc found]\n", shndx,
+ elf_get_section_name(shndx), offset);
+ }
+ return g_elf_buf + *val; /* no relocation applies */
+}
+
+size_t elf_map_virt_addr(uint32_t address, Elf32_Word& out_off)
+{
+ /* for relocatable file, this is trivial */
+ for(size_t i = 0; i < elf_ehdr()->e_shnum; i++)
+ {
+ Elf32_Shdr *shdr = elf_shdr(i);
+ if(shdr->sh_offset <= address && address < shdr->sh_offset + shdr->sh_size)
+ {
+ out_off = address - shdr->sh_offset;
+ if(g_verbose)
+ {
+ printf("[map %#x to section %zi (%s) at %#x]\n", address, i,
+ elf_get_section_name(i), out_off);
+ }
+ return i;
+ }
+ }
+ return 0; /* section 0 is always invalid */
+}
+
+size_t elf_map_ptr(void *ptr, Elf32_Word& out_off)
+{
+ uint32_t addr = (uint32_t)((uint8_t *)ptr - g_elf_buf);
+ return elf_map_virt_addr(addr, out_off);
+}
+
+/* same as elf_reloc_addr32 but find section automatically from pointer */
+void *elf_reloc_addr32_ptr(uint32_t *val)
+{
+ Elf32_Word off;
+ size_t sec = elf_map_ptr((void *)val, off);
+ /* if it does not belong to any section, don't do anything */
+ if(sec == 0)
+ {
+ printf("Warning: reloc addr pointer not in any section\n");
+ return g_elf_buf + *val;
+ }
+ return elf_reloc_addr32(sec, off);
+}
+
+Elf32_Sym *elf_get_symbol_by_ptr(void *ptr)
+{
+ Elf32_Word off;
+ size_t sec = elf_map_ptr(ptr, off);
+ return sec ? elf_get_symbol_by_address(sec, off) : nullptr;
+}
+
+/* check if a string is safe */
+bool elf_is_str_ptr_safe(const char *str)
+{
+ Elf32_Word name_off;
+ /* find the section it belongs to */
+ size_t name_shndx = elf_map_ptr((void *)str, name_off);
+ if(name_shndx == 0)
+ return false;
+ /* check the string fit in the section */
+ return elf_get_string_ptr_safe(name_shndx, name_off) != nullptr;
+}
+
+bool elf_is_ptr_safe(void *ptr, size_t sz)
+{
+ Elf32_Word ptr_off;
+ /* find the section it belongs to */
+ size_t ptr_shndx = elf_map_ptr((void *)ptr, ptr_off);
+ if(ptr_shndx == 0)
+ return false;
+ /* check the string fit in the section */
+ return elf_get_section_ptr(ptr_shndx, ptr_off, sz) != nullptr;
+}
+
+bool elf_init()
+{
+ if(g_elf_size < sizeof(Elf32_Ehdr))
+ {
+ printf("Invalid ELF file: too small\n");
+ return false;
+ }
+ Elf32_Ehdr *ehdr = elf_ehdr();
+ if(ehdr->e_ident[EI_MAG0] != ELFMAG0 ||
+ ehdr->e_ident[EI_MAG1] != ELFMAG1 ||
+ ehdr->e_ident[EI_MAG2] != ELFMAG2 ||
+ ehdr->e_ident[EI_MAG3] != ELFMAG3)
+ {
+ printf("Invalid ELF file: invalid ident\n");
+ return false;
+ }
+ /* we only support relocatable files */
+ if(ehdr->e_type != ET_REL)
+ {
+ printf("Unsupported ELF file: this is not a relocatable file\n");
+ return false;
+ }
+ if(ehdr->e_ident[EI_CLASS] != ELFCLASS32 || ehdr->e_machine != EM_ARM)
+ {
+ printf("Unsupported ELF file: this is not a 32-bit ARM ELF file\n");
+ return false;
+ }
+ /* go through sections */
+ if(ehdr->e_shoff == 0)
+ {
+ printf("Invalid ELF file: no sections\n");
+ return false;
+ }
+ if(ehdr->e_shentsize < sizeof(Elf32_Shdr))
+ {
+ printf("Invalid ELF file: section entry size too small\n");
+ return false;
+ }
+ if(NTH_SHDR_OFF(ehdr->e_shnum) > g_elf_size)
+ {
+ printf("Invalid ELF file: sections header does not fit in the file\n");
+ return false;
+ }
+ for(size_t i = 0; i < ehdr->e_shnum; i++)
+ {
+ Elf32_Shdr *shdr = (Elf32_Shdr *)(g_elf_buf + NTH_SHDR_OFF(i));
+ if(shdr->sh_type == SHT_SYMTAB)
+ g_elf_symtab = shdr;
+ }
+ /* handle symbol table */
+ if(g_elf_symtab)
+ {
+ if(g_elf_symtab->sh_offset + g_elf_symtab->sh_size > g_elf_size)
+ {
+ printf("Invalid ELF file: symtab does not file in the file\n");
+ return false;
+ }
+ g_elf_symtab_strtab = elf_shdr(g_elf_symtab->sh_link);
+ if(g_elf_symtab_strtab == nullptr)
+ {
+ printf("Invalid ELF file: symtab's strtab is not valid\n");
+ }
+ if(g_elf_symtab_strtab->sh_type != SHT_STRTAB)
+ {
+ printf("Invalid ELF file: symtab's strtab is not a string table\n");
+ return false;
+ }
+ }
+ /* handle section string table */
+ if(ehdr->e_shstrndx != SHN_UNDEF)
+ {
+ g_elf_shstrtab = elf_shdr(ehdr->e_shstrndx);
+ if(g_elf_shstrtab == nullptr)
+ {
+ printf("Invalid ELF file: section string table is invalid\n");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+/* main code */
+
+void usage()
+{
+ printf("usage: nvptool [options] inputs...\n");
+ printf("options:\n");
+ printf(" -h/--help Display help\n");
+ printf(" -x/--extract Extract nvp map from icx_nvp_emmc.ko\n");
+ printf(" -o/--output Set output file\n");
+ printf(" -v/--verbose Enable debug output\n");
+ printf(" -u/--unsafe Perform potentially unsafe operations\n");
+ exit(1);
+}
+
+struct zone_info_v1_t
+{
+ uint32_t node;
+ uint32_t start;
+ uint32_t count;
+ uint32_t size;
+ uint32_t semaphore[4]; /* a 16-byte structure, useless for us */
+ uint32_t name; /* pointer to string */
+} __attribute__((packed));
+
+struct zone_info_v2_t
+{
+ uint32_t node;
+ uint32_t start;
+ uint32_t count;
+ uint32_t size;
+ uint32_t semaphore[3]; /* a 12-byte structure, useless for us */
+ uint32_t name; /* pointer to string */
+} __attribute__((packed));
+
+struct area_info_v1_t
+{
+ uint32_t type; /* 1 = large, 2 = small */
+ uint32_t zoneinfo; /* pointer to zone_info_t[] */
+ uint32_t zonecount;
+ uint32_t semaphore[4]; /* a 16-byte structure, useless for us */
+ uint32_t name; /* pointer to string */
+} __attribute__((packed));
+
+struct area_info_v2_t
+{
+ uint32_t type; /* 1 = large, 2 = small */
+ uint32_t zoneinfo; /* pointer to zone_info_t[] */
+ uint32_t zonecount;
+ uint32_t semaphore[3]; /* a 16-byte structure, useless for us */
+ uint32_t name; /* pointer to string */
+} __attribute__((packed));
+
+int guess_version(void *area_info_ptr)
+{
+ /* the "semaphore" part is always filled with zeroes, so simply check if there
+ * are 3 or 4 of them */
+ area_info_v1_t *ai_v1 = (area_info_v1_t *)area_info_ptr;
+ if(ai_v1->semaphore[3] == 0)
+ return 1; /* v1: semaphore has 4 fields */
+ else
+ return 2; /* v2: semaphore has 3 fields */
+}
+
+int do_extract(const char *output, int argc, char **argv)
+{
+ if(argc != 1)
+ {
+ printf("You need to specify exactly one input file to extract from.\n");
+ return 3;
+ }
+ FILE *fout = NULL;
+ if(output)
+ {
+ fout = fopen(output, "w");
+ if(fout == NULL)
+ {
+ printf("Cannot open output file '%s'\n", output);
+ return 4;
+ }
+ }
+ /* read elf file */
+ g_elf_buf = read_file(argv[0], g_elf_size);
+ if(g_elf_buf == nullptr)
+ {
+ printf("Cannot open input file '%s'\n", argv[0]);
+ return 1;
+ }
+ if(!elf_init())
+ {
+ printf("This is not a valid ELF file\n");
+ return 1;
+ }
+ if(g_elf_symtab == nullptr)
+ {
+ printf("This ELF file does not have a symbol table\n");
+ return 1;
+ }
+ /* look for symbol 'AreaInfo' */
+ Elf32_Sym *sym_AreaInfo = elf_get_symbol_by_name("AreaInfo");
+ if(sym_AreaInfo == nullptr)
+ {
+ printf("Cannot find symbol 'AreaInfo'\n");
+ return 1;
+ }
+ printf("AreaInfo:\n");
+ if(g_verbose)
+ {
+ printf("[%u bytes at address %#x in section %u (%s)]\n",
+ (unsigned)sym_AreaInfo->st_size, (unsigned)sym_AreaInfo->st_value,
+ (unsigned)sym_AreaInfo->st_shndx, elf_get_section_name(sym_AreaInfo->st_shndx));
+ }
+ /* guess version */
+ int ver = guess_version(elf_get_symbol_ptr(sym_AreaInfo, sizeof(area_info_v1_t)));
+ if(g_verbose)
+ printf("[guessed version: %d]\n", ver);
+ size_t sizeof_area_info = (ver == 1) ? sizeof(area_info_v1_t) : sizeof(area_info_v2_t);
+ size_t sizeof_zone_info = (ver == 1) ? sizeof(zone_info_v1_t) : sizeof(zone_info_v2_t);
+ /* sanity check AreaInfo */
+ size_t area_count = sym_AreaInfo->st_size / sizeof_area_info;
+ if(!g_unsafe && (sym_AreaInfo->st_size % sizeof_area_info) != 0)
+ {
+ printf("AreaInfo size (%u) is a not a multiple of area_info_t size (%zu).\n",
+ (unsigned)sym_AreaInfo->st_size, sizeof_area_info);
+ printf("Use unsafe option to override this check\n");
+ return 1;
+ }
+ area_info_v1_t *AreaInfo_v1 = (area_info_v1_t *)elf_get_symbol_ptr(sym_AreaInfo,
+ sym_AreaInfo->st_size);
+ area_info_v2_t *AreaInfo_v2 = (area_info_v2_t *)AreaInfo_v1;
+ if(AreaInfo_v1 == nullptr)
+ {
+ printf("Symbol does not point to a valid address\n");
+ return 1;
+ }
+ for(size_t i = 0; i < area_count; i++)
+ {
+ uint32_t type;
+ uint32_t *zoneinfo_ptr;
+ uint32_t zonecount;
+ uint32_t *name_ptr;
+
+ if(ver == 1)
+ {
+ type = AreaInfo_v1[i].type;
+ zoneinfo_ptr = &AreaInfo_v1[i].zoneinfo;
+ zonecount = AreaInfo_v1[i].zonecount;
+ name_ptr = &AreaInfo_v1[i].name;
+ }
+ else
+ {
+ type = AreaInfo_v2[i].type;
+ zoneinfo_ptr = &AreaInfo_v2[i].zoneinfo;
+ zonecount = AreaInfo_v2[i].zonecount;
+ name_ptr = &AreaInfo_v2[i].name;
+ }
+
+ if(g_verbose)
+ {
+ printf(" [type=%u info=%#x count=%u name=%#x]\n", type, *zoneinfo_ptr,
+ zonecount, *name_ptr);
+ }
+ /* translate name address */
+ const char *name = (const char *)elf_reloc_addr32_ptr(name_ptr);
+ if(name == nullptr || !elf_is_str_ptr_safe(name))
+ {
+ printf(" Entry name is not a string\n");
+ continue;
+ }
+ /* skip reserved entries */
+ if(*zoneinfo_ptr == 0)
+ {
+ printf(" %s\n", name);
+ continue;
+ }
+ /* relocate the zoneinfo pointer */
+ void *Zone = elf_reloc_addr32_ptr(zoneinfo_ptr);;
+ if(Zone == nullptr)
+ {
+ printf(" %s\n", name);
+ printf(" Zone info pointer is not valid\n");
+ continue;
+ }
+ /* in safe mode, make sure the zone info pointer is a symbol */
+ Elf32_Sym *zoneinfo_sym = elf_get_symbol_by_ptr((void *)Zone);
+ const char *zoneinfo_sym_name = "<no symbol>";
+ if(zoneinfo_sym)
+ zoneinfo_sym_name = elf_get_symbol_name(zoneinfo_sym);
+ printf(" %s (%s)\n", name, zoneinfo_sym_name);
+ if(!g_unsafe && !zoneinfo_sym)
+ {
+ printf(" Zone info pointer does not correspond to any symbol.\n");
+ printf(" Use unsafe option to override this check\n");
+ continue;
+ }
+ /* if we have the symbol, make sure the claimed size match */
+ if(!g_unsafe && zoneinfo_sym)
+ {
+ if(zoneinfo_sym->st_size != sizeof_zone_info * zonecount)
+ {
+ printf(" Zone info symbol size (%u) does not match expected size (%zu)\n",
+ (unsigned)zoneinfo_sym->st_size, sizeof_zone_info * zonecount);
+ printf(" Use unsafe option to override this check\n");
+ continue;
+ }
+ }
+ /* sanity check */
+ if(!elf_is_ptr_safe((void *)Zone, sizeof_zone_info * zonecount))
+ {
+ printf(" Zone info pointer is not valid\n");
+ continue;
+ }
+ /* read zone */
+ zone_info_v1_t *Zone_v1 = (zone_info_v1_t *)Zone;
+ zone_info_v2_t *Zone_v2 = (zone_info_v2_t *)Zone;
+ for(size_t j = 0; j < zonecount; j++)
+ {
+ uint32_t node, start, count, size;
+ uint32_t *name_ptr;
+
+ if(ver == 1)
+ {
+ node = Zone_v1[j].node;
+ start = Zone_v1[j].start;
+ count = Zone_v1[j].count;
+ size = Zone_v1[j].size;
+ name_ptr = &Zone_v1[j].name;
+ }
+ else
+ {
+ node = Zone_v2[j].node;
+ start = Zone_v2[j].start;
+ count = Zone_v2[j].count;
+ size = Zone_v2[j].size;
+ name_ptr = &Zone_v2[j].name;
+ }
+
+ if(g_verbose)
+ {
+ printf(" [node=%u start=%#x count=%u size=%u name=%#x]\n",
+ node, start, count, size, *name_ptr);
+ }
+ /* translate name address */
+ const char *name = (const char *)elf_reloc_addr32_ptr(name_ptr);
+ if(name == nullptr || !elf_is_str_ptr_safe(name))
+ {
+ printf(" Entry name is not a string\n");
+ continue;
+ }
+ printf(" %s: node %03u, size %u\n", name, node, size);
+ if(fout)
+ fprintf(fout, "%u,%u,%s\n", node, size, name);
+ }
+ }
+ if(fout)
+ fclose(fout);
+ /* success */
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ const char *output = NULL;
+ bool extract = false;
+
+ if(argc <= 1)
+ usage();
+
+ while(1)
+ {
+ static struct option long_options[] =
+ {
+ {"help", no_argument, 0, 'h'},
+ {"extract", no_argument, 0, 'x'},
+ {"output", required_argument, 0, 'o'},
+ {"verbose", no_argument, 0, 'v'},
+ {"unsafe", no_argument, 0, 'u'},
+ {0, 0, 0, 0}
+ };
+
+ int c = getopt_long(argc, argv, "hxo:vu", long_options, NULL);
+ if(c == -1)
+ break;
+ switch(c)
+ {
+ case -1:
+ break;
+ case 'h':
+ usage();
+ break;
+ case 'o':
+ output = optarg;
+ break;
+ case 'x':
+ extract = true;
+ break;
+ case 'v':
+ g_verbose = true;
+ break;
+ case 'u':
+ g_unsafe = true;
+ break;
+ default:
+ abort();
+ }
+ }
+
+ if(extract)
+ return do_extract(output, argc - optind, argv + optind);
+ printf("You need to specify an operation. Run nvptool -h for help\n");
+ return 1;
+}
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 @@
+dbg,000
+syi,001
+ubp,002
+fup,003
+prk,004
+hld,005
+rtc,006
+mid,007
+pcd,008
+ser,009
+ufn,010
+kas,011
+shp,012
+tst,013
+gty,014
+fmp,015
+sdp,016
+ncp,017
+psk,018
+nvr,077
+she,084
+btc,085
+ins,089
+ctr,090
+sku,091
+bpr,019
+bfp,020
+bfd,021
+bml,022
+apd,078
+blf,079
+slp,080
+vrt,081
+fni,082
+sid,083
+mso,086
+cng,023
+lyr,024
+dbv,025
+fur,026
+ums,027
+skd,028
+ups,029
+mdk,030
+fvi,031
+mac,032
+fpi,033
+tr0,034
+tr1,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+sps,069
+rbt,070
+edw,071
+bti,072
+hdi,073
+lbi,074
+fui,075
+eri,076
+pci,087
+dbi,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 @@
+dbg,000
+bti,001
+hdi,002
+cng,003
+ser,004
+app,005
+eri,006
+dcc,007
+mdl,008
+fup,009
+bok,010
+shp,011
+dba,012
+dbv,013
+tr0,014
+tr1,015
+mid,016
+tst,017
+gty,018
+fui,019
+lbi,020
+dor,021
+edw,022
+ubp,023
+syi,024
+exm,025
+pcd,026
+btc,027
+rnd,028
+ufn,029
+sdp,030
+ncp,031
+kas,032
+sfi,033
+rtc,034
+bpr,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+slp,069
+ipt,070
+mtm,071
+mcr,072
+mdk,073
+muk,074
+pts,075
+skt,076
+mac,077
+apd,078
+blf,079
+hld,080
+skd,081
+fmp,082
+sps,083
+msc,084
+vrt,085
+psk,086
+bml,087
+bfd,088
+bfp,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 @@
+dbg,000
+syi,001
+ubp,002
+fup,003
+bok,004
+hld,005
+rtc,006
+mid,007
+pcd,008
+ser,009
+ufn,010
+kas,011
+shp,012
+tst,013
+gty,014
+fmp,015
+sdp,016
+ncp,017
+psk,018
+pts,077
+bpr,019
+bfp,020
+bfd,021
+bml,022
+apd,078
+blf,079
+slp,080
+vrt,081
+fni,082
+sid,083
+mlk,084
+mso,086
+cng,023
+dba,024
+dbv,025
+dor,026
+rnd,027
+skd,028
+sfi,029
+mdk,030
+dcc,031
+skt,032
+mtm,033
+tr0,034
+tr1,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+sps,069
+mdl,070
+edw,071
+bti,072
+hdi,073
+lbi,074
+fui,075
+eri,076
+btc,085
+pci,087
+dbi,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 @@
+dbg,000
+syi,001
+ubp,002
+fup,003
+bok,004
+hld,005
+rtc,006
+mid,007
+pcd,008
+ser,009
+ufn,010
+kas,011
+shp,012
+tst,013
+gty,014
+fmp,015
+sdp,016
+ncp,017
+psk,018
+pts,077
+bpr,019
+bfp,020
+bfd,021
+bml,022
+apd,078
+blf,079
+slp,080
+vrt,081
+fni,082
+sid,083
+mlk,084
+mso,086
+cng,023
+dba,024
+dbv,025
+dor,026
+rnd,027
+skd,028
+sfi,029
+mdk,030
+dcc,031
+skt,032
+mtm,033
+tr0,034
+tr1,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+sps,069
+mdl,070
+edw,071
+bti,072
+hdi,073
+lbi,074
+fui,075
+eri,076
+btc,085
+pci,087
+dbi,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 @@
+dbg,000
+syi,001
+ubp,002
+fup,003
+bok,004
+hld,005
+rtc,006
+mid,007
+pcd,008
+ser,009
+ufn,010
+kas,011
+shp,012
+tst,013
+gty,014
+fmp,015
+sdp,016
+ncp,017
+psk,018
+pts,077
+btc,085
+bpr,019
+bfp,020
+bfd,021
+bml,022
+apd,078
+blf,079
+slp,080
+vrt,081
+fni,082
+sid,083
+mlk,084
+mso,086
+sdc,089
+cng,023
+dba,024
+dbv,025
+dor,026
+rnd,027
+skd,028
+sfi,029
+mdk,030
+dcc,031
+skt,032
+mtm,033
+tr0,034
+tr1,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+sps,069
+mdl,070
+edw,071
+bti,072
+hdi,073
+lbi,074
+fui,075
+eri,076
+pci,087
+dbi,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 @@
+dbg,000
+syi,001
+ubp,002
+fup,003
+bok,004
+hld,005
+rtc,006
+mid,007
+pcd,008
+ser,009
+ufn,010
+kas,011
+shp,012
+tst,013
+gty,014
+fmp,015
+sdp,016
+ncp,017
+psk,018
+pts,077
+btc,085
+bpr,019
+bfp,020
+bfd,021
+bml,022
+apd,078
+blf,079
+slp,080
+vrt,081
+fni,082
+sid,083
+mlk,084
+mso,086
+sdc,089
+cng,023
+dba,024
+dbv,025
+dor,026
+rnd,027
+skd,028
+sfi,029
+mdk,030
+dcc,031
+skt,032
+mtm,033
+tr0,034
+tr1,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+sps,069
+mdl,070
+edw,071
+bti,072
+hdi,073
+lbi,074
+fui,075
+eri,076
+pci,087
+dbi,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 @@
+dbg,000
+bti,001
+hdi,002
+cng,003
+ser,004
+app,005
+eri,006
+dcc,007
+mdl,008
+fup,009
+bok,010
+shp,011
+dba,012
+dbv,013
+tr0,014
+tr1,015
+mid,016
+tst,017
+gty,018
+fui,019
+lbi,020
+dor,021
+edw,022
+ubp,023
+syi,024
+exm,025
+pcd,026
+rnd,028
+ufn,029
+sdp,030
+ncp,031
+kas,032
+rtc,034
+bpr,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+slp,069
+ipt,070
+pts,075
+skt,076
+mac,077
+apd,078
+blf,079
+hld,080
+skd,081
+fmp,082
+sps,083
+msc,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 @@
+dbg,000
+bti,001
+hdi,002
+cng,003
+ser,004
+app,005
+eri,006
+dcc,007
+mdl,008
+fup,009
+bok,010
+shp,011
+dba,012
+dbv,013
+tr0,014
+tr1,015
+mid,016
+tst,017
+gty,018
+fui,019
+lbi,020
+dor,021
+edw,022
+ubp,023
+syi,024
+exm,025
+pcd,026
+btc,027
+rnd,028
+ufn,029
+sdp,030
+ncp,031
+kas,032
+sfi,033
+rtc,034
+bpr,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+slp,069
+ipt,070
+mtm,071
+mcr,072
+mdk,073
+muk,074
+pts,075
+skt,076
+mac,077
+apd,078
+blf,079
+hld,080
+skd,081
+fmp,082
+sps,083
+msc,084
+vrt,085
+psk,086
+bml,087
+bfd,088
+bfp,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 @@
+dbg,000
+bti,001
+hdi,002
+cng,003
+ser,004
+app,005
+eri,006
+dcc,007
+mdl,008
+fup,009
+bok,010
+shp,011
+dba,012
+dbv,013
+tr0,014
+tr1,015
+mid,016
+tst,017
+gty,018
+fui,019
+lbi,020
+dor,021
+edw,022
+ubp,023
+syi,024
+exm,025
+pcd,026
+rnd,028
+ufn,029
+sdp,030
+ncp,031
+kas,032
+rtc,034
+bpr,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+slp,069
+ipt,070
+pts,075
+skt,076
+mac,077
+apd,078
+blf,079
+hld,080
+skd,081
+fmp,082
+sps,083
+msc,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 @@
+dbg,000
+bti,001
+hdi,002
+cng,003
+ser,004
+app,005
+eri,006
+dcc,007
+mdl,008
+fup,009
+bok,010
+shp,011
+dba,012
+dbv,013
+tr0,014
+tr1,015
+mid,016
+tst,017
+gty,018
+fui,019
+lbi,020
+dor,021
+edw,022
+ubp,023
+syi,024
+exm,025
+pcd,026
+rnd,028
+ufn,029
+sdp,030
+ncp,031
+kas,032
+rtc,034
+bpr,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+slp,069
+ipt,070
+pts,075
+skt,076
+mac,077
+apd,078
+blf,079
+hld,080
+skd,081
+fmp,082
+sps,083
+msc,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 @@
+dbg,000
+bti,001
+hdi,002
+cng,003
+ser,004
+app,005
+eri,006
+dcc,007
+mdl,008
+fup,009
+bok,010
+shp,011
+dba,012
+dbv,013
+tr0,014
+tr1,015
+mid,016
+tst,017
+gty,018
+fui,019
+lbi,020
+dor,021
+edw,022
+ubp,023
+syi,024
+exm,025
+pcd,026
+btc,027
+rnd,028
+ufn,029
+sdp,030
+ncp,031
+kas,032
+sfi,033
+rtc,034
+bpr,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+slp,069
+ipt,070
+mtm,071
+mcr,072
+mdk,073
+muk,074
+pts,075
+skt,076
+mac,077
+apd,078
+blf,079
+hld,080
+skd,081
+fmp,082
+sps,083
+msc,084
+vrt,085
+psk,086
+bml,087
+bfd,088
+bfp,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 @@
+dbg,000
+syi,001
+ubp,002
+fup,003
+bok,004
+hld,005
+rtc,006
+mid,007
+pcd,008
+ser,009
+ufn,010
+kas,011
+shp,012
+tst,013
+gty,014
+fmp,015
+sdp,016
+ncp,017
+psk,018
+pts,077
+bpr,019
+bfp,020
+bfd,021
+bml,022
+apd,078
+blf,079
+slp,080
+vrt,081
+fni,082
+sid,083
+mlk,084
+mso,086
+cng,023
+dba,024
+dbv,025
+dor,026
+rnd,027
+skd,028
+sfi,029
+mdk,030
+dcc,031
+skt,032
+mtm,033
+tr0,034
+tr1,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+sps,069
+mdl,070
+edw,071
+bti,072
+hdi,073
+lbi,074
+fui,075
+eri,076
+btc,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 @@
+dbg,000
+syi,001
+ubp,002
+fup,003
+bok,004
+hld,005
+rtc,006
+mid,007
+pcd,008
+ser,009
+ufn,010
+kas,011
+shp,012
+tst,013
+gty,014
+fmp,015
+sdp,016
+ncp,017
+psk,018
+pts,077
+bpr,019
+bfp,020
+bfd,021
+bml,022
+apd,078
+blf,079
+slp,080
+vrt,081
+fni,082
+sid,083
+mlk,084
+mso,086
+cng,023
+dba,024
+dbv,025
+dor,026
+rnd,027
+skd,028
+sfi,029
+mdk,030
+dcc,031
+skt,032
+mtm,033
+tr0,034
+tr1,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+sps,069
+mdl,070
+edw,071
+bti,072
+hdi,073
+lbi,074
+fui,075
+eri,076
+btc,085
+pci,087
+dbi,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 @@
+dbg,000
+bti,001
+hdi,002
+cng,003
+ser,004
+app,005
+eri,006
+dcc,007
+mdl,008
+fup,009
+bok,010
+shp,011
+dba,012
+dbv,013
+tr0,014
+tr1,015
+mid,016
+tst,017
+gty,018
+fui,019
+lbi,020
+dor,021
+edw,022
+ubp,023
+syi,024
+exm,025
+pcd,026
+btc,027
+rnd,028
+ufn,029
+sdp,030
+ncp,031
+kas,032
+sfi,033
+rtc,034
+bpr,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+slp,069
+ipt,070
+mtm,071
+mcr,072
+mdk,073
+muk,074
+pts,075
+skt,076
+mac,077
+apd,078
+blf,079
+hld,080
+skd,081
+fmp,082
+sps,083
+msc,084
+vrt,085
+psk,086
+bml,087
+bfd,088
+bfp,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 @@
+dbg,000
+syi,001
+ubp,002
+fup,003
+bok,004
+hld,005
+rtc,006
+mid,007
+pcd,008
+ser,009
+ufn,010
+kas,011
+shp,012
+tst,013
+gty,014
+fmp,015
+sdp,016
+ncp,017
+psk,018
+pts,077
+btc,085
+bpr,019
+bfp,020
+bfd,021
+bml,022
+apd,078
+blf,079
+slp,080
+vrt,081
+fni,082
+sid,083
+mlk,084
+mso,086
+sdc,089
+cng,023
+dba,024
+dbv,025
+dor,026
+rnd,027
+skd,028
+sfi,029
+mdk,030
+dcc,031
+skt,032
+mtm,033
+tr0,034
+tr1,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+sps,069
+mdl,070
+edw,071
+bti,072
+hdi,073
+lbi,074
+fui,075
+eri,076
+pci,087
+dbi,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 @@
+dbg,000
+bti,001
+hdi,002
+cng,003
+ser,004
+app,005
+eri,006
+dcc,007
+mdl,008
+fup,009
+bok,010
+shp,011
+dba,012
+dbv,013
+tr0,014
+tr1,015
+mid,016
+tst,017
+gty,018
+fui,019
+lbi,020
+dor,021
+edw,022
+ubp,023
+syi,024
+exm,025
+pcd,026
+cgp,027
+rnd,028
+ufn,029
+sdp,030
+ncp,031
+kas,032
+sfi,033
+rtc,034
+bpr,035
+e00,036
+e01,037
+e02,038
+e03,039
+e04,040
+e05,041
+e06,042
+e07,043
+e08,044
+e09,045
+e10,046
+e11,047
+e12,048
+e13,049
+e14,050
+e15,051
+e16,052
+e17,053
+e18,054
+e19,055
+e20,056
+e21,057
+e22,058
+e23,059
+e24,060
+e25,061
+e26,062
+e27,063
+e28,064
+e29,065
+e30,066
+e31,067
+clv,068
+slp,069
+ipt,070
+mtm,071
+mcr,072
+mdk,073
+muk,074
+pts,075
+skt,076
+mac,077
+apd,078
+blf,079
+hld,080
+skd,081
+fmp,082
+sps,083
+msc,084
+vrt,085
+psk,086
+bml,087
+bfd,088
+bfp,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 @@
+#
+# usage: parse_all_nvp_headers /path/to/directory
+#
+# the expected structure is:
+# nwz-*/<kernel>
+# nw-*/<kernel/
+# where <kernel> must be of the form
+# linux-kernel-*.tgz
+#
+if [ "$#" -lt 1 ]; then
+ >&2 echo "usage: parse_all_nvp_header.sh /path/to/directory"
+ exit 1
+fi
+
+# list interesting directories
+for dir in `find "$1" -maxdepth 1 -name "nw-*" -or -name "nwz-*"`
+do
+ # extract codename
+ codename=`basename "$dir"`
+ # only consider linux based targets
+ if [ -e "$dir/not_linux" ]; then
+ #echo "$codename: not linux based"
+ continue
+ fi
+ # check if we can find a kernel
+ kernel_tgz=`find "$dir" -maxdepth 1 -name "linux-kernel-*.tgz"`
+ if [ "$kernel_tgz" == "" ]; then
+ echo "$codename: no kernel found"
+ continue
+ fi
+ echo "$codename: found kernel `basename $kernel_tgz`"
+ ./parse_nvp_header.sh "$kernel_tgz" > "$codename.txt"
+done
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 @@
+#
+# usage: parse_all_nvp_nodes /path/to/directory
+#
+# the expected structure is:
+# nwz-*/rootfs.tar
+# nwz-*/rootfs.tar
+#
+if [ "$#" -lt 1 ]; then
+ >&2 echo "usage: parse_all_nvp_header.sh /path/to/directory"
+ exit 1
+fi
+
+# list interesting directories
+for dir in `find "$1" -maxdepth 1 -name "nw-*" -or -name "nwz-*"`
+do
+ # extract codename
+ codename=`basename "$dir"`
+ # only consider linux based targets
+ if [ -e "$dir/not_linux" ]; then
+ #echo "$codename: not linux based"
+ continue
+ fi
+ # check if we can find a rootfs
+ rootfs_tgz="$dir/rootfs.tgz"
+ if [ ! -e "$rootfs_tgz" ]; then
+ echo "$codename: no rootfs found"
+ continue
+ fi
+ echo "$codename: found rootfs `basename $rootfs_tgz`"
+ ./parse_nvp_nodes.sh "$rootfs_tgz" "nodes-$codename.txt"
+done
+
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 @@
+# usage
+# parse_header.sh /path/to/icx_nvp.h
+# parse_header.sh /path/to/linux/source [file]
+# parse_header.sh /path/to/linux.tgz [file]
+# the optional argument is an additional filter when there are several matches
+# and is an argument to grep
+#
+if [ "$#" -lt 1 ]; then
+ >&2 echo "usage: parse_header.sh /path/to/icx_nvp.h|/path/to/kernel/source|/path/to/kernel.tgz [filter]"
+ exit 1
+fi
+
+FILE="$1"
+IN_TGZ="0"
+FILTER="$2"
+
+# for directories, list all files
+if [ -d "$FILE" ]; then
+ LIST=`find "$FILE"`
+else
+ # otherwise try un unpack it using tar, to see if it's an archive
+ LIST=`tar -tzf "$FILE"`
+ if [ "$?" == 0 ]; then
+ IN_TGZ="1"
+ TGZ="$FILE"
+ else
+ # assume the input is just the right file
+ LIST="$FILE"
+ fi
+fi
+
+# apply user filter
+if [ "$FILTER" != "" ]; then
+ LIST=`echo "$LIST" | grep "$FILTER"`
+fi
+# if file contains icx_nvp_emmc.h, we want that
+if [ "`echo "$LIST" | grep "icx_nvp_emmc.h" | wc -l`" = "1" ]; then
+ LIST=`echo "$LIST" | grep "icx_nvp_emmc.h"`
+else
+ LIST=`echo "$LIST" | grep 'icx[[:digit:]]*_nvp[[:alpha:]_]*.h'`
+fi
+LIST_CNT=`echo "$LIST" | wc -l`
+if [ "$LIST_CNT" = "0" ]; then
+ >&2 echo "No icx nvp file found"
+ exit 1
+elif [ "$LIST_CNT" != "1" ]; then
+ >&2 echo "Several matches for icx nvp:"
+ >&2 echo "$LIST"
+ exit 1
+else
+ FILE="$LIST"
+fi
+
+# if file is in archive, we need to extract it
+if [ "$IN_TGZ" = "1" ]; then
+ >&2 echo "Extracting $FILE from $TGZ"
+ TMP=`mktemp`
+ tar -Ozxf "$TGZ" "$FILE" > $TMP
+ if [ "$?" != 0 ]; then
+ >&2 echo "Extraction failed"
+ exit 1
+ fi
+ FILE="$TMP"
+else
+ >&2 echo "Analyzing $FILE"
+fi
+
+cat "$FILE" | awk ' \
+BEGIN { \
+ expr = "#define[[:space:]]+ICX_NVP_NODE_([[:alnum:]]+)[[:space:]]+ICX_NVP_NODE_BASE[[:space:]]*\"([[:digit:]]+)\""; \
+} \
+{ \
+ if($0 ~ expr) \
+ { \
+ print(tolower(gensub(expr, "\\1,\\2", "g", $0)));
+ } \
+}'
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 @@
+# usage
+# parse_nodes.sh /path/to/icx_nvp_emmc.ko output_file
+# parse_nodes.sh /path/to/rootfs/dir output_file
+# parse_nodes.sh /path/to/rootfs.tgz output_file
+#
+if [ "$#" -lt 2 ]; then
+ >&2 echo "usage: parse_header.sh /path/to/icx_nvp.ko|/path/to/rootfs/dir|/path/to/rootfs.tgz output_file"
+ exit 1
+fi
+
+FILE="$1"
+IN_TGZ="0"
+OUTPUT="$2"
+
+# for directories, list all files
+if [ -d "$FILE" ]; then
+ LIST=`find "$FILE"`
+else
+ # otherwise try un unpack it using tar, to see if it's an archive
+ LIST=`tar -tzf "$FILE"`
+ if [ "$?" == 0 ]; then
+ IN_TGZ="1"
+ TGZ="$FILE"
+ else
+ # assume the input is just the right file
+ LIST="$FILE"
+ fi
+fi
+
+# look for icx_nvp_emmc.ko
+LIST=`echo "$LIST" | grep "icx[[:digit:]]*_nvp[[:alpha:]_]*.ko"`
+LIST_CNT=`echo "$LIST" | wc -l`
+if [ "$LIST" == "" ]; then
+ >&2 echo "No icx nvp file found"
+ exit 1
+elif [ "$LIST_CNT" != "1" ]; then
+ >&2 echo "Several matches for icx nvp:"
+ >&2 echo "$LIST"
+ exit 1
+else
+ FILE="$LIST"
+fi
+
+# if file is in archive, we need to extract it
+if [ "$IN_TGZ" = "1" ]; then
+ >&2 echo "Extracting $FILE from $TGZ"
+ TMP=`mktemp`
+ tar -Ozxf "$TGZ" "$FILE" > $TMP
+ if [ "$?" != 0 ]; then
+ >&2 echo "Extraction failed"
+ exit 1
+ fi
+ FILE="$TMP"
+else
+ >&2 echo "Analyzing $FILE"
+fi
+
+./nvptool -x "$FILE" -o "$OUTPUT" >/dev/null