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 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 34 | /*----------------------------------------------------------------------------- |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 35 | * do_fdosboot -- |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 36 | *----------------------------------------------------------------------------- |
| 37 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 38 | int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 39 | { |
| 40 | char *name; |
| 41 | char *ep; |
| 42 | int size; |
| 43 | int rcode = 0; |
wdenk | fbe4b5c | 2003-10-06 21:55:32 +0000 | [diff] [blame] | 44 | char buf [12]; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 45 | int drive = CONFIG_SYS_FDC_DRIVE_NUMBER; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 46 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 47 | /* pre-set load_addr */ |
| 48 | if ((ep = getenv("loadaddr")) != NULL) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 49 | load_addr = simple_strtoul(ep, NULL, 16); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /* pre-set Boot file name */ |
| 53 | if ((name = getenv("bootfile")) == NULL) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 54 | name = "uImage"; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | switch (argc) { |
| 58 | case 1: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 59 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 60 | case 2: |
| 61 | /* only one arg - accept two forms: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 62 | * just load address, or just boot file name. |
| 63 | * The latter form must be written "filename" here. |
| 64 | */ |
| 65 | if (argv[1][0] == '"') { /* just boot filename */ |
| 66 | name = argv [1]; |
| 67 | } else { /* load address */ |
| 68 | load_addr = simple_strtoul(argv[1], NULL, 16); |
| 69 | } |
| 70 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 71 | case 3: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 72 | load_addr = simple_strtoul(argv[1], NULL, 16); |
| 73 | name = argv [2]; |
| 74 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 75 | default: |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 76 | return cmd_usage(cmdtp); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* Init physical layer */ |
| 80 | if (!fdc_fdos_init (drive)) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 81 | return (-1); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 82 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 83 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 84 | /* Open file */ |
| 85 | if (dos_open (name) < 0) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 86 | printf ("Unable to open %s\n", name); |
| 87 | return 1; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 88 | } |
| 89 | if ((size = dos_read (load_addr)) < 0) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 90 | printf ("boot error\n"); |
| 91 | return 1; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 92 | } |
| 93 | flush_cache (load_addr, size); |
| 94 | |
| 95 | sprintf(buf, "%x", size); |
| 96 | setenv("filesize", buf); |
| 97 | |
| 98 | printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 99 | size, load_addr); |
| 100 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 101 | /* Check if we should attempt an auto-start */ |
Wolfgang Denk | 3e5ab1a | 2011-01-11 20:56:34 +0100 | [diff] [blame] | 102 | if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 103 | char *local_args[2]; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 104 | local_args[0] = argv[0]; |
| 105 | local_args[1] = NULL; |
| 106 | printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); |
| 107 | rcode = do_bootm (cmdtp, 0, 1, local_args); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 108 | } |
| 109 | return rcode; |
| 110 | } |
| 111 | |
| 112 | /*----------------------------------------------------------------------------- |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 113 | * do_fdosls -- |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 114 | *----------------------------------------------------------------------------- |
| 115 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 116 | int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 117 | { |
| 118 | char *path = ""; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 119 | int drive = CONFIG_SYS_FDC_DRIVE_NUMBER; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 120 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 121 | switch (argc) { |
| 122 | case 1: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 123 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 124 | case 2: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 125 | path = argv [1]; |
| 126 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /* Init physical layer */ |
| 130 | if (!fdc_fdos_init (drive)) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 131 | return (-1); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 132 | } |
| 133 | /* Open directory */ |
| 134 | if (dos_open (path) < 0) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 135 | printf ("Unable to open %s\n", path); |
| 136 | return 1; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 137 | } |
| 138 | return (dos_dir ()); |
| 139 | } |
| 140 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 141 | U_BOOT_CMD( |
| 142 | fdosboot, 3, 0, do_fdosboot, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 143 | "boot from a dos floppy file", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 144 | "[loadAddr] [filename]" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 145 | ); |
| 146 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 147 | U_BOOT_CMD( |
| 148 | fdosls, 2, 0, do_fdosls, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 149 | "list files in a directory", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 150 | "[directory]" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 151 | ); |