Project

General

Profile

SciphoneDreamG2 » History » Version 25

zecke, 02/21/2016 10:05 AM

1 1 laforge
2 22 laforge
h1. Sciphone Dream G2
3 1 laforge
4 22 laforge
5
The Sciphone Dream G2 is a [[MT6235]] based phone running UI software to mimic the look+feel of Android.
6
7 1 laforge
There is currently an u-boot and Linux port for the MT6235 underway, the primary development platform is the Sciphone G2.
8
9 23 laforge
*[[OsmocomBB]] does not yet support any Mediatek chipsets, so this phone is not supported by [[OsmocomBB]].*
10 1 laforge
11 24 laforge
More information on the hardware of the device can be found at http://en.qi-hardware.com/wiki/Sciphone_Dream_G2
12 1 laforge
The phone has a engineering menu which can be activated by dialing *#36466331#
13 16 steve-m
14
15 22 laforge
h2. Serial Cable
16
17
18 16 steve-m
You can make a serial cable by sacrificing the headset that comes with the phone, and swapping the pins inside the connector.
19 2 steve-m
20
Serial pinout:
21 9 laforge
22 2 steve-m
||Pin||signal||comment||
23 9 laforge
||1||GND||
24
||2||GND||
25 1 laforge
||5||Rx||(From PC to Phone)||
26
||7||Tx||(From Phone to PC)||
27
28 25 zecke
{{thumbnail(sciphone_serial.jpg)}}
29 2 steve-m
30 1 laforge
31 22 laforge
h2. JTAG
32
33
34 4 steve-m
The JTAG port of the MT6235 is accessible on the phone PCB, see the attached picture.
35 22 laforge
You can use "OpenOCD":http://openocd.berlios.de/web/ along with the attached configuration file ([raw-attachment:openocd_mt6235.cfg]) for debugging.
36 1 laforge
37 25 zecke
{{thumbnail(scig2_front.JPG,20%)}}
38
{{thumbnail(scig2_jtag.jpg,20%)}}
39 1 laforge
40 11 steve-m
41 22 laforge
h2. Serial Bootloader
42
 
43 1 laforge
44 22 laforge
Like all Mediatek MT62xx SoCs, the phone uses the [[MTKRomloader]].
45
46 10 steve-m
For executing U-Boot and Linux using the MTK romloader, proceed as follows:
47 1 laforge
48 22 laforge
* clone osmocom-bb.git and checkout the branch 'steve-m/loader_sciphone'
49
* compile the code, connect the phone and run osmocon:
50
<pre>
51 1 laforge
$ ./osmocon -p /dev/ttyUSB0 -m mtk ../../target/firmware/board/mt62xx/loader.mtkram.bin
52 22 laforge
</pre>
53
* press and *hold* the powerbutton of the phone, until the loading has finished and you see the following:
54
<pre>
55 1 laforge
[...]
56
Received branch address ack, code should run now
57 10 steve-m
58 1 laforge
Running on mt62xx in environment mtkram
59
HW_CODE = 0x6235
60 22 laforge
</pre>
61 1 laforge
62 22 laforge
*Uploading U-Boot*
63
* *don't* terminate osmocon and execute:
64
<pre>
65 10 steve-m
$ ./osmoload memload 0x500000 u-boot.bin
66
$ ./osmoload jump 0x500000
67 22 laforge
</pre>
68 13 laforge
69 22 laforge
* now terminate osmocon and open a serial terminal of your choice (115200-8N1)
70
* see below for loading Linux with U-Boot
71 13 laforge
72
73 22 laforge
h2. MTK boot process
74
75
76 25 zecke
{{thumbnail(mt62xx_boot.jpg)}}
77 1 laforge
78 22 laforge
MT62xx chips have IPL (Initial Program Loader) saved in ROM.
79 1 laforge
80
81 22 laforge
This is first code executed after power up.
82 1 laforge
83
84 22 laforge
It configures basic functionality of CPU (serial port 19200n8) and waits on 0xA beacon.
85 1 laforge
86 22 laforge
87
If beacon won't be received, it jumps to NAND memory read procedure.
88
89
90
At NAND 0x0 address Boot Header is placed which holds informations about NAND memory and parameters of image which is going to be loaded.
91
92
93 1 laforge
NAND memory read procedure tries to read NAND memory from 0x0 address with following NFI controller settings:
94
95 13 laforge
||Bus width||Address bytes||Page size||Column shift||Used in Sciphone G2||
96 1 laforge
||1||3||512||8||||
97 13 laforge
||0||3||512||8||||
98 14 laforge
||1||4||512||8||||
99 13 laforge
||0||4||512||8||yes||
100 1 laforge
||1||4||2048||16||||
101
||0||4||2048||16||yes||
102
||1||5||2048||16||||
103
||0||4||2048||16||||
104 15 laforge
105 22 laforge
If Boot Header read from NAND memory will match to currently used NFI configuration, bootloader will start to read data from NAND to internal SRAM. Internal SRAM size is 64kB, which means that code loaded by IPL can't be bigger than that.
106 1 laforge
107
108 22 laforge
*Note:* IPL doesn't configure PLL and SDRAM controller, so there is no possibility to load code to external RAM. Here is where SPL (Secondary Program Loader) comes into the game.
109 1 laforge
110 13 laforge
111 22 laforge
h2. SPL - Runing U-Boot from NAND
112 1 laforge
113 15 laforge
114 22 laforge
SPL (Second Program Loader) is just small U-Boot loader which includes low level CPU initialization (PLL, SDRAM) and NAND driver.
115 1 laforge
116 15 laforge
117 22 laforge
Using default build it occupies less than 4kB, but it lacks NAND memory detection. All the NAND memory types can be specified using preprocessor which is not comfortable. We already identified three different NAND memories and that would be bad to create seperate builds for them.
118 1 laforge
119 22 laforge
120
Fortunatelly there is no need to strip down SPL size to 4kB, so SPL code has been reworked and new functionalities are added. It detects NAND memory at startup and configures NFI controller automatically. New implementation can be found at "nand_spl/nand_boot_detect.c".
121
122
123
SPL also automatically configures SDRAM controler according to RAM you have on your device (currently it tries two configurations).
124
125
126
SPL is generated on every U-Boot build and binary can be found at "nand_spl/u-boot-spl.bin".
127
128
129
SPL will be loaded and executed by IPL only if Boot Header will contain valid data (in this case checksum and length is most important).
130
131
132 6 laforge
To generate Boot Header and place it at the begining of binary you should use mtk_image tool. MTK Boot Header generator can be found at "tools/mtk_image.c".
133
134 22 laforge
<pre>
135 1 laforge
Usage ./mtk_image [ -s size ] [ -o file ] mtk_dump.bin image.bin
136
	[ -s size ]	- size of image, if not specified file size will be taken
137 6 laforge
	[ -o file ]	- name of output file
138 1 laforge
	mtk_dump.bin	- dump of NAND memory from address 0 (at least 64 bytes)
139 6 laforge
	image.bin	- image to be loaded by MTK bootloader
140 22 laforge
</pre>
141 1 laforge
142 22 laforge
mtk_image tool needs dump file from your device (at least 64 bytes read from NAND 0x0 address) as there are different NAND memory configurations. Thanks to that Boot Header will be properly generated for your device.
143 6 laforge
144 1 laforge
145 22 laforge
*Note! Before flashing U-Boot to NAND, create full dump of your NAND, otherwise you'll be not able to restore phone's original software.*
146 1 laforge
147 6 laforge
148 22 laforge
h2. U-Boot
149
150
151
Port of U-Boot for Sciphone G2 can be found at "U-Boot":http://git.osmocom.org/gitweb?p=uboot-mt623x.git;a=summary
152
153 1 laforge
Building U-Boot:
154
155 22 laforge
<pre>
156 1 laforge
export CROSS_COMPILE=arm-linux-gnueabi-
157
make sciphone_g2_config
158 8 laforge
make
159 22 laforge
</pre>
160 1 laforge
161
162 22 laforge
h2. Linux kernel
163 1 laforge
164 22 laforge
165
Port of Linux kernel for Sciphone G2 can be found at "Linux kernel":http://git.osmocom.org/gitweb?p=linux-mt623x.git;a=summary
166
167 1 laforge
Building Linux:
168
169 22 laforge
<pre>
170 8 laforge
export CROSS_COMPILE=arm-linux-gnueabi-
171
make ARCH=arm sciphone_g2_defconfig
172 1 laforge
make ARCH=arm uImage
173 22 laforge
</pre>
174 1 laforge
175 8 laforge
176 22 laforge
h2. Building initramfs file system
177 1 laforge
178 8 laforge
179 22 laforge
The easiest way to have file system in Linux kernel is to build "Initramfs image":http://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt.
180
181
182
You need to download "Busybox":http://www.busybox.net/, configure it and build it.
183
184
<pre>
185 8 laforge
export CROSS_COMPILE=arm-linux-gnueabi-
186
make menuconfig
187
make
188
make install
189 22 laforge
</pre>
190 1 laforge
191 22 laforge
Generated file system by default installs in _install directory.
192 1 laforge
193 22 laforge
194 1 laforge
Additional to that you'll need to create console device in already built filesystem.
195
196 22 laforge
<pre>
197 1 laforge
sudo mknod dev/console c 5 1
198 22 laforge
</pre>
199 1 laforge
200
Now you can create CPIO archive:
201
202 22 laforge
<pre>
203 1 laforge
find . | cpio -o -H newc > rootfs.cpio
204 22 laforge
</pre>
205 7 laforge
206 22 laforge
Next step is to point to Linux kernel where initramfs image is located.
207 7 laforge
208 22 laforge
209 1 laforge
In menuconfig of Linux kernel you should modify following option:
210
211 22 laforge
<pre>
212 1 laforge
CONFIG_INITRAMFS_SOURCE=<path_to_cpio>
213
General setup -> Initial RAM filesystem and RAM disk -> Initramfs source file(s)
214 22 laforge
</pre>
215 1 laforge
216 22 laforge
After these steps Linux kernel image will have initramfs built in.
217 1 laforge
218 14 laforge
219 22 laforge
*Important note:* Initramfs ignores 'init=' variable given in kernel boot parameters list. It always executes /init command at startup and you can't change it. Check if you have /init in your file system (BusyBox has /linuxrc by default, so just change its name to init).
220
Every time you change initramfs file system you have to rebuild also Linux kernel.
221
222
223 13 laforge
To unpack CPIO archive you can use following command:
224
225 22 laforge
<pre>
226 1 laforge
cpio -i -d -H newc -F <path_to_cpio_archive> --no-absolute-filenames
227 22 laforge
</pre>
228 13 laforge
229 1 laforge
230 22 laforge
h2. Reading data files in U-Boot
231 1 laforge
232 22 laforge
233
*NAND*
234
235 1 laforge
Following command will read 256 bytes from NAND address 0 at address 0x800000.
236 13 laforge
237 22 laforge
<pre>
238 1 laforge
nand read 0x800000 0 0x100
239 22 laforge
</pre>
240 13 laforge
241 22 laforge
*Serial*
242 1 laforge
243
Following command will read data at address 0x800000 from serial at baudrate 115200 (using kermit protocol).
244
245 22 laforge
<pre>
246 1 laforge
loadb 0x800000 115200
247 22 laforge
</pre>
248 1 laforge
249 22 laforge
*SD/MMC*
250 1 laforge
251 13 laforge
Following command will read uImage file at address 0x800000 from MMC card.
252 1 laforge
253 22 laforge
<pre>
254 1 laforge
mmcinfo
255 13 laforge
fatload mmc 0 0x800000 uImage
256 22 laforge
</pre>
257 13 laforge
258
259 22 laforge
h2. NAND memory
260
261
262 13 laforge
So far three types of NAND memories has been identified:
263 1 laforge
264
||Chip||Size||
265
||HY27XS08121M||512Mb (64MB) NAND||
266 13 laforge
||HY27XA081G1M||1Gb (128MB) NAND||
267 1 laforge
||TC58NVG0S3AFT||1Gb (128MB) NAND||
268
269 22 laforge
All of them are supported by "mt62xx_nand.c" NAND driver in U-Boot.
270 1 laforge
271
272 22 laforge
This driver has also support for ECC hardware decoding and encoding.
273
274
275 1 laforge
ECC layout which is used by MTK looks as follows:
276 13 laforge
277 22 laforge
<pre>
278 13 laforge
/*
279 22 laforge
* For small and large page NAND devices ecc block size is the same:
280 13 laforge
 *
281 22 laforge
*      ecc_block_size = 256
282 13 laforge
 *
283 22 laforge
* Placement of ecc bytes in spare area is as follows:
284 1 laforge
 *
285 22 laforge
* --------------------------------------------------------------
286
* |                            SPARE                           |
287
* --------------------------------------------------------------
288
* |    | ECC0  |       | ECC1  |       | ECC2  |       | ECC3  |
289
* --------------------------------------------------------------
290
* 0    8       16      24      32      40      48      56      64
291 1 laforge
 *
292 22 laforge
* ECC0 = 12 bits (from 1st ECC block) + 12 bits (from 2nd ECC block)
293
* ECC1 = 12 bits (from 3rd ECC block) + 12 bits (from 4th ECC block)
294
* ECC2 = 12 bits (from 5th ECC block) + 12 bits (from 6th ECC block)
295
* ECC2 = 12 bits (from 7th ECC block) + 12 bits (from 8th ECC block)
296 1 laforge
 */
297
298 22 laforge
</pre>
299 1 laforge
300 13 laforge
ECC layout information is pretty important as built-in bootloader in MT62xx chips
301
has hardware ECC enabled and it won't load code from NAND if ECC layout will
302 22 laforge
not match.
303 13 laforge
304 1 laforge
305 22 laforge
This layout is also important to properly dump or restore existing firmware.
306
307
308 1 laforge
NAND driver for Linux is under development.
309
310
311 22 laforge
h2. LCD
312
313
Sciphone G2 has LCD with 240x320 resolution.
314
315
316 1 laforge
Currently two different LCD controllers has been identified (on Sciphone G2):
317 22 laforge
* ILI9331
318
* ILI9325
319
These controllers are already supported in U-Boot.
320 1 laforge
321 22 laforge
322 1 laforge
To identify what kind of controller is in your device, just check U-Boot prints.
323
324 22 laforge
<pre>
325 13 laforge
DRAM:  32 MiB
326
NAND:  64 MiB
327
MMC:   msdc_mmc: 0
328 1 laforge
mtk_lcd INFO: Read LCD device code: 9331.
329 22 laforge
</pre>
330 1 laforge
331 22 laforge
U-Boot supports displaying bitmap on the screen, you just have to create bitmap in proper format.
332 1 laforge
333
334 22 laforge
By default U-Boot will build osmocomBB bitmap.
335 13 laforge
336
337 22 laforge
To convert your customized bitmap change type of bitmap to indexed.
338
339
340
Using GIMP, select "Image -> Mode -> Indexed...". Maximum number of colours is 240 (16 is used by internal U-Boot CMAP).
341
342
343 13 laforge
In existing U-Boot bmp logo converting tool (tools/bmp_logo.c) there are two issues:
344 22 laforge
* width of bitmap has to be aligned to 4 (otherwise padding bytes will be added and bitmap will be not properly displayed)
345
* size of bitmap can't be bigger than 65535 (LCD on Sciphone G2 is 240x320 = 76800)
346
Both issues are fixed on "uboot-mt623x":http://git.osmocom.org/gitweb?p=uboot-mt623x.git;a=summary.
347 13 laforge
348
349 22 laforge
MT6235 LCD controller shares data lines with NFI (NAND) controller. Currently there is no possibility to use NAND when LCD is used.
350
351
352 1 laforge
Frame buffer driver for Linux is under development.
353 13 laforge
354
355 22 laforge
h2. BBT handling
356
357
358 13 laforge
Comment from "sciphone_g2.h" configuration file explains how BBT is handled.
359
360 22 laforge
<pre>
361 13 laforge
/*
362 22 laforge
* Below option allows U-Boot to save BBT table in NAND.
363
* Without this option BBT table is created everytime when first nand
364
* command is executed (except "nand dump"). Full scanning of NAND
365
* takes long time and unnecessarily delays first command execution.
366 13 laforge
 *
367 22 laforge
* NOTE! This option is disabled by defaut as at startup it deletes last
368
* two blocks of NAND. Most of people run code from RAM and don't have
369
* NAND memory dumped yet. If you don't like to wait on first nand
370
* command, you should enable below option.
371 13 laforge
 */
372
#define MT62XX_NAND_BBT_IN_NAND
373 22 laforge
</pre>
374 13 laforge
375
376 22 laforge
h2. MTD partitions
377
378
379 13 laforge
Layout of MTD partitions is following:
380
381 22 laforge
<pre>
382 13 laforge
device nand0 <mt62xx_nand.0>, # parts = 5
383
 #: name                size            offset          mask_flags
384
 0: sbl                 0x00020000      0x00000000      0
385
 1: env                 0x00020000      0x00020000      0
386
 2: u-boot              0x00200000      0x00040000      0
387
 3: kernel              0x00200000      0x00240000      0
388 6 laforge
 4: root                0x03bc0000      0x00440000      0
389 22 laforge
</pre>
390 17 laforge
391
392 22 laforge
h2. Building images with [[OpenEmbedded]]
393 17 laforge
394
395 22 laforge
Currently the easiest way to build your own Linux distribution for Sciphone G2 is to use OE.
396 17 laforge
397
398 22 laforge
Setting up of OE is described "here":http://www.openembedded.org/index.php/Getting_started.
399
400
401
To have Sciphone G2 target and Linux kernel with U-Boot from [[OsmocomBB]] repositories, you need to apply patch from "here":http://downloads.qi-hardware.com/people/marcin/.
402
403
404
Under above link you can also find example config file for OE build.
405
406
407 17 laforge
So far following images has been successfully run on Sciphone G2:
408
409 22 laforge
<pre>
410 17 laforge
minimal-image
411
opie-image-16mb
412
opie-image
413
x11-image
414 22 laforge
</pre>
415 17 laforge
After successfull build of image, following directory will contain U-Boot, Linux kernel and file system image:
416
417 22 laforge
<pre>
418 18 laforge
/YOUR_BUILD_DIRECTORY/deploy/images/sciphone_g2/
419 22 laforge
</pre>
420 17 laforge
421 22 laforge
U-Boot and Linux kernel are built from latest sources found in [[OsmocomBB]] repositories.
422 17 laforge
423
424 22 laforge
h2. Running Linux distro
425
426
427 25 zecke
{{thumbnail(scig2_opie.jpg)}}
428 17 laforge
429 22 laforge
It's possible to run any Linux distribution without flashing Sciphone's original firmware.
430 17 laforge
431
432 22 laforge
To do this, you need to prepare microSD card and use osmocon loader to load u-Boot image to RAM.
433 17 laforge
434
435 22 laforge
Current images for U-Boot and Root File Systems can be found "here":http://downloads.qi-hardware.com/people/marcin/.
436 17 laforge
437 22 laforge
First of all ext3 partition has to be created on SD card.
438
439
440
*Note!!! Followig method will erase all data on your SD card.*
441
442
<pre>
443 17 laforge
sudo fdisk /dev/sdbX
444
press p (prints partition table)
445
press d (deletes partition table)
446
press n (adds new partition)
447
sudo mkfs.ext3 /dev/sdbX
448 22 laforge
</pre>
449 17 laforge
450
Next step is to copy built image to SD card:
451
452 22 laforge
<pre>
453 17 laforge
sudo dd if=<path_to_ext3_image_file> of=/dev/sdbx
454 22 laforge
</pre>
455 19 laforge
456 22 laforge
When operation is finished, you can pull out SD card from PC and insert it to Sciphone.
457 20 laforge
458
459 22 laforge
Now you can load U-Boot image using osmocon tool.
460 20 laforge
461
462 22 laforge
When U-Boot starts, it loads /boot/uImage kernel file from SD card to RAM and boots it (OE automatically copies built kernel to /boot directory).
463 21 laforge
464 20 laforge
465 22 laforge
After that you should see [[OsmocomBB]] splash screen with "Please wait ..." text and after few moments an OPIE welcome screen should appear.
466 19 laforge
467 22 laforge
468
*Note!!! Initial boot takes much longer time than next ones.*
469
470
If your screen is not properly calibrated, execute *ts_calibrate* command from shell which will recalibrate your touchscreen.
471
472
473
h2. Additional equipment
474
475
476
Sciphone G2 has microSD card slot in hardly available place.
477
478
During development process you'll waste a lot of time to pull out and put in microSD card with new software.
479
480 1 laforge
Below picture shows home made microSD card extension cable which makes SD card changes much faster.
481
482 25 zecke
{{thumbnail(microsd_extension.jpg)}}
483
{{thumbnail(scig2_microsd.jpg)}}
484 1 laforge
485
486 22 laforge
h2. Links
487 1 laforge
488 22 laforge
"- video showing Sciphone G2 running Angstrom Linux with OPIE[[BR":http://www.youtube.com/watch?v=-_guRruQi0I]]
489
490
"- video showing Sciphone G2 running Linux kernel[[BR":http://www.youtube.com/watch?v=w_Iwsckm7Ko]]
491
492
"- Sciphone G2 binary images and patches[[BR":http://downloads.qi-hardware.com/people/marcin/]]
Add picture from clipboard (Maximum size: 48.8 MB)