mmc: Use map_sysmem() with buffers in the mmc command
The current implementation casts an address to a pointer. Make it more sandbox-friendly by using map_sysmem(). Rename the variable to 'ptr' since it is a pointer, not an address. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
15
cmd/mmc.c
15
cmd/mmc.c
@@ -8,6 +8,7 @@
|
|||||||
#include <command.h>
|
#include <command.h>
|
||||||
#include <console.h>
|
#include <console.h>
|
||||||
#include <display_options.h>
|
#include <display_options.h>
|
||||||
|
#include <mapmem.h>
|
||||||
#include <memalign.h>
|
#include <memalign.h>
|
||||||
#include <mmc.h>
|
#include <mmc.h>
|
||||||
#include <part.h>
|
#include <part.h>
|
||||||
@@ -349,12 +350,12 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int flag,
|
|||||||
{
|
{
|
||||||
struct mmc *mmc;
|
struct mmc *mmc;
|
||||||
u32 blk, cnt, n;
|
u32 blk, cnt, n;
|
||||||
void *addr;
|
void *ptr;
|
||||||
|
|
||||||
if (argc != 4)
|
if (argc != 4)
|
||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
|
|
||||||
addr = (void *)hextoul(argv[1], NULL);
|
ptr = map_sysmem(hextoul(argv[1], NULL), 0);
|
||||||
blk = hextoul(argv[2], NULL);
|
blk = hextoul(argv[2], NULL);
|
||||||
cnt = hextoul(argv[3], NULL);
|
cnt = hextoul(argv[3], NULL);
|
||||||
|
|
||||||
@@ -365,8 +366,9 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int flag,
|
|||||||
printf("MMC read: dev # %d, block # %d, count %d ... ",
|
printf("MMC read: dev # %d, block # %d, count %d ... ",
|
||||||
curr_device, blk, cnt);
|
curr_device, blk, cnt);
|
||||||
|
|
||||||
n = blk_dread(mmc_get_blk_desc(mmc), blk, cnt, addr);
|
n = blk_dread(mmc_get_blk_desc(mmc), blk, cnt, ptr);
|
||||||
printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
|
printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
|
||||||
|
unmap_sysmem(ptr);
|
||||||
|
|
||||||
return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
|
return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
|
||||||
}
|
}
|
||||||
@@ -442,12 +444,12 @@ static int do_mmc_write(struct cmd_tbl *cmdtp, int flag,
|
|||||||
{
|
{
|
||||||
struct mmc *mmc;
|
struct mmc *mmc;
|
||||||
u32 blk, cnt, n;
|
u32 blk, cnt, n;
|
||||||
void *addr;
|
void *ptr;
|
||||||
|
|
||||||
if (argc != 4)
|
if (argc != 4)
|
||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
|
|
||||||
addr = (void *)hextoul(argv[1], NULL);
|
ptr = map_sysmem(hextoul(argv[1], NULL), 0);
|
||||||
blk = hextoul(argv[2], NULL);
|
blk = hextoul(argv[2], NULL);
|
||||||
cnt = hextoul(argv[3], NULL);
|
cnt = hextoul(argv[3], NULL);
|
||||||
|
|
||||||
@@ -462,8 +464,9 @@ static int do_mmc_write(struct cmd_tbl *cmdtp, int flag,
|
|||||||
printf("Error: card is write protected!\n");
|
printf("Error: card is write protected!\n");
|
||||||
return CMD_RET_FAILURE;
|
return CMD_RET_FAILURE;
|
||||||
}
|
}
|
||||||
n = blk_dwrite(mmc_get_blk_desc(mmc), blk, cnt, addr);
|
n = blk_dwrite(mmc_get_blk_desc(mmc), blk, cnt, ptr);
|
||||||
printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
|
printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
|
||||||
|
unmap_sysmem(ptr);
|
||||||
|
|
||||||
return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
|
return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user