blob: 69303255ff0e72ba4d6fac2d05eb1e2f7a4851db [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001/*
2 * (C) Copyright 2002
Albert ARIBAUDfa82f872011-08-04 18:45:45 +02003 * Stäubli Faverges - <www.staubli.com>
wdenk2262cfe2002-11-18 00:14:45 +00004 * Pierre AUBERT p.aubert@staubli.com
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
wdenk2262cfe2002-11-18 00:14:45 +00007 */
8
9/*
10 * Dos floppy support
11 */
12
13#include <common.h>
14#include <config.h>
15#include <command.h>
16#include <fdc.h>
17
wdenk2262cfe2002-11-18 00:14:45 +000018/*-----------------------------------------------------------------------------
wdenk8bde7f72003-06-27 21:31:46 +000019 * do_fdosboot --
wdenk2262cfe2002-11-18 00:14:45 +000020 *-----------------------------------------------------------------------------
21 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020022int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk2262cfe2002-11-18 00:14:45 +000023{
24 char *name;
25 char *ep;
26 int size;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020027 int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
wdenk8bde7f72003-06-27 21:31:46 +000028
wdenk2262cfe2002-11-18 00:14:45 +000029 /* pre-set load_addr */
30 if ((ep = getenv("loadaddr")) != NULL) {
wdenk8bde7f72003-06-27 21:31:46 +000031 load_addr = simple_strtoul(ep, NULL, 16);
wdenk2262cfe2002-11-18 00:14:45 +000032 }
33
34 /* pre-set Boot file name */
35 if ((name = getenv("bootfile")) == NULL) {
wdenk8bde7f72003-06-27 21:31:46 +000036 name = "uImage";
wdenk2262cfe2002-11-18 00:14:45 +000037 }
38
39 switch (argc) {
40 case 1:
wdenk8bde7f72003-06-27 21:31:46 +000041 break;
wdenk2262cfe2002-11-18 00:14:45 +000042 case 2:
43 /* only one arg - accept two forms:
wdenk8bde7f72003-06-27 21:31:46 +000044 * just load address, or just boot file name.
45 * The latter form must be written "filename" here.
46 */
47 if (argv[1][0] == '"') { /* just boot filename */
48 name = argv [1];
49 } else { /* load address */
50 load_addr = simple_strtoul(argv[1], NULL, 16);
51 }
52 break;
wdenk2262cfe2002-11-18 00:14:45 +000053 case 3:
wdenk8bde7f72003-06-27 21:31:46 +000054 load_addr = simple_strtoul(argv[1], NULL, 16);
55 name = argv [2];
56 break;
wdenk2262cfe2002-11-18 00:14:45 +000057 default:
Simon Glass4c12eeb2011-12-10 08:44:01 +000058 return CMD_RET_USAGE;
wdenk2262cfe2002-11-18 00:14:45 +000059 }
60
61 /* Init physical layer */
62 if (!fdc_fdos_init (drive)) {
wdenk8bde7f72003-06-27 21:31:46 +000063 return (-1);
wdenk2262cfe2002-11-18 00:14:45 +000064 }
wdenk8bde7f72003-06-27 21:31:46 +000065
wdenk2262cfe2002-11-18 00:14:45 +000066 /* Open file */
67 if (dos_open (name) < 0) {
wdenk8bde7f72003-06-27 21:31:46 +000068 printf ("Unable to open %s\n", name);
69 return 1;
wdenk2262cfe2002-11-18 00:14:45 +000070 }
71 if ((size = dos_read (load_addr)) < 0) {
wdenk8bde7f72003-06-27 21:31:46 +000072 printf ("boot error\n");
73 return 1;
wdenk2262cfe2002-11-18 00:14:45 +000074 }
75 flush_cache (load_addr, size);
76
Simon Glass41ef3722013-02-24 17:33:22 +000077 setenv_hex("filesize", size);
wdenk2262cfe2002-11-18 00:14:45 +000078
79 printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
wdenk8bde7f72003-06-27 21:31:46 +000080 size, load_addr);
81
Mike Frysinger67d668b2011-06-05 13:43:02 +000082 return bootm_maybe_autostart(cmdtp, argv[0]);
wdenk2262cfe2002-11-18 00:14:45 +000083}
84
85/*-----------------------------------------------------------------------------
wdenk8bde7f72003-06-27 21:31:46 +000086 * do_fdosls --
wdenk2262cfe2002-11-18 00:14:45 +000087 *-----------------------------------------------------------------------------
88 */
Wolfgang Denk54841ab2010-06-28 22:00:46 +020089int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk2262cfe2002-11-18 00:14:45 +000090{
91 char *path = "";
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020092 int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
wdenk8bde7f72003-06-27 21:31:46 +000093
wdenk2262cfe2002-11-18 00:14:45 +000094 switch (argc) {
95 case 1:
wdenk8bde7f72003-06-27 21:31:46 +000096 break;
wdenk2262cfe2002-11-18 00:14:45 +000097 case 2:
wdenk8bde7f72003-06-27 21:31:46 +000098 path = argv [1];
99 break;
wdenk2262cfe2002-11-18 00:14:45 +0000100 }
101
102 /* Init physical layer */
103 if (!fdc_fdos_init (drive)) {
wdenk8bde7f72003-06-27 21:31:46 +0000104 return (-1);
wdenk2262cfe2002-11-18 00:14:45 +0000105 }
106 /* Open directory */
107 if (dos_open (path) < 0) {
wdenk8bde7f72003-06-27 21:31:46 +0000108 printf ("Unable to open %s\n", path);
109 return 1;
wdenk2262cfe2002-11-18 00:14:45 +0000110 }
111 return (dos_dir ());
112}
113
wdenk0d498392003-07-01 21:06:45 +0000114U_BOOT_CMD(
115 fdosboot, 3, 0, do_fdosboot,
Peter Tyser2fb26042009-01-27 18:03:12 -0600116 "boot from a dos floppy file",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200117 "[loadAddr] [filename]"
wdenk8bde7f72003-06-27 21:31:46 +0000118);
119
wdenk0d498392003-07-01 21:06:45 +0000120U_BOOT_CMD(
121 fdosls, 2, 0, do_fdosls,
Peter Tyser2fb26042009-01-27 18:03:12 -0600122 "list files in a directory",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200123 "[directory]"
wdenk8bde7f72003-06-27 21:31:46 +0000124);