+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
#include "common.h"
#include <stdlib.h>
#include "print-utils.h"
-static const FLASH char * const FLASH rc_names[] = {
- FSTR("OK"),
- FSTR("DISK_ERR"),
- FSTR("INT_ERR"),
- FSTR("NOT_READY"),
- FSTR("NO_FILE"),
- FSTR("NO_PATH"),
- FSTR("INVALID_NAME"),
- FSTR("DENIED"),
- FSTR("EXIST"),
- FSTR("INVALID_OBJECT"),
- FSTR("WRITE_PROTECTED"),
- FSTR("INVALID_DRIVE"),
- FSTR("NOT_ENABLED"),
- FSTR("NO_FILE_SYSTEM"),
- FSTR("MKFS_ABORTED"),
- FSTR("TIMEOUT"),
- FSTR("LOCKED"),
- FSTR("NOT_ENOUGH_CORE"),
- FSTR("TOO_MANY_OPEN_FILES")
- };
-
+/*
+ * status <pd#> - Show socket status
+ *
+ */
static
-void put_rc (FRESULT rc)
+command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
-#if 0
- printf_P(PSTR("rc=%u FR_%S\n"), rc, rc_names[rc]);
-#else
- printf_P(PSTR("rc=%u FR_"), rc);
- my_puts_P(rc_names[rc]);
- my_puts_P(PSTR("\n"));
+ DSTATUS res;
+ BYTE dev;
-#endif
+ (void) cmdtp; (void) flag;
-}
+ if (argc < 2)
+ return CMD_RET_USAGE;
+ dev = (BYTE) strtoul(argv[1], 0, 10);
+ res = disk_status(dev);
+ printf_P(PSTR("Socket status: %02x\n"), res);
+
+ return CMD_RET_SUCCESS;
+}
/*
- * di <pd#> - Initialize disk
+ * init <pd#> - Initialize disk
*
*/
static
return CMD_RET_USAGE;
dev = (BYTE) strtoul(argv[1], 0, 10);
- res = disk_status(dev);
- printf_P(PSTR("disk_status=%.2x\n"), res);
- if ((res & STA_NODISK) == 0) {
- res = disk_initialize(dev);
+ if (disk_status(dev) & STA_NODISK) {
+ printf_P(PSTR("No Disk\n"));
+ return CMD_RET_FAILURE;
}
+
+ res = disk_initialize(dev);
printf_P(PSTR("rc=%.2x\n"), res);
- if (res) {
+
+ if (res & (STA_NODISK | STA_NOINIT))
return CMD_RET_FAILURE;
- }
return CMD_RET_SUCCESS;
}
/*
- * ds <pd#> - Show disk status
+ * info <pd#> - Show disk info
*
*/
static
-command_ret_t do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+command_ret_t do_info(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
+ DSTATUS res;
BYTE dev;
union {
dev = (BYTE) strtoul(argv[1], 0, 10);
+ res = disk_status(dev);
+ if (res & (STA_NODISK | STA_NOINIT)) {
+ printf_P(res & STA_NODISK ?
+ PSTR("No disk\n") : PSTR("Not initialized\n"));
+ return CMD_RET_FAILURE;
+ }
if (disk_ioctl(dev, GET_SECTOR_COUNT, &dat.ul) == RES_OK)
printf_P(PSTR("Drive size: %lu sectors\n"), dat.ul);
-
if (disk_ioctl(dev, GET_BLOCK_SIZE, &dat.ul) == RES_OK)
printf_P(PSTR("Erase block: %lu sectors\n"), dat.ul);
-
if (disk_ioctl(dev, MMC_GET_TYPE, &dat.uc) == RES_OK)
printf_P(PSTR("Card type: %u\n"), dat.uc);
-
if (disk_ioctl(dev, MMC_GET_CSD, dat.uca) == RES_OK)
dump_ram(dat.uca, 0, 16, "CSD:");
-
if (disk_ioctl(dev, MMC_GET_CID, dat.uca) == RES_OK)
dump_ram(dat.uca, 0, 16, "CID:");
-
if (disk_ioctl(dev, MMC_GET_OCR, dat.uca) == RES_OK)
dump_ram(dat.uca, 0, 4, "OCR:");
-
if (disk_ioctl(dev, MMC_GET_SDSTAT, dat.uca) == RES_OK)
dump_ram(dat.uca, 0, 64, "SD Status:");
- if (disk_ioctl(dev, ATA_GET_MODEL, dat.uca) == RES_OK) {
- dat.uca[40] = '\0';
- printf_P(PSTR("Model: %s\n"), dat.uca);
- }
- if (disk_ioctl(dev, ATA_GET_SN, dat.uca) == RES_OK) {
- dat.uca[20] = '\0'; printf_P(PSTR("S/N: %s\n"), dat.uca);
- }
-
return CMD_RET_SUCCESS;
}
/*
* Disk ioctl
- * dcs <pd#> - CTRL_SYNC
+ * sync <pd#> - CTRL_SYNC
*
*/
static
command_ret_t do_help(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
cmd_tbl_t cmd_sd_sub[] = {
+CMD_TBL_ITEM(
+ status, 2, 1, do_status,
+ "Socket staus",
+ ""
+),
CMD_TBL_ITEM(
init, 2, 1, do_init,
"Initialize disk",
""
),
CMD_TBL_ITEM(
- status, 2, 1, do_status,
- "Disk status",
+ info, 2, 1, do_info,
+ "Disk info",
""
),
CMD_TBL_ITEM(
dump, CONFIG_SYS_MAXARGS, 1, do_dump,
- "Dump sector",
- ""
+ "Dump sector(s)",
+ "<drive> [sector [count ]]"
),
CMD_TBL_ITEM(
read, 2, 1, do_read,
- "read disk sector(s) into meomory",
- "drive [sector [count [memaddr]]]"
+ "Read disk sector(s) into meomory",
+ "<drive> [sector [count [memaddr]]]"
),
CMD_TBL_ITEM(
write, 2, 1, do_write,
- "write sector(s) from meomory to disk",
- "drive [sector [count [memaddr]]]"
+ "Write sector(s) from meomory to disk",
+ "<drive> [sector [count [memaddr]]]"
),
CMD_TBL_ITEM(
sync, 2, 1, do_ioctl_sync,
CMD_TBL_ITEM(
help, CONFIG_SYS_MAXARGS, 1, do_help,
- "print sub command description/usage",
+ "Print sub command description/usage",
"\n"
" - print brief description of all sub commands\n"
"sd help command ...\n"
/* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
{FSTR("?"), CONFIG_SYS_MAXARGS, 1, do_help,
- FSTR("alias for 'help'"),
+ FSTR("Alias for 'help'"),
#ifdef CONFIG_SYS_LONGHELP
FSTR(""),
#endif /* CONFIG_SYS_LONGHELP */