Commit c99e87f8 authored by Tom Rini's avatar Tom Rini

Merge branch '2020-10-23-misc-changes'

Highlights:
- Fix a problem with the bootm overlap tests
- Remove duplicated code in fatwrite
- Cleanup our current "misc" command code and add a new one for misc
  class devices.
- Various GPIO fixes
parents 001ab993 16cc5ad0
Pipeline #5132 passed with stages
in 65 minutes and 59 seconds
......@@ -885,7 +885,7 @@ cmd_static_rela = \
tools/relocate-rela $(3) $(4) $$start $$end
else
quiet_cmd_static_rela =
cmd_static_rela =
cmd_static_rela = true
endif
# Always append INPUTS so that arch config.mk's can add custom ones
......@@ -1309,9 +1309,13 @@ init_sp_bss_offset_check: u-boot.dtb FORCE
fi
endif
shell_cmd = { $(echo-cmd) $(cmd_$(1)); }
quiet_cmd_objcopy_uboot = OBJCOPY $@
cmd_objcopy_uboot = $(cmd_objcopy) && $(call shell_cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE)) || rm -f $@
u-boot-nodtb.bin: u-boot FORCE
$(call if_changed,objcopy)
$(call cmd,static_rela,$<,$@,$(CONFIG_SYS_TEXT_BASE))
$(call if_changed,objcopy_uboot)
$(BOARD_SIZE_CHECK)
u-boot.ldr: u-boot
......
......@@ -1025,6 +1025,14 @@ config CMD_LSBLK
Print list of available block device drivers, and for each, the list
of known block devices.
config CMD_MISC
bool "misc"
depends on MISC
help
Enable the command "misc" for accessing miscellaneous devices with
a MISC uclass driver. The command provides listing all MISC devices
as well as read and write functionalities via their drivers.
config CMD_MMC
bool "mmc"
help
......@@ -1708,8 +1716,7 @@ config CMD_RNG
help
Print bytes from the hardware random number generator.
# TODO: rename to CMD_SLEEP
config CMD_MISC
config CMD_SLEEP
bool "sleep"
default y
help
......
......@@ -94,8 +94,9 @@ obj-$(CONFIG_CMD_MEMORY) += mem.o
obj-$(CONFIG_CMD_IO) += io.o
obj-$(CONFIG_CMD_MFSL) += mfsl.o
obj-$(CONFIG_CMD_MII) += mii.o
obj-$(CONFIG_CMD_MDIO) += mdio.o
obj-$(CONFIG_CMD_MISC) += misc.o
obj-$(CONFIG_CMD_MDIO) += mdio.o
obj-$(CONFIG_CMD_SLEEP) += sleep.o
obj-$(CONFIG_CMD_MMC) += mmc.o
obj-$(CONFIG_MP) += mp.o
obj-$(CONFIG_CMD_MTD) += mtd.o
......@@ -141,6 +142,7 @@ obj-$(CONFIG_CMD_SMC) += smccc.o
obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o pxe_utils.o
obj-$(CONFIG_CMD_TERMINAL) += terminal.o
obj-$(CONFIG_CMD_TIME) += time.o
obj-$(CONFIG_CMD_TIMER) += timer.o
obj-$(CONFIG_CMD_TRACE) += trace.o
obj-$(CONFIG_HUSH_PARSER) += test.o
obj-$(CONFIG_CMD_TPM) += tpm-common.o
......
......@@ -98,48 +98,7 @@ U_BOOT_CMD(
static int do_fat_fswrite(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
loff_t size;
int ret;
unsigned long addr;
unsigned long count;
long offset;
struct blk_desc *dev_desc = NULL;
struct disk_partition info;
int dev = 0;
int part = 1;
void *buf;
if (argc < 5)
return cmd_usage(cmdtp);
part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
if (part < 0)
return 1;
dev = dev_desc->devnum;
if (fat_set_blk_dev(dev_desc, &info) != 0) {
printf("\n** Unable to use %s %d:%d for fatwrite **\n",
argv[1], dev, part);
return 1;
}
addr = simple_strtoul(argv[3], NULL, 16);
count = (argc <= 5) ? 0 : simple_strtoul(argv[5], NULL, 16);
/* offset should be a hex, but "-1" is allowed */
offset = (argc <= 6) ? 0 : simple_strtol(argv[6], NULL, 16);
buf = map_sysmem(addr, count);
ret = file_fat_write(argv[4], buf, offset, count, &size);
unmap_sysmem(buf);
if (ret < 0) {
printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
argv[4], argv[1], dev, part);
return 1;
}
printf("%llu bytes written\n", size);
return 0;
return do_save(cmdtp, flag, argc, argv, FS_TYPE_FAT);
}
U_BOOT_CMD(
......
// SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2001
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
* Copyright (c) 2020 Wind River Systems, Inc.
*
* Author:
* Bin Meng <bin.meng@windriver.com>
*
* A command interface to access misc devices with MISC uclass driver APIs.
*/
/*
* Misc functions
*/
#include <common.h>
#include <command.h>
#include <console.h>
#include <linux/delay.h>
static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
#include <dm.h>
#include <errno.h>
#include <misc.h>
enum misc_op {
MISC_OP_READ,
MISC_OP_WRITE
};
static char *misc_op_str[] = {
"read",
"write"
};
static int do_misc_list(struct cmd_tbl *cmdtp, int flag,
int argc, char *const argv[])
{
ulong start = get_timer(0);
ulong mdelay = 0;
ulong delay;
char *frpart;
if (argc != 2)
return CMD_RET_USAGE;
struct udevice *dev;
printf("Device Index Driver\n");
printf("-------------------------------------\n");
for (uclass_first_device(UCLASS_MISC, &dev);
dev;
uclass_next_device(&dev)) {
printf("%-20s %5d %10s\n", dev->name, dev->seq,
dev->driver->name);
}
delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
return 0;
}
frpart = strchr(argv[1], '.');
static int do_misc_op(struct cmd_tbl *cmdtp, int flag,
int argc, char *const argv[], enum misc_op op)
{
int (*misc_op)(struct udevice *, int, void *, int);
struct udevice *dev;
int offset;
void *buf;
int size;
int ret;
ret = uclass_get_device_by_name(UCLASS_MISC, argv[0], &dev);
if (ret) {
printf("Unable to find device %s\n", argv[0]);
return ret;
}
if (frpart) {
uint mult = CONFIG_SYS_HZ / 10;
for (frpart++; *frpart != '\0' && mult > 0; frpart++) {
if (*frpart < '0' || *frpart > '9') {
mdelay = 0;
break;
}
mdelay += (*frpart - '0') * mult;
mult /= 10;
offset = simple_strtoul(argv[1], NULL, 16);
buf = (void *)simple_strtoul(argv[2], NULL, 16);
size = simple_strtoul(argv[3], NULL, 16);
if (op == MISC_OP_READ)
misc_op = misc_read;
else
misc_op = misc_write;
ret = misc_op(dev, offset, buf, size);
if (ret < 0) {
if (ret == -ENOSYS) {
printf("The device does not support %s\n",
misc_op_str[op]);
ret = 0;
}
} else {
if (ret == size)
ret = 0;
else
printf("Partially %s %d bytes\n", misc_op_str[op], ret);
}
delay += mdelay;
while (get_timer(start) < delay) {
if (ctrlc())
return (-1);
return ret;
}
udelay(100);
}
static int do_misc_read(struct cmd_tbl *cmdtp, int flag,
int argc, char *const argv[])
{
return do_misc_op(cmdtp, flag, argc, argv, MISC_OP_READ);
}
return 0;
static int do_misc_write(struct cmd_tbl *cmdtp, int flag,
int argc, char *const argv[])
{
return do_misc_op(cmdtp, flag, argc, argv, MISC_OP_WRITE);
}
U_BOOT_CMD(
sleep , 2, 1, do_sleep,
"delay execution for some time",
"N\n"
" - delay execution for N seconds (N is _decimal_ and can be\n"
" fractional)"
);
static struct cmd_tbl misc_commands[] = {
U_BOOT_CMD_MKENT(list, 0, 1, do_misc_list, "", ""),
U_BOOT_CMD_MKENT(read, 4, 1, do_misc_read, "", ""),
U_BOOT_CMD_MKENT(write, 4, 1, do_misc_write, "", ""),
};
#ifdef CONFIG_CMD_TIMER
static int do_timer(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
static int do_misc(struct cmd_tbl *cmdtp, int flag,
int argc, char *const argv[])
{
static ulong start;
struct cmd_tbl *misc_cmd;
int ret;
if (argc != 2)
if (argc < 2)
return CMD_RET_USAGE;
misc_cmd = find_cmd_tbl(argv[1], misc_commands,
ARRAY_SIZE(misc_commands));
argc -= 2;
argv += 2;
if (!misc_cmd || argc != misc_cmd->maxargs)
return CMD_RET_USAGE;
if (!strcmp(argv[1], "start"))
start = get_timer(0);
ret = misc_cmd->cmd(misc_cmd, flag, argc, argv);
if (!strcmp(argv[1], "get")) {
ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
}
return 0;
return cmd_process_error(misc_cmd, ret);
}
U_BOOT_CMD(
timer, 2, 1, do_timer,
"access the system timer",
"start - Reset the timer reference.\n"
"timer get - Print the time since 'start'."
misc, 6, 1, do_misc,
"Access miscellaneous devices with MISC uclass driver APIs",
"list - list all miscellaneous devices\n"
"misc read name offset addr len - read `len' bytes starting at\n"
" `offset' of device `name'\n"
" to memory at `addr'\n"
"misc write name offset addr len - write `len' bytes starting at\n"
" `offset' of device `name'\n"
" from memory at `addr'"
);
#endif
// SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2001
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*/
#include <common.h>
#include <command.h>
#include <console.h>
#include <linux/delay.h>
static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
ulong start = get_timer(0);
ulong mdelay = 0;
ulong delay;
char *frpart;
if (argc != 2)
return CMD_RET_USAGE;
delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
frpart = strchr(argv[1], '.');
if (frpart) {
uint mult = CONFIG_SYS_HZ / 10;
for (frpart++; *frpart != '\0' && mult > 0; frpart++) {
if (*frpart < '0' || *frpart > '9') {
mdelay = 0;
break;
}
mdelay += (*frpart - '0') * mult;
mult /= 10;
}
}
delay += mdelay;
while (get_timer(start) < delay) {
if (ctrlc())
return (-1);
udelay(100);
}
return 0;
}
U_BOOT_CMD(
sleep , 2, 1, do_sleep,
"delay execution for some time",
"N\n"
" - delay execution for N seconds (N is _decimal_ and can be\n"
" fractional)"
);
// SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2001
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*/
#include <common.h>
#include <command.h>
static int do_timer(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
static ulong start;
if (argc != 2)
return CMD_RET_USAGE;
if (!strcmp(argv[1], "start"))
start = get_timer(0);
if (!strcmp(argv[1], "get")) {
ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
}
return 0;
}
U_BOOT_CMD(
timer, 2, 1, do_timer,
"access the system timer",
"start - Reset the timer reference.\n"
"timer get - Print the time since 'start'."
);
......@@ -256,9 +256,11 @@ int bootm_find_images(int flag, int argc, char *const argv[], ulong start,
/* check if ramdisk overlaps OS image */
if (images.rd_start && (((ulong)images.rd_start >= start &&
(ulong)images.rd_start <= start + size) ||
((ulong)images.rd_end >= start &&
(ulong)images.rd_end <= start + size))) {
(ulong)images.rd_start < start + size) ||
((ulong)images.rd_end > start &&
(ulong)images.rd_end <= start + size) ||
((ulong)images.rd_start < start &&
(ulong)images.rd_end >= start + size))) {
printf("ERROR: RD image overlaps OS image (OS=0x%lx..0x%lx)\n",
start, start + size);
return 1;
......
......@@ -66,7 +66,7 @@ CONFIG_CMD_NAND=y
CONFIG_CMD_DHCP=y
CONFIG_CMD_MII=y
CONFIG_CMD_PING=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_OF_CONTROL=y
CONFIG_ENV_OVERWRITE=y
CONFIG_ENV_IS_IN_FLASH=y
......
......@@ -22,7 +22,7 @@ CONFIG_CMD_SDRAM=y
# CONFIG_CMD_SOURCE is not set
# CONFIG_CMD_SETEXPR is not set
CONFIG_CMD_PING=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_ENV_OVERWRITE=y
CONFIG_ENV_IS_IN_FLASH=y
CONFIG_ENV_ADDR=0xA0020000
......
......@@ -31,7 +31,7 @@ CONFIG_CMD_SDRAM=y
CONFIG_CMD_DHCP=y
CONFIG_CMD_MII=y
CONFIG_CMD_PING=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_ENV_OVERWRITE=y
CONFIG_ENV_IS_IN_FLASH=y
CONFIG_ENV_ADDR=0x40000
......
......@@ -30,7 +30,7 @@ CONFIG_CMD_MEMINFO=y
CONFIG_CMD_GPIO=y
# CONFIG_CMD_LOADS is not set
CONFIG_CMD_NAND=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
# CONFIG_NET is not set
# CONFIG_DM_DEVICE_REMOVE is not set
......
......@@ -32,7 +32,7 @@ CONFIG_CMD_SPI=y
CONFIG_CMD_USB=y
CONFIG_CMD_MII=y
CONFIG_CMD_PING=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_NET_RANDOM_ETHADDR=y
# CONFIG_DM_DEVICE_REMOVE is not set
......
......@@ -32,7 +32,7 @@ CONFIG_CMD_SPI=y
CONFIG_CMD_USB=y
CONFIG_CMD_MII=y
CONFIG_CMD_PING=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_NET_RANDOM_ETHADDR=y
# CONFIG_DM_DEVICE_REMOVE is not set
......
......@@ -30,7 +30,7 @@ CONFIG_CMD_MEMINFO=y
CONFIG_CMD_USB=y
CONFIG_CMD_MII=y
CONFIG_CMD_PING=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_NET_RANDOM_ETHADDR=y
# CONFIG_DM_DEVICE_REMOVE is not set
......
......@@ -32,7 +32,7 @@ CONFIG_CMD_NAND=y
CONFIG_CMD_USB=y
CONFIG_CMD_MII=y
CONFIG_CMD_PING=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_NET_RANDOM_ETHADDR=y
# CONFIG_DM_DEVICE_REMOVE is not set
......
......@@ -30,7 +30,7 @@ CONFIG_CMD_MEMINFO=y
CONFIG_CMD_USB=y
CONFIG_CMD_MII=y
CONFIG_CMD_PING=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_NET_RANDOM_ETHADDR=y
# CONFIG_DM_DEVICE_REMOVE is not set
......
......@@ -46,7 +46,7 @@ CONFIG_CMD_USB=y
CONFIG_CMD_USB_MASS_STORAGE=y
# CONFIG_CMD_ITEST is not set
# CONFIG_CMD_SETEXPR is not set
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
# CONFIG_SPL_DOS_PARTITION is not set
# CONFIG_ISO_PARTITION is not set
CONFIG_EFI_PARTITION_ENTRIES_NUMBERS=64
......
......@@ -33,7 +33,7 @@ CONFIG_CMD_USB=y
CONFIG_CMD_USB_MASS_STORAGE=y
# CONFIG_CMD_ITEST is not set
# CONFIG_CMD_SETEXPR is not set
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
# CONFIG_DOS_PARTITION is not set
# CONFIG_ISO_PARTITION is not set
CONFIG_EFI_PARTITION_ENTRIES_NUMBERS=64
......
......@@ -47,7 +47,7 @@ CONFIG_CMD_USB=y
CONFIG_CMD_USB_MASS_STORAGE=y
# CONFIG_CMD_ITEST is not set
# CONFIG_CMD_SETEXPR is not set
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
# CONFIG_SPL_DOS_PARTITION is not set
# CONFIG_ISO_PARTITION is not set
CONFIG_EFI_PARTITION_ENTRIES_NUMBERS=64
......
......@@ -30,7 +30,7 @@ CONFIG_CMD_MEMINFO=y
CONFIG_CMD_USB=y
CONFIG_CMD_MII=y
CONFIG_CMD_PING=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_NET_RANDOM_ETHADDR=y
# CONFIG_DM_DEVICE_REMOVE is not set
......
......@@ -24,7 +24,7 @@ CONFIG_CMD_I2C=y
# CONFIG_CMD_SETEXPR is not set
# CONFIG_CMD_NFS is not set
CONFIG_CMD_CACHE=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_MP=y
# CONFIG_DOS_PARTITION is not set
# CONFIG_ISO_PARTITION is not set
......
......@@ -26,7 +26,7 @@ CONFIG_CMD_NAND=y
# CONFIG_CMD_SETEXPR is not set
# CONFIG_CMD_NFS is not set
CONFIG_CMD_CACHE=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_MP=y
# CONFIG_ISO_PARTITION is not set
# CONFIG_EFI_PARTITION is not set
......
......@@ -28,7 +28,7 @@ CONFIG_CMD_MEMINFO=y
# CONFIG_CMD_FLASH is not set
# CONFIG_CMD_LOADS is not set
CONFIG_CMD_SPI=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
# CONFIG_NET is not set
# CONFIG_DM_DEVICE_REMOVE is not set
......
......@@ -31,7 +31,7 @@ CONFIG_CMD_MEMINFO=y
CONFIG_CMD_USB=y
CONFIG_CMD_MII=y
CONFIG_CMD_PING=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_NET_RANDOM_ETHADDR=y
# CONFIG_DM_DEVICE_REMOVE is not set
......
......@@ -52,7 +52,7 @@ CONFIG_CMD_MMC=y
CONFIG_CMD_USB=y
CONFIG_CMD_USB_MASS_STORAGE=y
# CONFIG_CMD_ITEST is not set
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
# CONFIG_SPL_DOS_PARTITION is not set
# CONFIG_ISO_PARTITION is not set
CONFIG_EFI_PARTITION_ENTRIES_NUMBERS=64
......
......@@ -32,7 +32,7 @@ CONFIG_CMD_USB=y
CONFIG_CMD_USB_MASS_STORAGE=y
# CONFIG_CMD_NFS is not set
CONFIG_CMD_CACHE=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_CMD_PMIC=y
CONFIG_CMD_REGULATOR=y
CONFIG_CMD_EXT4_WRITE=y
......
......@@ -25,7 +25,7 @@ CONFIG_CMD_MMC=y
CONFIG_CMD_USB_MASS_STORAGE=y
# CONFIG_CMD_NET is not set
CONFIG_CMD_CACHE=y
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_CMD_EXT4_WRITE=y
CONFIG_OF_CONTROL=y
CONFIG_ENV_OVERWRITE=y
......
......@@ -42,7 +42,7 @@ CONFIG_CMD_PART=y
# CONFIG_CMD_SOURCE is not set
# CONFIG_CMD_SETEXPR is not set
# CONFIG_CMD_BLOCK_CACHE is not set
# CONFIG_CMD_MISC is not set
# CONFIG_CMD_SLEEP is not set
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y