wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Stäubli Faverges - <www.staubli.com> |
| 4 | * Pierre AUBERT p.aubert@staubli.com |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * Dos floppy support |
| 27 | */ |
| 28 | |
| 29 | #include <common.h> |
| 30 | #include <config.h> |
| 31 | #include <command.h> |
| 32 | #include <fdc.h> |
| 33 | |
| 34 | #if (CONFIG_COMMANDS & CFG_CMD_FDOS) |
| 35 | |
| 36 | /*----------------------------------------------------------------------------- |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 37 | * do_fdosboot -- |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 38 | *----------------------------------------------------------------------------- |
| 39 | */ |
| 40 | int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 41 | { |
| 42 | char *name; |
| 43 | char *ep; |
| 44 | int size; |
| 45 | int rcode = 0; |
| 46 | char buf [10]; |
| 47 | int drive = CFG_FDC_DRIVE_NUMBER; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 48 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 49 | /* pre-set load_addr */ |
| 50 | if ((ep = getenv("loadaddr")) != NULL) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 51 | load_addr = simple_strtoul(ep, NULL, 16); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /* pre-set Boot file name */ |
| 55 | if ((name = getenv("bootfile")) == NULL) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 56 | name = "uImage"; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | switch (argc) { |
| 60 | case 1: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 61 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 62 | case 2: |
| 63 | /* only one arg - accept two forms: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 64 | * just load address, or just boot file name. |
| 65 | * The latter form must be written "filename" here. |
| 66 | */ |
| 67 | if (argv[1][0] == '"') { /* just boot filename */ |
| 68 | name = argv [1]; |
| 69 | } else { /* load address */ |
| 70 | load_addr = simple_strtoul(argv[1], NULL, 16); |
| 71 | } |
| 72 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 73 | case 3: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 74 | load_addr = simple_strtoul(argv[1], NULL, 16); |
| 75 | name = argv [2]; |
| 76 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 77 | default: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 78 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 79 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* Init physical layer */ |
| 83 | if (!fdc_fdos_init (drive)) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 84 | return (-1); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 85 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 86 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 87 | /* Open file */ |
| 88 | if (dos_open (name) < 0) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 89 | printf ("Unable to open %s\n", name); |
| 90 | return 1; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 91 | } |
| 92 | if ((size = dos_read (load_addr)) < 0) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 93 | printf ("boot error\n"); |
| 94 | return 1; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 95 | } |
| 96 | flush_cache (load_addr, size); |
| 97 | |
| 98 | sprintf(buf, "%x", size); |
| 99 | setenv("filesize", buf); |
| 100 | |
| 101 | printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 102 | size, load_addr); |
| 103 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 104 | /* Check if we should attempt an auto-start */ |
| 105 | if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 106 | char *local_args[2]; |
| 107 | extern int do_bootm (cmd_tbl_t *, int, int, char *[]); |
| 108 | local_args[0] = argv[0]; |
| 109 | local_args[1] = NULL; |
| 110 | printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); |
| 111 | rcode = do_bootm (cmdtp, 0, 1, local_args); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 112 | } |
| 113 | return rcode; |
| 114 | } |
| 115 | |
| 116 | /*----------------------------------------------------------------------------- |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 117 | * do_fdosls -- |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 118 | *----------------------------------------------------------------------------- |
| 119 | */ |
| 120 | int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 121 | { |
| 122 | char *path = ""; |
| 123 | int drive = CFG_FDC_DRIVE_NUMBER; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 124 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 125 | switch (argc) { |
| 126 | case 1: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 127 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 128 | case 2: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 129 | path = argv [1]; |
| 130 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /* Init physical layer */ |
| 134 | if (!fdc_fdos_init (drive)) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 135 | return (-1); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 136 | } |
| 137 | /* Open directory */ |
| 138 | if (dos_open (path) < 0) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 139 | printf ("Unable to open %s\n", path); |
| 140 | return 1; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 141 | } |
| 142 | return (dos_dir ()); |
| 143 | } |
| 144 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame^] | 145 | U_BOOT_CMD( |
| 146 | fdosboot, 3, 0, do_fdosboot, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 147 | "fdosboot- boot from a dos floppy file\n", |
| 148 | "[loadAddr] [filename]\n" |
| 149 | ); |
| 150 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame^] | 151 | U_BOOT_CMD( |
| 152 | fdosls, 2, 0, do_fdosls, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 153 | "fdosls - list files in a directory\n", |
| 154 | "[directory]\n" |
| 155 | ); |
| 156 | |
| 157 | #endif /* CONFIG_COMMANDS & CFG_CMD_FDOS */ |