wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame^] | 1 | /* |
| 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> |
| 27 | #include <cmd_elf.h> |
| 28 | |
| 29 | /* |
| 30 | * FIXME: Add code to test image and it's header. |
| 31 | */ |
| 32 | static int |
| 33 | image_check(ulong addr) |
| 34 | { |
| 35 | return valid_elf_image(addr); |
| 36 | } |
| 37 | |
| 38 | void |
| 39 | init_fsboot(void) |
| 40 | { |
| 41 | char *envp; |
| 42 | ulong loadaddr; |
| 43 | ulong testaddr; |
| 44 | ulong alt_loadaddr; |
| 45 | char buf[9]; |
| 46 | |
| 47 | /* |
| 48 | * Get test image address |
| 49 | */ |
| 50 | if ((envp = getenv("testaddr")) != NULL) |
| 51 | testaddr = simple_strtoul(envp, NULL, 16); |
| 52 | else |
| 53 | testaddr = -1; |
| 54 | |
| 55 | /* |
| 56 | * Are we going to test boot and image? |
| 57 | */ |
| 58 | if ((testaddr != -1) && image_check(testaddr)) { |
| 59 | |
| 60 | /* Set alt_loadaddr */ |
| 61 | alt_loadaddr = testaddr; |
| 62 | sprintf(buf, "%lX", alt_loadaddr); |
| 63 | setenv("alt_loadaddr", buf); |
| 64 | |
| 65 | /* Clear test_addr */ |
| 66 | setenv("testaddr", NULL); |
| 67 | |
| 68 | /* |
| 69 | * Save current environment with alt_loadaddr, |
| 70 | * and cleared testaddr. |
| 71 | */ |
| 72 | saveenv(); |
| 73 | |
| 74 | /* |
| 75 | * Setup temporary loadaddr to alt_loadaddr |
| 76 | * XXX - DO NOT SAVE ENVIRONMENT! |
| 77 | */ |
| 78 | loadaddr = alt_loadaddr; |
| 79 | sprintf(buf, "%lX", loadaddr); |
| 80 | setenv("loadaddr", buf); |
| 81 | |
| 82 | } else { /* Normal boot */ |
| 83 | setenv("alt_loadaddr", NULL); /* Clear alt_loadaddr */ |
| 84 | setenv("testaddr", NULL); /* Clear testaddr */ |
| 85 | saveenv(); |
| 86 | } |
| 87 | |
| 88 | return; |
| 89 | } |
| 90 | |