summaryrefslogtreecommitdiffstats
path: root/commands/mm.c
diff options
context:
space:
mode:
Diffstat (limited to 'commands/mm.c')
-rw-r--r--commands/mm.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/commands/mm.c b/commands/mm.c
index c7f62fca54..8755a0f2c9 100644
--- a/commands/mm.c
+++ b/commands/mm.c
@@ -1,19 +1,5 @@
-/*
- * Copyright (c) 2013 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: © 2013 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
#include <common.h>
#include <command.h>
@@ -30,7 +16,7 @@
static int do_mem_mm(int argc, char *argv[])
{
- int ret = 0;
+ int ret;
int fd;
char *filename = "/dev/mem";
int mode = O_RWSIZE_4;
@@ -54,8 +40,10 @@ static int do_mem_mm(int argc, char *argv[])
mask = simple_strtoull(argv[optind++], NULL, 0);
fd = open_and_lseek(filename, mode | O_RDWR | O_CREAT, adr);
- if (fd < 0)
+ if (fd < 0) {
+ printf("Could not open \"%s\": %m\n", filename);
return 1;
+ }
switch (mode) {
case O_RWSIZE_1:
@@ -79,9 +67,9 @@ static int do_mem_mm(int argc, char *argv[])
goto out_write;
break;
case O_RWSIZE_4:
+ ret = pread(fd, &val32, 4, adr);
if (ret < 0)
goto out_read;
- ret = pread(fd, &val32, 4, adr);
val32 &= ~mask;
val32 |= (value & mask);
ret = pwrite(fd, &val32, 4, adr);
@@ -89,9 +77,9 @@ static int do_mem_mm(int argc, char *argv[])
goto out_write;
break;
case O_RWSIZE_8:
+ ret = pread(fd, &val64, 8, adr);
if (ret < 0)
goto out_read;
- ret = pread(fd, &val64, 8, adr);
val64 &= ~mask;
val64 |= (value & mask);
ret = pwrite(fd, &val64, 8, adr);
@@ -130,7 +118,7 @@ BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(mm)
.cmd = do_mem_mm,
BAREBOX_CMD_DESC("memory modify with mask")
- BAREBOX_CMD_OPTS("[-bwld] ADDR VAL MASK")
+ BAREBOX_CMD_OPTS("[-bwlq] [-d FILE] ADDR VAL MASK")
BAREBOX_CMD_GROUP(CMD_GRP_MEM)
BAREBOX_CMD_HELP(cmd_mm_help)
BAREBOX_CMD_END