Commit graph

1273 commits

Author SHA1 Message Date
Lorenzo Miori
2dd6633d71 ypr0 - ypr1: dynamically move rockbox executable
This trivial patch wants to exploit /tmp filesystem to place
Rockbox executable. Why that? It will be then possible to
easily unlock & umount the storage partition, in order to provide
Rockbox itself a mean for RAW storage access. In turn, this will
allow a Rockbox-handled USB Mass Storage support, as well as other
goodies (storage info is one I can think of).

It takes way less than a second so it doesn't hurt boot time.
Moreover, YPR0/YPR1 targets have plenty (64MB) of RAM, so
the humble half meg executable won't hurt at all.

Change-Id: Ibc9d9a40712e924c8e19cfd7c62189b182f0401a
2020-07-07 17:51:41 +00:00
Lorenzo Miori
3016d74c5a Samsung YP-R0: remove deprecated kernel module
This patch removes the deprecated kernel module to manage
the fm-radio chip on the ypr0 target.
http://gerrit.rockbox.org/r/#/c/1594/ implements the interface to
the i2c bus by using the i2c-dev kernel driver, no need for
additional complexity.

Change-Id: I0d09e2e9d1714b3cb8a72b3d79a91602a627cc90
2020-07-07 16:51:05 +00:00
Dominik Riebeling
a686dbfaa4 sbtools: Avoid calling pkg-config on each compiler invocation.
Only expand pkg-config calls once by making the compiler flags simply
expanded variables. Makes things more predicable and slightly faster.

Change-Id: Ie2ed066f205a95ec8a7708cefeb29e9989815db6
2020-06-21 09:07:17 +02:00
Dominik Riebeling
9b4e6ef7b3 deploy: Support Python3.
Change-Id: Iff92a1f6a918f7da80f26f1a9ca02a6f6f082b7d
2020-06-13 20:11:53 +02:00
Dominik Riebeling
440791105a deploy: Fix various style issues.
Fix various pylint issues and some python3 compatibility.

Change-Id: I2c35ccc5ad2d0902c229f9de57912cf6d5a83ece
2020-06-13 20:11:48 +02:00
Dominik Riebeling
aefbc13e19 deploy: Add missing Windows system libraries to known list.
Building with mxe failed due to the toolchain (and Qt5) introducing
dependencies to system libraries we don't know about. Commit 3083abeb95
thus ignored the actual problem. Revert that and instead add the missing
system libraries to the list of known libraries.

Change-Id: I29ac296765e580b751d3d906d58ab563d05efde2
2020-06-13 20:11:43 +02:00
Solomon Peachy
2434b6ca25 misc: Remove all 'twiki' references in favor of up-to-date 'wiki' links.
(This migration happened over a decade ago!)

Change-Id: Ib396414a16f2d763e549af49e3f3b03047dab49c
2020-06-07 01:38:55 +00:00
Amaury Pouly
fba4df5d6d nwztools/scsitool: add command to write NVP
Change-Id: I4a7a9688af1abb14de82013703f3a02b4644d5ed
2020-05-27 23:39:06 +02:00
Amaury Pouly
c75dbaae25 nwztool/scsitool: add brute-forced kas
Change-Id: I692b06c7c456bfa4395aa2aa848fdc664bd203d4
2020-05-17 20:21:13 +02:00
Amaury Pouly
47104e9e51 nwztools/scsitool: add preliminary code to decode SCSI requests
This can be useful to quickly device usb traces

Change-Id: I843fbd5280f11686ea810b44ffb1414e844ebcf9
2020-05-17 20:21:13 +02:00
Amaury Pouly
e3532b1667 nwztools/scsitool: fix compile issue with some version of cryptopp
Change-Id: Ia20f0142a2b08bddd61a0056f49c8e4c9ed49caa
2020-05-17 20:21:12 +02:00
Amaury Pouly
ae6a49638b nwztools/scsitool: add more NVP properties
At least newer devices support more NVP properties in a device-independent
numbering. Many are supported but I just added two useful ones

Change-Id: I57926de7f0dd364b46a57ca8d48a5c4d4f20402b
2020-05-17 20:21:12 +02:00
Amaury Pouly
f86723716c nwztools/scsitool: add alternative firmware upgrade command
Newer devices seem to require flags 0x00 where older devices wanted 0x80, now
try both variants

Change-Id: Ifeee641052857c66c1b64860d7309a235021a168
2020-05-17 20:21:12 +02:00
Amaury Pouly
1686093e78 nwztools/scsitool: tweak output
Change-Id: I43c5101502f3d2c34296b510b738276fd74f9b3d
2020-05-17 20:21:12 +02:00
Solomon Peachy
9eba95d625 FS13192: rbutil: Fix linking error on Fedora 32 beta
Change-Id: I350553db037ad9f65aced3f974afeaeee3fe822a
2020-03-29 18:57:08 +02:00
Amaury Pouly
05a40ab07c scsi: add support for listing devices on Windows
Change-Id: I963028c6017796152a201791c078f672bf84a40a
2020-01-29 13:27:18 +01:00
Amaury Pouly
392db31d90 sonynwz/scsitools: fix string buffer size
Change-Id: I8997e7c3791b805a70a30cd1209a69b7afbec1e7
2020-01-29 13:26:42 +01:00
Amaury Pouly
44fb7f384e sonynwz/scsitools: add NWZ-S610 series
Change-Id: I8977e1bcc805df463f7b08f11be889368db4eab2
2020-01-29 13:25:56 +01:00
Amaury Pouly
ee15e45224 nwztool/scsitool: rewrite device detection on linux to make it simpler
Change-Id: I8f393a53ea64c82f05e437923bcba05aa8a7a75c
2020-01-12 23:12:18 +01:00
Amaury Pouly
9e94a5eadc nwztools/scsitool: fix out of buffer access
Change-Id: Ib2c25dd21d39fda026e008950a805f032c916a72
2020-01-12 23:11:59 +01:00
Amaury Pouly
fbad457339 nwztools/scsitools: simplify code and enable O2
Change-Id: Ic14bc5ff643c9cf4c6380b4c34999d704c65e460
2020-01-12 21:42:23 +01:00
Amaury Pouly
d6c9303c75 sonynwz/scsitools: add support for NW-A56
Change-Id: I07e57218638ef62c0e4bf92833add6c3ba7bdcd8
2020-01-12 17:59:02 +01:00
Franklin Wei
3083abeb95 deploy-rbutil.py: allow zipball building to proceed if no DLLs are found
This helps with MXE static builds, which were failing because no DLLs were
found.

Change-Id: Id3fcdf9a7682a9ecb6a5892415077bf16e8b24cb
2019-11-14 19:42:06 -05:00
Franklin Wei
b2fb095ab5 rbutil: include nwztools source in release tarball
Change-Id: Ic6d998441fb532a914eea2838fdc0d196f930bb2
2019-11-10 19:56:50 -05:00
Franklin Wei
a5f228eee2 rbutil: fix windows cross compile (via M cross environment)
This fixes a couple of issues when cross-compiling for windows:
 - lib builds (i.e. mks5lboot) were overriding the cross CC/CXX with the
   native CC, producing incompatible binaries.
 - Qt made the accessibility plugin part of the core library, so we no
   longer need to import it.

Change-Id: I9d884aee62dfa51d3624a3fa9b99c23b3b375f20
2019-11-09 20:54:57 -05:00
Amaury Pouly
4ed5727654 nwztools: fix Makefile
Seems like newer versions of mingw will sponteanously add a .exe suffix to
the output path if it doesn't have one, for example mingw-gcc -o scsitool bla
will actually create scsitool.exe and of course this breaks my release script.
Fix this by explicitely adding the .exe to avoid any problem

Change-Id: Ic8019b968b532b2ca612ba0c03977a96c22cee01
2019-04-22 23:45:33 +02:00
Amaury Pouly
063ff294a2 nwztools: add DMP-Z1 to the database
This is one of those fancy gold-plated devices. Of course it breaks my scripts
that were nicely expecting every device to start with NW.

Change-Id: I161320f620f65f4f92c2650d192b26a9831eeb9d
2019-04-22 23:45:33 +02:00
Solomon Peachy
07084f62c4 Fix host build of mkimxboot, mknwzboot, nwztools, and rbutil with crypto++
Necessary to get working builds on my Fedora 29 system.

Change-Id: Ia6232427c959629ade9a85fc412738f688facedb
2019-01-25 12:58:18 +01:00
Amaury Pouly
c1194aedb0 sonynwz: add NW-ZX300G nvp info
There is something weird going on: the Sony website has two different entries:
- NW-ZX300/NW-ZX300A/NW-A45/NW-A47/NW-A45HN/NW-A46HN
- NW-ZX300,NW-ZX300A update(20181004)/NW-ZX300G
with slightly different nvp entries, but it is impossible to tell whether
an NW-ZX300(A) belong to one or the other. Since the diff is very small,
I am adding this as nw-zx300g but treat all devices as nz-zx300 since the
destination node is the same and that is the main usage of the tool anyway.

Change-Id: I3dc2fdec52650f938d568bed578184f6bc43d130
2018-11-30 15:37:10 +01:00
Amaury Pouly
110e3b43a0 sonynwz: add NW-A57 and NW-ZX300G to the database
Change-Id: I9bbfa56c5b2d79568de5443f1098d724c4beda6a
2018-11-30 15:37:10 +01:00
Amaury Pouly
4c318057f6 nwzstools/scsitool: try to guess series if possible
If the model is not known (ie model ID in the database) but another device from
the same series is known, then the database information probably applies and
one can use the "force" option -s to tell the tool to ignore the model ID.
Automatically print such advice when the series can be guessed.

Change-Id: I6bcc7aa29693df8c3d7d8e709ece7cea650be717
2018-11-30 15:37:10 +01:00
Amaury Pouly
da752d0084 nwztools/scsitool: add experimental command to list Sony devices
Change-Id: Ic4f382667c5c84514be661d36032c47fb8f92e75
2018-11-30 15:37:10 +01:00
Amaury Pouly
e01248efcd rbscsi: add experimental API to list connected SCSI devices
For now it is only implemented on linux using /sys scanning

Change-Id: Ifdfe7564e6e8d0307ae6ddc53e49bb9aaf5a8268
2018-11-30 15:37:10 +01:00
Amaury Pouly
4365437159 Indentation fix
Change-Id: Ia0f96dd27c520cf2bfec4765619f53eaffee3e20
2018-11-30 15:37:10 +01:00
Amaury Pouly
110fd2cae6 Add the NWZ-A844 to the database
For some reason even Sony didn't have it in its list...

Change-Id: I26de6071e5887cc7c6ebb695ea333c7b3d1b50db
2018-11-30 15:37:10 +01:00
Amaury Pouly
0120ecd651 sonynwz: add nvp map for NW-A50 series
Change-Id: I49f3399552721e515cc01021c2e0aa28c781ec28
2018-10-29 15:10:24 +01:00
Amaury Pouly
8a4cb5e619 sonynwz: add NW-A55 to database
Change-Id: I59861119c59490f586b3c6ed32a1c41df8b3d365
2018-10-29 13:29:39 +01:00
Marcin Bukat
734be0d6aa MIPS: fix memset()
swr/swl instructions used for word aligning were wrong. This
made memset() terribly broken. I can't imagine how it went
uncaught for soooo long. Spotted by Solomon Peachy.

I run unit tests for alignments 0,1,2,3
size 1, 2, 3, 4, 5, 63, 64, 65, 127, 128, 129;
and fill pattern 0x00 and other (since 0 is special case in this
implementation).

Change-Id: I513a10734335fe97734c10ab5a6c3e3fb3f4687a
2018-09-07 09:43:05 +02:00
Amaury Pouly
11437662c4 nwztools/scsitool: fix completely stupid code
Change-Id: I3771388d24fe5fa249dcb40b231d7a4e06d3c3c8
2018-01-13 19:12:43 +01:00
Amaury Pouly
4d988d43d8 nwztools/scsitool: print clearer message when nvp info is incomplete
Change-Id: I13b20b88b35e825da929a31e71ff42d68a79f131
2018-01-13 12:18:01 +01:00
Amaury Pouly
6c856c412a Add information for NWZ-S630 and NWZ-S730
Change-Id: I4c48c9a8d862eaf67ec27c1c13b9b7f1fb204fc0
2018-01-13 12:07:21 +01:00
Amaury Pouly
0d794c0c06 sonynwz: Add NVP information for NWZ-A810
Change-Id: I37671ddf15ee1a4b469f97fe06ec86249ff9ce60
2018-01-07 23:24:58 +01:00
Amaury Pouly
ec4fa0333c hwstub: add code to dump STMP rom
Change-Id: I083024662f3c085f7bcd2f85b0a68de85725b0f3
2017-11-12 14:14:30 +01:00
Amaury Pouly
dd6b8427f9 hwstub: expose read/write functions
Previously only atomic read/write 8/16/32 were exposed. But it is useful to
be able to read a whole buffer at once, this is more efficient than N times
read8.

Change-Id: I06e331641e1ab1f74c0e16e8c432eafb398e8e6d
2017-11-12 14:13:21 +01:00
Amaury Pouly
df0edba18e hwstub: fix horrible bug
It's a wonder it worked, basically any big transfer returned garbage

Change-Id: Ic2b2fc1805423c70db8eac40692ba842c72462ab
2017-11-12 14:12:44 +01:00
Amaury Pouly
07d3b3c1fb nwztools/scsitools: print device list when listing series
Change-Id: Ic46c724c5d89a775dc20853410c8fe6f0ff9a4c8
2017-11-01 12:43:33 +01:00
Amaury Pouly
62f0ba1c30 nwztools: add NW-A46 to the database
Change-Id: I85dc2080e0be07ff689384c0445f4f1595baf4ac
2017-11-01 12:43:33 +01:00
Amaury Pouly
7807934a27 atjboottool: document more header fields and crypto code
The encryption definitely uses some standard elliptic curve encryption over
binary fields (163 and 233 bits, standard polynomials). It is still unclear
how this is used in the actual encryption, the key authentification and
derivation do not look standard.

Change-Id: I6b9180ff7e6115e1dceca8489e986a02a9ea6fc9
2017-10-26 18:17:59 +01:00
Amaury Pouly
819d3ee02e nwztools: add NW-A45
Change-Id: I75a7723498564ee73c3682391582e354ad672fd7
2017-10-24 17:47:28 +01:00
Amaury Pouly
2ae792c2f5 nwztools: add NW-ZX300A
Change-Id: I8b311ed6b48b92b9ecf4fb25c19119cfb2d5beb1
2017-10-24 11:46:19 +01:00
Amaury Pouly
e441c2696d nwztools/upgtools: make the tool print the whole kas, not just 16 bytes
Change-Id: I9daca9148b7aaea905a765dfeb95faf6fb7198b1
2017-10-22 15:35:10 +02:00
Amaury Pouly
7e42e90294 atjboottool: add support for FwuTail
Change-Id: Ib01a2ff92294dd0bb59439c23f26bc31eafa4a39
2017-10-20 23:57:58 +02:00
Amaury Pouly
6e79c4cb7c nwztools: add KAS for NW-A40 series
Change-Id: I6e22ba0a58eb62dcc9f2025ee7233f5afae1bbec
2017-10-20 19:46:35 +02:00
Amaury Pouly
1eab18c9e4 nwztools/scsitools: don't try to get nodes when we don't know about the device
Change-Id: Id35671f1e039a94e2b319262e4faa51d73f12afd
2017-10-17 13:34:54 +02:00
Amaury Pouly
9a8a52cb07 nwztools/scsitool: slightly rework of help_us and help
Now print list of devices immediately even if the rest of the command line
is empty (ie 'scsitool -s ?' works, whereas before one would need an actual
device to even get a list). Add more information in the help_us command:
print kas, lyr and fpi.

Change-Id: Icfeeaeebe28c774a74ca54661357fafa25c3d114
2017-10-17 13:05:58 +02:00
Amaury Pouly
6922323466 sonynwz: add NW-A47 to the database and regenerate nwz_db.{c,h}
Change-Id: I6331a48a4d336348e90a32cf151427b29eeedb2b
2017-10-17 13:05:11 +02:00
Amaury Pouly
5af813c5b7 nwztools: add NW-ZX300 KAS, extracted from a device
Now this is very weird, is it yet another format/encryption?

Change-Id: I119dec1e6d636a99508fb1394de27237ca3ab814
2017-10-07 22:01:00 +02:00
Amaury Pouly
0fbd93b7e6 nwztools/scsitools: fix database
I forgot to add the NW-ZX300 to its series

Change-Id: I78fd9440492e1868b887f6a2e137d4d0c2ff199a
2017-10-07 18:44:30 +02:00
Amaury Pouly
7eb240a288 Add Sony NW-ZX300 model id to database
Change-Id: I8e7a14b86408c52cbd4a059e2db6a9c9d0966fc6
2017-10-07 12:45:48 +02:00
Amaury Pouly
2f3801be34 fix typo
Change-Id: Ic357f82d61cc0004ac6193fa9dbbc90976042574
2017-10-06 18:31:11 +02:00
Amaury Pouly
d9da4833a7 nwztools/scsitool: various improvements
The tool now provides more useful information for developers when the device
is not supported. Is also has a new verb "help_us" that also prints all this
information (notably the device info and model ID).

Change-Id: I04baec8fff23eb83a0408add6296b5d42e9aa8e7
2017-10-06 12:10:40 +02:00
Amaury Pouly
698779e3e8 sonynwz: add nvp nodes for NW-A40/ZX300, various fixes for tools
We still miss the model IDS for those device so scsitool won't be able to
recognize them automatically.

Change-Id: I17ae0f0d95c011cea8e289def63c7673b6c4b667
2017-10-06 12:10:33 +02:00
Amaury Pouly
ea679de837 atjboottool: put afi and fw code in its own files
Change-Id: I16347ebee0f82d5fdf32f5aa8f955c07fe148eba
2017-09-29 18:22:30 +02:00
Amaury Pouly
95c32a505a atjboottool: split fwu code into its own file
Slightly cleanup the code by removing the old and dangerous --force option.

Change-Id: I776633a9924797fcd509b8b80623bcd64b391672
2017-09-29 17:56:04 +02:00
Amaury Pouly
5f4de5bf48 nwztools/scsitools: make do_fw_upgrade output less confusing
Change-Id: If616e646aeddf20aa3cee79a821a420d9102c708
2017-09-19 21:53:52 +02:00
Amaury Pouly
99cc8f8802 upgtools: fix bug in brute force search
DES ignores the parity bit of each byte (making the 64-bit key really 56-bit),
but the current code skipped the parity bit of each half-byte, thus missing
some keys.

Change-Id: Ia523ebb944e458905b7de1742df151df22166150
2017-09-19 15:30:37 +02:00
Amaury Pouly
127e6bbfdd Add support for the NWZ-E350
Strangely it has the SAME encryption key as the E450. Either they didn't bother
changing it or more likely they have exactly the same internals and a slightly
different case.

Change-Id: I39ab88845b3e40db34160c2e61dde421f391df44
2017-09-17 23:47:49 +02:00
Marcin Bukat
8b744571c0 ATJ hwstub: Add cache coherency
All the hard work was done by pamaury. I simply added proper
defines.

Change-Id: Ib374eea7cd20f35518ad8a68d771c57c54ae01ca
2017-09-15 21:44:59 +02:00
Amaury Pouly
e6de6c107e qeditor: add workaround for c++11 in qt4, suggest to use qt5
Change-Id: Iad7b8fd171d57228796a68cb3406914213b91926
2017-09-06 20:45:34 +02:00
Amaury Pouly
1d121e8c08 Initial commit for the Sony NWZ linux port
SUPPORTED SERIES:
- NWZ-E450
- NWZ-E460
- NWZ-E470
- NWZ-E580
- NWZ-A10

NOTES:
- bootloader makefile convert an extra font to be installed alongside the bootloader
  since sysfont is way too small
- the toolsicon bitmap comes from the Oxygen iconset
- touchscreen driver is untested

TODO:
- implement audio routing driver (pcm is handled by pcm-alsa)
- fix playback: it crashes on illegal instruction in DEBUG builds
- find out why the browser starts at / instead of /contents
- implement radio support
- implement return to OF for usb handling
- calibrate battery curve (NB: of can report a battery level on a 0-5 scale but
  probabl don't want to use that ?)
- implement simulator build (we need a nice image of the player)
- figure out if we can detect jack removal

POTENTIAL TODOS:
- try to build a usb serial gadget and gdbserver

Change-Id: Ic77d71e0651355d47cc4e423a40fb64a60c69a80
2017-09-05 21:42:12 +02:00
Amaury Pouly
e2271ed75e qeditor: fix compile error and some comments
Change-Id: I157c83fea8173adc53254f15aa49e41ee1ba7549
2017-08-28 22:52:29 +02:00
Amaury Pouly
d1ca2e45e9 atjboottool: cleanup and add support for atj2127
Several people asked me recently how to decrypt atj2127 firmware. Someone
posted on github (https://github.com/nfd/atj2127decrypt) a decrypt utility
clearly reverse engineered from some unknown source. The code is an absolute
horror but I concluded that ATJ changed very little between ATJ213x and ATJ2127
so I added support for the ATJ2127, credit to this github code that I stole
and rewrite (code was under MIT licence). At the same time do some small code
cleanups.
Note that there is not 100% sure way that I know to distinguish between the
two firmware types, so the code tries to do an educated guess to detect
ATJ2127. If this does not work, use --atj21217 option. Also note that contrary
to the github tool that decrypts and unpack in one go, this tool only does one
step at once. So first decrypt: HEX -> AFI, then unpack AFI -> files.
I also added for a different version of AFI. Based on AFI files I have, there
are, I think, two versions: the "old" ones (pre-ATJ213x) and "new" ones. The
tool only supported the new one but for some reason the ATJ2127 uses the old
ones without a mostly empty header. Strangely, even this mostly empty header
does not seem to follow the old layout as reverse engineered by the s1mp3
project (https://sourceforge.net/p/s1mp3/code/HEAD/tree/trunk/s1fwx/heads.h),
so in fact there might be three versions. In any case, only the header is
different, the rest of the file is identical so at the moment I just don't
print any header info for "old" files.

Change-Id: I1de61e64f433f6cacd239cd3c1ba469b9bb12442
2017-07-30 14:32:12 +02:00
Amaury Pouly
37a945d203 nwztools/scsitool: add a command to query multiple nvp nodes at once
Change-Id: I89fed904b282a202bc845b08f4c8d1200a49636d
2017-06-18 23:16:18 +02:00
Amaury Pouly
91ede1ea08 nwztools/scsitool: fix devinfo, add dhp
The devinfo request returned the raw data, now the tool prints the various
fields. Also add support for the dhp (destination/headphones/color ...): this
one is untested because it's only supported starting from A10 or A20. There is
still a problem with the dpcc prop: although it should work for DEVINFO, it does
not, despite the fact that the get_dev_info command works and is internally (on
the Sony) translated into a dpcc request. I keep the code just in case.

Change-Id: I5aa8ef4afb0b11d3c0ddfa3d38f3e737ee1aff66
2017-06-18 13:37:26 +02:00
Amaury Pouly
8d5dcd395d nwztools/scsitool: print error on check sense
The detailled error message is only printed if -d switch is on command line,
otherwise there is no error message which is wrong so fix that.

Change-Id: I397541c467940e9b290ee8d4ae704368b1ce132b
2017-06-18 13:35:42 +02:00
Amaury Pouly
e9bb9a25ad nwztools: add KAS for NW-S10 (brute-forced using upgtool)
Change-Id: Ia37818faee29130ffe3690c83f85a39bd35637e0
2017-06-13 21:03:03 +02:00
Amaury Pouly
cd812218ab nwztools: add nvp description for NW-S10 series
Change-Id: Id6a6e51288f4ff24c0063b6c16b74109211e63c0
2017-06-13 20:41:43 +02:00
Amaury Pouly
28c3f6b4d3 Add NW-A36 and NW-A37 model IDs, based on the A30 service manual.
I am unsure about the names of the player, the manual says A36HN and A37HN but
at the same time there is a A35 and A35HN with the same ID, and Sony does not
usually put the "HN" in its device list.

Change-Id: Idbf32970aa334b30f1b8947a78b8eebd524b193b
2017-06-05 16:17:13 -05:00
Igor Skochinsky
03dd4b92be nwztools/database: misc improvements
* make gen_db.py work on Windows/Python 2

- use hashlib module instead of md5sum, also don't rely on / for file path
matching
- don't use 'file' for a variable name

* fix parse_nvp_header.sh for older kernels

pre-emmc kernel sources use a slightly different #define format; adjust
regexp to catch it.

* add nwz-x1000 series NVP layout (from icx1087_nvp.h)

some new tags have no description, alas the driver doesn't have
them :/

*  minor fixes to nvp/README

fixed typos/wording

Change-Id: I77d8c2704be2f2316e32aadcfd362df7102360d4
2017-04-25 11:24:24 +10:00
Igor Skochinsky
f1c8d63a76 nwztools/upgtools: misc fixes
* added KAS for nwz-x1000 (extracted from an NWZ-X1060 via "get_dnk_nvp kas")

* hint that -o is needed when extracting

Change-Id: Ic91c448aa058a22c8ddcae54726f628f7cf60f6b
2017-04-25 11:23:57 +10:00
Amaury Pouly
88dd2026c4 nwztools/upgtools: add key for NWZ-A840
Change-Id: I0a191db1970e64b5ced518c68861392ba342404f
2017-04-25 11:22:08 +10:00
Amaury Pouly
15e66a5b19 nwztools: small cleanups
Change-Id: I4fde020ca0556a84d051f9b5e46f49ee1241266e
2017-04-25 11:21:54 +10:00
Amaury Pouly
1597c4fe34 scsi: don't make the linux lib depend on a library header file
The code dependend on the sg_lib header being present, remove this dependency
so that we only need public headers.

Change-Id: I69398453635135deb33e2adf67f15ddb80e4ba16
2017-04-03 15:02:19 +02:00
Amaury Pouly
d052f13999 nwztools/script: fix dump_rootfs.sh to handle ext4
Change-Id: I04bd7599a58669df96dfd018a2ab0e3d53e06694
2017-02-04 17:20:09 +01:00
Amaury Pouly
2ea0ccb6c5 regtools/qeditor: replace deprecated QStyleOptionViewItemV4
...by QStyleOptionViewItem. Yes Qt got it right, in 5.7 they deprecated
QStyleOptionViewItemV4 and recommend using QStyleOptionViewItem which contains
less fields except on newer Qt where it contains all fields. Hopefully it still
works on Qt>4.x for a large enough value of x.

Change-Id: I013c383d2424b04c1c0745f0d7b1d5e62a29d324
2017-02-04 17:19:50 +01:00
Amaury Pouly
2a3a6bb4b3 regtools/qeditor: compute RAM size
Change-Id: I7bfb5cc25bc3dc55f379b2319b20dc9510434de0
2017-02-04 17:19:20 +01:00
Amaury Pouly
fa5324bbbb regtools/qeditor: enable imx233 analysers for imx233
The clock structure is identical, and the EMI are the same.
Also fix SSP clock, it was broken on imx233 as well.

Change-Id: I25ec66059b00b1a456ef2f02131d225082536c0a
2017-02-04 17:18:59 +01:00
Amaury Pouly
fafb770ca5 regtools/soc_desc: fix bug in library
Because a node ref is at root doesn't make it valid, check that soc is valid
otherwise we return garbage.

Change-Id: I6e5befc959dc670ab39a87484e87af6d90be7726
2017-02-04 17:18:37 +01:00
Amaury Pouly
6f0f1193e5 regtools: add new tool list/find/describe registers
Change-Id: I2d93d24bd421e1a2ea6d27b8f7cfd17311e6d458
2017-02-04 17:18:13 +01:00
Amaury Pouly
a1d1832049 hwstub: be more quiet about register description loading failure
Change-Id: I0edbb838022b71485179edec7361a6c554a1ab11
2017-01-24 15:34:20 +01:00
Amaury Pouly
30ac37b20b hwstub: fix memory leak in net backend
Change-Id: I98bef5aa0c518e698c42761d02899adde8bc4aca
2017-01-24 15:34:20 +01:00
Amaury Pouly
fdb98c258f hwstub/jz4760b: add lua code to probe for ei/di and ext instructions
Add lua code to check whether ei/di and ext instructions are supported. This
is unclear since xburst is somewhere between mips32r1 and mips32r2. Details
results are below, but in summary: they don't work (ei has no effect, di/ext
cause illegal instruction exceptions)

> ./hwstub_shell -q -b -e 'require("jz/misc"); JZ.misc.enable_sram()' \
  -f lua/xburst.lua -e "XBURST.test_ext_inst(0xb32d0000)"
[...]
Selecting soc jz4760b. Redirecting HW to hwstub.soc.jz4760b
  data: d7168acf
error: lua/xburst.lua:209: call failed
trapped exception in call

> ./hwstub_shell -q -b -e 'require("jz/misc"); JZ.misc.enable_sram()' \
  -f lua/xburst.lua -e "XBURST.test_ei_di_inst(0xb32d0000)"
[...]
Selecting soc jz4760b. Redirecting HW to hwstub.soc.jz4760b
Testing ei
  Test SR
    Enable interrupts with CP0
    SR: 0x1
    Disable interrupts with CP0
    SR: 0x0
  Test ei/di
    Enable interrupts with ei
    SR: 0x0
    Disable interrupts with di
error: lua/xburst.lua:244: call failed
trapped exception in call

Change-Id: I2e162b5dd5e70488bcd8b58f3ca401a3ecab3c4b
2017-01-24 15:34:20 +01:00
Amaury Pouly
9bb6050d40 hwstub: rewrite exception catching
Since we can catch exceptions like data aborts on read/write, it takes very
little to also catch exceptions in calls. When extending this with the catching
of illegal instructions, the call instruction now becomes much more robust and
also for address and instruction probing. Since we can catch several types of
exception, rename set_data_abort_jmp to set_exception_jmp. At the same time,
simplify the logic in read/write request handlers. Also fix a bug in ARM
jump code: it was using
  stmia r1, {..., pc}
as if pc would get current pc + 8 but this is actually implementation defined
on older ARMs (typically pc + 12) and deprecated on newer ARMs, so rewrite the
code avoid that. The set_exception_jmp() function now also reports the exception
type.

Change-Id: Icd0dd52d2456b361b27c4776be09c3d13528ed93
2017-01-24 15:34:19 +01:00
Amaury Pouly
f3cce72269 hwstub/jz460b: implement exception recovery
Now that we now that jz4760b implements EBASE, we can use it to rebase
exceptions to use a k1seg address, that maps to the physical address of the
TCSM0. It requires to enable HAB1 to have this translation. This most the most
inefficient way to access tighly coupled memory ever, but it works.

Change-Id: I894ca929c9835696102eb2fef44b06e6eaf96d44
2017-01-24 15:34:19 +01:00
Amaury Pouly
07bc348c91 hwstub: add tool to dump memory regions (such as ROM, RAM, or peripherals)
Although this case be done with hwstub_shell, this is common enough to deserve
its own tool.

Change-Id: I9253e40850f37257464548a3acefb14ea083841d
2017-01-24 15:34:19 +01:00
Amaury Pouly
f4091be1d3 hwstub: small fixes to argument processing and usage()
Change-Id: I3daa5e0c3fa2e7eab6a3d75b4c8aa66254d72f3c
2017-01-24 15:34:05 +01:00
Amaury Pouly
9851849ae6 hwstub/jz4760b: build packtools automatically if neeeded
Change-Id: I543e405bf75868d0f7509a35e08fe31ed253e0e6
2017-01-24 15:31:05 +01:00
Amaury Pouly
8934169666 hwstub: add verbose mode to make
Use make V=1 to print all commands

Change-Id: I28bd4151178413f10ddab292f1d582a9d019f5ea
2017-01-24 15:31:05 +01:00
Amaury Pouly
eadba57d53 hwstub: fix long transfers failing because of control xfer size of libusb
libusb limits control transfer sizes to 4k, see diff for details.

Change-Id: Id2e638010274009ea641d06e9040a8b9ab9d54a9
2017-01-24 15:31:05 +01:00
Amaury Pouly
24c208336c hwstub: fix library sending wrong data on long transfers
Change-Id: I886b8dc28e306f631389dbed41451eb086fea4fc
2017-01-24 15:31:05 +01:00
Amaury Pouly
06c5e5f4c1 hwstub: add Fiio X3II IPL/SPL dumping code
Change-Id: I76f7cffc700e8051d02936c24e8a70a0f8925edf
2017-01-24 15:25:14 +01:00
Amaury Pouly
3a219cefe1 hwstub: add Shanling M2 IPL/SPL dumping code
Change-Id: I14987d9783dd371f4990a5bcfbfb2d1c0c9be213
2017-01-24 15:25:14 +01:00
Amaury Pouly
8e07d68452 hwstub: add various jz stuff and xburst tests
The JZ misc allows to enable and test SRAM.
The XBurst code uses the coprocessor interface to analyse the cpu. It also
provides a test platform for various features like EBASE and exceptions.
I was able to test and confirm that on jz4760b (thus xburst), EBASE works
(but top 2 bits are not controllable and always 01). The processor claims
to support vector interrupts but this is untested. The values in ConfigX
are not to be trusted blindly, clearly some are wrong. I tried to use the
JZ4780 Config7 "ebase gate" to change bit 30 of EBASE but it does not work,
which suggests that JZ480 uses a newer version of XBurst. Detailled log below:

> ./hwstub_shell -q -f lua/xburst.lua -e "XBURST.init()"
[...]
XBurst:
  PRId: 0x2ed0024f
    CPU: JZ4760(B)
  Config: 0x80000483
    Architecture Type: MIPS32
    Architecture Level: Release 2 (or more)
    MMU Type: Standard TLB
  Config1: 0x3e63318a
    MMU Size: 32
    ICache
      Sets per way: 128
      Ways: 4
      Line size: 32
    DCache
      Sets per way: 128
      Ways: 4
      Line size: 32
    FPU: no
  Config2: 0x80000000
  Config3: 0x20
    Vectored interrupt: yes
  Config7: 0x0

> ./hwstub_shell -q -e 'require("jz/misc"); JZ.misc.enable_sram()' \
  -f lua/xburst.lua -e "XBURST.test_ebase(0x80000000);XBURST.test_ebase(0xb32d0000)
[...]
Testing EBASE...
  Disable BEV
  SR value: 0x2000fc00
  EBASE value: 0x80000000
    Value after writing 0x80000000: 0x80000000
    Value after writing 0x80040000: 0x80040000
  Test result: EBase seems to work
    Disable config7 gate: write 0x0 to Config7
    Value after writing 0xfffff000: 0xbffff000
    Enable config7 gate: write 0x80 to Config7
    Value after writing 0xc0000000: 0x80000000
  Config7 result: Config7 gate does not work
Exception test with EBASE at 0x80000000...
  Writing instructions to memory
  Old SR: 0x2000fc00
  New SR: 0xfc00
  EBASE: 80000000
  Before: cafebabe
  After: deadbeef
  Exception result: Exception and EBASE are working
Testing EBASE...
  Disable BEV
  SR value: 0x2000fc00
  EBASE value: 0x80000000
    Value after writing 0x80000000: 0x80000000
    Value after writing 0x80040000: 0x80040000
  Test result: EBase seems to work
    Disable config7 gate: write 0x0 to Config7
    Value after writing 0xfffff000: 0xbffff000
    Enable config7 gate: write 0x80 to Config7
    Value after writing 0xc0000000: 0x80000000
  Config7 result: Config7 gate does not work
Exception test with EBASE at 0xb32d0000...
  Writing instructions to memory
  Old SR: 0x2000fc00
  New SR: 0xfc00
  EBASE: b32d0000
  Before: cafebabe
  After: deadbeef
  Exception result: Exception and EBASE are working

Change-Id: I894227981a141a8c14419b36ed9f519baf145ad1
2017-01-24 15:25:14 +01:00
Amaury Pouly
50eaa2d9ac hwstub: fix bug in jz4760B boot rom backend probe
Change-Id: Idb2b3b3903d88c8f6b494d5c9f04778daf3aaed0
2017-01-24 15:25:14 +01:00
Amaury Pouly
8fabbb008c hwstub: add support for coprocessor operations
At the moment the stub only implement them for MIPS.

Change-Id: Ica835a0e9c70fa5675c3d655eae986e812a47de8
2017-01-24 15:25:14 +01:00
Amaury Pouly
d91d9f6851 jz4760b/regtools: fix/rename some register fields, add clock analyzer to qeditor
Change-Id: I196414d6e4fc18c00b77903e334b7e6adfb7debc
2017-01-24 15:25:14 +01:00
Amaury Pouly
51cce81cd4 headergen_v2: add two new macros to write a raw write to set/clr variants
These macros are like jz_setf but instead of writing fields, they write a
raw value directly: jz_set(REG, value) and jz_clr(REG, value).

Change-Id: I660f20dd691b26d367533877875fc3226a26c992
2017-01-24 15:25:14 +01:00
Amaury Pouly
a36694eb4a hwstub: implement EXEC command over net
Apparently I completely forgot to implement it so using hwstub over net would
just fail all EXEC commands :-s

Change-Id: I0d0506cbbce9b86c9a4f19036dacc922d1e51338
2017-01-24 15:25:14 +01:00
Amaury Pouly
56340f4cd0 hwstub: add the possibility to flush caches before exec
This is needed on the jz4760b because if some data is loaded to DRAM, then it
is cached and a disaster lurks if dcaches/icache are not flushed. Targets that
needs this must define CONFIG_FLUSH_CACHES in target-config.h and implement
target_flush_caches(). Currently MIPS has some generic code for mips32r1 that
requires to define {D,I}CACHE_SIZE and {D,I}CACHE_LINE_SIZE in target-config.h

Change-Id: I5a3fc085de9445d8c8a2eb61ae4e2dc9bb6b4e8e
2017-01-24 15:25:14 +01:00
Amaury Pouly
83155f32bf jz4760b_tools: improve usbboot tool
Change-Id: I21b61a3f56d718bef3aa0cf5096359c463c1f93a
2017-01-24 15:23:21 +01:00
Amaury Pouly
f698b201ad hwstub/jz4760b: fix some typos in lua script after register name changes
Change-Id: Ie46ec293fcd5a16143818e77cd6c79cc08620fb5
2017-01-24 15:22:43 +01:00
Amaury Pouly
cc2389b7a6 hwstub: add jz4760b stub
The stub is quite versatile: it can be loaded using bootrom or another other
means (like factory boot on Fiio X1). It relocates itself to TCSM0 and provides
basic functionality (it does not recover from failed read/writes at the moment).

Change-Id: Ib646a4b43fba9358d6f93f0f73a5c2e9bcd775a7
2017-01-24 15:22:27 +01:00
Amaury Pouly
d7c71a3fe8 update jz4760b register desc
Change-Id: Id0a071528eca08fe512941be9c8091819e817e4c
2017-01-24 15:17:46 +01:00
Amaury Pouly
4fd9400458 hwstub/tools/shell: add JZ4760B and Fiio X1 code
The jz code can do several useful things like dumping the IPL and SPL.
The Fiio code can play with backlight and has code do dump the IPL
and SPL with the correct parameters (extracted by reverse engineering).

Change-Id: I317b3174f5db8d38c9a56670c1d45565142ec208
2017-01-24 15:17:46 +01:00
Amaury Pouly
0b6cbd8e49 regtools: add JZ4760B description
This is a register description file for the JZ4760B. There are several
details worth noticing:
- it was obtained by gathering information from several sources/headers, but
  since there are inconsistencies between them about the exact differences
  between JZ4760 and JZ4760B, this file probably contains some errors
- the register names are not the same as the manual ones (which are not the
  same as the one in the headers anyway): I dropped the "R" suffix on most
  registers because it's redundant
- Ingenic likes to have read-only registers and then set/clr registers, with
  very confusing names like DIR/DIRS/DIRC: in the file, the set/clr registers
  are described as set/clr variants of the original register
- Parts of the description were obtained programmatically, which explains why
  there are empty nodes or partially undocumented registers

Change-Id: I8da1d61e172e932e1a4a58ac0a5008f02b1751be
2017-01-24 15:17:46 +01:00
Amaury Pouly
6ef3f7c13b regtools: fix normalization procedure
The code was not updated when I added support for list and other stuff, and thus
it did not properly sort by addresses.

Change-Id: Iaed0717b607beedfb2856c020c2a760e7a5667c5
2017-01-24 15:17:46 +01:00
Amaury Pouly
6b227c5ea6 regtools: convert all reg dumps to v2. keep v1 for reference
Change-Id: Ib496eb5d47adb75479ce94a203d4a93524700843
2017-01-16 20:09:18 +01:00
Amaury Pouly
759a78e5df imxtools/sbtools: switch SHA1 implementation to Crypto++
The current implementation was custom and super slow. Since we use Crypto++
anyway, we might as well get use a good implementation.

Change-Id: I761ad7401653471e54000e1c2bc3d9882378112f
2017-01-16 19:59:28 +01:00
Amaury Pouly
8b3f5a8ad7 imxtools/sbtools: switch AES implementation to Crypto++
Instead of having our own copy of the AES code, use a good library to do that.
Crypto++ is well-maintained, supports a lot of ciphers, works on many OSes, and
is optimized for many architectures.

Change-Id: I7d7d24b47993206d7338c5f9bac8bbdd3915a667
2017-01-16 19:59:26 +01:00
Amaury Pouly
5ff3a3a98f imxtools/sbtools: various fixes
Change bug() macro, fix memory leaks, always use -h for help, fix usage(),
fix comment, remove useless macro

Change-Id: I30554b5e07e6f2845560a570808603cf8c4da5ad
2017-01-16 19:58:31 +01:00
Amaury Pouly
2b20026dd7 imxtools/sbtools: rework cryptography
It was a mess, a mix of crypto_* and cbc_mac calls. I made everything call crypto
functions, and also separate key setup from cryptographic operations, this will
be useful to speed up the code in the upcoming commits. Drop support for "usbotp"
key, since the crypto code for that was never mainlined and we can always get the
keys from a device as long as we have code execution (using the DCP debug registers).

Change-Id: I7aa24d12207ffb744225d1b9cc7cb1dc7281dd22
2017-01-16 19:58:24 +01:00
Amaury Pouly
cb8a98e365 imxtools: correctly read unencrypted images in raw mode
Change-Id: I87830b81a017f36d2887d9c289d09812f227b157
2017-01-16 19:51:12 +01:00
Amaury Pouly
a5950c69af imxtools: rework key/IV overriding logic
The overriding of the IV and real key should be the exception, there is no
need to manually set them to false.

Change-Id: Id66754f20a79aa5c1a991839345d1242e0aa587d
2017-01-16 19:50:25 +01:00
Amaury Pouly
2df6b1fc43 imxtools: rework sb file production
The old code had some annoying way of dealing with padding by adding explicit
instructions to the stream, which is 1) ugly 2) not in par with freescale
tools. The trick, which this new version implements, is to put the useful length
of the section in the section header, and the actual (with padding) length in
the boot tag. This way the tools can just ignore padding instruction by
reading the section header, and the bootloader can still load the image because
it uses the boot tags.
Also correctly handle the case where the first section does not start right
after the header (there is a bug in freescale tools for this case by the way).
There is an ambiguity in the way the padding instructions should be encrypted:
the bootloader should logically treat them as regular instruction of the section
stream, but it appears the freescale tools do not generate them as part of the
stream and instead encrypt them like boot tags, which is stupid because there
is no way the bootloader could decrypt them, and anyway we don't care because
the bootloader doesn't decrypt them at all.

Change-Id: Iabdc1d1f9f82d374779bf03efb75c2c3998f5b5d
2017-01-16 19:49:07 +01:00
Amaury Pouly
0cabc1fc51 nwztools/upgtools: add real KAS for NW-ZX100 and fix typo
Change-Id: I4e4679d6e92c1c0fc8a03db5201aee39d82b24b2
2017-01-14 12:02:34 +01:00
Amaury Pouly
1d7f6048f4 nwztools: add a "reset all settings" message in dest_tool
Users can't read the wiki instructions, hopefully they can read this...

Change-Id: I3840879fdc663fb6e7f9234f352eea04a556256a
2017-01-09 22:15:53 +01:00
Amaury Pouly
90284b6fe0 nwztools: fix typo (nwz-zx100 -> nw-zx100)
Also now gen_db.py can check for such mismatch

Change-Id: I4d91aae0dde08c866eda2ed5da3c11431c46e06a
2017-01-09 21:48:43 +01:00
Amaury Pouly
1d7b37eda1 nwztools: add various info about S740, S750, S640, E050
Change-Id: I2cc887ce2824a2d0b9aeb2a89df662c621c28750
2017-01-08 22:34:57 +01:00
Amaury Pouly
a38e9bac26 nwztools: forgot file
Change-Id: I4341f2af71675cb795987ecc5ce12104445a9d97
2017-01-08 22:33:00 +01:00
Amaury Pouly
18b4bf299f nwztools/upgtools: add real NW-A20 kas
Change-Id: I88fb2aefafbc7820a49847fbf0888de9cf81bd3f
2017-01-08 16:08:43 +01:00
Amaury Pouly
9b2fab1ca9 Makefile cleanups
Change-Id: I69b8b81d357553c979682d42097eba864c951512
2017-01-08 16:08:28 +01:00
Amaury Pouly
1895af8e15 nwztools/scitool: rework node size, remove relaxed mode
The cool now takes the database as a hint and will not complain if the device
returns less data. The tool also supports user provided size and raw node numbers
that are not in the database (advanced usage).

Change-Id: I8cec536718d7eff01c7803bea648d6122b82377a
2017-01-08 16:07:18 +01:00
Amaury Pouly
26774ece35 nwztools: add NW-WM1 kas
Like the NW-A30, we don't know how to use it, but record it anyway.

Change-Id: Iebd26637253613625a4885afe88695ad3ffb0605
2017-01-08 12:31:47 +01:00
Amaury Pouly
80d91e0cf5 nwztools: add A35 model and KAS
We don't know the encryption method, the KAS is completely different but it
might be useful to record it anyway for future purposes. MID extracted from
device, Japanese NW-A35.

Change-Id: I4c4bb5b063da99003b5c316061d8c490b77428a4
2017-01-08 12:30:46 +01:00
Amaury Pouly
096ae78c20 nwztool/upgtools: replace NWZ-A10 kas by the real one
Extracted from a target.

Change-Id: Ieb4aff15f332a681142a7079c1adf3b1da31de24
2017-01-08 12:09:54 +01:00
Amaury Pouly
1bd8207e30 nwztools: rename nwz-a20 to nw-a20, that was a typo
Change-Id: I88ae7391732c6f41c3c4adccce2ddf0a92142067
2017-01-08 12:09:49 +01:00
Amaury Pouly
5a0a7b8b58 nwztools: remove NW-ZX2
It is Android based and despite the fact that Sony wrote an NVP driver for it,
experiments suggest it is unused because it returns ff all the time...

Change-Id: I37750b659e341b21bed5ebaccf60f9f5fe569f64
2017-01-07 22:22:59 +01:00
Amaury Pouly
be68b6a7bd nwztools: add NW-WM1A/Z model IDs
Also fix code that was supposed to sort things deterministically and was a
massive failure.

Change-Id: Iedf25f05a94ef51421710a283eb60f33ee977de1
2017-01-07 17:32:47 +01:00
Amaury Pouly
76c73c707a nwztools/scsitools: use new SCSI library
Change-Id: I1b5688ba7ad99c7a22ba4532c8237b4563e4a9e4
2017-01-07 16:31:28 +01:00
Amaury Pouly
86e745a25e nwztools/scsitool: add relaxed mode for nvp
Change-Id: I0a139eb236f825368ae627fdbb2f75286f747f10
2017-01-07 15:53:03 +01:00
Amaury Pouly
456a3fc952 imxtools: various fixes for Windows
Don't use colors since the terminal doesn't support it. Also packing is broken
on MinGW so use #pragma pack when compiling for windows, this is also supported
by MSCV.

Change-Id: I635649d52ed5f2e0af46cb9ca2ec325955b2ddb2
2017-01-07 15:52:33 +01:00
Amaury Pouly
950f4bdc02 imxtools: move firmware read/write to library
Split the ugly firmware read/write into a API function and a much simplified code.
Also the code can now report progress.

Change-Id: I3f998eaf0c067c6da42b1d2dd9c5a5bf43c6915d
2017-01-07 15:52:33 +01:00
Amaury Pouly
0778184782 imxtools/scsitools: move stmp scsi api to its own file
No code modification code, just moving code around.

Change-Id: I30744d3994aa7540f4b5b158f31b51959d5d8586
2017-01-07 15:52:33 +01:00
Amaury Pouly
7fafbe1fc1 imxtools/scsitools: rework stmp scsi API
Sanitize the whole library by hiding most of the horrible details of the
implementation. This means that all logical/drive/table attributes are exported
in structures that are internally filled by higher-level API functions. This makes
the code much more readable and prepares for a split between scsitool and the stmp
scsi library.

Change-Id: Id85d450b25cf99cd7c0896c6fc35bcd00babe9e1
2017-01-07 15:52:33 +01:00
Amaury Pouly
0fd869423a imxtools/scsitools: use new SCSI library
The function names and prototypes are also normalized so make subsequent reworks
easier.

Change-Id: Ifa5d64aa144b11f8c087517ddc904744e3037361
2017-01-07 15:52:33 +01:00
Amaury Pouly
ae84354b40 Add multiplatform library for raw SCSI commands
Several tools need to perform raw SCSI commands, and we need to support Linux,
Windows and Mac OS, without pulling tons of dependencies to build it easily.
This very simple library has no dependency and supports Linux.

TODO:
- windows
- mac os

Change-Id: I496f5ad2490bd3e96ad962d31cce4e511a523c3a
2017-01-07 15:52:33 +01:00
Amaury Pouly
ad2297d353 nwztools/scsitool: add option to force/specify series
We cannot auto-detect a device if we don't know its model ID, but we can't know
the model ID if we haven't decrypted the upgrade which requires the key. The only
way to solve this chicken-and-egg problem is to get the NVP table from kernel,
create an empty series in the database (no model ID), then get the key using
scsitool and forcing the model (using this commit), then decrypt the upgrade
and get the model ID list.

Change-Id: I8eced486a5f6a1a99028b25fdc4f87a3b11e31a8
2017-01-04 17:14:31 +01:00
Amaury Pouly
dbeb6db1b5 nwztools: cleanup crypto, switch MD5 to Crypto++
We already use Crypto++ for DES anyway, and using OpenSSL is not great because
of its incompatible licence.

Change-Id: I78771b84c1708795a0c0c30afa5bdfe4885dea4e
2017-01-04 17:05:15 +01:00
Amaury Pouly
92ecbd5fb8 nwztools/upg: move upg handling to its own file, completely rework kas handling
This was a huge mess, the new is much cleaner hopefully.

Change-Id: I43663d021dc8bc31662d3923e1c3da22d987ebf9
2017-01-04 17:04:38 +01:00
Amaury Pouly
5cfd4a5b8e nwztools/upgtools: add more brute force algorithms
Allow to search for hex with upper case and alphanumeric. This is *much* slower
of course.

Change-Id: I41a2fc63c4b2220c21147b711098ebc37ddb3527
2017-01-04 17:04:19 +01:00
Amaury Pouly
bfd5704749 nwztools: add NW-WM1 nvp table, regenerate database
Change-Id: If5781f0a98b3f2fee08a2daed383064cc59f1680
2017-01-04 17:03:54 +01:00
Amaury Pouly
3c3e133f99 nwztools: small fixes
Make sure scripts use bash, make nwz database generator more deterministic

Change-Id: I26812b697abe0406fb3c60d6eb231cb27edc81d5
2017-01-04 17:03:14 +01:00
Amaury Pouly
985f6e6935 imxtools: fix bug aes128 (did not update cbc-macp)
Although this does bug is never triggered because we never decrypt and use the
resulting CBC-MAC, it's a major overlook.

Change-Id: I3c5d318e6428d528483bf888ea284e9ded3889f0
2017-01-01 19:52:00 +01:00
Amaury Pouly
5c50efc9ce hwstub/tools: always run make for the libraries
This ensures that the libs are always up-to-date hopefully.

Change-Id: I790302fcabc91457091006de749b76735fdd510f
2016-12-12 11:53:41 +01:00
Amaury Pouly
8e82839fe2 hwstub: various cleanups
- hwstub load now properly stops reading the log when the device returns a 0
  size buffer instead of STALLing
- add debug output option to hwstub_load
- correctly report transfered size on write error
- add some debug error message in usb code so that some errors can be diagnosed
  more easily
- add a batch mode to hwstub_shell to disable the interactive shell
- increase usb control timeout to 1sec, 100ms was really tight
- cap usb buffer size to ~4000 bytes because libusb has a hardwired limit of
  4096 bytes for control transfers

Change-Id: Id3200ab99ce70a7a3b09ce7faeaafa4a0fac64c7
2016-12-12 11:35:16 +01:00
Amaury Pouly
a88f57ec36 nwztools/scripts: mount storage with ext3 instead of ext2
Since ext3 supports ext2, we can support more platforms. Some platforms use ext4
with a very specific set of options, we I haven't encountered those yet so it's
not currently a problem.

Change-Id: Iff87e925a4caa866c6a66b1883ad6baab88c0b8d
2016-11-20 21:36:54 +01:00
Amaury Pouly
ce966d3d28 hwstub/tools: fix compilation of shell against lua5.3
The unsigned function were deprecated and hidden begind a compat flag. Since
they will get removed in the next version, I simply reimplemented them, those
are mostly casts anyway.

Change-Id: Ie5db81d7c8589b1e5e9b45a2a4ed41919aa07387
2016-11-20 21:36:54 +01:00
Amaury Pouly
06502772a8 nwztools/plattools: improve makefile to build images automatically
Change-Id: Ibf17fe523c6ef534368d6f94f43fce5ac0c91caf
2016-11-20 21:36:54 +01:00
Marcin Bukat
deaeb73912 Add KAS for NWZ-E470
Change-Id: I1b8272a486ba2377e5047855acda3f80aa92c232
2016-11-14 20:54:05 +01:00
Amaury Pouly
0c1a96101c nwztools: rework dualboot
The new code gets closer to an actual bootloader:
- it provides a menu with three options: Sony, Rockox, tools with icons (and
  extracts the Sony logo from the NVP)
- the dualboot install script now creates a symlink from /.rockbox to
  /contents/.rockox which is necessary to run rockbox
- more text drawing / framebuffer functions
In the long run, we will move this under bootloader/ and rbutil/ and also use
firmware/ drawing facilities, at the moment we use OF display program which
is slow and creates some flickering.
The logo extraction/placement code was tested with resolution 240x320 and I
guessed some reasonable values for 240x400, but those will probably need some
tweaking.

Change-Id: I0319be902d21a7d33c1dee0fffdb4797065dbf8a
2016-11-12 22:16:48 +01:00
Amaury Pouly
33856d9ceb nwztool/scsitools: cleanup and add destination changer tool
Now that we have a nice database of player index, the scsitool becomes more
useful and supports a lot more players. I did some general cleanup of the code,
though eventually it would be nice to really split it into a library and a CLI.
The SCSI vendor command allow to read but also write most NVP nodes. Since there
seems to a demand to change destination and sound pressure settings on device,
I implement this feature in the tool. I do not plan to allow arbitrary NVP
writes because this could easily brick the device. Changing the destination
should be safe, but as usual, use at your own risks.

Change-Id: Iff4e8cc3ac97b965c1df849051c5fd373756cda5
2016-11-11 16:07:14 +01:00
Amaury Pouly
c95e30b75d nwztools/plattools: use player database and rework stuff
Using the database, we can now safely read/write the NVP. I also add more
support for Sony's "display" tool.

Change-Id: I8439fe9bad391c7f29859d99f236781be7983625
2016-11-11 16:07:14 +01:00
Amaury Pouly
44bb2856a5 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
2016-11-11 16:07:14 +01:00
Amaury Pouly
19de536ce2 nwztools/upgtools: cleanup
There is no need to store the key and sig since those are derived from the KAS
anyway.

Change-Id: I228913b1cb32e496db265e9a7aaf3bb4200a9f6b
2016-11-11 16:07:14 +01:00
Marcin Bukat
ba9f405dc4 ATJ hwstub make irq based usb driver work
0e2b490 introduced rework of usb driver which was broken. It was reverted
in f2da975 to restore hwstub functionality on ATJ.

This commit reenables usb rework AND fixes remining issues.
The problem was with 0 length OUT thransfers. Additionally
a few cleanups were made.

Change-Id: I529ea9ad6540509e9287ca7e1cd2b44369b03cbb
2016-11-10 13:57:02 +01:00
Marcin Bukat
f2da975be6 Revert "hwstub: rework usb driver for atj213x"
This reverts commit 0e2b4908d0.

Although I swear it was tested it apparently broke hwstub on atj.
I will need to investigate more whats going on. Revert for now.

Change-Id: I2ff3adf8c72bb0e53be7d81b975382adfb700eab
2016-11-08 08:37:24 +01:00
Amaury Pouly
3b7e7cb535 hwstub_shell: fix a horrible bug
Change-Id: I4ac259e6cd7b707ca725c6ba1c526f5aeed56b71
2016-11-06 21:59:50 +01:00
Amaury Pouly
25bd580509 forgot file
Change-Id: I32e23035a608ee04a69690975ab4bf629a902388
2016-11-06 00:15:08 +01:00
Amaury Pouly
5017babb30 nwztools/plattools: fix black screen issue in dualboot, rework dualboot
Sony added extensions to the frambuffer interface. It is important to take them
into account since the OF uses them and might leave the framebuffer in an
unusual state which would make the dualboot not display anything. Also rework
the dualboot code so that it can boot rockbox (not doing anything at the moment),
display all tools or boot the OF.

Change-Id: Ia0f589c9ec8558f375270841503c0964aff07f0b
2016-11-06 00:12:04 +01:00
Amaury Pouly
d492f25c54 nwztools: add preliminary dualboot and dualboot install script
At the moment, the script install_duaboot does the following:
- rename SpiderApp to SpiderApp.of (unless it already exists)
- install payload as SpiderApp
- fixes permissions
Since SpiderApp is the main app, it will execute instead of the OF.
The current dualboot code (dualboot.c) is still a preliminary but the current
version displays an "all tools" menu to choose for. When exitting the menu
using BACK, it will run the OF.

With the modifications made by the install script, it should not be possible
to break the device. In the worst case scenario, the dualboot code crashes
and it restarted by the sysmgrd, or hangs. A safe way to recover is to plug
the USB cable and reset the device: the system manager will then start the
USB app and one can reflash the device if necessary.

Change-Id: Id9edab0347538ad2a8651a28aea7fd083feaa626
2016-11-01 17:09:07 +01:00
Amaury Pouly
b045e4da34 nwztools/upgtools: sanitize series name and add keys
Unify series names: e46x -> e460 to be consistent with Sony' name. Add keys
for various players that were cracked using upgtools. The real KAS would need
to be extracted from a target but at least we can open/create firmware upgrades.

Change-Id: Id23a10e10170d7f6330c6699bf205c4df5ddebfe
2016-10-31 17:51:18 +01:00
Amaury Pouly
0a2290653b nwztools/plattools: rework/clean and add an all-in-one tool
This new tool (all_tools) embeds all the other tools and provides a menu to
choose which one to run.

Change-Id: I0e07864dd46559a7079b0f942c25155e6fa07112
2016-10-31 17:50:16 +01:00
Amaury Pouly
ad9a2d5241 nwztools/plattools: add a tool to change destination and sound pressure
Since the nwz_lib does not have any nvp code yet, it's quite of ugly hack
with hardcoded nvp node (11) for shipment information (shp). Thus I whitelisted
two series (NWZ-E460 and NWZ-A860) which I know for sure use this node ID.

Change-Id: I94c9b0db1f9d7ad764d2aa50576a911e710f25e1
2016-10-28 23:28:25 +02:00
Amaury Pouly
3097239ce6 nwztools/plattools: add device list
This list can map from model id to device name. It was automatically extracted
from Sony's tools. In the future, we will probably generate it from a clean
database containing more useful information.

Change-Id: Ibe580edf25b60bf0bf4aef4a06f40dddd19c5404
2016-10-28 23:27:29 +02:00
Amaury Pouly
281c8d4700 nwztools/scripts: export model id in an environment variable
This is useful because there is no easy way to get it except from Sony's tool,
unless one knows the npv node, but that requires to know the model already...

Change-Id: I202f7cdb2f7cf924cc5bdb53c17e34600d4bf153
2016-10-28 23:25:43 +02:00
Amaury Pouly
37f95f67fe nwztools/upgtools: rewrite keysig brute force search
The new search has two new features:
- it takes advantage of the fact that DES keys are only 56-bit long (and not 64)
- it is now multithreaded
As a proof of concept, I ran it on the A10 series firmware upgrade and was able
to find the key in a few seconds using 4 threads. The search is still limited
to ascii hex passwords (seems to work on all devices I have tried thus far).

Change-Id: Ied080286d2bbdc493a6ceaecaaadba802b429666
2016-10-27 23:06:16 +02:00
Amaury Pouly
794104dd17 nwztools/plattools: switch to BACK key to quit
The power off/option does not exist on some models.

Change-Id: Ifb45293b3b3faa96d9fece2340cbd98299a4a0b7
2016-10-26 20:46:57 +02:00
Amaury Pouly
d42b43c786 nwztools/plattools: add test_power, rework input, add test_ts (touchscreen)
Change-Id: I55ca29627801b5e760d1dbe407d96cd055f659ab
2016-10-26 20:46:57 +02:00
Amaury Pouly
fed083cf06 hwstub: fix compile and linking ordering
Change-Id: I0acd3db2f644f4521da715d4931315bdb7548eae
2016-10-22 15:55:33 +02:00
Amaury Pouly
0b01ca69e0 nwztools/plattools: add adc test
Change-Id: Ic3ef964e8b5cc7b8ca3f02f141e9e4436a4d41db
2016-10-19 18:20:27 +02:00
Amaury Pouly
8d24b62912 nwztools/plattools: add backlight test
Change-Id: I4bef0824eeed54238578d8b24a9845e8602d61af
2016-10-19 17:58:40 +02:00
Amaury Pouly
ba91ff10e8 nwztools: add a new plattools directory with code to run on the device
This is code is intended to development into a library of code for the NWZ that
will be useful to write the "bootloader" on those device. At the same time, it
comes with test programs that are easy to run in firmware upgrade mode and also
provide a great test bench for the library. At the moment, two test programs are
available:
- test_display: simply prints two messages using /usr/bin/lcdmsg
- test_keys: displays input key event

Change-Id: I9d214894ffc9127b528fcdd3eb5d6b61f4e657a7
2016-10-19 17:09:04 +02:00
Amaury Pouly
13d892eef1 nwztools: update makefile and add script
The new script allows the upgrade to execute a file found on the user partition.

Change-Id: I564941d01bcdbae050002e77cb119f3d95ecdc21
2016-10-19 17:09:04 +02:00
Amaury Pouly
eaa1cb3469 fix typo
Change-Id: Ia69e5ff941549ca98b23b40927137bb29876b8f9
2016-10-19 17:09:04 +02:00
Amaury Pouly
21fb5aff39 nwztools: rework upg scripts
The exec_file allows to embed a script/executable and run it on target. It takes
of unpacking, remounting contents rw and redirect output to exec.txt at the root
of the drive. More generally, rework how the makefile works.

Change-Id: Iec719227be96e80701ad8f5398d2d34389f4da9e
2016-10-19 17:09:04 +02:00
Amaury Pouly
6f7ee0bb7c regtools: fix library bug when checking if a reference is valid or not
Change-Id: I8adea40d2fa7c1a26f1975d987233249f61af8ef
2016-09-21 00:31:18 +01:00
Amaury Pouly
7b1bcae879 regtools: rename error_t to err_t to avoid name clash
Change-Id: Ib8d34e4f58f3225b1dafc533ce7e1b7867ad053b
2016-09-21 00:31:12 +01:00
Amaury Pouly
84ff8a4df9 headergen_v1: remove warnings with newer GCCs
Change-Id: I90ed3a0c911014eee013cbea0e98a85f4310471d
2016-09-21 00:31:07 +01:00
Amaury Pouly
cf82f208e3 nwztools: cleanup the code
There was a lot of copy and paste, and the code was just crap. This commit tries
to clarify the code and also document the encryption procedure. Hopefully I didn't
break anything.

Change-Id: I257793010e7cf94f2b090b30bb8608359d3886e3
2016-08-30 17:21:05 +10:00
Amaury Pouly
de8950d63d upgtools: add NWZ-E45x Series key and signature
Also fix a typo in the script makefile

Change-Id: Ie747d8b99ca0f6a98bbcaf1c82e66c7788f00e6e
2016-08-30 17:21:05 +10:00
Amaury Pouly
71a369b37a upgtools: small cleanups
KAS was in its own structure for historical reasons, but it's stupid now.

Change-Id: Ie8d69ac6d489337cd857ace1abe5b1e4b1177172
2016-08-30 17:21:05 +10:00
Amaury Pouly
9d121cfd51 nwztools: upgrade upgtools and add dumping script
Change-Id: I315d1010ce5477c0112f4a890156b360e8123e11
2016-08-17 21:26:31 +01:00
Amaury Pouly
e62203aac1 regtools: add headergen_v2
This new header generator works differently from the previous one:
- it uses the new format
- the generated macro follow a different style (see below)
- the generated macro are highly documented!
- it supports SCT-style platform or RMW-style ones

Compared to the old style, the new one generate a big set of macros per
register/field/enum (loosely related to iohw.h from Embedded C spec). The user
then calls generic (names are customizable) macros to perform operations:

reg_read(REG_A)
reg_read(REG_B(3))
reg_read_field(REG_A, FIELD_X)
reg_read_field(REG_B(3), COOL_FIELD)
reg_write(REG_A, 0x42)
reg_write_field(REG_A, FIELD_X(1), FIELD_Y(3), IRQ_V(FIQ))
reg_write_fielc(REG_B(3), COOL_FIELD_V(I_AM_COOL), BLA(42))

the following use RMW or SET/CLR variants, depending on target:
reg_set_field(REG_A, FLAG_U, FLAG_V)
reg_clr_field(REG_A, FIELD_X, FIELD_Y, IRQ)
reg_clr_field(REG_B(3), COOL_FIELD, BLA)

the following does clear followed by set, on SET/CLR targets:
reg_cs(REG_A, 0xff, 0x42)
reg_cs(REG_B(3), 0xaa, 0x55)
reg_cs_field(REG_A, FIELD_X(1), FIELD_Y(3), IRQ_V(FIQ))
reg_cs_field(REG_B(3), COOL_FIELD_V(I_AM_COOL))

The generator code is pretty long but has lots of documentation and lots of
macro names can be customized.

Change-Id: I5d6c5ec2406e58b5da11a5240c3a409a5bb5239a
2016-05-25 00:11:07 +01:00
Amaury Pouly
c90d42dcc6 jz4670_tools: add usbboot tool, tweak Makefile and packtool
Although the jz4740 contains a similar tool to usbboot, its command-line
interface is not very useful, also it does not compile by default because it
relies on some external code, and it contains code specific to some JZ4740
devices.

Change-Id: I22688238d147e21fb0fd524466b333b6003d4ff1
2016-04-08 18:54:46 +01:00
Amaury Pouly
4934bd6f24 hwstub: remove the old library
Change-Id: I94d0f67cfd0d636407cd9cf3afbe0db4064de28e
2016-04-08 18:52:36 +01:00
Amaury Pouly
5ac0166388 qeditor: port to the new hwstub library and add features
This commit adds support for the version of the hwstub library, which requires
a lot of changes. It also adds some editing features, such as register access
and much better editing of fields using the mouse (double click on a field
to be able to resize and move it).

Change-Id: I3c4e4cc855cb44911c72bc8127bad841b68efe52
2016-04-08 18:46:46 +01:00
Amaury Pouly
cc4c9b70bc regtools: add register access to soc desc
Registers (and variants) can now specify the type of access supported:
- unspecified: for variant means same as register, for register defaults R/W
- read/write
- read only
- write only
Backward compatibility is preserved by setting access to unspecified by default.

Change-Id: I3e84ae18f962a45db62f996a542d08405d05b895
2016-04-08 19:38:36 +02:00
Amaury Pouly
f6c61eb11a hwstub: port hwstub_shell to the new library
Also use this opportunity to cleanup support for multiple devices: the shell
now supports dynamic changes in the device and will call init() everytime
a new device is selected, to prepare a new environment. The shell now
honors register width on register read/write. The shell also provides access
to variants as follows by creating a subtable under the register using the
variant type in UPPER case and having the same layout as a register.
For example if register HW.GPIO.DIR has variants "set" and "clr", those can
be used like this:
HW.GPIO.DIR.SET.write(0xff)
HW.GPIO.DIR.CLR.write(0xff00)

Change-Id: I943947fa98bce875de0cba4338e8b7196a4c1165
2016-04-08 19:38:18 +02:00
Amaury Pouly
a2f4c5201d hwstub: port hwstub_load to the new library
Change-Id: I7e8ae50907401a9480a0da809a4470f1728d3a57
2016-04-08 19:37:59 +02:00
Amaury Pouly
3d8a08ca25 hwstub: rewrite and expand library
Rewrite the hwstub library in C++, with a clean and modular design.
The library was designed from the ground up to be aware of multithreading
issues and to handle memory allocation nicely with shared pointers.

Compared to the original library, it brings the following major features:
- support for JZ boot devices, it is very easy to add support for others
- support for network transparent operations (through sockets): both tcp
  and unix domains are support

Change-Id: I75899cb9c7aa938c17ede2bb3f468e7a55d625b4
2016-04-08 19:37:30 +02:00