├── .gitignore
├── LICENCE
├── Makefile
├── README
├── aes.c
├── bdev.c
├── breakpoint.c
├── bundles
├── AppleTV2,1
│ ├── 8M89
│ │ ├── Makefile
│ │ ├── iBSS
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ │ └── iBoot
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ ├── Makefile
│ ├── bootrom.h
│ └── device.h
├── Common.mk
├── Makefile
├── iPad1,1
│ ├── 7B500
│ │ ├── Makefile
│ │ ├── iBSS
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ │ └── iBoot
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ ├── Makefile
│ ├── bootrom.h
│ └── device.h
├── iPhone2,1
│ ├── 8B117
│ │ ├── Makefile
│ │ ├── iBSS
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ │ └── iBoot
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ ├── Makefile
│ ├── bootrom.h
│ └── device.h
├── iPhone3,1
│ ├── 8B117
│ │ ├── Makefile
│ │ ├── iBSS
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ │ └── iBoot
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ ├── Makefile
│ ├── bootrom.h
│ └── device.h
├── iPod2,1
│ ├── 8B117
│ │ ├── Makefile
│ │ ├── iBSS
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ │ └── iBoot
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ ├── Makefile
│ ├── bootrom.h
│ └── device.h
├── iPod3,1
│ ├── 8B117
│ │ ├── Makefile
│ │ ├── iBSS
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ │ └── iBoot
│ │ │ ├── Makefile
│ │ │ └── offsets.h
│ ├── Makefile
│ ├── bootrom.h
│ └── device.h
└── iPod4,1
│ ├── 8B117
│ ├── Makefile
│ ├── iBSS
│ │ ├── Makefile
│ │ └── offsets.h
│ └── iBoot
│ │ ├── Makefile
│ │ └── offsets.h
│ ├── Makefile
│ ├── bootrom.h
│ └── device.h
├── commands.c
├── common.c
├── coprocessor.S
├── entry.S
├── filesystem.c
├── framebuffer.c
├── free.c
├── functions.c
├── heap.c
├── image.c
├── include
├── aes.h
├── bdev.h
├── breakpoint.h
├── commands.h
├── common.h
├── coprocessor.h
├── filesystem.h
├── font.h
├── framebuffer.h
├── functions.h
├── heap.h
├── image.h
├── kernel.h
├── lock.h
├── memory.h
├── nvram.h
├── patch.h
├── radio.h
├── task.h
└── uart.h
├── kernel.c
├── lock.c
├── main.c
├── malloc.c
├── memory.c
├── nvram.c
├── patch.c
├── radio.c
├── task.c
├── tools
├── Makefile
└── bin2c.c
└── uart.c
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.elf
3 | payload
4 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | mkdir -p payloads
3 | make -C tools
4 | make -C bundles
5 |
6 | clean:
7 | rm -rf payloads
8 | make clean -C tools
9 | make clean -C bundles
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chronic-Dev/cyanide/9fd84704be7ddb3170ec52e178ef942be0c3a5ba/README
--------------------------------------------------------------------------------
/aes.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - aes.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "aes.h"
25 | #include "common.h"
26 | #include "commands.h"
27 | #include "functions.h"
28 |
29 | int(*aes_crypto_cmd)(AesOption option, void* input, void* output, unsigned int size, AesMode mode, void* iv, void* key) = NULL;
30 |
31 | int aes_init() {
32 | //printf("Initializing aes\n");
33 | aes_crypto_cmd = find_function("aes_crypto_cmd", TARGET_BASEADDR, TARGET_BASEADDR);
34 | if(aes_crypto_cmd == NULL) {
35 | puts("Unable to find aes_crypto_cmd\n");
36 | } else {
37 | printf("Found aes_crypto_cmd at 0x%x\n", aes_crypto_cmd);
38 | cmd_add("aes", &aes_cmd, "encrypt/decrypt kbag aes keys using gid");
39 | }
40 |
41 | return 0;
42 | }
43 |
44 | int aes_cmd(int argc, CmdArg* argv) {
45 | int i = 0;
46 | char* kbag = NULL;
47 | char* action = NULL;
48 | unsigned int size = 0;
49 | unsigned char* key = NULL;
50 |
51 | if(argc != 3) {
52 | puts("usage: aes [data]\n");
53 | return 0;
54 | }
55 |
56 | kbag = argv[2].string;
57 | action = argv[1].string;
58 | key = (unsigned char*) malloc(kAesSizeMax);
59 | if(!strcmp(action, "dec")) {
60 | size = aes_decrypt_key(kbag, &key);
61 |
62 | } else if(!strcmp(action, "enc")) {
63 | size = aes_encrypt_key(kbag, &key);
64 |
65 | } else {
66 | free(key);
67 | return -1;
68 | }
69 |
70 | // print iv
71 | enter_critical_section();
72 | printf("-iv ");
73 | for(i = 0; i < 16; i++) {
74 | printf("%02x", key[i]);
75 | }
76 |
77 | // and key
78 | printf(" -k ");
79 | for(i = 16; i < size; i++) {
80 | printf("%02x", key[i]);
81 | }
82 | printf("\n");
83 | exit_critical_section();
84 |
85 | if(key) free(key);
86 | return 0;
87 | }
88 |
89 | unsigned int aes_decrypt_key(unsigned char* in, unsigned char** out) {
90 | int i = 0;
91 | unsigned int size = 0;
92 | unsigned int byte = 0;
93 | unsigned char* data = *out;
94 | if(data == NULL) {
95 | return 0;
96 | }
97 |
98 | size = strlen(in) / 2;
99 | if(size > kAesSizeMax || size < kAesSizeMin) {
100 | return 0;
101 | }
102 |
103 | for(i = 0; i < size; i++) {
104 | sscanf(in, "%02x", &byte);
105 | data[i] = byte;
106 | in += 2;
107 | }
108 |
109 | aes_crypto_cmd(kAesDecrypt, data, data, size, kAesTypeGid, 0, 0);
110 | return size;
111 | }
112 |
113 | unsigned int aes_encrypt_key(unsigned char* in, unsigned char** out) {
114 | int i = 0;
115 | unsigned int size = 0;
116 | unsigned int byte = 0;
117 | unsigned char* data = *out;
118 | if(data == NULL) {
119 | return 0;
120 | }
121 |
122 | size = strlen(in) / 2;
123 | if(size > kAesSizeMax || size < kAesSizeMin) {
124 | return 0;
125 | }
126 |
127 | for(i = 0; i < size; i++) {
128 | sscanf(in, "%02x", &byte);
129 | data[i] = byte;
130 | in += 2;
131 | }
132 |
133 | aes_crypto_cmd(kAesEncrypt, data, data, size, kAesTypeGid, 0, 0);
134 | return size;
135 | }
136 |
--------------------------------------------------------------------------------
/bdev.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - bdev.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "bdev.h"
25 | #include "lock.h"
26 | #include "common.h"
27 | #include "commands.h"
28 |
29 | BdevDescriptor** gBdevList = (void*) SELF_BDEV_LIST;
30 |
31 | void* find_bdev_list() {
32 | return 0;
33 | }
34 |
35 | int bdev_init() {
36 | //gBdevList = find_bdev_list();
37 | if(gBdevList == NULL) {
38 | puts("Unable to find gBdevList\n");
39 | } else {
40 | printf("Found gBdevList at 0x%x\n", gBdevList);
41 | cmd_add("bdev", &bdev_cmd, "read or write data to block devices");
42 | }
43 | return 0;
44 | }
45 |
46 | int bdev_cmd(int argc, CmdArg* argv) {
47 | char* action = NULL;
48 | char* device = NULL;
49 | void* source = NULL;
50 | unsigned int size = 0;
51 | void* destination = NULL;
52 | BdevDescriptor* bdev = NULL;
53 |
54 | if(argc < 2) {
55 | puts("usage: bdev [source] [size] [destination]\n");
56 | puts(" bdev \t\tname of blockdevice\n");
57 | puts(" source \t\tsource address of transaction");
58 | puts(" size \t\tsize of transaction in bytes\n");
59 | puts(" destination \t\tdestination address of transation\n\n");
60 | return 0;
61 | }
62 |
63 | action = argv[1].string;
64 | if(argc == 2) {
65 | if(!strcmp(action, "list")) {
66 | bdev_display_list();
67 | return 0;
68 | }
69 | }
70 |
71 | if(argc == 6) {
72 | device = argv[2].string;
73 | source = (void*) argv[3].uinteger;
74 | size = argv[4].uinteger;
75 | destination = (void*) argv[5].uinteger;
76 | BdevDescriptor* bdev = (BdevDescriptor*) bdev_find_device(device);
77 | if(!bdev) {
78 | puts("unknown block device\n\n");
79 | return -1;
80 | }
81 |
82 | if(!strcmp(action, "read")) {
83 | puts("reading... ");
84 | bdev_read(bdev, destination, source, size);
85 | puts("done\n\n");
86 |
87 | } else if(!strcmp(action, "write")) {
88 | puts("writing... ");
89 | bdev_write(bdev, source, destination, size);
90 | puts("done\n\n");
91 | }
92 | }
93 |
94 | return 0;
95 | }
96 |
97 | BdevDescriptor* bdev_find_device(const char* name) {
98 | BdevDescriptor* bdev = *gBdevList;
99 | while(bdev != NULL) {
100 | if(!strcmp(name, bdev->name)) {
101 | return bdev;
102 | }
103 | bdev = bdev->next;
104 | }
105 | return NULL;
106 | }
107 |
108 | void bdev_display_list() {
109 | BdevDescriptor* bdev = *gBdevList;
110 | enter_critical_section();
111 | printf("Block Devices:\n");
112 | while(bdev != NULL) {
113 | printf(" (0x%08x) name: %s size: %p\n", bdev, bdev->name, bdev->logicalSize);
114 | bdev = bdev->next;
115 | }
116 | printf("\n");
117 | exit_critical_section();
118 | }
119 |
120 | int bdev_read(BdevDescriptor* bdev, void* destination, void* source, unsigned int size) {
121 | enter_critical_section();
122 | printf("read: %p write: %p\n", bdev->read, bdev->write);
123 | exit_critical_section();
124 | bdev->read(bdev, destination, source, 0, size);
125 | return size;
126 | }
127 |
128 | int bdev_write(BdevDescriptor* bdev, void* source, void* destination, unsigned int size) {
129 | bdev->write(bdev, destination, source, 0, size);
130 | return size;
131 | }
132 |
--------------------------------------------------------------------------------
/breakpoint.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - breakpoint.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | * Copyright (C) 2010 Cyril Cattiaux
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | **/
20 |
21 | #include
22 | #include
23 |
24 | #include "lock.h"
25 | #include "common.h"
26 | #include "commands.h"
27 | #include "breakpoint.h"
28 | #include "coprocessor.h"
29 |
30 | /*
31 | * Public Functions
32 | */
33 |
34 | BreakpointEntry* breakpoint_root = NULL;
35 |
36 | BreakpointLog* breakpoint_logs = NULL;
37 |
38 | int break_init() {
39 | cmd_add("break", &break_cmd, "create and delete debugging breakpoints");
40 | return 0;
41 | }
42 |
43 | int break_cmd(int argc, CmdArg* argv) {
44 | char* action = NULL;
45 | unsigned int value = 0;
46 | if(argc < 2) {
47 | enter_critical_section();
48 | puts("usage: break [options]\n");
49 | puts(" list \t\tdisplay list of active breakpoints\n");
50 | puts(" add [ ]\t\tadd new active breakpoint\n");
51 | puts(" remove \t\tremove active breakpoint\n");
52 | puts(" log \n");
53 | puts(" show \t\tdisplay log of hit breakpoints\n");
54 | puts(" show \t\tdisplay a full breakpoint trace\n");
55 | puts(" clear \t\tclears the log\n");
56 | puts("\n");
57 | exit_critical_section();
58 | return 0;
59 | }
60 |
61 | action = argv[1].string;
62 | if(!strcmp(action, "list")) {
63 | if (argc != 2) {
64 | printf("[!] 'list' don't need any argument. Read usage.\n", action);
65 | return -1;
66 | }
67 | breakpoint_list();
68 | return 0;
69 | } else if(!strcmp(action, "add")) {
70 | if (argc != 3 && argc != 5) {
71 | printf("[!] 'log add' needs either 1 or 3 arguments. Read usage.\n");
72 | return -1;
73 | }
74 |
75 | if (argv[2].type!=CMDARG_TYPE_INTEGER) {
76 | puts("[!] must be an integer !\n");
77 | return -1;
78 | }
79 | value = argv[2].uinteger;
80 | BreakpointEntry* bp = breakpoint_add((void *) value, FALSE);
81 | if (bp != NULL) {
82 | enter_critical_section();
83 | printf("New breakpoint at 0x%08x with id %d\n", bp->address, bp->id);
84 | if (argc == 5) {
85 | bp->hexdump_address = (void *) argv[3].uinteger;
86 | bp->hexdump_len = argv[4].uinteger;
87 | printf("The breakpoint will trigger a hexdump of address:0x%08x len:0x%08x.\n", bp->hexdump_address, bp->hexdump_len);
88 | }
89 | exit_critical_section();
90 | return 0;
91 | } else {
92 | enter_critical_section();
93 | printf("[!] Failed to add breakpoint at %0x%08x.\n", value);
94 | exit_critical_section();
95 | return -1;
96 | }
97 | } else if(!strcmp(action, "remove")) {
98 | if (argc != 3) {
99 | printf("[!] 'remove' needs 1 argument: the id of the breakpoint.\n", action);
100 | return -1;
101 | }
102 |
103 | value = argv[2].uinteger;
104 | if (breakpoint_remove(value)) {
105 | enter_critical_section();
106 | printf("Removed breakpoint %d.\n", value);
107 | exit_critical_section();
108 | return 0;
109 | } else {
110 | enter_critical_section();
111 | printf("[!] Breakpoint %d not found.\n", value);
112 | exit_critical_section();
113 | return -1;
114 | }
115 | } else if (!strcmp(action, "log")) {
116 | if (argc < 3 || argv[2].type!=CMDARG_TYPE_STRING) {
117 | printf("[!] 'log' sub-action missing. Read command usage.\n");
118 | return -1;
119 | }
120 | char* subaction = argv[2].string;
121 | if (!strcmp(subaction, "show")) {
122 | if (argc == 4) {
123 | breakpoint_log_show(argv[3].uinteger);
124 | } else if (argc == 3) {
125 | breakpoint_log_list();
126 | } else {
127 | printf("[!] 'log clear' takes either 0 or 1 argument. Read usage.\n", action);
128 | return -1;
129 | }
130 | return 0;
131 | } else if (!strcmp(subaction, "clear")) {
132 | if (argc != 3) {
133 | printf("[!] 'log clear' don't need any argument. Read usage.\n", action);
134 | return -1;
135 | }
136 | breakpoint_log_clear();
137 | printf("Log cleared.\n");
138 | return 0;
139 | } else {
140 | printf("[!] Unknwon 'log' sub-action %s. Read command usage.\n", subaction);
141 | return -1;
142 | }
143 | } else {
144 | enter_critical_section();
145 | printf("[!] Unknown command <%s>.\n", action);
146 | exit_critical_section();
147 | return -1;
148 | }
149 |
150 | return 0;
151 | }
152 |
153 | void breakpoint_log_list() {
154 | BreakpointLog *bl = breakpoint_logs;
155 | enter_critical_section();
156 | if (bl==NULL) {
157 | printf("The log is empty.\n");
158 | } else {
159 | printf("Breakpoint log :\n");
160 | while (bl!=NULL) {
161 | printf("#%04d id:%04d pc=0x%08x\n", bl->id, bl->bp_id, bl->pc);
162 | bl = bl->next;
163 | }
164 | }
165 | exit_critical_section();
166 | }
167 |
168 | void breakpoint_log_show(unsigned int id) {
169 | BreakpointLog *bl = breakpoint_log_find(id);
170 | enter_critical_section();
171 | if (bl==NULL) {
172 | printf("[!] Can't find the log entry of id %d\n", id);
173 | } else {
174 | printf("Breakpoint log entry #%d:\n", bl->id);
175 | printf("\nBreakpoint %d hit at 0x%08x\n", bl->bp_id, bl->pc);
176 | printf(" r0: 0x%08x r1: 0x%08x r2: 0x%08x r3: 0x%08x\n", bl->r0, bl->r1, bl->r2, bl->r3);
177 | printf(" r4: 0x%08x r5: 0x%08x r6: 0x%08x r7: 0x%08x\n", bl->r4, bl->r5, bl->r6, bl->r7);
178 | printf(" r8: 0x%08x r9: 0x%08x r10: 0x%08x r11: 0x%08x\n", bl->r8, bl->r9, bl->r10, bl->r11);
179 | printf(" r12: 0x%08x sp: 0x%08x lr: 0x%08x spsr: 0x%08x\n", bl->r12, bl->sp, bl->lr, bl->spsr);
180 |
181 | printf("\nStack Dump:\n");
182 | int sp = bl->sp;
183 | int i;
184 | for(i = 0; i < 0x10; i += 4) {
185 | printf("0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n", sp, bl->stack[i], bl->stack[i+1], bl->stack[i+2], bl->stack[i+3]);
186 | sp += 0x10;
187 | }
188 |
189 | if (bl->hexdump_result!=NULL) {
190 | printf("\nMemory Dump of 0x%08x:\n", bl->hexdump_address);
191 | hexdump((unsigned char*) bl->hexdump_result, bl->hexdump_len);
192 | }
193 |
194 | printf("\n");
195 | }
196 | exit_critical_section();
197 | }
198 |
199 | void breakpoint_log_clear() {
200 | BreakpointLog *bl = breakpoint_logs;
201 | while (bl!=NULL) {
202 | BreakpointLog *tmp = bl;
203 | bl = bl->next;
204 | if (tmp->hexdump_result!=NULL) free(tmp->hexdump_result);
205 | free(tmp);
206 | }
207 | breakpoint_logs = NULL;
208 | }
209 |
210 | BreakpointLog* breakpoint_log_find(unsigned int id) {
211 | BreakpointLog *bl = breakpoint_logs;
212 | while (bl!=NULL) {
213 | if (bl->id==id) {
214 | return bl;
215 | }
216 | bl = bl->next;
217 | }
218 | return NULL;
219 | }
220 |
221 | void breakpoint_log_add(BreakpointLog *log) {
222 | if (breakpoint_logs==NULL) {
223 | log->id = 0;
224 | log->next = NULL;
225 | breakpoint_logs = log;
226 | } else {
227 | // seek to last element
228 | BreakpointLog *bl = breakpoint_logs;
229 | int id = 0;
230 | while (bl->next!=NULL) {
231 | id = bl->id + 1;
232 | bl = bl->next;
233 | }
234 | if (bl!=NULL) id = bl->id +1;
235 | log->id = id;
236 | log->next = NULL;
237 | bl->next = log;
238 | }
239 | }
240 |
241 | BreakpointLog* breakpoint_log_remove(unsigned int id) {
242 | BreakpointLog *prev = breakpoint_logs;
243 | BreakpointLog *bl = breakpoint_logs;
244 | while (bl!=NULL) {
245 | if (bl->id==id) {
246 | prev->next = bl->next;
247 | return bl;
248 | }
249 | prev = bl;
250 | bl = bl->next;
251 | }
252 | return NULL;
253 | }
254 |
255 | void breakpoint_list() {
256 | enter_critical_section();
257 |
258 | BreakpointEntry* bp = breakpoint_root;
259 | if(bp == NULL) {
260 | printf("No active breakpoints\n");
261 | } else {
262 | printf("Breakpoints:\n");
263 | while(bp != NULL) {
264 | if(*((unsigned int*)bp->address) == bp->value) {
265 | *((volatile unsigned short*)bp->address) = BKPT_THUMB;
266 | }
267 | printf(" [%d] 0x%08x reset:%s hexdump:0x%08x-0x%08x\n", bp->id, bp->address,
268 | bp->reset ? "true" : "false", bp->hexdump_address, bp->hexdump_len);
269 |
270 | bp = bp->next;
271 | }
272 | printf("\n");
273 | }
274 |
275 | exit_critical_section();
276 | }
277 |
278 | BreakpointEntry* breakpoint_add(void* address, Bool reset) {
279 | BreakpointEntry* bp = breakpoint_root;
280 | if(bp != NULL) {
281 | while(bp != NULL) {
282 | if(*((unsigned int*)bp->address) == bp->value) {
283 | *((volatile unsigned short*)bp->address) = BKPT_THUMB;
284 | }
285 |
286 | if(bp->next == NULL) {
287 | BreakpointEntry* new_bp = malloc(sizeof(BreakpointEntry));
288 | new_bp->id = bp->id + 1;
289 | new_bp->reset = reset;
290 | new_bp->value = *((unsigned int*)address);
291 | new_bp->address = (void*)address;
292 | new_bp->next = NULL;
293 | new_bp->hexdump_address = NULL;
294 | new_bp->hexdump_len = 0;
295 | bp->next = new_bp;
296 |
297 | *((volatile unsigned short*)address) = BKPT_THUMB;
298 | clear_icache();
299 | //clear_dcache();
300 |
301 | return new_bp;
302 | }
303 | bp = bp->next;
304 | }
305 |
306 | } else {
307 | // no breakpoints exist yet, create breakpoint_root
308 | breakpoint_root = malloc(sizeof(BreakpointEntry));
309 | breakpoint_root->id = 0;
310 | breakpoint_root->reset = reset;
311 | breakpoint_root->value = *((unsigned int*)address);
312 | breakpoint_root->address = (void*)address;
313 | breakpoint_root->next = NULL;
314 | breakpoint_root->hexdump_address = NULL;
315 | breakpoint_root->hexdump_len = 0;
316 |
317 | *((volatile unsigned short*)address) = BKPT_THUMB;
318 | clear_icache();
319 | //clear_dcache();
320 |
321 | return breakpoint_root;
322 | }
323 |
324 | return NULL;
325 | }
326 |
327 | Bool breakpoint_remove(unsigned int id) {
328 | BreakpointEntry* prev = NULL;
329 | BreakpointEntry* bp = breakpoint_root;
330 | while(bp != NULL) {
331 | if(bp->id == id) {
332 | if(prev == NULL) {
333 | breakpoint_root = bp->next;
334 | } else {
335 | prev->next = bp->next;
336 | }
337 | *((volatile unsigned int*)bp->address) = bp->value;
338 | clear_icache();
339 | //clear_dcache();
340 |
341 | //free(bp);
342 | return TRUE;
343 | }
344 | prev = bp;
345 | bp = bp->next;
346 | }
347 |
348 | return FALSE;
349 | }
350 |
351 | /*
352 | * Private Functions
353 | */
354 | void breakpoint(unsigned int* stack) {
355 | BreakpointEntry* bp = breakpoint_root;
356 |
357 | unsigned int r[13];
358 | unsigned int *sp = (unsigned int*) stack[0];
359 | unsigned int lr = stack[1];
360 | unsigned int spsr = stack[2];
361 | unsigned int pc = stack[16];
362 | unsigned int i = 0;
363 | for(i = 0; i <= 12; i++) {
364 | r[i] = stack[i+3];
365 | }
366 |
367 | unsigned int id = 0;
368 | void* hexdump_address = NULL;
369 | unsigned int hexdump_len = 0;
370 | while(bp != NULL) {
371 | if(bp->address == (void*) pc) {
372 | if(bp->reset) {
373 | // reset our original breakpoint and remove our reset breakpoint
374 | hexdump_address = bp->hexdump_address;
375 | hexdump_len = bp->hexdump_len;
376 | if (breakpoint_remove(bp->id)) {
377 | BreakpointEntry *bp_copy = breakpoint_add(bp->address - 2, FALSE);
378 | bp_copy->hexdump_address = hexdump_address;
379 | bp_copy->hexdump_len = hexdump_len;
380 | }
381 | return;
382 | }
383 |
384 | // add the reset breakpoint and remove the original
385 | id = bp->id;
386 | hexdump_address = bp->hexdump_address;
387 | hexdump_len = bp->hexdump_len;
388 | if (breakpoint_remove(bp->id)) {
389 | BreakpointEntry *bp_reset = breakpoint_add(bp->address + 2, TRUE);
390 | bp_reset->hexdump_address = hexdump_address;
391 | bp_reset->hexdump_len = hexdump_len;
392 | }
393 |
394 | break;
395 | }
396 | bp = bp->next;
397 | }
398 |
399 | BreakpointLog *bl = malloc(sizeof(BreakpointLog));
400 | bl->r0 = r[0];
401 | bl->r1 = r[1];
402 | bl->r2 = r[2];
403 | bl->r3 = r[3];
404 | bl->r4 = r[4];
405 | bl->r5 = r[5];
406 | bl->r6 = r[6];
407 | bl->r7 = r[7];
408 | bl->r8 = r[8];
409 | bl->r9 = r[9];
410 | bl->r10 = r[10];
411 | bl->r11 = r[11];
412 | bl->r12 = r[12];
413 | bl->sp = (unsigned int) sp;
414 | bl->lr = lr;
415 | bl->spsr = spsr;
416 | bl->pc = pc;
417 | bl->bp_id = id;
418 | for(i = 0; i < 0x10; i++) {
419 | bl->stack[i] = sp[i];
420 | }
421 | if (hexdump_len > 0) {
422 | unsigned char* buf = (unsigned char*) malloc(hexdump_len);
423 | memcpy(buf, hexdump_address, hexdump_len);
424 | bl->hexdump_address = hexdump_address;
425 | bl->hexdump_len = hexdump_len;
426 | bl->hexdump_result = (void*) buf;
427 | } else {
428 | bl->hexdump_address = NULL;
429 | bl->hexdump_len = 0;
430 | bl->hexdump_result = NULL;
431 | }
432 | breakpoint_log_add(bl);
433 | breakpoint_log_show(bl->id);
434 | }
435 |
--------------------------------------------------------------------------------
/bundles/AppleTV2,1/8M89/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C iBSS
3 | make -C iBoot
4 |
5 | clean:
6 | make clean -C iBSS
7 | make clean -C iBoot
--------------------------------------------------------------------------------
/bundles/AppleTV2,1/8M89/iBSS/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBSS
8 | MODEL = k66ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o patch.o memory.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/AppleTV2,1/8M89/iBSS/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - AppleTV2,1/8M86/iBSS/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef OFFSETS_H
21 | #define OFFSETS_H
22 |
23 | // Base address
24 | #define TARGET_BASEADDR (0x84000000)
25 |
26 | // Standard offsets
27 | #define TARGET_FREE (0xE57C+1)
28 | #define TARGET_MALLOC (0xE588+1)
29 | #define TARGET_JUMP_TO (0x11A40+1)
30 | #define TARGET_PRINTF (0x17078+1)
31 | #define TARGET_VPRINTF (0x0+1)
32 |
33 | // Command offsets
34 | #define TARGET_CMD_LIST_BEGIN (0x1E000)
35 | #define TARGET_CMD_LIST_END (0x1E02C)
36 |
37 | // Task functions
38 | #define TARGET_TASK_YIELD (0x1233C+1)
39 | #define TARGET_TASK_RUNNING (0x1E3C0)
40 | #define TARGET_TASK_LIST (0x21348)
41 |
42 | // AES offsets
43 | #define TARGET_AES_CRYPTO_CMD (0x1360C+1)
44 |
45 | // BDev offsets
46 | #define TARGET_BDEV_LIST (0x20924)
47 |
48 | // Image offsets
49 | #define TARGET_IMAGE_LIST (0x1E390)
50 |
51 | // Filesystem offsets
52 | //#define TARGET_FS_MOUNT (0x0)
53 | //#define TARGET_FS_UNMOUNT (0x0)
54 | //#define TARGET_FS_LOAD_FILE (0x0)
55 |
56 | // Kernel offsets
57 | #define TARGET_KERNEL_LOAD (0xF0CC+1)
58 | #define TARGET_KERNEL_PHYMEM (0x21D80)
59 | #define TARGET_KERNEL_BOOTARGS (0x1B22C)
60 |
61 | // NVRAM offsets
62 | #define TARGET_NVRAM_LIST (0x1E498)
63 |
64 | #endif // OFFSETS_H
65 |
--------------------------------------------------------------------------------
/bundles/AppleTV2,1/8M89/iBoot/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBoot
8 | MODEL = k66ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/AppleTV2,1/8M89/iBoot/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - AppleTV2,1/8M86/iBoot/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef OFFSETS_H
21 | #define OFFSETS_H
22 |
23 | // Base address
24 | #define TARGET_BASEADDR (0x5FF00000)
25 |
26 | // Standard offsets
27 | #define TARGET_FREE (0x11F60+1)
28 | #define TARGET_MALLOC (0x11F6C+1)
29 | #define TARGET_JUMP_TO (0x15B14+1)
30 | #define TARGET_PRINTF (0x24AE0+1)
31 | #define TARGET_VPRINTF (0x0+1)
32 |
33 | // Command offsets
34 | #define TARGET_CMD_LIST_BEGIN (0x31568)
35 | #define TARGET_CMD_LIST_END (0x31580)
36 | #define TARGET_CMD_RAMDISK (0xF84+1)
37 |
38 | // Task functions
39 | #define TARGET_TASK_YIELD (0x16438+1)
40 | #define TARGET_TASK_RUNNING (0x31428)
41 | #define TARGET_TASK_LIST (0x314C0)
42 |
43 | // AES offsets
44 | #define TARGET_AES_CRYPTO_CMD (0x1770C+1)
45 |
46 | // BDev offsets
47 | #define TARGET_BDEV_LIST (0xFFFFFFFF)
48 |
49 | // Image offsets
50 | #define TARGET_IMAGE_LIST (0x313F8)
51 |
52 | // Filesystem offsets
53 | #define TARGET_FS_MOUNT (0x19F40+1)
54 | #define TARGET_FS_UNMOUNT (0x0+1)
55 | #define TARGET_FS_LOAD_FILE (0x1A0F0+1)
56 |
57 | // Kernel offsets
58 | #define TARGET_KERNEL_LOAD (0x13924+1)
59 | #define TARGET_KERNEL_PHYMEM (0x362C0)
60 | #define TARGET_KERNEL_BOOTARGS (0x28C5C)
61 |
62 | // NVRAM offset
63 | #define TARGET_NVRAM_LIST (0x31504)
64 |
65 | #endif // OFFSETS_H
66 |
--------------------------------------------------------------------------------
/bundles/AppleTV2,1/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C 8M89
3 |
4 | clean:
5 | make clean -C 8M89
--------------------------------------------------------------------------------
/bundles/AppleTV2,1/bootrom.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - AppleTV2,1/bootrom.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef BOOTROM_H
21 | #define BOOTROM_H
22 |
23 |
24 | #endif // BOOTROM_H
25 |
--------------------------------------------------------------------------------
/bundles/AppleTV2,1/device.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - AppleTV2.1/device.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef DEVICE_H
21 | #define DEVICE_H
22 |
23 | #define S5L8930X
24 | #define LOADADDR 0x41000000
25 | #define FRAMEBUFFER 0x5F700000
26 | #define FRAMEBUFFER_WIDTH 1024
27 | #define FRAMEBUFFER_HEIGHT 768
28 | #define IBOOT_BASEADDR 0x5FF00000
29 | #define IBEC_BASEADDR 0x5FF00000
30 | #define IBSS_BASEADDR 0x84000000
31 | #define LLB_BASEADDR 0x84000000
32 | #define KERNEL_PATH "/boot/System/Library/Caches/com.apple.kernelcaches/kernelcache"
33 |
34 | #endif // DEVICE_H
35 |
--------------------------------------------------------------------------------
/bundles/Common.mk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chronic-Dev/cyanide/9fd84704be7ddb3170ec52e178ef942be0c3a5ba/bundles/Common.mk
--------------------------------------------------------------------------------
/bundles/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C iPad1,1
3 | make -C iPhone2,1
4 | make -C iPhone3,1
5 | make -C iPod2,1
6 | make -C iPod3,1
7 | make -C iPod4,1
8 | make -C AppleTV2,1
9 |
10 | clean:
11 | make clean -C iPad1,1
12 | make clean -C iPhone2,1
13 | make clean -C iPhone3,1
14 | make clean -C iPod2,1
15 | make clean -C iPod3,1
16 | make clean -C iPod4,1
17 | make clean -C AppleTV2,1
18 |
19 |
--------------------------------------------------------------------------------
/bundles/iPad1,1/7B500/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C iBSS
3 | make -C iBoot
4 |
5 | clean:
6 | make clean -C iBSS
7 | make clean -C iBoot
--------------------------------------------------------------------------------
/bundles/iPad1,1/7B500/iBSS/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBSS
8 | MODEL = k48ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPad1,1/7B500/iBSS/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPad1,1/7B500/iBSS/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef OFFSETS_H
21 | #define OFFSETS_H
22 |
23 | // Base address
24 | #define TARGET_BASEADDR (0x84000000)
25 |
26 | // Standard offsets
27 | #define TARGET_FREE (0x9DCC+1)
28 | #define TARGET_MALLOC (0x9DD8+1)
29 | #define TARGET_JUMP_TO (0xDEF4+1)
30 | #define TARGET_PRINTF (0x12E44+1)
31 | #define TARGET_VPRINTF (0x12DF4+1)
32 |
33 | // Command offsets
34 | #define TARGET_CMD_LIST_BEGIN (0x19000)
35 | #define TARGET_CMD_LIST_END (0x1902C)
36 |
37 | // Task functions
38 | #define TARGET_TASK_YIELD (0xE770+1)
39 | #define TARGET_TASK_RUNNING (0x19714)
40 | #define TARGET_TASK_LIST (0x197AC)
41 |
42 | // AES offsets
43 | #define TARGET_AES_CRYPTO_CMD (0xF900+1)
44 |
45 | // BDev offsets
46 | #define TARGET_BDEV_LIST (0x1B9E0)
47 |
48 | // Image offsets
49 | #define TARGET_IMAGE_LIST (0x196F4)
50 |
51 | // Filesystem offsets
52 | //#define TARGET_FS_MOUNT (0x0)
53 | //#define TARGET_FS_UNMOUNT (0x0)
54 | //#define TARGET_FS_LOAD_FILE (0x0)
55 |
56 | // Kernel offsets
57 | #define TARGET_KERNEL_LOAD (0xA5A4+1)
58 | #define TARGET_KERNEL_PHYMEM (0x1BA80)
59 | #define TARGET_KERNEL_BOOTARGS (0x1637C)
60 |
61 | // NVRAM offsets
62 | #define TARGET_NVRAM_LIST (0x197E8)
63 |
64 | #endif // OFFSETS_H
65 |
--------------------------------------------------------------------------------
/bundles/iPad1,1/7B500/iBoot/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBoot
8 | MODEL = k48ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPad1,1/7B500/iBoot/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPad1,1/7B500/iBoot/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef OFFSETS_H
21 | #define OFFSETS_H
22 |
23 | // Base address
24 | #define TARGET_BASEADDR (0x5FF00000)
25 |
26 | // Standard offsets
27 | #define TARGET_FREE (0xCA94+1)
28 | #define TARGET_MALLOC (0xD2C8+1)
29 | #define TARGET_JUMP_TO (0x1147C+1)
30 | #define TARGET_PRINTF (0x1F1EC+1)
31 | #define TARGET_VPRINTF (0x1EB38+1)
32 |
33 | // Command offsets
34 | #define TARGET_CMD_LIST_BEGIN (0x29000)
35 | #define TARGET_CMD_LIST_END (0x2902C)
36 |
37 | // Task functions
38 | #define TARGET_TASK_YIELD (0x11D94+1)
39 | #define TARGET_TASK_RUNNING (0x2976C)
40 | #define TARGET_TASK_LIST (0x29804)
41 |
42 | // AES offsets
43 | #define TARGET_AES_CRYPTO_CMD (0x1300C+1)
44 |
45 | // BDev offsets
46 | #define TARGET_BDEV_LIST (0x2D140)
47 |
48 | // Image offsets
49 | #define TARGET_IMAGE_LIST (0x2974C)
50 |
51 | // Filesystem offsets
52 | //#define TARGET_FS_MOUNT (0x0)
53 | //#define TARGET_FS_UNMOUNT (0x0)
54 | //#define TARGET_FS_LOAD_FILE (0x0)
55 |
56 | // NVRAM offsets
57 | #define TARGET_NVRAM_LIST (0x29844)
58 |
59 | #endif // OFFSETS_H
60 |
--------------------------------------------------------------------------------
/bundles/iPad1,1/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C 7B500
3 |
4 | clean:
5 | make clean -C 7B500
6 |
--------------------------------------------------------------------------------
/bundles/iPad1,1/bootrom.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPad1,1/bootrom.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef BOOTROM_H
21 | #define BOOTROM_H
22 |
23 |
24 | #endif // BOOTROM_H
25 |
--------------------------------------------------------------------------------
/bundles/iPad1,1/device.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPad1,1/device.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef DEVICE_H
21 | #define DEVICE_H
22 |
23 | #define S5L8930X
24 | #define LOADADDR 0x41000000
25 | #define FRAMEBUFFER 0x5F700000
26 | #define FRAMEBUFFER_WIDTH 1024
27 | #define FRAMEBUFFER_HEIGHT 768
28 | #define IBOOT_BASEADDR 0x5FF00000
29 | #define IBEC_BASEADDR 0x5FF00000
30 | #define IBSS_BASEADDR 0x84000000
31 | #define LLB_BASEADDR 0x84000000
32 | #define KERNEL_PATH "/System/Library/Caches/com.apple.kernelcache/kernelcache"
33 |
34 | #endif // DEVICE_H
35 |
--------------------------------------------------------------------------------
/bundles/iPhone2,1/8B117/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C iBSS
3 | make -C iBoot
4 |
5 | clean:
6 | make clean -C iBSS
7 | make clean -C iBoot
--------------------------------------------------------------------------------
/bundles/iPhone2,1/8B117/iBSS/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBSS
8 | MODEL = n88ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPhone2,1/8B117/iBSS/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone2,1/8B117/iBSS/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef OFFSETS_H
21 | #define OFFSETS_H
22 |
23 | // Base address
24 | #define TARGET_BASEADDR (0x84000000)
25 |
26 | // Standard offsets
27 | #define TARGET_FREE (0xA5CC+1)
28 | #define TARGET_MALLOC (0xA5D8+1)
29 | #define TARGET_JUMP_TO (0xDED8+1)
30 | #define TARGET_PRINTF (0x134CC+1)
31 | #define TARGET_VPRINTF (0x0+1)
32 |
33 | // Command offsets
34 | #define TARGET_CMD_LIST_BEGIN (0x19000)
35 | #define TARGET_CMD_LIST_END (0x1902C)
36 | #define TARGET_CMD_RAMDISK (0xDEAD+1)
37 |
38 | // Task functions
39 | #define TARGET_TASK_YIELD (0xE760+1)
40 | #define TARGET_TASK_RUNNING (0x19C00)
41 | #define TARGET_TASK_LIST (0x19C98)
42 |
43 | // AES offsets
44 | #define TARGET_AES_CRYPTO_CMD (0xF9B8+1)
45 |
46 | // BDev offsets
47 | #define TARGET_BDEV_LIST (0x1C300)
48 |
49 | // Image offsets
50 | #define TARGET_IMAGE_LIST (0x19BD0)
51 |
52 | // Filesystem offsets
53 | //#define TARGET_FS_MOUNT (0x0)
54 | //#define TARGET_FS_UNMOUNT (0x0)
55 | //#define TARGET_FS_LOAD_FILE (0x0)
56 |
57 | // Kernel offsets
58 | #define TARGET_KERNEL_LOAD (0xB11C+1)
59 | #define TARGET_KERNEL_PHYMEM (0x15DE4)
60 | #define TARGET_KERNEL_BOOTARGS (0x1C3C0)
61 |
62 | // NVRAM offsets
63 | #define TARGET_NVRAM_LIST (0x19CD4)
64 |
65 | #endif // OFFSETS_H
66 |
--------------------------------------------------------------------------------
/bundles/iPhone2,1/8B117/iBoot/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBoot
8 | MODEL = n88ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPhone2,1/8B117/iBoot/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone2,1/8B117/iBoot/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | * Copyright (C) 2010 Nicolas Haunold
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | **/
20 |
21 | #ifndef OFFSETS_H
22 | #define OFFSETS_H
23 |
24 | // Base address
25 | #define TARGET_BASEADDR (0x4FF00000)
26 |
27 | // Standard offsets
28 | #define TARGET_FREE (0xDB24+1)
29 | #define TARGET_MALLOC (0xDB30+1)
30 | #define TARGET_JUMP_TO (0x1164C+1)
31 | #define TARGET_PRINTF (0x20538+1)
32 | #define TARGET_VPRINTF (0x204E8+1)
33 |
34 | // Command offsets
35 | #define TARGET_CMD_LIST_BEGIN (0x29DD4)
36 | #define TARGET_CMD_LIST_END (0x29DEC)
37 | //#define TARGET_CMD_RAMDISK (0xDEAD+1)
38 |
39 | // Task functions
40 | #define TARGET_TASK_YIELD (0x11F70+1)
41 | #define TARGET_TASK_RUNNING (0x29C94)
42 | #define TARGET_TASK_LIST (0x29D2C)
43 |
44 | // AES offsets
45 | #define TARGET_AES_CRYPTO_CMD (0x132E0+1)
46 |
47 | // BDev offsets
48 | #define TARGET_BDEV_LIST (0x2D800)
49 |
50 | // Image offsets
51 | #define TARGET_IMAGE_LIST (0x29C64)
52 |
53 | // Filesystem offsets
54 | //#define TARGET_FS_MOUNT (0xDEAD+1)
55 | //#define TARGET_FS_UNMOUNT (0xDEAD+1)
56 | //#define TARGET_FS_LOAD_FILE (0xDEAD+1)
57 |
58 | // Kernel offsets
59 | #define TARGET_KERNEL_LOAD (0xE674+1)
60 | #define TARGET_KERNEL_PHYMEM (0x2E240)
61 | #define TARGET_KERNEL_BOOTARGS (0x2372C)
62 |
63 | // NVRAM offset
64 | #define TARGET_NVRAM_LIST (0x29D70)
65 |
66 | #endif // OFFSETS_H
67 |
--------------------------------------------------------------------------------
/bundles/iPhone2,1/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C 8B117
3 |
4 | clean:
5 | make clean -C 8B117
6 |
--------------------------------------------------------------------------------
/bundles/iPhone2,1/bootrom.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone3,1/bootrom.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef BOOTROM_H
21 | #define BOOTROM_H
22 |
23 |
24 | #endif // BOOTROM_H
25 |
--------------------------------------------------------------------------------
/bundles/iPhone2,1/device.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone3,1/device.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef DEVICE_H
21 | #define DEVICE_H
22 |
23 | #define S5L8920X
24 | #define LOADADDR 0x41000000
25 | #define FRAMEBUFFER 0x4FD00000
26 | #define FRAMEBUFFER_WIDTH 320
27 | #define FRAMEBUFFER_HEIGHT 480
28 | #define IBOOT_BASEADDR 0x4FF00000
29 | #define IBEC_BASEADDR 0x4FF00000
30 | #define IBSS_BASEADDR 0x84000000
31 | #define LLB_BASEADDR 0x84000000
32 | #define KERNEL_PATH "/boot/System/Library/Caches/com.apple.kernelcaches/kernelcache"
33 |
34 | #endif // DEVICE_H
35 |
--------------------------------------------------------------------------------
/bundles/iPhone3,1/8B117/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C iBSS
3 | make -C iBoot
4 |
5 | clean:
6 | make clean -C iBSS
7 | make clean -C iBoot
--------------------------------------------------------------------------------
/bundles/iPhone3,1/8B117/iBSS/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBSS
8 | MODEL = n90ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPhone3,1/8B117/iBSS/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone3,1/8B117/iBSS/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef OFFSETS_H
21 | #define OFFSETS_H
22 |
23 | // Base address
24 | #define TARGET_BASEADDR (0x84000000)
25 |
26 | // Standard offsets
27 | #define TARGET_FREE (0x12220+1)
28 | #define TARGET_MALLOC (0x1222C+1)
29 | #define TARGET_JUMP_TO (0x15E18+1)
30 | #define TARGET_PRINTF (0x1B684+1)
31 | #define TARGET_VPRINTF (0x1AF54+1)
32 |
33 | // Command offsets
34 | #define TARGET_CMD_LIST_BEGIN (0x24000)
35 | #define TARGET_CMD_LIST_END (0x2402C)
36 |
37 | // Task functions
38 | #define TARGET_TASK_YIELD (0x16714+1)
39 | #define TARGET_TASK_RUNNING (0x24880)
40 | #define TARGET_TASK_LIST (0x24918)
41 |
42 | // AES offsets
43 | #define TARGET_AES_CRYPTO_CMD (0x17B50+1)
44 |
45 | // BDev offsets
46 | #define TARGET_BDEV_LIST (0x28440)
47 |
48 | // Image offsets
49 | #define TARGET_IMAGE_LIST (0x24850)
50 |
51 | // Filesystem offsets
52 | //#define TARGET_FS_MOUNT (0x0)
53 | //#define TARGET_FS_UNMOUNT (0x0)
54 | //#define TARGET_FS_LOAD_FILE (0x0)
55 |
56 | // Kernel offsets
57 | #define TARGET_KERNEL_LOAD (0x12D70+1)
58 | #define TARGET_KERNEL_PHYMEM (0x28980)
59 | #define TARGET_KERNEL_BOOTARGS (0x20B04)
60 |
61 | // NVRAM offsets
62 | #define TARGET_NVRAM_LIST (0x24958)
63 |
64 | #endif // OFFSETS_H
65 |
--------------------------------------------------------------------------------
/bundles/iPhone3,1/8B117/iBoot/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBoot
8 | MODEL = n90ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPhone3,1/8B117/iBoot/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone3,1/8B117/iBoot/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef OFFSETS_H
21 | #define OFFSETS_H
22 |
23 | // Base address
24 | #define TARGET_BASEADDR (0x5FF00000)
25 |
26 | // Standard offsets
27 | #define TARGET_FREE (0x12BB8+1) // image3_free
28 | #define TARGET_MALLOC (0x12BC4+1) // image3_malloc
29 | #define TARGET_JUMP_TO (0x1684C+1)
30 | #define TARGET_PRINTF (0x2C3D4+1)
31 | #define TARGET_VPRINTF (0x2BCA4+1)
32 |
33 | // Command offsets
34 | #define TARGET_CMD_LIST_BEGIN (0x399D8)
35 | #define TARGET_CMD_LIST_END (0x399F0)
36 | //#define TARGET_CMD_RAMDISK (0x1058+1)
37 |
38 | // Task functions
39 | #define TARGET_TASK_YIELD (0x17170+1)
40 | #define TARGET_TASK_RUNNING (0x3987C)
41 | #define TARGET_TASK_LIST (0x39914)
42 |
43 | // AES offsets
44 | #define TARGET_AES_CRYPTO_CMD (0x185AC+1)
45 |
46 | // BDev offsets
47 | #define TARGET_BDEV_LIST (0x3D800)
48 |
49 | // Image offsets
50 | #define TARGET_IMAGE_LIST (0x3984C)
51 |
52 | // Filesystem offsets
53 | #define TARGET_FS_MOUNT (0x1ADC0+1)
54 | #define TARGET_FS_UNMOUNT (0x1AFD8+1)
55 | #define TARGET_FS_LOAD_FILE (0x1AF70+1)
56 |
57 | // Kernel offsets
58 | #define TARGET_KERNEL_LOAD (0x13708+1)
59 | #define TARGET_KERNEL_PHYMEM (0x3EC40)
60 |
61 | // NVRAM offset
62 | #define TARGET_NVRAM_LIST (0x39958)
63 |
64 | #endif // OFFSETS_H
65 |
--------------------------------------------------------------------------------
/bundles/iPhone3,1/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C 8B117
3 |
4 | clean:
5 | make clean -C 8B117
6 |
--------------------------------------------------------------------------------
/bundles/iPhone3,1/bootrom.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone3,1/bootrom.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef BOOTROM_H
21 | #define BOOTROM_H
22 |
23 |
24 | #endif // BOOTROM_H
25 |
--------------------------------------------------------------------------------
/bundles/iPhone3,1/device.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone3,1/device.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef DEVICE_H
21 | #define DEVICE_H
22 |
23 | #define S5L8930X
24 | #define LOADADDR 0x41000000
25 | #define FRAMEBUFFER 0x5F700000
26 | #define FRAMEBUFFER_WIDTH 640
27 | #define FRAMEBUFFER_HEIGHT 960
28 | #define IBOOT_BASEADDR 0x5FF00000
29 | #define IBEC_BASEADDR 0x5FF00000
30 | #define IBSS_BASEADDR 0x84000000
31 | #define LLB_BASEADDR 0x84000000
32 | #define KERNEL_PATH "/boot/System/Library/Caches/com.apple.kernelcaches/kernelcache"
33 |
34 | #endif // DEVICE_H
35 |
--------------------------------------------------------------------------------
/bundles/iPod2,1/8B117/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C iBSS
3 | make -C iBoot
4 |
5 | clean:
6 | make clean -C iBSS
7 | make clean -C iBoot
--------------------------------------------------------------------------------
/bundles/iPod2,1/8B117/iBSS/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x0A000000
7 | TYPE = iBSS
8 | MODEL = n72ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPod2,1/8B117/iBSS/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPod2,1/8B117/iBSS/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef OFFSETS_H
21 | #define OFFSETS_H
22 |
23 | // Base address
24 | #define TARGET_BASEADDR (0x22000000)
25 |
26 | // Standard offsets
27 | #define TARGET_FREE (0x7E64+1)
28 | #define TARGET_MALLOC ((0x7E6E)+1)
29 | #define TARGET_JUMP_TO (0xC198+1)
30 | #define TARGET_PRINTF (0x11478+1)
31 | #define TARGET_VPRINTF (0x11430+1)
32 |
33 | // Command offsets
34 | #define TARGET_CMD_LIST_BEGIN (0x17000)
35 | #define TARGET_CMD_LIST_END (0x1702C)
36 |
37 | // Task functions
38 | #define TARGET_TASK_YIELD (0xCA22+1)
39 | #define TARGET_TASK_RUNNING (0x17C08)
40 | #define TARGET_TASK_LIST (0x17CA0)
41 |
42 | // AES offsets
43 | #define TARGET_AES_CRYPTO_CMD (0xD844+1)
44 |
45 | // BDev offsets
46 | #define TARGET_BDEV_LIST (0x19B20)
47 |
48 | // Image offsets
49 | #define TARGET_IMAGE_LIST (0x17968)
50 |
51 | // Filesystem offsets
52 | //#define TARGET_FS_MOUNT (0x0)
53 | //#define TARGET_FS_UNMOUNT (0x0)
54 | //#define TARGET_FS_LOAD_FILE (0x0)
55 |
56 | // Kernel offsets
57 | #define TARGET_KERNEL_LOAD (0x8964+1)
58 | #define TARGET_KERNEL_PHYMEM (0x19BD0)
59 | #define TARGET_KERNEL_BOOTARGS (0x137A0)
60 |
61 | // NVRAM offsets
62 | #define TARGET_NVRAM_LIST (0x17CE0)
63 |
64 | #endif // OFFSETS_H
65 |
--------------------------------------------------------------------------------
/bundles/iPod2,1/8B117/iBoot/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x0A000000
7 | TYPE = iBoot
8 | MODEL = n72ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPod2,1/8B117/iBoot/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPod2,1/8B117/iBoot/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef OFFSETS_H
21 | #define OFFSETS_H
22 |
23 | // Base address
24 | #define TARGET_BASEADDR (0x0FF00000)
25 |
26 | // Standard offsets
27 | #define TARGET_FREE (0x9428+1)
28 | #define TARGET_MALLOC (0x9432+1)
29 | #define TARGET_JUMP_TO (0xDDE8+1)
30 | #define TARGET_PRINTF (0x1C734+1)
31 | #define TARGET_VPRINTF (0x1C6EC+1)
32 |
33 | // Command offsets
34 | #define TARGET_CMD_LIST_BEGIN (0x26E3C)
35 | #define TARGET_CMD_LIST_END (0x26E54)
36 |
37 | // Task functions
38 | #define TARGET_TASK_YIELD ((0xE69E)+1)
39 | #define TARGET_TASK_RUNNING (0x26D20)
40 | #define TARGET_TASK_LIST (0x26DB8)
41 |
42 | // AES offsets
43 | #define TARGET_AES_CRYPTO_CMD (0xF4C0+1)
44 |
45 | // BDev offsets
46 | #define TARGET_BDEV_LIST (0x29600)
47 |
48 | // Image offsets
49 | #define TARGET_IMAGE_LIST (0x25968)
50 |
51 | // Filesystem offsets
52 | //#define TARGET_FS_MOUNT (0x0)
53 | //#define TARGET_FS_UNMOUNT (0x0)
54 | //#define TARGET_FS_LOAD_FILE (0x0)
55 |
56 | // Kernel offsets
57 | #define TARGET_KERNEL_LOAD (0x9F28+1)
58 | #define TARGET_KERNEL_PHYMEM (0x2A000)
59 | #define TARGET_KERNEL_BOOTARGS (0x1EBC4)
60 |
61 | // NVRAM offset
62 | #define TARGET_NVRAM_LIST (0x26E08)
63 |
64 | #endif // OFFSETS_H
65 |
--------------------------------------------------------------------------------
/bundles/iPod2,1/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C 8B117
3 |
4 | clean:
5 | make clean -C 8B117
6 |
--------------------------------------------------------------------------------
/bundles/iPod2,1/bootrom.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone3,1/bootrom.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef BOOTROM_H
21 | #define BOOTROM_H
22 |
23 |
24 | #endif // BOOTROM_H
25 |
--------------------------------------------------------------------------------
/bundles/iPod2,1/device.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone3,1/device.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef DEVICE_H
21 | #define DEVICE_H
22 |
23 | #define S5L8720X
24 | #define LOADADDR 0x09000000
25 | #define FRAMEBUFFER 0x0FC00000
26 | #define FRAMEBUFFER_WIDTH 320
27 | #define FRAMEBUFFER_HEIGHT 480
28 | #define IBOOT_BASEADDR 0x0FF00000
29 | #define IBEC_BASEADDR 0x0FF00000
30 | #define IBSS_BASEADDR 0x22000000
31 | #define LLB_BASEADDR 0x22000000
32 | #define KERNEL_PATH "/boot/System/Library/Caches/com.apple.kernelcaches/kernelcache"
33 |
34 | #endif // DEVICE_H
35 |
--------------------------------------------------------------------------------
/bundles/iPod3,1/8B117/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C iBSS
3 | make -C iBoot
4 |
5 | clean:
6 | make clean -C iBSS
7 | make clean -C iBoot
--------------------------------------------------------------------------------
/bundles/iPod3,1/8B117/iBSS/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBSS
8 | MODEL = n18ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPod3,1/8B117/iBSS/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPod3,1/8B117/iBSS/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef OFFSETS_H
21 | #define OFFSETS_H
22 |
23 | // Base address
24 | #define TARGET_BASEADDR (0x84000000)
25 |
26 | // Standard offsets
27 | #define TARGET_FREE (0xE048+1)
28 | #define TARGET_MALLOC (0xE2CC+1)
29 | #define TARGET_JUMP_TO (0x121AC+1)
30 | #define TARGET_PRINTF (0x17664+1)
31 | #define TARGET_VPRINTF (0x16F34+1)
32 |
33 | // Command offsets
34 | #define TARGET_CMD_LIST_BEGIN (0x1E000)
35 | #define TARGET_CMD_LIST_END (0x1E02C)
36 |
37 | // Task functions
38 | #define TARGET_TASK_YIELD (0x12AA8+1)
39 | #define TARGET_TASK_RUNNING (0x1E984)
40 | #define TARGET_TASK_LIST (0x1EA1C)
41 |
42 | // AES offsets
43 | #define TARGET_AES_CRYPTO_CMD (0x13CE8+1)
44 |
45 | // BDev offsets
46 | #define TARGET_BDEV_LIST (0x21680)
47 |
48 | // Image offsets
49 | #define TARGET_IMAGE_LIST (0x1E954)
50 |
51 | // Filesystem offsets
52 | //#define TARGET_FS_MOUNT (0x0)
53 | //#define TARGET_FS_UNMOUNT (0x0)
54 | //#define TARGET_FS_LOAD_FILE (0x0)
55 |
56 | // Kernel offsets
57 | #define TARGET_KERNEL_LOAD (0xF5E4+1)
58 | #define TARGET_KERNEL_PHYMEM (0x21BC0)
59 | #define TARGET_KERNEL_BOOTARGS (0x1BA04)
60 |
61 | // NVRAM offsets
62 | #define TARGET_NVRAM_LIST (0x1EA5C)
63 |
64 | #endif // OFFSETS_H
65 |
--------------------------------------------------------------------------------
/bundles/iPod3,1/8B117/iBoot/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBoot
8 | MODEL = n18ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPod3,1/8B117/iBoot/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPod3,1/8B117/iBoot/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | * Copyright (C) 2010 Nicolas Haunold
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | **/
20 |
21 | #ifndef OFFSETS_H
22 | #define OFFSETS_H
23 |
24 | // Base address
25 | #define TARGET_BASEADDR (0x4FF00000)
26 |
27 | // Standard offsets
28 | #define TARGET_FREE (0xFD74+1) // image3_free
29 | #define TARGET_MALLOC (0xFD80+1) // image3_malloc
30 | #define TARGET_JUMP_TO (0x13728+1)
31 | #define TARGET_PRINTF (0x22458+1)
32 | #define TARGET_VPRINTF (0x21D28+1)
33 |
34 | // Command offsets
35 | #define TARGET_CMD_LIST_BEGIN (0x2CAC0)
36 | #define TARGET_CMD_LIST_END (0x2CAD8)
37 | //#define TARGET_CMD_RAMDISK (0xDEAD+1)
38 |
39 | // Task functions
40 | #define TARGET_TASK_YIELD (0x1404C+1)
41 | #define TARGET_TASK_RUNNING (0x2C980)
42 | #define TARGET_TASK_LIST (0x2CA18)
43 |
44 | // AES offsets
45 | #define TARGET_AES_CRYPTO_CMD (0x152BC+1)
46 |
47 | // BDev offsets
48 | #define TARGET_BDEV_LIST (0x30100)
49 |
50 | // Image offsets
51 | #define TARGET_IMAGE_LIST (0x2C950)
52 |
53 | // Filesystem offsets
54 | #define TARGET_FS_MOUNT (0x17AB4+1)
55 | #define TARGET_FS_UNMOUNT (0x17CCC+1)
56 | #define TARGET_FS_LOAD_FILE (0x17C64+1)
57 |
58 | // Kernel offsets
59 | #define TARGET_KERNEL_LOAD (0x108C4+1)
60 | #define TARGET_KERNEL_PHYMEM (0x30E40)
61 |
62 | // NVRAM offset
63 | #define TARGET_NVRAM_LIST (0x2CA5C)
64 |
65 | #endif // OFFSETS_H
66 |
--------------------------------------------------------------------------------
/bundles/iPod3,1/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C 8B117
3 |
4 | clean:
5 | make clean -C 8B117
6 |
--------------------------------------------------------------------------------
/bundles/iPod3,1/bootrom.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone3,1/bootrom.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef BOOTROM_H
21 | #define BOOTROM_H
22 |
23 |
24 | #endif // BOOTROM_H
25 |
--------------------------------------------------------------------------------
/bundles/iPod3,1/device.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone3,1/device.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef DEVICE_H
21 | #define DEVICE_H
22 |
23 | #define S5L8922X
24 | #define LOADADDR 0x41000000
25 | #define FRAMEBUFFER 0x4FD00000
26 | #define FRAMEBUFFER_WIDTH 320
27 | #define FRAMEBUFFER_HEIGHT 480
28 | #define IBOOT_BASEADDR 0x4FF00000
29 | #define IBEC_BASEADDR 0x4FF00000
30 | #define IBSS_BASEADDR 0x84000000
31 | #define LLB_BASEADDR 0x84000000
32 | #define KERNEL_PATH "/boot/System/Library/Caches/com.apple.kernelcaches/kernelcache"
33 |
34 | #endif // DEVICE_H
35 |
--------------------------------------------------------------------------------
/bundles/iPod4,1/8B117/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C iBSS
3 | make -C iBoot
4 |
5 | clean:
6 | make clean -C iBSS
7 | make clean -C iBoot
--------------------------------------------------------------------------------
/bundles/iPod4,1/8B117/iBSS/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBSS
8 | MODEL = n81ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o patch.o memory.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPod4,1/8B117/iBSS/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPod4,1/8B117/iBSS/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | * Copyright (C) 2010 Dustin Howett
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | **/
20 |
21 | #ifndef OFFSETS_H
22 | #define OFFSETS_H
23 |
24 | // Base address
25 | #define TARGET_BASEADDR (0x84000000)
26 |
27 | // Task functions
28 | #define TARGET_TASK_RUNNING (0x22738)
29 | #define TARGET_TASK_LIST (0x227D0)
30 |
31 | // BDev offsets
32 | #define TARGET_BDEV_LIST (0x26280)
33 |
34 | // Kernel offsets
35 | #define TARGET_KERNEL_PHYMEM (0x267C0)
36 |
37 | #endif // OFFSETS_H
38 |
--------------------------------------------------------------------------------
/bundles/iPod4,1/8B117/iBoot/Makefile:
--------------------------------------------------------------------------------
1 | CROSS ?= arm-elf-
2 | CC = $(CROSS)gcc
3 | LD = $(CROSS)ld
4 | SRC = ../../../..
5 | BIN2C = $(SRC)/tools/bin2c
6 | LOADADDR = 0x42000000
7 | TYPE = iBoot
8 | MODEL = n81ap
9 | OBJCOPY = $(CROSS)objcopy
10 | OBJECTS = entry.o main.o common.o commands.o task.o lock.o aes.o bdev.o image.o nvram.o filesystem.o kernel.o memory.o patch.o functions.o framebuffer.o breakpoint.o uart.o radio.o
11 | CFLAGS = -I. -I./.. -I./../.. -I./$(SRC)/include -nostdlib -mlittle-endian
12 | LDFLAGS = -Ttext=$(LOADADDR) -nostdlib -lc -lm -lgcc
13 |
14 | %.o: $(SRC)/%.S
15 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
16 |
17 | %.o: $(SRC)/%.c
18 | $(CC) -c $(<) -o $(@) $(INCLUDES) $(CFLAGS)
19 |
20 | all: payload
21 |
22 | payload: payload.elf
23 | $(BIN2C) payload $(SRC)/payloads/$(TYPE).$(MODEL).h $(TYPE)_$(MODEL)
24 |
25 | payload.elf: $(OBJECTS)
26 | $(CC) -o $(@) $(OBJECTS) $(LDFLAGS)
27 | $(OBJCOPY) -O binary $(@) payload
28 |
29 | clean:
30 | rm -rf *.o *.elf payload
31 |
32 |
--------------------------------------------------------------------------------
/bundles/iPod4,1/8B117/iBoot/offsets.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPod4,1/8B117/iBoot/offsets.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | * Copyright (C) 2010 Nicolas Haunold
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | **/
20 |
21 | #ifndef OFFSETS_H
22 | #define OFFSETS_H
23 |
24 | // Base address
25 | #define TARGET_BASEADDR (0x5FF00000)
26 |
27 | // Task functions
28 | #define TARGET_TASK_RUNNING (0x37734)
29 | #define TARGET_TASK_LIST (0x377CC)
30 |
31 | // BDev offsets
32 | #define TARGET_BDEV_LIST (0x3B940)
33 |
34 | // Filesystem offsets
35 | #define TARGET_FS_UNMOUNT (0x19A50+1)
36 | #define TARGET_FS_LOAD_FILE (0x199E8+1)
37 |
38 | // Kernel offsets
39 | #define TARGET_KERNEL_PHYMEM (0x3CA80)
40 |
41 | #endif // OFFSETS_H
42 |
--------------------------------------------------------------------------------
/bundles/iPod4,1/Makefile:
--------------------------------------------------------------------------------
1 | all:
2 | make -C 8B117
3 |
4 | clean:
5 | make clean -C 8B117
--------------------------------------------------------------------------------
/bundles/iPod4,1/bootrom.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPod4,1/bootrom.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef BOOTROM_H
21 | #define BOOTROM_H
22 |
23 |
24 | #endif // BOOTROM_H
25 |
--------------------------------------------------------------------------------
/bundles/iPod4,1/device.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - iPhone3,1/device.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef DEVICE_H
21 | #define DEVICE_H
22 |
23 | #define S5L8930X
24 | #define LOADADDR 0x41000000
25 | #define FRAMEBUFFER 0x5F700000
26 | #define FRAMEBUFFER_WIDTH 640
27 | #define FRAMEBUFFER_HEIGHT 960
28 | #define IBOOT_BASEADDR 0x5FF00000
29 | #define IBEC_BASEADDR 0x5FF00000
30 | #define IBSS_BASEADDR 0x84000000
31 | #define LLB_BASEADDR 0x84000000
32 | #define KERNEL_PATH "/boot/System/Library/Caches/com.apple.kernelcaches/kernelcache"
33 |
34 | #endif // DEVICE_H
35 |
--------------------------------------------------------------------------------
/common.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - common.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "task.h"
25 | #include "lock.h"
26 | #include "common.h"
27 | #include "framebuffer.h"
28 |
29 | void(*_free)(void* ptr) = NULL;
30 | void*(*_malloc)(unsigned int size) = NULL;
31 | int(*_printf)(const char *fmt, ...) = NULL;
32 |
33 | void* gLoadaddr = NULL;
34 | void* gBaseaddr = NULL;
35 | void* gRomBaseaddr = NULL;
36 | void* gBssBaseaddr = NULL;
37 | void* gBootBaseaddr = NULL;
38 |
39 | int cout_count = 0;
40 |
41 | void* find_printf() {
42 | int i = 0;
43 | int j = 0;
44 | unsigned int sp;
45 | unsigned int* stack = &sp;
46 | void(*default_block_write)(void) = find_function("default_block_write", TARGET_BASEADDR, TARGET_BASEADDR);
47 | default_block_write();
48 | for(i = 0; i < 0x100; i += 4) {
49 | unsigned int value = *(stack - i);
50 | if((value & TARGET_BASEADDR) == TARGET_BASEADDR) {
51 | for(j = 0; j < 0x100; j++) {
52 | unsigned short* instruction = (unsigned short*)(value + j);
53 | if(*instruction == 0xB40F) {
54 | return (void*) value + (j+1);
55 | }
56 | }
57 | }
58 | }
59 | return 0;
60 | }
61 |
62 | void* find_free() {
63 | return find_function("free", TARGET_BASEADDR, TARGET_BASEADDR);
64 | }
65 |
66 | void* find_malloc() {
67 | void* bytes = patch_find(TARGET_BASEADDR, 0x40000, "\x80\xB5\x00\xAF\x01\x21\x00\x22", 8);
68 | if (bytes==NULL) return NULL;
69 | return bytes+1;
70 | }
71 |
72 | int common_init() {
73 | _printf = find_printf();
74 | if(_printf == NULL) {
75 | fb_print("Unable to find printf\n");
76 | return -1;
77 | } else {
78 | printf("Found printf at 0x%x\n", _printf);
79 | }
80 |
81 | _malloc = find_malloc();
82 | if(_malloc == NULL) {
83 | puts("Unable to find malloc\n");
84 | return -1;
85 | } else {
86 | printf("Found malloc at 0x%x\n", _malloc);
87 | }
88 |
89 | _free = find_free();
90 | if(_free == NULL) {
91 | puts("Unable to find free\n");
92 | return -1;
93 | } else {
94 | printf("Found free at 0x%x\n", _free);
95 | }
96 |
97 | return 0;
98 | }
99 |
100 | void _puts(const char* message) {
101 | printf("%s", message);
102 | fb_print(message);
103 | }
104 |
105 | void hexdump(unsigned char* buf, unsigned int len) {
106 | int i, j;
107 | enter_critical_section();
108 | printf("0x%08x: ", buf);
109 | for (i = 0; i < len; i++) {
110 | if (i % 16 == 0 && i != 0) {
111 | for (j=i-16; j < i; j++) {
112 | unsigned char car = buf[j];
113 | if (car < 0x20 || car > 0x7f) car = '.';
114 | printf("%c", car);
115 | }
116 | printf("\n0x%08x: ", buf+i);
117 | }
118 | printf("%02x ", buf[i]);
119 | }
120 |
121 | int done = (i % 16);
122 | int remains = 16 - done;
123 | if (done > 0) {
124 | for (j = 0; j < remains; j++) {
125 | printf(" ");
126 | }
127 | }
128 |
129 | if ((i - done) >= 0) {
130 | if (done == 0 && i > 0) done = 16;
131 | for (j = (i - done); j < i; j++) {
132 | unsigned char car = buf[j];
133 | if (car < 0x20 || car > 0x7f) car = '.';
134 | printf("%c", car);
135 | }
136 | }
137 |
138 | printf("\n\n");
139 | exit_critical_section();
140 | }
141 |
142 | void printf_begin() {
143 | cout_count = 0;
144 | }
145 |
146 | void printf_filler() {
147 | int blanks = (0x201 - (cout_count % 0x200));
148 | if (blanks > 100 || blanks == 0) return;
149 | int i;
150 | for (i = 0; i < blanks; i++) {
151 | _printf("");
152 | }
153 | printf_begin();
154 | }
155 |
156 | int gpprintf(const char* fmt, ...) {
157 | int ret;
158 | //va_list args;
159 | enter_critical_section();
160 |
161 | //va_start(args, fmt);
162 | //ret = vprintf(fmt, args);
163 | //va_end(args);
164 |
165 | cout_count += ret;
166 | printf_filler();
167 | exit_critical_section();
168 |
169 | return ret;
170 | }
171 |
172 |
173 | void panic(const char* why) {
174 | printf("%s", why);
175 | while(1){}
176 | }
177 |
--------------------------------------------------------------------------------
/coprocessor.S:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - coprocessor.S
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | .global read_processor_id
21 | .global read_processor_features
22 | .global read_silicon_id
23 | .global read_control_register
24 | .global write_control_register
25 | .global read_auxcontrol_register
26 | .global write_auxcontrol_register
27 | .global read_TBB0
28 | .global write_TBB0
29 | .global read_DAC
30 | .global write_DAC
31 | .global clear_icache
32 | @ pod2g: removed, not armv6 compatible
33 | @.global clear_dcache
34 | @.global clear_cpu_caches
35 |
36 | .code 32
37 | read_processor_id:
38 | mrc p15, 0, r0, c0, c0, 0
39 | bx lr
40 |
41 | read_processor_features:
42 | mrc p15, 0, r0, c0, c1, 0
43 | bx lr
44 |
45 | read_silicon_id:
46 | mrc p15, 1, r0, c0, c0, 7
47 | bx lr
48 |
49 | read_control_register:
50 | mrc p15, 0, r0, c1, c0, 0
51 | bx lr
52 |
53 | write_control_register:
54 | mcr p15, 0, r0, c1, c0, 0
55 | bx lr
56 |
57 | read_auxcontrol_register:
58 | mrc p15, 0, r0, c1, c0, 1
59 | bx lr
60 |
61 | write_auxcontrol_register:
62 | mcr p15, 0, r0, c1, c0, 1
63 | bx lr
64 |
65 | read_TBB0:
66 | mrc p15, 0, r0, c2, c0, 0
67 | bx lr
68 |
69 | write_TBB0:
70 | mcr p15, 0, r0, c2, c0, 0
71 | bx lr
72 |
73 | read_DAC:
74 | mrc p15, 0, r0, c3, c0, 0
75 | bx lr
76 |
77 | write_DAC:
78 | mcr p15, 0, r0, c3, c0, 0
79 | bx lr
80 |
81 | clear_icache:
82 | mov r0, #0
83 | mcr p15, 0, r0, c7, c5, 0 @ Invalidate I-Cache
84 | mcr p15, 0, r0, c7, c5, 4 @ Flush Prefetch Buffer
85 | nop
86 | nop
87 | nop
88 | nop
89 | bx lr
90 |
91 | @ pod2g: removed, not armv6 compatible
92 | @clear_dcache:
93 | @ mov r2, #0x2000
94 | @
95 | @outside:
96 | @ sub r2, r2, #0x40
97 | @ mov r1, #0
98 | @
99 | @inside:
100 | @ subs r1, r1, #0x40000000
101 | @ orr r0, r1, r2
102 | @ mcr p15, 0, r0, c7, c10, 2
103 | @ bne inside
104 | @ cmp r2, #0
105 | @ bne outside
106 | @ mov r0, #0
107 | @ mcr p15, 0, r0, c7, c10, 4
108 | @ bx lr
109 | @
110 | @clear_cpu_caches:
111 | @ bl clear_dcache
112 | @ bl clear_icache
113 | @ bx lr
114 |
--------------------------------------------------------------------------------
/entry.S:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - entry.S
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | * Copyright (C) 2010 Cyril Cattiaux
6 | *
7 | * This program is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | **/
20 |
21 | #include "offsets.h"
22 |
23 | .arm
24 | .ltorg
25 | .code 32
26 | .global _start
27 | _start:
28 | b reset
29 | ldr pc, undefined_vector
30 | ldr pc, syscall_vector
31 | ldr pc, prefetch_abort_vector
32 | ldr pc, data_abort_vector
33 | ldr pc, reserved_vector
34 | ldr pc, irq_vector
35 | ldr pc, fiq_vector
36 |
37 | reset_vector: .word reset
38 | undefined_vector: .word halt
39 | syscall_vector: .word halt
40 | prefetch_abort_vector: .word halt
41 | data_abort_vector: .word halt
42 | reserved_vector: .word halt
43 | irq_vector: .word halt
44 | fiq_vector: .word halt
45 |
46 | .pool
47 | .set FP_CMD_1, 0x47184b00 @ search: LDR R3, =0x41000000 @ BR R3
48 | .set FP_CMD_2, 0x41000000 @ search: 0x41000000
49 | .set PATCH_CMD_1, 0x47184b00 @ _patch: LDR R3, =0x42000000 @ BX R3
50 | .set PATCH_CMD_2, 0x42000000 @ _patch: 0x42000000
51 |
52 | .set FP_CMD2_1, 0x47184b00 @ search: LDR R3, =0x09000000 @ BR R3
53 | .set FP_CMD2_2, 0x09000000 @ search: 0x09000000
54 | .set PATCH_CMD2_1, 0x47184b00 @ _patch: LDR R3, =0x0A000000 @ BX R3
55 | .set PATCH_CMD2_2, 0x0A000000 @ _patch: 0x0A000000
56 |
57 | .set new_loadaddr, 0x41000000
58 | .set new_payload_dest, 0x42000000
59 | .set old_loadaddr, 0x09000000
60 | .set old_payload_dest, 0x0A000000
61 |
62 | .code 32
63 | @---------------------------------------------
64 | reset:
65 | push {r0-r12, lr}
66 | mov r5, pc
67 | lsr r5, #24
68 | cmp r5, #0x42
69 | beq relocated
70 |
71 | cmp r5, #0x0A
72 | beq relocated
73 |
74 | cmp r5, #0x41
75 | beq relocate_new
76 |
77 | cmp r5, #0x09
78 | beq relocate_old
79 |
80 | b halt
81 |
82 | relocate_new:
83 | ldr r0, =new_loadaddr
84 | ldr r1, =new_payload_dest
85 | b relocate
86 |
87 | relocate_old:
88 | ldr r0, =old_loadaddr
89 | ldr r1, =old_payload_dest
90 | b relocate
91 |
92 | relocate:
93 | mov r4, r1
94 | bl copy
95 | bl patch
96 | cmp r5, #0x09
97 | bne flush_new
98 | @bl clear_dcache
99 | bl clear_icache
100 | b jump_main
101 | flush_new:
102 | bl clear_icache
103 | bl flush_dcache
104 |
105 | jump_main:
106 | blx r4
107 | b done
108 |
109 | relocated:
110 | ldr r0, [sp, #0x0]
111 | ldr r1, [sp, #0x4]
112 | ldr r2, [sp, #0x8]
113 | ldr r3, [sp, #0xc]
114 | bl main
115 | str r0, [sp, #0x0] @ push r0 return onto the stack to be returned
116 |
117 | done:
118 | pop {r0-r12, pc}
119 |
120 | halt:
121 | b halt
122 |
123 | @---------------------------------------------
124 | .code 32
125 | copy:
126 | mov r2, #0x00100000
127 | copy_loop:
128 | ldr r3, [r0], #4
129 | str r3, [r1], #4
130 | subs r2, r2, #4
131 | bne copy_loop
132 | bx lr
133 |
134 | @---------------------------------------------
135 | .code 32
136 | patch:
137 | push {lr}
138 | mov r0, pc
139 | lsr r0, #24
140 |
141 | patch1:
142 | ldr r0, =FP_CMD_1
143 | ldr r1, =TARGET_BASEADDR
144 | mov r2, #0x2c000 @ search area
145 | ldr r3, =FP_CMD_2
146 | blx find_64
147 | cmp r0, #0
148 | beq patch2
149 | ldr r1, =PATCH_CMD_1
150 | str r1, [r0]
151 | ldr r1, =PATCH_CMD_2
152 | str r1, [r0, #4]
153 | b patch_done
154 |
155 | patch2:
156 | ldr r0, =FP_CMD2_1
157 | ldr r1, =TARGET_BASEADDR
158 | mov r2, #0x24000 @ search area
159 | ldr r3, =FP_CMD2_2
160 | blx find_64
161 | cmp r0, #0
162 | beq patch3
163 | ldr r1, =PATCH_CMD2_1
164 | str r1, [r0]
165 | ldr r1, =PATCH_CMD2_2
166 | str r1, [r0, #4]
167 | b patch_done
168 |
169 | patch3:
170 |
171 | patch_done:
172 | pop {pc}
173 |
174 | @---------------------------------------------
175 | .code 16
176 | .thumb_func
177 | find_64:
178 | push {r4, lr}
179 |
180 | find_loop:
181 | ldr r4, [r1]
182 | cmp r4, r0
183 | bne find_loop_continue
184 | ldr r4, [r1,#4]
185 | cmp r4, r3
186 | beq find_return
187 |
188 | find_loop_continue:
189 | add r1, #2
190 | sub r2, #2
191 | cmp r2, #0
192 | bne find_loop
193 | mov r1, #0
194 |
195 | find_return:
196 | mov r0, r1
197 | pop {r4, pc}
198 |
199 | @---------------------------------------------
200 | .code 32
201 | clear_icache:
202 | mov r0, #0
203 | mcr p15, 0, r0, c7, c5
204 | mcr p15, 0, r0, c7, c5, 4 @ Flush Prefetch Buffer
205 | nop
206 | nop
207 | nop
208 | nop
209 | bx lr
210 |
211 | @---------------------------------------------
212 | .code 32
213 | flush_dcache:
214 | mrc p15, 0, r0, c1, c0, 1
215 | bx lr
216 |
217 | @---------------------------------------------
218 | .code 32
219 | clear_dcache:
220 | mov r0, #0
221 | mcr p15, 0, r0, c7, c10, 0 @ Clean Entire Data Cache
222 | mcr p15, 0, r0, c7, c10, 4 @ Data Synchronization Barrier
223 | bx lr
224 |
225 | @---------------------------------------------
226 | .end
227 |
--------------------------------------------------------------------------------
/filesystem.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - filesystem.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 |
22 | #include "filesystem.h"
23 |
24 | int(*fs_load_file)(const char *path, void* address, unsigned int* size) = SELF_FS_LOAD_FILE;
25 | void(*fs_mount)(const char *partition, const char *type, const char *path) = NULL;
26 | void(*fs_unmount)(const char *path) = SELF_FS_UNMOUNT;
27 |
28 | void* find_fs_mount() {
29 | return find_function("fs_mount", TARGET_BASEADDR, TARGET_BASEADDR);
30 | }
31 |
32 | void* find_fs_unmount() {
33 | return 0;
34 | }
35 |
36 | void* find_fs_load_file() {
37 | return 0;
38 | }
39 |
40 | int fs_init() {
41 | fs_mount = find_fs_mount();
42 | if(fs_mount == NULL) {
43 | puts("Unable to find fs_mount\n");
44 | } else {
45 | printf("Found fs_mount at 0x%x\n", fs_mount);
46 | }
47 |
48 | //fs_unmount = find_fs_unmount();
49 | if(fs_unmount == NULL) {
50 | puts("Unable to find fs_unmount\n");
51 | } else {
52 | printf("Found fs_unmount at 0x%x\n", fs_unmount);
53 | }
54 |
55 | //fs_load_file = find_fs_load_file();
56 | if(fs_load_file == NULL) {
57 | puts("Unable to find fs_load_file\n");
58 | } else {
59 | printf("Found fs_load_file at 0x%x\n", fs_load_file);
60 | }
61 |
62 | if(fs_mount && fs_unmount && fs_load_file) {
63 | cmd_add("fs", &fs_cmd, "perform operations on the filesystem");
64 | }
65 |
66 | return 0;
67 | }
68 |
69 | int fs_cmd(int argc, CmdArg* argv) {
70 | char* path = NULL;
71 | char* action = NULL;
72 | char* device = NULL;
73 | void* address = NULL;
74 | unsigned int* size = 0;
75 |
76 | if(argc < 3) {
77 | puts("usage: fs [options]\n");
78 | puts(" mount \tmount device to path\n");
79 | puts(" unmount \tunmount specified path\n");
80 | puts(" load \tload file from path to address\n\n");
81 | return 0;
82 | }
83 |
84 | action = argv[1].string;
85 | if(argc == 3) {
86 | if(strcmp(action, "umount")) {
87 | path = argv[2].string;
88 | fs_unmount(path);
89 | }
90 |
91 | } else if(argc == 4) {
92 | if(!strcmp(action, "mount")) {
93 | path = argv[3].string;
94 | device = argv[2].string;
95 | fs_mount(device, "hfs", path);
96 |
97 | } else if(!strcmp(action, "load")) {
98 | path = argv[2].string;
99 | address = (void*) argv[3].uinteger;
100 | fs_load_file(path, address, size);
101 | }
102 | }
103 |
104 | return 0;
105 | }
106 |
--------------------------------------------------------------------------------
/framebuffer.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - framebuffer.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 |
22 | #include "font.h"
23 | #include "device.h"
24 | #include "common.h"
25 | #include "commands.h"
26 | #include "framebuffer.h"
27 |
28 | static Font* gFbFont;
29 | static unsigned int gFbX;
30 | static unsigned int gFbY;
31 | static unsigned int gFbTWidth;
32 | static unsigned int gFbTHeight;
33 | static unsigned int gFbWidth;
34 | static unsigned int gFbHeight;
35 |
36 | Bool gFbHasInit = FALSE;
37 | Bool gFbDisplayText = FALSE;
38 |
39 | static unsigned int gFbBackgroundColor;
40 | static unsigned int gFbForegroundColor;
41 |
42 | inline int font_get_pixel(Font* font, int ch, int x, int y) {
43 | register int index = ((font->width * font->height) * ch) + (font->width * y) + x;
44 | return (font->data[index / 8] >> (index % 8)) & 0x1;
45 | }
46 |
47 | volatile unsigned int* fb_get_pixel(register unsigned int x, register unsigned int y) {
48 | return (((unsigned int*)FRAMEBUFFER) + (y * gFbWidth) + x);
49 | }
50 |
51 | static void fb_scrollup() {
52 | register volatile unsigned int* newFirstLine = fb_get_pixel(0, gFbFont->height);
53 | register volatile unsigned int* oldFirstLine = fb_get_pixel(0, 0);
54 | register volatile unsigned int* end = oldFirstLine + (gFbWidth * gFbHeight);
55 | while(newFirstLine < end) {
56 | *(oldFirstLine++) = *(newFirstLine++);
57 | }
58 | while(oldFirstLine < end) {
59 | *(oldFirstLine++) = gFbBackgroundColor;
60 | }
61 | gFbY--;
62 | }
63 |
64 | void fb_setup() {
65 | gFbFont = (Font*) font_data;
66 | gFbBackgroundColor = COLOR_BLACK;
67 | gFbForegroundColor = COLOR_WHITE;
68 | gFbWidth = FRAMEBUFFER_WIDTH;
69 | gFbHeight = FRAMEBUFFER_HEIGHT;
70 | gFbTWidth = gFbWidth / gFbFont->width;
71 | gFbTHeight = gFbHeight / gFbFont->height;
72 | }
73 |
74 | int fb_init() {
75 | if(gFbHasInit) return 0;
76 | fb_setup();
77 | fb_clear();
78 | fb_set_loc(0,0);
79 | fb_display_text(TRUE);
80 |
81 | fb_print("=====================================================");
82 | #ifdef S5L8930X
83 | fb_print("=====================================================");
84 | fb_print(" ");
85 | #endif
86 |
87 | fb_print(" greenpois0n ");
88 |
89 | #ifdef S5L8930X
90 | fb_print(" ");
91 | #endif
92 |
93 | fb_print(" http://www.greenpois0n.com ");
94 |
95 | #ifdef S5L8930X
96 | fb_print(" ");
97 | fb_print("=====================================================");
98 | #endif
99 | fb_print("=====================================================");
100 |
101 | cmd_add("fbecho", &fb_cmd, "write characters back to framebuffer");
102 | gFbHasInit = TRUE;
103 | return 0;
104 | }
105 |
106 | int fb_cmd(int argc, CmdArg* argv) {
107 | cmd_start();
108 | int i = 0;
109 | if (argc < 2) {
110 | puts("usage: fbecho \n");
111 | return 0;
112 | }
113 |
114 | //enter_critical_section();
115 | for (i = 1; i < argc; i++) {
116 | fb_print(argv[i].string);
117 | fb_print(" ");
118 | }
119 | //exit_critical_section();
120 | fb_print("\n");
121 | return 0;
122 | }
123 |
124 | void fb_clear() {
125 | unsigned int *p = 0;
126 | for(p = (unsigned int*)FRAMEBUFFER; p < (unsigned int*)(FRAMEBUFFER + (gFbWidth * gFbHeight * 4)); p++) {
127 | *p = gFbBackgroundColor;
128 | }
129 | }
130 |
131 | unsigned int fb_get_x() {
132 | return gFbX;
133 | }
134 |
135 | unsigned int fb_get_y() {
136 | return gFbY;
137 | }
138 |
139 | unsigned int fb_get_width() {
140 | return gFbTWidth;
141 | }
142 |
143 | unsigned int fb_get_height() {
144 | return gFbTHeight;
145 | }
146 |
147 | void fb_set_loc(unsigned int x, unsigned int y) {
148 | gFbX = x;
149 | gFbY = y;
150 | }
151 |
152 | void fb_set_colors(unsigned int fore, unsigned int back) {
153 | gFbForegroundColor = fore;
154 | gFbBackgroundColor = back;
155 | }
156 |
157 | void fb_display_text(Bool option) {
158 | gFbDisplayText = option;
159 | }
160 |
161 | void fb_putc(int c) {
162 | if(c == '\r') {
163 | gFbX = 0;
164 |
165 | } else if(c == '\n') {
166 | gFbX = 0;
167 | gFbY++;
168 |
169 | } else {
170 | register unsigned int sx;
171 | register unsigned int sy;
172 |
173 | for(sy = 0; sy < gFbFont->height; sy++) {
174 | for(sx = 0; sx < gFbFont->width; sx++) {
175 | if(font_get_pixel(gFbFont, c, sx, sy)) {
176 | *(fb_get_pixel(sx + (gFbFont->width * gFbX), sy + (gFbFont->height * gFbY))) = gFbForegroundColor;
177 | } else {
178 | *(fb_get_pixel(sx + (gFbFont->width * gFbX), sy + (gFbFont->height * gFbY))) = gFbBackgroundColor;
179 | }
180 | }
181 | }
182 |
183 | gFbX++;
184 | }
185 |
186 | if(gFbX == gFbTWidth) {
187 | gFbX = 0;
188 | gFbY++;
189 | }
190 |
191 | if(gFbY == gFbTHeight) {
192 | fb_scrollup();
193 | }
194 | }
195 |
196 | void fb_print(const char* str) {
197 | if(!gFbDisplayText)
198 | return;
199 |
200 | unsigned int len = strlen(str);
201 | int i;
202 | for(i = 0; i < len; i++) {
203 | fb_putc(str[i]);
204 | }
205 | }
206 |
207 | void fb_print_force(const char* str) {
208 | size_t len = strlen(str);
209 | int i;
210 | for(i = 0; i < len; i++) {
211 | fb_putc(str[i]);
212 | }
213 | }
214 |
215 | void fb_draw_image(unsigned int* image, unsigned int x, unsigned int y, unsigned int width, unsigned int height) {
216 | register unsigned int sx;
217 | register unsigned int sy;
218 | for(sy = 0; sy < height; sy++) {
219 | for(sx = 0; sx < width; sx++) {
220 | *(fb_get_pixel(sx + x, sy + y)) = image[(sy * width) + sx];
221 | }
222 | }
223 | }
224 |
225 | void fb_capture_image(unsigned int* image, unsigned int x, unsigned int y, unsigned int width, unsigned int height) {
226 | register unsigned int sx;
227 | register unsigned int sy;
228 | for(sy = 0; sy < height; sy++) {
229 | for(sx = 0; sx < width; sx++) {
230 | image[(sy * width) + sx] = *(fb_get_pixel(sx + x, sy + y));
231 | }
232 | }
233 | }
234 |
--------------------------------------------------------------------------------
/free.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - free.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 |
21 | #include
22 | #include
23 |
24 | #include "heap.h"
25 |
26 | void free(void* ptr) {
27 | chunk_header_t* chunk;
28 | chunk_header_t* next_chunk;
29 | chunk_header_t* prev_chunk;
30 | chunk_header_t* current_chunk;
31 | chunk_header_t** chunk_header;
32 |
33 | if (ptr) {
34 | chunk = (void*) ptr - 8;
35 | next_chunk = get_next_chunk(chunk);
36 | prev_chunk = get_prev_chunk(chunk);
37 | gHeapRemaining += chunk->size * 8;
38 | if (chunk == next_chunk || chunk == prev_chunk
39 | || get_prev_chunk(next_chunk) != chunk
40 | || get_next_chunk(prev_chunk) != chunk
41 | || chunk->prev_size & 1) {
42 | puts("Heap Error\n");
43 | }
44 |
45 | chunk->prev_size |= 1;
46 |
47 | if ((chunk->prev_size << 30) < 0) {
48 | *prev_chunk->head = prev_chunk->next;
49 | if(prev_chunk->next) {
50 | prev_chunk->next->head = prev_chunk->head;
51 | }
52 |
53 | prev_chunk->size += chunk->size;
54 | chunk->size = 0;
55 | chunk->prev_size &= 3u;
56 | chunk = prev_chunk;
57 | }
58 |
59 | if ((next_chunk->prev_size << 31) < 0) {
60 | *next_chunk->head = next_chunk->next;
61 | if(next_chunk->next) {
62 | next_chunk->next->head = next_chunk->head;
63 | }
64 |
65 | chunk->size += next_chunk->size;
66 | next_chunk->size = 0;
67 | next_chunk->prev_size &= 3u;
68 | }
69 |
70 | next_chunk->prev_size |= 2;
71 | next_chunk->prev_size = (next_chunk->prev_size & 3) | (4 * chunk->size);
72 |
73 | chunk_header = &gHeapHeader[get_zone(chunk->size * 8)];
74 | current_chunk = *chunk_header;
75 | chunk->head = chunk_header;
76 | chunk->next = current_chunk;
77 |
78 | if(current_chunk) {
79 | current_chunk->head = &chunk;
80 | }
81 |
82 | *chunk_header = chunk;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/functions.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - functions.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "task.h"
25 | #include "lock.h"
26 | #include "common.h"
27 | #include "commands.h"
28 |
29 | static unsigned char push = 0xB5;
30 | static unsigned char push_r7_lr[] = { 0x80, 0xB5 };
31 | static unsigned char push_r4_r7_lr[] = { 0x90, 0xB5 };
32 | static unsigned char push_r4_to_r7_lr[] = { 0xF0, 0xB5 };
33 | static unsigned char push_r4_r5_r7_lr[] = { 0xB0, 0xB5 };
34 |
35 | static unsigned char* functions[][3] = {
36 | { "aes_crypto_cmd", "aes_crypto_cmd", push_r4_r7_lr },
37 | { "free", "heap_panic", push_r4_to_r7_lr },
38 | { "fs_mount", "fs_mount", push_r4_to_r7_lr },
39 | { "cmd_ramdisk", "Ramdisk too large", push_r4_r5_r7_lr },
40 | { "cmd_go", "jumping into image", push_r7_lr },
41 | { "image_load", "image validation failed but untrusted images are permitted", push_r4_to_r7_lr },
42 | { "fsboot", "root filesystem mount failed", push_r4_to_r7_lr },
43 | { "kernel_load", "rd=md0", push_r4_to_r7_lr },
44 | { "task_yield", "task_yield", push_r4_r5_r7_lr },
45 | { "default_block_write", "no reasonable default block write routine", push_r7_lr },
46 | { "populate_images", "image %p: bdev %p type %c%c%c%c offset 0x%x", push_r4_r5_r7_lr },
47 | { "uart_read", "uart_read", push_r4_to_r7_lr },
48 | { "uart_write", "uart_write", push_r4_to_r7_lr },
49 | { "task_create", "task_create", push_r4_to_r7_lr },
50 | { "task_exit", "task_exit", push_r4_to_r7_lr },
51 | { NULL, NULL, NULL }
52 | };
53 |
54 | unsigned int find_reference(unsigned char* data, unsigned int base, unsigned int size, char* signature) {
55 | unsigned int i = 0;
56 |
57 | // First find the string
58 | unsigned int address = 0;
59 | for(i = 0; i < size; i++) {
60 | if(!memcmp(&data[i], signature, strlen(signature))) {
61 | address = base | i;
62 | break;
63 | }
64 | }
65 | if(address == 0) return NULL;
66 |
67 | // Next find where that string is referenced
68 | unsigned int reference = 0;
69 | for(i = 0; i < size; i++) {
70 | if(!memcmp(&data[i], &address, 4)) {
71 | reference = base | i;
72 | break;
73 | }
74 | }
75 | if(reference == 0) return NULL;
76 | reference -= 8;
77 |
78 | unsigned int reference2 = 0;
79 | for(i = 0; i < size; i++) {
80 | if(!memcmp(&data[i], &reference, 4)) {
81 | reference2 = base | i;
82 | break;
83 | }
84 | }
85 | if(reference2 == 0) return NULL;
86 | return reference2;
87 | }
88 |
89 | unsigned int find_top(unsigned char* data, unsigned int base, unsigned int size, unsigned int address) {
90 | // Find the top of that function
91 | int i = 0;
92 | unsigned int function = 0;
93 | while(i > 0) {
94 | i--;
95 | if(data[i] == push) {
96 | function = base | i;
97 | break;
98 | }
99 | }
100 | if(function == 0) return NULL;
101 | }
102 |
103 | unsigned int find_offset(unsigned char* data, unsigned int base, unsigned int size, unsigned char** what) {
104 | unsigned int i = 0;
105 | unsigned char* top = what[2];
106 | unsigned char* name = what[0];
107 | unsigned char* signature = what[1];
108 | unsigned int dbase = (unsigned int) data;
109 |
110 | // First find the string
111 | unsigned int address = 0;
112 | for(i = 0; i < size; i++) {
113 | if(!memcmp(&data[i], signature, strlen(signature))) {
114 | address = base | i;
115 | break;
116 | }
117 | }
118 | if(address == 0) return NULL;
119 |
120 | // Next find where that string is referenced
121 | unsigned int reference = 0;
122 | for(i = 0; i < size; i++) {
123 | if(!memcmp(&data[i], &address, 4)) {
124 | reference = base | i;
125 | break;
126 | }
127 | }
128 | if(reference == 0) return NULL;
129 |
130 | // Finally find the top of that function
131 | unsigned int function = 0;
132 | while(i > 0) {
133 | i--;
134 | if(data[i] == push) {
135 | function = dbase | i;
136 | break;
137 | }
138 | }
139 | if(function == 0) return NULL;
140 |
141 | return function;
142 | }
143 |
144 | unsigned int find_string(unsigned char* data, unsigned int base, unsigned int size, const char* name) {
145 | // First find the string
146 | int i = 0;
147 | unsigned int address = 0;
148 | for(i = 0; i < size; i++) {
149 | if(!memcmp(&data[i], name, strlen(name))) {
150 | address = &data[i];
151 | break;
152 | }
153 | }
154 | return address;
155 | }
156 |
157 | void* find_function(const char* name, unsigned char* target, unsigned char* base) {
158 | int i = 0;
159 | unsigned int found = 0;
160 | for(i = 0; i < sizeof(functions); i++) {
161 | if(!strcmp(functions[i][0], name)) {
162 | found = find_offset(target, base, 0x40000, functions[i]);
163 | if(found < 0) {
164 | return NULL;
165 | }
166 | break;
167 | }
168 | }
169 |
170 | return (void*) found;
171 | }
172 |
--------------------------------------------------------------------------------
/heap.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - heap.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | #include "heap.h"
27 |
28 | uint32_t gHeapRemaining;
29 | uint32_t gHeapChunkCount;
30 | heap_chunk_t gHeapChunkList[3];
31 | chunk_header_t* gHeapHeader[32];
32 |
33 | void heap_add_chunk(void* address, uint32_t size) {
34 | chunk_header_t* chunk;
35 | chunk_header_t* last_chunk;
36 | chunk_header_t* first_chunk;
37 |
38 | if(gHeapChunkCount > 3) {
39 | puts("Too many chunks\n");
40 | return;
41 | }
42 | memset(address, '\0', size);
43 |
44 | gHeapChunkList[gHeapChunkCount].address = address;
45 | gHeapChunkList[gHeapChunkCount].size = size;
46 | gHeapChunkCount++;
47 |
48 | chunk = address;
49 | chunk->prev_size &= 0xFCu;
50 | chunk->prev_size &= 3u;
51 | chunk->size = 1;
52 |
53 | first_chunk = get_next_chunk(chunk);
54 | first_chunk->prev_size &= 0xFCu;
55 | first_chunk->prev_size = (first_chunk->prev_size & 7) | 4;
56 | first_chunk->size = (size / 8) - 2;
57 |
58 | last_chunk = get_next_chunk(first_chunk);
59 | last_chunk->prev_size &= 0xFCu;
60 | last_chunk->prev_size = (last_chunk->prev_size & 3) | (4 * first_chunk->size);
61 | last_chunk->size = 1;
62 |
63 | free((void*) first_chunk + 8);
64 | }
65 |
66 | uint32_t get_zone(uint32_t size) {
67 | return (uint32_t) log(size/8);
68 | }
69 |
70 | uint32_t get_min_alloc(uint32_t size) {
71 | uint32_t result = (size + 15) & 0xFFFFFFF8;
72 | if(result <= 0xF) {
73 | result = 16;
74 | }
75 | return result;
76 | }
77 |
78 | chunk_header_t* get_next_chunk(chunk_header_t* chunk) {
79 | return (void*) chunk + (8 * chunk->size);
80 | }
81 |
82 | chunk_header_t*_get_prev_chunk(chunk_header_t* chunk) {
83 | return (void*) chunk - (8 * (chunk->prev_size >> 2));
84 | }
85 |
--------------------------------------------------------------------------------
/image.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - image.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 |
22 | #include "aes.h"
23 | #include "bdev.h"
24 | #include "lock.h"
25 | #include "task.h"
26 | #include "image.h"
27 | #include "common.h"
28 | #include "device.h"
29 |
30 | LinkedList* gImageList = NULL;
31 |
32 | void* find_image_list() {
33 | unsigned int ref = find_string(TARGET_BASEADDR, TARGET_BASEADDR, 0x50000, "tobi");
34 | ImageDescriptor* image = ref-0x1C;
35 | return image->list.prev;
36 | }
37 |
38 | int image_init() {
39 | gImageList = find_image_list();
40 | if(gImageList == NULL) {
41 | puts("Unable to find gImageList\n");
42 | } else {
43 | printf("Found gImageList at 0x%x\n", gImageList);
44 | cmd_add("image", &image_cmd, "display and operate on for firmware images");
45 | }
46 | return 0;
47 | }
48 |
49 | int image_cmd(int argc, CmdArg* argv) {
50 | unsigned int image = 0;
51 | void* address = NULL;
52 | char* action = NULL;
53 | if(argc < 2) {
54 | puts("usage: image [options]\n");
55 | puts(" list \t\tdisplay list of bdev images\n");
56 | puts(" load \t\tload an img3 from bdev\n");
57 | puts(" decrypt \t\tdecrypt an img3 in memory\n");
58 | return 0;
59 | }
60 |
61 | action = argv[1].string;
62 | if(!strcmp(action, "list")) {
63 | image_display_list();
64 | }
65 |
66 | if(argc == 3) {
67 | if(!strcmp(action, "decrypt")) {
68 | address = (void*) argv[2].uinteger;
69 | return image_decrypt(address);
70 | }
71 | }
72 |
73 | if(argc == 4) {
74 | if(!strcmp(action, "load")) {
75 | image = argv[2].uinteger;
76 | address = (void*) argv[3].uinteger;
77 | return image_load(image, address, 0x100000);
78 | }
79 | }
80 |
81 | return 0;
82 | }
83 |
84 | void image_display_list() {
85 | char type[] = "type";
86 | LinkedList* list = gImageList->next;
87 |
88 | enter_critical_section();
89 | printf("Images:\n");
90 | while(list != gImageList) {
91 | ImageDescriptor* image = (ImageDescriptor*)list;
92 | type[0] = (image->info.imageIdentifier & 0xFF000000) >> 24;
93 | type[1] = (image->info.imageIdentifier & 0xFF0000) >> 16;
94 | type[2] = (image->info.imageIdentifier & 0xFF00) >> 8;
95 | type[3] = (image->info.imageIdentifier & 0xFF);
96 | type[4] = '\0';
97 | printf(" %p: bdev: %p type: %s offset: 0x%05x len: 0x%x\n", image,
98 | image->device, type, image->startAddress, image->info.imageSize);
99 |
100 | list = image->list.next;
101 | }
102 | printf("\n");
103 | exit_critical_section();
104 | }
105 |
106 | void* image_find_tag(void* image, unsigned int tag, unsigned int size) {
107 | unsigned int i = 0;
108 | unsigned int* current = image;
109 | current = image;
110 | for (i = 0; i < size; i++) {
111 | if (*current == tag) {
112 | return current;
113 | }
114 | if(i % 0x1000) task_yield();
115 | current++;
116 | }
117 | return 0;
118 | }
119 |
120 | int image_decrypt(void* image) {
121 | void* data = NULL;
122 |
123 | ImageHeader* header = (ImageHeader*) image;
124 | data = image_find_tag(image, IMAGE_DATA, header->fullSize);
125 |
126 | if (data == 0) {
127 | puts("Unable to find DATA tag\n");
128 | return -1;
129 | }
130 |
131 | ImageKbag* kbag = (ImageKbag*) image_find_tag(image, IMAGE_KBAG, header->fullSize);
132 | if (kbag == 0) {
133 | puts("Unable to find KBAG tag\n");
134 | return -1;
135 | }
136 |
137 | ImageTagHeader* data_header = (ImageTagHeader*) data;
138 | data = (void*) data_header + sizeof(ImageTagHeader);
139 |
140 | /* Decrypt kbag */
141 | #ifdef S5L8720X
142 | printf("Decrypting kbag of size 0x%x with type 0x%x\n", kAesSize128, kAesTypeGid);
143 | aes_crypto_cmd(kAesDecrypt, kbag->iv, kbag->iv, kAesSize128, kAesTypeGid, 0, 0);
144 | #else
145 | printf("Decrypting kbag of size 0x%x with type 0x%x\n", kAesSize256, kAesTypeGid);
146 | aes_crypto_cmd(kAesDecrypt, kbag->iv, kbag->iv, kAesSize256, kAesTypeGid, 0, 0);
147 | #endif*/
148 |
149 |
150 | /* Decrypt data */
151 | //FIXME: derive AES type from kbag type
152 | #ifdef S5L8720X
153 | printf("Decrypting data of size 0x%x with type 0x%x\n", 0x20, kAesTypeGid);
154 | aes_crypto_cmd(kAesDecrypt, data, data, (data_header->dataSize - (data_header->dataSize % 16)), kAesType128, kbag->key, kbag->iv);
155 |
156 | #else
157 | printf("Decrypting data of size 0x%x with type 0x%x\n", 0x30, kAesTypeGid);
158 | aes_crypto_cmd(kAesDecrypt, data, data, (data_header->dataSize - (data_header->dataSize % 16)), kAesType256, kbag->key, kbag->iv);
159 | #endif
160 | return 0;
161 | }
162 |
163 | ImageDescriptor* image_find(unsigned int signature) {
164 | LinkedList* list = gImageList->next;
165 | while(list != gImageList) {
166 | ImageDescriptor* image = (ImageDescriptor*) list;
167 | if(image->info.imageIdentifier == signature) {
168 | return image;
169 | }
170 | list = image->list.next;
171 | }
172 | return NULL;
173 | }
174 |
175 | int image_load(unsigned int signature, void* dataout, unsigned int maxsize) {
176 | ImageDescriptor* image = image_find(signature);
177 | if(image == NULL) {
178 | puts("unable to find requested image\n");
179 | return -1;
180 | }
181 |
182 | image->device->read(image->device, dataout,
183 | (void*) image->startAddress, 0, image->info.imageSize);
184 |
185 | image_decrypt(dataout);
186 | }
187 |
--------------------------------------------------------------------------------
/include/aes.h:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * greenpois0n - payload/include/aes.h
4 | * (c) 2010 Chronic-Dev Team
5 | *
6 | */
7 |
8 | #ifndef AES_H
9 | #define AES_H
10 |
11 | #include "device.h"
12 | #include "offsets.h"
13 | #include "common.h"
14 | #include "commands.h"
15 |
16 | #define kAesSizeMin 0x20
17 | #define kAesSizeMax 0x30
18 |
19 | typedef enum {
20 | #ifdef S5L8720X
21 | kAesTypeGid = 0x200,
22 | kAesTypeUid = 0x201
23 | #else
24 | kAesTypeGid = 0x20000200,
25 | kAesTypeUid = 0x20000201
26 | #endif /* S5L8900X */
27 | } AesMode;
28 |
29 | typedef enum {
30 | kAesEncrypt = 0x10,
31 | kAesDecrypt = 0x11
32 | } AesOption;
33 |
34 | typedef enum {
35 | kAesType128 = 0x00000000,
36 | kAesType192 = 0x10000000,
37 | kAesType256 = 0x20000000
38 | } AesType;
39 |
40 | typedef enum {
41 | kAesSize128 = 0x20,
42 | kAesSize192 = 0x28,
43 | kAesSize256 = 0x30
44 | } AesSize;
45 |
46 | extern int(*aes_crypto_cmd)(AesOption option, void* input,
47 | void* output, unsigned int size, AesMode mode,
48 | void* iv, void* key);
49 |
50 | int aes_init();
51 | int aes_cmd(int argc, CmdArg* argv);
52 | unsigned int aes_decrypt_key(unsigned char* in, unsigned char** out);
53 | unsigned int aes_encrypt_key(unsigned char* in, unsigned char** out);
54 |
55 | #endif /* AES_H */
56 |
--------------------------------------------------------------------------------
/include/bdev.h:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * greenpois0n - payload/include/bdev.h
4 | * (c) 2010 Chronic-Dev Team
5 | *
6 | */
7 |
8 | #ifndef BDEV_H
9 | #define BDEV_H
10 |
11 | #include "common.h"
12 | #include "device.h"
13 | #include "offsets.h"
14 | #include "commands.h"
15 |
16 | #ifdef TARGET_BDEV_LIST
17 | # define SELF_BDEV_LIST ((void*)(TARGET_BASEADDR + TARGET_BDEV_LIST))
18 | #endif
19 |
20 | #ifndef SELF_BDEV_LIST
21 | # define SELF_BDEV_LIST 0
22 | #endif
23 |
24 | typedef struct BdevDescriptor {
25 | struct BdevDescriptor* next;
26 | void* unk1;
27 | unsigned int blockSize;
28 | unsigned int numOfBlocks;
29 | unsigned int unk2;
30 | unsigned long long logicalSize;
31 | void(*read)(struct BdevDescriptor* bdev, void* source, void* destination, unsigned int unk, unsigned int size);
32 | void(*default_block_read)();
33 | void(*write)(struct BdevDescriptor* bdev, void* source, void* destination, unsigned int unk, unsigned int size);
34 | void(*default_block_write)();
35 | void(*default_block_erase)();
36 | char name[0x10];
37 | } BdevDescriptor;
38 |
39 | extern BdevDescriptor** gBdevList;
40 |
41 | int bdev_init();
42 | int bdev_cmd(int argc, CmdArg* argv);
43 | void bdev_display_list();
44 | BdevDescriptor* bdev_find_device(const char* name);
45 |
46 | int bdev_read(BdevDescriptor* bdev, void* destination, void* source, unsigned int size);
47 | int bdev_write(BdevDescriptor* bdev, void* source, void* destination, unsigned int size);
48 |
49 | #endif // BDEV_H
50 |
--------------------------------------------------------------------------------
/include/breakpoint.h:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * greenpois0n - payload/include/breakpoint.h
4 | * (c) 2010 Chronic-Dev Team
5 | *
6 | */
7 |
8 | #ifndef BREAKPOINT_H
9 | #define BREAKPOINT_H
10 |
11 | #include "common.h"
12 | #include "commands.h"
13 |
14 | #define BKPT_THUMB ((unsigned short) 0xbe00)
15 | #define BKPT_ARM ((unsigned int) 0xe1200071)
16 |
17 | typedef struct BreakpointEntry {
18 | unsigned int id;
19 | Bool reset;
20 | unsigned int value;
21 | void* address;
22 | void* hexdump_address;
23 | unsigned int hexdump_len;
24 | struct BreakpointEntry* next;
25 | } BreakpointEntry;
26 |
27 | typedef struct BreakpointLog {
28 | unsigned int id;
29 | unsigned int bp_id;
30 | unsigned int pc;
31 | unsigned int r0;
32 | unsigned int r1;
33 | unsigned int r2;
34 | unsigned int r3;
35 | unsigned int r4;
36 | unsigned int r5;
37 | unsigned int r6;
38 | unsigned int r7;
39 | unsigned int r8;
40 | unsigned int r9;
41 | unsigned int r10;
42 | unsigned int r11;
43 | unsigned int r12;
44 | unsigned int sp;
45 | unsigned int lr;
46 | unsigned int spsr;
47 | unsigned int stack[0x10];
48 | void* hexdump_address;
49 | unsigned int hexdump_len;
50 | unsigned int* hexdump_result;
51 | struct BreakpointLog *next;
52 | } BreakpointLog;
53 |
54 | /*
55 | * Public Functions
56 | */
57 |
58 | int break_init();
59 | int break_cmd(int argc, CmdArg* argv);
60 | void breakpoint_list();
61 | BreakpointEntry* breakpoint_add(void* address, Bool reset);
62 | Bool breakpoint_remove(unsigned int id);
63 | void breakpoint_log_list();
64 | void breakpoint_log_show(unsigned int id);
65 | void breakpoint_log_clear();
66 | BreakpointLog* breakpoint_log_find(unsigned int id);
67 | void breakpoint_log_add(BreakpointLog *log);
68 | BreakpointLog* breakpoint_log_remove(unsigned int id);
69 |
70 | /*
71 | * Private Functions
72 | */
73 | void breakpoint(unsigned int* stack);
74 |
75 | #endif /* BREAKPOINT_H */
76 |
--------------------------------------------------------------------------------
/include/commands.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - commands.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef COMMANDS_H
21 | #define COMMANDS_H
22 |
23 | #include "device.h"
24 | #include "offsets.h"
25 |
26 | #define MAX_COMMANDS 40
27 |
28 | #define CMDARG_TYPE_STRING 0
29 | #define CMDARG_TYPE_INTEGER 1
30 |
31 | typedef struct CmdArg {
32 | signed int unk1;
33 | unsigned int uinteger;
34 | signed int integer;
35 | unsigned int type;
36 | unsigned char* string;
37 | } CmdArg;
38 |
39 | typedef int(*CmdFunction)(int argc, CmdArg* argv);
40 |
41 | typedef struct CmdInfo {
42 | char* name;
43 | CmdFunction handler;
44 | char* description;
45 | } CmdInfo;
46 |
47 | extern unsigned char* gCmdListBegin;
48 | extern unsigned char* gCmdListEnd;
49 |
50 | extern int gCmdCount;
51 | extern Bool gCmdHasInit;
52 | extern CmdInfo** gCmdCommands;
53 |
54 | extern int(*jump_to)(int flags, void* addr, int phymem);
55 | extern int(*load_ramdisk)(int argc);
56 |
57 | int cmd_init();
58 | void cmd_add(char* name, CmdFunction handler, char* description);
59 |
60 | int cmd_help(int argc, CmdArg* argv);
61 | int cmd_echo(int argc, CmdArg* argv);
62 | int cmd_hexdump(int argc, CmdArg* argv);
63 | int cmd_jump(int argc, CmdArg* argv);
64 | int cmd_mw(int argc, CmdArg* argv);
65 | int cmd_md(int argc, CmdArg* argv);
66 | int cmd_call(int argc, CmdArg* argv);
67 | int cmd_fsboot(int argc, CmdArg* argv);
68 | int cmd_rdboot(int argc, CmdArg* argv);
69 | int cmd_ramdisk(int argc, CmdArg* argv);
70 | int cmd_test(int argc, CmdArg* argv);
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/include/common.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - common.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef COMMON_H
21 | #define COMMON_H
22 |
23 | #include "device.h"
24 | #include "offsets.h"
25 |
26 | #ifndef NULL
27 | #define NULL 0
28 | #endif
29 |
30 | #define FLIPENDIAN(x) flip_endian((unsigned char*)(&(x)), sizeof(x))
31 |
32 | #define GETREG32(addr) (*((unsigned int*) addr))
33 | #define SETREG32(addr, val) (*(volatile unsigned int*) addr = val)
34 |
35 | #define GETREG16(addr) (*((unsigned short*) addr))
36 | #define SETREG16(addr, val) (*(volatile unsigned short*) addr = val)
37 |
38 | #ifdef NULL
39 | #undef NULL
40 | #define NULL 0
41 | #endif
42 |
43 | #define free _free
44 | #define puts _puts
45 | #define printf _printf
46 | #define malloc _malloc
47 |
48 | typedef enum {
49 | TRUE = 1,
50 | FALSE = 0
51 | } Bool;
52 |
53 | typedef struct LinkedList {
54 | void* prev;
55 | void* next;
56 | } LinkedList;
57 |
58 | extern void(*_free)(void* ptr);
59 | extern void _puts(const char* message);
60 | extern void*(*_malloc)(unsigned int size);
61 | extern int(*_printf)(const char *format, ...);
62 |
63 | extern void* gLoadaddr;
64 | extern void* gBaseaddr;
65 | extern void* gRomBaseaddr;
66 | extern void* gBssBaseaddr;
67 | extern void* gBootBaseaddr;
68 |
69 | static inline void flip_endian(unsigned char* x, int length) {
70 | unsigned int i = 0;
71 | unsigned char tmp = '\0';
72 | for(i = 0; i < (length / 2); i++) {
73 | tmp = x[i];
74 | x[i] = x[length - i - 1];
75 | x[length - i - 1] = tmp;
76 | }
77 | }
78 |
79 | int common_init();
80 | int gpprintf(const char *format, ...);
81 | void printf_begin();
82 | void panic(const char* why);
83 |
84 | #endif /* COMMON_H */
85 |
--------------------------------------------------------------------------------
/include/coprocessor.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - coprocessor.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef COPROCESSOR_H
21 | #define COPROCESSOR_H
22 |
23 | // c0
24 | int read_processor_id();
25 | int read_processor_features();
26 | int read_silicon_id();
27 |
28 | // c1
29 | int read_control_register();
30 | void write_control_register(int value);
31 | int read_auxcontrol_register();
32 | void write_auxcontrol_register(int value);
33 |
34 | // c2
35 | int read_TBB0();
36 | void write_TBB0(int value);
37 |
38 | // c3
39 | int read_DAC();
40 | void write_DAC(int value);
41 |
42 | // c7
43 | void clear_icache();
44 | //void clear_dcache(); //pod2g: removed, not armv6 compatible
45 |
46 | // multiple
47 | //void clear_cpu_caches(); //pod2g: removed, not armv6 compatible
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/include/filesystem.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - filesystem.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef FILESYSTEM_H
21 | #define FILESYSTEM_H
22 |
23 | #include "common.h"
24 | #include "device.h"
25 | #include "offsets.h"
26 | #include "commands.h"
27 |
28 | #ifdef TARGET_FS_UNMOUNT
29 | # define SELF_FS_UNMOUNT ((void*)(TARGET_BASEADDR + TARGET_FS_UNMOUNT))
30 | #endif
31 | #ifdef TARGET_FS_LOAD_FILE
32 | # define SELF_FS_LOAD_FILE ((void*)(TARGET_BASEADDR + TARGET_FS_LOAD_FILE))
33 | #endif
34 |
35 | #ifndef SELF_FS_UNMOUNT
36 | # define SELF_FS_UNMOUNT 0
37 | #endif
38 | #ifndef SELF_FS_LOAD_FILE
39 | # define SELF_FS_LOAD_FILE 0
40 | #endif
41 |
42 | extern void(*fs_unmount)(const char *path);
43 | extern int(*fs_load_file)(const char *path, void* address, unsigned int* size);
44 | extern void(*fs_mount)(const char *partition, const char *type, const char *path);
45 |
46 | int fs_init();
47 | int fs_cmd(int argc, CmdArg* argv);
48 |
49 | #endif /* FILESYSTEM_H */
50 |
--------------------------------------------------------------------------------
/include/font.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - font.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef FONT_H
21 | #define FONT_H
22 |
23 | static const unsigned char font_data[] = {
24 | 0x06, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x40, 0x05, 0x44, 0x40,
25 | 0x04, 0x54, 0x00, 0x00, 0x00, 0x84, 0xf3, 0x39, 0x04, 0x00, 0x00, 0x95,
26 | 0x5a, 0xa9, 0x95, 0x5a, 0xa9, 0x95, 0x0a, 0x24, 0xc9, 0x93, 0x24, 0x1e,
27 | 0x82, 0x20, 0xc0, 0x11, 0x0c, 0x41, 0x47, 0x30, 0x04, 0x01, 0x38, 0x41,
28 | 0xe0, 0x38, 0x92, 0x23, 0x49, 0x40, 0x10, 0x04, 0x8f, 0x27, 0x38, 0x82,
29 | 0x00, 0x10, 0x0a, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x1f,
30 | 0x41, 0x7c, 0x00, 0x00, 0x24, 0xcb, 0xd2, 0x24, 0x82, 0x20, 0x78, 0x40,
31 | 0x92, 0x18, 0x82, 0x87, 0x20, 0x08, 0x42, 0x10, 0x04, 0x41, 0x1c, 0x00,
32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x41, 0x10, 0x04, 0x01, 0x00, 0x00,
33 | 0x00, 0xf0, 0x04, 0x41, 0x10, 0x04, 0x41, 0x10, 0x04, 0x0f, 0x00, 0x00,
34 | 0x40, 0x10, 0x04, 0x41, 0xfc, 0x04, 0x41, 0x10, 0x3f, 0x00, 0x00, 0x00,
35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
36 | 0x00, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
37 | 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x4f, 0x10, 0x04,
38 | 0x41, 0xf0, 0x04, 0x41, 0x10, 0x04, 0x41, 0x10, 0xc4, 0x41, 0x10, 0x04,
39 | 0x41, 0x10, 0x04, 0x41, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
40 | 0x4f, 0x10, 0x04, 0x41, 0x10, 0x04, 0x41, 0x10, 0x04, 0x41, 0x10, 0x00,
41 | 0x66, 0x04, 0x06, 0x06, 0x7c, 0x00, 0x00, 0x0c, 0x0c, 0xc4, 0x0c, 0xc0,
42 | 0x07, 0x00, 0x00, 0x00, 0x7c, 0x8a, 0xa2, 0x28, 0x00, 0x00, 0x40, 0xc8,
43 | 0x47, 0x7c, 0x42, 0x00, 0x00, 0x00, 0x23, 0x09, 0x87, 0x20, 0x35, 0x00,
44 | 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45 | 0x00, 0x00, 0x00, 0x00, 0x10, 0x04, 0x41, 0x10, 0x00, 0x01, 0x00, 0x80,
46 | 0xa2, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0xca, 0xa7, 0x7c, 0x8a,
47 | 0x02, 0x00, 0x00, 0xe1, 0x14, 0x0e, 0xe5, 0x10, 0x00, 0x00, 0x48, 0x95,
48 | 0x42, 0x28, 0x55, 0x02, 0x00, 0x80, 0x50, 0x14, 0x42, 0x95, 0x58, 0x00,
49 | 0x00, 0x10, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x08, 0x82,
50 | 0x40, 0x20, 0x00, 0x00, 0x08, 0x04, 0x82, 0x20, 0x84, 0x00, 0x00, 0x00,
51 | 0x10, 0x29, 0x9f, 0x12, 0x01, 0x00, 0x00, 0x00, 0x04, 0xf1, 0x11, 0x04,
52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x10, 0x02, 0x00, 0x00, 0x00,
53 | 0xf0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x38, 0x04,
54 | 0x00, 0x40, 0x10, 0x42, 0x08, 0x41, 0x00, 0x00, 0x00, 0xa1, 0x44, 0x51,
55 | 0xa4, 0x10, 0x00, 0x00, 0x10, 0x46, 0x41, 0x10, 0xc4, 0x07, 0x00, 0x80,
56 | 0x13, 0x41, 0x8c, 0x10, 0x7c, 0x00, 0x00, 0x7c, 0x10, 0xc2, 0x40, 0x91,
57 | 0x03, 0x00, 0x00, 0xc2, 0x28, 0xc9, 0x87, 0x20, 0x00, 0x00, 0x7c, 0x41,
58 | 0x33, 0x41, 0x91, 0x03, 0x00, 0x00, 0x23, 0x04, 0xcd, 0x14, 0x39, 0x00,
59 | 0x00, 0x7c, 0x10, 0x82, 0x10, 0x82, 0x00, 0x00, 0x80, 0x13, 0x45, 0x4e,
60 | 0x14, 0x39, 0x00, 0x00, 0x38, 0x51, 0x66, 0x41, 0x88, 0x01, 0x00, 0x00,
61 | 0x40, 0x38, 0x04, 0x40, 0x38, 0x04, 0x00, 0x00, 0x84, 0x43, 0x00, 0x0c,
62 | 0x21, 0x00, 0x00, 0x84, 0x10, 0x02, 0x81, 0x40, 0x00, 0x00, 0x00, 0xc0,
63 | 0x07, 0x7c, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x42, 0x08, 0x00,
64 | 0x00, 0x38, 0x11, 0x42, 0x10, 0x00, 0x01, 0x00, 0x80, 0x13, 0x65, 0x55,
65 | 0x13, 0x38, 0x00, 0x00, 0x10, 0x4a, 0x14, 0x7d, 0x51, 0x04, 0x00, 0xc0,
66 | 0x23, 0x49, 0x8e, 0x24, 0x3d, 0x00, 0x00, 0x38, 0x51, 0x10, 0x04, 0x91,
67 | 0x03, 0x00, 0xc0, 0x23, 0x49, 0x92, 0x24, 0x3d, 0x00, 0x00, 0x7c, 0x41,
68 | 0xf0, 0x04, 0xc1, 0x07, 0x00, 0xc0, 0x17, 0x04, 0x4f, 0x10, 0x04, 0x00,
69 | 0x00, 0x38, 0x51, 0x10, 0x64, 0x91, 0x03, 0x00, 0x40, 0x14, 0x45, 0x5f,
70 | 0x14, 0x45, 0x00, 0x00, 0x38, 0x04, 0x41, 0x10, 0x84, 0x03, 0x00, 0x00,
71 | 0x87, 0x20, 0x08, 0x92, 0x18, 0x00, 0x00, 0x44, 0x49, 0x31, 0x14, 0x49,
72 | 0x04, 0x00, 0x40, 0x10, 0x04, 0x41, 0x10, 0x7c, 0x00, 0x00, 0x44, 0xd1,
73 | 0x56, 0x45, 0x51, 0x04, 0x00, 0x40, 0x14, 0x4d, 0x55, 0x16, 0x45, 0x00,
74 | 0x00, 0x38, 0x51, 0x14, 0x45, 0x91, 0x03, 0x00, 0xc0, 0x13, 0x45, 0x4f,
75 | 0x10, 0x04, 0x00, 0x00, 0x38, 0x51, 0x14, 0x45, 0x95, 0x03, 0x01, 0xc0,
76 | 0x13, 0x45, 0x4f, 0x91, 0x44, 0x00, 0x00, 0x38, 0x51, 0xe0, 0x40, 0x91,
77 | 0x03, 0x00, 0xc0, 0x47, 0x10, 0x04, 0x41, 0x10, 0x00, 0x00, 0x44, 0x51,
78 | 0x14, 0x45, 0x91, 0x03, 0x00, 0x40, 0x14, 0x45, 0x8a, 0xa2, 0x10, 0x00,
79 | 0x00, 0x44, 0x51, 0x54, 0x55, 0x5b, 0x04, 0x00, 0x40, 0x14, 0x29, 0x84,
80 | 0x12, 0x45, 0x00, 0x00, 0x44, 0x91, 0x42, 0x10, 0x04, 0x01, 0x00, 0xc0,
81 | 0x07, 0x21, 0x84, 0x10, 0x7c, 0x00, 0x00, 0x38, 0x82, 0x20, 0x08, 0x82,
82 | 0x03, 0x00, 0x40, 0x10, 0x08, 0x04, 0x02, 0x41, 0x00, 0x00, 0x38, 0x08,
83 | 0x82, 0x20, 0x88, 0x03, 0x00, 0x00, 0xa1, 0x44, 0x00, 0x00, 0x00, 0x00,
84 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x04, 0x02, 0x00, 0x00,
85 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x79, 0x91, 0x07, 0x00, 0x40,
86 | 0x10, 0x34, 0x53, 0x34, 0x35, 0x00, 0x00, 0x00, 0x80, 0x13, 0x05, 0x91,
87 | 0x03, 0x00, 0x00, 0x04, 0x59, 0x59, 0x94, 0x59, 0x00, 0x00, 0x00, 0x80,
88 | 0x13, 0x7d, 0x81, 0x03, 0x00, 0x00, 0x23, 0x09, 0x8f, 0x20, 0x08, 0x00,
89 | 0x00, 0x00, 0x80, 0x17, 0x45, 0x1e, 0x14, 0x39, 0x40, 0x10, 0x34, 0x53,
90 | 0x14, 0x45, 0x00, 0x00, 0x10, 0x80, 0x41, 0x10, 0x84, 0x03, 0x00, 0x00,
91 | 0x04, 0x60, 0x10, 0x04, 0x49, 0x12, 0x03, 0x04, 0x41, 0x94, 0x1c, 0x49,
92 | 0x04, 0x00, 0x80, 0x41, 0x10, 0x04, 0x41, 0x38, 0x00, 0x00, 0x00, 0xc0,
93 | 0x52, 0x55, 0x55, 0x04, 0x00, 0x00, 0x00, 0x34, 0x53, 0x14, 0x45, 0x00,
94 | 0x00, 0x00, 0x80, 0x13, 0x45, 0x91, 0x03, 0x00, 0x00, 0x00, 0x34, 0x53,
95 | 0x34, 0x35, 0x41, 0x00, 0x00, 0x80, 0x95, 0x45, 0x99, 0x05, 0x41, 0x00,
96 | 0x00, 0x34, 0x53, 0x10, 0x04, 0x00, 0x00, 0x00, 0x80, 0x13, 0x38, 0xd0,
97 | 0x03, 0x00, 0x80, 0x20, 0x3c, 0x82, 0x20, 0x31, 0x00, 0x00, 0x00, 0x40,
98 | 0x14, 0x45, 0x99, 0x05, 0x00, 0x00, 0x00, 0x44, 0x91, 0xa2, 0x10, 0x00,
99 | 0x00, 0x00, 0x40, 0x14, 0x55, 0x95, 0x02, 0x00, 0x00, 0x00, 0x44, 0x0a,
100 | 0xa1, 0x44, 0x00, 0x00, 0x00, 0x40, 0x14, 0x65, 0x16, 0x14, 0x39, 0x00,
101 | 0x00, 0x7c, 0x08, 0x21, 0x7c, 0x00, 0x00, 0x60, 0x04, 0x62, 0x20, 0x04,
102 | 0x06, 0x00, 0x00, 0x41, 0x10, 0x04, 0x41, 0x10, 0x00, 0x00, 0x18, 0x08,
103 | 0x81, 0x11, 0x88, 0x01, 0x00, 0x80, 0x54, 0x25, 0x00, 0x00, 0x00, 0x00,
104 | 0x00, 0x54, 0x40, 0x04, 0x44, 0x40, 0x05, 0x00, 0x40, 0x05, 0x44, 0x40,
105 | 0x04, 0x54, 0x00, 0x00, 0x54, 0x40, 0x04, 0x44, 0x40, 0x05, 0x00, 0x40,
106 | 0x05, 0x44, 0x40, 0x04, 0x54, 0x00, 0x00, 0x54, 0x40, 0x04, 0x44, 0x40,
107 | 0x05, 0x00, 0x40, 0x05, 0x44, 0x40, 0x04, 0x54, 0x00, 0x00, 0x54, 0x40,
108 | 0x04, 0x44, 0x40, 0x05, 0x00, 0x40, 0x05, 0x44, 0x40, 0x04, 0x54, 0x00,
109 | 0x00, 0x54, 0x40, 0x04, 0x44, 0x40, 0x05, 0x00, 0x40, 0x05, 0x44, 0x40,
110 | 0x04, 0x54, 0x00, 0x00, 0x54, 0x40, 0x04, 0x44, 0x40, 0x05, 0x00, 0x40,
111 | 0x05, 0x44, 0x40, 0x04, 0x54, 0x00, 0x00, 0x54, 0x40, 0x04, 0x44, 0x40,
112 | 0x05, 0x00, 0x40, 0x05, 0x44, 0x40, 0x04, 0x54, 0x00, 0x00, 0x54, 0x40,
113 | 0x04, 0x44, 0x40, 0x05, 0x00, 0x40, 0x05, 0x44, 0x40, 0x04, 0x54, 0x00,
114 | 0x00, 0x54, 0x40, 0x04, 0x44, 0x40, 0x05, 0x00, 0x40, 0x05, 0x44, 0x40,
115 | 0x04, 0x54, 0x00, 0x00, 0x54, 0x40, 0x04, 0x44, 0x40, 0x05, 0x00, 0x40,
116 | 0x05, 0x44, 0x40, 0x04, 0x54, 0x00, 0x00, 0x54, 0x40, 0x04, 0x44, 0x40,
117 | 0x05, 0x00, 0x40, 0x05, 0x44, 0x40, 0x04, 0x54, 0x00, 0x00, 0x54, 0x40,
118 | 0x04, 0x44, 0x40, 0x05, 0x00, 0x40, 0x05, 0x44, 0x40, 0x04, 0x54, 0x00,
119 | 0x00, 0x54, 0x40, 0x04, 0x44, 0x40, 0x05, 0x00, 0x40, 0x05, 0x44, 0x40,
120 | 0x04, 0x54, 0x00, 0x00, 0x54, 0x40, 0x04, 0x44, 0x40, 0x05, 0x00, 0x40,
121 | 0x05, 0x44, 0x40, 0x04, 0x54, 0x00, 0x00, 0x54, 0x40, 0x04, 0x44, 0x40,
122 | 0x05, 0x00, 0x40, 0x05, 0x44, 0x40, 0x04, 0x54, 0x00, 0x00, 0x54, 0x40,
123 | 0x04, 0x44, 0x40, 0x05, 0x00, 0x40, 0x05, 0x44, 0x40, 0x04, 0x54, 0x00,
124 | 0x00, 0x54, 0x40, 0x04, 0x44, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
125 | 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x41, 0x10, 0x04, 0x01, 0x00, 0x00,
126 | 0x40, 0x78, 0x45, 0x51, 0x78, 0x04, 0x00, 0x30, 0x92, 0x70, 0x08, 0x52,
127 | 0x03, 0x00, 0x00, 0x00, 0x44, 0x8e, 0xe2, 0x44, 0x00, 0x00, 0x44, 0x91,
128 | 0x42, 0x7c, 0x04, 0x41, 0x00, 0x00, 0x41, 0x10, 0x00, 0x41, 0x10, 0x00,
129 | 0x00, 0x38, 0xc1, 0x91, 0x48, 0x1c, 0xe4, 0x00, 0x0a, 0x00, 0x00, 0x00,
130 | 0x00, 0x00, 0x00, 0x00, 0x38, 0x51, 0x35, 0x55, 0x91, 0x03, 0x00, 0x00,
131 | 0x27, 0x69, 0x14, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x29, 0x25, 0x12,
132 | 0x09, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
133 | 0xe0, 0x01, 0x00, 0x00, 0x00, 0x80, 0x13, 0x5d, 0xd3, 0x14, 0x39, 0x00,
134 | 0xf0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa1, 0x10, 0x00,
135 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xf1, 0x11, 0xc4, 0x07, 0x00, 0x8c,
136 | 0x84, 0x10, 0x1e, 0x00, 0x00, 0x00, 0xe0, 0x40, 0x0c, 0xe4, 0x00, 0x00,
137 | 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
138 | 0x14, 0x45, 0x53, 0x13, 0x00, 0x80, 0x77, 0x5d, 0x16, 0x45, 0x51, 0x00,
139 | 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140 | 0x00, 0x00, 0x08, 0x41, 0x18, 0x04, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00,
141 | 0x23, 0x49, 0x0c, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x40, 0x22, 0x91, 0x52,
142 | 0x02, 0x00, 0xc2, 0x20, 0x08, 0x27, 0x8c, 0xf2, 0x20, 0x20, 0x0c, 0x82,
143 | 0x70, 0xa1, 0x20, 0x84, 0x03, 0x03, 0x21, 0x10, 0x13, 0x46, 0x79, 0x10,
144 | 0x00, 0x10, 0x00, 0x41, 0x08, 0x91, 0x03, 0x00, 0x02, 0xe1, 0x44, 0xd1,
145 | 0x17, 0x45, 0x00, 0x80, 0x10, 0x4e, 0x14, 0x7d, 0x51, 0x04, 0x00, 0x84,
146 | 0xe2, 0x44, 0xd1, 0x17, 0x45, 0x00, 0x20, 0x35, 0x4e, 0x14, 0x7d, 0x51,
147 | 0x04, 0x00, 0x0a, 0xe0, 0x44, 0xd1, 0x17, 0x45, 0x00, 0x40, 0x28, 0x4e,
148 | 0x14, 0x7d, 0x51, 0x04, 0x00, 0x00, 0xaf, 0x24, 0xf9, 0x93, 0xe4, 0x00,
149 | 0x00, 0x38, 0x51, 0x10, 0x04, 0x91, 0x43, 0x08, 0xc2, 0x17, 0x04, 0x4f,
150 | 0x10, 0x7c, 0x00, 0x80, 0x7c, 0x41, 0xf0, 0x04, 0xc1, 0x07, 0x00, 0xc4,
151 | 0x17, 0x04, 0x4f, 0x10, 0x7c, 0x00, 0xa0, 0x7c, 0x41, 0xf0, 0x04, 0xc1,
152 | 0x07, 0x00, 0x02, 0xe1, 0x10, 0x04, 0x41, 0x38, 0x00, 0x80, 0x10, 0x0e,
153 | 0x41, 0x10, 0x84, 0x03, 0x00, 0x84, 0xe2, 0x10, 0x04, 0x41, 0x38, 0x00,
154 | 0xa0, 0x00, 0x0e, 0x41, 0x10, 0x84, 0x03, 0x00, 0xc0, 0x23, 0x49, 0x97,
155 | 0x24, 0x3d, 0x00, 0x40, 0x29, 0xd1, 0x54, 0x65, 0x51, 0x04, 0x00, 0x02,
156 | 0xe1, 0x44, 0x51, 0x14, 0x39, 0x00, 0x80, 0x10, 0x4e, 0x14, 0x45, 0x91,
157 | 0x03, 0x00, 0x84, 0xe2, 0x44, 0x51, 0x14, 0x39, 0x00, 0x40, 0x29, 0x4e,
158 | 0x14, 0x45, 0x91, 0x03, 0x00, 0x0a, 0xe0, 0x44, 0x51, 0x14, 0x39, 0x00,
159 | 0x00, 0x00, 0x40, 0xa4, 0x10, 0x4a, 0x04, 0x00, 0x80, 0x93, 0x65, 0xd5,
160 | 0x34, 0x39, 0x00, 0x20, 0x10, 0x51, 0x14, 0x45, 0x91, 0x03, 0x00, 0x08,
161 | 0x11, 0x45, 0x51, 0x14, 0x39, 0x00, 0x40, 0x28, 0x40, 0x14, 0x45, 0x91,
162 | 0x03, 0x00, 0x0a, 0x10, 0x45, 0x51, 0x14, 0x39, 0x00, 0x80, 0x10, 0x51,
163 | 0xa4, 0x10, 0x04, 0x01, 0x00, 0x40, 0xf0, 0x44, 0x4f, 0x10, 0x04, 0x00,
164 | 0x00, 0x38, 0x51, 0x52, 0x24, 0x51, 0x03, 0x00, 0x02, 0x01, 0x38, 0x90,
165 | 0x17, 0x79, 0x00, 0x80, 0x10, 0x80, 0x03, 0x79, 0x91, 0x07, 0x00, 0x84,
166 | 0x02, 0x38, 0x90, 0x17, 0x79, 0x00, 0x40, 0x29, 0x80, 0x03, 0x79, 0x91,
167 | 0x07, 0x00, 0x80, 0x02, 0x38, 0x90, 0x17, 0x79, 0x00, 0x40, 0x28, 0x84,
168 | 0x03, 0x79, 0x91, 0x07, 0x00, 0x00, 0x00, 0x78, 0xa8, 0x9f, 0xf8, 0x00,
169 | 0x00, 0x00, 0x80, 0x13, 0x05, 0x91, 0x43, 0x08, 0x02, 0x01, 0x38, 0xd1,
170 | 0x17, 0x38, 0x00, 0x80, 0x10, 0x80, 0x13, 0x7d, 0x81, 0x03, 0x00, 0x84,
171 | 0x02, 0x38, 0xd1, 0x17, 0x38, 0x00, 0x00, 0x28, 0x80, 0x13, 0x7d, 0x81,
172 | 0x03, 0x00, 0x02, 0x01, 0x18, 0x04, 0x41, 0x38, 0x00, 0x40, 0x08, 0x80,
173 | 0x41, 0x10, 0x84, 0x03, 0x00, 0x84, 0x02, 0x18, 0x04, 0x41, 0x38, 0x00,
174 | 0x00, 0x28, 0x80, 0x41, 0x10, 0x84, 0x03, 0x00, 0xc0, 0xc0, 0x38, 0x51,
175 | 0x14, 0x39, 0x00, 0x40, 0x29, 0x40, 0x33, 0x45, 0x51, 0x04, 0x00, 0x02,
176 | 0x01, 0x38, 0x51, 0x14, 0x39, 0x00, 0x80, 0x10, 0x80, 0x13, 0x45, 0x91,
177 | 0x03, 0x00, 0x84, 0x02, 0x38, 0x51, 0x14, 0x39, 0x00, 0x40, 0x29, 0x80,
178 | 0x13, 0x45, 0x91, 0x03, 0x00, 0x80, 0x02, 0x38, 0x51, 0x14, 0x39, 0x00,
179 | 0x00, 0x00, 0x04, 0xf0, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x78, 0x59,
180 | 0x35, 0x3d, 0x00, 0x20, 0x10, 0x40, 0x14, 0x45, 0x99, 0x05, 0x00, 0x08,
181 | 0x01, 0x44, 0x51, 0x94, 0x59, 0x00, 0x40, 0x28, 0x40, 0x14, 0x45, 0x99,
182 | 0x05, 0x00, 0x80, 0x02, 0x44, 0x51, 0x94, 0x59, 0x00, 0x00, 0x20, 0x44,
183 | 0x14, 0x65, 0x16, 0x14, 0x39, 0x00, 0x10, 0x3c, 0x51, 0x14, 0x3d, 0x41,
184 | 0x00, 0x28, 0x40, 0x14, 0x65, 0x16, 0x14, 0x39,
185 | };
186 |
187 | #endif
188 |
--------------------------------------------------------------------------------
/include/framebuffer.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - framebuffer.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef FRAMEBUFFER_H
21 | #define FRAMEBUFFER_H
22 |
23 | #include "commands.h"
24 |
25 | #define COLOR_WHITE 0xffffff
26 | #define COLOR_BLACK 0x0
27 |
28 | typedef struct Font {
29 | unsigned int width;
30 | unsigned int height;
31 | unsigned char data[];
32 | } Font;
33 |
34 | extern Bool gFbHasInit;
35 |
36 | int fb_init();
37 | int fb_cmd(int argc, CmdArg* argv);
38 | void fb_clear();
39 | void fb_display_text(Bool option);
40 | void fb_set_loc(unsigned int x, unsigned int y);
41 | unsigned int fb_get_x();
42 | unsigned int fb_get_y();
43 | unsigned int fb_get_width();
44 | unsigned int fb_get_height();
45 | void fb_putc(int c);
46 | void fb_print(const char* str);
47 | void fb_print_force(const char* str);
48 | void fb_draw_image(unsigned int* image, unsigned int x, unsigned int y, unsigned int width, unsigned int height);
49 | void fb_capture_image(unsigned int* image, unsigned int x, unsigned int y, unsigned int width, unsigned int height);
50 | unsigned int* fb_load_image(const char* data, unsigned int len, unsigned int* width, unsigned int* height, unsigned int alpha);
51 |
52 | #endif /* FRAMEBUFFER_H */
53 |
--------------------------------------------------------------------------------
/include/functions.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - functions.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef FUNCTIONS_H
21 | #define FUNCTIONS_H
22 |
23 | unsigned int find_reference(unsigned char* data, unsigned int base, unsigned int size, unsigned int address);
24 | unsigned int find_top(unsigned char* data, unsigned int base, unsigned int size, unsigned int address);
25 | unsigned int find_offset(unsigned char* data, unsigned int base, unsigned int size, unsigned char** what);
26 | unsigned int find_string(unsigned char* data, unsigned int base, unsigned int size, const char* name);
27 | void* find_function(const char* name, unsigned char* target, unsigned char* base);
28 |
29 | #endif /* LOCK_H */
30 |
31 |
--------------------------------------------------------------------------------
/include/heap.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - heap.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef HEAP_H
21 | #define HEAP_H
22 |
23 | #include
24 |
25 | #define panic(x) fprintf(stderr, "PANIC: %s", x);exit(1)
26 |
27 | typedef struct chunk_header {
28 | int prev_size;
29 | int size;
30 | struct chunk_header* next;
31 | struct chunk_header** head;
32 | } chunk_header_t;
33 |
34 | typedef struct heap_chunk {
35 | void* address;
36 | uint32_t size;
37 | } heap_chunk_t;
38 |
39 | extern uint32_t gHeapRemaining;
40 | extern uint32_t gHeapChunkCount;
41 | extern heap_chunk_t gHeapChunkList[3];
42 | extern chunk_header_t* gHeapHeader[32];
43 |
44 | void _free(void* ptr);
45 | void* _malloc(uint32_t size);
46 | void _heap_add_chunk(void* address, uint32_t size);
47 |
48 | uint32_t _get_zone(uint32_t size);
49 | uint32_t _get_min_alloc(uint32_t size);
50 | chunk_header_t* _get_next_chunk(chunk_header_t* chunk);
51 | chunk_header_t* _get_prev_chunk(chunk_header_t* chunk);
52 | void _link_chunk(chunk_header_t* chunk, unsigned int size);
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/include/image.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - image.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef IMAGE_H
21 | #define IMAGE_H
22 |
23 | #include "common.h"
24 | #include "device.h"
25 | #include "offsets.h"
26 | #include "commands.h"
27 |
28 | #define IMAGE_IMG3 0x496D6733
29 | #define IMAGE_8900 0x30303938
30 |
31 | #define IMAGE_IBOOT 0x69626F74
32 | #define IMAGE_LLB 0x696C6C62
33 |
34 | #define IMAGE_DATA 0x44415441
35 | #define IMAGE_KBAG 0x4B424147
36 | #define IMAGE_COMP 0x636F6D70
37 | #define IMAGE_LZSS 0x6C7A7373
38 |
39 | typedef struct Image8900Header {
40 | unsigned int signature;
41 | unsigned char version[3];
42 | unsigned char format;
43 | unsigned int unk1;
44 | unsigned int dataSize;
45 | unsigned int footerSignatureOffset;
46 | unsigned int footerCertOffset;
47 | unsigned int footerCertSize;
48 | unsigned char salt[0x20];
49 | unsigned short unk2;
50 | unsigned short epoch;
51 | unsigned char headerSignature[0x10];
52 | unsigned char padding[0x7B0];
53 | } Image8900Header;
54 |
55 | typedef struct ImageHeader {
56 | unsigned int signature;
57 | unsigned int fullSize;
58 | unsigned int dataSize;
59 | unsigned int shshOffset;
60 | unsigned int imageType;
61 | } ImageHeader;
62 |
63 | typedef struct ImageTagHeader {
64 | unsigned int signature;
65 | unsigned int fullSize;
66 | unsigned int dataSize;
67 | } ImageTagHeader;
68 |
69 | typedef struct ImageKbag {
70 | ImageTagHeader header;
71 | unsigned int state;
72 | unsigned int type;
73 | unsigned char iv[16];
74 | unsigned char key[32];
75 | } ImageKbag;
76 |
77 | typedef struct ImageComp {
78 | unsigned int signature;
79 | unsigned int compressionType;
80 | unsigned int checksum;
81 | unsigned int uncompressedSize;
82 | unsigned int compressedSize;
83 | unsigned char padding[0x16C];
84 | } ImageComp;
85 |
86 | typedef struct ImageDescriptor ImageDescriptor;
87 | typedef struct ImageInfo {
88 | int dataSize;
89 | int imageSize;
90 | int imageIdentifier;
91 | int imageType;
92 | int unk2;
93 | ImageDescriptor* current;
94 | } ImageInfo;
95 |
96 | struct ImageDescriptor {
97 | LinkedList list;
98 | struct BdevDescriptor* device;
99 | unsigned int startAddress;
100 | int unk1;
101 | ImageInfo info;
102 | };
103 |
104 | extern LinkedList* gImageList;
105 |
106 | int image_init();
107 | int image_cmd(int argc, CmdArg* argv);
108 | void image_display_list();
109 | int image_decrypt(void* image);
110 | ImageDescriptor* image_find(unsigned int signature);
111 | void* image_find_tag(void* image, unsigned int tag, unsigned int size);
112 | int image_load(unsigned int signature, void* dataout, unsigned int maxsize);
113 |
114 | #endif
115 |
--------------------------------------------------------------------------------
/include/kernel.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - kernel.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef KERNEL_H
21 | #define KERNEL_H
22 |
23 | #include "common.h"
24 | #include "device.h"
25 | #include "offsets.h"
26 | #include "commands.h"
27 |
28 | #ifdef TARGET_KERNEL_PHYMEM
29 | # define SELF_KERNEL_PHYMEM ((void*)(TARGET_BASEADDR + TARGET_KERNEL_PHYMEM))
30 | #endif
31 |
32 | #ifndef SELF_KERNEL_PHYMEM
33 | # define SELF_KERNEL_PHYMEM 0
34 | #endif
35 |
36 | extern char* gBootArgs;
37 | extern char** gKernelPhyMem;
38 | extern int(*kernel_atv_load)(char* boot_path, char** output);
39 | extern int(*kernel_load)(void* input, int max_size, char** output);
40 |
41 | int kernel_init();
42 | int kernel_cmd(int argc, CmdArg* argv);
43 | int kernel_patch(void* address);
44 |
45 | #endif /* KERNEL_H */
46 |
--------------------------------------------------------------------------------
/include/lock.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - lock.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef LOCK_H
21 | #define LOCK_H
22 |
23 | void enter_critical_section();
24 | void exit_critical_section();
25 |
26 | void enable_irq();
27 | void disable_irq();
28 |
29 | #endif /* LOCK_H */
30 |
31 |
--------------------------------------------------------------------------------
/include/memory.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - memory.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef MEMORY_H
21 | #define MEMORY_H
22 |
23 | #include "common.h"
24 | #include "commands.h"
25 |
26 | int memory_init();
27 | int memory_cmd(int argc, CmdArg* argv);
28 |
29 | int memory_search(char* source, unsigned int size, char* bytes);
30 |
31 | #endif /* LOCK_H */
32 |
33 |
--------------------------------------------------------------------------------
/include/nvram.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - nvram.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef NVRAM_H
21 | #define NVRAM_H
22 |
23 | #include "common.h"
24 | #include "device.h"
25 | #include "offsets.h"
26 | #include "commands.h"
27 |
28 | typedef struct NvramVar {
29 | struct NvramVar* prev;
30 | struct NvramVar* next;
31 | unsigned char* string;
32 | unsigned int integer;
33 | unsigned int save;
34 | char name[0x40];
35 | } NvramVar;
36 |
37 | extern LinkedList* gNvramList;
38 |
39 | int nvram_init();
40 | int nvram_cmd(int argc, CmdArg* argv);
41 | void nvram_display_list();
42 | int nvram_get_var(const char* name);
43 | int nvram_remove_var(const char* name);
44 | NvramVar* nvram_find_var(const char* name);
45 | int nvram_set_var(const char* name, const char* value);
46 |
47 |
48 | #endif /* NVRAM_H */
49 |
--------------------------------------------------------------------------------
/include/patch.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - patch.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef PATCH_H
21 | #define PATCH_H
22 |
23 | #include "common.h"
24 | #include "commands.h"
25 | #include "device.h"
26 | #include "offsets.h"
27 |
28 | int patch_init();
29 | int patch_cmd(int argc, CmdArg* argv);
30 | int patch_kernel(unsigned char* address, unsigned int size);
31 | int patch_firmware(unsigned char* address, int size);
32 | unsigned char* patch_find(unsigned char* start, int length, unsigned char* find, int size);
33 |
34 | #endif /* TASK_H */
35 |
--------------------------------------------------------------------------------
/include/radio.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - radio.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef RADIO_H
21 | #define RADIO_H
22 |
23 | #include "common.h"
24 | #include "commands.h"
25 |
26 | int radio_init();
27 | int radio_cmd(int argc, CmdArg* argv);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/include/task.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - task.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef TASK_H
21 | #define TASK_H
22 |
23 | #include "common.h"
24 | #include "device.h"
25 | #include "offsets.h"
26 | #include "commands.h"
27 |
28 | #ifdef TARGET_TASK_RUNNING
29 | # define SELF_TASK_RUNNING ((TaskDescriptor**)(TARGET_BASEADDR + TARGET_TASK_RUNNING))
30 | #endif
31 | #ifdef TARGET_TASK_LIST
32 | # define SELF_TASK_LIST ((LinkedList*)(TARGET_BASEADDR + TARGET_TASK_LIST))
33 | #endif
34 |
35 | #ifndef SELF_TASK_RUNNING
36 | # define SELF_TASK_RUNNING 0
37 | #endif
38 |
39 | #ifndef SELF_TASK_LIST
40 | # define SELF_TASK_LIST 0
41 | #endif
42 |
43 | #define TaskDescriptorIdentifier1 0x7461736b // 'task'
44 | #define TaskDescriptorIdentifier2 0x74736b32 // 'tsk2'
45 |
46 | typedef struct Event Event;
47 |
48 | typedef void (*TaskRoutineFunction)(void* opaque);
49 | typedef void (*EventHandler)(Event* event, void* opaque);
50 |
51 | typedef struct TaskRegisterState {
52 | unsigned int r4;
53 | unsigned int r5;
54 | unsigned int r6;
55 | unsigned int r7;
56 | unsigned int r8;
57 | unsigned int r9;
58 | unsigned int r10;
59 | unsigned int r11;
60 | unsigned int sp;
61 | unsigned int lr;
62 | } TaskRegisterState;
63 |
64 | typedef enum TaskState {
65 | TASK_READY = 1,
66 | TASK_RUNNING = 2,
67 | TASK_IDLE = 3,
68 | TASK_SLEEPING = 4,
69 | TASK_STOPPED = 5
70 | } TaskState;
71 |
72 | struct Event {
73 | LinkedList list;
74 | unsigned long long deadline;
75 | unsigned long long interval;
76 | EventHandler handler;
77 | void* opaque;
78 | };
79 |
80 | typedef struct TaskDescriptor {
81 | unsigned int identifier1;
82 | LinkedList taskList;
83 | LinkedList runqueueList;
84 | TaskState state;
85 | unsigned int criticalSectionNestCount;
86 | TaskRegisterState savedRegisters;
87 | Event sleepEvent;
88 | LinkedList linked_list_3;
89 | unsigned int exitState;
90 | TaskRoutineFunction taskRoutine;
91 | void* unknown_passed_value;
92 | void* storage;
93 | unsigned int storageSize;
94 | char taskName[16];
95 | unsigned int identifier2;
96 | } TaskDescriptor;
97 |
98 | typedef void(*Task)(void* arg);
99 |
100 | extern LinkedList* gTaskList;
101 | extern TaskDescriptor** gTaskRunning;
102 | //extern unsigned int* gTaskCount;
103 | extern void(*task_yield)(void);
104 | extern TaskDescriptor*(*task_create)(char* name, Task task, void* arg, unsigned int stack);
105 | extern void(*task_start)(TaskDescriptor* task);
106 |
107 | int task_init();
108 | int task_cmd(int argc, CmdArg* argv);
109 | void task_display_list();
110 | TaskDescriptor* task_find(const char* name);
111 | int task_display_info(const char* name);
112 | //void task_start(TaskDescriptor* task);
113 | //void task_exit(TaskDescriptor* task);
114 |
115 | #endif /* TASK_H */
116 |
--------------------------------------------------------------------------------
/include/uart.h:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - uart.h
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #ifndef UART_H
21 | #define UART_H
22 |
23 | #include "common.h"
24 | #include "commands.h"
25 |
26 | extern void(*uart_write)(int bus, char* buffer, int size);
27 | extern void(*uart_read)(int bus, char* buffer, int size1, int size2);
28 |
29 | int uart_init();
30 | int uart_cmd(int argc, CmdArg* argv);
31 | void uart_reader(void* arg);
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/kernel.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - kernel.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "lock.h"
25 | #include "image.h"
26 | #include "patch.h"
27 | #include "nvram.h"
28 | #include "kernel.h"
29 | #include "common.h"
30 | #include "commands.h"
31 | #include "functions.h"
32 | #include "filesystem.h"
33 |
34 | static char* gKernelAddr = NULL;
35 | char* gBootArgs = NULL;
36 | char** gKernelPhyMem = SELF_KERNEL_PHYMEM;
37 |
38 | int(*kernel_atv_load)(char* boot_path, char** output) = NULL;
39 | int(*kernel_load)(void* input, int max_size, char** output) = NULL;
40 |
41 | void* find_kernel_bootargs() {
42 | return find_string(TARGET_BASEADDR, TARGET_BASEADDR, 0x40000, "rd=md0");
43 | }
44 |
45 | void* find_kernel_load() {
46 | return find_function("kernel_load", TARGET_BASEADDR, TARGET_BASEADDR);
47 | }
48 |
49 | void* find_kernel_phymem() {
50 | return 0;
51 | }
52 |
53 | int kernel_init() {
54 | gBootArgs = find_kernel_bootargs();
55 | if(gBootArgs == NULL) {
56 | puts("Unable to find gBootArgs\n");
57 | } else {
58 | printf("Found gBootArgs at 0x%x\n", gBootArgs);
59 | }
60 | kernel_load = find_kernel_load();
61 | if(kernel_load == NULL) {
62 | puts("Unable to find kernel_load function\n");
63 | } else {
64 | printf("Found kernel_load at 0x%x\n", kernel_load);
65 | }
66 | cmd_add("kernel", &kernel_cmd, "operations for filesystem kernel");
67 | return 0;
68 | }
69 |
70 | int kernel_cmd(int argc, CmdArg* argv) {
71 | char* action = NULL;
72 | unsigned int size = 0;
73 | unsigned int* compressed = 0;
74 | unsigned char* address = NULL;
75 | if(argc < 2) {
76 | puts("usage: kernel [options]\n");
77 | puts(" load \t\tload filesystem kernel to address\n");
78 | puts(" patch \t\tpatches kernel at address in memory\n");
79 | puts(" bootargs \t\treplace current bootargs with another\n");
80 | puts(" boot \t\tboot a loaded kernel\n");
81 | return 0;
82 | }
83 |
84 | action = argv[1].string;
85 | size = argv[3].uinteger;
86 | address = (unsigned char*) argv[2].uinteger;
87 | if(!strcmp(action, "load")) {
88 | if(strstr((char*) (IBOOT_BASEADDR + 0x200), "k66ap")) {
89 | printf("Loading AppleTV kernelcache from %s\n", KERNEL_PATH);
90 | kernel_atv_load(KERNEL_PATH, &gKernelAddr);
91 | } else {
92 | printf("Loading kernelcache from 0x%x\n", address);
93 | kernel_load((void*) address, size, &gKernelAddr);
94 | }
95 | printf("kernelcache prepped at %p with phymem %p\n", gKernelAddr, *gKernelPhyMem);
96 | }
97 | else if(!strcmp(action, "patch")) {
98 | printf("patching kernel...\n");
99 | if(gKernelAddr) {
100 | patch_kernel(gKernelAddr, 0xC00000);
101 | }
102 | }
103 | else if(!strcmp(action, "bootargs")) {
104 | kernel_bootargs(argc, argv);
105 | }
106 | else if(!strcmp(action, "boot")) {
107 | if(gKernelAddr) {
108 | printf("booting kernel...\n");
109 | jump_to(3, gKernelAddr, *gKernelPhyMem);
110 | }
111 | }
112 | return 0;
113 | }
114 |
115 | int kernel_bootargs(int argc, CmdArg* argv) {
116 | if(gBootArgs == NULL) {
117 | puts("Unable to set kernel bootargs");
118 | return -1;
119 | }
120 |
121 | int i = 0;
122 | int size = strlen(gBootArgs);
123 | for(i = 2; i < argc; i++) {
124 | if(i == 2) {
125 | strncpy(gBootArgs, "", size);
126 | }
127 | if(i > 2) {
128 | strncat(gBootArgs, " ", size);
129 | }
130 | strncat(gBootArgs, argv[i].string, size);
131 | }
132 |
133 | return 0;
134 | }
135 |
136 | /*
137 | int kernel_load(void* dest, int max_size, int* size) {
138 | unsigned int* file_size = 0;
139 | void* image = (void*) 0x43000000;
140 | ImageHeader* header = (ImageHeader*) image;
141 |
142 | puts("Loading kernelcache image\n");
143 |
144 | // Mount disk and load kernelcache
145 | fs_mount("nand0a", "hfs", "/boot");
146 | fs_load_file(KERNEL_PATH, image, file_size);
147 |
148 | // Decrypt image
149 | image_decrypt(image);
150 |
151 | // Find start of (actual) data
152 | unsigned char* data = image_find_tag(image, IMAGE_DATA, header->fullSize);
153 | data += sizeof(ImageTagHeader);
154 |
155 | // Assume data starts with a complzss header
156 | ImageComp* comp = (ImageComp*)data;
157 | FLIPENDIAN(comp->signature);
158 | FLIPENDIAN(comp->compressionType);
159 | FLIPENDIAN(comp->compressedSize);
160 | FLIPENDIAN(comp->uncompressedSize);
161 |
162 | if(comp->signature != IMAGE_COMP || comp->compressionType != IMAGE_LZSS) {
163 | puts("Didn't find expected COMPLZSS header\n");
164 | fs_unmount("/boot");
165 | return;
166 | }
167 |
168 | enter_critical_section();
169 | printf("LZSS compressed: %d uncompressed: %d\n", comp->compressedSize, comp->uncompressedSize);
170 | exit_critical_section();
171 |
172 | char *lzss_data = ((char *)(comp) + sizeof(ImageComp));
173 | int len = lzss_decompress(dest, comp->uncompressedSize, lzss_data, comp->compressedSize);
174 |
175 | enter_critical_section();
176 | printf("Actually uncompressed: %d\n", len);
177 | exit_critical_section();
178 | fs_unmount("/boot");
179 |
180 | puts("Finished loading kernelcache\n");
181 | *size = len;
182 | return 0;
183 | }
184 | */
185 |
186 | int kernel_patch(void* address) {
187 | printf("Not implemented yet\n");
188 | return 0;
189 | }
190 |
191 |
--------------------------------------------------------------------------------
/lock.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - lock.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "task.h"
25 | #include "lock.h"
26 | #include "common.h"
27 |
28 | void enter_critical_section() {
29 | return;
30 | TaskDescriptor* current_task = *gTaskRunning;
31 | if(current_task->criticalSectionNestCount < 0
32 | || current_task->criticalSectionNestCount > 1000) {
33 | panic("enter_critical_section: error\n");
34 | }
35 |
36 | current_task->criticalSectionNestCount++;
37 | if(current_task->criticalSectionNestCount == 1) {
38 | disable_irq();
39 | }
40 | }
41 |
42 | void exit_critical_section() {
43 | return;
44 | TaskDescriptor* current_task = *gTaskRunning;
45 | if(current_task->criticalSectionNestCount < 0
46 | || current_task->criticalSectionNestCount > 1000) {
47 | panic("exit_critical_section: error\n");
48 | }
49 |
50 | current_task->criticalSectionNestCount--;
51 | if(current_task->criticalSectionNestCount == 0) {
52 | enable_irq();
53 | }
54 | }
55 |
56 | void enable_irq() {
57 | __asm__("mrs r0, cpsr");
58 | __asm__("bic r1, r0, #0x80");
59 | __asm__("msr cpsr_c, r1");
60 | __asm__("and r0, r0, #0x80");
61 | }
62 |
63 | void disable_irq() {
64 | __asm__("mrs r0, cpsr");
65 | __asm__("orr r1, r0, #0x80");
66 | __asm__("msr cpsr_c, R1");
67 | __asm__("and r0, r0, #0x80");
68 | }
69 |
--------------------------------------------------------------------------------
/main.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - main.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "aes.h"
25 | #include "bdev.h"
26 | #include "radio.h"
27 | #include "nvram.h"
28 | #include "image.h"
29 | #include "patch.h"
30 | #include "memory.h"
31 | #include "kernel.h"
32 | #include "common.h"
33 | #include "commands.h"
34 | #include "filesystem.h"
35 | #include "framebuffer.h"
36 |
37 | Bool gGpHasInit = FALSE;
38 |
39 | int gp_init() {
40 | if(common_init()) return -1;
41 | if(cmd_init()) return -1;
42 | if(fb_init()) return -1;
43 | if(uart_init()) return -1;
44 | if(radio_init()) return -1;
45 | if(patch_init()) return -1;
46 | if(memory_init()) return -1;
47 | if(task_init()) return -1;
48 | if(aes_init()) return -1;
49 | if(bdev_init()) return -1;
50 | if(image_init()) return -1;
51 | if(nvram_init()) return -1;
52 | if(fs_init()) return -1;
53 | if(kernel_init()) return -1;
54 |
55 | gGpHasInit = TRUE;
56 | return 0;
57 | }
58 |
59 | int main(int argc, CmdArg* argv) {
60 | int i = 0;
61 | char result[0x10];
62 | if(!gGpHasInit || gCmdCount == 0) {
63 | if(gp_init()) {
64 | puts("Unable to initialize greenpois0n!!\n");
65 | return -1;
66 | }
67 | puts("Greenpois0n initialized\n");
68 | return 0;
69 | }
70 |
71 | for(i = 1; i < argc; i++) {
72 | if(!strcmp(argv[i].string, "$_")) {
73 | NvramVar* retval = nvram_find_var("?");
74 | argv[i].string = retval->string;
75 | continue;
76 | }
77 | if(argv[i].string[0] == '$') {
78 | NvramVar* var = nvram_find_var(&(argv[i].string[1]));
79 | if(var == NULL) {
80 | printf("Unable to find nvram var for %s\n", &(argv[i].string[1]));
81 | } else {
82 | argv[i].string = var->string;
83 | }
84 | }
85 | }
86 |
87 | if(argc > 1) {
88 | int i = 0;
89 | char* command = argv[1].string;
90 | for(i = 0; i < gCmdCount; i++) {
91 | if(!strcmp(gCmdCommands[i]->name, command)) {
92 | int ret = gCmdCommands[i]->handler(argc-1, &argv[1]);
93 | snprintf(result, 0xF, "0x%x", ret);
94 | nvram_set_var("cmd-results", result);
95 | return ret;
96 | }
97 | }
98 |
99 | printf("Command %s not found.\n\n", command);
100 | return -1;
101 | }
102 |
103 | return 0;
104 | }
105 |
106 |
--------------------------------------------------------------------------------
/malloc.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - malloc.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 |
21 | #include "heap.h"
22 |
23 | void* malloc(uint32_t size) {
24 | unsigned int zone;
25 | unsigned int min_size;
26 | chunk_header_t** header;
27 | chunk_header_t* candidate;
28 | chunk_header_t* next_chunk;
29 |
30 | enter_critical_section();
31 | min_size = get_min_alloc(size);
32 |
33 | zone = get_zone(min_size);
34 |
35 | header = &gHeapHeader[zone];
36 |
37 | NEXT:
38 | if(zone <= 0x1F) {
39 | for(candidate = *header; ; candidate = candidate->next) {
40 | if(!candidate) {
41 | zone++;
42 | header++;
43 | goto NEXT;
44 | }
45 |
46 | if(min_size <= (8 * candidate->size)) {
47 | break;
48 | }
49 | }
50 | *candidate->head = candidate->next;
51 | next_chunk = candidate->next;
52 | if(next_chunk) {
53 | next_chunk->head = candidate->head;
54 | }
55 | link_chunk(candidate, min_size);
56 | gHeapRemaining -= candidate->size * 8;
57 | exit_critical_section();
58 | } else {
59 | return 0;
60 | }
61 |
62 | return (void*) candidate + 8;
63 | }
64 |
65 | void link_chunk(chunk_header_t* chunk, unsigned int size) {
66 | chunk_header_t* next;
67 | chunk_header_t* last;
68 | chunk_header_t** header;
69 |
70 | if(chunk->size * 8 < size + 16) {
71 | next = _get_next_chunk(chunk);
72 | chunk->prev_size &= 0xFDu;
73 |
74 | } else {
75 | next = (void*) chunk + size;
76 | last = _get_next_chunk(chunk);
77 |
78 | next->prev_size = (next->prev_size & 0xFD) | 1;
79 | next->prev_size = (next->prev_size & 3) | (4 * (size / 8));
80 | next->size = chunk->size - ((size / 8) & 0x3FFFFFFF);
81 |
82 | chunk->size = size / 8;
83 | last->prev_size = (last->prev_size & 3) | (4 * next->size);
84 |
85 | header = &gHeapHeader[_get_zone(next->size * 8)];
86 | next->head = header;
87 | next->next = *header;
88 |
89 | if(*header) {
90 | (*header)->head = &next->next;
91 | }
92 | *header = next;
93 | }
94 |
95 | chunk->prev_size &= 0xFEu;
96 | }
97 |
98 |
--------------------------------------------------------------------------------
/memory.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - memory.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "lock.h"
25 | #include "memory.h"
26 | #include "common.h"
27 | #include "commands.h"
28 |
29 | int memory_init() {
30 | //printf("Initializing memory\n");
31 | cmd_add("memory", &memory_cmd, "display, search, and manipulate memory");
32 | return 0;
33 | }
34 |
35 | int memory_cmd(int argc, CmdArg* argv) {
36 | char* bytes = NULL;
37 | char* action = NULL;
38 | char* source = NULL;
39 | char* destination = NULL;
40 | unsigned int size = 0;
41 |
42 | if(argc < 4) {
43 | puts("usage: memory [options]\n");
44 | puts(" search \tfind address of specified byte sequence\n");
45 | puts(" dump \tdump memory from address over usb\n");
46 | puts(" copy \tcopy memory from one address to another\n");
47 | puts(" move \tmove memory from one address to another\n");
48 | return 0;
49 | }
50 |
51 | action = argv[1].string;
52 | if(argc == 5) {
53 | if(!strcmp(action, "search")) {
54 | bytes = argv[4].string;
55 | size = argv[3].uinteger;
56 | source = (void*) argv[2].uinteger;
57 | return memory_search(source, size, bytes);
58 | }
59 | }
60 |
61 | if(argc == 4) {
62 | if(!strcmp(action, "dump")) {
63 | printf("Not implemented yet\n");
64 | return 0;
65 | }
66 | }
67 |
68 | if(argc == 5) {
69 | if(!strcmp(action, "copy")) {
70 | size = argv[4].uinteger;
71 | source = (char*) argv[2].uinteger;
72 | destination = (char*) argv[3].uinteger;
73 | return memcpy(destination, source, size);
74 | }
75 | }
76 |
77 | if(argc == 5) {
78 | if(!strcmp(action, "move")) {
79 | size = argv[4].uinteger;
80 | source = (char*) argv[2].uinteger;
81 | destination = (char*) argv[3].uinteger;
82 | return memmove(destination, source, size);
83 | }
84 | }
85 |
86 | return 0;
87 | }
88 |
89 | int memory_search(char* source, unsigned int size, char* bytes) {
90 | int i = 0;
91 | char buffer[64];
92 | unsigned int byte = 0;
93 |
94 | int length = strlen(bytes) / 2;
95 | if(length <= 0 || length >= 64) {
96 | printf("byte sequence is too long\n");
97 | return -1;
98 | }
99 |
100 | memset(buffer, '\0', 64);
101 | for(i = 0; i < length; i++) {
102 | sscanf(bytes, "%02x", &byte);
103 | buffer[i] = byte;
104 | bytes += 2;
105 | }
106 |
107 | for(i = 0; i < size; i++) {
108 | if(!memcmp(&source[i], buffer, length)) {
109 | printf("Found byte sequence at 0x%x\n", &source[i]);
110 | return (int) &source[i];
111 | }
112 | }
113 |
114 | printf("unable to find byte sequence\n");
115 | return -1;
116 | }
117 |
--------------------------------------------------------------------------------
/nvram.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - nvram.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 |
23 | #include "lock.h"
24 | #include "nvram.h"
25 | #include "common.h"
26 |
27 | LinkedList* gNvramList = NULL;
28 |
29 | void* find_nvram_list() {
30 | unsigned int ref1 = find_string(TARGET_BASEADDR, TARGET_BASEADDR, 0x40000, "build-style");
31 | unsigned int* ref2 = find_string(ref1+4, ref1+4, 0x40000, "build-style");
32 | ref2 -= 5;
33 | return *ref2;
34 | }
35 |
36 | int nvram_init() {
37 | gNvramList = find_nvram_list();
38 | if(gNvramList == NULL) {
39 | puts("Unable to find gNvramList\n");
40 | } else {
41 | printf("Found gNvramList at 0x%x\n", gNvramList);
42 | cmd_add("nvram", &nvram_cmd, "view and modify nvram variables");
43 | }
44 | return 0;
45 | }
46 |
47 | int nvram_cmd(int argc, CmdArg* argv) {
48 | char* var = NULL;
49 | char* value = NULL;
50 | char* action = NULL;
51 | if(argc < 2) {
52 | puts("usage: nvram [options]\n");
53 | puts(" list \t\tdisplay list of nvram variables\n");
54 | puts(" remove \t\tdeletes entry from nvram variables\n");
55 | puts(" get \t\tshow contents of nvram variable\n");
56 | puts(" set \t\tset contents of nvram variable\n\n");
57 | return 0;
58 | }
59 |
60 | action = argv[1].string;
61 | if(argc == 2) {
62 | if(!strcmp(action, "list")) {
63 | nvram_display_list();
64 | return 0;
65 | }
66 |
67 | } else if(argc == 3) {
68 | if(!strcmp(action, "get")) {
69 | var = argv[2].string;
70 | return nvram_get_var(var);
71 |
72 | } else if(!strcmp(action, "remove")) {
73 | var = argv[2].string;
74 | return nvram_remove_var(var);
75 | }
76 |
77 | } else if(argc == 4) {
78 | if(!strcmp(action, "set")) {
79 | var = argv[2].string;
80 | value = argv[3].string;
81 | return nvram_set_var(var, value);
82 | }
83 | }
84 |
85 | return 0;
86 | }
87 |
88 | void nvram_display_list() {
89 | NvramVar* var = (NvramVar*) gNvramList->next;
90 | enter_critical_section();
91 | while(var != (void*) gNvramList) {
92 | printf("0x%08x: %s = %s\n", var, var->name, var->string);
93 | var = var->next;
94 | }
95 | printf("\n");
96 | exit_critical_section();
97 | }
98 |
99 | int nvram_remove_var(const char* name) {
100 | NvramVar* var = nvram_find_var(name);
101 | if(var == NULL) {
102 | return -1;
103 | }
104 |
105 | NvramVar* next = var->next;
106 | NvramVar* prev = var->prev;
107 |
108 | next->prev = prev;
109 | prev->next = next;
110 |
111 | var->next = 0;
112 | var->prev = 0;
113 |
114 | free(var->string);
115 | free(var);
116 |
117 | return 0;
118 | }
119 |
120 | NvramVar* nvram_find_var(const char* name) {
121 | NvramVar* var = (NvramVar*) gNvramList->next;
122 | while(var != (void*) gNvramList) {
123 | if(!strcmp(name, var->name)) {
124 | return var;
125 | }
126 | var = (NvramVar*) var->next;
127 | }
128 | return NULL;
129 | }
130 |
131 | int nvram_get_var(const char* name) {
132 | enter_critical_section();
133 | NvramVar* var = nvram_find_var(name);
134 | if(var == NULL) {
135 | puts("unable to find nvram entry\n\n");
136 | exit_critical_section();
137 | return -1;
138 | }
139 |
140 | printf("%s = %s\n", var->name, var->string);
141 | exit_critical_section();
142 |
143 | return 0;
144 | }
145 |
146 | int nvram_set_var(const char* name, const char* value) {
147 | enter_critical_section();
148 | NvramVar* var = NULL;
149 | var = nvram_find_var(name);
150 | if(var != NULL) {
151 | nvram_remove_var(name);
152 | var = NULL;
153 | }
154 | NvramVar* next = (NvramVar*) gNvramList;
155 | NvramVar* prev = (NvramVar*) gNvramList->prev;
156 |
157 | var = malloc(sizeof(NvramVar));
158 | if(var == NULL) {
159 | exit_critical_section();
160 | return -1;
161 | }
162 |
163 | strncpy(var->name, name, 0x40);
164 | var->string = malloc(0x200);
165 | if(var->string == NULL) {
166 | free(var);
167 | exit_critical_section();
168 | return -1;
169 | }
170 |
171 | strncpy(var->string, value, 0x200);
172 | var->integer = strtoul(var->string, NULL, 0);
173 | var->save = 1;
174 |
175 | var->next = next;
176 | var->prev = prev;
177 |
178 | next->prev = var;
179 | prev->next = var;
180 |
181 | exit_critical_section();
182 | return 0;
183 | }
184 |
--------------------------------------------------------------------------------
/radio.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - radio.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "uart.h"
25 | #include "radio.h"
26 | #include "commands.h"
27 |
28 | static Bool gRadioReadInit = FALSE;
29 |
30 | int radio_init() {
31 | srand(1);
32 | if(uart_read && uart_write) {
33 | cmd_add("radio", &radio_cmd, "send AT commands to baseband radio");
34 | }
35 | return 0;
36 | }
37 |
38 | int radio_cmd(int argc, CmdArg* argv) {
39 | int i = 0;
40 | int ret = 0;
41 | char* data = NULL;
42 |
43 | if(gRadioReadInit == FALSE) {
44 | //TaskDescriptor* radio_reader_task = task_create("radio_reader", &radio_reader, 0, 0x2000);
45 | //task_start(radio_reader_task);
46 | gRadioReadInit = TRUE;
47 | }
48 |
49 | if(argc == 1) {
50 | radio_send_random();
51 | return 0;
52 | }
53 |
54 | data = malloc(0x100);
55 | memset(data, '\0', 0x100);
56 | for(i = 1; i < argc; i++) {
57 | if(i > 2) {
58 | strncat(data, " ", 0x100);
59 | }
60 | strncat(data, argv[i].string, 0x100);
61 | }
62 | ret = radio_write(data);
63 |
64 | free(data);
65 | return ret;
66 | }
67 |
68 | int radio_write(char* command) {
69 | int size = 0;
70 | char data[0x100];
71 | memset(data, '\0', 0x100);
72 | strncpy(data, command, 0x100);
73 | strncat(data, "\r", 0x100);
74 | size = strlen(data);
75 | uart_write(1, data, size);
76 | return size;
77 | }
78 |
79 | int radio_read(char* buffer, unsigned int size) {
80 | return size;
81 | }
82 |
83 | void radio_set_debug() {
84 | radio_write("at+cmee=1");
85 | radio_write("at+creg=1");
86 | }
87 |
88 | int radio_find_commands() {
89 | srand(1);
90 | int i = 0;
91 | char string[8];
92 | char command[32];
93 | memset(string, '\0', 8);
94 | while(1) {
95 | memset(command, '\0', 32);
96 | strcpy(command, "at+");
97 | for(i = 0; i < 4; i++) {
98 | string[0] = (char) (rand() % 26) + 0x61;
99 | strncat(command, string, 32);
100 | }
101 | strncat(command, "=?", 32);
102 | radio_write(command);
103 | //radio_read(response);
104 | }
105 | return 0;
106 | }
107 |
108 | int radio_send_random() {
109 | int i = 0;
110 | char string[8];
111 | char command[32];
112 | memset(string, '\0', 8);
113 | memset(command, '\0', 32);
114 | strcpy(command, "at+");
115 | for(i = 0; i < 4; i++) {
116 | string[0] = (char) (rand() % 26) + 0x61;
117 | strncat(command, string, 32);
118 | }
119 | strncat(command, "=?", 32);
120 | printf("Sending \"%s\"\n", command);
121 | radio_write(command);
122 | return 0;
123 | }
124 |
125 | void radio_reader(void* arg) {
126 | char byte;
127 | while(1) {
128 | uart_read(1, &byte, 1, 1);
129 | printf("%c", byte);
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/task.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - task.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #include "task.h"
25 | #include "lock.h"
26 | #include "common.h"
27 | #include "commands.h"
28 | #include "functions.h"
29 |
30 | LinkedList* gTaskList = SELF_TASK_LIST;
31 | TaskDescriptor** gTaskRunning = SELF_TASK_RUNNING;
32 | void(*task_yield)(void) = NULL;
33 | void(*task_start)(TaskDescriptor* task) = NULL;
34 | TaskDescriptor*(*task_create)(char* name, Task task, void* arg, unsigned int stack) = NULL;
35 |
36 | void* find_task_yield() {
37 | return find_function("task_yield", TARGET_BASEADDR, TARGET_BASEADDR);
38 | }
39 |
40 | void* find_task_running() {
41 | return 0;
42 | }
43 |
44 | void* find_task_list() {
45 | return 0;
46 | }
47 |
48 | void* find_task_create() {
49 | return find_function("task_create", TARGET_BASEADDR, TARGET_BASEADDR);
50 | }
51 |
52 | void* find_task_exit() {
53 | return find_function("task_exit", TARGET_BASEADDR, TARGET_BASEADDR);
54 | }
55 |
56 | void* find_task_start() {
57 | unsigned int x = patch_find(TARGET_BASEADDR, 0x40000, "\x90\xB5\x01\xAF\x43\x69\x04\x46", 8);
58 | return x+1;
59 | }
60 |
61 | int task_init() {
62 | task_yield = find_task_yield();
63 | if(task_yield == NULL) {
64 | puts("Unable to find task_yield\n");
65 | } else {
66 | printf("Found task_yield at 0x%x\n", task_yield);
67 | }
68 |
69 | //gTaskRunning = find_task_running();
70 | if(gTaskRunning == NULL) {
71 | puts("Unable to find gTaskRunning\n");
72 | } else {
73 | printf("Found gTaskRunning at 0x%x\n", gTaskRunning);
74 | }
75 |
76 | //gTaskList = find_task_list();
77 | if(gTaskList == NULL) {
78 | puts("Unable to find gTaskList\n");
79 | } else {
80 | printf("Found gTaskList at 0x%x\n", gTaskList);
81 | }
82 |
83 | task_create = find_task_create();
84 | if(task_create == NULL) {
85 | puts("Unable to find task_create\n");
86 | } else {
87 | printf("Found task_create at 0x%x\n", task_create);
88 | }
89 |
90 | task_start = find_task_start();
91 | if(task_start == NULL) {
92 | puts("Unable to find task_start\n");
93 | } else {
94 | printf("Found task_start at 0x%x\n", task_start);
95 | }
96 |
97 | if(task_yield && gTaskRunning && gTaskList) {
98 | cmd_add("task", &task_cmd, "view and change running tasks");
99 | }
100 |
101 | return 0;
102 | }
103 |
104 | int task_cmd(int argc, CmdArg* argv) {
105 | int i = 0;
106 | char* name = NULL;
107 | char* action = NULL;
108 | if(argc < 2) {
109 | puts("usage: task [options]\n");
110 | puts(" list \t\tdisplay list of active tasks\n");
111 | puts(" info \t\tdisplay info about task\n");
112 | puts(" create \t\tcreate a new task with name");
113 | puts(" start \t\tstart a existing task\n");
114 | return 0;
115 | }
116 |
117 | action = argv[1].string;
118 | if(!strcmp(action, "list")) {
119 | task_display_list();
120 | }
121 |
122 | if(argc >= 3) {
123 | name = malloc(0x10);
124 | memset(name, 0, 0x10);
125 | if(!strcmp(action, "info")) {
126 | for(i = 2; i < argc; i++) {
127 | if(i > 2) {
128 | strncat(name, " ", 0x10);
129 | }
130 | strncat(name, argv[i].string, 0x10);
131 | }
132 |
133 | task_display_info(name);
134 | } else
135 |
136 | if(!strcmp(action, "start")) {
137 | for(i = 2; i < argc; i++) {
138 | if(i > 2) {
139 | strncat(name, " ", 0x10);
140 | }
141 | strncat(name, argv[i].string, 0x10);
142 | }
143 |
144 | TaskDescriptor* task = task_find(name);
145 | if(task != NULL) {
146 | task_start(task);
147 | } else {
148 | puts("Cannot find task\n");
149 | }
150 | } else
151 |
152 | if(!strcmp(action, "exit")) {
153 | for(i = 2; i < argc; i++) {
154 | if(i > 2) {
155 | strncat(name, " ", 0x10);
156 | }
157 | strncat(name, argv[i].string, 0x10);
158 | }
159 |
160 | TaskDescriptor* task = task_find(name);
161 | if(task != NULL) {
162 | task_exit(task);
163 | } else {
164 | puts("Cannot find task\n");
165 | }
166 | }
167 |
168 | free(name);
169 | }
170 |
171 | return 0;
172 | }
173 |
174 | void task_display_list() {
175 | LinkedList* list = gTaskList->next;
176 |
177 | puts("Tasks:\n");
178 | while(list != gTaskList) {
179 | TaskDescriptor* task = (void*) list - 4;
180 |
181 | enter_critical_section();
182 | printf(" (0x%08x) %s", task, task->taskName);
183 | if(task == *gTaskRunning) printf("*");
184 | printf("\n");
185 | exit_critical_section();
186 |
187 | list = list->next;
188 | }
189 | puts("\n");
190 | }
191 |
192 | TaskDescriptor* task_find(const char* name) {
193 | LinkedList* list = gTaskList->next;
194 | while(list != gTaskList) {
195 | TaskDescriptor* task = (void*) list - 4;
196 | if(!strcmp(task->taskName, name)) {
197 | return task;
198 | }
199 | list = list->next;
200 | }
201 | return NULL;
202 | }
203 |
204 | int task_display_info(const char* name) {
205 | TaskDescriptor* task = task_find(name);
206 | if(task == NULL) {
207 | puts("Cannot find task\n");
208 | return -1;
209 | }
210 |
211 | enter_critical_section();
212 | printf("Found %s\n", task->taskName);
213 | printf(" identifier1 = 0x%08x\n", task->identifier1);
214 | printf(" taskList.prev = 0x%08x\n", task->taskList.prev);
215 | printf(" taskList.next = 0x%08x\n", task->taskList.next);
216 | printf(" runqueueList.prev = 0x%08x\n", task->runqueueList.prev);
217 | printf(" runqueueList.next = 0x%08x\n", task->runqueueList.next);
218 | printf(" state = %d\n", task->state);
219 | printf(" criticalSectionNestCount = %d\n", task->criticalSectionNestCount);
220 | printf(" registers.r4 = 0x%08x\n", task->savedRegisters.r4);
221 | printf(" registers.r5 = 0x%08x\n", task->savedRegisters.r5);
222 | printf(" registers.r6 = 0x%08x\n", task->savedRegisters.r6);
223 | printf(" registers.r7 = 0x%08x\n", task->savedRegisters.r7);
224 | printf(" registers.r8 = 0x%08x\n", task->savedRegisters.r8);
225 | printf(" registers.r9 = 0x%08x\n", task->savedRegisters.r9);
226 | printf(" registers.r10 = 0x%08x\n", task->savedRegisters.r10);
227 | printf(" registers.r11 = 0x%08x\n", task->savedRegisters.r11);
228 | printf(" registers.sp = 0x%08x\n", task->savedRegisters.sp);
229 | printf(" registers.lr = 0x%08x\n", task->savedRegisters.lr);
230 | printf(" exitState = 0x%08x\n", task->exitState);
231 | printf(" taskRoutine = 0x%08x\n", task->taskRoutine);
232 | printf(" unknown_passed_value = 0x%08x\n", task->unknown_passed_value);
233 | printf(" storage = 0x%x\n", task->storage);
234 | printf(" storageSize = 0x%08x\n", task->storageSize);
235 | printf(" taskName = %s\n", task->taskName);
236 | printf(" identifier2 = 0x%08x\n", task->identifier2);
237 | exit_critical_section();
238 | }
239 |
240 | /*
241 | void task_add_queue(TaskDescriptor* task) {
242 | printf("task_add_queue: Not implemented\n");
243 | }
244 |
245 | void task_start(TaskDescriptor* task) {
246 | printf("task_start: Not implemented\n");
247 | if(task->state == 0) {
248 | task->state = TASK_READY;
249 | enter_critical_section();
250 | task_add_queue(task);
251 | exit_critical_section();
252 | }
253 | }
254 | */
255 | void task_exit(TaskDescriptor* task) {
256 | printf("task_exit: Not implemented\n");
257 | }
258 |
259 |
--------------------------------------------------------------------------------
/tools/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY all: bin2c
2 |
3 |
4 | bin2c:
5 | gcc bin2c.c -o bin2c
6 |
7 | .PHONY clean:
8 | rm -f bin2c bin2c.o
9 |
--------------------------------------------------------------------------------
/tools/bin2c.c:
--------------------------------------------------------------------------------
1 | /*
2 | * bin2c: A Program to convert binary data into C source code
3 | * Copyright 2004 by Adrian Prantl
4 | *
5 | * This program is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 2 of the License, or
8 | * (at your option) any later version.
9 | *
10 | */
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | char* self = 0;
17 |
18 | void usage() {
19 | printf("Usage:\n%s input.bin output.h name\n\n", self);
20 | }
21 |
22 | void bail_out(const char* s1, const char* s2) {
23 | fprintf(stderr, "%s: FATAL ERROR:\n%s%s\n", self, s1, s2);
24 | exit(1);
25 | }
26 |
27 | int main(int argc, char** argv) {
28 | FILE *fi, *fo;
29 | int c, i;
30 |
31 | self = argv[0];
32 |
33 | if (argc != 4) {
34 | usage();
35 | return 0;
36 | }
37 |
38 | if ((fi = fopen(argv[1], "rb")) == 0)
39 | bail_out("Cannot open input file ", argv[1]);
40 |
41 | if ((fo = fopen(argv[2], "w")) == 0)
42 | bail_out("Cannot open output file ", argv[2]);
43 |
44 | if ((c = fgetc(fi)) != EOF) {
45 | fprintf(fo, "#ifndef %s_H\n", argv[3]);
46 | fprintf(fo, "#define %s_H\n\n", argv[3]);
47 | fprintf(fo, "const unsigned char %s[] = {\n", argv[3]);
48 | fprintf(fo, c < 16 ? " 0x%02x" : " 0x%02x", (unsigned char) c);
49 | }
50 |
51 | i = 1;
52 | while ((c = fgetc(fi)) != EOF) {
53 | if (i < 12)
54 | fprintf(fo, c < 16 ? ", 0x%02x" : ", 0x%02x", (unsigned char) c);
55 | else {
56 | fprintf(fo, c < 16 ? ",\n 0x%02x" : ",\n 0x%02x", (unsigned char) c);
57 | i = 0;
58 | }
59 | i++;
60 | }
61 | fprintf(fo, "\n};\n\n");
62 | fprintf(fo, "#endif\n");
63 |
64 | printf("converted %s\n", argv[1]);
65 |
66 | return 0;
67 | }
68 |
69 |
--------------------------------------------------------------------------------
/uart.c:
--------------------------------------------------------------------------------
1 | /**
2 | * GreenPois0n Cynanide - uart.c
3 | * Copyright (C) 2010 Chronic-Dev Team
4 | * Copyright (C) 2010 Joshua Hill
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program. If not, see .
18 | **/
19 |
20 | #include
21 | #include
22 |
23 | #include "uart.h"
24 | #include "task.h"
25 | #include "common.h"
26 | #include "commands.h"
27 | #include "functions.h"
28 |
29 | void(*uart_write)(int bus, char* buffer, int size) = NULL;
30 | void(*uart_read)(int bus, char* buffer, int size1, int size2) = NULL;
31 |
32 | void* find_uart_read() {
33 | return find_function("uart_read", TARGET_BASEADDR, TARGET_BASEADDR);
34 | }
35 |
36 | void* find_uart_write() {
37 | return find_function("uart_write", TARGET_BASEADDR, TARGET_BASEADDR);
38 | }
39 |
40 | int uart_init() {
41 | uart_read = find_uart_read();
42 | if(uart_read == NULL) {
43 | puts("Unable to find uart_read\n");
44 | } else {
45 | printf("Found uart_read at 0x%x\n", uart_read);
46 | }
47 |
48 | uart_write = find_uart_write();
49 | if(uart_write == NULL) {
50 | puts("Unable to find uart_write\n");
51 | } else {
52 | printf("Found uart_write at 0x%x\n", uart_write);
53 | }
54 |
55 | if(uart_read && uart_write) {
56 | cmd_add("uart", &uart_cmd, "read and write data to serial interfaces");
57 | }
58 |
59 | return 0;
60 | }
61 |
62 | int uart_cmd(int argc, CmdArg* argv) {
63 | int i = 0;
64 | int bus = 0;
65 | char* action = NULL;
66 | unsigned char* data = NULL;
67 | if(argc < 2) {
68 | puts("usage: uart [options]\n");
69 | puts(" read \t\tdisplay list of active tasks\n");
70 | puts(" write \t\tdisplay info about task\n");
71 | return 0;
72 | }
73 |
74 | bus = argv[2].uinteger;
75 | action = argv[1].string;
76 | if(!strcmp(action, "read")) {
77 | TaskDescriptor* uart_reader_task = task_create("bb_reader", &uart_reader, 0, 0x200);
78 | task_start(uart_reader_task);
79 |
80 | } else
81 | if(!strcmp(action, "write")) {
82 | data = malloc(0x100);
83 | memset(data, 0, 0x100);
84 | for(i = 3; i < argc; i++) {
85 | if(i > 2) {
86 | strncat(data, " ", 0x100);
87 | }
88 | strncat(data, argv[i].string, 0x100);
89 | }
90 | strncat(data, "\r\n", 0x100);
91 | uart_write(bus, data, strlen(data));
92 | }
93 |
94 | free(data);
95 |
96 | return 0;
97 | }
98 |
99 | void uart_reader(void* arg) {
100 | char byte;
101 | while(1) {
102 | uart_read(1, &byte, 1, 1);
103 | printf("%c", byte);
104 | }
105 | }
106 |
--------------------------------------------------------------------------------