blob: 8ea1140e7fe880d145218eaa20504152b7c0dd96 [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;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020043 int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
wdenk57b2d802003-06-27 21:31:46 +000044
wdenk591dda52002-11-18 00:14:45 +000045 /* pre-set load_addr */
46 if ((ep = getenv("loadaddr")) != NULL) {
wdenk57b2d802003-06-27 21:31:46 +000047 load_addr = simple_strtoul(ep, NULL, 16);
wdenk591dda52002-11-18 00:14:45 +000048 }
49
50 /* pre-set Boot file name */
51 if ((name = getenv("bootfile")) == NULL) {
wdenk57b2d802003-06-27 21:31:46 +000052 name = "uImage";
wdenk591dda52002-11-18 00:14:45 +000053 }
54
55 switch (argc) {
56 case 1:
wdenk57b2d802003-06-27 21:31:46 +000057 break;
wdenk591dda52002-11-18 00:14:45 +000058 case 2:
59 /* only one arg - accept two forms:
wdenk57b2d802003-06-27 21:31:46 +000060 * just load address, or just boot file name.
61 * The latter form must be written "filename" here.
62 */
63 if (argv[1][0] == '"') { /* just boot filename */
64 name = argv [1];
65 } else { /* load address */
66 load_addr = simple_strtoul(argv[1], NULL, 16);
67 }
68 break;
wdenk591dda52002-11-18 00:14:45 +000069 case 3:
wdenk57b2d802003-06-27 21:31:46 +000070 load_addr = simple_strtoul(argv[1], NULL, 16);
71 name = argv [2];
72 break;
wdenk591dda52002-11-18 00:14:45 +000073 default:
Simon Glassa06dfc72011-12-10 08:44:01 +000074 return CMD_RET_USAGE;
wdenk591dda52002-11-18 00:14:45 +000075 }
76
77 /* Init physical layer */
78 if (!fdc_fdos_init (drive)) {
wdenk57b2d802003-06-27 21:31:46 +000079 return (-1);
wdenk591dda52002-11-18 00:14:45 +000080 }
wdenk57b2d802003-06-27 21:31:46 +000081
wdenk591dda52002-11-18 00:14:45 +000082 /* Open file */
83 if (dos_open (name) < 0) {
wdenk57b2d802003-06-27 21:31:46 +000084 printf ("Unable to open %s\n", name);
85 return 1;
wdenk591dda52002-11-18 00:14:45 +000086 }
87 if ((size = dos_read (load_addr)) < 0) {
wdenk57b2d802003-06-27 21:31:46 +000088 printf ("boot error\n");
89 return 1;
wdenk591dda52002-11-18 00:14:45 +000090 }
91 flush_cache (load_addr, size);
92
Simon Glass103789d2013-02-24 17:33:22 +000093 setenv_hex("filesize", size);
wdenk591dda52002-11-18 00:14:45 +000094
95 printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
wdenk57b2d802003-06-27 21:31:46 +000096 size, load_addr);
97
Mike Frysinger194c2e82011-06-05 13:43:02 +000098 return bootm_maybe_autostart(cmdtp, argv[0]);
wdenk591dda52002-11-18 00:14:45 +000099}
100
101/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +0000102 * do_fdosls --
wdenk591dda52002-11-18 00:14:45 +0000103 *-----------------------------------------------------------------------------
104 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200105int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk591dda52002-11-18 00:14:45 +0000106{
107 char *path = "";
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200108 int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
wdenk57b2d802003-06-27 21:31:46 +0000109
wdenk591dda52002-11-18 00:14:45 +0000110 switch (argc) {
111 case 1:
wdenk57b2d802003-06-27 21:31:46 +0000112 break;
wdenk591dda52002-11-18 00:14:45 +0000113 case 2:
wdenk57b2d802003-06-27 21:31:46 +0000114 path = argv [1];
115 break;
wdenk591dda52002-11-18 00:14:45 +0000116 }
117
118 /* Init physical layer */
119 if (!fdc_fdos_init (drive)) {
wdenk57b2d802003-06-27 21:31:46 +0000120 return (-1);
wdenk591dda52002-11-18 00:14:45 +0000121 }
122 /* Open directory */
123 if (dos_open (path) < 0) {
wdenk57b2d802003-06-27 21:31:46 +0000124 printf ("Unable to open %s\n", path);
125 return 1;
wdenk591dda52002-11-18 00:14:45 +0000126 }
127 return (dos_dir ());
128}
129
wdenkf287a242003-07-01 21:06:45 +0000130U_BOOT_CMD(
131 fdosboot, 3, 0, do_fdosboot,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600132 "boot from a dos floppy file",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200133 "[loadAddr] [filename]"
wdenk57b2d802003-06-27 21:31:46 +0000134);
135
wdenkf287a242003-07-01 21:06:45 +0000136U_BOOT_CMD(
137 fdosls, 2, 0, do_fdosls,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600138 "list files in a directory",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200139 "[directory]"
wdenk57b2d802003-06-27 21:31:46 +0000140);