Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f6eb6e936 | ||
|
|
1776315097 | ||
|
|
def1d49ab4 | ||
|
|
3e863759d3 | ||
|
|
87202c38a0 | ||
|
|
246394d25b | ||
|
|
6ecc3e2a80 | ||
|
|
9164f331a3 | ||
|
|
d5ff815e72 | ||
|
|
8c624670cc | ||
|
|
51072eb40a | ||
|
|
bd54b19bbf | ||
|
|
69b5278710 | ||
|
|
2e78262c10 | ||
|
|
c03e01879e | ||
|
|
9087b564ba | ||
|
|
8084f68b50 | ||
|
|
1ebc2b8308 | ||
|
|
ae03494a73 | ||
|
|
6665ba9917 | ||
|
|
75df75b4e9 | ||
|
|
82dd535429 | ||
|
|
288726981a | ||
|
|
8635ea66a7 | ||
|
|
cbffb8f924 | ||
|
|
7b5d36bd4c | ||
|
|
067c84ea2c | ||
|
|
29c2b60670 | ||
|
|
09b6b377fe | ||
|
|
a6ec2b36c4 | ||
|
|
2cbeb4d0fe | ||
|
|
116e77bef7 | ||
|
|
2746da7a03 | ||
|
|
3d7b15e30b | ||
|
|
912ec5210e | ||
|
|
6a6a6348f5 | ||
|
|
01ec9928f9 | ||
|
|
bd141d2739 | ||
|
|
463dc3c6dd | ||
|
|
3f96851407 | ||
|
|
10217cd331 | ||
|
|
886b40e4b5 | ||
|
|
99294e1b74 | ||
|
|
5f0b6bb328 | ||
|
|
aa366ea133 | ||
|
|
4ef49e123a | ||
|
|
64505e1b73 | ||
|
|
a9c0daab68 | ||
|
|
420482c6b7 | ||
|
|
09a6405501 | ||
|
|
cc8cca84ef | ||
|
|
e98891e52d | ||
|
|
e66d87fde0 | ||
|
|
e4f7cf7bc5 | ||
|
|
cd9b51ad80 | ||
|
|
2189eebaf0 | ||
|
|
08adc52c78 | ||
|
|
95571860d0 | ||
|
|
f35c4048fe | ||
|
|
d76b5a2b44 | ||
|
|
d8c6a03147 | ||
|
|
fc51f45195 | ||
|
|
26c1c2914e | ||
|
|
230d45c9e3 | ||
|
|
f059663164 | ||
|
|
d9e6d47f1b | ||
|
|
b2bd1d90c7 | ||
|
|
863cf8134a | ||
|
|
6c220a45fd | ||
|
|
ada683ed9b | ||
|
|
5efa0d96b8 | ||
|
|
a321f275ef | ||
|
|
7868ad0c71 | ||
|
|
c0e490cc30 | ||
|
|
15b05dce75 | ||
|
|
e4b4d211c1 | ||
|
|
b0130e52d6 | ||
|
|
6d69da6cd1 | ||
|
|
3666e285dc | ||
|
|
ddb3406855 | ||
|
|
11410296a7 | ||
|
|
d636ef78dd | ||
|
|
0d6b32c371 | ||
|
|
66966a242d | ||
|
|
d1bb1b6094 | ||
|
|
28ca666c6e | ||
|
|
f8ad95ee4d | ||
|
|
f6c9450319 | ||
|
|
2127e08052 | ||
|
|
a072a2cf83 | ||
|
|
3a83d99f9a | ||
|
|
1a89112c25 | ||
|
|
10a2bc6319 | ||
|
|
55c158fc34 | ||
|
|
e41cf5236a | ||
|
|
54ddeb6407 | ||
|
|
8167e841ce | ||
|
|
ad7bab8df8 | ||
|
|
805bafacef | ||
|
|
40cd74c506 | ||
|
|
c92df79829 | ||
|
|
62aa414dc0 | ||
|
|
36aff5fca4 | ||
|
|
d9aeffa1d0 | ||
|
|
d0d249c738 | ||
|
|
db546a17b8 | ||
|
|
d35d6142ca | ||
|
|
2d52d8c3c6 | ||
|
|
1ba42ce46f | ||
|
|
1736afae69 | ||
|
|
0f5f96149f | ||
|
|
e084cdaabe | ||
|
|
89e70ea88c | ||
|
|
2544d42ee2 | ||
|
|
0d1d64bbfe | ||
|
|
26099e9536 | ||
|
|
17c6aefdcb | ||
|
|
ab07fec919 | ||
|
|
0e687beed3 | ||
|
|
131e8bbe1f | ||
|
|
0809303feb | ||
|
|
33d00aa714 | ||
|
|
24a12b2e72 | ||
|
|
6062a736d2 | ||
|
|
6cd01df098 | ||
|
|
8a21acc9cc | ||
|
|
8c1cfe3a6e | ||
|
|
8e2c830433 | ||
|
|
868bee0413 | ||
|
|
d6ad749515 | ||
|
|
83bcb7358c | ||
|
|
67d3e4de70 | ||
|
|
8c5590d150 | ||
|
|
cb25a8bd3e | ||
|
|
3c4c0088f0 | ||
|
|
e75b963d3a | ||
|
|
378dfe3162 | ||
|
|
dddf92646d | ||
|
|
791f805fa0 | ||
|
|
5325bfdfd1 | ||
|
|
3d42ebaf73 | ||
|
|
4ab76a5112 | ||
|
|
f4b0e9b6f3 | ||
|
|
6cf03a9e28 | ||
|
|
ded123141c | ||
|
|
8ea3ba3771 | ||
|
|
0e0844b78b | ||
|
|
a1d95afbf7 | ||
|
|
dc8844f112 | ||
|
|
a67a16479c | ||
|
|
24f34d2f55 | ||
|
|
19a8d76e0c | ||
|
|
aa89ef8dad | ||
|
|
ff7a89b781 | ||
|
|
8eb58ad08c | ||
|
|
32f2e53304 | ||
|
|
f79b653523 | ||
|
|
cc6e2dcfcd | ||
|
|
adbe2dabad | ||
|
|
4b7769a67d | ||
|
|
27acbb09a5 | ||
|
|
b142205f1c | ||
|
|
e4858deccd | ||
|
|
3ce8ca13f1 | ||
|
|
ad68e324c6 | ||
|
|
34b55a222e | ||
|
|
bc9441ddd6 | ||
|
|
6e0941a3c4 | ||
|
|
603a64757d | ||
|
|
2002ba27a2 | ||
|
|
01a7da1d95 | ||
|
|
70c09fb5b7 | ||
|
|
29084d4acf | ||
|
|
0d76941600 | ||
|
|
5dc162bc4a | ||
|
|
564b0715f1 | ||
|
|
6e710dcac9 | ||
|
|
b2883167d5 | ||
|
|
1b99ad115a | ||
|
|
9baad78435 | ||
|
|
d2ce7052ec | ||
|
|
d29c63cac9 | ||
|
|
f597e28a87 | ||
|
|
a0eff48f30 | ||
|
|
5310efb16c | ||
|
|
01239ea839 | ||
|
|
b4cbab6774 | ||
|
|
366680af1b | ||
|
|
4de49acb49 | ||
|
|
238f92ab25 | ||
|
|
71b63c29d3 | ||
|
|
e7de4ffe34 | ||
|
|
b581c7f25d | ||
|
|
d10814e808 | ||
|
|
b582869208 | ||
|
|
dd2c6b7f18 | ||
|
|
5b17b8e398 | ||
|
|
d96a54994e | ||
|
|
b80dfdc657 | ||
|
|
d06e88ce39 | ||
|
|
df9fae0c0e | ||
|
|
3fed685e79 | ||
|
|
ef4a506905 | ||
|
|
1a7d30cebf | ||
|
|
ea52c0509a | ||
|
|
01726cddc5 | ||
|
|
cd52b36d38 | ||
|
|
7ab41812ea | ||
|
|
2cab7a9c80 | ||
|
|
3ead19bdea | ||
|
|
03eeca994d | ||
|
|
b596e97926 | ||
|
|
589443a356 | ||
|
|
869a872897 | ||
|
|
48fc14c913 | ||
|
|
37f5d06973 | ||
|
|
f8d3fa0ecd | ||
|
|
f62628bf29 | ||
|
|
8301455a5b | ||
|
|
860d71d18a | ||
|
|
48384d4e47 | ||
|
|
ce177a9588 | ||
|
|
2421b9f6c2 | ||
|
|
eac07b18d9 | ||
|
|
418f3cfd4b | ||
|
|
3f0d6f85d3 | ||
|
|
027a6d9a18 | ||
|
|
58c0dbe275 | ||
|
|
2110196958 | ||
|
|
9195f3c7da | ||
|
|
4f92794cdf | ||
|
|
535561efbf | ||
|
|
5da30a5bc5 | ||
|
|
8fdba437af | ||
|
|
583cc8a963 | ||
|
|
491f06015b | ||
|
|
1aca3bef85 | ||
|
|
b4575a40fc | ||
|
|
8bc521f3e5 | ||
|
|
b1cfc3181b | ||
|
|
1ddf269c69 | ||
|
|
dc910a5317 | ||
|
|
34c8fb057d | ||
|
|
04f9369ace | ||
|
|
b0f69c8b6b | ||
|
|
dc4fd72133 | ||
|
|
20eed53d8c | ||
|
|
e2aaa2cb40 | ||
|
|
4d7899fa40 | ||
|
|
3f975a93b3 | ||
|
|
5f4476566d | ||
|
|
b7206abf11 | ||
|
|
034b17cef4 |
No files matched your search
@@ -22,6 +22,7 @@ logot:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
cd src && ${MAKE} clean
|
cd src && ${MAKE} clean
|
||||||
|
cd libusb && ${MAKE} clean
|
||||||
cd logotool && ${MAKE} clean
|
cd logotool && ${MAKE} clean
|
||||||
|
|
||||||
install:
|
install:
|
||||||
@@ -31,6 +32,8 @@ install:
|
|||||||
-cp src/gui/goxf ${DESTDIR}${PREFIX}/bin
|
-cp src/gui/goxf ${DESTDIR}${PREFIX}/bin
|
||||||
cp logotool/logotool ${DESTDIR}${PREFIX}/bin
|
cp logotool/logotool ${DESTDIR}${PREFIX}/bin
|
||||||
cp 0xFFFF.desktop ${DESTDIR}${PREFIX}/share/applications/
|
cp 0xFFFF.desktop ${DESTDIR}${PREFIX}/share/applications/
|
||||||
|
mkdir -p ${DESTDIR}${PREFIX}/share/man/man1
|
||||||
|
cp man/*.1 ${DESTDIR}${PREFIX}/share/man/man1
|
||||||
|
|
||||||
deinstall:
|
deinstall:
|
||||||
rm -f ${DESTDIR}${PREFIX}/bin/0xFFFF
|
rm -f ${DESTDIR}${PREFIX}/bin/0xFFFF
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
VERSION=0.4.0
|
VERSION = 0.6
|
||||||
PREFIX=/usr
|
PREFIX = /usr/local
|
||||||
|
|
||||||
|
|
||||||
# NetBSD stuff
|
# NetBSD stuff
|
||||||
CFLAGS+=-I/usr/pkg/include -O2
|
#CFLAGS += -I/usr/pkg/include -g -O2
|
||||||
LDFLAGS+=-L/usr/pkg/lib -Wl,-R/usr/pkg/lib
|
#LDFLAGS += -L/usr/pkg/lib -Wl,-R/usr/pkg/lib
|
||||||
|
|
||||||
HAVE_USB=1
|
|
||||||
HAVE_GUI=1
|
|
||||||
+2
-2
@@ -40,14 +40,14 @@ and sometimes (in the early days often) replacing proprietary software.
|
|||||||
|
|
||||||
The non-free bits in the core infrastructure of the IT OS 2007 are a road block
|
The non-free bits in the core infrastructure of the IT OS 2007 are a road block
|
||||||
for efforts to create free operating systems/distributions besides IT OS on the
|
for efforts to create free operating systems/distributions besides IT OS on the
|
||||||
N770/N800.
|
770/N800.
|
||||||
|
|
||||||
The reason for why it is helpful to have other operating system/distribution on
|
The reason for why it is helpful to have other operating system/distribution on
|
||||||
the N800 is simple: There are hundreds of GNU/Linux distributions out there.
|
the N800 is simple: There are hundreds of GNU/Linux distributions out there.
|
||||||
Each one exists because there is a userbase that exactly likes their flavor of
|
Each one exists because there is a userbase that exactly likes their flavor of
|
||||||
GNU/Linux.
|
GNU/Linux.
|
||||||
|
|
||||||
For the N770/N800 Internet Tablets there exists only one such distribution: The
|
For the 770/N800 Internet Tablets there exists only one such distribution: The
|
||||||
Internet Tablet OS. With the sheer amount of GNU/Linux distributions for
|
Internet Tablet OS. With the sheer amount of GNU/Linux distributions for
|
||||||
desktops/workstations/servers/routers/PDAs on the one hand and the single OS
|
desktops/workstations/servers/routers/PDAs on the one hand and the single OS
|
||||||
solution for the Internet Tablets on the other I doubt that it can handle all
|
solution for the Internet Tablets on the other I doubt that it can handle all
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ This file tries to collect a bunch of common questions/answers about flashing
|
|||||||
flashed together.
|
flashed together.
|
||||||
|
|
||||||
On the n800 firmwares, these two pieces are distributed in a single
|
On the n800 firmwares, these two pieces are distributed in a single
|
||||||
file, but when flashing a n770, NOLO requires to provide the xloader
|
file, but when flashing a 770, NOLO requires to provide the xloader
|
||||||
(without commiting) and then the secondary piece.
|
(without commiting) and then the secondary piece.
|
||||||
|
|
||||||
This piece of software is closed source and is the responsable of
|
This piece of software is closed source and is the responsable of
|
||||||
@@ -61,13 +61,13 @@ This file tries to collect a bunch of common questions/answers about flashing
|
|||||||
|
|
||||||
<b>*) How can I identify my device?</b>
|
<b>*) How can I identify my device?</b>
|
||||||
|
|
||||||
Theorically n770 and n800 have different USB device ID, but this is not
|
Theorically 770 and n800 have different USB device ID, but this is not
|
||||||
true at all. The first series of the n800 comes with the same usb-id
|
true at all. The first series of the n800 comes with the same usb-id
|
||||||
than n770. That's weird!
|
than 770. That's weird!
|
||||||
|
|
||||||
So, the only way to identify the device is by asking nolo for the version
|
So, the only way to identify the device is by asking nolo for the version
|
||||||
information of different pieces of the firmware. This can be faked, because
|
information of different pieces of the firmware. This can be faked, because
|
||||||
you can flash n770 stuff on n800 and viceversa, but it's not recommended
|
you can flash 770 stuff on n800 and viceversa, but it's not recommended
|
||||||
because it wouldn't work :)
|
because it wouldn't work :)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+44
-17
@@ -1,30 +1,57 @@
|
|||||||
SPECS FOR TEH FIASCO FIRMWARE FILE FORMAT ffff!
|
Copyright (C) 2007-2011 pancake <pancake@youterm.com>
|
||||||
|
Copyright (C) 2011-2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
SPECS FOR THE FIASCO FIRMWARE FILE FORMAT ffff!
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
|
|
||||||
These notes has not been taken properly and may be wrong. It must
|
This is final working version of FIASCO format. FIASCO image which
|
||||||
be revised to fit the reality. But this is mostly a general idea:
|
is generated by this spec is acceptable by Nokia flasher-3.5 and
|
||||||
|
unpack data same as FIASO image generated by Nokia fiasco-gen. This
|
||||||
|
format is implemented in 0xFFFF and every image which I tested
|
||||||
|
(generated by 0xFFFF and fiasco-gen) was properly unpacked under
|
||||||
|
0xFFFF and flasher-3.5 with same result. Small difference is that
|
||||||
|
fiasco-gen add some unknown subsection block to image header
|
||||||
|
(type '4' or '/') which contains some messy characters... But if
|
||||||
|
these sections missing, flasher-3.5 working fine too. And old FIASCO
|
||||||
|
images (for N8x0) does not have these subsectin...
|
||||||
|
|
||||||
|
|
||||||
FILE HEADER
|
FILE HEADER
|
||||||
|
|
||||||
1 byte = 0xb4 -- signature
|
1 byte = 0xb4 -- signature
|
||||||
4 bytes -- firmware name length (big endian)
|
4 bytes -- FW header length (big endian)
|
||||||
6 bytes -- versioning info ( byte 4 is format version )
|
|
||||||
N-6 bytes -- firmware name (zero fill)
|
|
||||||
|
|
||||||
|
|
||||||
PIECE HEADER
|
FW HEADER
|
||||||
|
|
||||||
1 byte = 0x54 -- piece signature
|
4 bytes -- number of FW header blocks (big endian)
|
||||||
6 bytes -- unknown
|
|
||||||
2 bytes -- checksum for the piece contents (xorpair)
|
|
||||||
12 bytes -- piece name (first byte is FF if is the last)
|
|
||||||
4 bytes -- piece size (big endian)
|
|
||||||
4 bytes -- unknown
|
|
||||||
block {
|
block {
|
||||||
1 byte -- if (value '1'-'9') { ..there's a comment.. }
|
1 byte -- type of block
|
||||||
1 byte -- length of comment
|
0xE8 - Fiasco name
|
||||||
N bytes -- comment
|
0x31 - FW name
|
||||||
|
1 byte -- length of block data
|
||||||
|
N bytes -- block data
|
||||||
}
|
}
|
||||||
N bytes -- piece data
|
|
||||||
|
|
||||||
|
|
||||||
|
IMAGE
|
||||||
|
|
||||||
|
1 byte = 0x54 -- signature
|
||||||
|
1 byte -- number of subsection blocks + 1
|
||||||
|
5 bytes -- unknown (always 0x2e 0x19 0x01 0x01 0x00)
|
||||||
|
2 bytes -- checksum for the image contents (xorpair) (big endian)
|
||||||
|
12 bytes -- image name type (first byte is FF if is the last image)
|
||||||
|
4 bytes -- length of image data (big endian)
|
||||||
|
4 bytes -- unknown (always 0x00 0x00 0x00 0x00)
|
||||||
|
block {
|
||||||
|
1 byte -- type of subsection block
|
||||||
|
'1' - version
|
||||||
|
'2' - device & hw revisions (size of device is 16, hw revision 8)
|
||||||
|
'3' - layout
|
||||||
|
'4' - unknown
|
||||||
|
'/' - unknown
|
||||||
|
1 byte -- length of subsection block
|
||||||
|
N bytes -- subsection block data
|
||||||
|
}
|
||||||
|
1 byte -- unknown (0x00 is accepted, maybe end of subsections?)
|
||||||
|
N bytes -- image data
|
||||||
+1
-1
@@ -21,4 +21,4 @@ have flashed properly every piece inside the device, but keep in mind
|
|||||||
that it is dangerous and you can brick your device.
|
that it is dangerous and you can brick your device.
|
||||||
|
|
||||||
But feel free to send feedback to provide a full support for local
|
But feel free to send feedback to provide a full support for local
|
||||||
flashing on n770 and n800.
|
flashing on 770 and n800.
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
Mk II protocol is the only protocol which can be used to flash eMMC images.
|
||||||
|
NOLO does not support eMMC, so flashing eMMC is done in Maemo system. NOLO
|
||||||
|
will boot device into "update" mode and Maemo will start only softupd daemon
|
||||||
|
(which is responsible for flashing from Maemo system) and load kernel driver
|
||||||
|
g_softupd which handle USB communication to user space daemon. When device
|
||||||
|
is in PC Suite mode Maemo system start softupd daemon and load kernel driver
|
||||||
|
g_nokia which can also handle communication via Mk II protocol.
|
||||||
|
|
||||||
|
Default Maemo flasher (v2.5.2 (Oct 21 2009)) support only some basic functions
|
||||||
|
via Mk II protocol - it can send eMMC image to softupd server which flash it.
|
||||||
|
But there is unofficial Maemo flasher (flasher v2.8.2 (Jan 8 2010)) distributed
|
||||||
|
with omap aes kernel driver for Nokia RX-51 under name "flasher.rover" which
|
||||||
|
support more functions. So "flasher.rover" is better for RE this protocol.
|
||||||
|
|
||||||
|
Via Mk II protocol over usb with softupd daemon in device it is possible to
|
||||||
|
flash any type of image except rootfs (xloader, secondary, kernel, mmc,
|
||||||
|
cmt-2nd, cmt-algo, cmt-mcusw). Maemo system using same Mk II protocol over
|
||||||
|
local TCP socket (server also provided by softupd) to update/flash system.
|
||||||
|
|
||||||
|
Over usb are used only these functions for communication:
|
||||||
|
|
||||||
|
usb_claim_interface (interface=1)
|
||||||
|
usb_set_altinterface (alternate=1)
|
||||||
|
|
||||||
|
usb_bulk_write (ep=1, timeout=5000)
|
||||||
|
usb_bulk_read (ep=129, timeout=5000)
|
||||||
|
|
||||||
|
For every (request) message which is send by host, server send back responce.
|
||||||
|
Format of message every message is same. It has 6 bytes header and (at least)
|
||||||
|
4 bytes body.
|
||||||
|
|
||||||
|
HEADER
|
||||||
|
|
||||||
|
4 bytes -- type of header
|
||||||
|
0x8810001B - out (sent by host: usb_bulk_write)
|
||||||
|
0x8800101B - in (received by host: usb_bulk_read)
|
||||||
|
2 bytes -- size of body (big endian)
|
||||||
|
|
||||||
|
BODY
|
||||||
|
|
||||||
|
4 bytes -- type of message
|
||||||
|
N bytes -- data
|
||||||
|
|
||||||
|
Reply message data always starts with char 0x00 (except pong responce).
|
||||||
|
|
||||||
|
Here are some sniffed messages from Nokia RX-51. First two messages seems to
|
||||||
|
must be always protocol version exchange (first host ask for protocol version of
|
||||||
|
server and then host send its protocol version). On RX-51 is used version "2".
|
||||||
|
|
||||||
|
Ping:
|
||||||
|
req_type = 0x00000000
|
||||||
|
res_type = 0x20000000
|
||||||
|
|
||||||
|
Get protocol version:
|
||||||
|
req_type = 0x01010000
|
||||||
|
req_data = "/update/protocol_version"
|
||||||
|
res_type = 0x21010000
|
||||||
|
res_data = 0x00 "2"
|
||||||
|
|
||||||
|
Tell our protocol version:
|
||||||
|
req_type = 0x02020000
|
||||||
|
req_data = "/update/host_protocol_version" 0x00 "2"
|
||||||
|
res_type = 0x22020000
|
||||||
|
res_data = 0x00
|
||||||
|
|
||||||
|
Get device:
|
||||||
|
req_type = 0x01030000
|
||||||
|
req_data = "/device/product_code"
|
||||||
|
res_type = 0x21030000
|
||||||
|
res_data = 0x00 "RX-51"
|
||||||
|
|
||||||
|
Get hwrev:
|
||||||
|
req_type = 0x01040000
|
||||||
|
req_data = "/device/hw_build"
|
||||||
|
res_type = 0x21040000
|
||||||
|
res_data = 0x00 "2101"
|
||||||
|
|
||||||
|
Get image types:
|
||||||
|
req_type = 0x01050000
|
||||||
|
req_data = "/update/supported_images"
|
||||||
|
res_type = 0x21050000
|
||||||
|
res_data = 0x00 "xloader,secondary,kernel,mmc,cmt-2nd,cmt-algo,cmt-mcusw"
|
||||||
|
|
||||||
|
Reboot device:
|
||||||
|
req_type = 0x0C060000
|
||||||
|
req_data = "reboot"
|
||||||
|
res_type = 0x2C060000
|
||||||
|
res_data = 0x00
|
||||||
+1
-1
@@ -37,7 +37,7 @@ Pieces can be automatically identified by using the '-I' flag:
|
|||||||
You can dump these pieces from the internal memory of the internet
|
You can dump these pieces from the internal memory of the internet
|
||||||
tablet by using the mtd-utils over /dev/mtd* or just running:
|
tablet by using the mtd-utils over /dev/mtd* or just running:
|
||||||
|
|
||||||
n770$ 0xFFFF -e /media/mmc1
|
770$ 0xFFFF -e /media/mmc1
|
||||||
|
|
||||||
There is another way for dumping pieces with extra parameters and options,
|
There is another way for dumping pieces with extra parameters and options,
|
||||||
read doc/dumping for more information.
|
read doc/dumping for more information.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<b>Usage guide</b>
|
<b>Usage guide</b>
|
||||||
|
|
||||||
0xFFFF is a free software implementation of the flasher for the Nokia Internet
|
0xFFFF is a free software implementation of the flasher for the Nokia Internet
|
||||||
Tablets (n770 and n800).
|
Tablets (770 and n800).
|
||||||
<pre>
|
<pre>
|
||||||
- flash separated pieces of the firmware.
|
- flash separated pieces of the firmware.
|
||||||
- retrieve information about the device
|
- retrieve information about the device
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ int uncompress_image(char *srcf, char *dstf)
|
|||||||
src = malloc ( fsize );
|
src = malloc ( fsize );
|
||||||
dst = malloc ( width*height*2 );
|
dst = malloc ( width*height*2 );
|
||||||
deof = dst+width*height*2;
|
deof = dst+width*height*2;
|
||||||
if ((int)src == -1 || (int)dst == -1 ) {
|
if (src == (void *)-1 || dst == (void *)-1 ) {
|
||||||
printf("Cannot malloc\n");
|
printf("Cannot malloc\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ int uncompress_image(char *srcf, char *dstf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Output Size: %d\n",dst2-dst);
|
fprintf(stderr, "Output Size: %lld\n",(long long int)(dst2-dst));
|
||||||
|
|
||||||
if ((dst2-dst)!=(width*height*2))
|
if ((dst2-dst)!=(width*height*2))
|
||||||
fprintf(stderr, "failed?\n");
|
fprintf(stderr, "failed?\n");
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
.TH 0xFFFF 1 "November 18, 2010"
|
||||||
|
.\" Please adjust this date whenever revising the manpage.
|
||||||
|
.SH NAME
|
||||||
|
0xFFFF \- Open Free Fiasco Firmware Flasher
|
||||||
|
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B 0xFFFF
|
||||||
|
.RB [OPTION]...
|
||||||
|
.SH DESCRIPTION
|
||||||
|
The 'Open Free Fiasco Firmware Flasher' aka 0xFFFF utility implements
|
||||||
|
a free (GPL3) userspace handler for the NOLO bootloader and related
|
||||||
|
utilities for the Nokia Internet Tablets like flashing, setting device
|
||||||
|
options, packing/unpacking FIASCO firmware format and more.
|
||||||
|
|
||||||
|
.SH OPTIONS
|
||||||
|
.TP
|
||||||
|
.BI -b [args]
|
||||||
|
boots the kernel with arguments
|
||||||
|
.TP
|
||||||
|
.BI -c
|
||||||
|
console prompt mode
|
||||||
|
.TP
|
||||||
|
.BI -d [vid:pid]
|
||||||
|
injects a usb device into the supported list
|
||||||
|
.TP
|
||||||
|
.BI -D [0|1|2]
|
||||||
|
sets the root device to flash (0), mmc (1) or usb (2)
|
||||||
|
.TP
|
||||||
|
.BI -f <flags>
|
||||||
|
set the given RD flags (see '-f help')
|
||||||
|
.TP
|
||||||
|
.BI -i
|
||||||
|
show device information (let standby mode)
|
||||||
|
.TP
|
||||||
|
.BI -l
|
||||||
|
list supported usb device ids
|
||||||
|
.TP
|
||||||
|
.BI -p [[p%]file]
|
||||||
|
piece-of-firmware % file-where-this-piece-is
|
||||||
|
.TP
|
||||||
|
.BI -r [0|1]
|
||||||
|
disable/enable R&D mode
|
||||||
|
.TP
|
||||||
|
.BI -R
|
||||||
|
reboot the omap board
|
||||||
|
.TP
|
||||||
|
.BI -U [0|1]
|
||||||
|
disable/enable the usb host mode
|
||||||
|
.TP
|
||||||
|
.BI -Q
|
||||||
|
enter shared queues server mode (for gui or remote)
|
||||||
|
.TP
|
||||||
|
.BI -s [serial]
|
||||||
|
serial port console (minicom like terminal)
|
||||||
|
.TP
|
||||||
|
.BI -h
|
||||||
|
show help message
|
||||||
|
.TP
|
||||||
|
.BI -S [subversion]
|
||||||
|
unpacks/flash pieces matching this sub-version information
|
||||||
|
.TP
|
||||||
|
.BI -n
|
||||||
|
do not flash or write to disk (simulation)
|
||||||
|
.TP
|
||||||
|
.BI -C [/dev/mtd]
|
||||||
|
check bad blocks on mtd
|
||||||
|
.TP
|
||||||
|
.BI -e [path]
|
||||||
|
dump/extract pieces to path
|
||||||
|
.TP
|
||||||
|
.BI -F [fiasco]
|
||||||
|
flash a fiasco firmware image
|
||||||
|
.TP
|
||||||
|
.BI -H [file]
|
||||||
|
calculate hash for file
|
||||||
|
.TP
|
||||||
|
.BI -I [piece]
|
||||||
|
identify a firmware piece
|
||||||
|
.TP
|
||||||
|
.BI -P [new-fiasco]
|
||||||
|
creates a new fiasco package, pieces as arguments
|
||||||
|
.TP
|
||||||
|
.BI -u [fiasco]
|
||||||
|
unpack target fiasco image
|
||||||
|
.TP
|
||||||
|
.BI -v
|
||||||
|
be verbose and noisy
|
||||||
|
.TP
|
||||||
|
.BI -V
|
||||||
|
show version information and exit.
|
||||||
|
.TP
|
||||||
|
.BI -x
|
||||||
|
extract configuration entries from /dev/mtd1
|
||||||
|
|
||||||
|
.SH AUTHOR
|
||||||
|
0xFFFF was written by pancake.
|
||||||
|
.PP
|
||||||
|
This manual page was written by Sebastian Reichel <elektranox@gmail.com>,
|
||||||
|
for the Debian project (but may be used by others).
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
.TH GOXF 1 "November 18, 2010"
|
||||||
|
.\" Please adjust this date whenever revising the manpage.
|
||||||
|
.SH NAME
|
||||||
|
goxf \- 0xFFFF GUI
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B goxf
|
||||||
|
.RB [FILE]
|
||||||
|
.SH DESCRIPTION
|
||||||
|
This utility is a graphical interface to 0xFFFF. It is used to
|
||||||
|
communicate with the NOLO bootloader of Nokia's internet tablets
|
||||||
|
(770, N800, N810, N900).
|
||||||
|
.SH OPTIONS
|
||||||
|
goxf takes no options.
|
||||||
|
.SH SEE ALSO
|
||||||
|
.B 0xFFFF(1)
|
||||||
|
.SH AUTHOR
|
||||||
|
goxf was written by pancake.
|
||||||
|
.PP
|
||||||
|
This manual page was written by Sebastian Reichel <elektranox@gmail.com>,
|
||||||
|
for the Debian project (but may be used by others).
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
.TH LOGOTOOL 1 "November 18, 2010"
|
||||||
|
.\" Please adjust this date whenever revising the manpage.
|
||||||
|
.SH NAME
|
||||||
|
logotool \- FIASCO logo file tool
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B logotool
|
||||||
|
.RB [OPTION]...
|
||||||
|
.SH DESCRIPTION
|
||||||
|
Tool to compress, uncompress or watch FIASCO logo files.
|
||||||
|
.SH OPTIONS
|
||||||
|
.TP
|
||||||
|
.BI -u img
|
||||||
|
uncompress image to img.rgb
|
||||||
|
.TP
|
||||||
|
.BI -c img
|
||||||
|
compres a 24 bit rgb raw image to a 16(565) one
|
||||||
|
.TP
|
||||||
|
.BI -m img
|
||||||
|
show image using mplayer (dumps to <img>.yuv)
|
||||||
|
.TP
|
||||||
|
.BI -v img
|
||||||
|
view uncompressed image using the 'display' command from ImageMagick (in monochrome)
|
||||||
|
.TP
|
||||||
|
.BI -w
|
||||||
|
specify width (required for -v and -c)
|
||||||
|
.TP
|
||||||
|
.BI -a
|
||||||
|
force RGBA instead of RGB when compressing (use with -c)
|
||||||
|
.TP
|
||||||
|
.BI -h
|
||||||
|
specify height (required for -v and -c)
|
||||||
|
.TP
|
||||||
|
.BI -V
|
||||||
|
show version information and exit.
|
||||||
|
.SH SEE ALSO
|
||||||
|
.B 0xFFFF(1)
|
||||||
|
.SH AUTHOR
|
||||||
|
logotool was written by pancake and esteve.
|
||||||
|
.PP
|
||||||
|
This manual page was written by Sebastian Reichel <elektranox@gmail.com>,
|
||||||
|
for the Debian project (but may be used by others).
|
||||||
+12
-18
@@ -1,25 +1,19 @@
|
|||||||
include ../config.mk
|
include ../config.mk
|
||||||
OBJ=main.o fiasco.o hexdump.o dump.o flash.o serial.o qmode.o
|
|
||||||
OBJ+=hash.o fpid.o query.o pieces.o utils.o devices.o console.o
|
CPPFLAGS += -DVERSION=\"$(VERSION)\" -D_GNU_SOURCE -I.
|
||||||
OBJ+=squeue/squeue.o
|
CFLAGS += -W -Wall -O2 -pedantic -std=c99
|
||||||
|
LIBS += -lm -lusb
|
||||||
|
|
||||||
|
OBJS = main.o nolo.o printf-utils.o image.o fiasco.o device.o usb-device.o cold-flash.o qmode.o console.o squeue/squeue.o operations.o local.o mkii.o disk.o cal.o
|
||||||
BIN = 0xFFFF
|
BIN = 0xFFFF
|
||||||
#LIBS=`${HAVE_USB} && echo -- '-lusb'`
|
|
||||||
LIBS=`if [ "${HAVE_USB}" = 1 ]; then echo '-lusb'; fi`
|
|
||||||
CFLAGS+=-DVERSION=\"${VERSION}\" -Wall -I .
|
|
||||||
CFLAGS+=-pedantic -std=c99 -DHAVE_USB=${HAVE_USB}
|
|
||||||
USBOBJ=../libusb/error.o ../libusb/usb.o ../libusb/descriptors.o
|
|
||||||
USBOBJ+=../libusb/linux.o ## XXX not portable
|
|
||||||
|
|
||||||
all: ${BIN}
|
all: $(BIN)
|
||||||
|
|
||||||
${BIN}: ${OBJ}
|
$(BIN): $(OBJS) Makefile ../config.mk
|
||||||
${CC} ${LDFLAGS} -o ${BIN} ${OBJ} ${LIBS}
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(OBJS) $(LIBS)
|
||||||
|
|
||||||
allusb: ${OBJ}
|
%.o: %.c Makefile ../config.mk
|
||||||
${CC} ${LDFLAGS} -o ${BIN} ${OBJ} ${USBOBJ}
|
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
static: ${OBJ}
|
|
||||||
${CC} ${LDFLAGS} -o ${BIN} -static ${OBJ} ${USBOBJ}
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f ${OBJ} ${BIN}
|
-rm -f $(OBJS) $(BIN)
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (c) 2011 Michael Buesch <mb@bu3sch.de>
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This is simple CAL parser form Calvaria */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <linux/fs.h>
|
||||||
|
#include <mtd/mtd-user.h>
|
||||||
|
|
||||||
|
#include "cal.h"
|
||||||
|
|
||||||
|
#define MAX_SIZE 393216
|
||||||
|
#define INDEX_LAST (0xFF + 1)
|
||||||
|
#define HDR_MAGIC "ConF"
|
||||||
|
|
||||||
|
struct cal {
|
||||||
|
int fd;
|
||||||
|
ssize_t size;
|
||||||
|
void * mem;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct header {
|
||||||
|
char magic[4]; /* Magic sequence */
|
||||||
|
uint8_t type; /* Type number */
|
||||||
|
uint8_t index; /* Index number */
|
||||||
|
uint16_t flags; /* Flags */
|
||||||
|
char name[16]; /* Human readable section name */
|
||||||
|
uint32_t length; /* Payload length */
|
||||||
|
uint32_t datasum; /* Data CRC32 checksum */
|
||||||
|
uint32_t hdrsum; /* Header CRC32 checksum */
|
||||||
|
} __attribute__((__packed__));
|
||||||
|
|
||||||
|
|
||||||
|
int cal_init_file(const char * file, struct cal ** cal_out) {
|
||||||
|
|
||||||
|
int fd = -1;
|
||||||
|
uint64_t blksize = 0;
|
||||||
|
ssize_t size = 0;
|
||||||
|
void * mem = NULL;
|
||||||
|
struct cal * cal = NULL;
|
||||||
|
struct stat st;
|
||||||
|
mtd_info_t mtd_info;
|
||||||
|
|
||||||
|
if ( stat(file, &st) != 0 )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
fd = open(file, O_RDONLY);
|
||||||
|
|
||||||
|
if ( fd < 0 )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if ( S_ISREG(st.st_mode) )
|
||||||
|
size = st.st_size;
|
||||||
|
else if ( S_ISBLK(st.st_mode) ) {
|
||||||
|
if ( ioctl(fd, BLKGETSIZE64, &blksize) != 0 )
|
||||||
|
goto err;
|
||||||
|
if ( blksize > SSIZE_MAX )
|
||||||
|
goto err;
|
||||||
|
size = blksize;
|
||||||
|
} else if ( S_ISCHR(st.st_mode) && major(st.st_rdev) == 90 ) {
|
||||||
|
if ( ioctl(fd, MEMGETINFO, &mtd_info) != 0 )
|
||||||
|
goto err;
|
||||||
|
size = mtd_info.size;
|
||||||
|
} else {
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( size == 0 || size > MAX_SIZE )
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
mem = malloc(size);
|
||||||
|
|
||||||
|
if ( ! mem )
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
if ( read(fd, mem, size) != size )
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
cal = malloc(sizeof(struct cal));
|
||||||
|
|
||||||
|
if ( ! cal )
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
cal->fd = fd;
|
||||||
|
cal->mem = mem;
|
||||||
|
cal->size = size;
|
||||||
|
|
||||||
|
*cal_out = cal;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
err:
|
||||||
|
close(fd);
|
||||||
|
free(mem);
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int cal_init(struct cal ** cal_out) {
|
||||||
|
|
||||||
|
return cal_init_file("/dev/mtd1ro", cal_out);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void cal_finish(struct cal * cal) {
|
||||||
|
|
||||||
|
if ( cal ) {
|
||||||
|
free(cal->mem);
|
||||||
|
free(cal);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t crc32(uint32_t crc, const void * _data, size_t size) {
|
||||||
|
|
||||||
|
const uint8_t * data = _data;
|
||||||
|
uint8_t value;
|
||||||
|
unsigned int bit;
|
||||||
|
size_t i;
|
||||||
|
const uint32_t poly = 0xEDB88320;
|
||||||
|
|
||||||
|
for ( i = 0; i < size; i++ ) {
|
||||||
|
value = data[i];
|
||||||
|
for ( bit = 8; bit; bit-- ) {
|
||||||
|
if ( (crc & 1) != (value & 1) )
|
||||||
|
crc = (crc >> 1) ^ poly;
|
||||||
|
else
|
||||||
|
crc >>= 1;
|
||||||
|
value >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int is_header(void *data, size_t size) {
|
||||||
|
|
||||||
|
struct header * hdr = data;
|
||||||
|
|
||||||
|
if ( size < sizeof(struct header) )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ( memcmp(hdr->magic, HDR_MAGIC, sizeof(hdr->magic)) != 0 )
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int64_t find_section(void *start, uint64_t count, int want_index, const char *want_name) {
|
||||||
|
|
||||||
|
int64_t offset = 0, found_offset = -1;
|
||||||
|
uint8_t * data = start;
|
||||||
|
struct header *hdr;
|
||||||
|
char sectname[sizeof(hdr->name) + 1] = { 0, };
|
||||||
|
uint32_t payload_len;
|
||||||
|
int previous_index = -1;
|
||||||
|
|
||||||
|
while ( 1 ) {
|
||||||
|
|
||||||
|
/* Find header start */
|
||||||
|
if ( count < sizeof(struct header) )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ( ! is_header(data + offset, count) ) {
|
||||||
|
count--;
|
||||||
|
offset++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
hdr = (struct header *)(data + offset);
|
||||||
|
payload_len = hdr->length;
|
||||||
|
|
||||||
|
if ( count - sizeof(struct header) < payload_len )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memcpy(sectname, hdr->name, sizeof(hdr->name));
|
||||||
|
|
||||||
|
if ( want_index == INDEX_LAST ) {
|
||||||
|
if ((int)hdr->index <= previous_index)
|
||||||
|
goto next;
|
||||||
|
} else {
|
||||||
|
if (want_index >= 0 && want_index != hdr->index)
|
||||||
|
goto next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( want_name && strcmp(sectname, want_name) != 0 )
|
||||||
|
goto next;
|
||||||
|
|
||||||
|
/* Found it */
|
||||||
|
found_offset = offset;
|
||||||
|
if ( want_index == INDEX_LAST )
|
||||||
|
previous_index = hdr->index;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
next:
|
||||||
|
count -= sizeof(struct header) + payload_len;
|
||||||
|
offset += sizeof(struct header) + payload_len;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return found_offset;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int cal_read_block(struct cal * cal, const char * name, void ** ptr, unsigned long * len, unsigned long flags) {
|
||||||
|
|
||||||
|
int64_t find_offset;
|
||||||
|
uint64_t filelen = cal->size;
|
||||||
|
uint8_t * data = cal->mem;
|
||||||
|
struct header * hdr;
|
||||||
|
|
||||||
|
find_offset = find_section(data, filelen, INDEX_LAST, name);
|
||||||
|
if ( find_offset < 0 )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
hdr = (struct header *)(data + find_offset);
|
||||||
|
|
||||||
|
if ( flags && hdr->flags != flags )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if ( crc32(0, hdr, sizeof(*hdr) - 4) != hdr->hdrsum )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
*ptr = data + find_offset + sizeof(struct header);
|
||||||
|
*len = hdr->length;
|
||||||
|
|
||||||
|
if ( crc32(0, *ptr, *len) != hdr->datasum )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (c) 2011 Michael Buesch <mb@bu3sch.de>
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CAL_H
|
||||||
|
#define CAL_H
|
||||||
|
|
||||||
|
#define CAL_MAX_NAME_LEN 16
|
||||||
|
#define CAL_FLAG_USER 0x0001
|
||||||
|
#define CAL_FLAG_WRITE_ONCE 0x0002
|
||||||
|
|
||||||
|
struct cal;
|
||||||
|
|
||||||
|
int cal_init(struct cal ** cal_out);
|
||||||
|
int cal_init_file(const char * file, struct cal ** cal_out);
|
||||||
|
void cal_finish(struct cal * cal);
|
||||||
|
int cal_read_block(struct cal * cal, const char * name, void ** ptr, unsigned long * len, unsigned long flags);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,410 @@
|
|||||||
|
/*
|
||||||
|
cold-flash.c - Cold flashing
|
||||||
|
Copyright (C) 2011-2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <usb.h>
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
#include "cold-flash.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "usb-device.h"
|
||||||
|
#include "printf-utils.h"
|
||||||
|
|
||||||
|
#define READ_DEV 0x81
|
||||||
|
#define WRITE_DEV 0x01
|
||||||
|
#define READ_TIMEOUT 500
|
||||||
|
#define WRITE_TIMEOUT 3000
|
||||||
|
|
||||||
|
static uint32_t tab[256];
|
||||||
|
|
||||||
|
static void crc32_gentab(void) {
|
||||||
|
|
||||||
|
int i, j;
|
||||||
|
uint32_t crc;
|
||||||
|
uint32_t poly = 0xEDB88320L;
|
||||||
|
|
||||||
|
for ( i = 0; i < 256; i++) {
|
||||||
|
|
||||||
|
crc = i;
|
||||||
|
|
||||||
|
for ( j = 8; j > 0; j-- ) {
|
||||||
|
|
||||||
|
if (crc & 1)
|
||||||
|
crc = (crc >> 1) ^ poly;
|
||||||
|
else
|
||||||
|
crc >>= 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
tab[i] = crc;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t crc32(unsigned char * bytes, size_t size, uint32_t crc) {
|
||||||
|
|
||||||
|
static int gen = 0;
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
if ( ! gen ) {
|
||||||
|
crc32_gentab();
|
||||||
|
gen = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( i = 0; i < size; ++i )
|
||||||
|
crc = (crc >> 8) ^ tab[(crc ^ bytes[i]) & 0xff];
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Omap Boot Messages */
|
||||||
|
/* See spruf98v.pdf (page 3444): OMAP35x Technical Reference Manual - 25.4.5 Periheral Booting */
|
||||||
|
|
||||||
|
/* Omap Peripheral boot message */
|
||||||
|
static const uint32_t omap_peripheral_msg = 0xF0030002;
|
||||||
|
|
||||||
|
/* Omap Void (no device) boot message */
|
||||||
|
static const uint32_t omap_void_msg = 0xF0030006;
|
||||||
|
|
||||||
|
/* Omap XIP memory boot message */
|
||||||
|
static const uint32_t omap_xip_msg = 0xF0030106;
|
||||||
|
|
||||||
|
/* Omap Nand boot message */
|
||||||
|
static const uint32_t omap_nand_msg = 0xF0030206;
|
||||||
|
|
||||||
|
/* Omap OneNAND boot message */
|
||||||
|
static const uint32_t omap_onenand_msg = 0xF0030306;
|
||||||
|
|
||||||
|
/* Omap DOC boot message */
|
||||||
|
static const uint32_t omap_doc_msg = 0xF0030406;
|
||||||
|
|
||||||
|
/* Omap MMC/SD2 boot message */
|
||||||
|
static const uint32_t omap_mmc2_msg = 0xF0030506;
|
||||||
|
|
||||||
|
/* Omap MMC/SD1 boot message */
|
||||||
|
static const uint32_t omap_mmc1_msg = 0xF0030606;
|
||||||
|
|
||||||
|
/* Omap XIP memory with wait monitoring boot message */
|
||||||
|
static const uint32_t omap_xipwait_msg = 0xF0030706;
|
||||||
|
|
||||||
|
/* Omap UART boot message */
|
||||||
|
static const uint32_t omap_uart_msg = 0xF0031006;
|
||||||
|
|
||||||
|
/* Omap HS USB boot message */
|
||||||
|
static const uint32_t omap_hsusb_msg = 0xF0031106;
|
||||||
|
|
||||||
|
/* Omap next device boot message */
|
||||||
|
static const uint32_t omap_next_msg = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
/* Omap memory boot message */
|
||||||
|
static const uint32_t omap_memory_msg = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/* Nokia X-Loader messages */
|
||||||
|
|
||||||
|
/* Structure of X-Loader message */
|
||||||
|
struct xloader_msg {
|
||||||
|
uint32_t type; /* 4 bytes - type of message */
|
||||||
|
uint32_t size; /* 4 bytes - size of file */
|
||||||
|
uint32_t crc1; /* 4 bytes - crc32 of file */
|
||||||
|
uint32_t crc2; /* 4 bytes - crc32 of first 12 bytes of message */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define XLOADER_MSG_TYPE_PING 0x6301326E
|
||||||
|
#define XLOADER_MSG_TYPE_SEND 0x6302326E
|
||||||
|
|
||||||
|
struct xloader_msg xloader_msg_create(uint32_t type, struct image * image) {
|
||||||
|
|
||||||
|
struct xloader_msg msg;
|
||||||
|
uint32_t need, readed;
|
||||||
|
int ret;
|
||||||
|
uint8_t buffer[1024];
|
||||||
|
|
||||||
|
msg.type = type;
|
||||||
|
msg.size = 0;
|
||||||
|
msg.crc1 = 0;
|
||||||
|
|
||||||
|
if ( image ) {
|
||||||
|
msg.size = image->size;
|
||||||
|
image_seek(image, 0);
|
||||||
|
readed = 0;
|
||||||
|
while ( readed < image->size ) {
|
||||||
|
need = image->size - readed;
|
||||||
|
if ( need > sizeof(buffer) )
|
||||||
|
need = sizeof(buffer);
|
||||||
|
ret = image_read(image, buffer, need);
|
||||||
|
if ( ret == 0 )
|
||||||
|
break;
|
||||||
|
msg.crc1 = crc32(buffer, ret, msg.crc1);
|
||||||
|
readed += ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.crc2 = crc32((unsigned char *)&msg, 12, 0);
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int read_asic(usb_dev_handle * udev, uint8_t * asic_buffer, int size, int asic_size) {
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
printf("Waiting for ASIC ID...\n");
|
||||||
|
ret = usb_bulk_read(udev, READ_DEV, (char *)asic_buffer, size, READ_TIMEOUT);
|
||||||
|
if ( ret != asic_size )
|
||||||
|
ERROR_RETURN("Invalid size of ASIC ID", -1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int send_2nd(usb_dev_handle * udev, struct image * image) {
|
||||||
|
|
||||||
|
uint8_t buffer[1024];
|
||||||
|
uint32_t need, readed;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
printf("Sending OMAP peripheral boot message...\n");
|
||||||
|
ret = usb_bulk_write(udev, WRITE_DEV, (char *)&omap_peripheral_msg, sizeof(omap_peripheral_msg), WRITE_TIMEOUT);
|
||||||
|
usleep(5000);
|
||||||
|
if ( ret != sizeof(omap_peripheral_msg) )
|
||||||
|
ERROR_RETURN("Sending OMAP peripheral boot message failed", -1);
|
||||||
|
|
||||||
|
printf("Sending 2nd X-Loader image size...\n");
|
||||||
|
ret = usb_bulk_write(udev, WRITE_DEV, (char *)&image->size, 4, WRITE_TIMEOUT);
|
||||||
|
usleep(5000);
|
||||||
|
if ( ret != 4 )
|
||||||
|
ERROR_RETURN("Sending 2nd X-Loader image size failed", -1);
|
||||||
|
|
||||||
|
printf("Sending 2nd X-Loader image...\n");
|
||||||
|
printf_progressbar(0, image->size);
|
||||||
|
image_seek(image, 0);
|
||||||
|
readed = 0;
|
||||||
|
while ( readed < image->size ) {
|
||||||
|
need = image->size - readed;
|
||||||
|
if ( need > sizeof(buffer) )
|
||||||
|
need = sizeof(buffer);
|
||||||
|
ret = image_read(image, buffer, need);
|
||||||
|
if ( ret == 0 )
|
||||||
|
break;
|
||||||
|
if ( usb_bulk_write(udev, WRITE_DEV, (char *)buffer, ret, WRITE_TIMEOUT) != ret )
|
||||||
|
PRINTF_ERROR_RETURN("Sending 2nd X-Loader image failed", -1);
|
||||||
|
readed += ret;
|
||||||
|
printf_progressbar(readed, image->size);
|
||||||
|
}
|
||||||
|
usleep(50000);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int send_secondary(usb_dev_handle * udev, struct image * image) {
|
||||||
|
|
||||||
|
struct xloader_msg init_msg;
|
||||||
|
uint8_t buffer[1024];
|
||||||
|
uint32_t need, readed;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
init_msg = xloader_msg_create(XLOADER_MSG_TYPE_SEND, image);
|
||||||
|
|
||||||
|
printf("Sending X-Loader init message...\n");
|
||||||
|
ret = usb_bulk_write(udev, WRITE_DEV, (char *)&init_msg, sizeof(init_msg), WRITE_TIMEOUT);
|
||||||
|
usleep(5000);
|
||||||
|
if ( ret != sizeof(init_msg) )
|
||||||
|
ERROR_RETURN("Sending X-Loader init message failed", -1);
|
||||||
|
|
||||||
|
printf("Waiting for X-Loader response...\n");
|
||||||
|
ret = usb_bulk_read(udev, READ_DEV, (char *)&buffer, 4, READ_TIMEOUT); /* 4 bytes - dummy value */
|
||||||
|
if ( ret != 4 )
|
||||||
|
ERROR_RETURN("No response", -1);
|
||||||
|
|
||||||
|
printf("Sending Secondary image...\n");
|
||||||
|
printf_progressbar(0, image->size);
|
||||||
|
image_seek(image, 0);
|
||||||
|
readed = 0;
|
||||||
|
while ( readed < image->size ) {
|
||||||
|
need = image->size - readed;
|
||||||
|
if ( need > sizeof(buffer) )
|
||||||
|
need = sizeof(buffer);
|
||||||
|
ret = image_read(image, buffer, need);
|
||||||
|
if ( ret == 0 )
|
||||||
|
break;
|
||||||
|
if ( usb_bulk_write(udev, WRITE_DEV, (char *)buffer, ret, WRITE_TIMEOUT) != ret )
|
||||||
|
PRINTF_ERROR_RETURN("Sending Secondary image failed", -1);
|
||||||
|
readed += ret;
|
||||||
|
printf_progressbar(readed, image->size);
|
||||||
|
}
|
||||||
|
usleep(5000);
|
||||||
|
|
||||||
|
printf("Waiting for X-Loader response...\n");
|
||||||
|
ret = usb_bulk_read(udev, READ_DEV, (char *)&buffer, 4, READ_TIMEOUT); /* 4 bytes - dummy value */
|
||||||
|
if ( ret != 4 )
|
||||||
|
ERROR_RETURN("No response", -1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ping_timeout(usb_dev_handle * udev) {
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
int pong = 0;
|
||||||
|
int try_ping = 10;
|
||||||
|
|
||||||
|
while ( try_ping > 0 ) {
|
||||||
|
|
||||||
|
struct xloader_msg ping_msg = xloader_msg_create(XLOADER_MSG_TYPE_PING, NULL);
|
||||||
|
int try_read = 4;
|
||||||
|
|
||||||
|
printf("Sending X-Loader ping message\n");
|
||||||
|
ret = usb_bulk_write(udev, WRITE_DEV, (char *)&ping_msg, sizeof(ping_msg), WRITE_TIMEOUT);
|
||||||
|
if ( ret != sizeof(ping_msg) )
|
||||||
|
ERROR_RETURN("Sending X-Loader ping message faild", -1);
|
||||||
|
|
||||||
|
printf("Waiting for X-Loader pong response...\n");
|
||||||
|
while ( try_read > 0 ) {
|
||||||
|
|
||||||
|
uint32_t ping_read;
|
||||||
|
ret = usb_bulk_read(udev, READ_DEV, (char *)&ping_read, sizeof(ping_read), READ_TIMEOUT);
|
||||||
|
if ( ret == sizeof(ping_read) ) {
|
||||||
|
printf("Got it\n");
|
||||||
|
pong = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
usleep(5000);
|
||||||
|
--try_read;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( pong )
|
||||||
|
break;
|
||||||
|
|
||||||
|
printf("Responce timeout\n");
|
||||||
|
--try_ping;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pong)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int init_cold_flash(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
uint8_t asic_buffer[127];
|
||||||
|
int asic_size = 69;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if ( dev->flash_device->protocol != FLASH_COLD )
|
||||||
|
ERROR_RETURN("Device is not in Cold Flash mode", -1);
|
||||||
|
|
||||||
|
if ( read_asic(dev->udev, asic_buffer, sizeof(asic_buffer), asic_size) != 0 )
|
||||||
|
ERROR_RETURN("Reading ASIC ID failed", -1);
|
||||||
|
|
||||||
|
if ( verbose ) {
|
||||||
|
printf("Got ASIC ID:");
|
||||||
|
for ( i = 0; i < asic_size; ++i )
|
||||||
|
printf(" 0x%.2X", (unsigned int)asic_buffer[i]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: Detect device from asic id */
|
||||||
|
|
||||||
|
/* ASIC ID specification: http://processors.wiki.ti.com/index.php/OMAP35x_and_AM/DM37x_Initialization#UART.2FUSB_Booting */
|
||||||
|
|
||||||
|
/* Number of subblocks */
|
||||||
|
if ( asic_buffer[0] != 0x05 )
|
||||||
|
ERROR_RETURN("Invalid ASIC ID", -1);
|
||||||
|
|
||||||
|
/* ID Subblock - header */
|
||||||
|
if ( memcmp(asic_buffer+1, "\x01\x05\x01", 3) != 0 )
|
||||||
|
ERROR_RETURN("Invalid ASIC ID", -1);
|
||||||
|
|
||||||
|
/* ID Subblock - OMAP chip version (check for OMAP35x) */
|
||||||
|
if ( memcmp(asic_buffer+4, "\x34\x30\x07", 3) != 0 )
|
||||||
|
ERROR_RETURN("Invalid ASIC ID", -1);
|
||||||
|
|
||||||
|
/* Reserved1 - header */
|
||||||
|
if ( memcmp(asic_buffer+8, "\x13\x02\x01", 3) != 0 )
|
||||||
|
ERROR_RETURN("Invalid ASIC ID", -1);
|
||||||
|
|
||||||
|
/* 2nd ID Subblock - header */
|
||||||
|
if ( memcmp(asic_buffer+12, "\x12\x15\x01", 3) != 0 )
|
||||||
|
ERROR_RETURN("Invalid ASIC ID", -1);
|
||||||
|
|
||||||
|
/* Reserved2 - header */
|
||||||
|
if ( memcmp(asic_buffer+35, "\x14\x15\x01", 3) != 0 )
|
||||||
|
ERROR_RETURN("Invalid ASIC ID", -1);
|
||||||
|
|
||||||
|
/* Checksum subblock - header */
|
||||||
|
if ( memcmp(asic_buffer+58, "\x15\x09\x01", 3) != 0 )
|
||||||
|
ERROR_RETURN("Invalid ASIC ID", -1);
|
||||||
|
|
||||||
|
printf("Detected OMAP35x chip\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int cold_flash(struct usb_device_info * dev, struct image * x2nd, struct image * secondary) {
|
||||||
|
|
||||||
|
if ( x2nd->type != IMAGE_2ND )
|
||||||
|
ERROR_RETURN("Image type is not 2nd X-Loader", -1);
|
||||||
|
|
||||||
|
if ( secondary->type != IMAGE_SECONDARY )
|
||||||
|
ERROR_RETURN("Image type is not Secondary", -1);
|
||||||
|
|
||||||
|
if ( send_2nd(dev->udev, x2nd) != 0 )
|
||||||
|
ERROR_RETURN("Sending 2nd X-Loader image failed", -1);
|
||||||
|
|
||||||
|
if ( ping_timeout(dev->udev) != 0 )
|
||||||
|
ERROR_RETURN("Sending X-Loader ping message failed", -1);
|
||||||
|
|
||||||
|
if ( send_secondary(dev->udev, secondary) != 0 )
|
||||||
|
ERROR_RETURN("Sending Secondary image failed", -1);
|
||||||
|
|
||||||
|
printf("Done\n");
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int leave_cold_flash(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
printf("Sending OMAP memory boot message...\n");
|
||||||
|
ret = usb_bulk_write(dev->udev, WRITE_DEV, (char *)&omap_memory_msg, sizeof(omap_memory_msg), WRITE_TIMEOUT);
|
||||||
|
usleep(5000);
|
||||||
|
if ( ret != sizeof(omap_memory_msg) )
|
||||||
|
ERROR_RETURN("Sending OMAP memory boot message failed", -1);
|
||||||
|
|
||||||
|
usleep(250000);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
cold-flash.h - Cold flashing
|
||||||
|
Copyright (C) 2011-2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef COLD_FLASH_H
|
||||||
|
#define COLD_FLASH_H
|
||||||
|
|
||||||
|
#include "image.h"
|
||||||
|
#include "usb-device.h"
|
||||||
|
|
||||||
|
/* Initialize Cold Flash mde */
|
||||||
|
int init_cold_flash(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
/* Flash 2nd and secondary image in Cold Flash mode. After flashing device will boot secondary image */
|
||||||
|
int cold_flash(struct usb_device_info * dev, struct image * x2nd, struct image * secondary);
|
||||||
|
|
||||||
|
/* Leave Cold Flashing mode and continue booting */
|
||||||
|
int leave_cold_flash(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
#endif
|
||||||
+55
-63
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
* Copyright (C) 2007, 2008 pancake <pancake@youterm.com>
|
* Copyright (C) 2007, 2008 pancake <pancake@youterm.com>
|
||||||
|
* Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -16,21 +17,21 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if HAVE_USB
|
|
||||||
#include "main.h"
|
|
||||||
#include "query.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
void cmd_exit(char *line)
|
#include "global.h"
|
||||||
{
|
#include "console.h"
|
||||||
|
|
||||||
|
static void cmd_exit(char *line) {
|
||||||
exit(0);
|
exit(0);
|
||||||
|
(void)line;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_help(char *line)
|
static void cmd_help(char *line) {
|
||||||
{
|
|
||||||
printf("connect connects via usb to nolo\n");
|
printf("connect connects via usb to nolo\n");
|
||||||
printf("reboot reboots remote host\n");
|
printf("reboot reboots remote host\n");
|
||||||
printf("info shows info of the remote system\n");
|
printf("info shows info of the remote system\n");
|
||||||
@@ -42,25 +43,16 @@ void cmd_help(char *line)
|
|||||||
printf(" f.ex: nanddump /dev/mtd0 0x0 0x4000 xloader.bin 1 1\n");
|
printf(" f.ex: nanddump /dev/mtd0 0x0 0x4000 xloader.bin 1 1\n");
|
||||||
printf("exit exits the shell\n");
|
printf("exit exits the shell\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
(void)line;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_info(char *line)
|
static void cmd_info(char *line) {
|
||||||
{
|
/* TODO */
|
||||||
char *p, str[128];
|
(void)line;
|
||||||
get_sw_version();
|
|
||||||
get_hw_revision(str, 128); // get hardware revision:
|
|
||||||
p = strstr(str, "hw_rev:");
|
|
||||||
if (p) // TODO: delimit string by comma
|
|
||||||
printf("SubVersionString autodetected: '%s'\n", p+7);
|
|
||||||
else printf("SubVersionString autodetected: (error)\n");
|
|
||||||
get_root_device(); // only for flashing
|
|
||||||
get_usb_mode();
|
|
||||||
get_rd_mode();
|
|
||||||
get_rd_flags();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_nanddump(char *line)
|
static void cmd_nanddump(char *line) {
|
||||||
{
|
|
||||||
char dev[128];
|
char dev[128];
|
||||||
int from;
|
int from;
|
||||||
int length;
|
int length;
|
||||||
@@ -72,58 +64,54 @@ void cmd_nanddump(char *line)
|
|||||||
(char *)&dev, (unsigned int*)&from, (unsigned int *)&length,
|
(char *)&dev, (unsigned int*)&from, (unsigned int *)&length,
|
||||||
(char *)&out, (int*)&ignbb, (int *)&ignoob);
|
(char *)&out, (int*)&ignbb, (int *)&ignoob);
|
||||||
|
|
||||||
if (ignoob == -1) {
|
/* TODO */
|
||||||
eprintf("Invalid arguments.\n");
|
|
||||||
eprintf("nanddump [dev] [start] [len] [out] [ignore-badblocks] [ignore-oob]\n");
|
|
||||||
eprintf(" f.ex: nanddump /dev/mtd0 0x0 0x4000 xloader.bin 1 1\n");
|
|
||||||
} else
|
|
||||||
nanddump(dev, from, length, out, ignbb, ignoob);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_dump(char *line)
|
static void cmd_dump(char *line) {
|
||||||
{
|
|
||||||
if ( ! line[0] ) {
|
if ( ! line[0] ) {
|
||||||
printf("Usage: dump [path]\n");
|
printf("Usage: dump [path]\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while(line[0]==' ') line = line +1;
|
|
||||||
reverse_extract_pieces(line);
|
while ( line[0] == ' ' )
|
||||||
|
++line;
|
||||||
|
|
||||||
|
/* TODO */
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_badblocks(char *line)
|
static void cmd_badblocks(char *line) {
|
||||||
{
|
|
||||||
if ( ! line[0] ) {
|
if ( ! line[0] ) {
|
||||||
printf("Usage: dump [path]\n");
|
printf("Usage: badblocks [path]\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while(line[0]==' ') line = line +1;
|
|
||||||
check_badblocks(line);
|
while ( line[0] == ' ' )
|
||||||
|
++line;
|
||||||
|
|
||||||
|
/* TODO */
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_connect(char *line)
|
static void cmd_connect(char *line) {
|
||||||
{
|
/* TODO */
|
||||||
connect_via_usb();
|
(void)line;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_reboot(char *line)
|
static void cmd_reboot(char *line) {
|
||||||
{
|
/* TODO */
|
||||||
reboot_board();
|
(void)line;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_shell(char *line)
|
static void cmd_shell(char *line) {
|
||||||
{
|
|
||||||
system("/bin/sh");
|
system("/bin/sh");
|
||||||
|
(void)line;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CMDS 11
|
static struct cmd_t {
|
||||||
#define IS_CMD(x) !strcmp(console_commands[i].name, x)
|
|
||||||
#define CALL_CMD(x) console_commands[x].callback((char *)line)
|
|
||||||
#define FOREACH_CMD(x) for(x=0;x<CMDS;x++)
|
|
||||||
|
|
||||||
struct cmd_t {
|
|
||||||
char *name;
|
char *name;
|
||||||
void (*callback)(char *);
|
void (*callback)(char *);
|
||||||
} console_commands[CMDS] = {
|
} console_commands[] = {
|
||||||
{ .name = "exit", .callback = &cmd_exit },
|
{ .name = "exit", .callback = &cmd_exit },
|
||||||
{ .name = "q", .callback = &cmd_exit },
|
{ .name = "q", .callback = &cmd_exit },
|
||||||
{ .name = "connect", .callback = &cmd_connect },
|
{ .name = "connect", .callback = &cmd_connect },
|
||||||
@@ -137,38 +125,42 @@ struct cmd_t {
|
|||||||
{ .name = "shell", .callback = &cmd_shell }
|
{ .name = "shell", .callback = &cmd_shell }
|
||||||
};
|
};
|
||||||
|
|
||||||
static int console_command(const char *line)
|
static int console_command(char *line) {
|
||||||
{
|
|
||||||
int i;
|
size_t i;
|
||||||
char command[11];
|
char command[11];
|
||||||
|
|
||||||
command[0] = '\0';
|
command[0] = '\0';
|
||||||
sscanf(line, "%10s", command);
|
sscanf(line, "%10s", command);
|
||||||
line = line + strlen(command);
|
line = line + strlen(command);
|
||||||
|
|
||||||
FOREACH_CMD(i)
|
for ( i = 0; i < (sizeof(console_commands)/sizeof(console_commands[0])); ++i )
|
||||||
if (IS_CMD(command))
|
if ( strcmp(console_commands[i].name, command) == 0 )
|
||||||
CALL_CMD(i);
|
console_commands[i].callback(line);
|
||||||
//
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int console_prompt()
|
int console_prompt(void) {
|
||||||
{
|
|
||||||
char line[1024];
|
char line[1024];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
write(1, "0xFFFF> ", 8);
|
write(1, "0xFFFF> ", 8);
|
||||||
line[0] = '\0';
|
line[0] = '\0';
|
||||||
fgets(line, 1024, stdin);
|
fgets(line, 1024, stdin);
|
||||||
|
|
||||||
if ( feof(stdin) ) {
|
if ( feof(stdin) ) {
|
||||||
write(1, "\n", 1);
|
write(1, "\n", 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (line[0]) line[strlen(line)-1] = '\0';
|
|
||||||
|
if ( line[0] )
|
||||||
|
line[strlen(line)-1] = '\0';
|
||||||
line[1023] = '\0';
|
line[1023] = '\0';
|
||||||
} while ( console_command(line) );
|
} while ( console_command(line) );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
* Copyright (C) 2007, 2008 pancake <pancake@youterm.com>
|
||||||
|
* Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -16,45 +17,9 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#ifndef CONSOLE_H
|
||||||
#include "hash.h"
|
#define CONSOLE_H
|
||||||
|
|
||||||
usho do_hash(usho *b, int len)
|
int console_prompt(void);
|
||||||
{
|
|
||||||
usho result = 0;
|
|
||||||
for(len>>=1;len--;b=b+1)
|
|
||||||
result^=b[0];
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
usho do_hash_file(const char *filename)
|
|
||||||
{
|
|
||||||
unsigned char buf[BSIZE];
|
|
||||||
FILE *fd = fopen(filename, "r");
|
|
||||||
usho hash = 0;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (fd == NULL) {
|
|
||||||
fprintf(stderr, "ERROR: File '%s' not found.\n", filename);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
do { ret = fread(&buf, 1, BSIZE, fd);
|
|
||||||
if (ret == -1)
|
|
||||||
return 0;
|
|
||||||
hash ^= do_hash((usho *)&buf, ret);
|
|
||||||
} while(ret);
|
|
||||||
|
|
||||||
fclose(fd);
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
usho us = do_hash_file("zImage");
|
|
||||||
unsigned char *h= (unsigned char *)&us;
|
|
||||||
printf("%x %x\n",h[0],h[1]);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
+329
@@ -0,0 +1,329 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
static const char * devices[] = {
|
||||||
|
[DEVICE_SU_18] = "SU-18",
|
||||||
|
[DEVICE_RX_34] = "RX-34",
|
||||||
|
[DEVICE_RX_44] = "RX-44",
|
||||||
|
[DEVICE_RX_48] = "RX-48",
|
||||||
|
[DEVICE_RX_51] = "RX-51",
|
||||||
|
};
|
||||||
|
|
||||||
|
enum device device_from_string(const char * device) {
|
||||||
|
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if ( ! device || ! device[0] )
|
||||||
|
return DEVICE_ANY;
|
||||||
|
|
||||||
|
for ( i = 0; i < sizeof(devices)/sizeof(devices[0]); ++i )
|
||||||
|
if ( devices[i] && strcmp(devices[i], device) == 0 )
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return DEVICE_UNKNOWN;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const char * device_to_string(enum device device) {
|
||||||
|
|
||||||
|
if ( device > sizeof(devices)/sizeof(devices[0]) )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return devices[device];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char * long_devices[] = {
|
||||||
|
[DEVICE_SU_18] = "Nokia 770",
|
||||||
|
[DEVICE_RX_34] = "Nokia N800",
|
||||||
|
[DEVICE_RX_44] = "Nokia N810",
|
||||||
|
[DEVICE_RX_48] = "Nokia N810 Wimax",
|
||||||
|
[DEVICE_RX_51] = "Nokia N900",
|
||||||
|
};
|
||||||
|
|
||||||
|
const char * device_to_long_string(enum device device) {
|
||||||
|
|
||||||
|
if ( device > sizeof(long_devices)/sizeof(long_devices[0]) )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return long_devices[device];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int hwrev_is_valid(const int16_t * hwrevs, int16_t hwrev) {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* hwrevs not specified, valid for any hwrev */
|
||||||
|
if ( ! hwrevs )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
for ( i = 0; hwrevs[i] != -1; ++i )
|
||||||
|
if ( hwrev == hwrevs[i] )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t * hwrevs_alloc_from_string(const char * str) {
|
||||||
|
|
||||||
|
const char * ptr = str;
|
||||||
|
const char * oldptr = ptr;
|
||||||
|
int count = 2;
|
||||||
|
int16_t * ret;
|
||||||
|
int16_t tmp;
|
||||||
|
int i;
|
||||||
|
char buf[5];
|
||||||
|
|
||||||
|
if ( ! str )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
while ( (ptr = strchr(ptr, ',')) ) {
|
||||||
|
++count;
|
||||||
|
++ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = calloc(count, sizeof(int16_t));
|
||||||
|
if ( ! ret )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
ptr = str;
|
||||||
|
while ( (ptr = strchr(ptr, ',')) ) {
|
||||||
|
strncpy(buf, oldptr, ptr-oldptr);
|
||||||
|
buf[4] = 0;
|
||||||
|
tmp = atoi(buf);
|
||||||
|
if ( tmp >= 0 )
|
||||||
|
ret[i++] = tmp;
|
||||||
|
++ptr;
|
||||||
|
oldptr = ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp = atoi(oldptr);
|
||||||
|
if ( tmp >= 0 )
|
||||||
|
ret[i++] = tmp;
|
||||||
|
|
||||||
|
ret[i++] = -1;
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
char * hwrevs_alloc_to_string(const int16_t * hwrevs) {
|
||||||
|
|
||||||
|
char * ret;
|
||||||
|
char * ptr;
|
||||||
|
int i;
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
|
for ( i = 0; hwrevs[i] != -1; ++i )
|
||||||
|
len += log10(hwrevs[i]+1)+2;
|
||||||
|
|
||||||
|
ret = calloc(1, len+1);
|
||||||
|
if ( ! ret )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ptr = ret;
|
||||||
|
for ( i = 0; hwrevs[i] != -1; ++i )
|
||||||
|
ptr += sprintf(ptr, "%d,", hwrevs[i]);
|
||||||
|
|
||||||
|
*(ptr-1) = 0;
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MAX_HWREVS 29
|
||||||
|
|
||||||
|
char ** device_list_alloc_to_bufs(const struct device_list * device_list) {
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
int size = 0;
|
||||||
|
const char * device;
|
||||||
|
const struct device_list * device_first;
|
||||||
|
char ** ret;
|
||||||
|
char * last_ptr;
|
||||||
|
int i, j, k;
|
||||||
|
|
||||||
|
device_first = device_list;
|
||||||
|
|
||||||
|
while ( device_first ) {
|
||||||
|
|
||||||
|
int local = 0;
|
||||||
|
|
||||||
|
if ( ! device_to_string(device_first->device) ) {
|
||||||
|
device_first = device_first->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( i = 0; device_first->hwrevs[i] != -1; ++i )
|
||||||
|
if ( device_first->hwrevs[i] >= 0 && device_first->hwrevs[i] <= 9999 )
|
||||||
|
++local;
|
||||||
|
|
||||||
|
size += (1+16+(MAX_HWREVS+1)*8)*(local/MAX_HWREVS+1);
|
||||||
|
count += local/MAX_HWREVS;
|
||||||
|
if ( local%MAX_HWREVS != 0 || local == 0 )
|
||||||
|
++count;
|
||||||
|
|
||||||
|
device_first = device_first->next;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = calloc(1, (count+1)*sizeof(char *) + size);
|
||||||
|
if ( ! ret )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
last_ptr = (char *)ret + (count+1)*sizeof(char *);
|
||||||
|
device_first = device_list;
|
||||||
|
|
||||||
|
while ( device_first ) {
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
|
||||||
|
device = device_to_string(device_first->device);
|
||||||
|
if ( ! device ) {
|
||||||
|
device_first = device_first->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( device_first->hwrevs[i+1] != -1 ) {
|
||||||
|
|
||||||
|
uint8_t len = 0;
|
||||||
|
ret[j] = ++last_ptr;
|
||||||
|
|
||||||
|
strncpy(ret[j]+1, device, 16);
|
||||||
|
last_ptr += 16;
|
||||||
|
len += 16;
|
||||||
|
|
||||||
|
k = 0;
|
||||||
|
|
||||||
|
for ( k = 0; k < MAX_HWREVS; ++k ) {
|
||||||
|
|
||||||
|
if ( device_first->hwrevs[i+1] == -1 )
|
||||||
|
break;
|
||||||
|
|
||||||
|
++i;
|
||||||
|
|
||||||
|
if ( device_first->hwrevs[i] < 0 || device_first->hwrevs[i] > 9999 )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
snprintf(ret[j]+1+16+k*8, 8, "%d", device_first->hwrevs[i]);
|
||||||
|
last_ptr += 8;
|
||||||
|
len += 8;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
((uint8_t*)ret[j])[0] = len;
|
||||||
|
|
||||||
|
++j;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
device_first = device_first->next;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ret[j] = NULL;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct device_list * device_list_alloc_from_buf(const char * buf, size_t size) {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
int len;
|
||||||
|
int count;
|
||||||
|
char str[17];
|
||||||
|
const char * ptr1;
|
||||||
|
const char * ptr;
|
||||||
|
struct device_list * ret;
|
||||||
|
|
||||||
|
ret = calloc(1, sizeof(struct device_list));
|
||||||
|
if ( ! ret )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
len = strnlen(buf, size);
|
||||||
|
if ( len > 16 )
|
||||||
|
len = 16;
|
||||||
|
|
||||||
|
memset(str, 0, sizeof(str));
|
||||||
|
memcpy(str, buf, len);
|
||||||
|
ptr1 = buf + len;
|
||||||
|
|
||||||
|
ret->device = device_from_string(str);
|
||||||
|
|
||||||
|
ptr = ptr1;
|
||||||
|
count = 1;
|
||||||
|
while ( ptr < buf + size ) {
|
||||||
|
|
||||||
|
while ( ptr < buf + size && *ptr < 32 )
|
||||||
|
++ptr;
|
||||||
|
|
||||||
|
if ( ptr >= buf + size )
|
||||||
|
break;
|
||||||
|
|
||||||
|
len = strnlen(ptr, buf + size - ptr);
|
||||||
|
if ( len > 8 )
|
||||||
|
len = 8;
|
||||||
|
|
||||||
|
ptr += len + 1;
|
||||||
|
++count;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ret->hwrevs = calloc(count, sizeof(int16_t));
|
||||||
|
if ( ! ret->hwrevs )
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
ptr = ptr1;
|
||||||
|
i = 0;
|
||||||
|
while ( ptr < buf + size ) {
|
||||||
|
|
||||||
|
while ( ptr < buf + size && *ptr < 32 )
|
||||||
|
++ptr;
|
||||||
|
|
||||||
|
if ( ptr >= buf + size )
|
||||||
|
break;
|
||||||
|
|
||||||
|
len = strnlen(ptr, buf + size - ptr);
|
||||||
|
if ( len > 8 )
|
||||||
|
len = 8;
|
||||||
|
|
||||||
|
memset(str, 0, sizeof(str));
|
||||||
|
memcpy(str, ptr, len);
|
||||||
|
ptr += len + 1;
|
||||||
|
ret->hwrevs[i++] = atoi(str);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ret->hwrevs[i] = -1;
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DEVICE_H
|
||||||
|
#define DEVICE_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
enum device {
|
||||||
|
DEVICE_UNKNOWN = 0,
|
||||||
|
DEVICE_ANY, /* Unspecified / Any device */
|
||||||
|
DEVICE_SU_18, /* Nokia 770 */
|
||||||
|
DEVICE_RX_34, /* Nokia N800 */
|
||||||
|
DEVICE_RX_44, /* Nokia N810 */
|
||||||
|
DEVICE_RX_48, /* Nokia N810 WiMax */
|
||||||
|
DEVICE_RX_51, /* Nokia N900 */
|
||||||
|
DEVICE_COUNT,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
hwrevs - array of int16_t
|
||||||
|
- terminated by -1
|
||||||
|
- valid numbers: 0-9999
|
||||||
|
*/
|
||||||
|
struct device_list {
|
||||||
|
enum device device;
|
||||||
|
int16_t * hwrevs;
|
||||||
|
struct device_list * next;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum device device_from_string(const char * device);
|
||||||
|
const char * device_to_string(enum device device);
|
||||||
|
const char * device_to_long_string(enum device device);
|
||||||
|
|
||||||
|
int hwrev_is_valid(const int16_t * hwrevs, int16_t hwrev);
|
||||||
|
|
||||||
|
int16_t * hwrevs_alloc_from_string(const char * str);
|
||||||
|
char * hwrevs_alloc_to_string(const int16_t * hwrevs);
|
||||||
|
|
||||||
|
char ** device_list_alloc_to_bufs(const struct device_list * device_list);
|
||||||
|
struct device_list * device_list_alloc_from_buf(const char * buf, size_t size);
|
||||||
|
|
||||||
|
#endif
|
||||||
-120
@@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
|
||||||
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
|
||||||
*
|
|
||||||
* 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 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if HAVE_USB
|
|
||||||
#include "main.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The internet tablet PC (and probably most of
|
|
||||||
* Nokia devices have different USB-IDs depending
|
|
||||||
* on the boot state.
|
|
||||||
*
|
|
||||||
* The following table shows this info:
|
|
||||||
*
|
|
||||||
* boot os
|
|
||||||
* n770 0421:0105 0421:0431
|
|
||||||
* n800 0421:0431
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
struct devices supported_devices[SUPPORTED_DEVICES] = {
|
|
||||||
{ "FFFF", 0x000, 0x0000, 0x0000 }, // dummy
|
|
||||||
{ "unkn", 0x421, 0x3f00, 0x0000 }, // probably a development board
|
|
||||||
{ "n770/n810", 0x421, 0x0105, 0x0001 }, // my n770
|
|
||||||
{ "n800", 0x421, 0x04c3, 0x0001 }, // a n800
|
|
||||||
{ 0 },
|
|
||||||
{ 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Returns 0 when no device was found and a positive
|
|
||||||
* non-zero value when one was found.
|
|
||||||
*
|
|
||||||
* The return value is the index into the supported_devices
|
|
||||||
* array which denotes the device which was found.
|
|
||||||
*/
|
|
||||||
int is_valid_device(struct usb_device_descriptor *udd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
struct devices ptr = supported_devices[1];
|
|
||||||
|
|
||||||
for(i=1 ; ptr.vendor_id; ptr = supported_devices[++i])
|
|
||||||
if ((udd->idVendor == ptr.vendor_id)
|
|
||||||
&& (udd->idProduct == ptr.product_id)) {
|
|
||||||
D printf("found %s\n", supported_devices[i].name);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* List all supported device-ids and it's names
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void list_valid_devices()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
struct devices ptr = supported_devices[1];
|
|
||||||
|
|
||||||
for(i=1; ptr.vendor_id; ptr = supported_devices[++i])
|
|
||||||
printf("%04x:%04x %s\n", ptr.vendor_id, ptr.product_id, ptr.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns true (1) when a valid usb device is found and stores the udd and devices
|
|
||||||
* structures for the specified device.
|
|
||||||
* Otherwise returns false (0)
|
|
||||||
*/
|
|
||||||
|
|
||||||
int usb_device_found(struct usb_device_descriptor *udd, struct devices *it_device)
|
|
||||||
{
|
|
||||||
struct usb_bus *bus;
|
|
||||||
int dev_index = 0;
|
|
||||||
|
|
||||||
if (usb_find_busses() < 0) {
|
|
||||||
fprintf(stderr, "\nerror: no usb busses found.\n");
|
|
||||||
exit(1);
|
|
||||||
} else {
|
|
||||||
switch(usb_find_devices()) {
|
|
||||||
case -1:
|
|
||||||
fprintf(stderr, "\nerror: no devices found.\n");
|
|
||||||
exit(1);
|
|
||||||
default:
|
|
||||||
for (bus = usb_busses; bus; bus = bus->next) {
|
|
||||||
struct usb_device *dev = bus->devices;
|
|
||||||
D printf("bus: \n");
|
|
||||||
for (; dev; dev = dev->next) {
|
|
||||||
*udd = dev->descriptor;
|
|
||||||
D printf(" dev (%s) - ", dev->filename);
|
|
||||||
D printf("vendor: %04x product: %04x\n", udd->idVendor, udd->idProduct);
|
|
||||||
|
|
||||||
if ((dev_index = is_valid_device(udd))) {
|
|
||||||
device = dev;
|
|
||||||
*it_device = supported_devices[dev_index];
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
+188
@@ -0,0 +1,188 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
|
||||||
|
#include <linux/fs.h>
|
||||||
|
|
||||||
|
#include "disk.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "device.h"
|
||||||
|
#include "usb-device.h"
|
||||||
|
#include "printf-utils.h"
|
||||||
|
|
||||||
|
static char global_buf[1 << 22]; /* 4MB */
|
||||||
|
|
||||||
|
int disk_init(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
ERROR("RAW mode is not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
enum device disk_get_device(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
return DEVICE_UNKNOWN;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int disk_flash_raw(const char * blkdev, const char * file) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)blkdev;
|
||||||
|
(void)file;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int disk_flash_image(struct usb_device_info * dev, struct image * image) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)image;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int disk_dump_raw(const char * blkdev, const char * file) {
|
||||||
|
|
||||||
|
int fd1, fd2;
|
||||||
|
int ret;
|
||||||
|
char * path;
|
||||||
|
uint64_t blksize;
|
||||||
|
size_t need, readed;
|
||||||
|
ssize_t size;
|
||||||
|
struct stat st;
|
||||||
|
struct statvfs buf;
|
||||||
|
|
||||||
|
printf("Dump block device %s to file %s...\n", blkdev, file);
|
||||||
|
|
||||||
|
if ( stat(blkdev, &st) != 0 ) {
|
||||||
|
ERROR_INFO("Cannot stat block device %s", blkdev);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! S_ISBLK(st.st_mode) ) {
|
||||||
|
ERROR("Invalid block device %s", blkdev);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd1 = open(blkdev, O_RDONLY);
|
||||||
|
|
||||||
|
if ( fd1 < 0 ) {
|
||||||
|
ERROR_INFO("Cannot open block device %s", blkdev);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ioctl(fd1, BLKGETSIZE64, &blksize) != 0 ) {
|
||||||
|
ERROR_INFO("Cannot get size of block device %s", blkdev);
|
||||||
|
close(fd1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( blksize > ULLONG_MAX ) {
|
||||||
|
ERROR("Block device %s is too big", blkdev);
|
||||||
|
close(fd1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( blksize == 0 ) {
|
||||||
|
ERROR("Block device %s has zero size", blkdev);
|
||||||
|
close(fd1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
path = strdup(file);
|
||||||
|
if ( ! path ) {
|
||||||
|
ALLOC_ERROR();
|
||||||
|
close(fd1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = statvfs(dirname(path), &buf);
|
||||||
|
|
||||||
|
free(path);
|
||||||
|
|
||||||
|
if ( ret == 0 && buf.f_bsize * buf.f_bfree < blksize ) {
|
||||||
|
ERROR("Not enought free space (have: %llu, need: %llu)", (unsigned long long int)(buf.f_bsize) * buf.f_bfree, (unsigned long long int)blksize);
|
||||||
|
close(fd1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd2 = creat(file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||||
|
|
||||||
|
if ( fd2 < 0 ) {
|
||||||
|
ERROR_INFO("Cannot create file %s", file);
|
||||||
|
close(fd1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
readed = 0;
|
||||||
|
printf_progressbar(0, blksize);
|
||||||
|
|
||||||
|
while ( readed < blksize ) {
|
||||||
|
need = blksize - readed;
|
||||||
|
if ( need > sizeof(global_buf) )
|
||||||
|
need = sizeof(global_buf);
|
||||||
|
size = read(fd1, global_buf, need);
|
||||||
|
if ( size == 0 )
|
||||||
|
break;
|
||||||
|
if ( write(fd2, global_buf, size) != size ) {
|
||||||
|
PRINTF_ERROR("Dumping image failed");
|
||||||
|
close(fd1);
|
||||||
|
close(fd2);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
readed += size;
|
||||||
|
printf_progressbar(readed, blksize);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd1);
|
||||||
|
close(fd2);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int disk_dump_image(struct usb_device_info * dev, enum image_type image, const char * file) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)image;
|
||||||
|
(void)file;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int disk_check_badblocks(struct usb_device_info * dev, const char * device) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)device;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DISK_H
|
||||||
|
#define DISK_H
|
||||||
|
|
||||||
|
#include "image.h"
|
||||||
|
#include "device.h"
|
||||||
|
#include "usb-device.h"
|
||||||
|
|
||||||
|
int disk_init(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
enum device disk_get_device(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
int disk_flash_raw(const char * blkdev, const char * file);
|
||||||
|
int disk_dump_raw(const char * blkdev, const char * file);
|
||||||
|
|
||||||
|
int disk_flash_image(struct usb_device_info * dev, struct image * image);
|
||||||
|
int disk_dump_image(struct usb_device_info * dev, enum image_type image, const char * file);
|
||||||
|
int disk_check_badblocks(struct usb_device_info * dev, const char * device);
|
||||||
|
|
||||||
|
#endif
|
||||||
-584
@@ -1,584 +0,0 @@
|
|||||||
/*
|
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
|
||||||
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
|
||||||
*
|
|
||||||
* 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 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "hexdump.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Extracts a piece from an mtd device
|
|
||||||
* -----------------------------------
|
|
||||||
* This function is known to be buggy, It does not takes care about
|
|
||||||
* badblocks and oob data. It is replaced by nanddump(), but will
|
|
||||||
* probably be fixed in the future or it will die.
|
|
||||||
*/
|
|
||||||
int rf_extract(char *dev, off_t from, off_t to, char *file)
|
|
||||||
{
|
|
||||||
off_t i, blk = 0xfffff;
|
|
||||||
char buf[0xfffff];
|
|
||||||
FILE *fs = fopen(dev, "rb");
|
|
||||||
FILE *fd = fopen(file, "wb+");
|
|
||||||
|
|
||||||
if (from>to) {
|
|
||||||
printf("Bad range %lld - %lld for %s\n", from, to, file);
|
|
||||||
goto __rf_extract_exit;
|
|
||||||
}
|
|
||||||
if (fs == NULL) { perror(dev); goto __rf_extract_exit; }
|
|
||||||
if (fd == NULL) { perror(file); goto __rf_extract_exit; }
|
|
||||||
|
|
||||||
printf("Extracting %s...\n", file);
|
|
||||||
fseek(fs, from, SEEK_SET);
|
|
||||||
|
|
||||||
for(i=from;i<to;i+=blk) {
|
|
||||||
int ret;
|
|
||||||
if (i+blk>to) blk = to-i;
|
|
||||||
ret = fread(buf, blk, 1, fs);
|
|
||||||
progressbar(i, to);
|
|
||||||
if (!ret || feof(fs)) break;
|
|
||||||
fwrite(buf, blk, 1, fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\r%s: %lld bytes dumped from %s\n",
|
|
||||||
file, to-from, dev);
|
|
||||||
|
|
||||||
__rf_extract_exit:
|
|
||||||
if (fs) fclose(fs);
|
|
||||||
if (fd) fclose(fd);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This function was covardly copied from nanddump.c @ mtd-utils-20060907
|
|
||||||
*/
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
//#include <asm/types.h>
|
|
||||||
#include <mtd/mtd-user.h>
|
|
||||||
#ifndef loff_t
|
|
||||||
#define loff_t off_t
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define M_RDONLY 0x00000001
|
|
||||||
#define M_RDRW 0x00000002
|
|
||||||
#define M_OMITOOB 0x00000010
|
|
||||||
#define M_OMITBAD 0x00000011
|
|
||||||
#define M_OMITECC 0x00000012
|
|
||||||
|
|
||||||
int mtd_open(char *file, mtd_info_t *meminfo, int *oobinfochanged,
|
|
||||||
struct nand_oobinfo *old_oobinfo, int *eccstats, int flags)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
*oobinfochanged = 0 ;
|
|
||||||
|
|
||||||
fd = open(file, (flags&M_RDONLY)?O_RDONLY:O_RDWR);
|
|
||||||
if (fd == -1) {
|
|
||||||
perror("mtd_open");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/* Fill in MTD device capability structure */
|
|
||||||
if (ioctl(fd, MEMGETINFO, meminfo) != 0) {
|
|
||||||
perror("MEMGETINFO");
|
|
||||||
close(fd);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure device page sizes are valid */
|
|
||||||
if (!(meminfo->oobsize == 64 && meminfo->writesize == 2048) &&
|
|
||||||
!(meminfo->oobsize == 16 && meminfo->writesize == 512) &&
|
|
||||||
!(meminfo->oobsize == 8 && meminfo->writesize == 256)) {
|
|
||||||
fprintf(stderr, "Unknown flash (not normal NAND)\n");
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mtd_close(int fd, struct nand_oobinfo *old_oobinfo, int oobinfochanged)
|
|
||||||
{
|
|
||||||
if (fd == -1)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
/* reset oobinfo */
|
|
||||||
if (oobinfochanged == 1) {
|
|
||||||
if (ioctl (fd, MEMSETOOBSEL, &old_oobinfo) != 0) {
|
|
||||||
perror ("MEMSETOOBSEL");
|
|
||||||
close(fd);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Close the output file and MTD device */
|
|
||||||
return close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
// configuration for nanddump //
|
|
||||||
//int noecc = 0; // don't error correct
|
|
||||||
int omitoob = 1; // omit oob data
|
|
||||||
int omitbad = 1;
|
|
||||||
// configuration for nanddump //
|
|
||||||
|
|
||||||
#define CONFIGURE_FLAGS(x) \
|
|
||||||
omitoob = x & M_OMITOOB; \
|
|
||||||
omitbad = x & M_OMITBAD;
|
|
||||||
|
|
||||||
int check_badblocks(char *mtddev)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
int oobinfochanged = 0 ;
|
|
||||||
int badblock = 0;
|
|
||||||
int badblocks = 1;
|
|
||||||
int eccstats = 0;
|
|
||||||
unsigned long int i;
|
|
||||||
unsigned long long blockstart = 1;
|
|
||||||
unsigned char oobbuf[64];
|
|
||||||
struct nand_oobinfo old_oobinfo;
|
|
||||||
struct mtd_oob_buf oob = {0, 16, oobbuf};
|
|
||||||
struct mtd_ecc_stats stat1, stat2;
|
|
||||||
mtd_info_t meminfo;
|
|
||||||
|
|
||||||
fd = mtd_open(mtddev, &meminfo, &oobinfochanged, &old_oobinfo, &eccstats, M_RDONLY);
|
|
||||||
|
|
||||||
if (fd == -1) {
|
|
||||||
printf("cannot open mtd\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "Block size %u, page size %u, OOB size %u\n",
|
|
||||||
meminfo.erasesize, meminfo.writesize, meminfo.oobsize);
|
|
||||||
fprintf(stderr, "Size %u, flags %u, type 0x%x\n",
|
|
||||||
meminfo.size, meminfo.flags, (int)meminfo.type);
|
|
||||||
|
|
||||||
|
|
||||||
oob.length = meminfo.oobsize;
|
|
||||||
for(i = 0; i < meminfo.size; i+= meminfo.writesize) {
|
|
||||||
|
|
||||||
// new eraseblock , check for bad block
|
|
||||||
if (blockstart != (i & (~meminfo.erasesize + 1))) {
|
|
||||||
blockstart = i & (~meminfo.erasesize + 1);
|
|
||||||
if ((badblock = ioctl(fd, MEMGETBADBLOCK, &blockstart)) < 0) {
|
|
||||||
perror("ioctl(MEMGETBADBLOCK)");
|
|
||||||
goto closeall;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (badblock) {
|
|
||||||
if (omitbad) {
|
|
||||||
printf("Bad block found at 0x%lx\n", i);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
char readbuf[2048]; // XXX hardcoded like mtd-utils?? ugly!
|
|
||||||
// dummy -- should be removed
|
|
||||||
if (pread(fd, readbuf, meminfo.writesize, i) != meminfo.writesize) {
|
|
||||||
perror("pread");
|
|
||||||
goto closeall;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ECC stats available ? */
|
|
||||||
if (eccstats) {
|
|
||||||
if (ioctl(fd, ECCGETSTATS, &stat2)) {
|
|
||||||
perror("ioctl(ECCGETSTATS)");
|
|
||||||
goto closeall;
|
|
||||||
}
|
|
||||||
if (stat1.failed != stat2.failed)
|
|
||||||
fprintf(stderr, "ECC: %d uncorrectable bitflip(s)"
|
|
||||||
" at offset 0x%08lx\n",
|
|
||||||
stat2.failed - stat1.failed, i);
|
|
||||||
if (stat1.corrected != stat2.corrected)
|
|
||||||
fprintf(stderr, "ECC: %d corrected bitflip(s) at"
|
|
||||||
" offset 0x%08lx\n",
|
|
||||||
stat2.corrected - stat1.corrected, i);
|
|
||||||
stat1 = stat2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (badblock) {
|
|
||||||
printf("Oops badblock %d at 0x%lx !\n", badblocks++, i);
|
|
||||||
} else {
|
|
||||||
/* Read OOB data and exit on failure */
|
|
||||||
oob.start = i;
|
|
||||||
if (ioctl(fd, MEMREADOOB, &oob) != 0) {
|
|
||||||
perror("ioctl(MEMREADOOB)");
|
|
||||||
goto closeall;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write out OOB data */
|
|
||||||
if (badblock)
|
|
||||||
D dump_bytes(oobbuf, meminfo.oobsize);
|
|
||||||
}
|
|
||||||
|
|
||||||
mtd_close(fd, &old_oobinfo, oobinfochanged);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
closeall:
|
|
||||||
mtd_close(fd, &old_oobinfo, oobinfochanged);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX warning ioob is not used
|
|
||||||
int nanddump(char *mtddev, unsigned long start_addr, unsigned long length, char *dumpfile, int isbl, int ioob)
|
|
||||||
{
|
|
||||||
unsigned char readbuf[2048];
|
|
||||||
int oobinfochanged = 0 ;
|
|
||||||
unsigned char oobbuf[64];
|
|
||||||
unsigned long ofs, end_addr = 0;
|
|
||||||
unsigned long long blockstart = 1;
|
|
||||||
struct nand_oobinfo none_oobinfo = {
|
|
||||||
.useecc = MTD_NANDECC_OFF,
|
|
||||||
};
|
|
||||||
int fd, ofd, bs, badblock = 0;
|
|
||||||
struct mtd_oob_buf oob = {0, 16, oobbuf};
|
|
||||||
mtd_info_t meminfo;
|
|
||||||
int badblocks = 1;
|
|
||||||
struct nand_oobinfo old_oobinfo;
|
|
||||||
int eccstats = 0;
|
|
||||||
struct mtd_ecc_stats stat1, stat2;
|
|
||||||
int flags = M_RDONLY;
|
|
||||||
|
|
||||||
printf("\nExtracting %s from %s...\n", dumpfile, mtddev);
|
|
||||||
|
|
||||||
fd = mtd_open(mtddev, &meminfo, &oobinfochanged, &old_oobinfo, &eccstats, flags);
|
|
||||||
|
|
||||||
if (meminfo.writesize == 0) {
|
|
||||||
printf("What the fuck.. this is not an MTD device!\n");
|
|
||||||
close(fd);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read the real oob length */
|
|
||||||
oob.length = meminfo.oobsize;
|
|
||||||
fprintf(stderr, "Block size %u, page size %u, OOB size %u\n",
|
|
||||||
meminfo.erasesize, meminfo.writesize, meminfo.oobsize);
|
|
||||||
fprintf(stderr, "Size %u, flags %u, type 0x%x\n",
|
|
||||||
meminfo.size, meminfo.flags, (int)meminfo.type);
|
|
||||||
|
|
||||||
if (flags & M_OMITECC) { // (noecc)
|
|
||||||
switch (ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW)) {
|
|
||||||
case -ENOTTY:
|
|
||||||
if (ioctl (fd, MEMGETOOBSEL, old_oobinfo) != 0) {
|
|
||||||
perror ("MEMGETOOBSEL");
|
|
||||||
close (fd);
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
if (ioctl (fd, MEMSETOOBSEL, none_oobinfo) != 0) {
|
|
||||||
perror ("MEMSETOOBSEL");
|
|
||||||
close (fd);
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
oobinfochanged = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
oobinfochanged = 2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
perror ("MTDFILEMODE");
|
|
||||||
close (fd);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* check if we can read ecc stats */
|
|
||||||
if (!ioctl(fd, ECCGETSTATS, &stat1)) {
|
|
||||||
eccstats = 1;
|
|
||||||
fprintf(stderr, "ECC failed: %d\n", stat1.failed);
|
|
||||||
fprintf(stderr, "ECC corrected: %d\n", stat1.corrected);
|
|
||||||
fprintf(stderr, "Number of bad blocks: %d\n", stat1.badblocks);
|
|
||||||
fprintf(stderr, "Number of bbt blocks: %d\n", stat1.bbtblocks);
|
|
||||||
} else
|
|
||||||
perror("No ECC status information available");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Open output file for writing. If file name is "-", write to standard
|
|
||||||
* output. */
|
|
||||||
if (!dumpfile) {
|
|
||||||
ofd = STDOUT_FILENO;
|
|
||||||
} else if ((ofd = open(dumpfile, O_WRONLY | O_TRUNC | O_CREAT, 0644))== -1) {
|
|
||||||
perror ("open outfile");
|
|
||||||
close(fd);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize start/end addresses and block size */
|
|
||||||
if (length)
|
|
||||||
end_addr = start_addr + length;
|
|
||||||
if (!length || end_addr > meminfo.size)
|
|
||||||
end_addr = meminfo.size;
|
|
||||||
|
|
||||||
bs = meminfo.writesize;
|
|
||||||
|
|
||||||
fprintf(stderr,
|
|
||||||
"Dumping data starting at 0x%08x and ending at 0x%08x...\n",
|
|
||||||
(unsigned int) start_addr, (unsigned int) end_addr);
|
|
||||||
|
|
||||||
/* Dump the flash contents */
|
|
||||||
for (ofs = start_addr; ofs < end_addr ; ofs+=bs) {
|
|
||||||
// new eraseblock , check for bad block
|
|
||||||
if (blockstart != (ofs & (~meminfo.erasesize + 1))) {
|
|
||||||
blockstart = ofs & (~meminfo.erasesize + 1);
|
|
||||||
if ((badblock = ioctl(fd, MEMGETBADBLOCK, &blockstart)) < 0) {
|
|
||||||
perror("ioctl(MEMGETBADBLOCK)");
|
|
||||||
goto closeall;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isbl && badblock) {
|
|
||||||
if (omitbad)
|
|
||||||
continue;
|
|
||||||
memset (readbuf, 0xff, bs);
|
|
||||||
} else {
|
|
||||||
/* Read page data and exit on failure */
|
|
||||||
if (pread(fd, readbuf, bs, ofs) != bs) {
|
|
||||||
perror("pread");
|
|
||||||
goto closeall;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO exist on n800??? // remove code?
|
|
||||||
/* ECC stats available ? */
|
|
||||||
if (eccstats) {
|
|
||||||
if (ioctl(fd, ECCGETSTATS, &stat2)) {
|
|
||||||
perror("ioctl(ECCGETSTATS)");
|
|
||||||
goto closeall;
|
|
||||||
}
|
|
||||||
if (stat1.failed != stat2.failed)
|
|
||||||
fprintf(stderr, "ECC: %d uncorrectable bitflip(s)"
|
|
||||||
" at offset 0x%08lx\n",
|
|
||||||
stat2.failed - stat1.failed, ofs);
|
|
||||||
if (stat1.corrected != stat2.corrected)
|
|
||||||
fprintf(stderr, "ECC: %d corrected bitflip(s) at"
|
|
||||||
" offset 0x%08lx\n",
|
|
||||||
stat2.corrected - stat1.corrected, ofs);
|
|
||||||
stat1 = stat2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write out page data */
|
|
||||||
//if (pretty_print) dump_bytes(readbuf, bs);
|
|
||||||
write(ofd, readbuf, bs);
|
|
||||||
progressbar(ofs, end_addr);
|
|
||||||
|
|
||||||
// OOB STUFF //
|
|
||||||
if (omitoob)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!isbl&&badblock) {
|
|
||||||
printf("Oops badblock %d *ignored* at 0x%lx !\n", badblocks++, ofs);
|
|
||||||
memset (readbuf, 0xff, meminfo.oobsize);
|
|
||||||
} else {
|
|
||||||
/* Read OOB data and exit on failure */
|
|
||||||
oob.start = ofs;
|
|
||||||
if (ioctl(fd, MEMREADOOB, &oob) != 0) {
|
|
||||||
perror("ioctl(MEMREADOOB)");
|
|
||||||
goto closeall;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write out OOB data */
|
|
||||||
D dump_bytes(oobbuf, meminfo.oobsize);
|
|
||||||
write(ofd, oobbuf, meminfo.oobsize);
|
|
||||||
}
|
|
||||||
|
|
||||||
mtd_close(fd, &old_oobinfo, oobinfochanged);
|
|
||||||
close(ofd);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
closeall:
|
|
||||||
mtd_close(fd, &old_oobinfo, oobinfochanged);
|
|
||||||
close(ofd);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int rf_strip(char *file)
|
|
||||||
{
|
|
||||||
FILE *fd = fopen(file, "rw");
|
|
||||||
unsigned char buf[4096];
|
|
||||||
int ret;
|
|
||||||
off_t eof = 0;
|
|
||||||
|
|
||||||
if (!fd) {
|
|
||||||
fprintf(stderr, "Weird! can't open %s???\n", file);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
printf("Stripping padding from %s... ", file);
|
|
||||||
fflush(stdout);
|
|
||||||
fseek(fd, 0, SEEK_END);
|
|
||||||
if (ftell(fd)>4096) {
|
|
||||||
do {
|
|
||||||
fseek(fd, -4096, SEEK_CUR);
|
|
||||||
ret = fread(buf, 1, 4096, fd);
|
|
||||||
fseek(fd, -4096, SEEK_CUR);
|
|
||||||
for(ret--;ret>0;ret--)
|
|
||||||
if (buf[ret]!=0xff) {
|
|
||||||
fseek(fd, ret+1, SEEK_CUR);
|
|
||||||
eof = ftell(fd);
|
|
||||||
goto __done;
|
|
||||||
}
|
|
||||||
} while(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
__done:
|
|
||||||
fclose(fd);
|
|
||||||
if (eof) truncate(file, eof);
|
|
||||||
printf("done at %d\n", (int)eof);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int is_n800()
|
|
||||||
{
|
|
||||||
int n800 = 0;
|
|
||||||
unsigned char buf[4];
|
|
||||||
FILE *fd = fopen("/dev/mtd0", "rb");
|
|
||||||
|
|
||||||
if (!fd) {
|
|
||||||
fprintf(stderr, "Cannot open /dev/mtd0.\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
fread(buf, 4, 1,fd);
|
|
||||||
if (!memcmp("\xff\xff\xff\xff", buf, 4))
|
|
||||||
n800 = 1;
|
|
||||||
|
|
||||||
fclose(fd);
|
|
||||||
|
|
||||||
return n800;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dump_config()
|
|
||||||
{
|
|
||||||
mtd_info_t meminfo;
|
|
||||||
int fd = open("/dev/mtd1", O_RDONLY);
|
|
||||||
char buf[1024];
|
|
||||||
int i=0,j;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
|
|
||||||
if (fd == -1) {
|
|
||||||
perror("open /dev/mtd1");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (ioctl(fd, MEMGETINFO, &meminfo) != 0) {
|
|
||||||
perror("MEMGETINFO");
|
|
||||||
close(fd);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(i<0x60000) {
|
|
||||||
iniloop:
|
|
||||||
ret = read(fd, buf, 4);
|
|
||||||
if (ret == -1)
|
|
||||||
break;
|
|
||||||
if (!memcmp(buf,"ConF", 4)) {
|
|
||||||
loop:
|
|
||||||
read(fd, buf, 4);
|
|
||||||
if (ret == -1) break;
|
|
||||||
printf("\n0x%08x : ConF %02x %02x %02x %02x : ", i,
|
|
||||||
buf[0], buf[1], buf[2], buf[3]);
|
|
||||||
fflush(stdout);
|
|
||||||
while(1) {
|
|
||||||
ret = read(fd, buf, 4);
|
|
||||||
if (ret <1) {
|
|
||||||
printf("Unexpected eof\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (buf[0]=='\0'||buf[1]=='\0'||buf[2]=='\0'||buf[3]=='\0') {
|
|
||||||
printf("%s \t ", buf);
|
|
||||||
fflush(stdout);
|
|
||||||
while(1) {
|
|
||||||
ret = read(fd, buf, 4);
|
|
||||||
if (ret <1) {
|
|
||||||
printf("Unexpected eof\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!memcmp(buf,"\xff\xff\xff\xff", 4))
|
|
||||||
goto iniloop;
|
|
||||||
if (!memcmp(buf,"ConF", 4))
|
|
||||||
goto loop;
|
|
||||||
printf ("%02x %02x %02x %02x ",
|
|
||||||
buf[0], buf[1], buf[2], buf[3]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
write(1, buf,4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
j = lseek(fd, 0, SEEK_CUR);
|
|
||||||
if (j==i) break; i = j;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
printf("\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int reverse_extract_pieces(char *dir)
|
|
||||||
{
|
|
||||||
char reply;
|
|
||||||
chdir(dir);
|
|
||||||
|
|
||||||
// TODO: get values from /proc/mtd ???
|
|
||||||
|
|
||||||
//rf_extract("/dev/mtd0", is_n800()?0x200:0, 0x003600, "xloader.bin");
|
|
||||||
nanddump("/dev/mtd0", is_n800()?0x200:0, 0x4000, "xloader.bin", 1,0); // 0x3600 size?
|
|
||||||
//rf_extract("/dev/mtd0", 0x004000, 0x01ffff, "secondary.bin");
|
|
||||||
nanddump("/dev/mtd0", 0x004000, 0, "secondary.bin", 1,0);
|
|
||||||
nanddump("/dev/mtd1", 0, 0, "config.bin", 0,0);
|
|
||||||
//rf_extract("/dev/mtd2", 0x000800, 0x200000, "zImage");
|
|
||||||
nanddump("/dev/mtd2", 0x000800, 0, "zImage", 0,0);
|
|
||||||
//rf_extract("/dev/mtd3", 0x000000, 0x1D00000, "initfs.jffs2");
|
|
||||||
nanddump("/dev/mtd3", 0x000000, 0, "initfs.jffs2", 0,0);
|
|
||||||
|
|
||||||
printf("\n\nExtract rootfs? (y/N): "); fflush(stdout);
|
|
||||||
read(0, &reply, 1);
|
|
||||||
if (reply=='y'||reply=='Y') {
|
|
||||||
//rf_extract("/dev/mtd4", 0x000000, 0x6000000, "rootfs.jffs2");
|
|
||||||
nanddump("/dev/mtd4", 0x000000, 0, "rootfs.jffs2", 0,0);
|
|
||||||
} else printf("*** Ignoring rootfs\n");
|
|
||||||
|
|
||||||
printf("\n\nStrip dumped files? (y/N): "); fflush(stdout);
|
|
||||||
read(0, &reply, 1);
|
|
||||||
if (reply=='y'||reply=='Y') {
|
|
||||||
rf_strip("xloader.bin");
|
|
||||||
rf_strip("secondary.bin");
|
|
||||||
rf_strip("zImage");
|
|
||||||
rf_strip("initfs.jffs2");
|
|
||||||
} else printf("*** Ignoring strip\n");
|
|
||||||
|
|
||||||
printf("\nIdentifying extracted files...\n");
|
|
||||||
printf("%s: xloader\n", fpid_file("xloader.bin"));
|
|
||||||
printf("%s: secondary.bin\n", fpid_file("secondary.bin"));
|
|
||||||
printf("%s: config.bin\n", fpid_file("config.bin"));
|
|
||||||
printf("%s: zImage\n", fpid_file("zImage"));
|
|
||||||
printf("%s: initfs.jffs2\n", fpid_file("initfs.jffs2"));
|
|
||||||
printf("%s: rootfs.jffs2\n", fpid_file("rootfs.jffs2"));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
+513
-268
@@ -1,327 +1,572 @@
|
|||||||
/*
|
/*
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
Copyright (C) 2007-2011 pancake <pancake@youterm.com>
|
||||||
*
|
Copyright (C) 2011-2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
* 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
|
This program is free software: you can redistribute it and/or modify
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
it under the terms of the GNU General Public License as published by
|
||||||
* (at your option) any later version.
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
*
|
(at your option) any later version.
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
This program is distributed in the hope that it will be useful,
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* GNU General Public License for more details.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
*
|
GNU General Public License for more details.
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fcntl.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include "main.h"
|
#include <fcntl.h>
|
||||||
#include "hash.h"
|
#include <unistd.h>
|
||||||
|
|
||||||
int (*fiasco_callback)(struct header_t *header) = NULL;
|
#include "global.h"
|
||||||
|
|
||||||
int openfiasco(char *name, char *piece_grep, int v)
|
#include "device.h"
|
||||||
{
|
#include "image.h"
|
||||||
struct header_t header;
|
#include "fiasco.h"
|
||||||
unsigned char buf[128];
|
|
||||||
unsigned char data[128];
|
|
||||||
unsigned char *pdata;
|
|
||||||
unsigned int namelen;
|
|
||||||
off_t off, here;
|
|
||||||
int i,j;
|
|
||||||
|
|
||||||
header.fd = open(name, O_RDONLY);
|
#define FIASCO_READ_ERROR(fiasco, ...) do { ERROR_INFO(__VA_ARGS__); fiasco_free(fiasco); return NULL; } while (0)
|
||||||
|
#define FIASCO_WRITE_ERROR(file, fd, ...) do { ERROR_INFO_STR(file, __VA_ARGS__); if ( fd >= 0 ) close(fd); return -1; } while (0)
|
||||||
|
#define READ_OR_FAIL(fiasco, buf, size) do { if ( read(fiasco->fd, buf, size) != size ) { FIASCO_READ_ERROR(fiasco, "Cannot read %d bytes", size); } } while (0)
|
||||||
|
#define READ_OR_RETURN(fiasco, buf, size) do { if ( read(fiasco->fd, buf, size) != size ) return fiasco; } while (0)
|
||||||
|
#define WRITE_OR_FAIL(file, fd, buf, size) do { if ( ! simulate ) { if ( write(fd, buf, size) != (ssize_t)size ) { FIASCO_WRITE_ERROR(file, fd, "Cannot write %d bytes", size); } } } while (0)
|
||||||
|
|
||||||
|
struct fiasco * fiasco_alloc_empty(void) {
|
||||||
|
|
||||||
|
struct fiasco * fiasco = calloc(1, sizeof(struct fiasco));
|
||||||
|
if ( ! fiasco )
|
||||||
|
ALLOC_ERROR_RETURN(NULL);
|
||||||
|
|
||||||
|
fiasco->fd = -1;
|
||||||
|
return fiasco;
|
||||||
|
|
||||||
if (header.fd == -1) {
|
|
||||||
fprintf(stderr, "Cannot open %s\n", name);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read header */
|
struct fiasco * fiasco_alloc_from_file(const char * file) {
|
||||||
read(header.fd, buf, 5);
|
|
||||||
if (buf[0] != 0xb4) {
|
|
||||||
printf("Invalid header\n");
|
|
||||||
return close(header.fd);
|
|
||||||
}
|
|
||||||
memcpy(&namelen,buf+1,4);
|
|
||||||
namelen = ntohl(namelen);
|
|
||||||
if (namelen>128) {
|
|
||||||
printf("Stupid length at header. Is this a joke?\n");
|
|
||||||
return close(header.fd);
|
|
||||||
}
|
|
||||||
memset(buf,'\0', 128);
|
|
||||||
read(header.fd, buf, namelen);
|
|
||||||
|
|
||||||
if (v) printf("Fiasco version: %2d\n", buf[3]);
|
uint8_t byte;
|
||||||
strcpy(header.fwname, (char *)buf+6);
|
uint32_t length;
|
||||||
if (v)
|
uint32_t count;
|
||||||
for(i=6;i<namelen;i+=strlen((char *)(buf+i))+1)
|
uint8_t length8;
|
||||||
printf("Name: %s\n", buf+i);
|
uint8_t count8;
|
||||||
|
|
||||||
|
char type[13];
|
||||||
|
char device[17];
|
||||||
|
char hwrevs[1024];
|
||||||
|
char version[257];
|
||||||
|
char layout[257];
|
||||||
|
uint16_t hash;
|
||||||
|
off_t offset;
|
||||||
|
struct image * image;
|
||||||
|
|
||||||
|
char hwrev[9];
|
||||||
|
unsigned char buf[512];
|
||||||
|
unsigned char *pbuf;
|
||||||
|
|
||||||
|
struct fiasco * fiasco = fiasco_alloc_empty();
|
||||||
|
if ( ! fiasco )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
fiasco->fd = open(file, O_RDONLY);
|
||||||
|
if ( fiasco->fd < 0 ) {
|
||||||
|
ERROR_INFO("Cannot open file");
|
||||||
|
fiasco_free(fiasco);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
fiasco->orig_filename = strdup(file);
|
||||||
|
|
||||||
|
READ_OR_FAIL(fiasco, &byte, 1);
|
||||||
|
if ( byte != 0xb4 )
|
||||||
|
FIASCO_READ_ERROR(fiasco, "Invalid fiasco signature");
|
||||||
|
|
||||||
|
READ_OR_FAIL(fiasco, &length, 4);
|
||||||
|
length = ntohl(length);
|
||||||
|
|
||||||
|
READ_OR_FAIL(fiasco, &count, 4);
|
||||||
|
count = ntohl(count);
|
||||||
|
|
||||||
|
VERBOSE("Number of header blocks: %d\n", count);
|
||||||
|
|
||||||
|
while ( count > 0 ) {
|
||||||
|
READ_OR_FAIL(fiasco, &byte, 1);
|
||||||
|
READ_OR_FAIL(fiasco, &length8, 1);
|
||||||
|
READ_OR_FAIL(fiasco, buf, length8);
|
||||||
|
if ( byte == 0xe8 ) {
|
||||||
|
memset(fiasco->name, 0, sizeof(fiasco->name));
|
||||||
|
strncpy(fiasco->name, (char *)buf, length8);
|
||||||
|
VERBOSE("Fiasco name: %s\n", fiasco->name);
|
||||||
|
} else if ( byte == 0x31 ) {
|
||||||
|
memset(fiasco->swver, 0, sizeof(fiasco->swver));
|
||||||
|
strncpy(fiasco->swver, (char *)buf, length8);
|
||||||
|
VERBOSE("SW version: %s\n", fiasco->swver);
|
||||||
|
} else {
|
||||||
|
VERBOSE("Unknown header %#x\n", byte);
|
||||||
|
}
|
||||||
|
--count;
|
||||||
|
}
|
||||||
|
|
||||||
/* walk the tree */
|
/* walk the tree */
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
here = lseek(header.fd, 0, SEEK_CUR);
|
|
||||||
if (read(header.fd, buf, 9)<9)
|
|
||||||
break;
|
|
||||||
if (buf[0] != 0x54) { // 'T'
|
|
||||||
/* skipping some bytes */
|
|
||||||
lseek(header.fd, -9, SEEK_CUR);
|
|
||||||
for(i=0;buf[0]!=0x54;i++) {
|
|
||||||
j = read(header.fd, buf, 1);
|
|
||||||
if (j == -1) {
|
|
||||||
printf("Cannot find next FIASCO header\n");
|
|
||||||
return close(header.fd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (v) printf("Skipping %d padding bytes\n", i);
|
|
||||||
lseek(header.fd, -1, SEEK_CUR);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
header.hash = buf[7]<<8|buf[8];
|
|
||||||
|
|
||||||
/* piece name */
|
/* If end of file, return fiasco image */
|
||||||
memset(data, '\0', 13);
|
READ_OR_RETURN(fiasco, buf, 7);
|
||||||
if (read(header.fd, data, 12)<12)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (data[0] == 0xff) {
|
/* Header of next image */
|
||||||
printf(" [eof]\n");
|
if ( ! buf[0] == 0x54 && buf[2] == 0x2E && buf[3] == 0x19 && buf[4] == 0x01 && buf[5] == 0x01 && buf[6] == 0x00 ) {
|
||||||
break;
|
ERROR("Invalid next image header");
|
||||||
} else if (v) printf(" %s\n", data);
|
return fiasco;
|
||||||
strcpy(header.name, (char *)data);
|
}
|
||||||
|
|
||||||
if (read(header.fd, buf, 9)<9)
|
count8 = buf[1];
|
||||||
break;
|
if ( count8 > 0 )
|
||||||
memcpy(&header.size, buf,4);
|
--count8;
|
||||||
header.size = ntohl(header.size);
|
|
||||||
if (v) {
|
READ_OR_RETURN(fiasco, &hash, 2);
|
||||||
printf(" offset: 0x%08x\n", (unsigned int)here);
|
hash = ntohs(hash);
|
||||||
printf(" size: %d bytes\n", header.size);
|
|
||||||
printf(" hash: %04x\n", header.hash);
|
memset(type, 0, sizeof(type));
|
||||||
|
READ_OR_RETURN(fiasco, type, 12);
|
||||||
|
|
||||||
|
byte = type[0];
|
||||||
|
if ( byte == 0xFF )
|
||||||
|
return fiasco;
|
||||||
|
|
||||||
|
VERBOSE(" %s\n", type);
|
||||||
|
|
||||||
|
READ_OR_RETURN(fiasco, &length, 4);
|
||||||
|
length = ntohl(length);
|
||||||
|
|
||||||
|
/* unknown */
|
||||||
|
READ_OR_RETURN(fiasco, buf, 4);
|
||||||
|
|
||||||
|
VERBOSE(" size: %d bytes\n", length);
|
||||||
|
VERBOSE(" hash: %#04x\n", hash);
|
||||||
|
VERBOSE(" subsections: %d\n", count8);
|
||||||
|
|
||||||
|
memset(device, 0, sizeof(device));
|
||||||
|
memset(hwrevs, 0, sizeof(hwrevs));
|
||||||
|
memset(version, 0, sizeof(version));
|
||||||
|
memset(layout, 0, sizeof(layout));
|
||||||
|
|
||||||
|
while ( count8 > 0 ) {
|
||||||
|
|
||||||
|
READ_OR_RETURN(fiasco, &byte, 1);
|
||||||
|
READ_OR_RETURN(fiasco, &length8, 1);
|
||||||
|
READ_OR_RETURN(fiasco, buf, length8);
|
||||||
|
|
||||||
|
VERBOSE(" subinfo\n");
|
||||||
|
VERBOSE(" length: %d\n", length8);
|
||||||
|
VERBOSE(" type: ");
|
||||||
|
|
||||||
|
if ( byte == '1' ) {
|
||||||
|
memset(version, 0, sizeof(version));
|
||||||
|
strncpy(version, (char *)buf, length8);
|
||||||
|
VERBOSE("version string\n");
|
||||||
|
VERBOSE(" version: %s\n", version);
|
||||||
|
} else if ( byte == '2' ) {
|
||||||
|
int tmp = length8;
|
||||||
|
if ( tmp > 16 ) tmp = 16;
|
||||||
|
memset(device, 0, sizeof(device));
|
||||||
|
strncpy(device, (char *)buf, tmp);
|
||||||
|
VERBOSE("hw revision\n");
|
||||||
|
VERBOSE(" device: %s\n", device);
|
||||||
|
pbuf = buf + strlen(device) + 1;
|
||||||
|
while ( pbuf < buf + length8 ) {
|
||||||
|
while ( pbuf < buf + length8 && *pbuf < 32 )
|
||||||
|
++pbuf;
|
||||||
|
if ( pbuf >= buf + length8 ) break;
|
||||||
|
tmp = buf + length8 - pbuf;
|
||||||
|
if ( tmp > 8 ) tmp = 8;
|
||||||
|
memset(hwrev, 0, sizeof(hwrev));
|
||||||
|
strncpy(hwrev, (char *)pbuf, tmp);
|
||||||
|
if ( ! hwrevs[0] )
|
||||||
|
strcpy(hwrevs, hwrev);
|
||||||
|
else {
|
||||||
|
/* TODO: check if hwrevs has enought size */
|
||||||
|
strcat(hwrevs, ",");
|
||||||
|
strcat(hwrevs, hwrev);
|
||||||
}
|
}
|
||||||
//printf("BYTE: %02x %02x %02x %02x %02x\n",
|
VERBOSE(" hw revision: %s\n", hwrev);
|
||||||
// buf[4], buf[5], buf[6], buf[7], buf[8]);
|
pbuf += strlen(hwrev) + 1;
|
||||||
/* XXX this is not ok */
|
|
||||||
//printf("BUF8: %02x\n", buf[8]);
|
|
||||||
while (buf[8] && buf[8]>'0' && buf[8] < '9') {
|
|
||||||
if (read(header.fd, data, 1)<1)
|
|
||||||
break;
|
|
||||||
i = data[0];
|
|
||||||
if (read(header.fd, data, i)<i)
|
|
||||||
break;
|
|
||||||
if (data[0]) {
|
|
||||||
if (v) {
|
|
||||||
printf(" version-length: %d\n", i);
|
|
||||||
printf(" version: %s\n", data);
|
|
||||||
}
|
}
|
||||||
pdata = data;
|
} else if ( byte == '3' ) {
|
||||||
while(pdata<data+i) {
|
memset(layout, 0, sizeof(layout));
|
||||||
strcat(header.name,pdata==data?"-":",");
|
strncpy(layout, (char *)buf, length8);
|
||||||
strcat(header.name, (char*)pdata);
|
VERBOSE("layout\n");
|
||||||
if (v) printf(" sub-version: %s\n", pdata);
|
|
||||||
pdata = pdata+strlen((char*)pdata)+1;
|
|
||||||
for(;*pdata=='\0'&&pdata<data+i;pdata=pdata+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
strcpy(header.version, (char *)data);
|
|
||||||
if (read(header.fd, buf+8, 1)<1)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* callback */
|
|
||||||
off = lseek(header.fd, 0, SEEK_CUR);
|
|
||||||
if (v) {
|
|
||||||
printf(" name: %s\n", header.name);
|
|
||||||
printf(" body-at: 0x%08x\n", (unsigned int)off);
|
|
||||||
}
|
|
||||||
if (piece_grep==NULL || (strstr(header.name, piece_grep))) {
|
|
||||||
printf("==> (%s) %s\n", piece_grep, header.name);
|
|
||||||
if (fiasco_callback != NULL) {
|
|
||||||
fiasco_callback(&header);
|
|
||||||
free(header.data);
|
|
||||||
continue;
|
|
||||||
} else {
|
} else {
|
||||||
// ??huh
|
VERBOSE("unknown ('%c':%#x)\n", byte, byte);
|
||||||
}
|
|
||||||
}
|
|
||||||
// XXX dup
|
|
||||||
lseek(header.fd, off, SEEK_SET);
|
|
||||||
lseek(header.fd, header.size, SEEK_CUR);
|
|
||||||
}
|
|
||||||
return close(header.fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fiasco_data_read(struct header_t *header)
|
--count8;
|
||||||
{
|
|
||||||
header->data = (unsigned char *)malloc(header->size);
|
|
||||||
if (header->data == NULL) {
|
|
||||||
printf("Cannot alloc %d bytes\n", header->size);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
read(header->fd, header->data, header->size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fiasco writer */
|
/* unknown */
|
||||||
int fiasco_new(const char *filename, const char *name)
|
READ_OR_RETURN(fiasco, buf, 1);
|
||||||
{
|
|
||||||
int fd;
|
offset = lseek(fiasco->fd, 0, SEEK_CUR);
|
||||||
//int len = htonl(strlen(name)+1+6+14);
|
|
||||||
|
VERBOSE(" version: %s\n", version);
|
||||||
|
VERBOSE(" device: %s\n", device);
|
||||||
|
VERBOSE(" hwrevs: %s\n", hwrevs);
|
||||||
|
VERBOSE(" data at: %#08x\n", (unsigned int)offset);
|
||||||
|
|
||||||
|
image = image_alloc_from_shared_fd(fiasco->fd, length, offset, hash, type, device, hwrevs, version, layout);
|
||||||
|
|
||||||
|
if ( ! image )
|
||||||
|
FIASCO_READ_ERROR(fiasco, "Cannot allocate image");
|
||||||
|
|
||||||
|
fiasco_add_image(fiasco, image);
|
||||||
|
|
||||||
|
lseek(fiasco->fd, offset+length, SEEK_SET);
|
||||||
|
|
||||||
fd = open(filename, O_RDWR|O_CREAT, 0644);
|
|
||||||
if (fd == -1)
|
|
||||||
return -1;
|
|
||||||
#if 1
|
|
||||||
write(fd, "\xb4\x00\x00\x00\x14\x00\x00\x00\x01\xe8\x0e", 11);
|
|
||||||
write(fd, "OSSO UART+USB", 14);
|
|
||||||
#else
|
|
||||||
/* 2nd format doesnt works. atm stay with old one */
|
|
||||||
write(fd, "\xb4", 1);
|
|
||||||
write(fd, &len, 4);
|
|
||||||
/* version header */
|
|
||||||
write(fd, "\x00\x00\x00\x02\xe8\x0e", 6);
|
|
||||||
/* firmware type */
|
|
||||||
write(fd, "OSSO UART+USB", 14);
|
|
||||||
/* firmware name */
|
|
||||||
write(fd, name, strlen(name));
|
|
||||||
write(fd, "", 1);
|
|
||||||
#endif
|
|
||||||
return fd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fiasco_add_eof(int fd)
|
return fiasco;
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
unsigned char buf[120];
|
|
||||||
if (fd == -1)
|
|
||||||
return -1;
|
|
||||||
memset(buf,'\xff', 120);
|
|
||||||
write(fd, buf, 120);
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fiasco_add(int fd, const char *name, const char *file, const char *version)
|
void fiasco_free(struct fiasco * fiasco) {
|
||||||
{
|
|
||||||
int gd,ret;
|
|
||||||
unsigned int sz;
|
|
||||||
unsigned char len;
|
|
||||||
unsigned short hash;
|
|
||||||
unsigned char *ptr = (unsigned char *)&hash;
|
|
||||||
char buf[4096];
|
|
||||||
char bname[32];
|
|
||||||
|
|
||||||
if (fd == -1)
|
struct image_list * list = fiasco->first;
|
||||||
return -1;
|
|
||||||
if (file == NULL)
|
while ( list ) {
|
||||||
return -1;
|
struct image_list * next = list->next;
|
||||||
gd = open(file, O_RDONLY);
|
image_list_del(list);
|
||||||
if (gd == -1)
|
list = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( fiasco->fd >= 0 )
|
||||||
|
close(fiasco->fd);
|
||||||
|
|
||||||
|
free(fiasco->orig_filename);
|
||||||
|
|
||||||
|
free(fiasco);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void fiasco_add_image(struct fiasco * fiasco, struct image * image) {
|
||||||
|
|
||||||
|
image_list_add(&fiasco->first, image);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int fiasco_write_to_file(struct fiasco * fiasco, const char * file) {
|
||||||
|
|
||||||
|
int fd = -1;
|
||||||
|
int i;
|
||||||
|
int device_count;
|
||||||
|
uint32_t size;
|
||||||
|
uint32_t length;
|
||||||
|
uint16_t hash;
|
||||||
|
uint8_t length8;
|
||||||
|
char ** device_hwrevs_bufs;
|
||||||
|
const char * str;
|
||||||
|
const char * type;
|
||||||
|
struct image_list * image_list;
|
||||||
|
struct image * image;
|
||||||
|
unsigned char buf[4096];
|
||||||
|
|
||||||
|
if ( ! fiasco )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
sz = htonl((unsigned int) lseek(gd, 0, SEEK_END));
|
printf("Generating Fiasco image %s...\n", file);
|
||||||
lseek(gd, 0, SEEK_SET);
|
|
||||||
// 4 bytes big endian
|
if ( ! fiasco->first )
|
||||||
//write(fd, "T\x02\x2e\x19\x01\x01\x00", 7); // header?
|
FIASCO_WRITE_ERROR(file, fd, "Nothing to write");
|
||||||
write(fd, "T\x01\x2e\x19\x01\x01\x00", 7); // header (old piece format)
|
|
||||||
|
if ( fiasco->name && strlen(fiasco->name)+1 > UINT8_MAX )
|
||||||
|
FIASCO_WRITE_ERROR(file, fd, "Fiasco name string is too long");
|
||||||
|
|
||||||
|
if ( fiasco->swver && strlen(fiasco->swver)+1 > UINT8_MAX )
|
||||||
|
FIASCO_WRITE_ERROR(file, fd, "SW version string is too long");
|
||||||
|
|
||||||
|
if ( ! simulate ) {
|
||||||
|
fd = open(file, O_RDWR|O_CREAT|O_TRUNC, 0644);
|
||||||
|
if ( fd < 0 ) {
|
||||||
|
ERROR_INFO("Cannot create file");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Writing Fiasco header...\n");
|
||||||
|
|
||||||
|
WRITE_OR_FAIL(file, fd, "\xb4", 1); /* signature */
|
||||||
|
|
||||||
|
if ( fiasco->name[0] )
|
||||||
|
str = fiasco->name;
|
||||||
|
else
|
||||||
|
str = "OSSO UART+USB";
|
||||||
|
|
||||||
|
length = 4 + strlen(str) + 3;
|
||||||
|
if ( fiasco->swver[0] )
|
||||||
|
length += strlen(fiasco->swver) + 3;
|
||||||
|
length = htonl(length);
|
||||||
|
WRITE_OR_FAIL(file, fd, &length, 4); /* FW header length */
|
||||||
|
|
||||||
|
if ( fiasco->swver[0] )
|
||||||
|
length = htonl(2);
|
||||||
|
else
|
||||||
|
length = htonl(1);
|
||||||
|
WRITE_OR_FAIL(file, fd, &length, 4); /* FW header blocks count */
|
||||||
|
|
||||||
|
/* Fiasco name */
|
||||||
|
length8 = strlen(str)+1;
|
||||||
|
WRITE_OR_FAIL(file, fd, "\xe8", 1);
|
||||||
|
WRITE_OR_FAIL(file, fd, &length8, 1);
|
||||||
|
WRITE_OR_FAIL(file, fd, str, length8);
|
||||||
|
|
||||||
|
/* SW version */
|
||||||
|
if ( fiasco->swver[0] ) {
|
||||||
|
printf("Writing SW version: %s\n", fiasco->swver);
|
||||||
|
length8 = strlen(fiasco->swver)+1;
|
||||||
|
WRITE_OR_FAIL(file, fd, "\x31", 1);
|
||||||
|
WRITE_OR_FAIL(file, fd, &length8, 1);
|
||||||
|
WRITE_OR_FAIL(file, fd, fiasco->swver, length8);
|
||||||
|
};
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
image_list = fiasco->first;
|
||||||
|
|
||||||
|
while ( image_list ) {
|
||||||
|
|
||||||
|
image = image_list->image;
|
||||||
|
|
||||||
|
if ( ! image )
|
||||||
|
FIASCO_WRITE_ERROR(file, fd, "Empty image");
|
||||||
|
|
||||||
|
printf("Writing image...\n");
|
||||||
|
image_print_info(image);
|
||||||
|
|
||||||
|
type = image_type_to_string(image->type);
|
||||||
|
|
||||||
|
device_hwrevs_bufs = device_list_alloc_to_bufs(image->devices);
|
||||||
|
|
||||||
|
device_count = 0;
|
||||||
|
if ( device_hwrevs_bufs && device_hwrevs_bufs[0] )
|
||||||
|
for ( ; device_hwrevs_bufs[device_count]; ++device_count );
|
||||||
|
|
||||||
|
if ( ! type )
|
||||||
|
FIASCO_WRITE_ERROR(file, fd, "Unknown image type");
|
||||||
|
|
||||||
|
if ( image->version && strlen(image->version) > UINT8_MAX )
|
||||||
|
FIASCO_WRITE_ERROR(file, fd, "Image version string is too long");
|
||||||
|
|
||||||
|
if ( image->layout && strlen(image->layout) > UINT8_MAX )
|
||||||
|
FIASCO_WRITE_ERROR(file, fd, "Image layout is too long");
|
||||||
|
|
||||||
|
printf("Writing image header...\n");
|
||||||
|
|
||||||
|
/* signature */
|
||||||
|
WRITE_OR_FAIL(file, fd, "T", 1);
|
||||||
|
|
||||||
|
/* number of subsections */
|
||||||
|
length8 = device_count+1;
|
||||||
|
if ( image->version )
|
||||||
|
++length8;
|
||||||
|
if ( image->layout )
|
||||||
|
++length8;
|
||||||
|
WRITE_OR_FAIL(file, fd, &length8, 1);
|
||||||
|
|
||||||
|
/* unknown */
|
||||||
|
WRITE_OR_FAIL(file, fd, "\x2e\x19\x01\x01\x00", 5);
|
||||||
|
|
||||||
/* checksum */
|
/* checksum */
|
||||||
hash = do_hash_file(file);
|
hash = htons(image->hash);
|
||||||
ptr[0]^=ptr[1]; ptr[1]=ptr[0]^ptr[1]; ptr[0]^=ptr[1];
|
WRITE_OR_FAIL(file, fd, &hash, 2);
|
||||||
write(fd, &hash, 2);
|
|
||||||
printf("hash: %04x\n", hash);
|
|
||||||
|
|
||||||
memset(bname, '\0', 13);
|
/* image type name */
|
||||||
if (name == NULL)
|
memset(buf, 0, 12);
|
||||||
name = fpid_file(file);
|
strncpy((char *)buf, type, 12);
|
||||||
/* failback */
|
WRITE_OR_FAIL(file, fd, buf, 12);
|
||||||
if (name == NULL)
|
|
||||||
name = file;
|
|
||||||
|
|
||||||
strncpy(bname, name, 12);
|
/* image size */
|
||||||
write(fd, bname, 12);
|
size = htonl(image->size);
|
||||||
|
WRITE_OR_FAIL(file, fd, &size, 4);
|
||||||
|
|
||||||
write(fd, &sz, 4);
|
/* unknown */
|
||||||
if (version) {
|
WRITE_OR_FAIL(file, fd, "\x00\x00\x00\x00", 4);
|
||||||
/* append metadata */
|
|
||||||
write(fd, "\x00\x00\x00\x00\x31", 5);
|
/* append version subsection */
|
||||||
len = strlen(version);
|
if ( image->version ) {
|
||||||
write(fd, &len, 1);
|
WRITE_OR_FAIL(file, fd, "1", 1); /* 1 - version */
|
||||||
write(fd, version, len);
|
length8 = strlen(image->version)+1;
|
||||||
write(fd, "\x00\x9b", 2);
|
WRITE_OR_FAIL(file, fd, &length8, 1);
|
||||||
} else {
|
WRITE_OR_FAIL(file, fd, image->version, length8);
|
||||||
write(fd, "\x00\x00\x00\x00\x9b", 5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* append device & hwrevs subsection */
|
||||||
|
for ( i = 0; i < device_count; ++i ) {
|
||||||
|
WRITE_OR_FAIL(file, fd, "2", 1); /* 2 - device & hwrevs */
|
||||||
|
WRITE_OR_FAIL(file, fd, &device_hwrevs_bufs[i][0], 1);
|
||||||
|
WRITE_OR_FAIL(file, fd, device_hwrevs_bufs[i]+1, ((uint8_t *)(device_hwrevs_bufs[i]))[0]);
|
||||||
|
}
|
||||||
|
free(device_hwrevs_bufs);
|
||||||
|
|
||||||
|
/* append layout subsection */
|
||||||
|
if ( image->layout ) {
|
||||||
|
length8 = strlen(image->layout);
|
||||||
|
WRITE_OR_FAIL(file, fd, "3", 1); /* 3 - layout */
|
||||||
|
WRITE_OR_FAIL(file, fd, &length8, 1);
|
||||||
|
WRITE_OR_FAIL(file, fd, image->layout, length8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* dummy byte - end of all subsections */
|
||||||
|
WRITE_OR_FAIL(file, fd, "\x00", 1);
|
||||||
|
|
||||||
|
printf("Writing image data...\n");
|
||||||
|
|
||||||
|
image_seek(image, 0);
|
||||||
while ( 1 ) {
|
while ( 1 ) {
|
||||||
ret = read(gd, buf, 4096);
|
size = image_read(image, buf, sizeof(buf));
|
||||||
if (ret<1)
|
if ( size == 0 )
|
||||||
break;
|
break;
|
||||||
write(fd, buf, ret);
|
WRITE_OR_FAIL(file, fd, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
image_list = image_list->next;
|
||||||
|
|
||||||
|
if ( image_list )
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
printf("\nDone\n\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fiasco_pack(int optind, char *argv[])
|
int fiasco_unpack(struct fiasco * fiasco, const char * dir) {
|
||||||
{
|
|
||||||
const char *file = argv[optind];
|
|
||||||
char *type;
|
|
||||||
int fd, ret;
|
|
||||||
|
|
||||||
fd = fiasco_new(file, file); // TODO use a format here
|
int fd = -1;
|
||||||
if (fd == -1)
|
char * name = NULL;
|
||||||
return 1;
|
char * layout_name = NULL;
|
||||||
|
struct image * image;
|
||||||
|
struct image_list * image_list;
|
||||||
|
uint32_t size;
|
||||||
|
char cwd[256];
|
||||||
|
unsigned char buf[4096];
|
||||||
|
|
||||||
|
if ( dir ) {
|
||||||
|
|
||||||
|
memset(cwd, 0, sizeof(cwd));
|
||||||
|
|
||||||
|
if ( ! getcwd(cwd, sizeof(cwd)) ) {
|
||||||
|
ERROR_INFO("Cannot store current directory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( chdir(dir) < 0 ) {
|
||||||
|
ERROR_INFO("Cannot change current directory to %s", dir);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fiasco_print_info(fiasco);
|
||||||
|
|
||||||
|
image_list = fiasco->first;
|
||||||
|
|
||||||
|
while ( image_list ) {
|
||||||
|
|
||||||
|
image = image_list->image;
|
||||||
|
|
||||||
|
name = image_name_alloc_from_values(image);
|
||||||
|
if ( ! name )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
printf("Unpacking image...\n");
|
||||||
|
image_print_info(image);
|
||||||
|
|
||||||
|
if ( image->layout ) {
|
||||||
|
|
||||||
|
layout_name = calloc(1, strlen(name) + strlen(".layout") + 1);
|
||||||
|
if ( ! layout_name )
|
||||||
|
ALLOC_ERROR_RETURN(-1);
|
||||||
|
|
||||||
|
sprintf(layout_name, "%s.layout", name);
|
||||||
|
|
||||||
|
printf(" Layout file: %s\n", layout_name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(" Output file: %s\n", name);
|
||||||
|
|
||||||
|
if ( ! simulate ) {
|
||||||
|
fd = open(name, O_RDWR|O_CREAT|O_TRUNC, 0644);
|
||||||
|
if ( fd < 0 ) {
|
||||||
|
ERROR_INFO("Cannot create output file %s", name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(name);
|
||||||
|
|
||||||
|
image_seek(image, 0);
|
||||||
|
while ( 1 ) {
|
||||||
|
size = image_read(image, buf, sizeof(buf));
|
||||||
|
if ( size == 0 )
|
||||||
|
break;
|
||||||
|
WRITE_OR_FAIL(name, fd, buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
printf("Package: %s\n", file);
|
|
||||||
while((file=argv[++optind])) {
|
|
||||||
type = (char *)fpid_file(file);
|
|
||||||
printf("Adding %s: %s..\n", type, file);
|
|
||||||
ret = fiasco_add(fd, type, file, NULL);
|
|
||||||
if (ret<0) {
|
|
||||||
printf("Error\n");
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return 1;
|
|
||||||
|
if ( image->layout ) {
|
||||||
|
|
||||||
|
if ( ! simulate ) {
|
||||||
|
fd = open(layout_name, O_RDWR|O_CREAT|O_TRUNC, 0644);
|
||||||
|
if ( fd < 0 ) {
|
||||||
|
ERROR_INFO("Cannot create layout file %s", layout_name);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fiasco_add_eof(fd);
|
|
||||||
printf("Done!\n");
|
free(layout_name);
|
||||||
|
|
||||||
|
WRITE_OR_FAIL(layout_name, fd, image->layout, (int)strlen(image->layout));
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
image_list = image_list->next;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( dir ) {
|
||||||
|
if ( chdir(cwd) < 0 ) {
|
||||||
|
ERROR_INFO("Cannot change current directory back to %s", cwd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nDone\n\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* local code */
|
void fiasco_print_info(struct fiasco * fiasco) {
|
||||||
#if 0
|
|
||||||
void my_callback(int fd, struct header_t *header)
|
if ( fiasco->orig_filename )
|
||||||
{
|
printf("File: %s\n", fiasco->orig_filename);
|
||||||
fiasco_data_read(header);
|
|
||||||
//read(fd, buf, header->size);
|
if ( fiasco->name[0] )
|
||||||
printf("Dumping %s\n", header->name);
|
printf(" Fiasco Name: %s\n", fiasco->name);
|
||||||
printf("DATA: %02x\n", header->data[0]);
|
|
||||||
fiasco_data_free(header);
|
if ( fiasco->swver[0] )
|
||||||
|
printf(" Fiasco Software release version: %s\n", fiasco->swver);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
if (argc!=2) {
|
|
||||||
printf("Usage: unfiasco [file]\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
fd = fiasco_new("myfiasco", "pancake-edition");
|
|
||||||
fiasco_add(fd, "kernel", "zImage", "2.6.22");
|
|
||||||
close(fd);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// fiasco_callback = &my_callback;
|
|
||||||
|
|
||||||
return openfiasco(argv[1]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2007-2011 pancake <pancake@youterm.com>
|
||||||
|
Copyright (C) 2011-2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FIASCO_H
|
||||||
|
#define FIASCO_H
|
||||||
|
|
||||||
|
#include "image.h"
|
||||||
|
|
||||||
|
struct fiasco {
|
||||||
|
char name[257];
|
||||||
|
char swver[257];
|
||||||
|
int fd;
|
||||||
|
char * orig_filename;
|
||||||
|
struct image_list * first;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fiasco * fiasco_alloc_empty(void);
|
||||||
|
struct fiasco * fiasco_alloc_from_file(const char * file);
|
||||||
|
void fiasco_free(struct fiasco * fiasco);
|
||||||
|
void fiasco_add_image(struct fiasco * fiasco, struct image * image);
|
||||||
|
int fiasco_write_to_file(struct fiasco * fiasco, const char * file);
|
||||||
|
int fiasco_unpack(struct fiasco * fiasco, const char * dir);
|
||||||
|
void fiasco_print_info(struct fiasco * fiasco);
|
||||||
|
|
||||||
|
#endif
|
||||||
-215
@@ -1,215 +0,0 @@
|
|||||||
/*
|
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
|
||||||
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
|
||||||
*
|
|
||||||
* 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 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if HAVE_USB
|
|
||||||
#include "main.h"
|
|
||||||
#include "hash.h"
|
|
||||||
#include "hexdump.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
void check_nolo_order_failed()
|
|
||||||
{
|
|
||||||
fprintf(stderr, "\nERROR: Provide xloader before the secondary. NOLO disagrees anything else.\n");
|
|
||||||
fprintf(stderr, "Use: -p xloader.bin -p secondary.bin\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void query_error_message()
|
|
||||||
{
|
|
||||||
/* query error message */
|
|
||||||
int len = 0;
|
|
||||||
char nolomsg[2048];
|
|
||||||
memset(nolomsg, '\0', 2048);
|
|
||||||
usb_control_msg(dev, 192, 5, 0, 0, nolomsg, 2048, 2000);
|
|
||||||
nolomsg[2047] = '\0';
|
|
||||||
printf("\nNOLO says:\n");
|
|
||||||
if (nolomsg[0] == '\0') {
|
|
||||||
printf(" (.. silence ..)\n");
|
|
||||||
} else {
|
|
||||||
dump_bytes((unsigned char *)nolomsg, 128);
|
|
||||||
do {
|
|
||||||
printf(" - %s\n", nolomsg+len);
|
|
||||||
len+=strlen(nolomsg+len)+1;
|
|
||||||
} while(nolomsg[len]!='\0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void check_nolo_order()
|
|
||||||
{
|
|
||||||
int i, xlo = 0;
|
|
||||||
|
|
||||||
for(i=0;i<pcs_n;i++) {
|
|
||||||
if (!strcmp(pcs[i].type, "xloader")) {
|
|
||||||
if (!xlo && ++i<pcs_n) {
|
|
||||||
printf("CHK%s\n", pcs[i].type);
|
|
||||||
xlo++;
|
|
||||||
if (!strcmp(pcs[i].type, "secondary")) {
|
|
||||||
xlo = 0x11;
|
|
||||||
break;
|
|
||||||
} else check_nolo_order_failed();
|
|
||||||
} check_nolo_order_failed();
|
|
||||||
} else
|
|
||||||
if (!strcmp(pcs[i].type, "secondary"))
|
|
||||||
check_nolo_order_failed();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xlo && xlo != 0x11)
|
|
||||||
check_nolo_order_failed();
|
|
||||||
}
|
|
||||||
|
|
||||||
void flash_image(const char *filename, const char *piece, const char *version)
|
|
||||||
{
|
|
||||||
FILE *fd;
|
|
||||||
int vlen = 0;
|
|
||||||
int request;
|
|
||||||
/*/ n800 flash queries have a variable size */
|
|
||||||
unsigned char fquery[256]; /* flash query */
|
|
||||||
unsigned long long size, off;
|
|
||||||
unsigned char bsize[4], tmp;
|
|
||||||
unsigned char nolofiller[128];
|
|
||||||
ushort hash = do_hash_file(filename);
|
|
||||||
|
|
||||||
if (piece == NULL) {
|
|
||||||
//exit(1);
|
|
||||||
piece = fpid_file(filename);
|
|
||||||
if (piece == NULL) {
|
|
||||||
printf("Unknown piece type\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
printf("Piece type: %s\n", piece);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (piece != NULL) {
|
|
||||||
if (!strcmp(piece, "fiasco")) {
|
|
||||||
fiasco_flash(filename);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version)
|
|
||||||
vlen = strlen(version)+1;
|
|
||||||
|
|
||||||
fd = fopen(filename, "rb");
|
|
||||||
if (fd == NULL) {
|
|
||||||
printf("Cannot open file\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
/* cook flash query */
|
|
||||||
memset(fquery, '\x00', 27); // reset buffer
|
|
||||||
memcpy(fquery, "\x2e\x19\x01\x01", 4); // header
|
|
||||||
//memcpy(fquery+5, "\xbf\x6b", 2); // some magic (modified crc16???)
|
|
||||||
memcpy(fquery+5, &hash, 2);
|
|
||||||
tmp = fquery[5]; fquery[5] = fquery[6]; fquery[6] = tmp;
|
|
||||||
memcpy(fquery+7, piece, strlen(piece)); // XXX ??!??
|
|
||||||
|
|
||||||
printf("| hash: 0x%hhx%hhx ", fquery[5], fquery[6]);
|
|
||||||
size = get_file_size(filename);
|
|
||||||
bsize[0] = (size & 0xff000000) >> 24;
|
|
||||||
bsize[1] = (size & 0x00ff0000) >> 16;
|
|
||||||
bsize[2] = (size & 0x0000ff00) >> 8;
|
|
||||||
bsize[3] = (size & 0x000000ff);
|
|
||||||
printf("size: %lld (%02x %02x %02x %02x)\n",
|
|
||||||
size, bsize[0], bsize[1], bsize[2], bsize[3]);
|
|
||||||
memcpy(fquery+0x13, &bsize, 4);
|
|
||||||
if (vlen) memcpy(fquery+27, version, vlen);
|
|
||||||
|
|
||||||
if (!strcmp(piece, "rootfs"))
|
|
||||||
request = 85;
|
|
||||||
else request = 68;
|
|
||||||
|
|
||||||
//dump_bytes(fquery, 27+vlen);
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, request, 0, 0, (char *)fquery, 27+vlen, 2000) <0) {
|
|
||||||
query_error_message();
|
|
||||||
perror("flash_image.header");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*/ cook and bulk nollo filler */
|
|
||||||
memset(&nolofiller, '\xff', 128);
|
|
||||||
memcpy(nolofiller+0x00, "NOLO filler", 11);
|
|
||||||
memcpy(nolofiller+0x40, "NOLO filler", 11);
|
|
||||||
usb_bulk_write(dev, 2, (char *)nolofiller, 128, 5000);
|
|
||||||
usb_bulk_write(dev, 2, (char *)nolofiller, 0, 5000);
|
|
||||||
|
|
||||||
/*/ bulk write image here */
|
|
||||||
printf("[=] Bulkwriting the %s piece...\n", piece);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
for(off = 0; off<size; off += BSIZE) {
|
|
||||||
char buf[BSIZE];
|
|
||||||
int bread, bsize = size-off;
|
|
||||||
if (bsize>BSIZE) bsize = BSIZE;
|
|
||||||
bread = fread(buf, bsize, 1, fd);
|
|
||||||
if (bread != 1)
|
|
||||||
printf("WARNING: Oops wrong read %d vs %d \n", bread, bsize);
|
|
||||||
bread = usb_bulk_write(dev, 2, buf, bsize, 5000);
|
|
||||||
if (bread == 64) {
|
|
||||||
query_error_message();
|
|
||||||
fclose(fd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
progressbar(off, size);
|
|
||||||
if (bread<0) {
|
|
||||||
printf("\n");
|
|
||||||
perror(" -ee- ");
|
|
||||||
fclose(fd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
fclose(fd);
|
|
||||||
/*/ EOF */
|
|
||||||
usb_bulk_write(dev, 2, (char *)nolofiller, 0, 1000);
|
|
||||||
progressbar(1, 1);
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
// index = 4????
|
|
||||||
if (!strcmp(piece, "rootfs")) {
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, 82, 0, 0, (char *)fquery, 0, 30000)<0) {
|
|
||||||
fprintf(stderr, "Oops. Invalid checksum?\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int t = 0;
|
|
||||||
if (!strcmp(piece, "secondary"))
|
|
||||||
t = 1;
|
|
||||||
else
|
|
||||||
if (!strcmp(piece, "kernel"))
|
|
||||||
t = 3;
|
|
||||||
else
|
|
||||||
if (!strcmp(piece, "initfs"))
|
|
||||||
t = 4;
|
|
||||||
if (!strcmp(piece, "xloader"))
|
|
||||||
printf("xloader flashed not commiting until secondary arrives...\n");
|
|
||||||
else
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, 80, 0, t, (char *)fquery, 0, 10000)<0) {
|
|
||||||
fprintf(stderr, "Oops. Invalid checksum?\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// unknown query !! :""
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, 67, 0, 0, (char *)fquery, 0, 2000)<0) {
|
|
||||||
fprintf(stderr, "Oops, the flash was denied or so :/\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
printf("Flash done succesfully.\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
-102
@@ -1,102 +0,0 @@
|
|||||||
/*
|
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
|
||||||
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
|
||||||
*
|
|
||||||
* 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 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
/* global structs */
|
|
||||||
char *pieces[] = {
|
|
||||||
"xloader", // xloader.bin
|
|
||||||
"2nd", // 2nd
|
|
||||||
"secondary", // secondary.bin
|
|
||||||
"kernel", // zImage
|
|
||||||
"initfs", // jffs'd initfs
|
|
||||||
"rootfs", // 80mB of blob
|
|
||||||
"omap-nand", // 8kB of food for the nand
|
|
||||||
"fiasco", // FIASCO IMAGE
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
long fpid_size(const char *filename)
|
|
||||||
{
|
|
||||||
long sz;
|
|
||||||
FILE *fd = fopen(filename, "r");
|
|
||||||
fseek(fd, 0, SEEK_END);
|
|
||||||
sz = ftell(fd);
|
|
||||||
fclose(fd);
|
|
||||||
return sz;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *fpid_file(const char *filename)
|
|
||||||
{
|
|
||||||
FILE *fd;
|
|
||||||
char buf[512];
|
|
||||||
unsigned char *b = (unsigned char *)&buf;
|
|
||||||
long size;
|
|
||||||
|
|
||||||
// 2nd : +0x34 = 2NDAPE
|
|
||||||
// secondary: +0x04 = NOLOScnd
|
|
||||||
// x-loader : +0x14 = X-LOADER
|
|
||||||
// xloader8 : +0x0c = NOLOXldr
|
|
||||||
// kernel : +0x00 = 0000 a0e1 0000 a0e1
|
|
||||||
// initfs : <2M...be sure with 3M 0x300000
|
|
||||||
|
|
||||||
fd = fopen(filename, "r");
|
|
||||||
if (fd == NULL) {
|
|
||||||
printf("Cannot open file '%s'\n", filename);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
fread(buf, 512, 1, fd);
|
|
||||||
fseek(fd, 0, SEEK_END);
|
|
||||||
size = ftell(fd);
|
|
||||||
fclose(fd);
|
|
||||||
|
|
||||||
if (!memcmp(b, "\xb4", 1))
|
|
||||||
return pieces[PIECE_FIASCO];
|
|
||||||
else
|
|
||||||
if (!memcmp(b+0x34, "2NDAPE", 6))
|
|
||||||
return pieces[PIECE_2ND];
|
|
||||||
else
|
|
||||||
if (!memcmp(b+0x04, "NOLOScnd", 8))
|
|
||||||
return pieces[PIECE_SECONDARY];
|
|
||||||
else
|
|
||||||
if (!memcmp(b+0x14, "X-LOADER", 8))
|
|
||||||
return pieces[PIECE_XLOADER];
|
|
||||||
else
|
|
||||||
if (!memcmp(b+0x0c, "NOLOXldr", 8))
|
|
||||||
return pieces[PIECE_XLOADER];
|
|
||||||
else
|
|
||||||
if (!memcmp(b+4,"NOLOXldr",8))
|
|
||||||
// TODO: this is xloader800, not valid on 770?
|
|
||||||
return pieces[PIECE_2ND];
|
|
||||||
else
|
|
||||||
if (!memcmp(b+0x00, "\x00\x00\xa0\xe1\x00\x00\xa0\xe1", 8)
|
|
||||||
|| (!memcmp(b, "\x21\x01\x01", 3)))
|
|
||||||
return pieces[PIECE_KERNEL];
|
|
||||||
else
|
|
||||||
// JFFS2 MAGIC
|
|
||||||
if (!memcmp(b+0x00, "\x85\x19", 2)) { //\x01\xe0", 4)) {
|
|
||||||
/*/ is jffs2 */
|
|
||||||
if (size < 0x300000)
|
|
||||||
return pieces[PIECE_INITFS];
|
|
||||||
return pieces[PIECE_ROOTFS];
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
#ifndef GLOBAL_H
|
||||||
|
#define GLOBAL_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
extern int simulate;
|
||||||
|
extern int noverify;
|
||||||
|
extern int verbose;
|
||||||
|
|
||||||
|
#define VERBOSE(...) do { if ( verbose ) { fprintf(stderr, __VA_ARGS__); } } while (0)
|
||||||
|
#define WARNING(...) do { fprintf(stderr, "Warning: "); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); } while (0)
|
||||||
|
#define ERROR_INFO_STR(str, ...) do { if ( str[0] ) fprintf(stderr, "Error: %s: ", str); else fprintf(stderr, "Error: "); fprintf(stderr, __VA_ARGS__); if ( errno ) fprintf(stderr, ": %s\n", strerror(errno)); else fprintf(stderr, "\n"); } while (0)
|
||||||
|
#define ERROR_STR(str, ...) do { errno = 0; ERROR_INFO_STR(str, __VA_ARGS__); } while (0)
|
||||||
|
#define ERROR_INFO(...) do { ERROR_INFO_STR("", __VA_ARGS__); } while (0)
|
||||||
|
#define ERROR(...) do { ERROR_STR("", __VA_ARGS__); } while (0)
|
||||||
|
#define ERROR_RETURN(str, ...) do { ERROR("%s", str); return __VA_ARGS__; } while (0)
|
||||||
|
|
||||||
|
#define ALLOC_ERROR() do { ERROR("Cannot allocate memory"); } while (0)
|
||||||
|
#define ALLOC_ERROR_RETURN(...) do { ALLOC_ERROR(); return __VA_ARGS__; } while (0)
|
||||||
|
|
||||||
|
#endif
|
||||||
+10
-2
@@ -1,8 +1,13 @@
|
|||||||
include ../../config.mk
|
include ../../config.mk
|
||||||
|
|
||||||
ifeq (${HAVE_GUI},1)
|
ifeq (${HAVE_GUI},1)
|
||||||
all:
|
all: goxf
|
||||||
gtkamlc --save-temps --Xcc=-I../squeue ../squeue/squeue.c ../fpid.c ../squeue/squeue.vapi gui.gtkaml extras.vapi --pkg gtk+-2.0 -o goxf
|
|
||||||
|
goxf:
|
||||||
|
${CC} -I../squeue ../squeue/squeue.c ../fpid.c gui.c `pkg-config --cflags --libs gtk+-2.0` -o goxf
|
||||||
|
|
||||||
|
c:
|
||||||
|
gtkamlc --save-temps --Xcc=-I../squeue ../squeue/squeue.c ../fpid.c ../squeue/squeue.vapi gui.gtkon extras.vapi --pkg gtk+-2.0 -o goxf
|
||||||
|
|
||||||
test:
|
test:
|
||||||
valac --save-temps --Xcc=-I.. squeue.vapi test.vala ../squeue.c -o v
|
valac --save-temps --Xcc=-I.. squeue.vapi test.vala ../squeue.c -o v
|
||||||
@@ -11,3 +16,6 @@ else
|
|||||||
all:
|
all:
|
||||||
@true
|
@true
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f goxf *.o *.c
|
||||||
+1163
File diff suppressed because it is too large.
Load diff
@@ -78,7 +78,7 @@
|
|||||||
<AboutDialog class:standalone="true" class:private="aboutdialog1" delete-event="{aboutdialog1.hide_on_delete}"
|
<AboutDialog class:standalone="true" class:private="aboutdialog1" delete-event="{aboutdialog1.hide_on_delete}"
|
||||||
border-width="5" title="About 0xFFFF gui" resizable="false" modal="true"
|
border-width="5" title="About 0xFFFF gui" resizable="false" modal="true"
|
||||||
window-position="{WindowPosition.CENTER_ON_PARENT}" has-separator="false"
|
window-position="{WindowPosition.CENTER_ON_PARENT}" has-separator="false"
|
||||||
program-name="0xFFFF" version="0.3.9" copyright="Copyright (c) 2008 pancake"
|
program-name="0xFFFF" version="0.5" copyright="Copyright (c) 2007-2009 pancake"
|
||||||
comments="The Free Nokia Internet Tablet flasher"
|
comments="The Free Nokia Internet Tablet flasher"
|
||||||
website="http://www.nopcode.org/0xFFFF/"
|
website="http://www.nopcode.org/0xFFFF/"
|
||||||
authors='{new string[] {"pancake (pancake@youterm.com)", null}}'>
|
authors='{new string[] {"pancake (pancake@youterm.com)", null}}'>
|
||||||
@@ -143,7 +143,7 @@ public bool loadFile( string filename )
|
|||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
try {
|
try {
|
||||||
string contents; int length;
|
string contents; size_t length;
|
||||||
FileUtils.get_contents (filename, out contents, out length);
|
FileUtils.get_contents (filename, out contents, out length);
|
||||||
//textview1.buffer.set_text (contents, length);
|
//textview1.buffer.set_text (contents, length);
|
||||||
} catch(Error e) {
|
} catch(Error e) {
|
||||||
@@ -0,0 +1,321 @@
|
|||||||
|
/*
|
||||||
|
| Frontend for the 0xFFFF flasher in gtkaml
|
||||||
|
| author: pancake <youterm.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
Window using="Gtk" gtkon:version=0.4
|
||||||
|
using:Extras="Extras"
|
||||||
|
using:SQueues="SQueues"
|
||||||
|
name="MainWindow"
|
||||||
|
title="0xFFFF GUI"
|
||||||
|
{
|
||||||
|
/* delete-event="{OnWindow1DeleteEvent}" */
|
||||||
|
VBox {
|
||||||
|
MenuBar !expand {
|
||||||
|
MenuItem label="_File" with-mnemonic {
|
||||||
|
submenu {
|
||||||
|
Menu {
|
||||||
|
ImageMenuItem stock-id="gtk-new" activate=OnFileNewEvent;
|
||||||
|
ImageMenuItem stock-id="gtk-open" activate=OnFileOpenEvent;
|
||||||
|
SeparatorMenuItem;
|
||||||
|
ImageMenuItem stock-id="gtk-quit" activate=OnQuitEvent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MenuItem label="_Target" with-mnemonic {
|
||||||
|
submenu {
|
||||||
|
Menu {
|
||||||
|
ImageMenuItem stock-id="gtk-connect" activate=OnConnect;
|
||||||
|
ImageMenuItem stock-id="gtk-stop" activate=OnStop;
|
||||||
|
ImageMenuItem stock-id="gtk-info" activate=OnGetInformation;
|
||||||
|
ImageMenuItem label="Reset" activate=OnReset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MenuItem label="_Help" with-mnemonic {
|
||||||
|
submenu {
|
||||||
|
Menu {
|
||||||
|
ImageMenuItem stock-id="gtk-about" activate=OnMenuHelpAboutActivatedEvent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HBox border-width="5" {
|
||||||
|
VBox border-width="3" spacing="3" {
|
||||||
|
ScrolledWindow can-focus="true" hscrollbar-policy="{PolicyType.AUTOMATIC}" vscrollbar-policy="{PolicyType.AUTOMATIC}" {
|
||||||
|
TreeView $.tv;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
VBox !expand border-width="3" spacing="3" {
|
||||||
|
Button label="gtk-connect" use-stock !expand clicked=OnConnect;
|
||||||
|
Button label="gtk-stop" use-stock !expand clicked=OnStop;
|
||||||
|
Button label="gtk-info" use-stock !expand clicked=OnGetInformation;
|
||||||
|
Label label="";
|
||||||
|
/*
|
||||||
|
<!-- <Button label="Options" use-stock="false" expand="false"/>
|
||||||
|
<Button label="Fiasco!" use-stock="false" expand="false"/>
|
||||||
|
<Button label="Unpack!" use-stock="false" expand/> -->
|
||||||
|
*/
|
||||||
|
Button label="gtk-add" use-stock="true" !expand clicked=OnFileOpenEvent;
|
||||||
|
Button label="gtk-remove" use-stock="true" expand="false" clicked=list_del;
|
||||||
|
Label label="";
|
||||||
|
Button label="gtk-media-record" use-stock="true" expand="false" clicked=OnFileFlashEvent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ProgressBar $.pb !expand;
|
||||||
|
|
||||||
|
//<!-- <Statusbar expand="false"/> -->
|
||||||
|
}
|
||||||
|
AboutDialog gtkaml:standalone $.aboutdialog1 delete-event=aboutdialog1.hide_on_delete
|
||||||
|
border-width="5" title="About 0xFFFF gui" resizable="false" modal="true"
|
||||||
|
window-position="{WindowPosition.CENTER_ON_PARENT}" has-separator="false"
|
||||||
|
program-name="0xFFFF" version="0.5" copyright="Copyright (c) 2007-2009 pancake"
|
||||||
|
comments="The Free Nokia Internet Tablet flasher"
|
||||||
|
website="http://www.nopcode.org/0xFFFF/"
|
||||||
|
authors='{new string[] {"pancake (pancake@youterm.com)", null}}';
|
||||||
|
|
||||||
|
-{
|
||||||
|
|
||||||
|
|
||||||
|
private void doCloseApplication () {
|
||||||
|
Gtk.main_quit ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnReset() {
|
||||||
|
q->push("reset:device", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFileFlashEvent() {
|
||||||
|
ListStore ls = (ListStore)tv.get_model();
|
||||||
|
weak string str;
|
||||||
|
TreeIter iter;
|
||||||
|
|
||||||
|
int n = ls.iter_n_children(null);
|
||||||
|
if (n >0) {
|
||||||
|
if (showYesNo("Do you want to flash these files?")) {
|
||||||
|
ls.get_iter_first(out iter);
|
||||||
|
do {
|
||||||
|
ls.get(iter, 2, out str, -1);
|
||||||
|
//stdout.printf("polla:%s\n", str);
|
||||||
|
q->push2("flash", str, 1);
|
||||||
|
} while(ls.iter_next(ref iter));
|
||||||
|
}
|
||||||
|
} else showMessage("No files selected", MessageType.ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFileOpenEvent () {
|
||||||
|
FileChooserDialog fc = new FileChooserDialog("Select file to open",
|
||||||
|
this, FileChooserAction.OPEN,
|
||||||
|
"gtk-cancel", ResponseType.CANCEL,
|
||||||
|
"gtk-open", ResponseType.ACCEPT);
|
||||||
|
int resp = fc.run ();
|
||||||
|
fc.hide ();
|
||||||
|
if (resp == ResponseType.ACCEPT) {
|
||||||
|
string file = fc.get_filename();
|
||||||
|
string *type = External.fpid_file(file);
|
||||||
|
string size = "%ld".printf(External.fpid_size(file));
|
||||||
|
if (type == null)
|
||||||
|
showMessage("Invalid file type", MessageType.ERROR);
|
||||||
|
else add_file(type, size, file);
|
||||||
|
}
|
||||||
|
fc.destroy ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool loadFile( string filename ) {
|
||||||
|
int err = 0;
|
||||||
|
try {
|
||||||
|
string contents; size_t length;
|
||||||
|
FileUtils.get_contents (filename, out contents, out length);
|
||||||
|
//textview1.buffer.set_text (contents, length);
|
||||||
|
} catch(Error e) {
|
||||||
|
showError ("Unexpected error while loading the file, please contact the author with the following information:\n\n" + e.message);
|
||||||
|
err++;
|
||||||
|
}
|
||||||
|
return err == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool showYesNo(string s) {
|
||||||
|
MessageDialog md = new MessageDialog (this,
|
||||||
|
DialogFlags.DESTROY_WITH_PARENT,
|
||||||
|
MessageType.QUESTION, ButtonsType.YES_NO, s);
|
||||||
|
int ret = md.run ();
|
||||||
|
md.destroy ();
|
||||||
|
return ret==ResponseType.YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showMessage(string s, MessageType mt) {
|
||||||
|
MessageDialog md = new MessageDialog (this,
|
||||||
|
DialogFlags.DESTROY_WITH_PARENT,
|
||||||
|
mt, ButtonsType.CLOSE, s);
|
||||||
|
md.run ();
|
||||||
|
md.destroy ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMenuHelpAboutActivatedEvent () {
|
||||||
|
aboutdialog1.transient_for = this;
|
||||||
|
aboutdialog1.response.connect ((x)=> { aboutdialog1.hide (); });
|
||||||
|
aboutdialog1.run ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showError (string s) {
|
||||||
|
MessageDialog md = new MessageDialog (this,
|
||||||
|
DialogFlags.DESTROY_WITH_PARENT,
|
||||||
|
MessageType.ERROR,
|
||||||
|
ButtonsType.CLOSE,
|
||||||
|
s);
|
||||||
|
md.run ();
|
||||||
|
md.destroy ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFileNewEvent () {
|
||||||
|
list_clear();
|
||||||
|
// TODO: clear file list
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnQuitEvent () {
|
||||||
|
doCloseApplication();
|
||||||
|
// TODO: send message to gracefully kill 0xFFFF
|
||||||
|
// TODO: handle ^C when flashing
|
||||||
|
}
|
||||||
|
|
||||||
|
public void list_clear() {
|
||||||
|
((ListStore)tv.model).clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void list_del() {
|
||||||
|
TreeIter iter;
|
||||||
|
TreeModel model;
|
||||||
|
|
||||||
|
TreeSelection sel = tv.get_selection();
|
||||||
|
|
||||||
|
if (sel.count_selected_rows() == 1) {
|
||||||
|
sel.get_selected(out model, out iter);
|
||||||
|
((ListStore)tv.model).remove(iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add_file(string type, string size, string file) {
|
||||||
|
ListStore listmodel = (ListStore)tv.get_model();
|
||||||
|
Gtk.TreeIter iter;
|
||||||
|
listmodel.append (out iter);
|
||||||
|
listmodel.set (iter, 0, type, 1, size, 2, file, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setup_treeview (Gtk.TreeView view) {
|
||||||
|
/* use liststore to hold accountname, accounttype, balance and color attribute */
|
||||||
|
/* for more info how gtkTreeview works take a look in the GTK API */
|
||||||
|
|
||||||
|
var listmodel = new Gtk.ListStore(4, typeof(string), typeof(string), typeof(string), typeof(string));
|
||||||
|
view.set_model(listmodel);
|
||||||
|
|
||||||
|
view.insert_column_with_attributes (-1, "Type", new Gtk.CellRendererText(), "text", 0, null);
|
||||||
|
view.insert_column_with_attributes (-1, "Size", new Gtk.CellRendererText(), "text", 1, null);
|
||||||
|
|
||||||
|
var cell = new Gtk.CellRendererText ();
|
||||||
|
cell.set ("foreground_set", true, null);
|
||||||
|
view.insert_column_with_attributes (-1, "Name", cell, "text", 2, "foreground", 3, null);
|
||||||
|
|
||||||
|
// Gtk.TreeIter iter;
|
||||||
|
// listmodel.append (out iter);
|
||||||
|
// listmodel.set (iter, 0, "initfs", 1, "3M", 2, "initfs.jffs", -1);
|
||||||
|
//listmodel.set (iter, 0, "initfs", 1, "3M", 2, "initfs.jffs", 3, "green", -1);
|
||||||
|
|
||||||
|
// listmodel.append (out iter);
|
||||||
|
// listmodel.set (iter, 0, "rootfs", 1, "52M", 2, "rootfs.jffs", -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool readFunc() {
|
||||||
|
weak string msg = p->get(0);
|
||||||
|
|
||||||
|
if (msg != null && msg[0]!='\0') {
|
||||||
|
stdout.printf("[<] msg received: %s\n", msg);
|
||||||
|
string[] foo = msg.split(":",2);
|
||||||
|
if (foo[1] != null) {
|
||||||
|
switch(foo[0]) {
|
||||||
|
case "bar":
|
||||||
|
viewer.pb.fraction = foo[1].to_int() / 100;
|
||||||
|
viewer.pb.text = foo[1]+"%";
|
||||||
|
break;
|
||||||
|
case "error":
|
||||||
|
viewer.showMessage(foo[1], MessageType.ERROR);
|
||||||
|
break;
|
||||||
|
case "info":
|
||||||
|
viewer.showMessage(foo[1], MessageType.INFO);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
stderr.printf("[E] Unknown message type\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//viewer.showMessage(msg, MessageType.INFO);
|
||||||
|
}
|
||||||
|
p->pop();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SQueue *q = null;
|
||||||
|
static SQueue *p = null;
|
||||||
|
|
||||||
|
private void OnGetInformation() {
|
||||||
|
msg("info:device");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnConnect() {
|
||||||
|
//msg("connect:device");
|
||||||
|
OnStop();
|
||||||
|
External.system("sudo 0xFFFF -Q &");
|
||||||
|
p->close();
|
||||||
|
q->close();
|
||||||
|
p = q = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnStop() {
|
||||||
|
External.system("sudo pkill 0xFFFF");
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool chk_queues() {
|
||||||
|
if (p == null)
|
||||||
|
p = SQueue.open("/tmp/0xFFFF.1", SQueueMode.OPEN);
|
||||||
|
if (q == null)
|
||||||
|
q = SQueue.open("/tmp/0xFFFF.2", SQueueMode.OPEN);
|
||||||
|
if (p == null || q == null) {
|
||||||
|
showMessage("Cannot connect to queues", MessageType.ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void msg(string str) {
|
||||||
|
if (!chk_queues())
|
||||||
|
return;
|
||||||
|
if (q->push(str, 0)<1) {
|
||||||
|
stderr.printf("Oops on push\n");
|
||||||
|
q->free();
|
||||||
|
q = null;
|
||||||
|
p->free();
|
||||||
|
p = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static MainWindow viewer;
|
||||||
|
|
||||||
|
static int main (string[] args) {
|
||||||
|
Gtk.init (ref args);
|
||||||
|
viewer = new MainWindow();
|
||||||
|
if (args.length > 1)
|
||||||
|
viewer.loadFile (args[1]);
|
||||||
|
viewer.resize(600,400);
|
||||||
|
viewer.set_position(WindowPosition.CENTER);
|
||||||
|
viewer.delete_event.connect ((x,y) => { Gtk.main_quit(); return false; });
|
||||||
|
setup_treeview(viewer.tv);
|
||||||
|
viewer.show_all ();
|
||||||
|
// viewer.showMessage("This software is beta and does not guaranties correct functionality", MessageType.WARNING);
|
||||||
|
Timeout.add(200, (SourceFunc)(readFunc));
|
||||||
|
Gtk.main ();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}-
|
||||||
|
}
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
#ifndef _INCLUDE_HASH_H_
|
|
||||||
#define _INCLUDE_HASH_H_
|
|
||||||
|
|
||||||
#define usho unsigned short
|
|
||||||
#define BSIZE 0x20000
|
|
||||||
|
|
||||||
usho do_hash(usho *b, int len);
|
|
||||||
usho do_hash_file(const char *filename);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* radare - advanced commandline hexadecimal editor
|
|
||||||
* Copyright (C) 2006,2007 pancake <pancake@youterm.com>
|
|
||||||
*
|
|
||||||
* 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 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "hexdump.h"
|
|
||||||
|
|
||||||
char getprintablechar(char a)
|
|
||||||
{
|
|
||||||
if (a>=' '&&a<='~')
|
|
||||||
return a;
|
|
||||||
return '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
int is_printable (int c)
|
|
||||||
{
|
|
||||||
if (c<' '||c>'~') return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Helper function
|
|
||||||
*/
|
|
||||||
void dump_bytes(unsigned char *buf, int len)
|
|
||||||
{
|
|
||||||
int i,j,seek = 0;
|
|
||||||
int inc = 16;
|
|
||||||
|
|
||||||
for(i=0; i<len; i+=inc) {
|
|
||||||
fprintf(stderr, "0x%08x | ", seek+i);
|
|
||||||
for(j=i;j<i+inc;j++) {
|
|
||||||
if (j>=len) {
|
|
||||||
fprintf(stderr, " ");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
fprintf(stderr, "%02x ", buf[j]);
|
|
||||||
}
|
|
||||||
fprintf(stderr, " ");
|
|
||||||
for(j=i; j<i+inc; j++) {
|
|
||||||
if (j >= len)
|
|
||||||
fprintf(stderr, " ");
|
|
||||||
else
|
|
||||||
if ( is_printable(buf[j]) )
|
|
||||||
fprintf(stderr, "%c", buf[j]);
|
|
||||||
else fprintf(stderr, ".");
|
|
||||||
}
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
}
|
|
||||||
fflush(stderr);
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
char getprintablechar(char a);
|
|
||||||
int is_printable (int c);
|
|
||||||
void dump_bytes(unsigned char *buf, int len);
|
|
||||||
+608
@@ -0,0 +1,608 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
#include "device.h"
|
||||||
|
#include "image.h"
|
||||||
|
|
||||||
|
#define IMAGE_STORE_CUR(image) do { if ( image->is_shared_fd ) { image->cur = lseek(image->fd, 0, SEEK_CUR) - image->offset; if ( image->cur > image->size ) image->cur = image->size; } } while (0)
|
||||||
|
#define IMAGE_RESTORE_CUR(image) do { if ( image->is_shared_fd ) { if ( image->cur <= image->size ) lseek(image->fd, image->offset + image->cur, SEEK_SET); else lseek(image->fd, image->offset + image->size, SEEK_SET); } } while (0)
|
||||||
|
|
||||||
|
/* format: type-device:hwrevs_version */
|
||||||
|
static void image_missing_values_from_name(struct image * image, const char * name) {
|
||||||
|
|
||||||
|
char * str;
|
||||||
|
char * ptr;
|
||||||
|
char * ptr2;
|
||||||
|
char * type = NULL;
|
||||||
|
char * device = NULL;
|
||||||
|
char * hwrevs = NULL;
|
||||||
|
char * version = NULL;
|
||||||
|
enum device new_device;
|
||||||
|
|
||||||
|
str = strdup(name);
|
||||||
|
if ( ! str )
|
||||||
|
return;
|
||||||
|
|
||||||
|
ptr = strchr(str, '_');
|
||||||
|
if ( ptr ) {
|
||||||
|
*ptr = 0;
|
||||||
|
++ptr;
|
||||||
|
version = strdup(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr = strchr(str, '-');
|
||||||
|
if ( ptr ) {
|
||||||
|
*ptr = 0;
|
||||||
|
++ptr;
|
||||||
|
type = strdup(str);
|
||||||
|
ptr2 = strchr(ptr, ':');
|
||||||
|
if ( ptr2 ) {
|
||||||
|
*ptr2 = 0;
|
||||||
|
++ptr2;
|
||||||
|
hwrevs = strdup(ptr2);
|
||||||
|
}
|
||||||
|
device = strdup(ptr);
|
||||||
|
} else {
|
||||||
|
type = strdup(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! image->type )
|
||||||
|
image->type = image_type_from_string(type);
|
||||||
|
free(type);
|
||||||
|
|
||||||
|
if ( ! image->devices || image->devices->device || image->devices->device == DEVICE_ANY ) {
|
||||||
|
new_device = device_from_string(device);
|
||||||
|
if ( new_device ) {
|
||||||
|
if ( ! image->devices ) image->devices = calloc(1, sizeof(struct device_list));
|
||||||
|
if ( image->devices )
|
||||||
|
image->devices->device = new_device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(device);
|
||||||
|
|
||||||
|
if ( image->devices && image->devices->device && ! image->devices->hwrevs )
|
||||||
|
image->devices->hwrevs = hwrevs_alloc_from_string(hwrevs);
|
||||||
|
else
|
||||||
|
free(hwrevs);
|
||||||
|
|
||||||
|
if ( ! image->version )
|
||||||
|
image->version = version;
|
||||||
|
else
|
||||||
|
free(version);
|
||||||
|
|
||||||
|
free(str);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* format: type-device:hwrevs_version */
|
||||||
|
char * image_name_alloc_from_values(struct image * image) {
|
||||||
|
|
||||||
|
char * name;
|
||||||
|
char * ptr;
|
||||||
|
char * hwrevs;
|
||||||
|
size_t length;
|
||||||
|
const char * type;
|
||||||
|
const char * device;
|
||||||
|
|
||||||
|
type = image_type_to_string(image->type);
|
||||||
|
|
||||||
|
if ( ! type )
|
||||||
|
type = "unknown";
|
||||||
|
|
||||||
|
if ( image->devices )
|
||||||
|
device = device_to_string(image->devices->device);
|
||||||
|
else
|
||||||
|
device = NULL;
|
||||||
|
|
||||||
|
if ( image->devices && image->devices->hwrevs )
|
||||||
|
hwrevs = hwrevs_alloc_to_string(image->devices->hwrevs);
|
||||||
|
else
|
||||||
|
hwrevs = NULL;
|
||||||
|
|
||||||
|
length = 1 + strlen(type);
|
||||||
|
|
||||||
|
if ( device )
|
||||||
|
length += 1 + strlen(device);
|
||||||
|
if ( hwrevs )
|
||||||
|
length += 1 + strlen(hwrevs);
|
||||||
|
if ( image->version )
|
||||||
|
length += 1 + strlen(image->version);
|
||||||
|
|
||||||
|
name = calloc(1, length);
|
||||||
|
if ( ! name )
|
||||||
|
ALLOC_ERROR_RETURN(NULL);
|
||||||
|
|
||||||
|
strcpy(name, type);
|
||||||
|
ptr = name + strlen(name);
|
||||||
|
|
||||||
|
if ( device )
|
||||||
|
ptr += sprintf(ptr, "-%s", device);
|
||||||
|
if ( hwrevs )
|
||||||
|
ptr += sprintf(ptr, ":%s", hwrevs);
|
||||||
|
if ( image->version )
|
||||||
|
ptr += sprintf(ptr, "_%s", image->version);
|
||||||
|
|
||||||
|
free(hwrevs);
|
||||||
|
|
||||||
|
return name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int image_append(struct image * image, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout) {
|
||||||
|
|
||||||
|
enum image_type detected_type;
|
||||||
|
|
||||||
|
image->hash = image_hash_from_data(image);
|
||||||
|
|
||||||
|
image->devices = calloc(1, sizeof(struct device_list));
|
||||||
|
if ( ! image->devices )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
image->devices->device = DEVICE_ANY;
|
||||||
|
|
||||||
|
if ( device && device[0] ) {
|
||||||
|
image->devices->device = device_from_string(device);
|
||||||
|
if ( ! noverify && image->devices->device == DEVICE_UNKNOWN ) {
|
||||||
|
ERROR("Specified Device %s is unknown", device);
|
||||||
|
image_free(image);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
detected_type = image_type_from_data(image);
|
||||||
|
image->type = detected_type;
|
||||||
|
|
||||||
|
if ( type && type[0] ) {
|
||||||
|
image->type = image_type_from_string(type);
|
||||||
|
if ( ! noverify && image->type == IMAGE_UNKNOWN ) {
|
||||||
|
ERROR("Specified Image type %s is unknown", type);
|
||||||
|
image_free(image);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if ( ! noverify && detected_type != image->type && detected_type != IMAGE_UNKNOWN ) {
|
||||||
|
ERROR("Image type mishmash (detected %s, got %s)", image_type_to_string(detected_type), type);
|
||||||
|
image_free(image);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( hwrevs && hwrevs[0] )
|
||||||
|
image->devices->hwrevs = hwrevs_alloc_from_string(hwrevs);
|
||||||
|
else
|
||||||
|
image->devices->hwrevs = NULL;
|
||||||
|
|
||||||
|
if ( version && version[0] )
|
||||||
|
image->version = strdup(version);
|
||||||
|
else
|
||||||
|
image->version = NULL;
|
||||||
|
|
||||||
|
if ( layout && layout[0] )
|
||||||
|
image->layout = strdup(layout);
|
||||||
|
else
|
||||||
|
image->layout = NULL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void image_align(struct image * image) {
|
||||||
|
|
||||||
|
size_t align = 0;
|
||||||
|
|
||||||
|
if ( image->type == IMAGE_MMC )
|
||||||
|
align = 8;
|
||||||
|
else
|
||||||
|
align = 7;
|
||||||
|
|
||||||
|
if ( align == 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( ( image->size & ( ( 1ULL << align ) - 1 ) ) == 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
align = ((image->size >> align) + 1) << align;
|
||||||
|
|
||||||
|
image->align = align - image->size;
|
||||||
|
image->size = align;
|
||||||
|
|
||||||
|
image->hash = image_hash_from_data(image);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct image * image_alloc(void) {
|
||||||
|
|
||||||
|
struct image * image = calloc(1, sizeof(struct image));
|
||||||
|
if ( ! image )
|
||||||
|
ALLOC_ERROR_RETURN(NULL);
|
||||||
|
return image;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct image * image_alloc_from_file(const char * file, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout) {
|
||||||
|
|
||||||
|
struct image * image = image_alloc();
|
||||||
|
if ( ! image )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
image->is_shared_fd = 0;
|
||||||
|
image->fd = open(file, O_RDONLY);
|
||||||
|
if ( image->fd < 0 ) {
|
||||||
|
ERROR_INFO("Cannot open image file %s", file);
|
||||||
|
free(image);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
image->size = lseek(image->fd, 0, SEEK_END);
|
||||||
|
image->offset = 0;
|
||||||
|
image->cur = 0;
|
||||||
|
image->orig_filename = strdup(file);
|
||||||
|
lseek(image->fd, 0, SEEK_SET);
|
||||||
|
|
||||||
|
if ( image_append(image, type, device, hwrevs, version, layout) < 0 )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if ( ( ! type || ! type[0] ) && ( ! device || ! device[0] ) && ( ! hwrevs || ! hwrevs[0] ) && ( ! version || ! version[0] ) )
|
||||||
|
image_missing_values_from_name(image, file);
|
||||||
|
|
||||||
|
image_align(image);
|
||||||
|
|
||||||
|
return image;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct image * image_alloc_from_shared_fd(int fd, size_t size, size_t offset, uint16_t hash, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout) {
|
||||||
|
|
||||||
|
struct image * image = image_alloc();
|
||||||
|
if ( ! image )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
image->is_shared_fd = 1;
|
||||||
|
image->fd = fd;
|
||||||
|
image->size = size;
|
||||||
|
image->offset = offset;
|
||||||
|
image->cur = 0;
|
||||||
|
|
||||||
|
if ( image_append(image, type, device, hwrevs, version, layout) < 0 )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if ( ! noverify && image->hash != hash ) {
|
||||||
|
ERROR("Image hash mishmash (counted %#04x, got %#04x)", image->hash, hash);
|
||||||
|
image_free(image);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
image_align(image);
|
||||||
|
|
||||||
|
return image;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void image_free(struct image * image) {
|
||||||
|
|
||||||
|
if ( ! image->is_shared_fd ) {
|
||||||
|
close(image->fd);
|
||||||
|
image->fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( image->devices ) {
|
||||||
|
struct device_list * next = image->devices->next;
|
||||||
|
free(image->devices->hwrevs);
|
||||||
|
free(image->devices);
|
||||||
|
image->devices = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(image->version);
|
||||||
|
free(image->layout);
|
||||||
|
free(image->orig_filename);
|
||||||
|
|
||||||
|
free(image);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void image_seek(struct image * image, size_t whence) {
|
||||||
|
|
||||||
|
if ( whence > image->size )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( whence >= image->size - image->align ) {
|
||||||
|
lseek(image->fd, image->size - image->align - 1, SEEK_SET);
|
||||||
|
image->acur = whence - ( image->size - image->align );
|
||||||
|
} else {
|
||||||
|
lseek(image->fd, image->offset + whence, SEEK_SET);
|
||||||
|
image->acur = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMAGE_STORE_CUR(image);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t image_read(struct image * image, void * buf, size_t count) {
|
||||||
|
|
||||||
|
size_t cur;
|
||||||
|
ssize_t ret;
|
||||||
|
size_t new_count = 0;
|
||||||
|
size_t ret_count = 0;
|
||||||
|
|
||||||
|
IMAGE_RESTORE_CUR(image);
|
||||||
|
|
||||||
|
if ( ! image->is_shared_fd || image->cur < image->size - image->align ) {
|
||||||
|
|
||||||
|
if ( image->is_shared_fd && image->cur + count > image->size - image->align )
|
||||||
|
new_count = image->size - image->align - image->cur;
|
||||||
|
else
|
||||||
|
new_count = count;
|
||||||
|
|
||||||
|
ret = read(image->fd, buf, new_count);
|
||||||
|
if ( ret > 0 )
|
||||||
|
ret_count += ret;
|
||||||
|
|
||||||
|
IMAGE_STORE_CUR(image);
|
||||||
|
|
||||||
|
if ( ret < 0 )
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ret_count == count )
|
||||||
|
return ret_count;
|
||||||
|
|
||||||
|
cur = lseek(image->fd, 0, SEEK_CUR) - image->offset;
|
||||||
|
|
||||||
|
if ( image->align && cur == image->size - image->align && image->acur < image->align ) {
|
||||||
|
|
||||||
|
if ( image->acur + count - ret_count > image->align )
|
||||||
|
new_count = image->align - image->acur;
|
||||||
|
else
|
||||||
|
new_count = count - ret_count;
|
||||||
|
|
||||||
|
memset((unsigned char *)buf+ret_count, 0xFF, new_count);
|
||||||
|
ret_count += new_count;
|
||||||
|
image->acur += new_count;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret_count;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void image_list_add(struct image_list ** list, struct image * image) {
|
||||||
|
|
||||||
|
struct image_list * last = calloc(1, sizeof(struct image_list));
|
||||||
|
if ( ! last )
|
||||||
|
ALLOC_ERROR_RETURN();
|
||||||
|
|
||||||
|
last->image = image;
|
||||||
|
|
||||||
|
if ( ! *list ) {
|
||||||
|
*list = last;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( (*list)->next )
|
||||||
|
list = &((*list)->next);
|
||||||
|
|
||||||
|
last->prev = *list;
|
||||||
|
(*list)->next = last;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void image_list_del(struct image_list * list) {
|
||||||
|
|
||||||
|
if ( ! list )
|
||||||
|
return;
|
||||||
|
|
||||||
|
image_list_unlink(list);
|
||||||
|
image_free(list->image);
|
||||||
|
free(list);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void image_list_unlink(struct image_list * list) {
|
||||||
|
|
||||||
|
if ( ! list )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( list->prev )
|
||||||
|
list->prev->next = list->next;
|
||||||
|
|
||||||
|
if ( list->next )
|
||||||
|
list->next->prev = list->prev;
|
||||||
|
|
||||||
|
list->prev = NULL;
|
||||||
|
list->next = NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint16_t do_hash(uint16_t * b, int len) {
|
||||||
|
|
||||||
|
uint16_t result = 0;
|
||||||
|
|
||||||
|
for ( len >>= 1; len--; b = b+1 )
|
||||||
|
result^=b[0];
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t image_hash_from_data(struct image * image) {
|
||||||
|
|
||||||
|
unsigned char buf[0x20000];
|
||||||
|
uint16_t hash = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
image_seek(image, 0);
|
||||||
|
while ( ( ret = image_read(image, &buf, sizeof(buf)) ) )
|
||||||
|
hash ^= do_hash((uint16_t *)&buf, ret);
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char * image_types[] = {
|
||||||
|
[IMAGE_XLOADER] = "xloader",
|
||||||
|
[IMAGE_2ND] = "2nd",
|
||||||
|
[IMAGE_SECONDARY] = "secondary",
|
||||||
|
[IMAGE_KERNEL] = "kernel",
|
||||||
|
[IMAGE_INITFS] = "initfs",
|
||||||
|
[IMAGE_ROOTFS] = "rootfs",
|
||||||
|
[IMAGE_MMC] = "mmc",
|
||||||
|
[IMAGE_CMT_2ND] = "cmt-2nd",
|
||||||
|
[IMAGE_CMT_ALGO] = "cmt-algo",
|
||||||
|
[IMAGE_CMT_MCUSW] = "cmt-mcusw",
|
||||||
|
};
|
||||||
|
|
||||||
|
enum image_type image_type_from_data(struct image * image) {
|
||||||
|
|
||||||
|
unsigned char buf[512];
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
image_seek(image, 0);
|
||||||
|
image_read(image, buf, sizeof(buf));
|
||||||
|
|
||||||
|
if ( memcmp(buf+52, "2NDAPE", 6) == 0 )
|
||||||
|
return IMAGE_2ND;
|
||||||
|
else if ( memcmp(buf+20, "2ND", 3) == 0 )
|
||||||
|
return IMAGE_2ND;
|
||||||
|
else if ( memcmp(buf+4, "NOLOScnd", 8) == 0 )
|
||||||
|
return IMAGE_SECONDARY;
|
||||||
|
else if ( memcmp(buf+20, "X-LOADER", 8) == 0 )
|
||||||
|
return IMAGE_XLOADER;
|
||||||
|
else if ( memcmp(buf+12, "NOLOXldr", 8) == 0 )
|
||||||
|
return IMAGE_XLOADER;
|
||||||
|
else if ( memcmp(buf+4, "NOLOXldr", 8) == 0 )
|
||||||
|
return IMAGE_2ND;
|
||||||
|
else if ( memcmp(buf+36, "\x18\x28\x6f\x01", 4) == 0 ) /* ARM Linux kernel magic number */
|
||||||
|
return IMAGE_KERNEL;
|
||||||
|
else if ( memcmp(buf, "\x14\x00\x00\xea", 4) == 0 ) /* ARM U-Boot - instruction branch +0x50 */
|
||||||
|
return IMAGE_KERNEL;
|
||||||
|
else if ( memcmp(buf, "UBI#", 4) == 0 ) /* UBI EC header */
|
||||||
|
return IMAGE_ROOTFS;
|
||||||
|
else if ( memcmp(buf+510, "\x55\xaa", 2) == 0 ) /* FAT boot sector signature */
|
||||||
|
return IMAGE_MMC;
|
||||||
|
else if ( memcmp(buf, "\xb0\x00\x01\x03\x9d\x00\x00\x00", 8) == 0 )
|
||||||
|
return IMAGE_CMT_2ND;
|
||||||
|
else if ( memcmp(buf, "\xb1\x00\x00\x00\x82\x00\x00\x00", 8) == 0 )
|
||||||
|
return IMAGE_CMT_ALGO;
|
||||||
|
else if ( memcmp(buf, "\xb2\x00\x00\x01\x44\x00\x00\x00", 8) == 0 )
|
||||||
|
return IMAGE_CMT_MCUSW;
|
||||||
|
else if ( memcmp(buf, "\x45\x3d\xcd\x28", 4) == 0 ) /* CRAMFS MAGIC */
|
||||||
|
return IMAGE_INITFS;
|
||||||
|
else if ( memcmp(buf, "\x85\x19", 2) == 0 ) { /* JFFS2 MAGIC */
|
||||||
|
if ( image->size < 0x300000 )
|
||||||
|
return IMAGE_INITFS;
|
||||||
|
else
|
||||||
|
return IMAGE_ROOTFS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return IMAGE_UNKNOWN;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
enum image_type image_type_from_string(const char * type) {
|
||||||
|
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if ( ! type )
|
||||||
|
return IMAGE_UNKNOWN;
|
||||||
|
|
||||||
|
for ( i = 0; i < sizeof(image_types)/sizeof(image_types[0]); ++i )
|
||||||
|
if ( image_types[i] && strcmp(image_types[i], type) == 0 )
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return IMAGE_UNKNOWN;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const char * image_type_to_string(enum image_type type) {
|
||||||
|
|
||||||
|
if ( type > sizeof(image_types)/sizeof(image_types[0]) )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return image_types[type];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int image_hwrev_is_valid(struct image * image, int16_t hwrev) {
|
||||||
|
|
||||||
|
struct device_list * device_ptr = image->devices;
|
||||||
|
|
||||||
|
while ( device_ptr ) {
|
||||||
|
if ( hwrev_is_valid(device_ptr->hwrevs, hwrev) )
|
||||||
|
return 1;
|
||||||
|
device_ptr = device_ptr->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void image_print_info(struct image * image) {
|
||||||
|
|
||||||
|
const char * str;
|
||||||
|
struct device_list * device = image->devices;
|
||||||
|
|
||||||
|
if ( image->orig_filename )
|
||||||
|
printf("File: %s\n", image->orig_filename);
|
||||||
|
|
||||||
|
str = image_type_to_string(image->type);
|
||||||
|
printf(" Image type: %s\n", str ? str : "unknown");
|
||||||
|
printf(" Image size: %d bytes\n", image->size);
|
||||||
|
|
||||||
|
if ( image->version )
|
||||||
|
printf(" Image version: %s\n", image->version);
|
||||||
|
|
||||||
|
if ( image->layout )
|
||||||
|
printf(" Image layout: included\n");
|
||||||
|
|
||||||
|
while ( device ) {
|
||||||
|
|
||||||
|
char * str2 = NULL;
|
||||||
|
struct device_list * next = device->next;
|
||||||
|
|
||||||
|
if ( device->device == DEVICE_UNKNOWN )
|
||||||
|
str = "unknown";
|
||||||
|
else
|
||||||
|
str = device_to_string(device->device);
|
||||||
|
|
||||||
|
if ( str )
|
||||||
|
printf(" Valid for: device %s", str);
|
||||||
|
|
||||||
|
if ( str && device->hwrevs )
|
||||||
|
str2 = hwrevs_alloc_to_string(device->hwrevs);
|
||||||
|
|
||||||
|
if ( str2 ) {
|
||||||
|
printf(", HW revisions: %s\n", str2);
|
||||||
|
free(str2);
|
||||||
|
} else if ( str ) {
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
device = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef IMAGE_H
|
||||||
|
#define IMAGE_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
enum image_type {
|
||||||
|
IMAGE_UNKNOWN = 0,
|
||||||
|
IMAGE_XLOADER,
|
||||||
|
IMAGE_2ND,
|
||||||
|
IMAGE_SECONDARY,
|
||||||
|
IMAGE_KERNEL,
|
||||||
|
IMAGE_INITFS,
|
||||||
|
IMAGE_ROOTFS,
|
||||||
|
IMAGE_MMC,
|
||||||
|
IMAGE_CMT_2ND,
|
||||||
|
IMAGE_CMT_ALGO,
|
||||||
|
IMAGE_CMT_MCUSW,
|
||||||
|
IMAGE_COUNT,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct image {
|
||||||
|
enum image_type type;
|
||||||
|
struct device_list * devices;
|
||||||
|
char * version;
|
||||||
|
char * layout;
|
||||||
|
uint16_t hash;
|
||||||
|
uint32_t size;
|
||||||
|
|
||||||
|
int fd;
|
||||||
|
int is_shared_fd;
|
||||||
|
uint32_t align;
|
||||||
|
size_t offset;
|
||||||
|
size_t cur;
|
||||||
|
size_t acur;
|
||||||
|
char * orig_filename;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct image_list {
|
||||||
|
struct image * image;
|
||||||
|
struct image_list * prev;
|
||||||
|
struct image_list * next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct image * image_alloc_from_file(const char * file, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout);
|
||||||
|
struct image * image_alloc_from_shared_fd(int fd, size_t size, size_t offset, uint16_t hash, const char * type, const char * device, const char * hwrevs, const char * version, const char * layout);
|
||||||
|
void image_free(struct image * image);
|
||||||
|
void image_seek(struct image * image, size_t whence);
|
||||||
|
size_t image_read(struct image * image, void * buf, size_t count);
|
||||||
|
void image_print_info(struct image * image);
|
||||||
|
void image_list_add(struct image_list ** list, struct image * image);
|
||||||
|
void image_list_del(struct image_list * list);
|
||||||
|
void image_list_unlink(struct image_list * list);
|
||||||
|
|
||||||
|
uint16_t image_hash_from_data(struct image * image);
|
||||||
|
enum image_type image_type_from_data(struct image * image);
|
||||||
|
char * image_name_alloc_from_values(struct image * image);
|
||||||
|
enum image_type image_type_from_string(const char * type);
|
||||||
|
const char * image_type_to_string(enum image_type type);
|
||||||
|
int image_hwrev_is_valid(struct image * image, int16_t hwrev);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
/*
|
||||||
|
libusb-sniff.c - Library for usb sniffing nokia's flasher-3.5
|
||||||
|
Copyright (C) 2011-2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* compile: gcc libusb-sniff.c -o libusb-sniff.so -W -Wall -O2 -fPIC -ldl -shared -m32 */
|
||||||
|
/* usage: sudo USBSNIFF_WAIT=1 LD_PRELOAD=./libusb-sniff.so flasher-3.5 ... */
|
||||||
|
/* usage: sudo USBSNIFF_SKIP_READ=1 USBSNIFF_SKIP_WRITE=1 LD_PRELOAD=./libusb-sniff.so flasher-3.5 ... */
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <usb.h>
|
||||||
|
|
||||||
|
static char to_ascii(char c) {
|
||||||
|
|
||||||
|
if ( c >= 32 && c <= 126 )
|
||||||
|
return c;
|
||||||
|
return '.';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dump_bytes(const char * buf, size_t size) {
|
||||||
|
|
||||||
|
size_t i, ascii_cnt = 0;
|
||||||
|
char ascii[17] = { 0, };
|
||||||
|
|
||||||
|
for ( i = 0; i < size; i++ ) {
|
||||||
|
if ( i % 16 == 0 ) {
|
||||||
|
if ( i != 0 ) {
|
||||||
|
printf(" |%s|\n", ascii);
|
||||||
|
ascii[0] = 0;
|
||||||
|
ascii_cnt = 0;
|
||||||
|
}
|
||||||
|
printf("%04X:", (unsigned int)i);
|
||||||
|
}
|
||||||
|
printf(" %02X", buf[i] & 0xFF);
|
||||||
|
ascii[ascii_cnt] = to_ascii(buf[i]);
|
||||||
|
ascii[ascii_cnt + 1] = 0;
|
||||||
|
ascii_cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ascii[0] ) {
|
||||||
|
if ( size % 16 )
|
||||||
|
for ( i = 0; i < 16 - (size % 16); i++ )
|
||||||
|
printf(" ");
|
||||||
|
printf(" |%s|\n", ascii);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_bulk_write(usb_dev_handle * dev, int ep, const char * bytes, int size, int timeout) {
|
||||||
|
|
||||||
|
static int (*real_usb_bulk_write)(usb_dev_handle * dev, int ep, const char * bytes, int size, int timeout) = NULL;
|
||||||
|
|
||||||
|
if ( ! real_usb_bulk_write )
|
||||||
|
real_usb_bulk_write = dlsym(RTLD_NEXT, "usb_bulk_write");
|
||||||
|
|
||||||
|
if ( ! getenv("USBSNIFF_SKIP_WRITE") ) {
|
||||||
|
|
||||||
|
printf("\n==== usb_bulk_write (ep=%d size=%d timeout=%d) ====\n", ep, size, timeout);
|
||||||
|
dump_bytes(bytes, size);
|
||||||
|
printf("====\n");
|
||||||
|
|
||||||
|
if ( getenv("USBSNIFF_WAIT") ) {
|
||||||
|
printf("Press ENTER"); fflush(stdout); getchar();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return real_usb_bulk_write(dev, ep, bytes, size, timeout);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_bulk_read(usb_dev_handle * dev, int ep, char * bytes, int size, int timeout) {
|
||||||
|
|
||||||
|
static int (*real_usb_bulk_read)(usb_dev_handle * dev, int ep, char * bytes, int size, int timeout) = NULL;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if ( ! real_usb_bulk_read )
|
||||||
|
real_usb_bulk_read = dlsym(RTLD_NEXT, "usb_bulk_read");
|
||||||
|
|
||||||
|
ret = real_usb_bulk_read(dev, ep, bytes, size, timeout);
|
||||||
|
|
||||||
|
if ( ! getenv("USBSNIFF_SKIP_READ") ) {
|
||||||
|
|
||||||
|
printf("\n==== usb_bulk_read (ep=%d size=%d timeout=%d) ret = %d ====\n", ep, size, timeout, ret);
|
||||||
|
if ( ret > 0 ) {
|
||||||
|
dump_bytes(bytes, ret);
|
||||||
|
printf("====\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( getenv("USBSNIFF_WAIT") ) {
|
||||||
|
printf("Press ENTER"); fflush(stdout); getchar();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout) {
|
||||||
|
|
||||||
|
static int (*real_usb_control_msg)(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout) = NULL;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if ( ! real_usb_control_msg )
|
||||||
|
real_usb_control_msg = dlsym(RTLD_NEXT, "usb_control_msg");
|
||||||
|
|
||||||
|
if ( requesttype == 64 && ! getenv("USBSNIFF_SKIP_CONTROL") ) {
|
||||||
|
|
||||||
|
printf("\n==== usb_control_msg(requesttype=%d, request=%d, value=%d, index=%d, size=%d, timeout=%d) ====\n", requesttype, request, value, index, size, timeout);
|
||||||
|
dump_bytes(bytes, size);
|
||||||
|
printf("====\n");
|
||||||
|
|
||||||
|
if ( getenv("USBSNIFF_WAIT") ) {
|
||||||
|
printf("Press ENTER"); fflush(stdout); getchar();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = real_usb_control_msg(dev, requesttype, request, value, index, bytes, size, timeout);
|
||||||
|
|
||||||
|
if ( requesttype != 64 && ! getenv("USBSNIFF_SKIP_CONTROL") ) {
|
||||||
|
|
||||||
|
printf("\n==== usb_control_msg(requesttype=%d, request=%d, value=%d, index=%d, size=%d, timeout=%d) ret = %d ====\n", requesttype, request, value, index, size, timeout, ret);
|
||||||
|
if ( ret > 0 ) {
|
||||||
|
dump_bytes(bytes, ret);
|
||||||
|
printf("====\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( getenv("USBSNIFF_WAIT") ) {
|
||||||
|
printf("Press ENTER"); fflush(stdout); getchar();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_set_configuration(usb_dev_handle *dev, int configuration) {
|
||||||
|
|
||||||
|
static int (*real_usb_set_configuration)(usb_dev_handle *dev, int configuration) = NULL;
|
||||||
|
|
||||||
|
if ( ! real_usb_set_configuration )
|
||||||
|
real_usb_set_configuration = dlsym(RTLD_NEXT, "usb_set_configuration");
|
||||||
|
|
||||||
|
printf("\n==== usb_set_configuration (configuration=%d) ====\n", configuration);
|
||||||
|
|
||||||
|
return real_usb_set_configuration(dev, configuration);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_claim_interface(usb_dev_handle *dev, int interface) {
|
||||||
|
|
||||||
|
static int (*real_usb_claim_interface)(usb_dev_handle *dev, int interface) = NULL;
|
||||||
|
|
||||||
|
if ( ! real_usb_claim_interface )
|
||||||
|
real_usb_claim_interface = dlsym(RTLD_NEXT, "usb_claim_interface");
|
||||||
|
|
||||||
|
printf("\n==== usb_claim_interface (interface=%d) ====\n", interface);
|
||||||
|
|
||||||
|
return real_usb_claim_interface(dev, interface);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int usb_set_altinterface(usb_dev_handle *dev, int alternate) {
|
||||||
|
|
||||||
|
static int (*real_usb_set_altinterface)(usb_dev_handle *dev, int alternate) = NULL;
|
||||||
|
|
||||||
|
if ( ! real_usb_set_altinterface )
|
||||||
|
real_usb_set_altinterface = dlsym(RTLD_NEXT, "usb_set_altinterface");
|
||||||
|
|
||||||
|
printf("\n==== usb_set_altinterface (alternate=%d) ====\n", alternate);
|
||||||
|
|
||||||
|
return real_usb_set_altinterface(dev, alternate);
|
||||||
|
|
||||||
|
}
|
||||||
+615
@@ -0,0 +1,615 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
#include "local.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "device.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "cal.h"
|
||||||
|
#include "disk.h"
|
||||||
|
|
||||||
|
static int failed;
|
||||||
|
|
||||||
|
static enum device device = DEVICE_UNKNOWN;
|
||||||
|
static int16_t hwrev = -1;
|
||||||
|
static char kernel_ver[256];
|
||||||
|
static char initfs_ver[256];
|
||||||
|
static char nolo_ver[256];
|
||||||
|
static char sw_ver[256];
|
||||||
|
static char content_ver[256];
|
||||||
|
static char rd_mode[256];
|
||||||
|
static int usb_host_mode = -1;
|
||||||
|
static int root_device = -1;
|
||||||
|
|
||||||
|
#define min(a, b) (a < b ? a : b)
|
||||||
|
#define local_cal_copy(dest, from, len) strncpy(dest, from, min(len, sizeof(dest)-1))
|
||||||
|
#define local_cal_read(cal, str, ptr, len) ( cal_read_block(cal, str, &ptr, &len, 0) == 0 && ptr )
|
||||||
|
#define local_cal_store(cal, str, dest) do { void * ptr; unsigned long int len; if ( local_cal_read(cal, str, ptr, len) ) local_cal_copy(dest, ptr, len); } while ( 0 )
|
||||||
|
|
||||||
|
static void local_cal_parse(void) {
|
||||||
|
|
||||||
|
struct cal * cal = NULL;
|
||||||
|
char buf[128];
|
||||||
|
|
||||||
|
printf("Reading CAL...\n");
|
||||||
|
|
||||||
|
if ( cal_init(&cal) < 0 || ! cal )
|
||||||
|
return;
|
||||||
|
|
||||||
|
local_cal_store(cal, "kernel-ver", kernel_ver);
|
||||||
|
local_cal_store(cal, "initfs-ver", kernel_ver);
|
||||||
|
local_cal_store(cal, "nolo-ver", nolo_ver);
|
||||||
|
local_cal_store(cal, "sw-release-ver", sw_ver);
|
||||||
|
local_cal_store(cal, "content-ver", content_ver);
|
||||||
|
local_cal_store(cal, "r&d_mode", rd_mode);
|
||||||
|
|
||||||
|
/* overwritten hw revision */
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
local_cal_store(cal, "hw-ver", buf);
|
||||||
|
|
||||||
|
if ( buf[0] && sscanf(buf, "%hd", &hwrev) != 1 )
|
||||||
|
hwrev = -1;
|
||||||
|
|
||||||
|
if ( hwrev == -1 ) {
|
||||||
|
|
||||||
|
/* original hw revision */
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
local_cal_store(cal, "phone-info", buf);
|
||||||
|
buf[4] = 0;
|
||||||
|
|
||||||
|
if ( buf[0] && sscanf(buf, "%hd", &hwrev) != 1 )
|
||||||
|
hwrev = -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[0] = 0;
|
||||||
|
local_cal_store(cal, "usb_host_mode", buf);
|
||||||
|
usb_host_mode = buf[0];
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
local_cal_store(cal, "root_device", buf);
|
||||||
|
|
||||||
|
if ( strcmp(buf, "mmc") == 0 )
|
||||||
|
root_device = 1;
|
||||||
|
else if ( strcmp(buf, "usb") == 0 )
|
||||||
|
root_device = 2;
|
||||||
|
else
|
||||||
|
root_device = 0;
|
||||||
|
|
||||||
|
cal_finish(cal);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_init(void) {
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
char * ptr;
|
||||||
|
char * ptr2;
|
||||||
|
FILE * file;
|
||||||
|
|
||||||
|
if ( failed )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
file = fopen("/proc/cpuinfo", "r");
|
||||||
|
if ( ! file ) {
|
||||||
|
failed = 1;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( fgets(buf, sizeof(buf), file) ) {
|
||||||
|
|
||||||
|
if ( strncmp(buf, "Hardware", strlen("Hardware")) == 0 ) {
|
||||||
|
|
||||||
|
ptr = buf + strlen("Hardware");
|
||||||
|
|
||||||
|
while ( ptr < buf + sizeof(buf) && *ptr > 0 && *ptr <= 32 )
|
||||||
|
++ptr;
|
||||||
|
|
||||||
|
if ( *ptr != ':' )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
++ptr;
|
||||||
|
|
||||||
|
while ( ptr < buf + sizeof(buf) && *ptr > 0 && *ptr <= 32 )
|
||||||
|
++ptr;
|
||||||
|
|
||||||
|
if ( ! *ptr )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ptr2 = buf + strlen(buf);
|
||||||
|
|
||||||
|
while ( *ptr2 <= 32 ) {
|
||||||
|
*ptr2 = 0;
|
||||||
|
--ptr2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( strcmp(ptr, "Nokia 770") == 0 )
|
||||||
|
device = DEVICE_SU_18;
|
||||||
|
else if ( strcmp(ptr, "Nokia N800") == 0 )
|
||||||
|
device = DEVICE_RX_34;
|
||||||
|
else if ( strcmp(ptr, "Nokia N810") == 0 )
|
||||||
|
device = DEVICE_RX_44;
|
||||||
|
else if ( strcmp(ptr, "Nokia N810 WiMAX") == 0 )
|
||||||
|
device = DEVICE_RX_48;
|
||||||
|
else if ( strcmp(ptr, "Nokia RX-51 board") == 0 )
|
||||||
|
device = DEVICE_RX_51;
|
||||||
|
|
||||||
|
if ( device ) {
|
||||||
|
printf("Found local device: %s\n", device_to_long_string(device));
|
||||||
|
fclose(file);
|
||||||
|
local_cal_parse();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
failed = 1;
|
||||||
|
printf("Not a local device\n");
|
||||||
|
fclose(file);
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
enum device local_get_device(void) {
|
||||||
|
|
||||||
|
return device;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_flash_image(struct image * image) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)image;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int local_nanddump(const char * file, int mtd, int offset, int length) {
|
||||||
|
|
||||||
|
struct statvfs buf;
|
||||||
|
char * command;
|
||||||
|
char * path;
|
||||||
|
size_t size;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
path = strdup(file);
|
||||||
|
if ( ! path )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
ret = statvfs(dirname(path), &buf);
|
||||||
|
|
||||||
|
free(path);
|
||||||
|
|
||||||
|
if ( ret == 0 && buf.f_bsize * buf.f_bfree < (long unsigned int)length ) {
|
||||||
|
ERROR("Not enought free space (have: %lu, need: %d)", buf.f_bsize * buf.f_bfree, length);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = snprintf(NULL, 0, "nanddump -i -o -b -s %d -l %d -f %s /dev/mtd%dro", offset, length, file, mtd);
|
||||||
|
|
||||||
|
command = malloc(size+1);
|
||||||
|
if ( ! command )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
snprintf(command, size+1, "nanddump -i -o -b -s %d -l %d -f %s /dev/mtd%dro", offset, length, file, mtd);
|
||||||
|
|
||||||
|
ret = system(command);
|
||||||
|
|
||||||
|
free(command);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct nanddump_args {
|
||||||
|
int valid;
|
||||||
|
int mtd;
|
||||||
|
int offset;
|
||||||
|
int length;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct nanddump_args nanddump_n900[] = {
|
||||||
|
[IMAGE_XLOADER] = { 1, 0, 0x00000000, 0x00004000 },
|
||||||
|
[IMAGE_SECONDARY] = { 1, 0, 0x00004000, 0x0001C000 },
|
||||||
|
[IMAGE_KERNEL] = { 1, 3, 0x00000800, 0x001FF800 },
|
||||||
|
[IMAGE_INITFS] = { 1, 4, 0x00000800, 0x001FF800 },
|
||||||
|
[IMAGE_ROOTFS] = { 1, 5, 0x00000000, 0x0fb40000 },
|
||||||
|
};
|
||||||
|
|
||||||
|
/* FIXME: Is this table correct? */
|
||||||
|
static struct nanddump_args nanddump[] = {
|
||||||
|
[IMAGE_XLOADER] = { 1, 0, 0x00000200, 0x00003E00 },
|
||||||
|
[IMAGE_SECONDARY] = { 1, 0, 0x00004000, 0x0001C000 },
|
||||||
|
[IMAGE_KERNEL] = { 1, 2, 0x00000800, 0x001FF800 },
|
||||||
|
[IMAGE_INITFS] = { 1, 3, 0x00000800, 0x001FF800 },
|
||||||
|
[IMAGE_ROOTFS] = { 1, 4, 0x00000000, 0x0fb80000 },
|
||||||
|
};
|
||||||
|
|
||||||
|
int local_dump_image(enum image_type image, const char * file) {
|
||||||
|
|
||||||
|
int ret = -1;
|
||||||
|
int fd = -1;
|
||||||
|
unsigned char * addr = NULL;
|
||||||
|
off_t nlen, len;
|
||||||
|
int align;
|
||||||
|
DIR * dir;
|
||||||
|
DIR * dir2;
|
||||||
|
struct dirent * dirent;
|
||||||
|
struct dirent * dirent2;
|
||||||
|
char * ptr;
|
||||||
|
int i;
|
||||||
|
char buf[1024];
|
||||||
|
char blk[1024];
|
||||||
|
|
||||||
|
printf("Dump %s image to file %s...\n", image_type_to_string(image), file);
|
||||||
|
|
||||||
|
if ( image == IMAGE_MMC ) {
|
||||||
|
|
||||||
|
/* Find block device in /dev/ for MyDocs (mmc device, partition 1) */
|
||||||
|
|
||||||
|
dir = opendir("/sys/class/mmc_host/");
|
||||||
|
if ( ! dir ) {
|
||||||
|
ERROR("Cannot find MyDocs mmc device");
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
|
||||||
|
blk[0] = 0;
|
||||||
|
|
||||||
|
while ( ( dirent = readdir(dir) ) ) {
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "/sys/class/mmc_host/%s/slot_name", dirent->d_name);
|
||||||
|
|
||||||
|
fd = open(buf, O_RDONLY);
|
||||||
|
if ( fd < 0 )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
buf[0] = 0;
|
||||||
|
read(fd, buf, sizeof(buf));
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if ( strncmp(buf, "internal", strlen("internal")) != 0 )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "/sys/class/mmc_host/%s/%s:0001", dirent->d_name, dirent->d_name);
|
||||||
|
|
||||||
|
dir2 = opendir(buf);
|
||||||
|
if ( ! dir2 )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
while ( ( dirent2 = readdir(dir2) ) ) {
|
||||||
|
|
||||||
|
if ( strncmp(dirent2->d_name, "block:mmcblk", strlen("block:mmcblk")) != 0 )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "/sys/class/mmc_host/%s/%s:0001/%s", dirent->d_name, dirent->d_name, dirent2->d_name);
|
||||||
|
|
||||||
|
blk[0] = 0;
|
||||||
|
if ( readlink(buf, blk, sizeof(blk)) < 0 )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ptr = strrchr(blk, '/');
|
||||||
|
if ( ! ptr ) {
|
||||||
|
blk[0] = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(blk, "/dev/");
|
||||||
|
i = strlen("/dev/");
|
||||||
|
++ptr;
|
||||||
|
|
||||||
|
while ( *ptr )
|
||||||
|
blk[i++] = *(ptr++);
|
||||||
|
|
||||||
|
strcpy(blk+i, "p1");
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir2);
|
||||||
|
|
||||||
|
if ( blk[0] )
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
|
if ( ! blk[0] ) {
|
||||||
|
ERROR("Cannot find MyDocs mmc device");
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = disk_dump_raw(blk, image_type_to_string(image));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ( device == DEVICE_RX_51 ) {
|
||||||
|
|
||||||
|
if ( image >= sizeof(nanddump_n900)/sizeof(nanddump_n900[0]) || ! nanddump_n900[image].valid ) {
|
||||||
|
ERROR("Unsuported image type: %s", image_type_to_string(image));
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = local_nanddump(file, nanddump_n900[image].mtd, nanddump_n900[image].offset, nanddump_n900[image].length);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ( image >= sizeof(nanddump)/sizeof(nanddump[0]) || ! nanddump[image].valid ) {
|
||||||
|
ERROR("Unsuported image type: %s", image_type_to_string(image));
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = local_nanddump(file, nanddump[image].mtd, nanddump[image].offset, nanddump[image].length);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ret != 0 ) {
|
||||||
|
ret = -1;
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = open(file, O_RDWR);
|
||||||
|
if ( fd < 0 )
|
||||||
|
goto clean;
|
||||||
|
|
||||||
|
len = lseek(fd, 0, SEEK_END);
|
||||||
|
if ( len == (off_t)-1 || len == 0 )
|
||||||
|
goto clean;
|
||||||
|
|
||||||
|
addr = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
|
|
||||||
|
if ( addr == MAP_FAILED )
|
||||||
|
addr = NULL;
|
||||||
|
|
||||||
|
if ( ! addr )
|
||||||
|
goto clean;
|
||||||
|
|
||||||
|
for ( nlen = len; nlen > 0; --nlen )
|
||||||
|
if ( addr[nlen-1] != 0xFF )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ( image == IMAGE_MMC )
|
||||||
|
align = 8;
|
||||||
|
else
|
||||||
|
align = 7;
|
||||||
|
|
||||||
|
if ( ( nlen & ( ( 1ULL << align ) - 1 ) ) != 0 )
|
||||||
|
nlen = ((nlen >> align) + 1) << align;
|
||||||
|
|
||||||
|
if ( nlen == 0 ) {
|
||||||
|
printf("File %s is empty, removing it...\n", file);
|
||||||
|
unlink(file);
|
||||||
|
} else if ( nlen != len ) {
|
||||||
|
printf("Truncating file %s to %d bytes...\n", file, (int)nlen);
|
||||||
|
ftruncate(fd, nlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
if ( addr )
|
||||||
|
munmap(addr, len);
|
||||||
|
|
||||||
|
if ( fd >= 0 )
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_check_badblocks(const char * device) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)device;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_reboot_device(void) {
|
||||||
|
|
||||||
|
if ( system("dsmetool -b") == 0 )
|
||||||
|
return 0;
|
||||||
|
return system("reboot");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_get_root_device(void) {
|
||||||
|
|
||||||
|
return root_device;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_set_root_device(int device) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)device;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_get_usb_host_mode(void) {
|
||||||
|
|
||||||
|
return usb_host_mode;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_set_usb_host_mode(int enable) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)enable;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_get_rd_mode(void) {
|
||||||
|
|
||||||
|
if ( strncmp(rd_mode, "master", strlen("master")) == 0 )
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_set_rd_mode(int enable) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)enable;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_get_rd_flags(char * flags, size_t size) {
|
||||||
|
|
||||||
|
const char * ptr;
|
||||||
|
|
||||||
|
if ( strncmp(rd_mode, "master", strlen("master")) == 0 )
|
||||||
|
ptr = rd_mode + strlen("master");
|
||||||
|
else
|
||||||
|
ptr = rd_mode;
|
||||||
|
|
||||||
|
if ( *ptr == ',' )
|
||||||
|
++ptr;
|
||||||
|
|
||||||
|
if ( ! *ptr ) {
|
||||||
|
flags[0] = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(flags, ptr, size);
|
||||||
|
flags[size-1] = 0;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_set_rd_flags(const char * flags) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)flags;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t local_get_hwrev(void) {
|
||||||
|
|
||||||
|
return hwrev;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_set_hwrev(int16_t hwrev) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)hwrev;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_get_kernel_ver(char * ver, size_t size) {
|
||||||
|
|
||||||
|
strncpy(ver, kernel_ver, size);
|
||||||
|
ver[size-1] = 0;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_set_kernel_ver(const char * ver) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_get_initfs_ver(char * ver, size_t size) {
|
||||||
|
|
||||||
|
strncpy(ver, initfs_ver, size);
|
||||||
|
ver[size-1] = 0;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_set_initfs_ver(const char * ver) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_get_nolo_ver(char * ver, size_t size) {
|
||||||
|
|
||||||
|
strncpy(ver, nolo_ver, size);
|
||||||
|
ver[size-1] = 0;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_set_nolo_ver(const char * ver) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_get_sw_ver(char * ver, size_t size) {
|
||||||
|
|
||||||
|
strncpy(ver, sw_ver, size);
|
||||||
|
ver[size-1] = 0;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_set_sw_ver(const char * ver) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_get_content_ver(char * ver, size_t size) {
|
||||||
|
|
||||||
|
strncpy(ver, content_ver, size);
|
||||||
|
ver[size-1] = 0;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int local_set_content_ver(const char * ver) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LOCAL_H
|
||||||
|
#define LOCAL_H
|
||||||
|
|
||||||
|
#include "image.h"
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
int local_init(void);
|
||||||
|
|
||||||
|
enum device local_get_device(void);
|
||||||
|
|
||||||
|
int local_flash_image(struct image * image);
|
||||||
|
int local_dump_image(enum image_type image, const char * file);
|
||||||
|
int local_check_badblocks(const char * device);
|
||||||
|
|
||||||
|
int local_reboot_device(void);
|
||||||
|
|
||||||
|
int local_get_root_device(void);
|
||||||
|
int local_set_root_device(int device);
|
||||||
|
|
||||||
|
int local_get_usb_host_mode(void);
|
||||||
|
int local_set_usb_host_mode(int enable);
|
||||||
|
|
||||||
|
int local_get_rd_mode(void);
|
||||||
|
int local_set_rd_mode(int enable);
|
||||||
|
|
||||||
|
int local_get_rd_flags(char * flags, size_t size);
|
||||||
|
int local_set_rd_flags(const char * flags);
|
||||||
|
|
||||||
|
int16_t local_get_hwrev(void);
|
||||||
|
int local_set_hwrev(int16_t hwrev);
|
||||||
|
|
||||||
|
int local_get_kernel_ver(char * ver, size_t size);
|
||||||
|
int local_set_kernel_ver(const char * ver);
|
||||||
|
|
||||||
|
int local_get_initfs_ver(char * ver, size_t size);
|
||||||
|
int local_set_initfs_ver(const char * ver);
|
||||||
|
|
||||||
|
int local_get_nolo_ver(char * ver, size_t size);
|
||||||
|
int local_set_nolo_ver(const char * ver);
|
||||||
|
|
||||||
|
int local_get_sw_ver(char * ver, size_t size);
|
||||||
|
int local_set_sw_ver(const char * ver);
|
||||||
|
|
||||||
|
int local_get_content_ver(char * ver, size_t size);
|
||||||
|
int local_set_content_ver(const char * ver);
|
||||||
|
|
||||||
|
#endif
|
||||||
+1313
-409
File diff suppressed because it is too large.
Load diff
-121
@@ -1,121 +0,0 @@
|
|||||||
|
|
||||||
#ifndef _INCLUDE_MAIN_H_
|
|
||||||
#define _INCLUDE_MAIN_H_
|
|
||||||
|
|
||||||
#include "hash.h"
|
|
||||||
#include "nolo.h"
|
|
||||||
#include "os.h"
|
|
||||||
extern char strbuf[1024];
|
|
||||||
|
|
||||||
#define _FILE_OFFSET_BITS 64
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
|
|
||||||
// Forward declaration for use in function arguments.
|
|
||||||
struct devices;
|
|
||||||
|
|
||||||
int queue_mode();
|
|
||||||
int reverse_extract_pieces(char *dir);
|
|
||||||
void flash_image(const char *filename, const char *piece, const char *version);
|
|
||||||
int fiasco_read_image(char *file);
|
|
||||||
void check_nolo_order();
|
|
||||||
extern struct usb_dev_handle *dev;
|
|
||||||
unsigned long get_file_size(const char *file);
|
|
||||||
void progressbar(unsigned long long part, unsigned long long total);
|
|
||||||
const char *fpid_file(const char *filename);
|
|
||||||
int add_piece(char *piece);
|
|
||||||
void eprintf(const char *format, ...);
|
|
||||||
|
|
||||||
#include <limits.h>
|
|
||||||
#ifndef PATH_MAX
|
|
||||||
#define PATH_MAX 4096
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAVE_USB
|
|
||||||
#include <usb.h>
|
|
||||||
|
|
||||||
int fiasco_flash(const char *file);
|
|
||||||
extern struct usb_device *device;
|
|
||||||
extern struct usb_dev_handle *dev;
|
|
||||||
int is_valid_device(struct usb_device_descriptor *udd);
|
|
||||||
void list_valid_devices();
|
|
||||||
int usb_device_found(struct usb_device_descriptor *udd, struct devices *it_device);
|
|
||||||
int console(const char *device);
|
|
||||||
int connect_via_usb();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int console_prompt();
|
|
||||||
|
|
||||||
//
|
|
||||||
void cmd_info(char *line);
|
|
||||||
int check_badblocks(char *mtddev);
|
|
||||||
int dump_config();
|
|
||||||
|
|
||||||
extern int verbose;
|
|
||||||
#define D if (verbose)
|
|
||||||
|
|
||||||
#define CMD_WRITE 64
|
|
||||||
#define CMD_QUERY 192
|
|
||||||
|
|
||||||
|
|
||||||
struct piece_t {
|
|
||||||
char *name;
|
|
||||||
char *type;
|
|
||||||
char *vers;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct devices {
|
|
||||||
char *name;
|
|
||||||
unsigned short vendor_id;
|
|
||||||
unsigned short product_id;
|
|
||||||
unsigned short flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define SUPPORTED_DEVICES 6
|
|
||||||
extern struct devices supported_devices[SUPPORTED_DEVICES];
|
|
||||||
|
|
||||||
extern int pcs_n;
|
|
||||||
extern struct piece_t pcs[10];
|
|
||||||
|
|
||||||
enum {
|
|
||||||
PIECE_XLOADER = 0,
|
|
||||||
PIECE_2ND,
|
|
||||||
PIECE_SECONDARY,
|
|
||||||
PIECE_KERNEL,
|
|
||||||
PIECE_INITFS,
|
|
||||||
PIECE_ROOTFS,
|
|
||||||
PIECE_OMAPNAND,
|
|
||||||
PIECE_FIASCO,
|
|
||||||
PIECE_LAST
|
|
||||||
};
|
|
||||||
|
|
||||||
struct header_t {
|
|
||||||
int fd;
|
|
||||||
char fwname[128];
|
|
||||||
char name[128];
|
|
||||||
char version[128];
|
|
||||||
unsigned short hash;
|
|
||||||
unsigned int size;
|
|
||||||
unsigned char *data;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern char *pieces[];
|
|
||||||
extern char *modes[];
|
|
||||||
extern char *root_devices[];
|
|
||||||
|
|
||||||
// fiasco
|
|
||||||
int openfiasco(char *name, char *grep, int v);
|
|
||||||
int fiasco_new(const char *filename, const char *name);
|
|
||||||
void fiasco_data_read(struct header_t *header);
|
|
||||||
int fiasco_add_eof(int fd);
|
|
||||||
extern int (*fiasco_callback)(struct header_t *header);
|
|
||||||
int fiasco_add(int fd, const char *name, const char *file, const char *version);
|
|
||||||
int fiasco_pack(int optind, char *argv[]);
|
|
||||||
int nanddump(char *mtddev, unsigned long start_addr, unsigned long length, char *dumpfile, int isbl, int ioob);
|
|
||||||
|
|
||||||
//
|
|
||||||
int reboot_board();
|
|
||||||
int get_rd_flags();
|
|
||||||
int get_usb_mode();
|
|
||||||
int get_nolo_version();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+239
@@ -0,0 +1,239 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mkii.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "device.h"
|
||||||
|
#include "usb-device.h"
|
||||||
|
|
||||||
|
int mkii_init(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
ERROR("Mk II protocol is not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
enum device mkii_get_device(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
return DEVICE_UNKNOWN;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_flash_image(struct usb_device_info * dev, struct image * image) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)image;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_reboot_device(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_get_root_device(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_set_root_device(struct usb_device_info * dev, int device) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)device;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_get_usb_host_mode(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_set_usb_host_mode(struct usb_device_info * dev, int enable) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)enable;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_get_rd_mode(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_set_rd_mode(struct usb_device_info * dev, int enable) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)enable;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_get_rd_flags(struct usb_device_info * dev, char * flags, size_t size) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)flags;
|
||||||
|
(void)size;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_set_rd_flags(struct usb_device_info * dev, const char * flags) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)flags;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t mkii_get_hwrev(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_set_hwrev(struct usb_device_info * dev, int16_t hwrev) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)hwrev;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_get_kernel_ver(struct usb_device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
(void)size;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_set_kernel_ver(struct usb_device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_get_initfs_ver(struct usb_device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
(void)size;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_set_initfs_ver(struct usb_device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_get_nolo_ver(struct usb_device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
(void)size;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_set_nolo_ver(struct usb_device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_get_sw_ver(struct usb_device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
(void)size;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_set_sw_ver(struct usb_device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_get_content_ver(struct usb_device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
(void)size;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int mkii_set_content_ver(struct usb_device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
ERROR("Not implemented yet");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MKII_H
|
||||||
|
#define MKII_H
|
||||||
|
|
||||||
|
#include "image.h"
|
||||||
|
#include "device.h"
|
||||||
|
#include "usb-device.h"
|
||||||
|
|
||||||
|
int mkii_init(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
enum device mkii_get_device(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
int mkii_flash_image(struct usb_device_info * dev, struct image * image);
|
||||||
|
int mkii_reboot_device(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
int mkii_get_root_device(struct usb_device_info * dev);
|
||||||
|
int mkii_set_root_device(struct usb_device_info * dev, int device);
|
||||||
|
|
||||||
|
int mkii_get_usb_host_mode(struct usb_device_info * dev);
|
||||||
|
int mkii_set_usb_host_mode(struct usb_device_info * dev, int enable);
|
||||||
|
|
||||||
|
int mkii_get_rd_mode(struct usb_device_info * dev);
|
||||||
|
int mkii_set_rd_mode(struct usb_device_info * dev, int enable);
|
||||||
|
|
||||||
|
int mkii_get_rd_flags(struct usb_device_info * dev, char * flags, size_t size);
|
||||||
|
int mkii_set_rd_flags(struct usb_device_info * dev, const char * flags);
|
||||||
|
|
||||||
|
int16_t mkii_get_hwrev(struct usb_device_info * dev);
|
||||||
|
int mkii_set_hwrev(struct usb_device_info * dev, int16_t hwrev);
|
||||||
|
|
||||||
|
int mkii_get_kernel_ver(struct usb_device_info * dev, char * ver, size_t size);
|
||||||
|
int mkii_set_kernel_ver(struct usb_device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int mkii_get_initfs_ver(struct usb_device_info * dev, char * ver, size_t size);
|
||||||
|
int mkii_set_initfs_ver(struct usb_device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int mkii_get_nolo_ver(struct usb_device_info * dev, char * ver, size_t size);
|
||||||
|
int mkii_set_nolo_ver(struct usb_device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int mkii_get_sw_ver(struct usb_device_info * dev, char * ver, size_t size);
|
||||||
|
int mkii_set_sw_ver(struct usb_device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int mkii_get_content_ver(struct usb_device_info * dev, char * ver, size_t size);
|
||||||
|
int mkii_set_content_ver(struct usb_device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
#endif
|
||||||
+832
@@ -0,0 +1,832 @@
|
|||||||
|
/*
|
||||||
|
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
* Copyright (C) 2007-2009 pancake <pancake@youterm.com>
|
||||||
|
* Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <usb.h>
|
||||||
|
|
||||||
|
#include "nolo.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include "printf-utils.h"
|
||||||
|
|
||||||
|
/* Request type */
|
||||||
|
#define NOLO_WRITE 64
|
||||||
|
#define NOLO_QUERY 192
|
||||||
|
|
||||||
|
/* Request */
|
||||||
|
#define NOLO_STATUS 1
|
||||||
|
#define NOLO_GET_NOLO_VERSION 3
|
||||||
|
#define NOLO_IDENTIFY 4
|
||||||
|
#define NOLO_SET 16
|
||||||
|
#define NOLO_GET 17
|
||||||
|
#define NOLO_STRING 18
|
||||||
|
#define NOLO_SET_STRING 19
|
||||||
|
#define NOLO_GET_STRING 20
|
||||||
|
#define NOLO_SEND_IMAGE 66
|
||||||
|
#define NOLO_SET_SW_RELEASE 67
|
||||||
|
#define NOLO_FLASH_IMAGE 80
|
||||||
|
#define NOLO_SEND_FLASH_FINISH 82
|
||||||
|
#define NOLO_SEND_FLASH_IMAGE 84
|
||||||
|
#define NOLO_BOOT 130
|
||||||
|
#define NOLO_REBOOT 131
|
||||||
|
|
||||||
|
/* Indexes - Flash image */
|
||||||
|
#define NOLO_IMAGE_BOOTLOADER 1
|
||||||
|
#define NOLO_IMAGE_KERNEL 3
|
||||||
|
#define NOLO_IMAGE_INITFS 4
|
||||||
|
#define NOLO_IMAGE_CMT 66
|
||||||
|
|
||||||
|
/* Indexes - Set & Get */
|
||||||
|
#define NOLO_RD_MODE 0
|
||||||
|
#define NOLO_ROOT_DEVICE 1
|
||||||
|
#define NOLO_USB_HOST_MODE 2
|
||||||
|
#define NOLO_ADD_RD_FLAGS 3
|
||||||
|
#define NOLO_DEL_RD_FLAGS 4
|
||||||
|
|
||||||
|
/* Values - R&D flags */
|
||||||
|
#define NOLO_RD_FLAG_NO_OMAP_WD 0x002
|
||||||
|
#define NOLO_RD_FLAG_NO_EXT_WD 0x004
|
||||||
|
#define NOLO_RD_FLAG_NO_LIFEGUARD 0x008
|
||||||
|
#define NOLO_RD_FLAG_SERIAL_CONSOLE 0x010
|
||||||
|
#define NOLO_RD_FLAG_NO_USB_TIMEOUT 0x020
|
||||||
|
#define NOLO_RD_FLAG_STI_CONSOLE 0x040
|
||||||
|
#define NOLO_RD_FLAG_NO_CHARGING 0x080
|
||||||
|
#define NOLO_RD_FLAG_FORCE_POWER_KEY 0x100
|
||||||
|
|
||||||
|
/* Values - Boot mode */
|
||||||
|
#define NOLO_BOOT_MODE_NORMAL 0
|
||||||
|
#define NOLO_BOOT_MODE_UPDATE 1
|
||||||
|
|
||||||
|
static int nolo_identify_string(struct usb_device_info * dev, const char * str, char * out, size_t size) {
|
||||||
|
|
||||||
|
char buf[512];
|
||||||
|
char * ptr;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
|
||||||
|
ret = usb_control_msg(dev->udev, NOLO_QUERY, NOLO_IDENTIFY, 0, 0, (char *)buf, sizeof(buf), 2000);
|
||||||
|
if ( ret < 0 )
|
||||||
|
ERROR_RETURN("NOLO_IDENTIFY failed", -1);
|
||||||
|
|
||||||
|
ptr = memmem(buf, ret, str, strlen(str));
|
||||||
|
if ( ! ptr )
|
||||||
|
ERROR_RETURN("Substring was not found", -1);
|
||||||
|
|
||||||
|
ptr += strlen(str) + 1;
|
||||||
|
|
||||||
|
while ( ptr-buf < ret && *ptr < 32 )
|
||||||
|
++ptr;
|
||||||
|
|
||||||
|
if ( ! *ptr )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
strncpy(out, ptr, size-1);
|
||||||
|
out[size-1] = 0;
|
||||||
|
return strlen(out);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nolo_set_string(struct usb_device_info * dev, char * str, char * arg) {
|
||||||
|
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_STRING, 0, 0, str, strlen(str), 2000) < 0 )
|
||||||
|
ERROR_RETURN("NOLO_STRING failed", -1);
|
||||||
|
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SET_STRING, 0, 0, arg, strlen(arg), 2000) < 0 )
|
||||||
|
ERROR_RETURN("NOLO_SET_STRING failed", -1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nolo_get_string(struct usb_device_info * dev, char * str, char * out, size_t size) {
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_STRING, 0, 0, str, strlen(str), 2000) < 0 )
|
||||||
|
ERROR_RETURN("NOLO_STRING failed", -1);
|
||||||
|
|
||||||
|
if ( ( ret = usb_control_msg(dev->udev, NOLO_QUERY, NOLO_GET_STRING, 0, 0, out, size-1, 2000) ) < 0 )
|
||||||
|
ERROR_RETURN("NOLO_GET_STRING failed", -1);
|
||||||
|
|
||||||
|
out[size-1] = 0;
|
||||||
|
out[ret] = 0;
|
||||||
|
return strlen(out);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nolo_get_version_string(struct usb_device_info * dev, const char * str, char * out, size_t size) {
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
char buf[512];
|
||||||
|
|
||||||
|
if ( strlen(str) > 500 )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
sprintf(buf, "version:%s", str);
|
||||||
|
|
||||||
|
ret = nolo_get_string(dev, buf, out, size);
|
||||||
|
if ( ret < 0 )
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if ( ! out[0] )
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_init(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
uint32_t val = 1;
|
||||||
|
enum device device;
|
||||||
|
|
||||||
|
printf("Initializing NOLO...\n");
|
||||||
|
|
||||||
|
while ( val != 0 )
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_QUERY, NOLO_STATUS, 0, 0, (char *)&val, 4, 2000) == -1 )
|
||||||
|
ERROR_RETURN("NOLO_STATUS failed", -1);
|
||||||
|
|
||||||
|
device = nolo_get_device(dev);
|
||||||
|
|
||||||
|
if ( ! dev->device )
|
||||||
|
dev->device = device;
|
||||||
|
|
||||||
|
if ( dev->device && device && dev->device != device ) {
|
||||||
|
ERROR("Device mishmash, expected %s, got %s", device_to_string(dev->device), device_to_string(device));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev->hwrev = nolo_get_hwrev(dev);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum device nolo_get_device(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
char buf[20];
|
||||||
|
if ( nolo_identify_string(dev, "prod_code", buf, sizeof(buf)) < 0 )
|
||||||
|
return DEVICE_UNKNOWN;
|
||||||
|
else if ( buf[0] )
|
||||||
|
return device_from_string(buf);
|
||||||
|
else
|
||||||
|
return DEVICE_UNKNOWN;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nolo_send_image(struct usb_device_info * dev, struct image * image, int flash) {
|
||||||
|
|
||||||
|
char buf[0x20000];
|
||||||
|
char * ptr;
|
||||||
|
const char * type;
|
||||||
|
uint8_t len;
|
||||||
|
uint16_t hash;
|
||||||
|
uint32_t size;
|
||||||
|
uint32_t need;
|
||||||
|
uint32_t readed;
|
||||||
|
int request;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if ( flash )
|
||||||
|
printf("Send and flash image:\n");
|
||||||
|
else
|
||||||
|
printf("Load image:\n");
|
||||||
|
image_print_info(image);
|
||||||
|
|
||||||
|
if ( image->type == IMAGE_2ND || image->type == IMAGE_MMC )
|
||||||
|
ERROR_RETURN("Sending 2nd and mmc images are not supported", -1);
|
||||||
|
|
||||||
|
if ( ! flash && image->type == IMAGE_ROOTFS )
|
||||||
|
ERROR_RETURN("Rootfs image must be sent in flash mode", -1);
|
||||||
|
|
||||||
|
ptr = buf;
|
||||||
|
|
||||||
|
/* Signature */
|
||||||
|
memcpy(ptr, "\x2E\x19\x01\x01", 4);
|
||||||
|
ptr += 4;
|
||||||
|
|
||||||
|
/* Space */
|
||||||
|
memcpy(ptr, "\x00", 1);
|
||||||
|
ptr += 1;
|
||||||
|
|
||||||
|
/* Hash */
|
||||||
|
hash = htons(image->hash);
|
||||||
|
memcpy(ptr, &hash, 2);
|
||||||
|
ptr += 2;
|
||||||
|
|
||||||
|
/* Type */
|
||||||
|
type = image_type_to_string(image->type);
|
||||||
|
if ( ! type )
|
||||||
|
ERROR_RETURN("Unknown image type", -1);
|
||||||
|
memset(ptr, 0, 12);
|
||||||
|
strncpy(ptr, type, 12);
|
||||||
|
ptr += 12;
|
||||||
|
|
||||||
|
/* Size */
|
||||||
|
size = htonl(image->size);
|
||||||
|
memcpy(ptr, &size, 4);
|
||||||
|
ptr += 4;
|
||||||
|
|
||||||
|
/* Space */
|
||||||
|
memcpy(ptr, "\x00\x00\x00\x00", 4);
|
||||||
|
ptr += 4;
|
||||||
|
|
||||||
|
/* Device & hwrev */
|
||||||
|
if ( image->devices ) {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
uint8_t len;
|
||||||
|
char buf[9];
|
||||||
|
char ** bufs = NULL;
|
||||||
|
struct device_list * device = image->devices;
|
||||||
|
|
||||||
|
while ( device ) {
|
||||||
|
if ( device->device == dev->device && hwrev_is_valid(device->hwrevs, dev->hwrev) )
|
||||||
|
break;
|
||||||
|
device = device->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( device )
|
||||||
|
bufs = device_list_alloc_to_bufs(device);
|
||||||
|
|
||||||
|
if ( bufs ) {
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
snprintf(buf, 8, "%d", dev->hwrev);
|
||||||
|
|
||||||
|
for ( i = 0; bufs[i]; ++i ) {
|
||||||
|
len = ((uint8_t*)bufs[i])[0];
|
||||||
|
if ( memmem(bufs[i]+1, len, buf, strlen(buf)) )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( bufs[i] ) {
|
||||||
|
/* Device & hwrev string header */
|
||||||
|
memcpy(ptr, "\x32", 1);
|
||||||
|
ptr += 1;
|
||||||
|
/* Device & hwrev string size */
|
||||||
|
memcpy(ptr, &len, 1);
|
||||||
|
ptr += 1;
|
||||||
|
/* Device & hwrev string */
|
||||||
|
memcpy(ptr, bufs[i]+1, len);
|
||||||
|
ptr += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(bufs);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Version */
|
||||||
|
if ( image->version ) {
|
||||||
|
len = strnlen(image->version, 255) + 1;
|
||||||
|
/* Version string header */
|
||||||
|
memcpy(ptr, "\x31", 1);
|
||||||
|
ptr += 1;
|
||||||
|
/* Version string size */
|
||||||
|
memcpy(ptr, &len, 1);
|
||||||
|
ptr += 1;
|
||||||
|
/* Version string */
|
||||||
|
memcpy(ptr, image->version, len);
|
||||||
|
ptr += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( flash )
|
||||||
|
request = NOLO_SEND_FLASH_IMAGE;
|
||||||
|
else
|
||||||
|
request = NOLO_SEND_IMAGE;
|
||||||
|
|
||||||
|
printf("Sending image header...\n");
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, request, 0, 0, buf, ptr-buf, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Sending image header failed", -1);
|
||||||
|
|
||||||
|
if ( flash )
|
||||||
|
printf("Sending and flashing image...\n");
|
||||||
|
else
|
||||||
|
printf("Sending image...\n");
|
||||||
|
printf_progressbar(0, image->size);
|
||||||
|
image_seek(image, 0);
|
||||||
|
readed = 0;
|
||||||
|
while ( readed < image->size ) {
|
||||||
|
need = image->size - readed;
|
||||||
|
if ( need > sizeof(buf) )
|
||||||
|
need = sizeof(buf);
|
||||||
|
ret = image_read(image, buf, need);
|
||||||
|
if ( ret == 0 )
|
||||||
|
break;
|
||||||
|
if ( usb_bulk_write(dev->udev, 2, buf, ret, 5000) != ret )
|
||||||
|
PRINTF_ERROR_RETURN("Sending image failed", -1);
|
||||||
|
readed += ret;
|
||||||
|
printf_progressbar(readed, image->size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( flash ) {
|
||||||
|
printf("Finishing flashing...\n");
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SEND_FLASH_FINISH, 0, 0, NULL, 0, 30000) < 0 )
|
||||||
|
ERROR_RETURN("Finishing failed", -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Done\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_load_image(struct usb_device_info * dev, struct image * image) {
|
||||||
|
|
||||||
|
if ( image->type != IMAGE_KERNEL && image->type != IMAGE_INITFS )
|
||||||
|
ERROR_RETURN("Only kernel or initfs image can be loaded", -1);
|
||||||
|
|
||||||
|
return nolo_send_image(dev, image, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
int flash;
|
||||||
|
int index;
|
||||||
|
unsigned long long int part;
|
||||||
|
unsigned long long int total;
|
||||||
|
unsigned long long int last_total;
|
||||||
|
char status[20];
|
||||||
|
char buf[128];
|
||||||
|
|
||||||
|
if ( image->type == IMAGE_ROOTFS )
|
||||||
|
flash = 1;
|
||||||
|
else
|
||||||
|
flash = 0;
|
||||||
|
|
||||||
|
ret = nolo_send_image(dev, image, flash);
|
||||||
|
if ( ret < 0 )
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if ( image->type == IMAGE_SECONDARY )
|
||||||
|
index = NOLO_IMAGE_BOOTLOADER;
|
||||||
|
else if ( image->type == IMAGE_KERNEL )
|
||||||
|
index = NOLO_IMAGE_KERNEL;
|
||||||
|
else if ( image->type == IMAGE_CMT_MCUSW )
|
||||||
|
index = NOLO_IMAGE_CMT;
|
||||||
|
else
|
||||||
|
index = -1;
|
||||||
|
|
||||||
|
if ( image->type == IMAGE_CMT_MCUSW )
|
||||||
|
nolo_set_string(dev, "cmt:verify", "1");
|
||||||
|
|
||||||
|
if ( ! flash && index >= 0 ) {
|
||||||
|
|
||||||
|
printf("Flashing image...\n");
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_FLASH_IMAGE, 0, index, NULL, 0, 10000) )
|
||||||
|
ERROR_RETURN("Flashing failed", -1);
|
||||||
|
|
||||||
|
printf("Done\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( image->type == IMAGE_CMT_MCUSW ) {
|
||||||
|
|
||||||
|
int state = 0;
|
||||||
|
last_total = 0;
|
||||||
|
|
||||||
|
if ( nolo_get_string(dev, "cmt:status", buf, sizeof(buf)) < 0 )
|
||||||
|
ERROR_RETURN("cmt:status failed", -1);
|
||||||
|
|
||||||
|
if ( strncmp(buf, "idle", strlen("idle")) == 0 )
|
||||||
|
state = 4;
|
||||||
|
else
|
||||||
|
printf("Erasing CMT...\n");
|
||||||
|
|
||||||
|
while ( state != 4 ) {
|
||||||
|
|
||||||
|
if ( nolo_get_string(dev, "cmt:status", buf, sizeof(buf)) < 0 )
|
||||||
|
PRINTF_ERROR_RETURN("cmt:status failed", -1);
|
||||||
|
|
||||||
|
if ( strncmp(buf, "finished", strlen("finished")) == 0 ) {
|
||||||
|
|
||||||
|
if ( state <= 0 ) {
|
||||||
|
printf_progressbar(last_total, last_total);
|
||||||
|
printf("Done\n");
|
||||||
|
}
|
||||||
|
if ( state <= 1 )
|
||||||
|
printf("Programming CMT...\n");
|
||||||
|
if ( state <= 2 ) {
|
||||||
|
printf_progressbar(last_total, last_total);
|
||||||
|
printf("Done\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
state = 4;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ( sscanf(buf, "%s:%llu/%llu", status, &part, &total) != 3 )
|
||||||
|
PRINTF_ERROR_RETURN("cmt:status unknown", -1);
|
||||||
|
|
||||||
|
if ( strcmp(status, "program") == 0 && state <= 0 ) {
|
||||||
|
printf_progressbar(last_total, last_total);
|
||||||
|
printf("Done\n");
|
||||||
|
state = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( strcmp(status, "program") == 0 && state <= 1 ) {
|
||||||
|
printf("Programming CMT...\n");
|
||||||
|
state = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf_progressbar(part, total);
|
||||||
|
last_total = total;
|
||||||
|
|
||||||
|
if ( strcmp(status, "erase") == 0 && state <= 0 && part == total ) {
|
||||||
|
printf("Done\n");
|
||||||
|
state = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( strcmp(status, "program") == 0 && state <= 2 && part == total ) {
|
||||||
|
printf("Done\n");
|
||||||
|
state = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
usleep(0xc350); // 0.5s
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_boot_device(struct usb_device_info * dev, const char * cmdline) {
|
||||||
|
|
||||||
|
int size = 0;
|
||||||
|
int mode = NOLO_BOOT_MODE_NORMAL;
|
||||||
|
|
||||||
|
if ( cmdline && strncmp(cmdline, "update", strlen("update")) == 0 && cmdline[strlen("update")] <= 32 ) {
|
||||||
|
mode = NOLO_BOOT_MODE_UPDATE;
|
||||||
|
cmdline += strlen("update");
|
||||||
|
if ( *cmdline ) ++cmdline;
|
||||||
|
while ( *cmdline && *cmdline <= 32 )
|
||||||
|
++cmdline;
|
||||||
|
if ( *cmdline ) {
|
||||||
|
printf("Booting kernel to update mode with cmdline: %s...\n", cmdline);
|
||||||
|
size = strlen(cmdline);
|
||||||
|
} else {
|
||||||
|
printf("Booting kernel to update mode with default cmdline...\n");
|
||||||
|
cmdline = NULL;
|
||||||
|
}
|
||||||
|
} else if ( cmdline && cmdline[0] ) {
|
||||||
|
printf("Booting kernel with cmdline: '%s'...\n", cmdline);
|
||||||
|
size = strlen(cmdline)+1;
|
||||||
|
} else {
|
||||||
|
printf("Booting kernel with default cmdline...\n");
|
||||||
|
cmdline = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_BOOT, mode, 0, (char *)cmdline, size, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Booting failed", -1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_reboot_device(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
printf("Rebooting device...\n");
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_REBOOT, 0, 0, NULL, 0, 2000) < 0 )
|
||||||
|
ERROR_RETURN("NOLO_REBOOT failed", -1);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_get_root_device(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
uint8_t device;
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_QUERY, NOLO_GET, 0, NOLO_ROOT_DEVICE, (char *)&device, 1, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Cannot get root device", -1);
|
||||||
|
return device;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_set_root_device(struct usb_device_info * dev, int device) {
|
||||||
|
|
||||||
|
printf("Setting root device to %d...\n", device);
|
||||||
|
if ( simulate )
|
||||||
|
return 0;
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SET, device, NOLO_ROOT_DEVICE, NULL, 0, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Cannot set root device", -1);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_get_usb_host_mode(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
uint32_t enabled;
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_QUERY, NOLO_GET, 0, NOLO_USB_HOST_MODE, (void *)&enabled, 4, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Cannot get USB host mode status", -1);
|
||||||
|
return enabled ? 1 : 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_set_usb_host_mode(struct usb_device_info * dev, int enable) {
|
||||||
|
|
||||||
|
printf("%s USB host mode...\n", enable ? "Enabling" : "Disabling");
|
||||||
|
if ( simulate )
|
||||||
|
return 0;
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SET, enable, NOLO_USB_HOST_MODE, NULL, 0, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Cannot change USB host mode status", -1);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_get_rd_mode(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
uint8_t enabled;
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_QUERY, NOLO_GET, 0, NOLO_RD_MODE, (char *)&enabled, 1, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Cannot get R&D mode status", -1);
|
||||||
|
return enabled ? 1 : 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_set_rd_mode(struct usb_device_info * dev, int enable) {
|
||||||
|
|
||||||
|
printf("%s R&D mode...\n", enable ? "Enabling" : "Disabling");
|
||||||
|
if ( simulate )
|
||||||
|
return 0;
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SET, enable, NOLO_RD_MODE, NULL, 0, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Cannot change R&D mode status", -1);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#define APPEND_STRING(ptr, buf, size, string) do { if ( (int)size > ptr-buf ) ptr += snprintf(ptr, size-(ptr-buf), "%s,", string); } while (0)
|
||||||
|
|
||||||
|
int nolo_get_rd_flags(struct usb_device_info * dev, char * flags, size_t size) {
|
||||||
|
|
||||||
|
uint16_t add_flags;
|
||||||
|
char * ptr = flags;
|
||||||
|
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_QUERY, NOLO_GET, 0, NOLO_ADD_RD_FLAGS, (char *)&add_flags, 2, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Cannot get R&D flags", -1);
|
||||||
|
|
||||||
|
if ( add_flags & NOLO_RD_FLAG_NO_OMAP_WD )
|
||||||
|
APPEND_STRING(ptr, flags, size, "no-omap-wd");
|
||||||
|
if ( add_flags & NOLO_RD_FLAG_NO_EXT_WD )
|
||||||
|
APPEND_STRING(ptr, flags, size, "no-ext-wd");
|
||||||
|
if ( add_flags & NOLO_RD_FLAG_NO_LIFEGUARD )
|
||||||
|
APPEND_STRING(ptr, flags, size, "no-lifeguard-reset");
|
||||||
|
if ( add_flags & NOLO_RD_FLAG_SERIAL_CONSOLE )
|
||||||
|
APPEND_STRING(ptr, flags, size, "serial-console");
|
||||||
|
if ( add_flags & NOLO_RD_FLAG_NO_USB_TIMEOUT )
|
||||||
|
APPEND_STRING(ptr, flags, size, "no-usb-timeout");
|
||||||
|
if ( add_flags & NOLO_RD_FLAG_STI_CONSOLE )
|
||||||
|
APPEND_STRING(ptr, flags, size, "sti-console");
|
||||||
|
if ( add_flags & NOLO_RD_FLAG_NO_CHARGING )
|
||||||
|
APPEND_STRING(ptr, flags, size, "no-charging");
|
||||||
|
if ( add_flags & NOLO_RD_FLAG_FORCE_POWER_KEY )
|
||||||
|
APPEND_STRING(ptr, flags, size, "force-power-key");
|
||||||
|
|
||||||
|
if ( ptr != flags && *(ptr-1) == ',' )
|
||||||
|
*(--ptr) = 0;
|
||||||
|
|
||||||
|
return ptr-flags;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef APPEND_STRING
|
||||||
|
|
||||||
|
int nolo_set_rd_flags(struct usb_device_info * dev, const char * flags) {
|
||||||
|
|
||||||
|
const char * ptr = flags;
|
||||||
|
const char * endptr = ptr;
|
||||||
|
|
||||||
|
int add_flags = 0;
|
||||||
|
int del_flags = 0;
|
||||||
|
|
||||||
|
if ( flags && flags[0] )
|
||||||
|
printf("Setting R&D flags to: %s...\n", flags);
|
||||||
|
else
|
||||||
|
printf("Clearing all R&D flags...\n");
|
||||||
|
|
||||||
|
while ( ptr && *ptr ) {
|
||||||
|
|
||||||
|
while ( *ptr <= 32 )
|
||||||
|
++ptr;
|
||||||
|
|
||||||
|
if ( ! *ptr )
|
||||||
|
break;
|
||||||
|
|
||||||
|
endptr = strchr(ptr, ',');
|
||||||
|
if ( endptr )
|
||||||
|
endptr -= 1;
|
||||||
|
else
|
||||||
|
endptr = ptr+strlen(ptr);
|
||||||
|
|
||||||
|
if ( strncmp("no-omap-wd", ptr, endptr-ptr) == 0 )
|
||||||
|
add_flags |= NOLO_RD_FLAG_NO_OMAP_WD;
|
||||||
|
if ( strncmp("no-ext-wd", ptr, endptr-ptr) == 0 )
|
||||||
|
add_flags |= NOLO_RD_FLAG_NO_EXT_WD;
|
||||||
|
if ( strncmp("no-lifeguard-reset", ptr, endptr-ptr) == 0 )
|
||||||
|
add_flags |= NOLO_RD_FLAG_NO_LIFEGUARD;
|
||||||
|
if ( strncmp("serial-console", ptr, endptr-ptr) == 0 )
|
||||||
|
add_flags |= NOLO_RD_FLAG_SERIAL_CONSOLE;
|
||||||
|
if ( strncmp("no-usb-timeout", ptr, endptr-ptr) == 0 )
|
||||||
|
add_flags |= NOLO_RD_FLAG_NO_USB_TIMEOUT;
|
||||||
|
if ( strncmp("sti-console", ptr, endptr-ptr) == 0 )
|
||||||
|
add_flags |= NOLO_RD_FLAG_STI_CONSOLE;
|
||||||
|
if ( strncmp("no-charging", ptr, endptr-ptr) == 0 )
|
||||||
|
add_flags |= NOLO_RD_FLAG_NO_CHARGING;
|
||||||
|
if ( strncmp("force-power-key", ptr, endptr-ptr) == 0 )
|
||||||
|
add_flags |= NOLO_RD_FLAG_FORCE_POWER_KEY;
|
||||||
|
|
||||||
|
if ( *(endptr+1) )
|
||||||
|
ptr = endptr+2;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! ( add_flags & NOLO_RD_FLAG_NO_OMAP_WD ) )
|
||||||
|
del_flags |= NOLO_RD_FLAG_NO_OMAP_WD;
|
||||||
|
if ( ! ( add_flags & NOLO_RD_FLAG_NO_EXT_WD ) )
|
||||||
|
del_flags |= NOLO_RD_FLAG_NO_EXT_WD;
|
||||||
|
if ( ! ( add_flags & NOLO_RD_FLAG_NO_LIFEGUARD ) )
|
||||||
|
del_flags |= NOLO_RD_FLAG_NO_LIFEGUARD;
|
||||||
|
if ( ! ( add_flags & NOLO_RD_FLAG_SERIAL_CONSOLE ) )
|
||||||
|
del_flags |= NOLO_RD_FLAG_SERIAL_CONSOLE;
|
||||||
|
if ( ! ( add_flags & NOLO_RD_FLAG_NO_USB_TIMEOUT ) )
|
||||||
|
del_flags |= NOLO_RD_FLAG_NO_USB_TIMEOUT;
|
||||||
|
if ( ! ( add_flags & NOLO_RD_FLAG_STI_CONSOLE ) )
|
||||||
|
del_flags |= NOLO_RD_FLAG_STI_CONSOLE;
|
||||||
|
if ( ! ( add_flags & NOLO_RD_FLAG_NO_CHARGING ) )
|
||||||
|
del_flags |= NOLO_RD_FLAG_NO_CHARGING;
|
||||||
|
if ( ! ( add_flags & NOLO_RD_FLAG_FORCE_POWER_KEY ) )
|
||||||
|
del_flags |= NOLO_RD_FLAG_FORCE_POWER_KEY;
|
||||||
|
|
||||||
|
if ( simulate )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SET, add_flags, NOLO_ADD_RD_FLAGS, NULL, 0, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Cannot add R&D flags", -1);
|
||||||
|
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SET, del_flags, NOLO_DEL_RD_FLAGS, NULL, 0, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Cannot del R&D flags", -1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t nolo_get_hwrev(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
char buf[10];
|
||||||
|
if ( nolo_identify_string(dev, "hw_rev", buf, sizeof(buf)) <= 0 )
|
||||||
|
return -1;
|
||||||
|
return atoi(buf);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_set_hwrev(struct usb_device_info * dev, int16_t hwrev) {
|
||||||
|
|
||||||
|
char buf[9];
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
snprintf(buf, 8, "%d", hwrev);
|
||||||
|
printf("Setting HW revision to: %s\n", buf);
|
||||||
|
return nolo_set_string(dev, "hw_rev", buf);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_get_kernel_ver(struct usb_device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
return nolo_get_version_string(dev, "kernel", ver, size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_set_kernel_ver(struct usb_device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
printf("nolo_set_kernel_ver is not implemented yet\n");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_get_initfs_ver(struct usb_device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
return nolo_get_version_string(dev, "initfs", ver, size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_set_initfs_ver(struct usb_device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
printf("nolo_set_initfs_ver is not implemented yet\n");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_get_nolo_ver(struct usb_device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
uint32_t version;
|
||||||
|
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_QUERY, NOLO_GET_NOLO_VERSION, 0, 0, (char *)&version, 4, 2000) < 0 )
|
||||||
|
ERROR_RETURN("Cannot get NOLO version", -1);
|
||||||
|
|
||||||
|
if ( (version & 255) > 1 )
|
||||||
|
ERROR_RETURN("Invalid NOLO version", -1);
|
||||||
|
|
||||||
|
return snprintf(ver, size, "%d.%d.%d", version >> 20 & 15, version >> 16 & 15, version >> 8 & 255);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_set_nolo_ver(struct usb_device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
printf("nolo_set_nolo_ver is not implemented yet\n");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_get_sw_ver(struct usb_device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
return nolo_get_version_string(dev, "sw-release", ver, size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_set_sw_ver(struct usb_device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
char buf[512];
|
||||||
|
char * ptr;
|
||||||
|
uint8_t len;
|
||||||
|
const char * str = "OSSO UART+USB";
|
||||||
|
|
||||||
|
printf("Setting Software release string to: %s\n", ver);
|
||||||
|
|
||||||
|
if ( strlen(ver) > UINT8_MAX )
|
||||||
|
ERROR_RETURN("Software release string is too long", -1);
|
||||||
|
|
||||||
|
ptr = buf;
|
||||||
|
|
||||||
|
memcpy(ptr, "\xe8", 1);
|
||||||
|
ptr += 1;
|
||||||
|
|
||||||
|
len = strlen(str)+1;
|
||||||
|
memcpy(ptr, &len, 1);
|
||||||
|
ptr += 1;
|
||||||
|
|
||||||
|
memcpy(ptr, str, len);
|
||||||
|
ptr += len;
|
||||||
|
|
||||||
|
memcpy(ptr, "\x31", 1);
|
||||||
|
ptr += 1;
|
||||||
|
|
||||||
|
len = strlen(ver)+1;
|
||||||
|
memcpy(ptr, &len, 1);
|
||||||
|
ptr += 1;
|
||||||
|
|
||||||
|
memcpy(ptr, ver, len);
|
||||||
|
ptr += len;
|
||||||
|
|
||||||
|
if ( usb_control_msg(dev->udev, NOLO_WRITE, NOLO_SET_SW_RELEASE, 0, 0, buf, ptr-buf, 2000) < 0 )
|
||||||
|
ERROR_RETURN("NOLO_SET_SW_RELEASE failed", -1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_get_content_ver(struct usb_device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
return nolo_get_version_string(dev, "content", ver, size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int nolo_set_content_ver(struct usb_device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
printf("nolo_set_content_ver is not implemented yet\n");
|
||||||
|
(void)dev;
|
||||||
|
(void)ver;
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
+64
-6
@@ -1,7 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
||||||
|
* Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#define NOLO_GET_STATUS 1
|
#ifndef NOLO_H
|
||||||
#define NOLO_GET_BOARD_ID 2
|
#define NOLO_H
|
||||||
#define NOLO_GET_VERSION 3
|
|
||||||
#define NOLO_GET_HWVERSION 4
|
#include "image.h"
|
||||||
#define NOLO_SET_RDFLAGS 16
|
#include "usb-device.h"
|
||||||
#define NOLO_GET_RDFLAGS 17
|
|
||||||
|
int nolo_init(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
enum device nolo_get_device(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
int nolo_load_image(struct usb_device_info * dev, struct image * image);
|
||||||
|
int nolo_flash_image(struct usb_device_info * dev, struct image * image);
|
||||||
|
int nolo_boot_device(struct usb_device_info * dev, const char * cmdline);
|
||||||
|
int nolo_reboot_device(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
int nolo_get_root_device(struct usb_device_info * dev);
|
||||||
|
int nolo_set_root_device(struct usb_device_info * dev, int device);
|
||||||
|
|
||||||
|
int nolo_get_usb_host_mode(struct usb_device_info * dev);
|
||||||
|
int nolo_set_usb_host_mode(struct usb_device_info * dev, int enable);
|
||||||
|
|
||||||
|
int nolo_get_rd_mode(struct usb_device_info * dev);
|
||||||
|
int nolo_set_rd_mode(struct usb_device_info * dev, int enable);
|
||||||
|
|
||||||
|
int nolo_get_rd_flags(struct usb_device_info * dev, char * flags, size_t size);
|
||||||
|
int nolo_set_rd_flags(struct usb_device_info * dev, const char * flags);
|
||||||
|
|
||||||
|
int16_t nolo_get_hwrev(struct usb_device_info * dev);
|
||||||
|
int nolo_set_hwrev(struct usb_device_info * dev, int16_t hwrev);
|
||||||
|
|
||||||
|
int nolo_get_kernel_ver(struct usb_device_info * dev, char * ver, size_t size);
|
||||||
|
int nolo_set_kernel_ver(struct usb_device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int nolo_get_initfs_ver(struct usb_device_info * dev, char * ver, size_t size);
|
||||||
|
int nolo_set_initfs_ver(struct usb_device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int nolo_get_nolo_ver(struct usb_device_info * dev, char * ver, size_t size);
|
||||||
|
int nolo_set_nolo_ver(struct usb_device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int nolo_get_sw_ver(struct usb_device_info * dev, char * ver, size_t size);
|
||||||
|
int nolo_set_sw_ver(struct usb_device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int nolo_get_content_ver(struct usb_device_info * dev, char * ver, size_t size);
|
||||||
|
int nolo_set_content_ver(struct usb_device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,639 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
#include "device.h"
|
||||||
|
#include "usb-device.h"
|
||||||
|
#include "cold-flash.h"
|
||||||
|
#include "nolo.h"
|
||||||
|
#include "mkii.h"
|
||||||
|
#include "disk.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
|
#include "operations.h"
|
||||||
|
|
||||||
|
struct device_info * dev_detect(void) {
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
|
struct device_info * dev = NULL;
|
||||||
|
struct usb_device_info * usb = NULL;
|
||||||
|
|
||||||
|
dev = calloc(1, sizeof(struct device_info));
|
||||||
|
if ( ! dev )
|
||||||
|
goto clean;
|
||||||
|
|
||||||
|
/* LOCAL */
|
||||||
|
if ( local_init() == 0 ) {
|
||||||
|
dev->method = METHOD_LOCAL;
|
||||||
|
dev->detected_device = local_get_device();
|
||||||
|
dev->detected_hwrev = local_get_hwrev();
|
||||||
|
return dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* USB */
|
||||||
|
usb = usb_open_and_wait_for_device();
|
||||||
|
if ( usb ) {
|
||||||
|
dev->method = METHOD_USB;
|
||||||
|
dev->usb = usb;
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
ret = nolo_init(dev->usb);
|
||||||
|
else if ( dev->usb->flash_device->protocol == FLASH_COLD )
|
||||||
|
ret = init_cold_flash(dev->usb);
|
||||||
|
else if ( dev->usb->flash_device->protocol == FLASH_MKII )
|
||||||
|
ret = mkii_init(dev->usb);
|
||||||
|
else if ( dev->usb->flash_device->protocol == FLASH_DISK )
|
||||||
|
ret = disk_init(dev->usb);
|
||||||
|
else {
|
||||||
|
ERROR("Unknown USB mode");
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ret < 0 )
|
||||||
|
goto clean;
|
||||||
|
|
||||||
|
dev->detected_device = dev_get_device(dev);
|
||||||
|
dev->detected_hwrev = dev_get_hwrev(dev);
|
||||||
|
|
||||||
|
if ( dev->detected_device && dev->usb->device && dev->detected_device != dev->usb->device ) {
|
||||||
|
ERROR("Bad device, expected %s, got %s", device_to_string(dev->usb->device), device_to_string(dev->detected_device));
|
||||||
|
goto clean;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
usb_close_device(usb);
|
||||||
|
free(dev);
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void dev_free(struct device_info * dev) {
|
||||||
|
|
||||||
|
if ( dev->usb )
|
||||||
|
usb_close_device(dev->usb);
|
||||||
|
free(dev);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
enum device dev_get_device(struct device_info * dev) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_get_device();
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
enum usb_flash_protocol protocol = dev->usb->flash_device->protocol;
|
||||||
|
|
||||||
|
if ( protocol == FLASH_COLD )
|
||||||
|
return DEVICE_UNKNOWN;
|
||||||
|
else if ( protocol == FLASH_NOLO )
|
||||||
|
return nolo_get_device(dev->usb);
|
||||||
|
else if ( protocol == FLASH_MKII )
|
||||||
|
return mkii_get_device(dev->usb);
|
||||||
|
/* else if ( protocol == FLASH_DISK )
|
||||||
|
return disk_get_device(dev->usb);*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return DEVICE_UNKNOWN;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_load_image(struct device_info * dev, struct image * image) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL ) {
|
||||||
|
ERROR("Loading image on local device is not supported");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
enum usb_flash_protocol protocol = dev->usb->flash_device->protocol;
|
||||||
|
|
||||||
|
if ( protocol == FLASH_NOLO )
|
||||||
|
return nolo_load_image(dev->usb, image);
|
||||||
|
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_cold_flash_images(struct device_info * dev, struct image * x2nd, struct image * secondary) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL ) {
|
||||||
|
ERROR("Cold Flashing on local device is not supported");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
enum usb_flash_protocol protocol = dev->usb->flash_device->protocol;
|
||||||
|
|
||||||
|
if ( protocol == FLASH_COLD )
|
||||||
|
return cold_flash(dev->usb, x2nd, secondary);
|
||||||
|
|
||||||
|
usb_switch_to_cold(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_flash_image(struct device_info * dev, struct image * image) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_flash_image(image);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
enum usb_flash_protocol protocol = dev->usb->flash_device->protocol;
|
||||||
|
|
||||||
|
if ( protocol == FLASH_NOLO )
|
||||||
|
return nolo_flash_image(dev->usb, image);
|
||||||
|
else if ( protocol == FLASH_MKII )
|
||||||
|
return mkii_flash_image(dev->usb, image);
|
||||||
|
else {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_dump_image(struct device_info * dev, enum image_type image, const char * file) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_dump_image(image, file);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
ERROR("Dump image via USB is not supported");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_check_badblocks(struct device_info * dev, const char * device) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_check_badblocks(device);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
ERROR("Check for badblocks via USB is not supported");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_boot_device(struct device_info * dev, const char * cmdline) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL ) {
|
||||||
|
ERROR("Booting device on local device does not make sense");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
enum usb_flash_protocol protocol = dev->usb->flash_device->protocol;
|
||||||
|
|
||||||
|
if ( protocol == FLASH_NOLO )
|
||||||
|
return nolo_boot_device(dev->usb, cmdline);
|
||||||
|
else {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_reboot_device(struct device_info * dev) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_reboot_device();
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
enum usb_flash_protocol protocol = dev->usb->flash_device->protocol;
|
||||||
|
|
||||||
|
if ( protocol == FLASH_COLD )
|
||||||
|
return leave_cold_flash(dev->usb);
|
||||||
|
else if ( protocol == FLASH_NOLO )
|
||||||
|
return nolo_reboot_device(dev->usb);
|
||||||
|
else if ( protocol == FLASH_MKII )
|
||||||
|
return mkii_reboot_device(dev->usb);
|
||||||
|
else {
|
||||||
|
ERROR("Rebooting device in RAW disk mode is not supported");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_get_root_device(struct device_info * dev) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_get_root_device();
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
enum usb_flash_protocol protocol = dev->usb->flash_device->protocol;
|
||||||
|
|
||||||
|
if ( protocol == FLASH_NOLO )
|
||||||
|
return nolo_get_root_device(dev->usb);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_set_root_device(struct device_info * dev, int device) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_set_root_device(device);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_set_root_device(dev->usb, device);
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_COLD ) {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_get_usb_host_mode(struct device_info * dev) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_get_usb_host_mode();
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_get_usb_host_mode(dev->usb);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_set_usb_host_mode(struct device_info * dev, int enable) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_set_usb_host_mode(enable);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_set_usb_host_mode(dev->usb, enable);
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_COLD ) {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_get_rd_mode(struct device_info * dev) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_get_rd_mode();
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_get_rd_mode(dev->usb);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_set_rd_mode(struct device_info * dev, int enable) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_set_rd_mode(enable);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_set_rd_mode(dev->usb, enable);
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_COLD ) {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_get_rd_flags(struct device_info * dev, char * flags, size_t size) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_get_rd_flags(flags, size);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_get_rd_flags(dev->usb, flags, size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_set_rd_flags(struct device_info * dev, const char * flags) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_set_rd_flags(flags);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_set_rd_flags(dev->usb, flags);
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_COLD ) {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t dev_get_hwrev(struct device_info * dev) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_get_hwrev();
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_get_hwrev(dev->usb);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_set_hwrev(struct device_info * dev, int16_t hwrev) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_set_hwrev(hwrev);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_set_hwrev(dev->usb, hwrev);
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_COLD ) {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_get_kernel_ver(struct device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_get_kernel_ver(ver, size);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_get_kernel_ver(dev->usb, ver, size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_set_kernel_ver(struct device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_set_kernel_ver(ver);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_set_kernel_ver(dev->usb, ver);
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_COLD ) {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_get_initfs_ver(struct device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_get_initfs_ver(ver, size);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_get_initfs_ver(dev->usb, ver, size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_set_initfs_ver(struct device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_set_initfs_ver(ver);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_set_initfs_ver(dev->usb, ver);
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_COLD ) {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_get_nolo_ver(struct device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_get_nolo_ver(ver, size);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_get_nolo_ver(dev->usb, ver, size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_set_nolo_ver(struct device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_set_nolo_ver(ver);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_set_nolo_ver(dev->usb, ver);
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_COLD ) {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_get_sw_ver(struct device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_get_sw_ver(ver, size);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_get_sw_ver(dev->usb, ver, size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_set_sw_ver(struct device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_set_sw_ver(ver);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_set_sw_ver(dev->usb, ver);
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_COLD ) {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_get_content_ver(struct device_info * dev, char * ver, size_t size) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_get_content_ver(ver, size);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_get_content_ver(dev->usb, ver, size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int dev_set_content_ver(struct device_info * dev, const char * ver) {
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_LOCAL )
|
||||||
|
return local_set_content_ver(ver);
|
||||||
|
|
||||||
|
if ( dev->method == METHOD_USB ) {
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_NOLO )
|
||||||
|
return nolo_set_content_ver(dev->usb, ver);
|
||||||
|
|
||||||
|
if ( dev->usb->flash_device->protocol == FLASH_COLD ) {
|
||||||
|
usb_switch_to_nolo(dev->usb);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OPERATIONS_H
|
||||||
|
#define OPERATIONS_H
|
||||||
|
|
||||||
|
#include "image.h"
|
||||||
|
#include "usb-device.h"
|
||||||
|
|
||||||
|
enum connection_method {
|
||||||
|
METHOD_UNKNOWN = 0,
|
||||||
|
METHOD_USB,
|
||||||
|
METHOD_LOCAL,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct device_info {
|
||||||
|
enum connection_method method;
|
||||||
|
enum device detected_device;
|
||||||
|
int16_t detected_hwrev;
|
||||||
|
struct usb_device_info * usb;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct device_info * dev_detect(void);
|
||||||
|
void dev_free(struct device_info * dev);
|
||||||
|
|
||||||
|
enum device dev_get_device(struct device_info * dev);
|
||||||
|
|
||||||
|
int dev_cold_flash_images(struct device_info * dev, struct image * x2nd, struct image * secondary);
|
||||||
|
int dev_load_image(struct device_info * dev, struct image * image);
|
||||||
|
int dev_flash_image(struct device_info * dev, struct image * image);
|
||||||
|
int dev_dump_image(struct device_info * dev, enum image_type image, const char * file);
|
||||||
|
int dev_check_badblocks(struct device_info * dev, const char * device);
|
||||||
|
|
||||||
|
int dev_boot_device(struct device_info * dev, const char * cmdline);
|
||||||
|
int dev_reboot_device(struct device_info * dev);
|
||||||
|
|
||||||
|
int dev_get_root_device(struct device_info * dev);
|
||||||
|
int dev_set_root_device(struct device_info * dev, int device);
|
||||||
|
|
||||||
|
int dev_get_usb_host_mode(struct device_info * dev);
|
||||||
|
int dev_set_usb_host_mode(struct device_info * dev, int enable);
|
||||||
|
|
||||||
|
int dev_get_rd_mode(struct device_info * dev);
|
||||||
|
int dev_set_rd_mode(struct device_info * dev, int enable);
|
||||||
|
|
||||||
|
int dev_get_rd_flags(struct device_info * dev, char * flags, size_t size);
|
||||||
|
int dev_set_rd_flags(struct device_info * dev, const char * flags);
|
||||||
|
|
||||||
|
int16_t dev_get_hwrev(struct device_info * dev);
|
||||||
|
int dev_set_hwrev(struct device_info * dev, int16_t hwrev);
|
||||||
|
|
||||||
|
int dev_get_kernel_ver(struct device_info * dev, char * ver, size_t size);
|
||||||
|
int dev_set_kernel_ver(struct device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int dev_get_initfs_ver(struct device_info * dev, char * ver, size_t size);
|
||||||
|
int dev_set_initfs_ver(struct device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int dev_get_nolo_ver(struct device_info * dev, char * ver, size_t size);
|
||||||
|
int dev_set_nolo_ver(struct device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int dev_get_sw_ver(struct device_info * dev, char * ver, size_t size);
|
||||||
|
int dev_set_sw_ver(struct device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
int dev_get_content_ver(struct device_info * dev, char * ver, size_t size);
|
||||||
|
int dev_set_content_ver(struct device_info * dev, const char * ver);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#ifndef _OS_H_
|
|
||||||
#define _OS_H_
|
|
||||||
|
|
||||||
#if __linux__ || __NetBSD__ || __FreBSD__ || __OpenBSD__ || __Darwin__ || __MacOSX__
|
|
||||||
#define HAVE_SQUEUE 1
|
|
||||||
#else
|
|
||||||
#define HAVE_SQUEUE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAVE_SQUEUE
|
|
||||||
|
|
||||||
#include "squeue/squeue.h"
|
|
||||||
extern int qmode;
|
|
||||||
extern struct squeue_t *p;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
|
||||||
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
|
||||||
*
|
|
||||||
* 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 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
int pcs_n = 0;
|
|
||||||
struct piece_t pcs[10];
|
|
||||||
|
|
||||||
int add_piece(char *piece)
|
|
||||||
{
|
|
||||||
int i,ok = 0;
|
|
||||||
char *file;
|
|
||||||
|
|
||||||
if (pcs_n==9) {
|
|
||||||
fprintf(stderr, "Oops...cannot add more pieces. no sense operation!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
file = strchr(piece, '%');
|
|
||||||
if (file) {
|
|
||||||
file[0]='\0';
|
|
||||||
file = file + 1;
|
|
||||||
for(i=0;pieces[i];i++)
|
|
||||||
if (!strcmp(pieces[i], piece))
|
|
||||||
ok = 1;
|
|
||||||
if (!ok) {
|
|
||||||
printf("Invalid piece name.\n");
|
|
||||||
printf("Pieces: ");
|
|
||||||
for(i=0;pieces[i];i++)
|
|
||||||
printf("%s ", pieces[i]);
|
|
||||||
printf("\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
pcs[pcs_n].name = strdup(file);
|
|
||||||
pcs[pcs_n].type = strdup(piece);
|
|
||||||
pcs[pcs_n].vers = NULL; // TODO version string not yet supported
|
|
||||||
} else {
|
|
||||||
/*/ autodetect piece type */
|
|
||||||
pcs[pcs_n].type = (char *)fpid_file(piece);
|
|
||||||
if (pcs[pcs_n].type == NULL) {
|
|
||||||
printf("Use -p [piece]:[file]\n");
|
|
||||||
printf("Pieces: ");
|
|
||||||
for(i=0;pieces[i];i++)
|
|
||||||
printf("%s ", pieces[i]);
|
|
||||||
printf("\n");
|
|
||||||
exit(1);
|
|
||||||
} else {
|
|
||||||
pcs[pcs_n].name = strdup(piece);
|
|
||||||
pcs[pcs_n].type = strdup(pcs[pcs_n].type);
|
|
||||||
pcs[pcs_n].vers = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pcs_n++;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
||||||
|
* Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -16,28 +17,19 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
unsigned long get_file_size(const char *file)
|
#include "global.h"
|
||||||
{
|
|
||||||
FILE *fd = fopen(file, "r");
|
#include "printf-utils.h"
|
||||||
unsigned long len = 0;
|
|
||||||
if (fd == NULL) {
|
int printf_prev = 0;
|
||||||
fprintf(stderr, "Cannot open file '%s'\n", file);
|
|
||||||
exit(1);
|
void printf_progressbar(unsigned long long part, unsigned long long total) {
|
||||||
}
|
|
||||||
fseek(fd, 0, SEEK_END);
|
|
||||||
len = ftell(fd);
|
|
||||||
fclose(fd);
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
void progressbar(unsigned long long part, unsigned long long total)
|
|
||||||
{
|
|
||||||
char *columns = getenv("COLUMNS");
|
char *columns = getenv("COLUMNS");
|
||||||
int pc;
|
int pc;
|
||||||
int tmp, cols = 80;
|
int tmp, cols = 80;
|
||||||
@@ -53,24 +45,52 @@ void progressbar(unsigned long long part, unsigned long long total)
|
|||||||
squeue_push2(p, "bar", msg, 0);
|
squeue_push2(p, "bar", msg, 0);
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
printf("\x1b[K %3d%% [", pc);
|
PRINTF_BACK();
|
||||||
|
PRINTF_ADD("\x1b[K %3d%% [", pc);
|
||||||
if (columns)
|
if (columns)
|
||||||
cols = atoi(columns);
|
cols = atoi(columns);
|
||||||
|
if (cols > 115)
|
||||||
|
cols = 115;
|
||||||
cols-=15;
|
cols-=15;
|
||||||
for(tmp=cols*pc/100;tmp;tmp--) printf("#");
|
for(tmp=cols*pc/100;tmp;tmp--) PRINTF_ADD("#");
|
||||||
for(tmp=cols-(cols*pc/100);tmp;tmp--) printf("-");
|
for(tmp=cols-(cols*pc/100);tmp;tmp--) PRINTF_ADD("-");
|
||||||
printf("]\r");
|
PRINTF_ADD("]");
|
||||||
|
if (part == total) PRINTF_END();
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#if HAVE_SQUEUE
|
#if HAVE_SQUEUE
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void eprintf(const char *format, ...)
|
void printf_and_wait(const char * format, ...) {
|
||||||
{
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
char c;
|
||||||
|
fd_set rfds;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
|
FD_ZERO(&rfds);
|
||||||
|
FD_SET(0, &rfds);
|
||||||
|
|
||||||
|
while ( select(1, &rfds, NULL, NULL, &tv) == 1 )
|
||||||
|
read(0, &c, 1);
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
vfprintf(stderr, format, ap);
|
vprintf(format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
//fflush(stderr); // XXX CRASH?!? stdin here?!?!?
|
fflush(stdout);
|
||||||
|
|
||||||
|
FD_ZERO(&rfds);
|
||||||
|
FD_SET(0, &rfds);
|
||||||
|
|
||||||
|
while ( select(1, &rfds, NULL, NULL, NULL) == 1 ) {
|
||||||
|
read(0, &c, 1);
|
||||||
|
if ( c == '\n' )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
||||||
|
* Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PRINTF_UTILS_H
|
||||||
|
#define PRINTF_UTILS_H
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
extern int printf_prev;
|
||||||
|
|
||||||
|
#define PRINTF_BACK() do { if ( printf_prev ) { printf("\r%-*s\r", printf_prev, ""); printf_prev = 0; } } while (0)
|
||||||
|
#define PRINTF_ADD(...) do { printf_prev += printf(__VA_ARGS__); } while (0)
|
||||||
|
#define PRINTF_LINE(...) do { PRINTF_BACK(); PRINTF_ADD(__VA_ARGS__); fflush(stdout); } while (0)
|
||||||
|
#define PRINTF_END() do { if ( printf_prev ) { printf("\n"); printf_prev = 0; } } while (0)
|
||||||
|
#define PRINTF_ERROR(...) do { PRINTF_END(); ERROR_INFO(__VA_ARGS__); } while (0)
|
||||||
|
#define PRINTF_ERROR_RETURN(str, ...) do { PRINTF_ERROR("%s", str); return __VA_ARGS__; } while (0)
|
||||||
|
|
||||||
|
void printf_progressbar(unsigned long long part, unsigned long long total);
|
||||||
|
void printf_and_wait(const char * format, ...);
|
||||||
|
|
||||||
|
#endif
|
||||||
+37
-22
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
* Copyright (C) 2008 pancake <pancake@youterm.com>
|
* Copyright (C) 2008 pancake <pancake@youterm.com>
|
||||||
|
* Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -16,30 +17,43 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "os.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
#include "qmode.h"
|
||||||
|
#include "nolo.h"
|
||||||
|
|
||||||
|
#if HAVE_SQUEUE
|
||||||
|
|
||||||
|
#include "squeue/squeue.h"
|
||||||
|
extern int qmode;
|
||||||
|
extern struct squeue_t *p;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAVE_SQUEUE
|
#if HAVE_SQUEUE
|
||||||
|
|
||||||
struct squeue_t *q;
|
struct squeue_t *q;
|
||||||
struct squeue_t *p;
|
struct squeue_t *p;
|
||||||
|
|
||||||
int fork_enabled = 0;
|
static int fork_enabled = 0;
|
||||||
int dofork()
|
static int dofork()
|
||||||
{
|
{
|
||||||
if (fork_enabled)
|
if (fork_enabled)
|
||||||
return fork();
|
return fork();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_message(char *msg)
|
static void process_message(char *msg)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
char *arg;
|
char *arg;
|
||||||
@@ -52,24 +66,24 @@ void process_message(char *msg)
|
|||||||
if (c!=0) {
|
if (c!=0) {
|
||||||
arg[0]='\0';
|
arg[0]='\0';
|
||||||
arg = arg +1;
|
arg = arg +1;
|
||||||
if (!strcmp(str, "flash")) {
|
/* if (!strcmp(str, "flash")) {
|
||||||
const char *type = fpid_file(arg);
|
const char *type = fpid_file(arg);
|
||||||
if (type == NULL) {
|
if (type == NULL) {
|
||||||
squeue_push2(p, "error", "Unknown piece format", 1);
|
squeue_push2(p, "error", "Unknown piece format", 1);
|
||||||
} else flash_image(arg, type, NULL);
|
} else flash_image(arg, type, NULL, NULL, NULL);
|
||||||
} else
|
} else*/
|
||||||
if (!strcmp(str, "reset")) {
|
if (!strcmp(str, "reset")) {
|
||||||
if (reboot_board() == 0) {
|
// if (reboot_board() == 0) {
|
||||||
squeue_push2(p,"info", "Device reboots", 1);
|
// squeue_push2(p,"info", "Device reboots", 1);
|
||||||
} else squeue_push2(p,"error", "Cannot reboot device", 1);
|
// } else squeue_push2(p,"error", "Cannot reboot device", 1);
|
||||||
} else
|
} else
|
||||||
if (!strcmp(str, "info")) {
|
if (!strcmp(str, "info")) {
|
||||||
get_rd_flags();
|
// get_rd_flags();
|
||||||
squeue_push2(p, "info", strbuf, 1);
|
// squeue_push2(p, "info", strbuf, 1);
|
||||||
get_nolo_version();
|
// get_nolo_version();
|
||||||
squeue_push2(p, "info", strbuf, 1);
|
// squeue_push2(p, "info", strbuf, 1);
|
||||||
get_usb_mode();
|
// get_usb_mode();
|
||||||
squeue_push2(p, "info", strbuf, 1);
|
// squeue_push2(p, "info", strbuf, 1);
|
||||||
} else
|
} else
|
||||||
squeue_push2(p, "error", "invalid command", 0);
|
squeue_push2(p, "error", "invalid command", 0);
|
||||||
} else {
|
} else {
|
||||||
@@ -78,7 +92,7 @@ void process_message(char *msg)
|
|||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cc()
|
static void cc(int signum)
|
||||||
{
|
{
|
||||||
squeue_close(p);
|
squeue_close(p);
|
||||||
squeue_close(q);
|
squeue_close(q);
|
||||||
@@ -88,7 +102,7 @@ static void cc()
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int queue_mode()
|
int queue_mode(void)
|
||||||
{
|
{
|
||||||
int pid = 0;
|
int pid = 0;
|
||||||
char *msg;
|
char *msg;
|
||||||
@@ -116,11 +130,11 @@ int queue_mode()
|
|||||||
} else {
|
} else {
|
||||||
do {
|
do {
|
||||||
#if HAVE_USB
|
#if HAVE_USB
|
||||||
if (connect_via_usb()) {
|
/* if (connect_via_usb()) {
|
||||||
fprintf(stderr, "Cannot connect to device. It is possibly not in boot stage.\n");
|
fprintf(stderr, "Cannot connect to device. It is possibly not in boot stage.\n");
|
||||||
squeue_push2(p, "error", "Cannot connect to the device", 1);
|
squeue_push2(p, "error", "Cannot connect to the device", 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}*/
|
||||||
#endif
|
#endif
|
||||||
printf("Waiting for a client in shared queues..\n");
|
printf("Waiting for a client in shared queues..\n");
|
||||||
setsid();
|
setsid();
|
||||||
@@ -138,9 +152,10 @@ int queue_mode()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int queue_mode()
|
int queue_mode(void)
|
||||||
{
|
{
|
||||||
/* dummy */
|
/* dummy */
|
||||||
fprintf(stderr, "No HAVE_SQUEUE support\n");
|
fprintf(stderr, "No HAVE_SQUEUE support\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
* Copyright (C) 2008 pancake <pancake@youterm.com>
|
||||||
|
* Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef QMODE_H
|
||||||
|
#define QMODE_H
|
||||||
|
|
||||||
|
int queue_mode(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
-367
@@ -1,367 +0,0 @@
|
|||||||
/*
|
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
|
||||||
* Copyright (C) 2007,2008 pancake <@youterm.com>
|
|
||||||
*
|
|
||||||
* 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 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if HAVE_USB
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <usb.h>
|
|
||||||
|
|
||||||
char strbuf[1024];
|
|
||||||
|
|
||||||
/* wait for status = 0 */
|
|
||||||
int get_status()
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
if (usb_control_msg(dev, CMD_QUERY, 1, 0, 0, (char *)&ret, 4, 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot get device status.\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* request type: CMD_WRITE
|
|
||||||
* request : 16
|
|
||||||
* value : 0|1 (=> client|host)
|
|
||||||
* index : 2
|
|
||||||
*/
|
|
||||||
int set_usb_mode(unsigned int mode)
|
|
||||||
{
|
|
||||||
if (mode > 1)
|
|
||||||
{
|
|
||||||
printf("Invalid USB mode specified '%d'.\n", mode);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, 16, mode, 2, 0, 0, 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot set USB mode.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Set USB mode to: '%s'.\n", (mode) ? "host" : "client");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* request type: CMD_QUERY
|
|
||||||
* request : 17
|
|
||||||
* index : 2
|
|
||||||
*
|
|
||||||
* return value: 0|1 (=> client|host)
|
|
||||||
*/
|
|
||||||
int get_usb_mode()
|
|
||||||
{
|
|
||||||
unsigned short mode = 0;
|
|
||||||
|
|
||||||
if (usb_control_msg(dev, CMD_QUERY, 17, 0, 2, (void *) &mode, sizeof(mode), 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot query device.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(strbuf, "Device's USB mode is '%s'\n", (mode) ? "host" : "client");
|
|
||||||
printf(strbuf);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Boots the Kernel with the given command-line.
|
|
||||||
*/
|
|
||||||
int boot_board(char *cmdline)
|
|
||||||
{
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, 130, 0, 0, cmdline, strlen(cmdline), 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot boot kernel.\n");
|
|
||||||
perror("boot_board");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Booting kernel with arguments: '%s'.\n", cmdline);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Reboots the omap mobo.
|
|
||||||
*/
|
|
||||||
int reboot_board()
|
|
||||||
{
|
|
||||||
// 131 = reboot
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, 131, 0, 0, 0, 0, 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot reboot board.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Mobo rebooted!\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int set_rd_mode(unsigned short mode)
|
|
||||||
{
|
|
||||||
if (((short)mode)==-1)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, NOLO_SET_RDFLAGS, mode, 0, 0, 0, 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot set R&D flags.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("rd mode changed to %s\n", mode?"on":"off");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* query root device
|
|
||||||
*/
|
|
||||||
int get_hw_revision(char *str, int len)
|
|
||||||
{
|
|
||||||
unsigned char string[512];
|
|
||||||
char tmpstr[64];
|
|
||||||
int i = 0, j=0, mod=0;
|
|
||||||
|
|
||||||
if (str == NULL)
|
|
||||||
str = tmpstr;
|
|
||||||
memset(string,'\0',512);
|
|
||||||
if (usb_control_msg(dev, CMD_QUERY, NOLO_GET_HWVERSION, 0, 0, (char *)string, 512, 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot query hw revision.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i=0;i<44&&i<len;i++) { // XXX ??
|
|
||||||
if (string[i]>19) {
|
|
||||||
if (i>0 && string[i-1]<19)
|
|
||||||
str[j++] = (++mod%2)?':':',';
|
|
||||||
str[j++] = string[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("HW revision string: '%s'\n", str);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_rd_mode()
|
|
||||||
{
|
|
||||||
char isrd = 1;
|
|
||||||
|
|
||||||
strbuf[0]='\0';
|
|
||||||
if (usb_control_msg(dev, CMD_QUERY, NOLO_GET_RDFLAGS, 0, 0, (char *)&isrd, 1, 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot query rd mode.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
sprintf(strbuf, "RD mode is: %s\n", isrd?"on":"off");
|
|
||||||
|
|
||||||
return isrd;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_root_device()
|
|
||||||
{
|
|
||||||
unsigned char opcode;
|
|
||||||
|
|
||||||
strbuf[0] = '\0';
|
|
||||||
if (usb_control_msg(dev, CMD_QUERY, NOLO_GET_RDFLAGS, 0, 1, (char *)&opcode, 1, 2000) < 0) {
|
|
||||||
fprintf(stderr, "Cannot query root device\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opcode>2) { // use sizeof || enum
|
|
||||||
fprintf(stderr, "Invalid root device received from the device '%d'.\n", opcode);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(strbuf, "Root device is: %s\n", root_devices[opcode]);
|
|
||||||
printf(strbuf);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* request type: CMD_WRITE
|
|
||||||
* request : 16
|
|
||||||
* value : 0|1|2 (=> flash|mmc|usb)
|
|
||||||
* index : 1
|
|
||||||
*/
|
|
||||||
int set_root_device(unsigned short root_device)
|
|
||||||
{
|
|
||||||
if (root_device>2) {
|
|
||||||
printf("Invalid root device specified '%d'.\n", root_device);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, NOLO_SET_RDFLAGS, root_device, 1, 0, 0, 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot set root device\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Root device set to: %s\n", root_devices[root_device]);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set flags:
|
|
||||||
* request type: CMD_WRITE
|
|
||||||
* request : 16
|
|
||||||
* value : flags to set, see below
|
|
||||||
* index : 3
|
|
||||||
*
|
|
||||||
* Clear flags:
|
|
||||||
* request type: CMD_WRITE
|
|
||||||
* request : 16
|
|
||||||
* value : flags to clear, see below
|
|
||||||
* index : 4
|
|
||||||
|
|
||||||
* Flags are composed of:
|
|
||||||
* 0x02 - disable OMAP watchdog (possibly)
|
|
||||||
* 0x04 - disable RETU watchdog (possibly)
|
|
||||||
* 0x08 - disable lifeguard reset
|
|
||||||
* 0x10 - enable serial console
|
|
||||||
* 0x20 - disable USB timeout
|
|
||||||
*
|
|
||||||
* The function encapsule the NOLO API in a way that it works like
|
|
||||||
* a chmod 707. The bits that are not set will be cleared after the
|
|
||||||
* call. This is done by issuing a 'clear flags' command with all the
|
|
||||||
* non set bits.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int set_rd_flags(unsigned short flags)
|
|
||||||
{
|
|
||||||
unsigned short reverse_flags = 0;
|
|
||||||
|
|
||||||
if (flags & ~(0x02 | 0x04 | 0x08 | 0x10 | 0x20)) {
|
|
||||||
printf("Invalid rd flags specified '%x'.\n", flags);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(flags & 0x02))
|
|
||||||
reverse_flags |= 0x02;
|
|
||||||
|
|
||||||
if (!(flags & 0x04))
|
|
||||||
reverse_flags |= 0x04;
|
|
||||||
|
|
||||||
if (!(flags & 0x08))
|
|
||||||
reverse_flags |= 0x08;
|
|
||||||
|
|
||||||
if (!(flags & 0x10))
|
|
||||||
reverse_flags |= 0x10;
|
|
||||||
|
|
||||||
if (!(flags & 0x20))
|
|
||||||
reverse_flags |= 0x20;
|
|
||||||
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, 16, flags, 3, 0, 0, 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot set rd flags\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usb_control_msg(dev, CMD_WRITE, 16, reverse_flags, 4, 0, 0, 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot set rd flags\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Set rd flags successfully!\n");
|
|
||||||
printf("disable OMAP watchdog : %s\n", (flags & 0x02) ? "set" : "not set");
|
|
||||||
printf("disable RETU watchdog : %s\n", (flags & 0x04) ? "set" : "not set");
|
|
||||||
printf("disable lifeguard reset: %s\n", (flags & 0x08) ? "set" : "not set");
|
|
||||||
printf("enable serial console : %s\n", (flags & 0x10) ? "set" : "not set");
|
|
||||||
printf("disable USB timeout : %s\n", (flags & 0x20) ? "set" : "not set");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_rd_flags()
|
|
||||||
{
|
|
||||||
unsigned short flags = 0;
|
|
||||||
|
|
||||||
if (usb_control_msg(dev, CMD_QUERY, NOLO_GET_RDFLAGS, 0, 3, (void *) &flags, sizeof(flags), 2000) == -1) {
|
|
||||||
fprintf(stderr, "Cannot get rd flags\n");
|
|
||||||
sprintf(strbuf, "error: Cannot read rd flags\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(strbuf,
|
|
||||||
"Current rd flag setting:\n"
|
|
||||||
"disable OMAP watchdog : %s\n"
|
|
||||||
"disable RETU watchdog : %s\n"
|
|
||||||
"disable lifeguard reset: %s\n"
|
|
||||||
"enable serial console : %s\n"
|
|
||||||
"disable USB timeout : %s\n"
|
|
||||||
, (flags & 0x02) ? "set" : "not set"
|
|
||||||
, (flags & 0x04) ? "set" : "not set"
|
|
||||||
, (flags & 0x08) ? "set" : "not set"
|
|
||||||
, (flags & 0x10) ? "set" : "not set"
|
|
||||||
, (flags & 0x20) ? "set" : "not set");
|
|
||||||
printf(strbuf);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int get_nolo_version()
|
|
||||||
{
|
|
||||||
unsigned int version; // ensure uint is at least 32 bits
|
|
||||||
|
|
||||||
//if (usb_control_msg(dev, CMD_QUERY, 3, 0, 1, (char *)&version, 4 , 2000) < 0) {
|
|
||||||
if (usb_control_msg(dev, CMD_QUERY, NOLO_GET_VERSION, 0, 0, (char *)&version, 4 , 2000) < 0) {
|
|
||||||
fprintf(stderr, "Cannot query nolo version. Old bootloader version?\n");
|
|
||||||
sprintf(strbuf, "error: Cannot query nolo version. Old bootloader?");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(strbuf,
|
|
||||||
"NOLO Version %d.%d.%d\n",
|
|
||||||
version >> 20 & 15,
|
|
||||||
version >> 16 & 15,
|
|
||||||
version >> 8 & 255);
|
|
||||||
|
|
||||||
if ((version & 255)> 1)
|
|
||||||
printf("Invalid API version (%d)\n", version&255);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int get_sw_version()
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
char bytes[1024];
|
|
||||||
|
|
||||||
strcpy(bytes, "version:sw-release");
|
|
||||||
ret = usb_control_msg(dev, CMD_WRITE, 18, 0, 0, (char *)&bytes, 18, 2000);
|
|
||||||
if (ret<0) {
|
|
||||||
fprintf(stderr, "error: cannot write query 18\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
bytes[0]='\0';
|
|
||||||
ret = usb_control_msg(dev, CMD_QUERY, 20, 0, 0, (char *)&bytes, 512, 2000);
|
|
||||||
if (ret<0) {
|
|
||||||
fprintf(stderr, "error: b0rken swversion read!\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (bytes[0]) {
|
|
||||||
sprintf(strbuf, "Software Version: %s\n", bytes);
|
|
||||||
printf("Software Version: %s\n", bytes); //???+strlen(bytes)+1));
|
|
||||||
} else
|
|
||||||
printf("No software version detected\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
-28
@@ -1,28 +0,0 @@
|
|||||||
#ifndef QUERY_H_
|
|
||||||
#define QUERY_H_
|
|
||||||
|
|
||||||
int boot_board(char *cmdline);
|
|
||||||
|
|
||||||
int reboot_board();
|
|
||||||
|
|
||||||
int get_status();
|
|
||||||
|
|
||||||
int get_usb_mode();
|
|
||||||
int set_usb_mode(unsigned int);
|
|
||||||
|
|
||||||
int get_rd_mode();
|
|
||||||
int set_rd_mode(unsigned short mode);
|
|
||||||
|
|
||||||
int get_rd_flags();
|
|
||||||
int set_rd_flags(unsigned short flags);
|
|
||||||
|
|
||||||
int get_hw_revision(char *str, int len);
|
|
||||||
|
|
||||||
int get_root_device();
|
|
||||||
int set_root_device(unsigned short);
|
|
||||||
|
|
||||||
int get_nolo_version();
|
|
||||||
|
|
||||||
int get_sw_version();
|
|
||||||
|
|
||||||
#endif /*QUERY_H_*/
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
* 0xFFFF - Open Free Fiasco Firmware Flasher
|
|
||||||
* Copyright (C) 2007 pancake <pancake@youterm.com>
|
|
||||||
*
|
|
||||||
* 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 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <termios.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
|
|
||||||
int open_serial(const char *file)
|
|
||||||
{
|
|
||||||
struct termios tc;
|
|
||||||
int fd = open (file, O_RDWR | O_SYNC);
|
|
||||||
if (fd < 0) {
|
|
||||||
perror (file);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
// 115200 baud, 8n1, no flow control
|
|
||||||
tcgetattr(fd, &tc);
|
|
||||||
tc.c_iflag = IGNPAR;
|
|
||||||
tc.c_oflag = 0;
|
|
||||||
tc.c_cflag = CS8 | CREAD | CLOCAL;
|
|
||||||
tc.c_lflag = 0;
|
|
||||||
cfsetispeed(&tc, B115200);
|
|
||||||
cfsetospeed(&tc, B115200);
|
|
||||||
tcsetattr(fd, TCSANOW, &tc);
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
int console(const char *device)
|
|
||||||
{
|
|
||||||
char str[513];
|
|
||||||
int fd = open_serial(device);
|
|
||||||
int pid;
|
|
||||||
|
|
||||||
if (fd == -1) {
|
|
||||||
fprintf(stderr, "Cannot open serial device %s\n", device);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = fork();
|
|
||||||
if (pid) {
|
|
||||||
while(1) {
|
|
||||||
fgets(str, 512, stdin);
|
|
||||||
if (write(fd, str, strlen(str)-1) == -1) {
|
|
||||||
perror("write");
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
char buf;
|
|
||||||
while(1) {
|
|
||||||
if (read(fd, &buf,1) == -1) {
|
|
||||||
perror("read");
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
write(1, &buf, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
+1
-1
@@ -89,7 +89,7 @@ _retry:
|
|||||||
}
|
}
|
||||||
|
|
||||||
pool = shmat(shmid, NULL, 0);
|
pool = shmat(shmid, NULL, 0);
|
||||||
if (((int)pool) == -1) {
|
if (pool == (void *)-1) {
|
||||||
perror("shmat");
|
perror("shmat");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace SQueues {
|
|||||||
[CCode (cname = "squeue_push2")]
|
[CCode (cname = "squeue_push2")]
|
||||||
public int push2(string cmd, string msg, int l);
|
public int push2(string cmd, string msg, int l);
|
||||||
[CCode (cname = "squeue_get")]
|
[CCode (cname = "squeue_get")]
|
||||||
public weak string get(int l);
|
public unowned string get(int l);
|
||||||
[CCode (cname = "squeue_pop")]
|
[CCode (cname = "squeue_pop")]
|
||||||
public int pop();
|
public int pop();
|
||||||
[CCode (cname = "squeue_stats")]
|
[CCode (cname = "squeue_stats")]
|
||||||
|
|||||||
@@ -0,0 +1,349 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include <usb.h>
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
#include "device.h"
|
||||||
|
#include "usb-device.h"
|
||||||
|
#include "printf-utils.h"
|
||||||
|
#include "nolo.h"
|
||||||
|
#include "cold-flash.h"
|
||||||
|
#include "mkii.h"
|
||||||
|
|
||||||
|
static struct usb_flash_device usb_devices[] = {
|
||||||
|
{ 0x0421, 0x0105, 2, 1, -1, FLASH_NOLO, { DEVICE_SU_18, DEVICE_RX_44, DEVICE_RX_48, DEVICE_RX_51, 0 } },
|
||||||
|
{ 0x0421, 0x0106, 0, -1, -1, FLASH_COLD, { DEVICE_RX_51, 0 } },
|
||||||
|
/* { 0x0421, 0x01c7, 0, -1, -1, FLASH_DISK, { DEVICE_RX_51, 0 } }, */
|
||||||
|
/* { 0x0421, 0x01c8, 1, 1, -1, FLASH_MKII, { DEVICE_RX_51, 0 } }, */
|
||||||
|
/* { 0x0421, 0x0431, 0, -1, -1, FLASH_DISK, { DEVICE_SU_18, DEVICE_RX_34, 0 } }, */
|
||||||
|
{ 0x0421, 0x3f00, 2, 1, -1, FLASH_NOLO, { DEVICE_RX_34, 0 } },
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char * usb_flash_protocols[] = {
|
||||||
|
[FLASH_NOLO] = "NOLO",
|
||||||
|
[FLASH_COLD] = "Cold flashing",
|
||||||
|
[FLASH_MKII] = "Mk II protocol",
|
||||||
|
[FLASH_DISK] = "RAW disk",
|
||||||
|
};
|
||||||
|
|
||||||
|
const char * usb_flash_protocol_to_string(enum usb_flash_protocol protocol) {
|
||||||
|
|
||||||
|
if ( protocol > sizeof(usb_flash_protocols) )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return usb_flash_protocols[protocol];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void usb_flash_device_info_print(const struct usb_flash_device * dev) {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
|
PRINTF_ADD("USB device: %s", device_to_string(dev->devices[0]));
|
||||||
|
|
||||||
|
for ( i = 1; dev->devices[i]; ++i )
|
||||||
|
PRINTF_ADD("/%s", device_to_string(dev->devices[i]));
|
||||||
|
|
||||||
|
PRINTF_ADD(" (%#04x:%#04x) in %s mode", dev->vendor, dev->product, usb_flash_protocol_to_string(dev->protocol));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void usb_descriptor_info_print(usb_dev_handle * udev, struct usb_device * dev, char * product, size_t size) {
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
char buf2[1024];
|
||||||
|
unsigned int x;
|
||||||
|
int ret;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
usb_get_string_simple(udev, dev->descriptor.iProduct, buf, sizeof(buf));
|
||||||
|
PRINTF_LINE("USB device product string: %s", buf[0] ? buf : "(not detected)");
|
||||||
|
PRINTF_END();
|
||||||
|
|
||||||
|
if ( product && buf[0] )
|
||||||
|
strncpy(product, buf, size);
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
memset(buf2, 0, sizeof(buf2));
|
||||||
|
ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, buf, sizeof(buf));
|
||||||
|
if ( ! isalnum(buf[0]) )
|
||||||
|
buf[0] = 0;
|
||||||
|
for ( i = 0; i < ret; i+=2 ) {
|
||||||
|
sscanf(buf+i, "%2x", &x);
|
||||||
|
if ( x > 32 && x < 128 )
|
||||||
|
buf2[i/2] = x;
|
||||||
|
else {
|
||||||
|
buf2[0] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! isalnum(buf2[0]) )
|
||||||
|
buf2[0] = 0;
|
||||||
|
PRINTF_LINE("USB device serial number string: %s", buf2[0] ? buf2 : ( buf[0] ? buf : "(not detected)" ));
|
||||||
|
PRINTF_END();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
char product[1024];
|
||||||
|
struct usb_device_info * ret = NULL;
|
||||||
|
|
||||||
|
for ( i = 0; usb_devices[i].vendor; ++i ) {
|
||||||
|
|
||||||
|
if ( dev->descriptor.idVendor == usb_devices[i].vendor && dev->descriptor.idProduct == usb_devices[i].product ) {
|
||||||
|
|
||||||
|
printf("\b\b ");
|
||||||
|
PRINTF_END();
|
||||||
|
PRINTF_ADD("Found ");
|
||||||
|
usb_flash_device_info_print(&usb_devices[i]);
|
||||||
|
PRINTF_END();
|
||||||
|
|
||||||
|
PRINTF_LINE("Opening USB...");
|
||||||
|
usb_dev_handle * udev = usb_open(dev);
|
||||||
|
if ( ! udev ) {
|
||||||
|
PRINTF_ERROR("usb_open failed");
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
usb_descriptor_info_print(udev, dev, product, sizeof(product));
|
||||||
|
|
||||||
|
#if defined(LIBUSB_HAS_GET_DRIVER_NP) && defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP)
|
||||||
|
PRINTF_LINE("Detaching kernel from USB interface...");
|
||||||
|
usb_detach_kernel_driver_np(udev, usb_devices[i].interface);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
PRINTF_LINE("Claiming USB interface...");
|
||||||
|
if ( usb_claim_interface(udev, usb_devices[i].interface) < 0 ) {
|
||||||
|
PRINTF_ERROR("usb_claim_interface failed");
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
usb_close(udev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( usb_devices[i].alternate >= 0 ) {
|
||||||
|
PRINTF_LINE("Setting alternate USB interface...");
|
||||||
|
if ( usb_set_altinterface(udev, usb_devices[i].alternate) < 0 ) {
|
||||||
|
PRINTF_ERROR("usb_claim_interface failed");
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
usb_close(udev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( usb_devices[i].configuration >= 0 ) {
|
||||||
|
PRINTF_LINE("Setting USB configuration...");
|
||||||
|
if ( usb_set_configuration(udev, usb_devices[i].configuration) < 0 ) {
|
||||||
|
PRINTF_ERROR("usb_set_configuration failed");
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
usb_close(udev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = calloc(1, sizeof(struct usb_device_info));
|
||||||
|
if ( ! ret ) {
|
||||||
|
ALLOC_ERROR();
|
||||||
|
usb_close(udev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( strstr(product, "N900") )
|
||||||
|
ret->device = DEVICE_RX_51;
|
||||||
|
else
|
||||||
|
ret->device = DEVICE_UNKNOWN;
|
||||||
|
|
||||||
|
/* TODO: Autodetect more devices */
|
||||||
|
|
||||||
|
if ( device_to_string(ret->device) )
|
||||||
|
PRINTF_LINE("Detected USB device: %s", device_to_string(ret->device));
|
||||||
|
else
|
||||||
|
PRINTF_LINE("Detected USB device: (not detected)");
|
||||||
|
PRINTF_END();
|
||||||
|
|
||||||
|
if ( ret->device ) {
|
||||||
|
enum device * device;
|
||||||
|
for ( device = usb_devices[i].devices; *device; ++device )
|
||||||
|
if ( *device == ret->device )
|
||||||
|
break;
|
||||||
|
if ( ! *device ) {
|
||||||
|
ERROR("Device mishmash");
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
usb_close(udev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret->hwrev = -1;
|
||||||
|
ret->flash_device = &usb_devices[i];
|
||||||
|
ret->udev = udev;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct usb_device_info * usb_search_device(struct usb_device * dev, int level) {
|
||||||
|
|
||||||
|
int i;
|
||||||
|
struct usb_device_info * ret = NULL;
|
||||||
|
|
||||||
|
if ( ! dev )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ret = usb_device_is_valid(dev);
|
||||||
|
if ( ret )
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
for ( i = 0; i < dev->num_children; i++ ) {
|
||||||
|
ret = usb_search_device(dev->children[i], level + 1);
|
||||||
|
if ( ret )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct usb_device_info * usb_open_and_wait_for_device(void) {
|
||||||
|
|
||||||
|
struct usb_bus * bus;
|
||||||
|
struct usb_device_info * ret = NULL;
|
||||||
|
int i = 0;
|
||||||
|
static char progress[] = {'/','-','\\', '|'};
|
||||||
|
|
||||||
|
usb_init();
|
||||||
|
usb_find_busses();
|
||||||
|
|
||||||
|
PRINTF_BACK();
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
while ( 1 ) {
|
||||||
|
|
||||||
|
PRINTF_LINE("Waiting for USB device... %c", progress[++i%sizeof(progress)]);
|
||||||
|
|
||||||
|
usb_find_devices();
|
||||||
|
|
||||||
|
for ( bus = usb_get_busses(); bus; bus = bus->next ) {
|
||||||
|
|
||||||
|
if ( bus->root_dev )
|
||||||
|
ret = usb_search_device(bus->root_dev, 0);
|
||||||
|
else {
|
||||||
|
struct usb_device *dev;
|
||||||
|
for ( dev = bus->devices; dev; dev = dev->next ) {
|
||||||
|
ret = usb_search_device(dev, 0);
|
||||||
|
if ( ret )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ret )
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ret )
|
||||||
|
break;
|
||||||
|
|
||||||
|
usleep(0xc350); // 0.5s
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PRINTF_BACK();
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
if ( ! ret )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_close_device(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
usb_close(dev->udev);
|
||||||
|
free(dev);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_switch_to_nolo(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
printf("\nSwitching to NOLO mode...\n");
|
||||||
|
|
||||||
|
if ( dev->flash_device->protocol == FLASH_COLD )
|
||||||
|
leave_cold_flash(dev);
|
||||||
|
else if ( dev->flash_device->protocol == FLASH_MKII )
|
||||||
|
mkii_reboot_device(dev);
|
||||||
|
else if ( dev->flash_device->protocol == FLASH_DISK )
|
||||||
|
printf_and_wait("Unplug USB cable, turn device off, press ENTER and plug USB cable again");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_switch_to_cold(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
printf("\nSwitching to Cold Flash mode...\n");
|
||||||
|
|
||||||
|
if ( dev->flash_device->protocol == FLASH_NOLO )
|
||||||
|
nolo_reboot_device(dev);
|
||||||
|
else if ( dev->flash_device->protocol == FLASH_MKII )
|
||||||
|
mkii_reboot_device(dev);
|
||||||
|
else if ( dev->flash_device->protocol == FLASH_DISK )
|
||||||
|
printf_and_wait("Unplug USB cable, turn device off, press ENTER and plug USB cable again");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_switch_to_mkii(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
printf("\nSwitching to Update mode...\n");
|
||||||
|
|
||||||
|
if ( dev->flash_device->protocol == FLASH_COLD )
|
||||||
|
leave_cold_flash(dev);
|
||||||
|
else if ( dev->flash_device->protocol == FLASH_NOLO )
|
||||||
|
nolo_boot_device(dev, "update");
|
||||||
|
else if ( dev->flash_device->protocol == FLASH_DISK )
|
||||||
|
printf_and_wait("Unplug USB cable, turn device off, press ENTER and plug USB cable again");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_switch_to_disk(struct usb_device_info * dev) {
|
||||||
|
|
||||||
|
printf("\nSwitching to RAW disk mode...\n");
|
||||||
|
|
||||||
|
if ( dev->flash_device->protocol == FLASH_COLD )
|
||||||
|
leave_cold_flash(dev);
|
||||||
|
else if ( dev->flash_device->protocol == FLASH_NOLO ) {
|
||||||
|
nolo_boot_device(dev, NULL);
|
||||||
|
printf_and_wait("Wait until device start, choose USB Mass Storage Mode and press ENTER");
|
||||||
|
} else if ( dev->flash_device->protocol == FLASH_MKII )
|
||||||
|
mkii_reboot_device(dev);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
0xFFFF - Open Free Fiasco Firmware Flasher
|
||||||
|
Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com>
|
||||||
|
|
||||||
|
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 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef USB_DEVICE_H
|
||||||
|
#define USB_DEVICE_H
|
||||||
|
|
||||||
|
#include <usb.h>
|
||||||
|
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
enum usb_flash_protocol {
|
||||||
|
FLASH_UNKN = 0,
|
||||||
|
FLASH_NOLO,
|
||||||
|
FLASH_COLD,
|
||||||
|
FLASH_MKII,
|
||||||
|
FLASH_DISK,
|
||||||
|
FLASH_COUNT,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usb_flash_device {
|
||||||
|
uint16_t vendor;
|
||||||
|
uint16_t product;
|
||||||
|
int interface;
|
||||||
|
int alternate;
|
||||||
|
int configuration;
|
||||||
|
enum usb_flash_protocol protocol;
|
||||||
|
enum device devices[DEVICE_COUNT];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct usb_device_info {
|
||||||
|
enum device device;
|
||||||
|
int16_t hwrev;
|
||||||
|
const struct usb_flash_device * flash_device;
|
||||||
|
usb_dev_handle * udev;
|
||||||
|
};
|
||||||
|
|
||||||
|
const char * usb_flash_protocol_to_string(enum usb_flash_protocol protocol);
|
||||||
|
struct usb_device_info * usb_open_and_wait_for_device(void);
|
||||||
|
void usb_close_device(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
void usb_switch_to_nolo(struct usb_device_info * dev);
|
||||||
|
void usb_switch_to_cold(struct usb_device_info * dev);
|
||||||
|
void usb_switch_to_mkii(struct usb_device_info * dev);
|
||||||
|
void usb_switch_to_disk(struct usb_device_info * dev);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in new issue
Block a user