Project

General

Profile

CompalRamloader » History » Version 5

fixeria, 07/27/2018 08:08 AM

1 1 laforge
h1. The Compal RAM Loader
2 3 laforge
3 5 fixeria
{{>toc}}
4 1 laforge
5 3 laforge
The Compal Ramloader is part of the original vendor firmware and what is executed first when a Compal phone like the [[MotorolaC123]] boots.
6
7
In the [[OsmocomBB]] project we only use this loader as it is stored in the original flash. We have implemented a host PC program
8
called [[osmocon]] that can talk to this Compal RAM loader.
9
10 1 laforge
It is flashed to the first block[s] of the NOR flash, which in turn is mapped to address 0x0000'0000
11
12
The tasks of the Ramloader are as follows:
13 3 laforge
* Initialize the minimally neccessary hardware (PLL, clock, GPIO, UART, ...)
14
* Check if a program on a PC is interested in downloading code into the phone
15
** if yes, actually perform the serial download into RAM and execute that code
16
** if no, continue booting the OS stored in the NOR flash
17 1 laforge
18
19 3 laforge
h2. Download Protocol
20
21
22 1 laforge
The download protocol is relatively simple, although device-specific quirks complicate it:
23
24
25 3 laforge
h3. Negotiating the existance of a PC download software
26 1 laforge
27
28 3 laforge
* The phone sends the PROMPT1 message (0x1b, 0xf6, 0x02, 0x00, 0x41, 0x01, 0x40)
29
* The PC responds with DNLOAD_CMD messge (0x1b, 0xf6, 0x02, 0x00, 0x52, 0x01, 0x53)
30
* The phone responds with the PROMPT2 message (0x1b, 0xf6, 0x02, 0x00, 0x41, 0x02, 0x43)
31
32
33
h3. Actual download of the executable code
34
35
* The PC downloads the software
36
** Optionally (C155) by starting with the byte 0x02 (the XOR initialization value)
37
** Sending two bytes length, containing the length of the code to be downloaded
38
** Sending the actual download data
39
** Sending a single byte containing the XOR sum of all characters sent, including the length bytes
40
* The phone responds with a DNLOAD_ACK message (0x1b, 0xf6, 0x02, 0x00, 0x41, 0x03, 0x42)
41
42
43
h4. Error cases
44
45 1 laforge
If something goes wrong, you will get
46 3 laforge
* DNLOAD_NACK (0x1b, 0xf6, 0x02, 0x00, 0x45, 0x53, 0x16)
47
* DNLOAD_NACK_MAGIC (0x1b, 0xf6, 0x02, 0x00, 0x41, 0x03, 0x57)
48 1 laforge
49 3 laforge
h2. Execution Environment
50 1 laforge
51 4 laforge
All the downloaded data (excluding the length bytes) is stored at the base address 0x0080'0100.
52 3 laforge
53
*However, since there is a 4byte header prepended by compal_dnload, use 0x0080'0104 as linker base address!*
54
55 1 laforge
The RAM loader already initializes the stack pointer.  It points to a 1020 bytes large location in memory.
56
57
On the C118, C121, C123 and C140, the CPU runs in ARM mode when jumping to the base address.
58
59
On the C155, the CPU runs in THUMB mode when jumping to the base address.  This is why the ramloader
60
automatically prefixes your payload with a 4-byte header that switches to ARM mode.
61
62 3 laforge
63
h2. Restrictions
64
65 1 laforge
66
* Since the length field is only 16 bits, you cannot download more than 64kBytes of code
67
* Since the exception vectors point to NOR flash, you cannot use Interrupts from your RAM-loaded code
Add picture from clipboard (Maximum size: 48.8 MB)