blob: 69303255ff0e72ba4d6fac2d05eb1e2f7a4851db [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
wdenk591dda52002-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
wdenk591dda52002-11-18 00:14:45 +000018/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +000019 * do_fdosboot --
wdenk591dda52002-11-18 00:14:45 +000020 *-----------------------------------------------------------------------------
21 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +020022int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk591dda52002-11-18 00:14:45 +000023{
24 char *name;
25 char *ep;
26 int size;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020027 int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
wdenk57b2d802003-06-27 21:31:46 +000028
wdenk591dda52002-11-18 00:14:45 +000029 /* pre-set load_addr */
30 if ((ep = getenv("loadaddr")) != NULL) {
wdenk57b2d802003-06-27 21:31:46 +000031 load_addr = simple_strtoul(ep, NULL, 16);
wdenk591dda52002-11-18 00:14:45 +000032 }
33
34 /* pre-set Boot file name */
35 if ((name = getenv("bootfile")) == NULL) {
wdenk57b2d802003-06-27 21:31:46 +000036 name = "uImage";
wdenk591dda52002-11-18 00:14:45 +000037 }
38
39 switch (argc) {
40 case 1:
wdenk57b2d802003-06-27 21:31:46 +000041 break;
wdenk591dda52002-11-18 00:14:45 +000042 case 2:
43 /* only one arg - accept two forms:
wdenk57b2d802003-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;
wdenk591dda52002-11-18 00:14:45 +000053 case 3:
wdenk57b2d802003-06-27 21:31:46 +000054 load_addr = simple_strtoul(argv[1], NULL, 16);
55 name = argv [2];
56 break;
wdenk591dda52002-11-18 00:14:45 +000057 default:
Simon Glassa06dfc72011-12-10 08:44:01 +000058 return CMD_RET_USAGE;
wdenk591dda52002-11-18 00:14:45 +000059 }
60
61 /* Init physical layer */
62 if (!fdc_fdos_init (drive)) {
wdenk57b2d802003-06-27 21:31:46 +000063 return (-1);
wdenk591dda52002-11-18 00:14:45 +000064 }
wdenk57b2d802003-06-27 21:31:46 +000065
wdenk591dda52002-11-18 00:14:45 +000066 /* Open file */
67 if (dos_open (name) < 0) {
wdenk57b2d802003-06-27 21:31:46 +000068 printf ("Unable to open %s\n", name);
69 return 1;
wdenk591dda52002-11-18 00:14:45 +000070 }
71 if ((size = dos_read (load_addr)) < 0) {
wdenk57b2d802003-06-27 21:31:46 +000072 printf ("boot error\n");
73 return 1;
wdenk591dda52002-11-18 00:14:45 +000074 }
75 flush_cache (load_addr, size);
76
Simon Glass103789d2013-02-24 17:33:22 +000077 setenv_hex("filesize", size);
wdenk591dda52002-11-18 00:14:45 +000078
79 printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
wdenk57b2d802003-06-27 21:31:46 +000080 size, load_addr);
81
Mike Frysinger194c2e82011-06-05 13:43:02 +000082 return bootm_maybe_autostart(cmdtp, argv[0]);
wdenk591dda52002-11-18 00:14:45 +000083}
84
85/*-----------------------------------------------------------------------------
wdenk57b2d802003-06-27 21:31:46 +000086 * do_fdosls --
wdenk591dda52002-11-18 00:14:45 +000087 *-----------------------------------------------------------------------------
88 */
Wolfgang Denk6262d0212010-06-28 22:00:46 +020089int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk591dda52002-11-18 00:14:45 +000090{
91 char *path = "";
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020092 int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
wdenk57b2d802003-06-27 21:31:46 +000093
wdenk591dda52002-11-18 00:14:45 +000094 switch (argc) {
95 case 1:
wdenk57b2d802003-06-27 21:31:46 +000096 break;
wdenk591dda52002-11-18 00:14:45 +000097 case 2:
wdenk57b2d802003-06-27 21:31:46 +000098 path = argv [1];
99 break;
wdenk591dda52002-11-18 00:14:45 +0000100 }
101
102 /* Init physical layer */
103 if (!fdc_fdos_init (drive)) {
wdenk57b2d802003-06-27 21:31:46 +0000104 return (-1);
wdenk591dda52002-11-18 00:14:45 +0000105 }
106 /* Open directory */
107 if (dos_open (path) < 0) {
wdenk57b2d802003-06-27 21:31:46 +0000108 printf ("Unable to open %s\n", path);
109 return 1;
wdenk591dda52002-11-18 00:14:45 +0000110 }
111 return (dos_dir ());
112}
113
wdenkf287a242003-07-01 21:06:45 +0000114U_BOOT_CMD(
115 fdosboot, 3, 0, do_fdosboot,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600116 "boot from a dos floppy file",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200117 "[loadAddr] [filename]"
wdenk57b2d802003-06-27 21:31:46 +0000118);
119
wdenkf287a242003-07-01 21:06:45 +0000120U_BOOT_CMD(
121 fdosls, 2, 0, do_fdosls,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600122 "list files in a directory",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200123 "[directory]"
wdenk57b2d802003-06-27 21:31:46 +0000124);