Skip to content

Commit ae94ca4

Browse files
committed
Update
1 parent 7db8865 commit ae94ca4

File tree

7 files changed

+558
-243
lines changed

7 files changed

+558
-243
lines changed

Makefile

+10-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ USE_PROPRIETARY_APE ?=
99
ifneq ($(USE_PROPRIETARY_APE),)
1010
APE_IMAGE_FN=$(USE_PROPRIETARY_APE)
1111
else
12-
APE_IMAGE_FN=ape_code.bs.bin
12+
ifneq ($(USE_REF_APE),)
13+
APE_IMAGE_FN=ape_code_ref.bs.bin
14+
else
15+
APE_IMAGE_FN=ape_code_poc.bs.bin
16+
endif
1317
endif
1418

1519
ARM_CFLAGS=
1620
TARGET_CFLAGS=-Wno-undefined-internal -DAPE_IMAGE_FN='"$(APE_IMAGE_FN)"'
1721

18-
all: otg.bin otg_dummy.bin otgdbg otgimg apeimg ape_shell.bin ape_code.bs.bin
22+
all: otg.bin otg_dummy.bin otgdbg otgimg apeimg ape_shell.bin $(APE_IMAGE_FN)
1923

2024
clean:
2125
rm -f otg*.bin *.o *.s *.ll-opt *.ll-unopt *.bin.tmp* otgdbg otgimg s1stamp s2stamp apeimg apestamp
@@ -90,15 +94,15 @@ apebyteswap: apebyteswap.o
9094
apebyteswap.o: apebyteswap.c otg.h otg_common.c
9195
$(HOST_CC) -c $(HOST_CFLAGS) -o "$@" "$<" -DOTG_HOST
9296

93-
ape_code.bs.bin: ape_code.bin apebyteswap
97+
ape_code_%.bs.bin: ape_code_%.bin apebyteswap
9498
cp "ape_code.bin" "$@.tmp"
9599
./apebyteswap "$@.tmp"
96100
mv "$@.tmp" "$@"
97-
ape_code.bin: ape_code.o ape_code.ld apestamp apeimg
98-
ld.lld -o "$@.tmp" --oformat binary -T ape_code.ld ape_code.o
101+
ape_code_%.bin: ape_code_%.o ape_code.ld apestamp apeimg
102+
ld.lld -o "$@.tmp" --oformat binary -T ape_code.ld "$<"
99103
./apestamp "$@.tmp" "$@.tmp2"
100104
./apeimg info "$@.tmp2" 2>/dev/null | grep -E '^Defects:\s+none$$' >/dev/null
101105
mv "$@.tmp2" "$@"
102106
rm "$@.tmp"
103-
ape_code.o: ape_code.c
107+
ape_code_%.o: ape_code_%.c
104108
./cc_arm "$@" "$<" -DOTG_APE $(ARM_CFLAGS)

ape_code.ld

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
OUTPUT_FORMAT(binary)
2-
ENTRY(APEEntrypoint)
2+
ENTRY(AEntrypoint)
33

44
SECTIONS {
55
. = 0x00100C00 - 0x78;
@@ -88,6 +88,6 @@ SECTIONS {
8888
_DataOffsetFlags = _DataOffset | (1 << 25); /* CRC32 */
8989
_BSSOffsetFlags = _BSSOffset | (1 << 28); /* ZERO_ON_FAST_BOOT */
9090

91-
_APEEntrypointM = APEEntrypoint & 0xFFFFFFFE;
92-
ASSERT(_APEEntrypointM == (0x001080C0), "entrypoint")
91+
_AEntrypointM = AEntrypoint & 0xFFFFFFFE;
92+
ASSERT(_AEntrypointM == (0x001080C0), "entrypoint")
9393
}

ape_code_poc.c

+276
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
#include "otg.h"
2+
#include <stdint.h>
3+
#include <stdnoreturn.h>
4+
5+
/* Image Build Information {{{1
6+
* -----------------------
7+
*/
8+
#define APE_IMAGE_NAME "OTG NCSI"
9+
#define APE_VER_MAJOR 1
10+
#define APE_VER_MINOR 3
11+
#define APE_VER_PATCH 7
12+
13+
// Originally these used dates/times in the format "Dec 3 2014" and "15:25:28"
14+
// respectively. We don't use dates/times since this needlessly affects build
15+
// determinism. We use something else meaningful instead. Note that these strings
16+
// must remain exactly 11 and 8 characters long, respectively.
17+
#define BUILD_DATE "OTG OTG OTG"
18+
#define BUILD_TIME "HAMSTROK"
19+
static_assert(sizeof(BUILD_DATE) == (11+1), "build date");
20+
static_assert(sizeof(BUILD_TIME) == ( 8+1), "build time");
21+
22+
/* Globals {{{1
23+
* -------
24+
*/
25+
#ifdef PROPRIETARY
26+
/* scrubbed */
27+
/* scrubbed */
28+
#endif
29+
30+
/* ISRs {{{1
31+
* ----
32+
*/
33+
extern isr_table g_isrTable;
34+
35+
noreturn void AHang(void) {
36+
for(;;);
37+
}
38+
39+
INTERRUPT void ISR_Exception(isr_args *args) {
40+
ISR_GET_REGS();
41+
42+
#ifdef PROPRIETARY
43+
/* scrubbed */
44+
/* scrubbed */
45+
/* scrubbed */
46+
/* scrubbed */
47+
/* scrubbed */
48+
/* scrubbed */
49+
/* scrubbed */
50+
/* scrubbed */
51+
/* scrubbed */
52+
/* scrubbed */
53+
/* scrubbed */
54+
/* scrubbed */
55+
/* scrubbed */
56+
/* scrubbed */
57+
/* scrubbed */
58+
/* scrubbed */
59+
/* scrubbed */
60+
/* scrubbed */
61+
/* scrubbed */
62+
/* scrubbed */
63+
/* scrubbed */
64+
/* scrubbed */
65+
/* scrubbed */
66+
/* scrubbed */
67+
/* scrubbed */
68+
/* scrubbed */
69+
/* scrubbed */
70+
/* scrubbed */
71+
/* scrubbed */
72+
/* scrubbed */
73+
/* scrubbed */
74+
/* scrubbed */
75+
/* scrubbed */
76+
/* scrubbed */
77+
/* scrubbed */
78+
/* scrubbed */
79+
/* scrubbed */
80+
/* scrubbed */
81+
#endif
82+
}
83+
84+
INTERRUPT void ISR_SysTick(isr_args *args) {
85+
ISR_GET_REGS();
86+
}
87+
88+
INTERRUPT void ISR_SVCall(isr_args *args) {
89+
ISR_GET_REGS();
90+
}
91+
92+
/* Main {{{1
93+
* ----
94+
*/
95+
#ifdef PROPRIETARY
96+
/* scrubbed */
97+
/* scrubbed */
98+
/* scrubbed */
99+
/* scrubbed */
100+
/* scrubbed */
101+
/* scrubbed */
102+
/* scrubbed */
103+
/* scrubbed */
104+
/* scrubbed */
105+
#endif
106+
107+
/* Init {{{1
108+
* ----
109+
*/
110+
#ifdef PROPRIETARY
111+
/* scrubbed */
112+
/* scrubbed */
113+
/* scrubbed */
114+
/* scrubbed */
115+
/* scrubbed */
116+
/* scrubbed */
117+
/* scrubbed */
118+
/* scrubbed */
119+
/* scrubbed */
120+
/* scrubbed */
121+
/* scrubbed */
122+
/* scrubbed */
123+
/* scrubbed */
124+
/* scrubbed */
125+
/* scrubbed */
126+
/* scrubbed */
127+
/* scrubbed */
128+
/* scrubbed */
129+
/* scrubbed */
130+
/* scrubbed */
131+
/* scrubbed */
132+
/* scrubbed */
133+
/* scrubbed */
134+
/* scrubbed */
135+
/* scrubbed */
136+
/* scrubbed */
137+
/* scrubbed */
138+
/* scrubbed */
139+
/* scrubbed */
140+
/* scrubbed */
141+
/* scrubbed */
142+
/* scrubbed */
143+
/* scrubbed */
144+
/* scrubbed */
145+
/* scrubbed */
146+
/* scrubbed */
147+
/* scrubbed */
148+
/* scrubbed */
149+
/* scrubbed */
150+
/* scrubbed */
151+
/* scrubbed */
152+
/* scrubbed */
153+
/* scrubbed */
154+
/* scrubbed */
155+
/* scrubbed */
156+
/* scrubbed */
157+
/* scrubbed */
158+
#endif
159+
160+
NO_INLINE void AStart(void) {
161+
#ifdef PROPRIETARY
162+
/* scrubbed */
163+
/* scrubbed */
164+
/* scrubbed */
165+
/* scrubbed */
166+
/* scrubbed */
167+
/* scrubbed */
168+
/* scrubbed */
169+
/* scrubbed */
170+
/* scrubbed */
171+
/* scrubbed */
172+
/* scrubbed */
173+
/* scrubbed */
174+
#endif
175+
}
176+
177+
178+
/* Image Headers and Entrypoint {{{1
179+
* ----------------------------
180+
*/
181+
__attribute__((section(".textstart"), naked)) noreturn void AEntrypoint(isr_args *args) {
182+
asm(
183+
"ldr sp, =" STRINGIFY(STACK_END) "\n"
184+
"bl AStart\n"
185+
"bl AHang\n"
186+
);
187+
}
188+
189+
extern int _ScratchTextStart, _ScratchTextEnd, _ScratchTextSize, _ScratchTextOffset, _ScratchTextOffsetFlags;
190+
extern int _TextStart, _TextEnd, _TextSize, _TextOffset, _TextOffsetFlags;
191+
extern int _DataStart, _DataEnd, _DataSize, _DataOffset, _DataOffsetFlags;
192+
extern int _BSSStart, _BSSEnd, _BSSSize, _BSSOffset, _BSSOffsetFlags;
193+
extern int _AEntrypointM;
194+
195+
const __attribute__((section(".header"))) ape_header gAPE_header = {
196+
.magic = "BCM\x1A",
197+
.unk04 = 0x03070700, // Unknown, not read by boot ROM.
198+
.imageName = APE_IMAGE_NAME " " STRINGIFY(APE_VER_MAJOR) "." STRINGIFY(APE_VER_MINOR) "." STRINGIFY(APE_VER_PATCH),
199+
.imageVersion = (APE_VER_MAJOR<<24) | (APE_VER_MINOR<<16) | (APE_VER_PATCH<<8),
200+
201+
// Use the entrypoint vector with the thumb flag masked out; it's actually
202+
// completely inconsequential since the boot ROM will add it back in, but
203+
// the original images don't set it so we don't either.
204+
.entrypoint = (uint32_t)&_AEntrypointM,
205+
206+
.unk020 = 0x00, // Unknown, not read by boot ROM.
207+
.headerSize = sizeof(ape_header)/4,
208+
.unk022 = 0x04, // Unknown, not read by boot ROM.
209+
.numSections = 4,
210+
.headerChecksum = 0xDEADBEEF, // Checksums are fixed later in apestamp.
211+
212+
.sections = {
213+
[0] = { // "Scratchcode"
214+
.loadAddr = (uint32_t)&_ScratchTextStart,
215+
.offsetFlags = (uint32_t)&_ScratchTextOffsetFlags,
216+
.uncompressedSize = (uint32_t)&_ScratchTextSize,
217+
.compressedSize = 0,
218+
.checksum = 0xDEADBEEF,
219+
},
220+
221+
[1] = { // "Maincode"
222+
.loadAddr = (uint32_t)&_TextStart,
223+
.offsetFlags = (uint32_t)&_TextOffsetFlags,
224+
.uncompressedSize = (uint32_t)&_TextSize,
225+
.compressedSize = 0,
226+
.checksum = 0xDEADBEEF,
227+
},
228+
229+
[2] = { // "Data"
230+
.loadAddr = (uint32_t)&_DataStart,
231+
.offsetFlags = (uint32_t)&_DataOffsetFlags,
232+
.uncompressedSize = (uint32_t)&_DataSize,
233+
.compressedSize = 0,
234+
.checksum = 0xDEADBEEF,
235+
},
236+
237+
[3] = { // "BSS"
238+
.loadAddr = (uint32_t)&_BSSStart,
239+
.offsetFlags = (uint32_t)&_BSSOffsetFlags,
240+
.uncompressedSize = (uint32_t)&_BSSSize,
241+
.compressedSize = 0,
242+
.checksum = 0,
243+
},
244+
},
245+
};
246+
247+
__attribute__((section(".isrtable"))) isr_table g_isrTable = {
248+
.stackEnd = (void*)STACK_END,
249+
.reset = AEntrypoint,
250+
.nmi = ISR_Exception,
251+
.hardFault = ISR_Exception,
252+
.memManage = ISR_Exception,
253+
.busFault = ISR_Exception,
254+
.usageFault = ISR_Exception,
255+
.svCall = ISR_SVCall,
256+
.debugMon = ISR_Exception,
257+
.pendSV = ISR_Exception,
258+
.sysTick = ISR_SysTick,
259+
.ext = {
260+
[EXTINT_HANDLE_EVENT] = ISR_Exception,
261+
[EXTINT_03H] = ISR_Exception,
262+
[EXTINT_H2B] = ISR_Exception,
263+
[EXTINT_0AH] = ISR_Exception,
264+
[EXTINT_RX_PACKET_EVEN_PORTS] = ISR_Exception,
265+
[EXTINT_SMBUS_0] = ISR_Exception,
266+
[EXTINT_SMBUS_1] = ISR_Exception,
267+
[EXTINT_RMU_EGRESS] = ISR_Exception,
268+
[EXTINT_GEN_STATUS_CHANGE] = ISR_Exception,
269+
[EXTINT_VOLTAGE_SOURCE_CHANGE] = ISR_Exception,
270+
[EXTINT_LINK_STATUS_CHANGE_EVEN_PORTS] = ISR_Exception,
271+
[EXTINT_LINK_STATUS_CHANGE_ODD_PORTS] = ISR_Exception,
272+
[EXTINT_RX_PACKET_ODD_PORTS] = ISR_Exception,
273+
},
274+
};
275+
276+
__attribute__((section(".trailingcrc"))) uint32_t g_trailingCRC = 0xDEADBEEF;

0 commit comments

Comments
 (0)