|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sony NW/NWZ series: unpacking and repacking UPGThis tool allows one pack and unpack firmware upgrades for Sony players that run linux. Codenames in the following table correspond to the SonyNW page Note: Android devices (NWZ-ZX1, NW-ZX2 etc...) are not supported! If your player is not in this list, help us. If the list below says "No (never)" it means your device cannot be supported because this feature is not supported by your device.
Getting the toolYou can either download a prebuilt tool or build it from source.
You can build the tool from source on Linux, you can also cross-compile from Linux to Windows. You can build it on windows but it will required a POSIX environment like MSYS or Cygwin.
Reporting an unsupporting device to developersIn order for a new device to be supported, it's "Key and Signature" (KAS) needs to be known. The KAS can be obtained from the device using thescsitool , available at SonyNWDestTool.
How to get UPG filesSony typically distributes firmware upgrades in the format of an executable file (EXE). For most older models, tools likecabextract or unshield (Linux) or 7-Zip (Windows) can extract files from the executable. The UPG file is typically located either in the root directory or in the subdirectory Data/Device .
For some recent models (NW-A50, NW-WM1 etc), it won't be possible to extract the UPG file directly from the executable. In this case, you need to run the executable and it will extract the UPG file to a temporary directory, usually C:\Users\[User_Name]\AppData\Local\Temp\SPackTool\[random_directory_name]\Package\Data\Device
What are UPG filesFirmware upgrades are distributed in the UPG file format. There are two versions of this format, but the only visible difference (for developers) is the length of the KAS (16 bytes for recent devices, 8 bytes for older ones) and the MD5 file for newer models (see below). A UPG file is just an encrypted firmware archive. There can be any numbers of files but some are specials:
Upgrade scriptIt is not important to understand how the upgrade script works, however reading it is useful because it contains two important pieces of information
ORDER_KERNEL_ROOTFS=2 ORDER_SYSTEM=6 ... COMMON_KERNEL_PARTITION=/emmc@bootimg SYSTEM_PARTITION=/emmc@android ... fwpup -f /contents/$_UPDATE_FN_.UPG -$ORDER_KERNEL_ROOTFS $COMMON_KERNEL_PARTITION ... fwpup -z -f /contents/$_UPDATE_FN_.UPG -$ORDER_SYSTEM $SYSTEM_PARTITIONWe can see that the script uses fwpup to unpack the files. the "-X" gives the index (-1 is index 1 for instance), the "-z" means the entry is compressed.
There is some magic going on for compressed files where the upgrade script will extract the MD5 from the second entry. This is not important to know as long as you do not touch the script.
Unpacking filesUnpacking files is very easy: here is how to extract all files to a subdirectorymkdir output_dir upgtool -e -m nw-a30 -o output_prefix/ NW_WM_FW.UPGThis will unpack files and creates files 0.bin , 1.bin and so on. If you know a file is compressed, you can ask the tool to uncompress it for you and (optionally) check its MD5 file against the second file.
For this you need to know the index and the name used in the MD5 file. For instance, if 1.bin contains
838860800 3b53977f89c3e1d768388ae2cf51a2b7 system.imgand you known the system partition has index 5, then you can run instead upgtool -e -m nw-a30 -o output_prefix/ NW_WM_FW.UPG -z 6,system.imgIt is possible to uncompressed several files by passing multiples -z options. If the MD5 file is missing or you do not want to check the MD5 (or you working with older devices that do not have MD5 files), just pass the index to -z as follows;
upgtool -e -m nw-a30 -o output_prefix/ NW_WM_FW.UPG -z 6Note: at the moment, upgtool will always extract all files at one, it does not support extracting just one file, although support for that could be added.
Packing filesPacking files is very similar to unpacking them, but there is a slightly subtlety with compressed files. If you do not want to compressed files, then simply give the tool the list of files, in the order you want. So the first file will have index 0, and so on. Here is an example to repack a file unpacked above:upgtool -c out.upg -m nw-a30 tmp/*.binor if you are working on windows: upgtool -c out.upg -m nw-a30 tmp/0.bin tmp/1.bin tmp/2.bin tmp/3bin tmp/4.bin tmp/5.bin tmp/6.bin tmp/7.bin tmp/8.binPacking files that are compressed is slightly more involved (on newer) models because of the MD5 files. You have two options:
Let the tool generate the MD5 fileIt is really recommended to the let tool do this for you. In this case, you will still need to pass an empty file for index 1 (the second file). Then add for each compressed entry a switch of the form-z index,name .
The index is the index of the file to compress and the name is the one that will appear in the MD5 file. For instance, we can repack the compressed system file of above as follows:
touch empty.txt # create an empty file upgtool -c out.upg -m nw-a30 -z 6,system.img tmp/0.bin empty.txt tmp/2.bin tmp/3bin tmp/4.bin tmp/5.bin tmp/6.bin tmp/7.bin tmp/8.bin Generate the MD5 by handFirst generate the MD5 (or keep it untouched if you are not modifying anything). Then repack the file, specify files to compress using-z index but no name.
upgtool -c out.upg -m nw-a30 -z 6 tmp/0.bin tmp/1.bin tmp/2.bin tmp/3bin tmp/4.bin tmp/5.bin tmp/6.bin tmp/7.bin tmp/8.bin
r3 - 02 Apr 2021 - 20:46:07 - UnknownUser
Copyright © by the contributing authors.
|