Skip to content

Commit 338b67f

Browse files
xypronsjg20
authored andcommitted
cmd: fix loads, saves on sandbox
The loads and saves commands crash on the sandbox due to illegal memory access. For command line arguments the sandbox uses a virtual address space which does not equal the addresses of the memory allocated with memmap(). Add the missing address translations for the loads and saves commands. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Simon Glass <[email protected]>
1 parent 76e1607 commit 338b67f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

cmd/load.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,17 @@ static ulong load_serial(long offset)
181181
} else
182182
#endif
183183
{
184+
void *dst;
185+
184186
ret = lmb_reserve(&lmb, store_addr, binlen);
185187
if (ret) {
186188
printf("\nCannot overwrite reserved area (%08lx..%08lx)\n",
187189
store_addr, store_addr + binlen);
188190
return ret;
189191
}
190-
memcpy((char *)(store_addr), binbuf, binlen);
192+
dst = map_sysmem(store_addr, binlen);
193+
memcpy(dst, binbuf, binlen);
194+
unmap_sysmem(dst);
191195
lmb_free(&lmb, store_addr, binlen);
192196
}
193197
if ((store_addr) < start_addr)
@@ -350,15 +354,19 @@ static int save_serial(ulong address, ulong count)
350354
if(write_record(SREC3_START)) /* write the header */
351355
return (-1);
352356
do {
353-
if(count) { /* collect hex data in the buffer */
354-
c = *(volatile uchar*)(address + reclen); /* get one byte */
355-
checksum += c; /* accumulate checksum */
357+
volatile uchar *src;
358+
359+
src = map_sysmem(address, count);
360+
if (count) { /* collect hex data in the buffer */
361+
c = src[reclen]; /* get one byte */
362+
checksum += c; /* accumulate checksum */
356363
data[2*reclen] = hex[(c>>4)&0x0f];
357364
data[2*reclen+1] = hex[c & 0x0f];
358365
data[2*reclen+2] = '\0';
359366
++reclen;
360367
--count;
361368
}
369+
unmap_sysmem((void *)src);
362370
if(reclen == SREC_BYTES_PER_RECORD || count == 0) {
363371
/* enough data collected for one record: dump it */
364372
if(reclen) { /* build & write a data record: */

0 commit comments

Comments
 (0)