wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Wave 7 Optics, Inc. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <config.h> |
| 10 | #include <command.h> |
Jeroen Hofstee | 6f38477 | 2014-10-08 22:58:01 +0200 | [diff] [blame] | 11 | #include <elf.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 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 | } |