Skip to content

Commit 8311ac5

Browse files
Rasmus Villemoestrini
Rasmus Villemoes
authored andcommitted
cmd: introduce 'write' command
It's almost no extra code to hook up a buddy to the 'read' command. In fact, since the command is passed its own 'struct cmd_tbl', we can use the exact same callback, and let it figure out for itself whether it was invoked as "read" or "write". Reviewed-by: Simon Glass <[email protected]> Signed-off-by: Rasmus Villemoes <[email protected]>
1 parent fca7db5 commit 8311ac5

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

cmd/Kconfig

+5
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,11 @@ config CMD_WDT
15621562
help
15631563
This provides commands to control the watchdog timer devices.
15641564

1565+
config CMD_WRITE
1566+
bool "write - Write binary data to a partition"
1567+
help
1568+
Provides low-level write access to a partition.
1569+
15651570
config CMD_AXI
15661571
bool "axi"
15671572
depends on AXI

cmd/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ obj-$(CONFIG_CMD_PXE) += pxe.o
140140
obj-$(CONFIG_CMD_WOL) += wol.o
141141
obj-$(CONFIG_CMD_QFW) += qfw.o
142142
obj-$(CONFIG_CMD_READ) += read.o
143+
obj-$(CONFIG_CMD_WRITE) += read.o
143144
obj-$(CONFIG_CMD_REGINFO) += reginfo.o
144145
obj-$(CONFIG_CMD_REISER) += reiser.o
145146
obj-$(CONFIG_CMD_REMOTEPROC) += remoteproc.o

cmd/read.c

+22-7
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
#include <mapmem.h>
1414
#include <part.h>
1515

16-
int do_read(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
16+
static int
17+
do_rw(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
1718
{
1819
struct blk_desc *dev_desc = NULL;
1920
struct disk_partition part_info;
2021
ulong offset, limit;
22+
uint blk, cnt, res;
2123
void *addr;
22-
uint blk;
23-
uint cnt;
2424
int part;
2525

2626
if (argc != 6) {
@@ -47,20 +47,35 @@ int do_read(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
4747
}
4848

4949
if (cnt + blk > limit) {
50-
printf("Read out of range\n");
50+
printf("%s out of range\n", cmdtp->name);
5151
return 1;
5252
}
5353

54-
if (blk_dread(dev_desc, offset + blk, cnt, addr) != cnt) {
55-
printf("Error reading blocks\n");
54+
if (IS_ENABLED(CONFIG_CMD_WRITE) && !strcmp(cmdtp->name, "write"))
55+
res = blk_dwrite(dev_desc, offset + blk, cnt, addr);
56+
else
57+
res = blk_dread(dev_desc, offset + blk, cnt, addr);
58+
59+
if (res != cnt) {
60+
printf("%s error\n", cmdtp->name);
5661
return 1;
5762
}
5863

5964
return 0;
6065
}
6166

67+
#ifdef CONFIG_CMD_READ
6268
U_BOOT_CMD(
63-
read, 6, 0, do_read,
69+
read, 6, 0, do_rw,
6470
"Load binary data from a partition",
6571
"<interface> <dev[:part|#partname]> addr blk# cnt"
6672
);
73+
#endif
74+
75+
#ifdef CONFIG_CMD_WRITE
76+
U_BOOT_CMD(
77+
write, 6, 0, do_rw,
78+
"Store binary data to a partition",
79+
"<interface> <dev[:part|#partname]> addr blk# cnt"
80+
);
81+
#endif

0 commit comments

Comments
 (0)