]>
Commit | Line | Data |
---|---|---|
2262cfee WD |
1 | /* |
2 | * (C) Copyright 2002 | |
fa82f871 | 3 | * Stäubli Faverges - <www.staubli.com> |
2262cfee WD |
4 | * Pierre AUBERT [email protected] |
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 | ||
2262cfee | 34 | /*----------------------------------------------------------------------------- |
8bde7f77 | 35 | * do_fdosboot -- |
2262cfee WD |
36 | *----------------------------------------------------------------------------- |
37 | */ | |
54841ab5 | 38 | int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
2262cfee WD |
39 | { |
40 | char *name; | |
41 | char *ep; | |
42 | int size; | |
fbe4b5cb | 43 | char buf [12]; |
6d0f6bcf | 44 | int drive = CONFIG_SYS_FDC_DRIVE_NUMBER; |
8bde7f77 | 45 | |
2262cfee WD |
46 | /* pre-set load_addr */ |
47 | if ((ep = getenv("loadaddr")) != NULL) { | |
8bde7f77 | 48 | load_addr = simple_strtoul(ep, NULL, 16); |
2262cfee WD |
49 | } |
50 | ||
51 | /* pre-set Boot file name */ | |
52 | if ((name = getenv("bootfile")) == NULL) { | |
8bde7f77 | 53 | name = "uImage"; |
2262cfee WD |
54 | } |
55 | ||
56 | switch (argc) { | |
57 | case 1: | |
8bde7f77 | 58 | break; |
2262cfee WD |
59 | case 2: |
60 | /* only one arg - accept two forms: | |
8bde7f77 WD |
61 | * just load address, or just boot file name. |
62 | * The latter form must be written "filename" here. | |
63 | */ | |
64 | if (argv[1][0] == '"') { /* just boot filename */ | |
65 | name = argv [1]; | |
66 | } else { /* load address */ | |
67 | load_addr = simple_strtoul(argv[1], NULL, 16); | |
68 | } | |
69 | break; | |
2262cfee | 70 | case 3: |
8bde7f77 WD |
71 | load_addr = simple_strtoul(argv[1], NULL, 16); |
72 | name = argv [2]; | |
73 | break; | |
2262cfee | 74 | default: |
4c12eeb8 | 75 | return CMD_RET_USAGE; |
2262cfee WD |
76 | } |
77 | ||
78 | /* Init physical layer */ | |
79 | if (!fdc_fdos_init (drive)) { | |
8bde7f77 | 80 | return (-1); |
2262cfee | 81 | } |
8bde7f77 | 82 | |
2262cfee WD |
83 | /* Open file */ |
84 | if (dos_open (name) < 0) { | |
8bde7f77 WD |
85 | printf ("Unable to open %s\n", name); |
86 | return 1; | |
2262cfee WD |
87 | } |
88 | if ((size = dos_read (load_addr)) < 0) { | |
8bde7f77 WD |
89 | printf ("boot error\n"); |
90 | return 1; | |
2262cfee WD |
91 | } |
92 | flush_cache (load_addr, size); | |
93 | ||
94 | sprintf(buf, "%x", size); | |
95 | setenv("filesize", buf); | |
96 | ||
97 | printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n", | |
8bde7f77 WD |
98 | size, load_addr); |
99 | ||
67d668bf | 100 | return bootm_maybe_autostart(cmdtp, argv[0]); |
2262cfee WD |
101 | } |
102 | ||
103 | /*----------------------------------------------------------------------------- | |
8bde7f77 | 104 | * do_fdosls -- |
2262cfee WD |
105 | *----------------------------------------------------------------------------- |
106 | */ | |
54841ab5 | 107 | int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
2262cfee WD |
108 | { |
109 | char *path = ""; | |
6d0f6bcf | 110 | int drive = CONFIG_SYS_FDC_DRIVE_NUMBER; |
8bde7f77 | 111 | |
2262cfee WD |
112 | switch (argc) { |
113 | case 1: | |
8bde7f77 | 114 | break; |
2262cfee | 115 | case 2: |
8bde7f77 WD |
116 | path = argv [1]; |
117 | break; | |
2262cfee WD |
118 | } |
119 | ||
120 | /* Init physical layer */ | |
121 | if (!fdc_fdos_init (drive)) { | |
8bde7f77 | 122 | return (-1); |
2262cfee WD |
123 | } |
124 | /* Open directory */ | |
125 | if (dos_open (path) < 0) { | |
8bde7f77 WD |
126 | printf ("Unable to open %s\n", path); |
127 | return 1; | |
2262cfee WD |
128 | } |
129 | return (dos_dir ()); | |
130 | } | |
131 | ||
0d498393 WD |
132 | U_BOOT_CMD( |
133 | fdosboot, 3, 0, do_fdosboot, | |
2fb2604d | 134 | "boot from a dos floppy file", |
a89c33db | 135 | "[loadAddr] [filename]" |
8bde7f77 WD |
136 | ); |
137 | ||
0d498393 WD |
138 | U_BOOT_CMD( |
139 | fdosls, 2, 0, do_fdosls, | |
2fb2604d | 140 | "list files in a directory", |
a89c33db | 141 | "[directory]" |
8bde7f77 | 142 | ); |