int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char *filename = "/"; int dev, part; struct blk_desc *dev_desc = NULL; disk_partition_t info; if (argc < 3) return CMD_RET_USAGE; part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); if (part < 0) return 1; if (argc == 4) { filename = argv[3]; } dev = dev_desc->devnum; PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename); reiserfs_set_blk_dev(dev_desc, &info); if (!reiserfs_mount(info.size)) { printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); return 1; } if (reiserfs_ls (filename)) { printf ("** Error reiserfs_ls() **\n"); return 1; }; return 0; }
static int do_zfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { const char *filename = "/@/"; int part; struct blk_desc *dev_desc; disk_partition_t info; struct zfs_device_s vdev; if (argc < 2) return cmd_usage(cmdtp); if (argc == 4) filename = argv[3]; else printf("zfsls %s %s %s\n", argv[1], argv[2], filename); part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); if (part < 0) return 1; zfs_set_blk_dev(&vdev, dev_desc, &info); zfs_ls(&vdev, filename, zfs_print, NULL); return 0; }
static int env_ext4_load(void) { ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); struct blk_desc *dev_desc = NULL; disk_partition_t info; int dev, part; int err; loff_t off; #ifdef CONFIG_MMC if (!strcmp(CONFIG_ENV_EXT4_INTERFACE, "mmc")) mmc_initialize(NULL); #endif part = blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE, CONFIG_ENV_EXT4_DEVICE_AND_PART, &dev_desc, &info, 1); if (part < 0) goto err_env_relocate; dev = dev_desc->devnum; ext4fs_set_blk_dev(dev_desc, &info); if (!ext4fs_mount(info.size)) { printf("\n** Unable to use %s %s for loading the env **\n", CONFIG_ENV_EXT4_INTERFACE, CONFIG_ENV_EXT4_DEVICE_AND_PART); goto err_env_relocate; } err = ext4_read_file(CONFIG_ENV_EXT4_FILE, buf, 0, CONFIG_ENV_SIZE, &off); ext4fs_close(); if (err == -1) { printf("\n** Unable to read \"%s\" from %s%d:%d **\n", CONFIG_ENV_EXT4_FILE, CONFIG_ENV_EXT4_INTERFACE, dev, part); goto err_env_relocate; } return env_import(buf, 1); err_env_relocate: set_default_env(NULL, 0); return -EIO; }
static int env_fat_save(void) { env_t __aligned(ARCH_DMA_MINALIGN) env_new; struct blk_desc *dev_desc = NULL; disk_partition_t info; int dev, part; int err; loff_t size; err = env_export(&env_new); if (err) return err; part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE, CONFIG_ENV_FAT_DEVICE_AND_PART, &dev_desc, &info, 1); if (part < 0) return 1; dev = dev_desc->devnum; if (fat_set_blk_dev(dev_desc, &info) != 0) { /* * This printf is embedded in the messages from env_save that * will calling it. The missing \n is intentional. */ printf("Unable to use %s %d:%d... ", CONFIG_ENV_FAT_INTERFACE, dev, part); return 1; } err = file_fat_write(CONFIG_ENV_FAT_FILE, (void *)&env_new, 0, sizeof(env_t), &size); if (err == -1) { /* * This printf is embedded in the messages from env_save that * will calling it. The missing \n is intentional. */ printf("Unable to write \"%s\" from %s%d:%d... ", CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part); return 1; } return 0; }
static int env_fat_load(void) { ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); struct blk_desc *dev_desc = NULL; disk_partition_t info; int dev, part; int err; part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE, CONFIG_ENV_FAT_DEVICE_AND_PART, &dev_desc, &info, 1); if (part < 0) goto err_env_relocate; dev = dev_desc->devnum; if (fat_set_blk_dev(dev_desc, &info) != 0) { /* * This printf is embedded in the messages from env_save that * will calling it. The missing \n is intentional. */ printf("Unable to use %s %d:%d... ", CONFIG_ENV_FAT_INTERFACE, dev, part); goto err_env_relocate; } err = file_fat_read(CONFIG_ENV_FAT_FILE, buf, CONFIG_ENV_SIZE); if (err == -1) { /* * This printf is embedded in the messages from env_save that * will calling it. The missing \n is intentional. */ printf("Unable to read \"%s\" from %s%d:%d... ", CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part); goto err_env_relocate; } return env_import(buf, 1); err_env_relocate: set_default_env(NULL); return -EIO; }
static int env_ext4_save(void) { env_t env_new; struct blk_desc *dev_desc = NULL; disk_partition_t info; int dev, part; int err; err = env_export(&env_new); if (err) return err; part = blk_get_device_part_str(CONFIG_ENV_EXT4_INTERFACE, CONFIG_ENV_EXT4_DEVICE_AND_PART, &dev_desc, &info, 1); if (part < 0) return 1; dev = dev_desc->devnum; ext4fs_set_blk_dev(dev_desc, &info); if (!ext4fs_mount(info.size)) { printf("\n** Unable to use %s %s for saveenv **\n", CONFIG_ENV_EXT4_INTERFACE, CONFIG_ENV_EXT4_DEVICE_AND_PART); return 1; } err = ext4fs_write(CONFIG_ENV_EXT4_FILE, (void *)&env_new, sizeof(env_t)); ext4fs_close(); if (err == -1) { printf("\n** Unable to write \"%s\" from %s%d:%d **\n", CONFIG_ENV_EXT4_FILE, CONFIG_ENV_EXT4_INTERFACE, dev, part); return 1; } puts("done\n"); return 0; }
static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char *filename = NULL; int dev; int part; ulong addr = 0; disk_partition_t info; struct blk_desc *dev_desc; unsigned long count; const char *addr_str; struct zfs_file zfile; struct zfs_device_s vdev; if (argc < 3) return CMD_RET_USAGE; count = 0; addr = simple_strtoul(argv[3], NULL, 16); filename = env_get("bootfile"); switch (argc) { case 3: addr_str = env_get("loadaddr"); if (addr_str != NULL) addr = simple_strtoul(addr_str, NULL, 16); else addr = CONFIG_SYS_LOAD_ADDR; break; case 4: break; case 5: filename = argv[4]; break; case 6: filename = argv[4]; count = simple_strtoul(argv[5], NULL, 16); break; default: return cmd_usage(cmdtp); } if (!filename) { puts("** No boot file defined **\n"); return 1; } part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); if (part < 0) return 1; dev = dev_desc->devnum; printf("Loading file \"%s\" from %s device %d%c%c\n", filename, argv[1], dev, part ? ':' : ' ', part ? part + '0' : ' '); zfs_set_blk_dev(&vdev, dev_desc, &info); memset(&zfile, 0, sizeof(zfile)); zfile.device = &vdev; if (zfs_open(&zfile, filename)) { printf("** File not found %s **\n", filename); return 1; } if ((count < zfile.size) && (count != 0)) zfile.size = (uint64_t)count; if (zfs_read(&zfile, (char *)addr, zfile.size) != zfile.size) { printf("** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part); zfs_close(&zfile); return 1; } zfs_close(&zfile); /* Loading ok, update default load address */ load_addr = addr; printf("%llu bytes read\n", zfile.size); env_set_hex("filesize", zfile.size); return 0; }
static int ums_init(const char *devtype, const char *devnums_part_str) { char *s, *t, *devnum_part_str, *name; struct blk_desc *block_dev; disk_partition_t info; int partnum; int ret = -1; struct ums *ums_new; s = strdup(devnums_part_str); if (!s) return -1; t = s; ums_count = 0; for (;;) { devnum_part_str = strsep(&t, ","); if (!devnum_part_str) break; partnum = blk_get_device_part_str(devtype, devnum_part_str, &block_dev, &info, 1); if (partnum < 0) goto cleanup; /* Check if the argument is in legacy format. If yes, * expose all partitions by setting the partnum = 0 * e.g. ums 0 mmc 0 */ if (!strchr(devnum_part_str, ':')) partnum = 0; /* f_mass_storage.c assumes SECTOR_SIZE sectors */ if (block_dev->blksz != SECTOR_SIZE) goto cleanup; ums_new = realloc(ums, (ums_count + 1) * sizeof(*ums)); if (!ums_new) goto cleanup; ums = ums_new; /* if partnum = 0, expose all partitions */ if (partnum == 0) { ums[ums_count].start_sector = 0; ums[ums_count].num_sectors = block_dev->lba; } else { ums[ums_count].start_sector = info.start; ums[ums_count].num_sectors = info.size; } ums[ums_count].read_sector = ums_read_sector; ums[ums_count].write_sector = ums_write_sector; name = malloc(UMS_NAME_LEN); if (!name) goto cleanup; snprintf(name, UMS_NAME_LEN, "UMS disk %d", ums_count); ums[ums_count].name = name; ums[ums_count].block_dev = *block_dev; printf("UMS: LUN %d, dev %d, hwpart %d, sector %#x, count %#x\n", ums_count, ums[ums_count].block_dev.devnum, ums[ums_count].block_dev.hwpart, ums[ums_count].start_sector, ums[ums_count].num_sectors); ums_count++; } if (ums_count) ret = 0; cleanup: free(s); if (ret < 0) ums_fini(); return ret; }
int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc, char *const argv[]) { __maybe_unused int dev; int part; ulong addr = CONFIG_SYS_LOAD_ADDR; ulong cnt; disk_partition_t info; #if defined(CONFIG_IMAGE_FORMAT_LEGACY) image_header_t *hdr; #endif struct blk_desc *dev_desc; #if CONFIG_IS_ENABLED(FIT) const void *fit_hdr = NULL; #endif bootstage_mark(BOOTSTAGE_ID_IDE_START); if (argc > 3) { bootstage_error(BOOTSTAGE_ID_IDE_ADDR); return CMD_RET_USAGE; } bootstage_mark(BOOTSTAGE_ID_IDE_ADDR); if (argc > 1) addr = simple_strtoul(argv[1], NULL, 16); bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE); part = blk_get_device_part_str(intf, (argc == 3) ? argv[2] : NULL, &dev_desc, &info, 1); if (part < 0) { bootstage_error(BOOTSTAGE_ID_IDE_TYPE); return 1; } dev = dev_desc->devnum; bootstage_mark(BOOTSTAGE_ID_IDE_TYPE); printf("\nLoading from %s device %d, partition %d: " "Name: %.32s Type: %.32s\n", intf, dev, part, info.name, info.type); debug("First Block: " LBAFU ", # of blocks: " LBAFU ", Block Size: %ld\n", info.start, info.size, info.blksz); if (blk_dread(dev_desc, info.start, 1, (ulong *)addr) != 1) { printf("** Read error on %d:%d\n", dev, part); bootstage_error(BOOTSTAGE_ID_IDE_PART_READ); return 1; } bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ); switch (genimg_get_format((void *) addr)) { #if defined(CONFIG_IMAGE_FORMAT_LEGACY) case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *) addr; bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT); if (!image_check_hcrc(hdr)) { puts("\n** Bad Header Checksum **\n"); bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM); return 1; } bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM); image_print_contents(hdr); cnt = image_get_image_size(hdr); break; #endif #if CONFIG_IS_ENABLED(FIT) case IMAGE_FORMAT_FIT: fit_hdr = (const void *) addr; puts("Fit image detected...\n"); cnt = fit_get_size(fit_hdr); break; #endif default: bootstage_error(BOOTSTAGE_ID_IDE_FORMAT); puts("** Unknown image type\n"); return 1; } cnt += info.blksz - 1; cnt /= info.blksz; cnt -= 1; if (blk_dread(dev_desc, info.start + 1, cnt, (ulong *)(addr + info.blksz)) != cnt) { printf("** Read error on %d:%d\n", dev, part); bootstage_error(BOOTSTAGE_ID_IDE_READ); return 1; } bootstage_mark(BOOTSTAGE_ID_IDE_READ); #if CONFIG_IS_ENABLED(FIT) /* This cannot be done earlier, * we need complete FIT image in RAM first */ if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) { if (!fit_check_format(fit_hdr)) { bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ); puts("** Bad FIT image format\n"); return 1; } bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK); fit_print_contents(fit_hdr); } #endif flush_cache(addr, (cnt+1)*info.blksz); /* Loading ok, update default load address */ load_addr = addr; return bootm_maybe_autostart(cmdtp, argv[0]); }
/****************************************************************************** * Reiserfs boot command intepreter. Derived from diskboot */ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char *filename = NULL; int dev, part; ulong addr = 0, filelen; disk_partition_t info; struct blk_desc *dev_desc = NULL; unsigned long count; char *addr_str; switch (argc) { case 3: addr_str = getenv("loadaddr"); if (addr_str != NULL) { addr = simple_strtoul (addr_str, NULL, 16); } else { addr = CONFIG_SYS_LOAD_ADDR; } filename = getenv ("bootfile"); count = 0; break; case 4: addr = simple_strtoul (argv[3], NULL, 16); filename = getenv ("bootfile"); count = 0; break; case 5: addr = simple_strtoul (argv[3], NULL, 16); filename = argv[4]; count = 0; break; case 6: addr = simple_strtoul (argv[3], NULL, 16); filename = argv[4]; count = simple_strtoul (argv[5], NULL, 16); break; default: return CMD_RET_USAGE; } if (!filename) { puts ("\n** No boot file defined **\n"); return 1; } part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); if (part < 0) return 1; dev = dev_desc->devnum; printf("Loading file \"%s\" from %s device %d%c%c\n", filename, argv[1], dev, part ? ':' : ' ', part ? part + '0' : ' '); reiserfs_set_blk_dev(dev_desc, &info); if (!reiserfs_mount(info.size)) { printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); return 1; } filelen = reiserfs_open(filename); if (filelen < 0) { printf("** File not found %s **\n", filename); return 1; } if ((count < filelen) && (count != 0)) { filelen = count; } if (reiserfs_read((char *)addr, filelen) != filelen) { printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part); return 1; } /* Loading ok, update default load address */ load_addr = addr; printf ("\n%ld bytes read\n", filelen); setenv_hex("filesize", filelen); return filelen; }