blob: a8822d91b07c5c64dd5106de5eba136faa2c041b [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001/*
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
wdenk591dda52002-11-18 00:14:45 +000034/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +000035 * do_fdosboot --
wdenk591dda52002-11-18 00:14:45 +000036 *-----------------------------------------------------------------------------
37 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +020038int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk591dda52002-11-18 00:14:45 +000039{
40 char *name;
41 char *ep;
42 int size;
43 int rcode = 0;
wdenk7182b0f2003-10-06 21:55:32 +000044 char buf [12];
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045 int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
wdenk57b2d802003-06-27 21:31:46 +000046
wdenk591dda52002-11-18 00:14:45 +000047 /* pre-set load_addr */
48 if ((ep = getenv("loadaddr")) != NULL) {
wdenk57b2d802003-06-27 21:31:46 +000049 load_addr = simple_strtoul(ep, NULL, 16);
wdenk591dda52002-11-18 00:14:45 +000050 }
51
52 /* pre-set Boot file name */
53 if ((name = getenv("bootfile")) == NULL) {
wdenk57b2d802003-06-27 21:31:46 +000054 name = "uImage";
wdenk591dda52002-11-18 00:14:45 +000055 }
56
57 switch (argc) {
58 case 1:
wdenk57b2d802003-06-27 21:31:46 +000059 break;
wdenk591dda52002-11-18 00:14:45 +000060 case 2:
61 /* only one arg - accept two forms:
wdenk57b2d802003-06-27 21:31:46 +000062 * 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;
wdenk591dda52002-11-18 00:14:45 +000071 case 3:
wdenk57b2d802003-06-27 21:31:46 +000072 load_addr = simple_strtoul(argv[1], NULL, 16);
73 name = argv [2];
74 break;
wdenk591dda52002-11-18 00:14:45 +000075 default:
Wolfgang Denk3b683112010-07-17 01:06:04 +020076 return cmd_usage(cmdtp);
wdenk591dda52002-11-18 00:14:45 +000077 }
78
79 /* Init physical layer */
80 if (!fdc_fdos_init (drive)) {
wdenk57b2d802003-06-27 21:31:46 +000081 return (-1);
wdenk591dda52002-11-18 00:14:45 +000082 }
wdenk57b2d802003-06-27 21:31:46 +000083
wdenk591dda52002-11-18 00:14:45 +000084 /* Open file */
85 if (dos_open (name) < 0) {
wdenk57b2d802003-06-27 21:31:46 +000086 printf ("Unable to open %s\n", name);
87 return 1;
wdenk591dda52002-11-18 00:14:45 +000088 }
89 if ((size = dos_read (load_addr)) < 0) {
wdenk57b2d802003-06-27 21:31:46 +000090 printf ("boot error\n");
91 return 1;
wdenk591dda52002-11-18 00:14:45 +000092 }
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",
wdenk57b2d802003-06-27 21:31:46 +000099 size, load_addr);
100
wdenk591dda52002-11-18 00:14:45 +0000101 /* Check if we should attempt an auto-start */
102 if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
wdenk57b2d802003-06-27 21:31:46 +0000103 char *local_args[2];
104 extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
105 local_args[0] = argv[0];
106 local_args[1] = NULL;
107 printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
108 rcode = do_bootm (cmdtp, 0, 1, local_args);
wdenk591dda52002-11-18 00:14:45 +0000109 }
110 return rcode;
111}
112
113/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +0000114 * do_fdosls --
wdenk591dda52002-11-18 00:14:45 +0000115 *-----------------------------------------------------------------------------
116 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200117int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk591dda52002-11-18 00:14:45 +0000118{
119 char *path = "";
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200120 int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
wdenk57b2d802003-06-27 21:31:46 +0000121
wdenk591dda52002-11-18 00:14:45 +0000122 switch (argc) {
123 case 1:
wdenk57b2d802003-06-27 21:31:46 +0000124 break;
wdenk591dda52002-11-18 00:14:45 +0000125 case 2:
wdenk57b2d802003-06-27 21:31:46 +0000126 path = argv [1];
127 break;
wdenk591dda52002-11-18 00:14:45 +0000128 }
129
130 /* Init physical layer */
131 if (!fdc_fdos_init (drive)) {
wdenk57b2d802003-06-27 21:31:46 +0000132 return (-1);
wdenk591dda52002-11-18 00:14:45 +0000133 }
134 /* Open directory */
135 if (dos_open (path) < 0) {
wdenk57b2d802003-06-27 21:31:46 +0000136 printf ("Unable to open %s\n", path);
137 return 1;
wdenk591dda52002-11-18 00:14:45 +0000138 }
139 return (dos_dir ());
140}
141
wdenkf287a242003-07-01 21:06:45 +0000142U_BOOT_CMD(
143 fdosboot, 3, 0, do_fdosboot,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600144 "boot from a dos floppy file",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200145 "[loadAddr] [filename]"
wdenk57b2d802003-06-27 21:31:46 +0000146);
147
wdenkf287a242003-07-01 21:06:45 +0000148U_BOOT_CMD(
149 fdosls, 2, 0, do_fdosls,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600150 "list files in a directory",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200151 "[directory]"
wdenk57b2d802003-06-27 21:31:46 +0000152);