blob: 0ef9a61be644d79c27d70e15f8eb2ffb702e257d [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * (C) Copyright 2001
3 * Wave 7 Optics, Inc.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <config.h>
26#include <command.h>
wdenkaffae2b2002-08-17 09:36:01 +000027
28/*
29 * FIXME: Add code to test image and it's header.
30 */
wdenk57b2d802003-06-27 21:31:46 +000031extern int valid_elf_image (unsigned long addr);
32
wdenkaffae2b2002-08-17 09:36:01 +000033static int
34image_check(ulong addr)
35{
36 return valid_elf_image(addr);
37}
38
39void
40init_fsboot(void)
41{
42 char *envp;
43 ulong loadaddr;
44 ulong testaddr;
45 ulong alt_loadaddr;
46 char buf[9];
47
48 /*
49 * Get test image address
50 */
51 if ((envp = getenv("testaddr")) != NULL)
52 testaddr = simple_strtoul(envp, NULL, 16);
53 else
54 testaddr = -1;
55
56 /*
57 * Are we going to test boot and image?
58 */
59 if ((testaddr != -1) && image_check(testaddr)) {
60
61 /* Set alt_loadaddr */
62 alt_loadaddr = testaddr;
63 sprintf(buf, "%lX", alt_loadaddr);
64 setenv("alt_loadaddr", buf);
65
66 /* Clear test_addr */
67 setenv("testaddr", NULL);
68
69 /*
70 * Save current environment with alt_loadaddr,
71 * and cleared testaddr.
72 */
73 saveenv();
74
75 /*
76 * Setup temporary loadaddr to alt_loadaddr
77 * XXX - DO NOT SAVE ENVIRONMENT!
78 */
79 loadaddr = alt_loadaddr;
80 sprintf(buf, "%lX", loadaddr);
81 setenv("loadaddr", buf);
82
83 } else { /* Normal boot */
84 setenv("alt_loadaddr", NULL); /* Clear alt_loadaddr */
85 setenv("testaddr", NULL); /* Clear testaddr */
86 saveenv();
87 }
88
89 return;
90}