]>
Commit | Line | Data |
---|---|---|
affae2bf WD |
1 | /* |
2 | * (C) Copyright 2001 | |
3 | * Wave 7 Optics, Inc. | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
affae2bf WD |
6 | */ |
7 | ||
8 | #include <common.h> | |
9 | #include <config.h> | |
10 | #include <command.h> | |
6f38477d | 11 | #include <elf.h> |
affae2bf WD |
12 | |
13 | /* | |
14 | * FIXME: Add code to test image and it's header. | |
15 | */ | |
16 | static int | |
17 | image_check(ulong addr) | |
18 | { | |
19 | return valid_elf_image(addr); | |
20 | } | |
21 | ||
22 | void | |
23 | init_fsboot(void) | |
24 | { | |
25 | char *envp; | |
26 | ulong loadaddr; | |
27 | ulong testaddr; | |
28 | ulong alt_loadaddr; | |
29 | char buf[9]; | |
30 | ||
31 | /* | |
32 | * Get test image address | |
33 | */ | |
34 | if ((envp = getenv("testaddr")) != NULL) | |
35 | testaddr = simple_strtoul(envp, NULL, 16); | |
36 | else | |
37 | testaddr = -1; | |
38 | ||
39 | /* | |
40 | * Are we going to test boot and image? | |
41 | */ | |
42 | if ((testaddr != -1) && image_check(testaddr)) { | |
43 | ||
44 | /* Set alt_loadaddr */ | |
45 | alt_loadaddr = testaddr; | |
46 | sprintf(buf, "%lX", alt_loadaddr); | |
47 | setenv("alt_loadaddr", buf); | |
48 | ||
49 | /* Clear test_addr */ | |
50 | setenv("testaddr", NULL); | |
51 | ||
52 | /* | |
53 | * Save current environment with alt_loadaddr, | |
54 | * and cleared testaddr. | |
55 | */ | |
56 | saveenv(); | |
57 | ||
58 | /* | |
59 | * Setup temporary loadaddr to alt_loadaddr | |
60 | * XXX - DO NOT SAVE ENVIRONMENT! | |
61 | */ | |
62 | loadaddr = alt_loadaddr; | |
63 | sprintf(buf, "%lX", loadaddr); | |
64 | setenv("loadaddr", buf); | |
65 | ||
66 | } else { /* Normal boot */ | |
67 | setenv("alt_loadaddr", NULL); /* Clear alt_loadaddr */ | |
68 | setenv("testaddr", NULL); /* Clear testaddr */ | |
69 | saveenv(); | |
70 | } | |
71 | ||
72 | return; | |
73 | } |