wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Wave 7 Optics, Inc. |
| 4 | * |
Wolfgang Denk | d79de1d | 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> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 11 | |
| 12 | /* |
| 13 | * FIXME: Add code to test image and it's header. |
| 14 | */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 15 | extern int valid_elf_image (unsigned long addr); |
| 16 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 17 | static int |
| 18 | image_check(ulong addr) |
| 19 | { |
| 20 | return valid_elf_image(addr); |
| 21 | } |
| 22 | |
| 23 | void |
| 24 | init_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 | } |