static ulong get_arg(char *s, int w) { /* * If the parameter starts with a '*' then assume it is a pointer to * the value we want. */ if (s[0] == '*') { ulong *p; ulong addr; ulong val; addr = simple_strtoul(&s[1], NULL, 16); switch (w) { case 1: p = map_sysmem(addr, sizeof(uchar)); val = (ulong)*(uchar *)p; unmap_sysmem(p); return val; case 2: p = map_sysmem(addr, sizeof(ushort)); val = (ulong)*(ushort *)p; unmap_sysmem(p); return val; case 4: default: p = map_sysmem(addr, sizeof(ulong)); val = *p; unmap_sysmem(p); return val; } } else { return simple_strtoul(s, NULL, 16); } }
/* Test that we can use the swapcase device correctly */ static int dm_test_pci_swapcase(struct unit_test_state *uts) { struct udevice *emul, *swap; ulong io_addr, mem_addr; char *ptr; /* Check that asking for the device automatically fires up PCI */ ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul)); ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap)); ut_assert(device_active(swap)); /* First test I/O */ io_addr = dm_pci_read_bar32(swap, 0); outb(2, io_addr); ut_asserteq(2, inb(io_addr)); /* * Now test memory mapping - note we must unmap and remap to cause * the swapcase emulation to see our data and response. */ mem_addr = dm_pci_read_bar32(swap, 1); ptr = map_sysmem(mem_addr, 20); strcpy(ptr, "This is a TesT"); unmap_sysmem(ptr); ptr = map_sysmem(mem_addr, 20); ut_asserteq_str("tHIS IS A tESt", ptr); unmap_sysmem(ptr); return 0; }
int bootz_setup(ulong image, ulong *start, ulong *end) { uint8_t *zimage = map_sysmem(image, 0); struct arm_z_header *arm_hdr = (struct arm_z_header *)zimage; int ret = 0; if (memcmp(zimage + 0x202, "HdrS", 4) == 0) { uint8_t setup_sects = *(zimage + 0x1f1); uint32_t syssize = le32_to_cpu(*(uint32_t *)(zimage + 0x1f4)); *start = 0; *end = (setup_sects + 1) * 512 + syssize * 16; printf("setting up X86 zImage [ %ld - %ld ]\n", *start, *end); } else if (le32_to_cpu(arm_hdr->zi_magic) == LINUX_ARM_ZIMAGE_MAGIC) { *start = le32_to_cpu(arm_hdr->zi_start); *end = le32_to_cpu(arm_hdr->zi_end); printf("setting up ARM zImage [ %ld - %ld ]\n", *start, *end); } else { printf("Unrecognized zImage\n"); ret = 1; } unmap_sysmem((void *)image); return ret; }
int efi_info_get(enum efi_entry_t type, void **datap, int *sizep) { struct efi_entry_hdr *entry; struct efi_info_hdr *info; int ret; if (!gd->arch.table) return -ENODATA; info = map_sysmem(gd->arch.table, 0); if (info->version != EFI_TABLE_VERSION) { ret = -EPROTONOSUPPORT; goto err; } entry = (struct efi_entry_hdr *)((ulong)info + info->hdr_size); while (entry->type != EFIET_END) { if (entry->type == type) { if (entry->addr) *datap = map_sysmem(entry->addr, entry->size); else *datap = entry + 1; *sizep = entry->size; return 0; } entry = (struct efi_entry_hdr *)((ulong)entry + entry->link); } ret = -ENOENT; err: unmap_sysmem(info); return ret; }
static int uniphier_i2c_remove(struct udevice *dev) { struct uniphier_i2c_dev *priv = dev_get_priv(dev); unmap_sysmem(priv->regs); return 0; }
static int uniphier_gpio_remove(struct udevice *dev) { struct uniphier_gpio_priv *priv = dev_get_priv(dev); unmap_sysmem(priv->base); return 0; }
int uniphier_pinctrl_remove(struct udevice *dev) { struct uniphier_pinctrl_priv *priv = dev_get_priv(dev); unmap_sysmem(priv->base); return 0; }
static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA u64 writeval; #else ulong writeval; #endif ulong addr, count; int size; void *buf; ulong bytes; if ((argc < 3) || (argc > 4)) return CMD_RET_USAGE; /* Check for size specification. */ if ((size = cmd_get_data_size(argv[0], 4)) < 1) return 1; /* Address is specified since argc > 1 */ addr = simple_strtoul(argv[1], NULL, 16); addr += base_address; /* Get the value to write. */ #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA writeval = simple_strtoull(argv[2], NULL, 16); #else writeval = simple_strtoul(argv[2], NULL, 16); #endif /* Count ? */ if (argc == 4) { count = simple_strtoul(argv[3], NULL, 16); } else { count = 1; } bytes = size * count; buf = map_sysmem(addr, bytes); while (count-- > 0) { if (size == 4) *((u32 *)buf) = (u32)writeval; #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA else if (size == 8) *((u64 *)buf) = (u64)writeval; #endif else if (size == 2) *((u16 *)buf) = (u16)writeval; else *((u8 *)buf) = (u8)writeval; buf += size; } unmap_sysmem(buf); return 0; }
int uniphier_sd_remove(struct udevice *dev) { struct uniphier_sd_priv *priv = dev_get_priv(dev); unmap_sysmem(priv->regbase); mmc_destroy(priv->mmc); return 0; }
int booti_setup(ulong image, ulong *relocated_addr, ulong *size, bool force_reloc) { struct Image_header *ih; uint64_t dst; uint64_t image_size, text_offset; *relocated_addr = image; ih = (struct Image_header *)map_sysmem(image, 0); if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) { puts("Bad Linux ARM64 Image magic!\n"); return 1; } /* * Prior to Linux commit a2c1d73b94ed, the text_offset field * is of unknown endianness. In these cases, the image_size * field is zero, and we can assume a fixed value of 0x80000. */ if (ih->image_size == 0) { puts("Image lacks image_size field, assuming 16MiB\n"); image_size = 16 << 20; text_offset = 0x80000; } else { image_size = le64_to_cpu(ih->image_size); text_offset = le64_to_cpu(ih->text_offset); } *size = image_size; /* * If bit 3 of the flags field is set, the 2MB aligned base of the * kernel image can be anywhere in physical memory, so respect * images->ep. Otherwise, relocate the image to the base of RAM * since memory below it is not accessible via the linear mapping. */ if (!force_reloc && (le64_to_cpu(ih->flags) & BIT(3))) dst = image - text_offset; else dst = gd->bd->bi_dram[0].start; *relocated_addr = ALIGN(dst, SZ_2M) + text_offset; unmap_sysmem(ih); return 0; }
static int do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong addr, writeval, count; int size; void *buf; ulong bytes; if ((argc < 3) || (argc > 4)) return CMD_RET_USAGE; /* Check for size specification. */ if ((size = cmd_get_data_size(argv[0], 4)) < 1) return 1; /* Address is specified since argc > 1 */ addr = simple_strtoul(argv[1], NULL, 16); addr += base_address; /* Get the value to write. */ writeval = simple_strtoul(argv[2], NULL, 16); /* Count ? */ if (argc == 4) { count = simple_strtoul(argv[3], NULL, 16); } else { count = 1; } bytes = size * count; buf = map_sysmem(addr, bytes); while (count-- > 0) { if (size == 4) *((ulong *)buf) = (ulong)writeval; else if (size == 2) *((ushort *)buf) = (ushort)writeval; else *((u_char *)buf) = (u_char)writeval; buf += size; } unmap_sysmem(buf); return 0; }
static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { long size; unsigned long addr; unsigned long count; block_dev_desc_t *dev_desc = NULL; disk_partition_t info; int dev = 0; int part = 1; void *buf; if (argc < 5) return cmd_usage(cmdtp); part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); if (part < 0) return 1; dev = dev_desc->dev; 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 = simple_strtoul(argv[5], NULL, 16); buf = map_sysmem(addr, count); size = file_fat_write(argv[4], buf, count); unmap_sysmem(buf); if (size == -1) { printf("\n** Unable to write \"%s\" from %s %d:%d **\n", argv[4], argv[1], dev, part); return 1; } printf("%ld bytes written\n", size); return 0; }
/* setup ARMv8 Generic Timer */ int timer_init(void) { void __iomem *base; u32 tmp; base = map_sysmem(CNT_CONTROL_BASE, SZ_4K); /* * Note: * In a system that implements both Secure and Non-secure states, * this register is only writable in Secure state. */ tmp = readl(base + CNTCR); tmp |= CNTCR_EN; writel(tmp, base + CNTCR); unmap_sysmem(base); return 0; }
/** * store_result: Store the resulting sum to an address or variable * * @algo: Hash algorithm being used * @sum: Hash digest (algo->digest_size bytes) * @dest: Destination, interpreted as a hex address if it starts * with * (or allow_env_vars is 0) or otherwise as an * environment variable. * @allow_env_vars: non-zero to permit storing the result to an * variable environment */ static void store_result(struct hash_algo *algo, const u8 *sum, const char *dest, int allow_env_vars) { unsigned int i; int env_var = 0; /* * If environment variables are allowed, then we assume that 'dest' * is an environment variable, unless it starts with *, in which * case we assume it is an address. If not allowed, it is always an * address. This is to support the crc32 command. */ if (allow_env_vars) { if (*dest == '*') dest++; else env_var = 1; } if (env_var) { char str_output[HASH_MAX_DIGEST_SIZE * 2 + 1]; char *str_ptr = str_output; for (i = 0; i < algo->digest_size; i++) { sprintf(str_ptr, "%02x", sum[i]); str_ptr += 2; } str_ptr = '\0'; setenv(dest, str_output); } else { ulong addr; void *buf; addr = simple_strtoul(dest, NULL, 16); buf = map_sysmem(addr, algo->digest_size); memcpy(buf, sum, algo->digest_size); unmap_sysmem(buf); } }
/* * Image booting support */ static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], bootm_headers_t *images) { int ret; struct Image_header *ih; ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, images, 1); /* Setup Linux kernel Image entry point */ if (!argc) { images->ep = load_addr; debug("* kernel: default image load address = 0x%08lx\n", load_addr); } else { images->ep = simple_strtoul(argv[0], NULL, 16); debug("* kernel: cmdline image address = 0x%08lx\n", images->ep); } ret = booti_setup(images); if (ret != 0) return 1; ih = (struct Image_header *)map_sysmem(images->ep, 0); lmb_reserve(&images->lmb, images->ep, le32_to_cpu(ih->image_size)); unmap_sysmem(ih); /* * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not * have a header that provide this informaiton. */ if (bootm_find_images(flag, argc, argv)) return 1; return 0; }
int booti_setup(ulong image, ulong *relocated_addr, ulong *size, bool force_reloc) { struct linux_image_h *lhdr; lhdr = (struct linux_image_h *)map_sysmem(image, 0); if (lhdr->magic != LINUX_RISCV_IMAGE_MAGIC) { puts("Bad Linux RISCV Image magic!\n"); return -EINVAL; } if (lhdr->image_size == 0) { puts("Image lacks image_size field, error!\n"); return -EINVAL; } *size = lhdr->image_size; *relocated_addr = gd->ram_base + lhdr->text_offset; unmap_sysmem(lhdr); return 0; }
static int booti_setup(bootm_headers_t *images) { struct Image_header *ih; uint64_t dst; ih = (struct Image_header *)map_sysmem(images->ep, 0); if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) { puts("Bad Linux ARM64 Image magic!\n"); return 1; } if (ih->image_size == 0) { puts("Image lacks image_size field, assuming 16MiB\n"); ih->image_size = (16 << 20); } /* * If we are not at the correct run-time location, set the new * correct location and then move the image there. */ dst = gd->bd->bi_dram[0].start + le32_to_cpu(ih->text_offset); unmap_sysmem(ih); if (images->ep != dst) { void *src; debug("Moving Image from 0x%lx to 0x%llx\n", images->ep, dst); src = (void *)images->ep; images->ep = dst; memmove((void *)dst, src, le32_to_cpu(ih->image_size)); } return 0; }
/* * Perform a memory test. A more complete alternative test can be * configured using CONFIG_SYS_ALT_MEMTEST. The complete test loops until * interrupted by ctrl-c or by a failure of one of the sub-tests. */ static int do_mem_mtest(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong start, end; vu_long *buf, *dummy; int iteration_limit; int ret; ulong errs = 0; /* number of errors, or -1 if interrupted */ ulong pattern; int iteration; #if defined(CONFIG_SYS_ALT_MEMTEST) const int alt_test = 1; #else const int alt_test = 0; #endif if (argc > 1) start = simple_strtoul(argv[1], NULL, 16); else start = CONFIG_SYS_MEMTEST_START; if (argc > 2) end = simple_strtoul(argv[2], NULL, 16); else end = CONFIG_SYS_MEMTEST_END; if (argc > 3) pattern = (ulong)simple_strtoul(argv[3], NULL, 16); else pattern = 0; if (argc > 4) iteration_limit = (ulong)simple_strtoul(argv[4], NULL, 16); else iteration_limit = 0; printf("Testing %08x ... %08x:\n", (uint)start, (uint)end); debug("%s:%d: start %#08lx end %#08lx\n", __func__, __LINE__, start, end); buf = map_sysmem(start, end - start); dummy = map_sysmem(CONFIG_SYS_MEMTEST_SCRATCH, sizeof(vu_long)); for (iteration = 0; !iteration_limit || iteration < iteration_limit; iteration++) { if (ctrlc()) { errs = -1UL; break; } printf("Iteration: %6d\r", iteration + 1); debug("\n"); if (alt_test) { errs = mem_test_alt(buf, start, end, dummy); } else { errs = mem_test_quick(buf, start, end, pattern, iteration); } if (errs == -1UL) break; } /* * Work-around for eldk-4.2 which gives this warning if we try to * case in the unmap_sysmem() call: * warning: initialization discards qualifiers from pointer target type */ { void *vbuf = (void *)buf; void *vdummy = (void *)dummy; unmap_sysmem(vbuf); unmap_sysmem(vdummy); } if (errs == -1UL) { /* Memory test was aborted - write a newline to finish off */ putc('\n'); ret = 1; } else { printf("Tested %d iteration(s) with %lu errors.\n", iteration, errs); ret = errs != 0; } return ret; /* not reached */ }
static int do_mem_loop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong addr, length, i, bytes; int size; #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA volatile u64 *llp; #endif volatile u32 *longp; volatile u16 *shortp; volatile u8 *cp; const void *buf; if (argc < 3) return CMD_RET_USAGE; /* * Check for a size specification. * Defaults to long if no or incorrect specification. */ if ((size = cmd_get_data_size(argv[0], 4)) < 0) return 1; /* Address is always specified. */ addr = simple_strtoul(argv[1], NULL, 16); /* Length is the number of objects, not number of bytes. */ length = simple_strtoul(argv[2], NULL, 16); bytes = size * length; buf = map_sysmem(addr, bytes); /* We want to optimize the loops to run as fast as possible. * If we have only one object, just run infinite loops. */ if (length == 1) { #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA if (size == 8) { llp = (u64 *)buf; for (;;) i = *llp; } #endif if (size == 4) { longp = (u32 *)buf; for (;;) i = *longp; } if (size == 2) { shortp = (u16 *)buf; for (;;) i = *shortp; } cp = (u8 *)buf; for (;;) i = *cp; } #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA if (size == 8) { for (;;) { llp = (u64 *)buf; i = length; while (i-- > 0) *llp++; } } #endif if (size == 4) { for (;;) { longp = (u32 *)buf; i = length; while (i-- > 0) *longp++; } } if (size == 2) { for (;;) { shortp = (u16 *)buf; i = length; while (i-- > 0) *shortp++; } } for (;;) { cp = (u8 *)buf; i = length; while (i-- > 0) *cp++; } unmap_sysmem(buf); return 0; }
static int do_mem_md(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong addr, length; #if defined(CONFIG_HAS_DATAFLASH) ulong nbytes, linebytes; #endif int size; int rc = 0; /* We use the last specified parameters, unless new ones are * entered. */ addr = dp_last_addr; size = dp_last_size; length = dp_last_length; if (argc < 2) return CMD_RET_USAGE; if ((flag & CMD_FLAG_REPEAT) == 0) { /* New command specified. Check for a size specification. * Defaults to long if no or incorrect specification. */ if ((size = cmd_get_data_size(argv[0], 4)) < 0) return 1; /* Address is specified since argc > 1 */ addr = simple_strtoul(argv[1], NULL, 16); addr += base_address; /* If another parameter, it is the length to display. * Length is the number of objects, not number of bytes. */ if (argc > 2) length = simple_strtoul(argv[2], NULL, 16); } #if defined(CONFIG_HAS_DATAFLASH) /* Print the lines. * * We buffer all read data, so we can make sure data is read only * once, and all accesses are with the specified bus width. */ nbytes = length * size; do { char linebuf[DISP_LINE_LEN]; void* p; linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes; rc = read_dataflash(addr, (linebytes/size)*size, linebuf); p = (rc == DATAFLASH_OK) ? linebuf : (void*)addr; print_buffer(addr, p, size, linebytes/size, DISP_LINE_LEN/size); nbytes -= linebytes; addr += linebytes; if (ctrlc()) { rc = 1; break; } } while (nbytes > 0); #else # if defined(CONFIG_BLACKFIN) /* See if we're trying to display L1 inst */ if (addr_bfin_on_chip_mem(addr)) { char linebuf[DISP_LINE_LEN]; ulong linebytes, nbytes = length * size; do { linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes; memcpy(linebuf, (void *)addr, linebytes); print_buffer(addr, linebuf, size, linebytes/size, DISP_LINE_LEN/size); nbytes -= linebytes; addr += linebytes; if (ctrlc()) { rc = 1; break; } } while (nbytes > 0); } else # endif { ulong bytes = size * length; const void *buf = map_sysmem(addr, bytes); /* Print the lines. */ print_buffer(addr, buf, size, length, DISP_LINE_LEN / size); addr += bytes; unmap_sysmem(buf); } #endif dp_last_addr = addr; dp_last_length = length; dp_last_size = size; return (rc); }
static int do_mem_cp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong addr, dest, count, bytes; int size; const void *src; void *buf; if (argc != 4) return CMD_RET_USAGE; /* Check for size specification. */ if ((size = cmd_get_data_size(argv[0], 4)) < 0) return 1; addr = simple_strtoul(argv[1], NULL, 16); addr += base_address; dest = simple_strtoul(argv[2], NULL, 16); dest += base_address; count = simple_strtoul(argv[3], NULL, 16); if (count == 0) { puts ("Zero length ???\n"); return 1; } #ifndef CONFIG_SYS_NO_FLASH /* check if we are copying to Flash */ if ( (addr2info(dest) != NULL) #ifdef CONFIG_HAS_DATAFLASH && (!addr_dataflash(dest)) #endif ) { int rc; puts ("Copy to Flash... "); rc = flash_write ((char *)addr, dest, count*size); if (rc != 0) { flash_perror (rc); return (1); } puts ("done\n"); return 0; } #endif #ifdef CONFIG_HAS_DATAFLASH /* Check if we are copying from RAM or Flash to DataFlash */ if (addr_dataflash(dest) && !addr_dataflash(addr)){ int rc; puts ("Copy to DataFlash... "); rc = write_dataflash (dest, addr, count*size); if (rc != 1) { dataflash_perror (rc); return (1); } puts ("done\n"); return 0; } /* Check if we are copying from DataFlash to RAM */ if (addr_dataflash(addr) && !addr_dataflash(dest) #ifndef CONFIG_SYS_NO_FLASH && (addr2info(dest) == NULL) #endif ){ int rc; rc = read_dataflash(addr, count * size, (char *) dest); if (rc != 1) { dataflash_perror (rc); return (1); } return 0; } if (addr_dataflash(addr) && addr_dataflash(dest)){ puts ("Unsupported combination of source/destination.\n\r"); return 1; } #endif #ifdef CONFIG_BLACKFIN /* See if we're copying to/from L1 inst */ if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) { memcpy((void *)dest, (void *)addr, count * size); return 0; } #endif bytes = size * count; buf = map_sysmem(dest, bytes); src = map_sysmem(addr, bytes); while (count-- > 0) { if (size == 4) *((u32 *)buf) = *((u32 *)src); #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA else if (size == 8) *((u64 *)buf) = *((u64 *)src); #endif else if (size == 2) *((u16 *)buf) = *((u16 *)src); else *((u8 *)buf) = *((u8 *)src); src += size; buf += size; /* reset watchdog from time to time */ if ((count % (64 << 10)) == 0) WATCHDOG_RESET(); } unmap_sysmem(buf); unmap_sysmem(src); return 0; }
static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong addr1, addr2, count, ngood, bytes; int size; int rcode = 0; const char *type; const void *buf1, *buf2, *base; #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA u64 word1, word2; #else ulong word1, word2; #endif if (argc != 4) return CMD_RET_USAGE; /* Check for size specification. */ if ((size = cmd_get_data_size(argv[0], 4)) < 0) return 1; type = size == 8 ? "double word" : size == 4 ? "word" : size == 2 ? "halfword" : "byte"; addr1 = simple_strtoul(argv[1], NULL, 16); addr1 += base_address; addr2 = simple_strtoul(argv[2], NULL, 16); addr2 += base_address; count = simple_strtoul(argv[3], NULL, 16); #ifdef CONFIG_HAS_DATAFLASH if (addr_dataflash(addr1) | addr_dataflash(addr2)){ puts ("Comparison with DataFlash space not supported.\n\r"); return 0; } #endif #ifdef CONFIG_BLACKFIN if (addr_bfin_on_chip_mem(addr1) || addr_bfin_on_chip_mem(addr2)) { puts ("Comparison with L1 instruction memory not supported.\n\r"); return 0; } #endif bytes = size * count; base = buf1 = map_sysmem(addr1, bytes); buf2 = map_sysmem(addr2, bytes); for (ngood = 0; ngood < count; ++ngood) { if (size == 4) { word1 = *(u32 *)buf1; word2 = *(u32 *)buf2; #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA } else if (size == 8) { word1 = *(u64 *)buf1; word2 = *(u64 *)buf2; #endif } else if (size == 2) { word1 = *(u16 *)buf1; word2 = *(u16 *)buf2; } else { word1 = *(u8 *)buf1; word2 = *(u8 *)buf2; } if (word1 != word2) { ulong offset = buf1 - base; #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*" PRIx64 ")\n", type, (void *)(addr1 + offset), size, word1, type, (void *)(addr2 + offset), size, word2); #else printf("%s at 0x%08lx (%#0*lx) != %s at 0x%08lx (%#0*lx)\n", type, (ulong)(addr1 + offset), size, word1, type, (ulong)(addr2 + offset), size, word2); #endif rcode = 1; break; } buf1 += size; buf2 += size; /* reset watchdog from time to time */ if ((ngood % (64 << 10)) == 0) WATCHDOG_RESET(); } unmap_sysmem(buf1); unmap_sysmem(buf2); printf("Total of %ld %s(s) were the same\n", ngood, type); return rcode; }
/* Modify memory. * * Syntax: * mm{.b, .w, .l, .q} {addr} * nm{.b, .w, .l, .q} {addr} */ static int mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) { ulong addr; #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA u64 i; #else ulong i; #endif int nbytes, size; void *ptr = NULL; if (argc != 2) return CMD_RET_USAGE; bootretry_reset_cmd_timeout(); /* got a good command to get here */ /* We use the last specified parameters, unless new ones are * entered. */ addr = mm_last_addr; size = mm_last_size; if ((flag & CMD_FLAG_REPEAT) == 0) { /* New command specified. Check for a size specification. * Defaults to long if no or incorrect specification. */ if ((size = cmd_get_data_size(argv[0], 4)) < 0) return 1; /* Address is specified since argc > 1 */ addr = simple_strtoul(argv[1], NULL, 16); addr += base_address; } #ifdef CONFIG_HAS_DATAFLASH if (addr_dataflash(addr)){ puts ("Can't modify DataFlash in place. Use cp instead.\n\r"); return 0; } #endif #ifdef CONFIG_BLACKFIN if (addr_bfin_on_chip_mem(addr)) { puts ("Can't modify L1 instruction in place. Use cp instead.\n\r"); return 0; } #endif /* Print the address, followed by value. Then accept input for * the next value. A non-converted value exits. */ do { ptr = map_sysmem(addr, size); printf("%08lx:", addr); if (size == 4) printf(" %08x", *((u32 *)ptr)); #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA else if (size == 8) printf(" %016" PRIx64, *((u64 *)ptr)); #endif else if (size == 2) printf(" %04x", *((u16 *)ptr)); else printf(" %02x", *((u8 *)ptr)); nbytes = cli_readline(" ? "); if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { /* <CR> pressed as only input, don't modify current * location and move to next. "-" pressed will go back. */ if (incrflag) addr += nbytes ? -size : size; nbytes = 1; /* good enough to not time out */ bootretry_reset_cmd_timeout(); } #ifdef CONFIG_BOOT_RETRY_TIME else if (nbytes == -2) { break; /* timed out, exit the command */ } #endif else { char *endp; #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA i = simple_strtoull(console_buffer, &endp, 16); #else i = simple_strtoul(console_buffer, &endp, 16); #endif nbytes = endp - console_buffer; if (nbytes) { /* good enough to not time out */ bootretry_reset_cmd_timeout(); if (size == 4) *((u32 *)ptr) = i; #ifdef CONFIG_SYS_SUPPORT_64BIT_DATA else if (size == 8) *((u64 *)ptr) = i; #endif else if (size == 2) *((u16 *)ptr) = i; else *((u8 *)ptr) = i; if (incrflag) addr += size; } } } while (nbytes); if (ptr) unmap_sysmem(ptr); mm_last_addr = addr; mm_last_size = size; return 0; }
int hash_command(const char *algo_name, int flags, cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong addr, len; if (argc < 2) return CMD_RET_USAGE; addr = simple_strtoul(*argv++, NULL, 16); len = simple_strtoul(*argv++, NULL, 16); if (multi_hash()) { struct hash_algo *algo; u8 output[HASH_MAX_DIGEST_SIZE]; u8 vsum[HASH_MAX_DIGEST_SIZE]; void *buf; if (hash_lookup_algo(algo_name, &algo)) { printf("Unknown hash algorithm '%s'\n", algo_name); return CMD_RET_USAGE; } argc -= 2; if (algo->digest_size > HASH_MAX_DIGEST_SIZE) { puts("HASH_MAX_DIGEST_SIZE exceeded\n"); return 1; } buf = map_sysmem(addr, len); algo->hash_func_ws(buf, len, output, algo->chunk_size); unmap_sysmem(buf); /* Try to avoid code bloat when verify is not needed */ #ifdef CONFIG_HASH_VERIFY if (flags & HASH_FLAG_VERIFY) { #else if (0) { #endif if (!argc) return CMD_RET_USAGE; if (parse_verify_sum(algo, *argv, vsum, flags & HASH_FLAG_ENV)) { printf("ERROR: %s does not contain a valid " "%s sum\n", *argv, algo->name); return 1; } if (memcmp(output, vsum, algo->digest_size) != 0) { int i; show_hash(algo, addr, len, output); printf(" != "); for (i = 0; i < algo->digest_size; i++) printf("%02x", vsum[i]); puts(" ** ERROR **\n"); return 1; } } else { show_hash(algo, addr, len, output); printf("\n"); if (argc) { store_result(algo, output, *argv, flags & HASH_FLAG_ENV); } } /* Horrible code size hack for boards that just want crc32 */ } else { ulong crc; ulong *ptr; crc = crc32_wd(0, (const uchar *)addr, len, CHUNKSZ_CRC32); printf("CRC32 for %08lx ... %08lx ==> %08lx\n", addr, addr + len - 1, crc); if (argc >= 3) { ptr = (ulong *)simple_strtoul(argv[0], NULL, 16); *ptr = crc; } } return 0; }
int uniphier_serial_remove(struct udevice *dev) { unmap_sysmem(uniphier_serial_port(dev)); return 0; }