Fixed tools/env utilities
[u-boot-openmoko/mini2440.git] / common / cmd_fdos.c
blobb3dbd19faea952f448f8c03e1f56f39e7bf96997
1 /*
2 * (C) Copyright 2002
3 * Stäubli Faverges - <www.staubli.com>
4 * Pierre AUBERT p.aubert@staubli.com
6 * See file CREDITS for list of people who contributed to this
7 * project.
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.
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.
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
26 * Dos floppy support
29 #include <common.h>
30 #include <config.h>
31 #include <command.h>
32 #include <fdc.h>
34 /*-----------------------------------------------------------------------------
35 * do_fdosboot --
36 *-----------------------------------------------------------------------------
38 int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
40 char *name;
41 char *ep;
42 int size;
43 int rcode = 0;
44 char buf [12];
45 int drive = CFG_FDC_DRIVE_NUMBER;
47 /* pre-set load_addr */
48 if ((ep = getenv("loadaddr")) != NULL) {
49 load_addr = simple_strtoul(ep, NULL, 16);
52 /* pre-set Boot file name */
53 if ((name = getenv("bootfile")) == NULL) {
54 name = "uImage";
57 switch (argc) {
58 case 1:
59 break;
60 case 2:
61 /* only one arg - accept two forms:
62 * just load address, or just boot file name.
63 * The latter form must be written "filename" here.
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);
70 break;
71 case 3:
72 load_addr = simple_strtoul(argv[1], NULL, 16);
73 name = argv [2];
74 break;
75 default:
76 printf ("Usage:\n%s\n", cmdtp->usage);
77 break;
80 /* Init physical layer */
81 if (!fdc_fdos_init (drive)) {
82 return (-1);
85 /* Open file */
86 if (dos_open (name) < 0) {
87 printf ("Unable to open %s\n", name);
88 return 1;
90 if ((size = dos_read (load_addr)) < 0) {
91 printf ("boot error\n");
92 return 1;
94 flush_cache (load_addr, size);
96 sprintf(buf, "%x", size);
97 setenv("filesize", buf);
99 printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
100 size, load_addr);
102 /* Check if we should attempt an auto-start */
103 if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
104 char *local_args[2];
105 extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
106 local_args[0] = argv[0];
107 local_args[1] = NULL;
108 printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
109 rcode = do_bootm (cmdtp, 0, 1, local_args);
111 return rcode;
114 /*-----------------------------------------------------------------------------
115 * do_fdosls --
116 *-----------------------------------------------------------------------------
118 int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
120 char *path = "";
121 int drive = CFG_FDC_DRIVE_NUMBER;
123 switch (argc) {
124 case 1:
125 break;
126 case 2:
127 path = argv [1];
128 break;
131 /* Init physical layer */
132 if (!fdc_fdos_init (drive)) {
133 return (-1);
135 /* Open directory */
136 if (dos_open (path) < 0) {
137 printf ("Unable to open %s\n", path);
138 return 1;
140 return (dos_dir ());
143 U_BOOT_CMD(
144 fdosboot, 3, 0, do_fdosboot,
145 "fdosboot- boot from a dos floppy file\n",
146 "[loadAddr] [filename]\n"
149 U_BOOT_CMD(
150 fdosls, 2, 0, do_fdosls,
151 "fdosls - list files in a directory\n",
152 "[directory]\n"