SingingCat 0
application
loader-api.c
1#include "main-header.h"
2#include "loader-api.h"
3
4void *loaderapiptr;
5
6// were we started with an old loader with an API? (1 if so, 0 if not)
7int loader_has_api() {
8 if (loaderapiptr == NULL) {
9 return 0;
10 }
11 return 1;
12}
13void *get_function_offset(int num) {
14 if (loaderapiptr == NULL) {
15 printf("******** Loader callbacks deprecated for Function %i! ********** \r\n", num);
16 return NULL;
17 }
18
19 // keep this below, for old loaders. Especially important is the "set_latest_app" function.
20 // older loaders ignore partitions, so we need to keep this going for some time to come
21 // specifically - until we have no more old loaders
22 void *res;
23
24 void * (*ptr)(int num);
25
26 ptr = loaderapiptr;
27 res = ptr(num);
28 if (res == NULL) {
29 printf("******** Function %i not implemented in loader! ********** \r\n", num);
30 }
31 return res;
32}
33
34uint32_t loader_get_version() {
35 if (!loader_has_api()) {
36 // old: 0x80001D4;
37 //stage 2 loader
38 uint32_t *b = (uint32_t *)(0x08001000 + (4 * 3));
39 return *b;
40 }
41 uint32_t (*f)();
42 f = get_function_offset(11);
43 if (f == NULL) {
44 return 0; // very old loader w/o get_version api call (but with api)
45 }
46 return f();
47}
48void loader_set_last_function_ptr(void *n) {
49 void (*f)(void *n);
50 f = get_function_offset(17);
51 if (f == NULL) {
52 return;
53 }
54 f(n);
55}
56
57void *loader_get_last_function_ptr() {
58 void *(*f)();
59
60 f = get_function_offset(5);
61 if (f == NULL) {
62 return NULL;
63 }
64 return f();
65}
66
67int loader_get_last_reset_cause() {
68 int (*f)();
69 f = get_function_offset(18);
70 if (f == NULL) {
71 return 0;
72 }
73 return f();
74}
75
76
77long loader_get_user_long() {
78 return 0;
79}
80
81void loader_set_user_long(long l) {
82 void (*f)(long);
83 f = get_function_offset(10);
84 f(l);
85}
86
87void loader_set_quickstart(byte b) {
88 return;
89}
90void loader_set_update_node(long l) {
91 void (*f)(long);
92 f = get_function_offset(20);
93 if (f == NULL) {
94 return;
95 }
96 f(l);
97}
98void loader_set_update_host(const char *n) {
99 void (*f)(const char *n);
100 f = get_function_offset(21);
101 if (f == NULL) {
102 return;
103 }
104 f(n);
105}
106
107int loader_get_quickstart() {
108 return 0;
109}
110
111void loader_erase_config() {
112 void (*f)();
113 f = get_function_offset(13);
114 if (f == NULL) {
115 return;
116 }
117 f();
118}
119
120void *loader_get_app_base_address(int index) {
121 void *(*f)(int);
122
123 f = get_function_offset(3);
124 if (f != NULL) {
125 return f(index);
126 }
127 // if no loader available, emulate these 2 addressees (for flash code)
128 if (index == 0) {
129 return (void *)0x08009000;
130 } else if (index == 1) {
131 return (void *)0x08034800;
132 }
133 return NULL;
134}
135int loader_get_app_base_address_count() {
136 int (*f)();
137 f = get_function_offset(2);
138 if (f == NULL) {
139 // no loader? emulate 2 addresses (for flash code)
140 return 2;
141 }
142 return f();
143}
144
145int loader_set_latest_app(void *z) {
146 int (*f)(void *n);
147 f = get_function_offset(6);
148 if (f == NULL) {
149 return 0;
150 }
151 return f(z);
152}
153struct meta_header *loader_get_app_meta_address(int index) {
154 void * (*f)(int);
155
156 f = get_function_offset(8);
157 if (f == NULL) {
158 return NULL;
159 }
160 return f(index);
161}