blob: 04a5e01947d2d72dd8a6e97b7c1b03a9274bce1a [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001/*
2 * (C) Copyright 2002
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02003 * Stäubli Faverges - <www.staubli.com>
wdenk591dda52002-11-18 00:14:45 +00004 * 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;
wdenk7182b0f2003-10-06 21:55:32 +000043 char buf [12];
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020044 int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
wdenk57b2d802003-06-27 21:31:46 +000045
wdenk591dda52002-11-18 00:14:45 +000046 /* pre-set load_addr */
47 if ((ep = getenv("loadaddr")) != NULL) {
wdenk57b2d802003-06-27 21:31:46 +000048 load_addr = simple_strtoul(ep, NULL, 16);
wdenk591dda52002-11-18 00:14:45 +000049 }
50
51 /* pre-set Boot file name */
52 if ((name = getenv("bootfile")) == NULL) {
wdenk57b2d802003-06-27 21:31:46 +000053 name = "uImage";
wdenk591dda52002-11-18 00:14:45 +000054 }
55
56 switch (argc) {
57 case 1:
wdenk57b2d802003-06-27 21:31:46 +000058 break;
wdenk591dda52002-11-18 00:14:45 +000059 case 2:
60 /* only one arg - accept two forms:
wdenk57b2d802003-06-27 21:31:46 +000061 * 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;
wdenk591dda52002-11-18 00:14:45 +000070 case 3:
wdenk57b2d802003-06-27 21:31:46 +000071 load_addr = simple_strtoul(argv[1], NULL, 16);
72 name = argv [2];
73 break;
wdenk591dda52002-11-18 00:14:45 +000074 default:
Wolfgang Denk3b683112010-07-17 01:06:04 +020075 return cmd_usage(cmdtp);
wdenk591dda52002-11-18 00:14:45 +000076 }
77
78 /* Init physical layer */
79 if (!fdc_fdos_init (drive)) {
wdenk57b2d802003-06-27 21:31:46 +000080 return (-1);
wdenk591dda52002-11-18 00:14:45 +000081 }
wdenk57b2d802003-06-27 21:31:46 +000082
wdenk591dda52002-11-18 00:14:45 +000083 /* Open file */
84 if (dos_open (name) < 0) {
wdenk57b2d802003-06-27 21:31:46 +000085 printf ("Unable to open %s\n", name);
86 return 1;
wdenk591dda52002-11-18 00:14:45 +000087 }
88 if ((size = dos_read (load_addr)) < 0) {
wdenk57b2d802003-06-27 21:31:46 +000089 printf ("boot error\n");
90 return 1;
wdenk591dda52002-11-18 00:14:45 +000091 }
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",
wdenk57b2d802003-06-27 21:31:46 +000098 size, load_addr);
99
Mike Frysinger194c2e82011-06-05 13:43:02 +0000100 return bootm_maybe_autostart(cmdtp, argv[0]);
wdenk591dda52002-11-18 00:14:45 +0000101}
102
103/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +0000104 * do_fdosls --
wdenk591dda52002-11-18 00:14:45 +0000105 *-----------------------------------------------------------------------------
106 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200107int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk591dda52002-11-18 00:14:45 +0000108{
109 char *path = "";
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200110 int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
wdenk57b2d802003-06-27 21:31:46 +0000111
wdenk591dda52002-11-18 00:14:45 +0000112 switch (argc) {
113 case 1:
wdenk57b2d802003-06-27 21:31:46 +0000114 break;
wdenk591dda52002-11-18 00:14:45 +0000115 case 2:
wdenk57b2d802003-06-27 21:31:46 +0000116 path = argv [1];
117 break;
wdenk591dda52002-11-18 00:14:45 +0000118 }
119
120 /* Init physical layer */
121 if (!fdc_fdos_init (drive)) {
wdenk57b2d802003-06-27 21:31:46 +0000122 return (-1);
wdenk591dda52002-11-18 00:14:45 +0000123 }
124 /* Open directory */
125 if (dos_open (path) < 0) {
wdenk57b2d802003-06-27 21:31:46 +0000126 printf ("Unable to open %s\n", path);
127 return 1;
wdenk591dda52002-11-18 00:14:45 +0000128 }
129 return (dos_dir ());
130}
131
wdenkf287a242003-07-01 21:06:45 +0000132U_BOOT_CMD(
133 fdosboot, 3, 0, do_fdosboot,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600134 "boot from a dos floppy file",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200135 "[loadAddr] [filename]"
wdenk57b2d802003-06-27 21:31:46 +0000136);
137
wdenkf287a242003-07-01 21:06:45 +0000138U_BOOT_CMD(
139 fdosls, 2, 0, do_fdosls,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600140 "list files in a directory",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200141 "[directory]"
wdenk57b2d802003-06-27 21:31:46 +0000142);