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