Blame view

post/post.c 9.63 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
a042ac843   wdenk   Initial revision
2
3
4
  /*
   * (C) Copyright 2002
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
a042ac843   wdenk   Initial revision
5
6
7
   */
  
  #include <common.h>
3a7d55716   Simon Glass   env: Move env_get...
8
  #include <env.h>
336d4615f   Simon Glass   dm: core: Create ...
9
  #include <malloc.h>
52cb4d4fb   Jean-Christophe PLAGNIOL-VILLARD   stdio/device: rew...
10
  #include <stdio_dev.h>
1045315df   Simon Glass   common: Move get_...
11
  #include <time.h>
a042ac843   wdenk   Initial revision
12
  #include <watchdog.h>
c90a4dd79   Christian Riesch   post/post.c: Use ...
13
  #include <div64.h>
a042ac843   wdenk   Initial revision
14
  #include <post.h>
9146d1382   Mike Frysinger   post: add gpio ho...
15
16
17
  #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
  #include <asm/gpio.h>
  #endif
d87080b72   Wolfgang Denk   GCC-4.x fixes: cl...
18
  DECLARE_GLOBAL_DATA_PTR;
a042ac843   wdenk   Initial revision
19
20
21
  #define POST_MAX_NUMBER		32
  
  #define BOOTMODE_MAGIC	0xDEAD0000
e92372c8a   Heiko Schocher   cosmetic, post: C...
22
  int post_init_f(void)
4532cb696   wdenk   * LWMON extensions:
23
  {
4532cb696   wdenk   * LWMON extensions:
24
25
26
27
28
  	int res = 0;
  	unsigned int i;
  
  	for (i = 0; i < post_list_size; i++) {
  		struct post_test *test = post_list + i;
50da83766   Wolfgang Denk   post/post.c: Codi...
29
  		if (test->init_f && test->init_f())
4532cb696   wdenk   * LWMON extensions:
30
  			res = -1;
4532cb696   wdenk   * LWMON extensions:
31
  	}
8bde7f776   wdenk   * Code cleanup:
32

4532cb696   wdenk   * LWMON extensions:
33
34
  	gd->post_init_f_time = post_time_ms(0);
  	if (!gd->post_init_f_time)
e92372c8a   Heiko Schocher   cosmetic, post: C...
35
36
  		printf("%s: post_time_ms not implemented
  ", __FILE__);
4532cb696   wdenk   * LWMON extensions:
37
38
39
  
  	return res;
  }
39ff7d5f4   Stefan Roese   POST: Remove dupl...
40
41
42
43
44
45
46
47
  /*
   * Supply a default implementation for post_hotkeys_pressed() for boards
   * without hotkey support. We always return 0 here, so that the
   * long-running tests won't be started.
   *
   * Boards with hotkey support can override this weak default function
   * by defining one in their board specific code.
   */
002ad7b87   Jeroen Hofstee   misc: use __weak
48
  __weak int post_hotkeys_pressed(void)
39ff7d5f4   Stefan Roese   POST: Remove dupl...
49
  {
9146d1382   Mike Frysinger   post: add gpio ho...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
  	int ret;
  	unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO;
  
  	ret = gpio_request(gpio, "hotkeys");
  	if (ret) {
  		printf("POST: gpio hotkey request failed
  ");
  		return 0;
  	}
  
  	gpio_direction_input(gpio);
  	ret = gpio_get_value(gpio);
  	gpio_free(gpio);
  
  	return ret;
  #endif
39ff7d5f4   Stefan Roese   POST: Remove dupl...
67
68
  	return 0;	/* No hotkeys supported */
  }
39ff7d5f4   Stefan Roese   POST: Remove dupl...
69

e92372c8a   Heiko Schocher   cosmetic, post: C...
70
  void post_bootmode_init(void)
a042ac843   wdenk   Initial revision
71
  {
e92372c8a   Heiko Schocher   cosmetic, post: C...
72
  	int bootmode = post_bootmode_get(0);
27b207fd0   wdenk   * Implement new m...
73
  	int newword;
42d1f0394   wdenk   * Patches by Xian...
74

e92372c8a   Heiko Schocher   cosmetic, post: C...
75
  	if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
27b207fd0   wdenk   * Implement new m...
76
  		newword = BOOTMODE_MAGIC | POST_SLOWTEST;
e92372c8a   Heiko Schocher   cosmetic, post: C...
77
  	else if (bootmode == 0)
27b207fd0   wdenk   * Implement new m...
78
  		newword = BOOTMODE_MAGIC | POST_POWERON;
e92372c8a   Heiko Schocher   cosmetic, post: C...
79
  	else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
27b207fd0   wdenk   * Implement new m...
80
  		newword = BOOTMODE_MAGIC | POST_NORMAL;
e92372c8a   Heiko Schocher   cosmetic, post: C...
81
  	else
27b207fd0   wdenk   * Implement new m...
82
  		/* Use old value */
50da83766   Wolfgang Denk   post/post.c: Codi...
83
  		newword = post_word_load() & ~POST_COLDBOOT;
a042ac843   wdenk   Initial revision
84

27b207fd0   wdenk   * Implement new m...
85
  	if (bootmode == 0)
27b207fd0   wdenk   * Implement new m...
86
87
  		/* We are booting after power-on */
  		newword |= POST_COLDBOOT;
27b207fd0   wdenk   * Implement new m...
88

e92372c8a   Heiko Schocher   cosmetic, post: C...
89
  	post_word_store(newword);
27b207fd0   wdenk   * Implement new m...
90

228f29ac6   wdenk   * Improve log buf...
91
92
  	/* Reset activity record */
  	gd->post_log_word = 0;
79843950b   Valentin Longchamp   POST: add post_lo...
93
  	gd->post_log_res = 0;
a042ac843   wdenk   Initial revision
94
  }
e92372c8a   Heiko Schocher   cosmetic, post: C...
95
  int post_bootmode_get(unsigned int *last_test)
a042ac843   wdenk   Initial revision
96
  {
e92372c8a   Heiko Schocher   cosmetic, post: C...
97
  	unsigned long word = post_word_load();
a042ac843   wdenk   Initial revision
98
  	int bootmode;
e92372c8a   Heiko Schocher   cosmetic, post: C...
99
  	if ((word & 0xFFFF0000) != BOOTMODE_MAGIC)
a042ac843   wdenk   Initial revision
100
  		return 0;
a042ac843   wdenk   Initial revision
101

27b207fd0   wdenk   * Implement new m...
102
  	bootmode = word & 0x7F;
a042ac843   wdenk   Initial revision
103

e92372c8a   Heiko Schocher   cosmetic, post: C...
104
  	if (last_test && (bootmode & POST_POWERTEST))
a042ac843   wdenk   Initial revision
105
  		*last_test = (word >> 8) & 0xFF;
a042ac843   wdenk   Initial revision
106
107
108
  
  	return bootmode;
  }
228f29ac6   wdenk   * Improve log buf...
109
  /* POST tests run before relocation only mark status bits .... */
e92372c8a   Heiko Schocher   cosmetic, post: C...
110
  static void post_log_mark_start(unsigned long testid)
228f29ac6   wdenk   * Improve log buf...
111
  {
79843950b   Valentin Longchamp   POST: add post_lo...
112
  	gd->post_log_word |= testid;
228f29ac6   wdenk   * Improve log buf...
113
  }
e92372c8a   Heiko Schocher   cosmetic, post: C...
114
  static void post_log_mark_succ(unsigned long testid)
228f29ac6   wdenk   * Improve log buf...
115
  {
79843950b   Valentin Longchamp   POST: add post_lo...
116
  	gd->post_log_res |= testid;
228f29ac6   wdenk   * Improve log buf...
117
118
119
  }
  
  /* ... and the messages are output once we are relocated */
e92372c8a   Heiko Schocher   cosmetic, post: C...
120
  void post_output_backlog(void)
228f29ac6   wdenk   * Improve log buf...
121
  {
228f29ac6   wdenk   * Improve log buf...
122
123
124
  	int j;
  
  	for (j = 0; j < post_list_size; j++) {
79843950b   Valentin Longchamp   POST: add post_lo...
125
  		if (gd->post_log_word & (post_list[j].testid)) {
50da83766   Wolfgang Denk   post/post.c: Codi...
126
  			post_log("POST %s ", post_list[j].cmd);
79843950b   Valentin Longchamp   POST: add post_lo...
127
  			if (gd->post_log_res & post_list[j].testid)
50da83766   Wolfgang Denk   post/post.c: Codi...
128
129
  				post_log("PASSED
  ");
63e73c9a8   wdenk   * Patches by Rein...
130
  			else {
e92372c8a   Heiko Schocher   cosmetic, post: C...
131
132
  				post_log("FAILED
  ");
770605e4f   Simon Glass   bootstage: Replac...
133
  				bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
63e73c9a8   wdenk   * Patches by Rein...
134
  			}
228f29ac6   wdenk   * Improve log buf...
135
136
137
  		}
  	}
  }
e92372c8a   Heiko Schocher   cosmetic, post: C...
138
  static void post_bootmode_test_on(unsigned int last_test)
a042ac843   wdenk   Initial revision
139
  {
e92372c8a   Heiko Schocher   cosmetic, post: C...
140
  	unsigned long word = post_word_load();
a042ac843   wdenk   Initial revision
141
142
143
144
  
  	word |= POST_POWERTEST;
  
  	word |= (last_test & 0xFF) << 8;
e92372c8a   Heiko Schocher   cosmetic, post: C...
145
  	post_word_store(word);
a042ac843   wdenk   Initial revision
146
  }
e92372c8a   Heiko Schocher   cosmetic, post: C...
147
  static void post_bootmode_test_off(void)
a042ac843   wdenk   Initial revision
148
  {
e92372c8a   Heiko Schocher   cosmetic, post: C...
149
  	unsigned long word = post_word_load();
a042ac843   wdenk   Initial revision
150
151
  
  	word &= ~POST_POWERTEST;
e92372c8a   Heiko Schocher   cosmetic, post: C...
152
  	post_word_store(word);
a042ac843   wdenk   Initial revision
153
  }
212a0cafa   Valentin Longchamp   POST: make env te...
154
155
  #ifndef CONFIG_POST_SKIP_ENV_FLAGS
  static void post_get_env_flags(int *test_flags)
a042ac843   wdenk   Initial revision
156
  {
e262efe35   Yuri Tikhonov   The patch introdu...
157
158
159
160
  	int  flag[] = {  POST_POWERON,   POST_NORMAL,   POST_SLOWTEST,
  			 POST_CRITICAL };
  	char *var[] = { "post_poweron", "post_normal", "post_slowtest",
  			"post_critical" };
d2397817f   Mike Frysinger   post: use ARRAY_SIZE
161
  	int varnum = ARRAY_SIZE(var);
a042ac843   wdenk   Initial revision
162
163
164
165
166
  	char list[128];			/* long enough for POST list */
  	char *name;
  	char *s;
  	int last;
  	int i, j;
a042ac843   wdenk   Initial revision
167
  	for (i = 0; i < varnum; i++) {
00caae6d4   Simon Glass   env: Rename geten...
168
  		if (env_get_f(var[i], list, sizeof(list)) <= 0)
a042ac843   wdenk   Initial revision
169
  			continue;
50da83766   Wolfgang Denk   post/post.c: Codi...
170
  		for (j = 0; j < post_list_size; j++)
a042ac843   wdenk   Initial revision
171
  			test_flags[j] &= ~flag[i];
a042ac843   wdenk   Initial revision
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
  
  		last = 0;
  		name = list;
  		while (!last) {
  			while (*name && *name == ' ')
  				name++;
  			if (*name == 0)
  				break;
  			s = name + 1;
  			while (*s && *s != ' ')
  				s++;
  			if (*s == 0)
  				last = 1;
  			else
  				*s = 0;
  
  			for (j = 0; j < post_list_size; j++) {
50da83766   Wolfgang Denk   post/post.c: Codi...
189
  				if (strcmp(post_list[j].cmd, name) == 0) {
a042ac843   wdenk   Initial revision
190
191
192
193
  					test_flags[j] |= flag[i];
  					break;
  				}
  			}
e92372c8a   Heiko Schocher   cosmetic, post: C...
194
  			if (j == post_list_size)
50da83766   Wolfgang Denk   post/post.c: Codi...
195
196
  				printf("No such test: %s
  ", name);
a042ac843   wdenk   Initial revision
197
198
199
200
  
  			name = s + 1;
  		}
  	}
212a0cafa   Valentin Longchamp   POST: make env te...
201
202
203
204
205
206
207
208
209
210
211
212
213
  }
  #endif
  
  static void post_get_flags(int *test_flags)
  {
  	int j;
  
  	for (j = 0; j < post_list_size; j++)
  		test_flags[j] = post_list[j].flags;
  
  #ifndef CONFIG_POST_SKIP_ENV_FLAGS
  	post_get_env_flags(test_flags);
  #endif
6dff55297   wdenk   * Patches by Mart...
214

e92372c8a   Heiko Schocher   cosmetic, post: C...
215
216
  	for (j = 0; j < post_list_size; j++)
  		if (test_flags[j] & POST_POWERON)
6dff55297   wdenk   * Patches by Mart...
217
  			test_flags[j] |= POST_SLOWTEST;
a042ac843   wdenk   Initial revision
218
  }
002ad7b87   Jeroen Hofstee   misc: use __weak
219
  __weak void show_post_progress(unsigned int test_num, int before, int result)
e070a56c7   Michael Zaidman   POST: add progres...
220
221
  {
  }
e070a56c7   Michael Zaidman   POST: add progres...
222

e92372c8a   Heiko Schocher   cosmetic, post: C...
223
  static int post_run_single(struct post_test *test,
a042ac843   wdenk   Initial revision
224
225
226
227
  				int test_flags, int flags, unsigned int i)
  {
  	if ((flags & test_flags & POST_ALWAYS) &&
  		(flags & test_flags & POST_MEM)) {
50da83766   Wolfgang Denk   post/post.c: Codi...
228
  		WATCHDOG_RESET();
a042ac843   wdenk   Initial revision
229
230
  
  		if (!(flags & POST_REBOOT)) {
e92372c8a   Heiko Schocher   cosmetic, post: C...
231
232
233
  			if ((test_flags & POST_REBOOT) &&
  				!(flags & POST_MANUAL)) {
  				post_bootmode_test_on(
e262efe35   Yuri Tikhonov   The patch introdu...
234
235
  					(gd->flags & GD_FLG_POSTFAIL) ?
  						POST_FAIL_SAVE | i : i);
a042ac843   wdenk   Initial revision
236
  			}
228f29ac6   wdenk   * Improve log buf...
237
  			if (test_flags & POST_PREREL)
e92372c8a   Heiko Schocher   cosmetic, post: C...
238
  				post_log_mark_start(test->testid);
228f29ac6   wdenk   * Improve log buf...
239
  			else
e92372c8a   Heiko Schocher   cosmetic, post: C...
240
  				post_log("POST %s ", test->cmd);
a042ac843   wdenk   Initial revision
241
  		}
e070a56c7   Michael Zaidman   POST: add progres...
242
  		show_post_progress(i, POST_BEFORE, POST_FAILED);
228f29ac6   wdenk   * Improve log buf...
243
  		if (test_flags & POST_PREREL) {
50da83766   Wolfgang Denk   post/post.c: Codi...
244
  			if ((*test->test)(flags) == 0) {
e92372c8a   Heiko Schocher   cosmetic, post: C...
245
  				post_log_mark_succ(test->testid);
e070a56c7   Michael Zaidman   POST: add progres...
246
  				show_post_progress(i, POST_AFTER, POST_PASSED);
50da83766   Wolfgang Denk   post/post.c: Codi...
247
  			} else {
e070a56c7   Michael Zaidman   POST: add progres...
248
  				show_post_progress(i, POST_AFTER, POST_FAILED);
28a385065   Yuri Tikhonov   POST: add POST_ST...
249
250
251
252
253
  				if (test_flags & POST_CRITICAL)
  					gd->flags |= GD_FLG_POSTFAIL;
  				if (test_flags & POST_STOP)
  					gd->flags |= GD_FLG_POSTSTOP;
  			}
228f29ac6   wdenk   * Improve log buf...
254
  		} else {
975afc34d   James Kosin   post: fix indenda...
255
256
257
  			if ((*test->test)(flags) != 0) {
  				post_log("FAILED
  ");
770605e4f   Simon Glass   bootstage: Replac...
258
  				bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
975afc34d   James Kosin   post: fix indenda...
259
260
261
262
263
264
265
266
267
268
  				show_post_progress(i, POST_AFTER, POST_FAILED);
  				if (test_flags & POST_CRITICAL)
  					gd->flags |= GD_FLG_POSTFAIL;
  				if (test_flags & POST_STOP)
  					gd->flags |= GD_FLG_POSTSTOP;
  			} else {
  				post_log("PASSED
  ");
  				show_post_progress(i, POST_AFTER, POST_PASSED);
  			}
228f29ac6   wdenk   * Improve log buf...
269
  		}
a042ac843   wdenk   Initial revision
270

50da83766   Wolfgang Denk   post/post.c: Codi...
271
  		if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
e92372c8a   Heiko Schocher   cosmetic, post: C...
272
  			post_bootmode_test_off();
a042ac843   wdenk   Initial revision
273
274
275
276
277
278
  
  		return 0;
  	} else {
  		return -1;
  	}
  }
50da83766   Wolfgang Denk   post/post.c: Codi...
279
  int post_run(char *name, int flags)
a042ac843   wdenk   Initial revision
280
281
282
  {
  	unsigned int i;
  	int test_flags[POST_MAX_NUMBER];
e92372c8a   Heiko Schocher   cosmetic, post: C...
283
  	post_get_flags(test_flags);
a042ac843   wdenk   Initial revision
284
285
286
  
  	if (name == NULL) {
  		unsigned int last;
28a385065   Yuri Tikhonov   POST: add POST_ST...
287
288
  		if (gd->flags & GD_FLG_POSTSTOP)
  			return 0;
e92372c8a   Heiko Schocher   cosmetic, post: C...
289
  		if (post_bootmode_get(&last) & POST_POWERTEST) {
e262efe35   Yuri Tikhonov   The patch introdu...
290
291
292
293
  			if (last & POST_FAIL_SAVE) {
  				last &= ~POST_FAIL_SAVE;
  				gd->flags |= GD_FLG_POSTFAIL;
  			}
a042ac843   wdenk   Initial revision
294
295
296
  			if (last < post_list_size &&
  				(flags & test_flags[last] & POST_ALWAYS) &&
  				(flags & test_flags[last] & POST_MEM)) {
e92372c8a   Heiko Schocher   cosmetic, post: C...
297
  				post_run_single(post_list + last,
ea909b760   wdenk   * Added support f...
298
299
  						 test_flags[last],
  						 flags | POST_REBOOT, last);
a042ac843   wdenk   Initial revision
300
301
  
  				for (i = last + 1; i < post_list_size; i++) {
28a385065   Yuri Tikhonov   POST: add POST_ST...
302
303
  					if (gd->flags & GD_FLG_POSTSTOP)
  						break;
e92372c8a   Heiko Schocher   cosmetic, post: C...
304
  					post_run_single(post_list + i,
ea909b760   wdenk   * Added support f...
305
306
  							 test_flags[i],
  							 flags, i);
a042ac843   wdenk   Initial revision
307
308
309
310
  				}
  			}
  		} else {
  			for (i = 0; i < post_list_size; i++) {
28a385065   Yuri Tikhonov   POST: add POST_ST...
311
312
  				if (gd->flags & GD_FLG_POSTSTOP)
  					break;
e92372c8a   Heiko Schocher   cosmetic, post: C...
313
  				post_run_single(post_list + i,
ea909b760   wdenk   * Added support f...
314
315
  						 test_flags[i],
  						 flags, i);
a042ac843   wdenk   Initial revision
316
317
318
319
320
321
  			}
  		}
  
  		return 0;
  	} else {
  		for (i = 0; i < post_list_size; i++) {
50da83766   Wolfgang Denk   post/post.c: Codi...
322
  			if (strcmp(post_list[i].cmd, name) == 0)
a042ac843   wdenk   Initial revision
323
324
325
326
  				break;
  		}
  
  		if (i < post_list_size) {
5744ddc66   Sascha Laue   Configure DSP POS...
327
  			WATCHDOG_RESET();
e92372c8a   Heiko Schocher   cosmetic, post: C...
328
  			return post_run_single(post_list + i,
a042ac843   wdenk   Initial revision
329
330
331
332
333
334
335
  						test_flags[i],
  						flags, i);
  		} else {
  			return -1;
  		}
  	}
  }
e92372c8a   Heiko Schocher   cosmetic, post: C...
336
  static int post_info_single(struct post_test *test, int full)
a042ac843   wdenk   Initial revision
337
338
339
  {
  	if (test->flags & POST_MANUAL) {
  		if (full)
e92372c8a   Heiko Schocher   cosmetic, post: C...
340
341
  			printf("%s - %s
  "
a042ac843   wdenk   Initial revision
342
343
344
  				"  %s
  ", test->cmd, test->name, test->desc);
  		else
e92372c8a   Heiko Schocher   cosmetic, post: C...
345
346
  			printf("  %-15s - %s
  ", test->cmd, test->name);
a042ac843   wdenk   Initial revision
347
348
349
350
351
352
  
  		return 0;
  	} else {
  		return -1;
  	}
  }
50da83766   Wolfgang Denk   post/post.c: Codi...
353
  int post_info(char *name)
a042ac843   wdenk   Initial revision
354
355
356
357
  {
  	unsigned int i;
  
  	if (name == NULL) {
e92372c8a   Heiko Schocher   cosmetic, post: C...
358
359
  		for (i = 0; i < post_list_size; i++)
  			post_info_single(post_list + i, 0);
a042ac843   wdenk   Initial revision
360
361
362
363
  
  		return 0;
  	} else {
  		for (i = 0; i < post_list_size; i++) {
50da83766   Wolfgang Denk   post/post.c: Codi...
364
  			if (strcmp(post_list[i].cmd, name) == 0)
a042ac843   wdenk   Initial revision
365
366
  				break;
  		}
50da83766   Wolfgang Denk   post/post.c: Codi...
367
  		if (i < post_list_size)
e92372c8a   Heiko Schocher   cosmetic, post: C...
368
  			return post_info_single(post_list + i, 1);
50da83766   Wolfgang Denk   post/post.c: Codi...
369
  		else
a042ac843   wdenk   Initial revision
370
  			return -1;
a042ac843   wdenk   Initial revision
371
372
  	}
  }
e92372c8a   Heiko Schocher   cosmetic, post: C...
373
  int post_log(char *format, ...)
a042ac843   wdenk   Initial revision
374
375
  {
  	va_list args;
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
376
  	char printbuffer[CONFIG_SYS_PBSIZE];
a042ac843   wdenk   Initial revision
377

50da83766   Wolfgang Denk   post/post.c: Codi...
378
  	va_start(args, format);
a042ac843   wdenk   Initial revision
379
380
381
382
  
  	/* For this to work, printbuffer must be larger than
  	 * anything we ever want to print.
  	 */
4d6402b01   Wolfgang Denk   post/post.c: fix ...
383
  	vsprintf(printbuffer, format, args);
50da83766   Wolfgang Denk   post/post.c: Codi...
384
  	va_end(args);
a042ac843   wdenk   Initial revision
385
386
  
  	/* Send to the stdout file */
e92372c8a   Heiko Schocher   cosmetic, post: C...
387
  	puts(printbuffer);
a042ac843   wdenk   Initial revision
388
389
390
  
  	return 0;
  }
2e5167cca   Wolfgang Denk   Replace CONFIG_RE...
391
  #ifdef CONFIG_NEEDS_MANUAL_RELOC
e92372c8a   Heiko Schocher   cosmetic, post: C...
392
  void post_reloc(void)
a042ac843   wdenk   Initial revision
393
  {
a042ac843   wdenk   Initial revision
394
395
396
397
398
399
400
401
402
403
  	unsigned int i;
  
  	/*
  	 * We have to relocate the test table manually
  	 */
  	for (i = 0; i < post_list_size; i++) {
  		ulong addr;
  		struct post_test *test = post_list + i;
  
  		if (test->name) {
50da83766   Wolfgang Denk   post/post.c: Codi...
404
  			addr = (ulong)(test->name) + gd->reloc_off;
e92372c8a   Heiko Schocher   cosmetic, post: C...
405
  			test->name = (char *)addr;
a042ac843   wdenk   Initial revision
406
407
408
  		}
  
  		if (test->cmd) {
50da83766   Wolfgang Denk   post/post.c: Codi...
409
  			addr = (ulong)(test->cmd) + gd->reloc_off;
e92372c8a   Heiko Schocher   cosmetic, post: C...
410
  			test->cmd = (char *)addr;
a042ac843   wdenk   Initial revision
411
412
413
  		}
  
  		if (test->desc) {
50da83766   Wolfgang Denk   post/post.c: Codi...
414
  			addr = (ulong)(test->desc) + gd->reloc_off;
e92372c8a   Heiko Schocher   cosmetic, post: C...
415
  			test->desc = (char *)addr;
a042ac843   wdenk   Initial revision
416
417
418
  		}
  
  		if (test->test) {
50da83766   Wolfgang Denk   post/post.c: Codi...
419
  			addr = (ulong)(test->test) + gd->reloc_off;
a042ac843   wdenk   Initial revision
420
421
  			test->test = (int (*)(int flags)) addr;
  		}
4532cb696   wdenk   * LWMON extensions:
422
423
  
  		if (test->init_f) {
50da83766   Wolfgang Denk   post/post.c: Codi...
424
  			addr = (ulong)(test->init_f) + gd->reloc_off;
4532cb696   wdenk   * LWMON extensions:
425
426
427
428
  			test->init_f = (int (*)(void)) addr;
  		}
  
  		if (test->reloc) {
50da83766   Wolfgang Denk   post/post.c: Codi...
429
  			addr = (ulong)(test->reloc) + gd->reloc_off;
4532cb696   wdenk   * LWMON extensions:
430
  			test->reloc = (void (*)(void)) addr;
8bde7f776   wdenk   * Code cleanup:
431

4532cb696   wdenk   * LWMON extensions:
432
433
  			test->reloc();
  		}
a042ac843   wdenk   Initial revision
434
435
  	}
  }
521af04d8   Peter Tyser   Conditionally per...
436
  #endif
a042ac843   wdenk   Initial revision
437

4532cb696   wdenk   * LWMON extensions:
438
439
440
441
442
443
444
  
  /*
   * Some tests (e.g. SYSMON) need the time when post_init_f started,
   * but we cannot use get_timer() at this point.
   *
   * On PowerPC we implement it using the timebase register.
   */
e92372c8a   Heiko Schocher   cosmetic, post: C...
445
  unsigned long post_time_ms(unsigned long base)
4532cb696   wdenk   * LWMON extensions:
446
  {
ea3310e8a   Tom Rini   Blackfin: Remove
447
  #if defined(CONFIG_PPC) || defined(CONFIG_ARM)
c90a4dd79   Christian Riesch   post/post.c: Use ...
448
  	return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ)
e92372c8a   Heiko Schocher   cosmetic, post: C...
449
  		- base;
4532cb696   wdenk   * LWMON extensions:
450
  #else
ad5bb451a   Wolfgang Denk   Restructure POST ...
451
  #warning "Not implemented yet"
4532cb696   wdenk   * LWMON extensions:
452
453
454
  	return 0; /* Not implemented yet */
  #endif
  }