blob: 8f4fe310d7d2b23bef6dd5da1bd2e50c50615d6f [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * (C) Copyright 2001
3 * Wave 7 Optics, Inc.
4 *
Wolfgang Denkd79de1d2013-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>
Jeroen Hofsteeb57fb1b2014-10-08 22:58:01 +020011#include <elf.h>
wdenkaffae2b2002-08-17 09:36:01 +000012
13/*
14 * FIXME: Add code to test image and it's header.
15 */
16static int
17image_check(ulong addr)
18{
19 return valid_elf_image(addr);
20}
21
22void
23init_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}