Project

General

Profile

Flashing » History » Version 3

jolly, 02/19/2016 10:49 PM

1 1 jolly
[[PageOutline]]
2
= Flashing an application into a C123 phone =
3
4
This tutorial explains how to flash one or multiple application(s) into C123 phone. Read carefully, otherwise you might brick your phone. Even if you follow this tutorial, you may brick your phone if you run into cable problem, weak battery or software fault. Also be sure to have another phone, because some firmware might not support battery charging. After flashing, the original firmware is gone, so be sure to save complete flash memory, if you want to restore original firmware in the future.
5
6
There will be three parts to be flashed:
7
8
 * the original Compal loader
9
 * the OSMOCOM menu (loads applications from flash into ram)
10
 * the application
11
12
Without the Compal loader, the phone is bricked. The OSMOCOM menu will allow to start the application from any flash page other than page 0.
13
14
== Memory ==
15
16
The memory is mapped as follows:
17
18
 * 0x000000-0x00ffff: Flash page 0
19
 * 0x010000-0x01ffff: Flash page 1
20
 * ... more Flash pages ...
21
 * 0x800000-0x83ffff: Ram
22
23
Our flash layout is:
24
25
 * 0x000000-0x001fff: Compal loader
26
 * 0x002000-0x00ffff: OSMOCOM menu
27
 * 0x010000-........: OSMOCOM application and storage
28
29
Note: The Compal loader and the OSMOCOM menu will located in the same flash page!
30
31
== preparations ==
32
33
=== Unlocking flash write of Osmocom loader ===
34
35
{{{
36
$ cd src/target/firmware/
37
$ edit Makefile
38
}}}
39
40
Enable the following compiler flags: (They are located at the bottom of the file.)
41
42
{{{
43
CFLAGS += -DCONFIG_FLASH_WRITE
44
CFLAGS += -DCONFIG_FLASH_WRITE_LOADER
45
}}}
46
47 3 jolly
Also you may want to allow the application to transmit, so enable TX supprt:
48
49
{{{
50
CFLAGS += -DCONFIG_TX_ENABLE
51
}}}
52
53 1 jolly
=== rebuilding the firmware ===
54
55
Now rebuild the firmware with write support enabled:
56
57
{{{
58
$ make clean
59
$ make
60
}}}
61
62
== actual installation ==
63
64
=== Booting the phone / downloading loader to ram ===
65
66
{{{
67
$ cd src
68
$ host/osmocon/osmocon -p /dev/ttyUSB0 -m c123xor target/firmware/board/compal_e88/loader.compalram.bin
69
}}}
70
71
Briefly press the power-on button of your phone (short push, not like a regular phone boot!).
72
See [wiki:osmocon] for more informations.
73
74
You will get the following output:
75
76
{{{
77
Received PROMPT1 from phone, responding with CMD
78
read_file(target/firmware/board/compal_e88/loader.compalram.bin): file_size=18436, hdr_len=4, dnload_len=18443
79
Received PROMPT2 from phone, starting download
80
handle_write(): 4096 bytes (4096/18443)
81
handle_write(): 4096 bytes (8192/18443)
82
handle_write(): 4096 bytes (12288/18443)
83
handle_write(): 4096 bytes (16384/18443)
84
handle_write(): 2059 bytes (18443/18443)
85
handle_write(): finished
86
Received DOWNLOAD ACK from phone, your code is running now!
87
Received DOWNLOAD ACK from phone, your code is running now!
88
89
90
OSMOCOM Loader (revision osmocon_v0.0.0-1322-g43c588b-modified)
91
======================================================================
92
Running on compal_e88 in environment compalram
93
Found flash of 2097152 bytes at 0x0 with 2 regions
94
}}}
95
96
Now open another console and talk to the loader as described below:
97
98
99
=== Flashing the loader + menu ===
100
101
The OSMOCOM loader is located in ram. (see above) It will be used to write to flash. Because it runs in ram, it will allow accessing the flash.
102
103
The OSMOCOM menu cannot be flashed without erasing the original Compal loader, because both are located in the same flash page. We can only erase the complete page, not parts of it. The first thing we must do is save the original loader:
104
105
{{{
106
$ cd src
107
$ host/osmocon/osmoload memdump 0x000000 0x2000 compal_loader.bin
108
}}}
109
110
To test if flashing works, we will first flash the Compal and OSMOCOM menu to a wrong location. If flashing fails, we still have the Compal loader working on it's original location, and the phone is not bricked.
111
112
First erase page at 0x010000 and program the just saved compal_loader.bin and the OSMOCOM menu:
113
114
{{{
115
$ host/osmocon/osmoload funlock 0x010000 0x10000
116
$ host/osmocon/osmoload ferase 0x010000 0x10000
117
$ host/osmocon/osmoload fprogram 0 0x010000 compal_loader.bin
118
$ host/osmocon/osmoload fprogram 0 0x012000 target/firmware/board/compal_e88/menu.e88loader.bin
119
}}}
120
121
If all these steps will not produce any error output, you can start flashing the Osmocom loader to it's right place at page 0x000000:
122
123
{{{
124
$ host/osmocon/osmoload funlock 0x000000 0x10000
125
$ host/osmocon/osmoload ferase 0x000000 0x10000
126
$ host/osmocon/osmoload fprogram 0 0x000000 compal_loader.bin
127
$ host/osmocon/osmoload fprogram 0 0x002000 target/firmware/board/compal_e88/menu.e88loader.bin
128
}}}
129
130
=== Preparing an application ===
131
132
The OSMOCOM menu will search for applications starting at any flash page. In order to detect an application, a header is used. create the header as follows:
133
134
{{{
135
$ echo "highram:RSSI" >temp
136
}}}
137
138
In this case we created a header for the RSSI application and call that "RSSI". Now we append the highram image to be loaded by the OSMOCOM menu:
139
140
{{{
141
$ cat target/firmware/board/compal_e88/rssi.highram.bin >>temp
142
}}}
143
144
Flashing the "temp" file is only possible, if the number of byte are even. In case they are odd, add one byte:
145
146
{{{
147
$ ls -la temp
148 2 jolly
-rw-r--r-- 1 root root 83761 Sep 27 10:08 temp
149
$ echo >>temp
150
$ ls -la temp
151 1 jolly
-rw-r--r-- 1 root root 83762 Sep 27 10:08 temp
152 2 jolly
}}}
153 1 jolly
154 2 jolly
Now the application is ready to be flashed to any flash page. In case of RSSI application, it requires two pages of flash memory. 
155 1 jolly
156 2 jolly
157 1 jolly
=== Flasing an application ===
158
159 2 jolly
In order to flash an application, you must check how large it is. You need to erase the amount of pages the firmware requires. You need to round it up to a multiple of 64k (one flash page).
160 1 jolly
161 2 jolly
In this example we will flash the RSSI firmware. It is between 64k and 128k, so we need at least two pages to erase:
162 1 jolly
163
{{{
164
$ host/osmocon/osmoload funlock 0x010000 0x20000
165
$ host/osmocon/osmoload ferase 0x010000 0x20000
166 2 jolly
$ host/osmocon/osmoload fprogram 0 0x010000 temp
167 1 jolly
}}}
168
169 2 jolly
Now we have flashed page 1 and page 2. In order to flash another application, you need to erase and flash page 3 or higher. 
170 1 jolly
171 2 jolly
172 1 jolly
== Testing ==
173
174
 * Power off your phone.
175
 * Disconnect the serial cable.
176 2 jolly
 * Turn it on (push power button), the OSMOCOM menu will appear and show available applications.
177
 * Use up/down keys or digits to select the application.
178
 * Press the green off-hook button, the application will be loaded to ram and is started.
Add picture from clipboard (Maximum size: 48.8 MB)