int source (ulong addr, const char *fit_uname) { ulong len; image_header_t *hdr; ulong *data; int verify; #if defined(CONFIG_FIT) const void* fit_hdr; int noffset; const void *fit_data; size_t fit_len; #endif verify = getenv_yesno ("verify"); switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; if (!image_check_magic (hdr)) { puts ("Bad magic number\n"); return 1; } if (!image_check_hcrc (hdr)) { puts ("Bad header crc\n"); return 1; } if (verify) { if (!image_check_dcrc (hdr)) { puts ("Bad data crc\n"); return 1; } } if (!image_check_type (hdr, IH_TYPE_SCRIPT)) { puts ("Bad image type\n"); return 1; } /* get length of script */ data = (ulong *)image_get_data (hdr); if ((len = uimage_to_cpu (*data)) == 0) { puts ("Empty Script\n"); return 1; } /* * scripts are just multi-image files with one component, seek * past the zero-terminated sequence of image lengths to get * to the actual image data */ while (*data++); break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: if (fit_uname == NULL) { puts ("No FIT subimage unit name\n"); return 1; } fit_hdr = (const void *)addr; if (!fit_check_format (fit_hdr)) { puts ("Bad FIT image format\n"); return 1; } /* get script component image node offset */ noffset = fit_image_get_node (fit_hdr, fit_uname); if (noffset < 0) { printf ("Can't find '%s' FIT subimage\n", fit_uname); return 1; } if (!fit_image_check_type (fit_hdr, noffset, IH_TYPE_SCRIPT)) { puts ("Not a image image\n"); return 1; } /* verify integrity */ if (verify) { if (!fit_image_check_hashes (fit_hdr, noffset)) { puts ("Bad Data Hash\n"); return 1; } } /* get script subimage data address and length */ if (fit_image_get_data (fit_hdr, noffset, &fit_data, &fit_len)) { puts ("Could not find script subimage data\n"); return 1; } data = (ulong *)fit_data; len = (ulong)fit_len; break; #endif default: puts ("Wrong image format for \"source\" command\n"); return 1; } debug ("** Script length: %ld\n", len); return run_command_list((char *)data, len, 0); }
int fit_image_load(bootm_headers_t *images, const char *prop_name, ulong addr, const char **fit_unamep, const char **fit_uname_configp, int arch, int image_type, int bootstage_id, enum fit_load_op load_op, ulong *datap, ulong *lenp) { int cfg_noffset, noffset; const char *fit_uname; const char *fit_uname_config; const void *fit; const void *buf; size_t size; int type_ok, os_ok; ulong load, data, len; int ret; fit = map_sysmem(addr, 0); fit_uname = fit_unamep ? *fit_unamep : NULL; fit_uname_config = fit_uname_configp ? *fit_uname_configp : NULL; printf("## Loading %s from FIT Image at %08lx ...\n", prop_name, addr); bootstage_mark(bootstage_id + BOOTSTAGE_SUB_FORMAT); if (!fit_check_format(fit)) { printf("Bad FIT %s image format!\n", prop_name); bootstage_error(bootstage_id + BOOTSTAGE_SUB_FORMAT); return -ENOEXEC; } bootstage_mark(bootstage_id + BOOTSTAGE_SUB_FORMAT_OK); if (fit_uname) { /* get ramdisk component image node offset */ bootstage_mark(bootstage_id + BOOTSTAGE_SUB_UNIT_NAME); noffset = fit_image_get_node(fit, fit_uname); } else { /* * no image node unit name, try to get config * node first. If config unit node name is NULL * fit_conf_get_node() will try to find default config node */ bootstage_mark(bootstage_id + BOOTSTAGE_SUB_NO_UNIT_NAME); if (IMAGE_ENABLE_BEST_MATCH && !fit_uname_config) { cfg_noffset = fit_conf_find_compat(fit, gd_fdt_blob()); } else { cfg_noffset = fit_conf_get_node(fit, fit_uname_config); } if (cfg_noffset < 0) { puts("Could not find configuration node\n"); bootstage_error(bootstage_id + BOOTSTAGE_SUB_NO_UNIT_NAME); return -ENOENT; } fit_uname_config = fdt_get_name(fit, cfg_noffset, NULL); printf(" Using '%s' configuration\n", fit_uname_config); if (image_type == IH_TYPE_KERNEL) { /* Remember (and possibly verify) this config */ images->fit_uname_cfg = fit_uname_config; if (IMAGE_ENABLE_VERIFY && images->verify) { puts(" Verifying Hash Integrity ... "); if (!fit_config_verify(fit, cfg_noffset)) { puts("Bad Data Hash\n"); bootstage_error(bootstage_id + BOOTSTAGE_SUB_HASH); return -EACCES; } puts("OK\n"); } bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG); } noffset = fit_conf_get_prop_node(fit, cfg_noffset, prop_name); fit_uname = fit_get_name(fit, noffset, NULL); } if (noffset < 0) { puts("Could not find subimage node\n"); bootstage_error(bootstage_id + BOOTSTAGE_SUB_SUBNODE); return -ENOENT; } printf(" Trying '%s' %s subimage\n", fit_uname, prop_name); ret = fit_image_select(fit, noffset, images->verify); if (ret) { bootstage_error(bootstage_id + BOOTSTAGE_SUB_HASH); return ret; } bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ARCH); if (!fit_image_check_target_arch(fit, noffset)) { puts("Unsupported Architecture\n"); bootstage_error(bootstage_id + BOOTSTAGE_SUB_CHECK_ARCH); return -ENOEXEC; } if (image_type == IH_TYPE_FLATDT && !fit_image_check_comp(fit, noffset, IH_COMP_NONE)) { puts("FDT image is compressed"); return -EPROTONOSUPPORT; } bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL); type_ok = fit_image_check_type(fit, noffset, image_type) || (image_type == IH_TYPE_KERNEL && fit_image_check_type(fit, noffset, IH_TYPE_KERNEL_NOLOAD)); os_ok = image_type == IH_TYPE_FLATDT || fit_image_check_os(fit, noffset, IH_OS_LINUX); if (!type_ok || !os_ok) { printf("No Linux %s %s Image\n", genimg_get_arch_name(arch), genimg_get_type_name(image_type)); bootstage_error(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL); return -EIO; } bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL_OK); /* get image data address and length */ if (fit_image_get_data(fit, noffset, &buf, &size)) { printf("Could not find %s subimage data!\n", prop_name); bootstage_error(bootstage_id + BOOTSTAGE_SUB_GET_DATA); return -ENOENT; } len = (ulong)size; /* verify that image data is a proper FDT blob */ if (image_type == IH_TYPE_FLATDT && fdt_check_header(buf)) { puts("Subimage data is not a FDT"); return -ENOEXEC; } bootstage_mark(bootstage_id + BOOTSTAGE_SUB_GET_DATA_OK); /* * 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; data = map_to_sysmem(vbuf); } if (load_op == FIT_LOAD_IGNORED) { /* Don't load */ } else if (fit_image_get_load(fit, noffset, &load)) { if (load_op == FIT_LOAD_REQUIRED) { printf("Can't get %s subimage load address!\n", prop_name); bootstage_error(bootstage_id + BOOTSTAGE_SUB_LOAD); return -EBADF; } } else { ulong image_start, image_end; ulong load_end; void *dst; /* * move image data to the load address, * make sure we don't overwrite initial image */ image_start = addr; image_end = addr + fit_get_size(fit); load_end = load + len; if (image_type != IH_TYPE_KERNEL && load < image_end && load_end > image_start) { printf("Error: %s overwritten\n", prop_name); return -EXDEV; } printf(" Loading %s from 0x%08lx to 0x%08lx\n", prop_name, data, load); dst = map_sysmem(load, len); memmove(dst, buf, len); data = load; } bootstage_mark(bootstage_id + BOOTSTAGE_SUB_LOAD); *datap = data; *lenp = len; if (fit_unamep) *fit_unamep = (char *)fit_uname; if (fit_uname_configp) *fit_uname_configp = (char *)fit_uname_config; return noffset; }
/** * boot_get_fdt - main fdt handling routine * @argc: command argument count * @argv: command argument list * @arch: architecture (IH_ARCH_...) * @images: pointer to the bootm images structure * @of_flat_tree: pointer to a char* variable, will hold fdt start address * @of_size: pointer to a ulong variable, will hold fdt length * * boot_get_fdt() is responsible for finding a valid flat device tree image. * Curently supported are the following ramdisk sources: * - multicomponent kernel/ramdisk image, * - commandline provided address of decicated ramdisk image. * * returns: * 0, if fdt image was found and valid, or skipped * of_flat_tree and of_size are set to fdt start address and length if * fdt image is found and valid * * 1, if fdt image is found but corrupted * of_flat_tree and of_size are set to 0 if no fdt exists */ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch, bootm_headers_t *images, char **of_flat_tree, ulong *of_size) { #if defined(CONFIG_IMAGE_FORMAT_LEGACY) const image_header_t *fdt_hdr; ulong load, load_end; ulong image_start, image_data, image_end; #endif ulong fdt_addr; char *fdt_blob = NULL; void *buf; #if CONFIG_IS_ENABLED(FIT) const char *fit_uname_config = images->fit_uname_cfg; const char *fit_uname_fdt = NULL; ulong default_addr; int fdt_noffset; #endif const char *select = NULL; int ok_no_fdt = 0; *of_flat_tree = NULL; *of_size = 0; if (argc > 2) select = argv[2]; if (select || genimg_has_config(images)) { #if CONFIG_IS_ENABLED(FIT) if (select) { /* * If the FDT blob comes from the FIT image and the * FIT image address is omitted in the command line * argument, try to use ramdisk or os FIT image * address or default load address. */ if (images->fit_uname_rd) default_addr = (ulong)images->fit_hdr_rd; else if (images->fit_uname_os) default_addr = (ulong)images->fit_hdr_os; else default_addr = load_addr; if (fit_parse_conf(select, default_addr, &fdt_addr, &fit_uname_config)) { debug("* fdt: config '%s' from image at 0x%08lx\n", fit_uname_config, fdt_addr); } else if (fit_parse_subimage(select, default_addr, &fdt_addr, &fit_uname_fdt)) { debug("* fdt: subimage '%s' from image at 0x%08lx\n", fit_uname_fdt, fdt_addr); } else #endif { fdt_addr = simple_strtoul(select, NULL, 16); debug("* fdt: cmdline image address = 0x%08lx\n", fdt_addr); } #if CONFIG_IS_ENABLED(FIT) } else { /* use FIT configuration provided in first bootm * command argument */ fdt_addr = map_to_sysmem(images->fit_hdr_os); fdt_noffset = fit_get_node_from_config(images, FIT_FDT_PROP, fdt_addr); if (fdt_noffset == -ENOENT) return 0; else if (fdt_noffset < 0) return 1; } #endif debug("## Checking for 'FDT'/'FDT Image' at %08lx\n", fdt_addr); /* * Check if there is an FDT image at the * address provided in the second bootm argument * check image type, for FIT images get a FIT node. */ buf = map_sysmem(fdt_addr, 0); switch (genimg_get_format(buf)) { #if defined(CONFIG_IMAGE_FORMAT_LEGACY) case IMAGE_FORMAT_LEGACY: /* verify fdt_addr points to a valid image header */ printf("## Flattened Device Tree from Legacy Image at %08lx\n", fdt_addr); fdt_hdr = image_get_fdt(fdt_addr); if (!fdt_hdr) goto no_fdt; /* * move image data to the load address, * make sure we don't overwrite initial image */ image_start = (ulong)fdt_hdr; image_data = (ulong)image_get_data(fdt_hdr); image_end = image_get_image_end(fdt_hdr); load = image_get_load(fdt_hdr); load_end = load + image_get_data_size(fdt_hdr); if (load == image_start || load == image_data) { fdt_addr = load; break; } if ((load < image_end) && (load_end > image_start)) { fdt_error("fdt overwritten"); goto error; } debug(" Loading FDT from 0x%08lx to 0x%08lx\n", image_data, load); memmove((void *)load, (void *)image_data, image_get_data_size(fdt_hdr)); fdt_addr = load; break; #endif case IMAGE_FORMAT_FIT: /* * This case will catch both: new uImage format * (libfdt based) and raw FDT blob (also libfdt * based). */ #if CONFIG_IS_ENABLED(FIT) /* check FDT blob vs FIT blob */ if (fit_check_format(buf)) { ulong load, len; fdt_noffset = boot_get_fdt_fit(images, fdt_addr, &fit_uname_fdt, &fit_uname_config, arch, &load, &len); images->fit_hdr_fdt = map_sysmem(fdt_addr, 0); images->fit_uname_fdt = fit_uname_fdt; images->fit_noffset_fdt = fdt_noffset; fdt_addr = load; break; } else #endif { /* * FDT blob */ debug("* fdt: raw FDT blob\n"); printf("## Flattened Device Tree blob at %08lx\n", (long)fdt_addr); } break; default: puts("ERROR: Did not find a cmdline Flattened Device Tree\n"); goto no_fdt; } printf(" Booting using the fdt blob at %#08lx\n", fdt_addr); fdt_blob = map_sysmem(fdt_addr, 0); } else if (images->legacy_hdr_valid && image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) { ulong fdt_data, fdt_len; /* * Now check if we have a legacy multi-component image, * get second entry data start address and len. */ printf("## Flattened Device Tree from multi component Image at %08lX\n", (ulong)images->legacy_hdr_os); image_multi_getimg(images->legacy_hdr_os, 2, &fdt_data, &fdt_len); if (fdt_len) { fdt_blob = (char *)fdt_data; printf(" Booting using the fdt at 0x%p\n", fdt_blob); if (fdt_check_header(fdt_blob) != 0) { fdt_error("image is not a fdt"); goto error; } if (fdt_totalsize(fdt_blob) != fdt_len) { fdt_error("fdt size != image size"); goto error; } } else { debug("## No Flattened Device Tree\n"); goto no_fdt; } } else { debug("## No Flattened Device Tree\n"); goto no_fdt; } *of_flat_tree = fdt_blob; *of_size = fdt_totalsize(fdt_blob); debug(" of_flat_tree at 0x%08lx size 0x%08lx\n", (ulong)*of_flat_tree, *of_size); return 0; no_fdt: ok_no_fdt = 1; error: *of_flat_tree = NULL; *of_size = 0; if (!select && ok_no_fdt) { debug("Continuing to boot without FDT\n"); return 0; } return 1; }
static int ait_menu_check_image(void) { char *s; unsigned long fit_addr; void *addr; int format; char *desc; char *subtype; int images_noffset; int noffset; int ndepth; int count = 0; int ret; int i; int found_uboot = -1; int found_ramdisk = -1; memset(imgs, 0, sizeof(imgs)); s = getenv("fit_addr_r"); fit_addr = s ? (unsigned long)simple_strtol(s, NULL, 16) : \ CONFIG_BOARD_IMG_ADDR_R; addr = (void *)fit_addr; /* check if it is a FIT image */ format = genimg_get_format(addr); if (format != IMAGE_FORMAT_FIT) return -EINVAL; if (!fit_check_format(addr)) return -EINVAL; /* print the FIT description */ ret = fit_get_desc(addr, 0, &desc); printf("FIT description: "); if (ret) printf("unavailable\n"); else printf("%s\n", desc); /* find images */ images_noffset = fdt_path_offset(addr, FIT_IMAGES_PATH); if (images_noffset < 0) { printf("Can't find images parent node '%s' (%s)\n", FIT_IMAGES_PATH, fdt_strerror(images_noffset)); return -EINVAL; } /* Process its subnodes, print out component images details */ for (ndepth = 0, count = 0, noffset = fdt_next_node(addr, images_noffset, &ndepth); (noffset >= 0) && (ndepth > 0); noffset = fdt_next_node(addr, noffset, &ndepth)) { if (ndepth == 1) { /* * Direct child node of the images parent node, * i.e. component image node. */ printf("Image %u (%s)\n", count, fit_get_name(addr, noffset, NULL)); fit_image_print(addr, noffset, ""); fit_image_get_type(addr, noffset, &imgs[count].type); /* Mandatory properties */ ret = fit_get_desc(addr, noffset, &desc); printf("Description: "); if (ret) printf("unavailable\n"); else printf("%s\n", desc); ret = fit_get_subtype(addr, noffset, &subtype); printf("Subtype: "); if (ret) { printf("unavailable\n"); } else { imgs[count].subtype = ait_subtype_nr(subtype); printf("%s %d\n", subtype, imgs[count].subtype); } sprintf(imgs[count].desc, "%s", desc); ret = fit_image_get_data(addr, noffset, &imgs[count].data, &imgs[count].size); printf("Data Size: "); if (ret) printf("unavailable\n"); else genimg_print_size(imgs[count].size); printf("Data @ %p\n", imgs[count].data); count++; } } for (i = 0; i < count; i++) { if (imgs[i].subtype == FIT_SUBTYPE_UBOOT_IMAGE) found_uboot = i; if (imgs[i].type == IH_TYPE_RAMDISK) { found_ramdisk = i; imgs[i].subtype = FIT_SUBTYPE_RAMDISK_IMAGE; } } /* dvn_* env var update, if the FIT descriptors are different */ if (found_uboot >= 0) { s = getenv("dvn_boot_vers"); if (s) { ret = strcmp(s, imgs[found_uboot].desc); if (ret != 0) { setenv("x_dvn_boot_vers", imgs[found_uboot].desc); } else { found_uboot = -1; printf("no new uboot version\n"); } } else { setenv("dvn_boot_vers", imgs[found_uboot].desc); } } if (found_ramdisk >= 0) { s = getenv("dvn_app_vers"); if (s) { ret = strcmp(s, imgs[found_ramdisk].desc); if (ret != 0) { setenv("x_dvn_app_vers", imgs[found_ramdisk].desc); } else { found_ramdisk = -1; printf("no new ramdisk version\n"); } } else { setenv("dvn_app_vers", imgs[found_ramdisk].desc); } } if ((found_uboot == -1) && (found_ramdisk == -1)) return -EINVAL; return 0; }
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]); }
/* command form: * fpga <op> <device number> <data addr> <datasize> * where op is 'load', 'dump', or 'info' * If there is no device number field, the fpga environment variable is used. * If there is no data addr field, the fpgadata environment variable is used. * The info command requires no data address field. */ int do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { int op, dev = FPGA_INVALID_DEVICE; size_t data_size = 0; void *fpga_data = NULL; char *devstr = getenv ("fpga"); char *datastr = getenv ("fpgadata"); int rc = FPGA_FAIL; int wrong_parms = 0; #if defined (CONFIG_FIT) const char *fit_uname = NULL; ulong fit_addr; #endif if (devstr) dev = (int) simple_strtoul (devstr, NULL, 16); if (datastr) fpga_data = (void *) simple_strtoul (datastr, NULL, 16); switch (argc) { case 5: /* fpga <op> <dev> <data> <datasize> */ data_size = simple_strtoul (argv[4], NULL, 16); case 4: /* fpga <op> <dev> <data> */ #if defined(CONFIG_FIT) if (fit_parse_subimage (argv[3], (ulong)fpga_data, &fit_addr, &fit_uname)) { fpga_data = (void *)fit_addr; debug("* fpga: subimage '%s' from FIT image " "at 0x%08lx\n", fit_uname, fit_addr); } else #endif { fpga_data = (void *) simple_strtoul (argv[3], NULL, 16); debug("* fpga: cmdline image address = 0x%08lx\n", (ulong)fpga_data); } debug("%s: fpga_data = 0x%x\n", __func__, (uint) fpga_data); case 3: /* fpga <op> <dev | data addr> */ dev = (int) simple_strtoul (argv[2], NULL, 16); debug("%s: device = %d\n", __func__, dev); /* FIXME - this is a really weak test */ if ((argc == 3) && (dev > fpga_count ())) { /* must be buffer ptr */ debug("%s: Assuming buffer pointer in arg 3\n", __func__); #if defined(CONFIG_FIT) if (fit_parse_subimage (argv[2], (ulong)fpga_data, &fit_addr, &fit_uname)) { fpga_data = (void *)fit_addr; debug("* fpga: subimage '%s' from FIT image " "at 0x%08lx\n", fit_uname, fit_addr); } else #endif { fpga_data = (void *) dev; debug("* fpga: cmdline image address = " "0x%08lx\n", (ulong)fpga_data); } debug("%s: fpga_data = 0x%x\n", __func__, (uint) fpga_data); dev = FPGA_INVALID_DEVICE; /* reset device num */ } case 2: /* fpga <op> */ op = (int) fpga_get_op (argv[1]); break; default: debug("%s: Too many or too few args (%d)\n", __func__, argc); op = FPGA_NONE; /* force usage display */ break; } if (dev == FPGA_INVALID_DEVICE) { puts("FPGA device not specified\n"); op = FPGA_NONE; } switch (op) { case FPGA_NONE: case FPGA_INFO: break; case FPGA_LOAD: case FPGA_LOADB: case FPGA_DUMP: if (!fpga_data || !data_size) wrong_parms = 1; break; case FPGA_LOADMK: if (!fpga_data) wrong_parms = 1; break; } if (wrong_parms) { puts("Wrong parameters for FPGA request\n"); op = FPGA_NONE; } switch (op) { case FPGA_NONE: return CMD_RET_USAGE; case FPGA_INFO: rc = fpga_info (dev); break; case FPGA_LOAD: rc = fpga_load (dev, fpga_data, data_size); break; case FPGA_LOADB: rc = fpga_loadbitstream(dev, fpga_data, data_size); break; case FPGA_LOADMK: switch (genimg_get_format (fpga_data)) { case IMAGE_FORMAT_LEGACY: { image_header_t *hdr = (image_header_t *)fpga_data; ulong data; data = (ulong)image_get_data (hdr); data_size = image_get_data_size (hdr); rc = fpga_load (dev, (void *)data, data_size); } break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: { const void *fit_hdr = (const void *)fpga_data; int noffset; const void *fit_data; if (fit_uname == NULL) { puts ("No FIT subimage unit name\n"); return 1; } if (!fit_check_format (fit_hdr)) { puts ("Bad FIT image format\n"); return 1; } /* get fpga component image node offset */ noffset = fit_image_get_node (fit_hdr, fit_uname); if (noffset < 0) { printf ("Can't find '%s' FIT subimage\n", fit_uname); return 1; } /* verify integrity */ if (!fit_image_verify(fit_hdr, noffset)) { puts ("Bad Data Hash\n"); return 1; } /* get fpga subimage data address and length */ if (fit_image_get_data (fit_hdr, noffset, &fit_data, &data_size)) { puts ("Could not find fpga subimage data\n"); return 1; } rc = fpga_load (dev, fit_data, data_size); } break; #endif default: puts ("** Unknown image type\n"); rc = FPGA_FAIL; break; } break; case FPGA_DUMP: rc = fpga_dump (dev, fpga_data, data_size); break; default: printf ("Unknown operation\n"); return CMD_RET_USAGE; } return (rc); }
static int do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { ulong addr = load_addr; ulong dest = 0; ulong data, len; int verify; int part = 0; #if defined(CONFIG_IMAGE_FORMAT_LEGACY) ulong count; image_header_t *hdr = NULL; #endif #if defined(CONFIG_FIT) const char *uname = NULL; const void* fit_hdr; int noffset; const void *fit_data; size_t fit_len; #endif #ifdef CONFIG_GZIP uint unc_len = CONFIG_SYS_XIMG_LEN; #endif uint8_t comp; verify = env_get_yesno("verify"); if (argc > 1) { addr = simple_strtoul(argv[1], NULL, 16); } if (argc > 2) { part = simple_strtoul(argv[2], NULL, 16); #if defined(CONFIG_FIT) uname = argv[2]; #endif } if (argc > 3) { dest = simple_strtoul(argv[3], NULL, 16); } switch (genimg_get_format((void *)addr)) { #if defined(CONFIG_IMAGE_FORMAT_LEGACY) case IMAGE_FORMAT_LEGACY: printf("## Copying part %d from legacy image " "at %08lx ...\n", part, addr); hdr = (image_header_t *)addr; if (!image_check_magic(hdr)) { printf("Bad Magic Number\n"); return 1; } if (!image_check_hcrc(hdr)) { printf("Bad Header Checksum\n"); return 1; } #ifdef DEBUG image_print_contents(hdr); #endif if (!image_check_type(hdr, IH_TYPE_MULTI) && !image_check_type(hdr, IH_TYPE_SCRIPT)) { printf("Wrong Image Type for %s command\n", cmdtp->name); return 1; } comp = image_get_comp(hdr); if ((comp != IH_COMP_NONE) && (argc < 4)) { printf("Must specify load address for %s command " "with compressed image\n", cmdtp->name); return 1; } if (verify) { printf(" Verifying Checksum ... "); if (!image_check_dcrc(hdr)) { printf("Bad Data CRC\n"); return 1; } printf("OK\n"); } count = image_multi_count(hdr); if (part >= count) { printf("Bad Image Part\n"); return 1; } image_multi_getimg(hdr, part, &data, &len); break; #endif #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: if (uname == NULL) { puts("No FIT subimage unit name\n"); return 1; } printf("## Copying '%s' subimage from FIT image " "at %08lx ...\n", uname, addr); fit_hdr = (const void *)addr; if (!fit_check_format(fit_hdr)) { puts("Bad FIT image format\n"); return 1; } /* get subimage node offset */ noffset = fit_image_get_node(fit_hdr, uname); if (noffset < 0) { printf("Can't find '%s' FIT subimage\n", uname); return 1; } if (!fit_image_check_comp(fit_hdr, noffset, IH_COMP_NONE) && (argc < 4)) { printf("Must specify load address for %s command " "with compressed image\n", cmdtp->name); return 1; } /* verify integrity */ if (verify) { if (!fit_image_verify(fit_hdr, noffset)) { puts("Bad Data Hash\n"); return 1; } } /* get subimage/external data address and length */ if (fit_image_get_data_and_size(fit_hdr, noffset, &fit_data, &fit_len)) { puts("Could not find script subimage data\n"); return 1; } if (fit_image_get_comp(fit_hdr, noffset, &comp)) { puts("Could not find script subimage " "compression type\n"); return 1; } data = (ulong)fit_data; len = (ulong)fit_len; break; #endif default: puts("Invalid image type for imxtract\n"); return 1; } if (argc > 3) { switch (comp) { case IH_COMP_NONE: #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) { size_t l = len; size_t tail; void *to = (void *) dest; void *from = (void *)data; printf(" Loading part %d ... ", part); while (l > 0) { tail = (l > CHUNKSZ) ? CHUNKSZ : l; WATCHDOG_RESET(); memmove(to, from, tail); to += tail; from += tail; l -= tail; } } #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ printf(" Loading part %d ... ", part); memmove((char *) dest, (char *)data, len); #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ break; #ifdef CONFIG_GZIP case IH_COMP_GZIP: printf(" Uncompressing part %d ... ", part); if (gunzip((void *) dest, unc_len, (uchar *) data, &len) != 0) { puts("GUNZIP ERROR - image not loaded\n"); return 1; } break; #endif #if defined(CONFIG_BZIP2) && defined(CONFIG_IMAGE_FORMAT_LEGACY) case IH_COMP_BZIP2: { int i; printf(" Uncompressing part %d ... ", part); /* * If we've got less than 4 MB of malloc() * space, use slower decompression algorithm * which requires at most 2300 KB of memory. */ i = BZ2_bzBuffToBuffDecompress( map_sysmem(ntohl(hdr->ih_load), 0), &unc_len, (char *)data, len, CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0); if (i != BZ_OK) { printf("BUNZIP2 ERROR %d - " "image not loaded\n", i); return 1; } } break; #endif /* CONFIG_BZIP2 */ default: printf("Unimplemented compression type %d\n", comp); return 1; } puts("OK\n"); } flush_cache(dest, ALIGN(len, ARCH_DMA_MINALIGN)); env_set_hex("fileaddr", data); env_set_hex("filesize", len); return 0; }
int autoscript (ulong addr, const char *fit_uname) { ulong len; image_header_t *hdr; ulong *data; char *cmd; int rcode = 0; int verify; #if defined(CONFIG_FIT) const void* fit_hdr; int noffset; const void *fit_data; size_t fit_len; #endif verify = getenv_yesno ("verify"); switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; if (!image_check_magic (hdr)) { puts ("Bad magic number\n"); return 1; } if (!image_check_hcrc (hdr)) { puts ("Bad header crc\n"); return 1; } if (verify) { if (!image_check_dcrc (hdr)) { puts ("Bad data crc\n"); return 1; } } if (!image_check_type (hdr, IH_TYPE_SCRIPT)) { puts ("Bad image type\n"); return 1; } /* get length of script */ data = (ulong *)image_get_data (hdr); if ((len = uimage_to_cpu (*data)) == 0) { puts ("Empty Script\n"); return 1; } /* * scripts are just multi-image files with one component, seek * past the zero-terminated sequence of image lengths to get * to the actual image data */ while (*data++); break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: if (fit_uname == NULL) { puts ("No FIT subimage unit name\n"); return 1; } fit_hdr = (const void *)addr; if (!fit_check_format (fit_hdr)) { puts ("Bad FIT image format\n"); return 1; } /* get script component image node offset */ noffset = fit_image_get_node (fit_hdr, fit_uname); if (noffset < 0) { printf ("Can't find '%s' FIT subimage\n", fit_uname); return 1; } if (!fit_image_check_type (fit_hdr, noffset, IH_TYPE_SCRIPT)) { puts ("Not a image image\n"); return 1; } /* verify integrity */ if (verify) { if (!fit_image_check_hashes (fit_hdr, noffset)) { puts ("Bad Data Hash\n"); return 1; } } /* get script subimage data address and length */ if (fit_image_get_data (fit_hdr, noffset, &fit_data, &fit_len)) { puts ("Could not find script subimage data\n"); return 1; } data = (ulong *)fit_data; len = (ulong)fit_len; break; #endif default: puts ("Wrong image format for autoscript\n"); return 1; } debug ("** Script length: %ld\n", len); if ((cmd = malloc (len + 1)) == NULL) { return 1; } /* make sure cmd is null terminated */ memmove (cmd, (char *)data, len); *(cmd + len) = 0; #ifdef CFG_HUSH_PARSER /*?? */ rcode = parse_string_outer (cmd, FLAG_PARSE_SEMICOLON); #else { char *line = cmd; char *next = cmd; /* * break into individual lines, * and execute each line; * terminate on error. */ while (*next) { if (*next == '\n') { *next = '\0'; /* run only non-empty commands */ if ((next - line) > 1) { debug ("** exec: \"%s\"\n", line); if (run_command (line, 0) < 0) { rcode = 1; break; } } line = next + 1; } ++next; } } #endif free (cmd); return rcode; }
int update_tftp(ulong addr) { char *filename, *env_addr; int images_noffset, ndepth, noffset; ulong update_addr, update_fladdr, update_size; void *fit; int ret = 0; /* use already present image */ if (addr) goto got_update_file; printf("Auto-update from TFTP: "); /* get the file name of the update file */ filename = getenv(UPDATE_FILE_ENV); if (filename == NULL) { printf("failed, env. variable '%s' not found\n", UPDATE_FILE_ENV); return 1; } printf("trying update file '%s'\n", filename); /* get load address of downloaded update file */ if ((env_addr = getenv("loadaddr")) != NULL) addr = simple_strtoul(env_addr, NULL, 16); else addr = CONFIG_UPDATE_LOAD_ADDR; if (update_load(filename, CONFIG_UPDATE_TFTP_MSEC_MAX, CONFIG_UPDATE_TFTP_CNT_MAX, addr)) { printf("Can't load update file, aborting auto-update\n"); return 1; } got_update_file: fit = (void *)addr; if (!fit_check_format((void *)fit)) { printf("Bad FIT format of the update file, aborting " "auto-update\n"); return 1; } /* process updates */ images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); ndepth = 0; noffset = fdt_next_node(fit, images_noffset, &ndepth); while (noffset >= 0 && ndepth > 0) { if (ndepth != 1) goto next_node; printf("Processing update '%s' :", fit_get_name(fit, noffset, NULL)); if (!fit_image_verify(fit, noffset)) { printf("Error: invalid update hash, aborting\n"); ret = 1; goto next_node; } printf("\n"); if (update_fit_getparams(fit, noffset, &update_addr, &update_fladdr, &update_size)) { printf("Error: can't get update parameteres, " "aborting\n"); ret = 1; goto next_node; } if (update_flash(update_addr, update_fladdr, update_size)) { printf("Error: can't flash update, aborting\n"); ret = 1; goto next_node; } next_node: noffset = fdt_next_node(fit, noffset, &ndepth); } return ret; }
/* command form: * fpga <op> <device number> <data addr> <datasize> * where op is 'load', 'dump', or 'info' * If there is no device number field, the fpga environment variable is used. * If there is no data addr field, the fpgadata environment variable is used. * The info command requires no data address field. */ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { int op, dev = FPGA_INVALID_DEVICE; size_t data_size = 0; void *fpga_data = NULL; char *devstr = getenv("fpga"); char *datastr = getenv("fpgadata"); int rc = FPGA_FAIL; int wrong_parms = 0; #if defined(CONFIG_FIT) const char *fit_uname = NULL; ulong fit_addr; #endif #if defined(CONFIG_CMD_FPGA_LOADFS) fpga_fs_info fpga_fsinfo; fpga_fsinfo.fstype = FS_TYPE_ANY; #endif if (devstr) dev = (int) simple_strtoul(devstr, NULL, 16); if (datastr) fpga_data = (void *)simple_strtoul(datastr, NULL, 16); switch (argc) { #if defined(CONFIG_CMD_FPGA_LOADFS) case 9: fpga_fsinfo.blocksize = (unsigned int) simple_strtoul(argv[5], NULL, 16); fpga_fsinfo.interface = argv[6]; fpga_fsinfo.dev_part = argv[7]; fpga_fsinfo.filename = argv[8]; #endif case 5: /* fpga <op> <dev> <data> <datasize> */ data_size = simple_strtoul(argv[4], NULL, 16); case 4: /* fpga <op> <dev> <data> */ #if defined(CONFIG_FIT) if (fit_parse_subimage(argv[3], (ulong)fpga_data, &fit_addr, &fit_uname)) { fpga_data = (void *)fit_addr; debug("* fpga: subimage '%s' from FIT image ", fit_uname); debug("at 0x%08lx\n", fit_addr); } else #endif { fpga_data = (void *)simple_strtoul(argv[3], NULL, 16); debug("* fpga: cmdline image address = 0x%08lx\n", (ulong)fpga_data); } debug("%s: fpga_data = 0x%x\n", __func__, (uint)fpga_data); case 3: /* fpga <op> <dev | data addr> */ dev = (int)simple_strtoul(argv[2], NULL, 16); debug("%s: device = %d\n", __func__, dev); /* FIXME - this is a really weak test */ if ((argc == 3) && (dev > fpga_count())) { /* must be buffer ptr */ debug("%s: Assuming buffer pointer in arg 3\n", __func__); #if defined(CONFIG_FIT) if (fit_parse_subimage(argv[2], (ulong)fpga_data, &fit_addr, &fit_uname)) { fpga_data = (void *)fit_addr; debug("* fpga: subimage '%s' from FIT image ", fit_uname); debug("at 0x%08lx\n", fit_addr); } else #endif { fpga_data = (void *)dev; debug("* fpga: cmdline image addr = 0x%08lx\n", (ulong)fpga_data); } debug("%s: fpga_data = 0x%x\n", __func__, (uint)fpga_data); dev = FPGA_INVALID_DEVICE; /* reset device num */ } case 2: /* fpga <op> */ op = (int)fpga_get_op(argv[1]); break; default: debug("%s: Too many or too few args (%d)\n", __func__, argc); op = FPGA_NONE; /* force usage display */ break; } if (dev == FPGA_INVALID_DEVICE) { puts("FPGA device not specified\n"); op = FPGA_NONE; } switch (op) { case FPGA_NONE: case FPGA_INFO: break; #if defined(CONFIG_CMD_FPGA_LOADFS) case FPGA_LOADFS: /* Blocksize can be zero */ if (!fpga_fsinfo.interface || !fpga_fsinfo.dev_part || !fpga_fsinfo.filename) wrong_parms = 1; #endif case FPGA_LOAD: case FPGA_LOADP: case FPGA_LOADB: case FPGA_LOADBP: case FPGA_DUMP: if (!fpga_data || !data_size) wrong_parms = 1; break; #if defined(CONFIG_CMD_FPGA_LOADMK) case FPGA_LOADMK: if (!fpga_data) wrong_parms = 1; break; #endif } if (wrong_parms) { puts("Wrong parameters for FPGA request\n"); op = FPGA_NONE; } switch (op) { case FPGA_NONE: return CMD_RET_USAGE; case FPGA_INFO: rc = fpga_info(dev); break; case FPGA_LOAD: rc = fpga_load(dev, fpga_data, data_size, BIT_FULL); break; #if defined(CONFIG_CMD_FPGA_LOADP) case FPGA_LOADP: rc = fpga_load(dev, fpga_data, data_size, BIT_PARTIAL); break; #endif case FPGA_LOADB: rc = fpga_loadbitstream(dev, fpga_data, data_size, BIT_FULL); break; #if defined(CONFIG_CMD_FPGA_LOADBP) case FPGA_LOADBP: rc = fpga_loadbitstream(dev, fpga_data, data_size, BIT_PARTIAL); break; #endif #if defined(CONFIG_CMD_FPGA_LOADFS) case FPGA_LOADFS: rc = fpga_fsload(dev, fpga_data, data_size, &fpga_fsinfo); break; #endif #if defined(CONFIG_CMD_FPGA_LOADMK) case FPGA_LOADMK: switch (genimg_get_format(fpga_data)) { #if defined(CONFIG_IMAGE_FORMAT_LEGACY) case IMAGE_FORMAT_LEGACY: { image_header_t *hdr = (image_header_t *)fpga_data; ulong data; uint8_t comp; comp = image_get_comp(hdr); if (comp == IH_COMP_GZIP) { ulong image_buf = image_get_data(hdr); data = image_get_load(hdr); ulong image_size = ~0UL; if (gunzip((void *)data, ~0UL, (void *)image_buf, &image_size) != 0) { puts("GUNZIP: error\n"); return 1; } data_size = image_size; } else { data = (ulong)image_get_data(hdr); data_size = image_get_data_size(hdr); } rc = fpga_load(dev, (void *)data, data_size, BIT_FULL); } break; #endif #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: { const void *fit_hdr = (const void *)fpga_data; int noffset; const void *fit_data; if (fit_uname == NULL) { puts("No FIT subimage unit name\n"); return 1; } if (!fit_check_format(fit_hdr)) { puts("Bad FIT image format\n"); return 1; } /* get fpga component image node offset */ noffset = fit_image_get_node(fit_hdr, fit_uname); if (noffset < 0) { printf("Can't find '%s' FIT subimage\n", fit_uname); return 1; } /* verify integrity */ if (!fit_image_verify(fit_hdr, noffset)) { puts ("Bad Data Hash\n"); return 1; } /* get fpga subimage data address and length */ if (fit_image_get_data(fit_hdr, noffset, &fit_data, &data_size)) { puts("Fpga subimage data not found\n"); return 1; } rc = fpga_load(dev, fit_data, data_size, BIT_FULL); } break; #endif default: puts("** Unknown image type\n"); rc = FPGA_FAIL; break; } break; #endif case FPGA_DUMP: rc = fpga_dump(dev, fpga_data, data_size); break; default: printf("Unknown operation\n"); return CMD_RET_USAGE; } return rc; }
static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand, ulong offset, ulong addr, char *cmd) { int r; char *ep, *s; size_t cnt; image_header_t *hdr; #if defined(CONFIG_FIT) const void *fit_hdr = NULL; #endif s = strchr(cmd, '.'); if (s != NULL && (strcmp(s, ".jffs2") && strcmp(s, ".e") && strcmp(s, ".i"))) { printf("Unknown nand load suffix '%s'\n", s); show_boot_progress(-53); return 1; } printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset); cnt = nand->writesize; r = nand_read_skip_bad(nand, offset, &cnt, (u_char *) addr); if (r) { puts("** Read error\n"); show_boot_progress (-56); return 1; } show_boot_progress (56); switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; show_boot_progress (57); image_print_contents (hdr); cnt = image_get_image_size (hdr); break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: fit_hdr = (const void *)addr; puts ("Fit image detected...\n"); cnt = fit_get_size (fit_hdr); break; #endif default: show_boot_progress (-57); puts ("** Unknown image type\n"); return 1; } show_boot_progress (57); r = nand_read_skip_bad(nand, offset, &cnt, (u_char *) addr); if (r) { puts("** Read error\n"); show_boot_progress (-58); return 1; } show_boot_progress (58); #if defined(CONFIG_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)) { show_boot_progress (-150); puts ("** Bad FIT image format\n"); return 1; } show_boot_progress (151); fit_print_contents (fit_hdr); } #endif /* Loading ok, update default load address */ load_addr = addr; /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) { char *local_args[2]; extern int do_bootm(cmd_tbl_t *, int, int, char *[]); local_args[0] = cmd; local_args[1] = NULL; printf("Automatic boot of image at addr 0x%08lx ...\n", addr); do_bootm(cmdtp, 0, 1, local_args); return 1; } return 0; }
int do_docboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { char *boot_device = NULL; char *ep; int dev; ulong cnt; ulong addr; ulong offset = 0; image_header_t *hdr; int rcode = 0; #if defined(CONFIG_FIT) const void *fit_hdr = NULL; #endif show_boot_progress (34); switch (argc) { case 1: addr = CONFIG_SYS_LOAD_ADDR; boot_device = getenv ("bootdevice"); break; case 2: addr = simple_strtoul(argv[1], NULL, 16); boot_device = getenv ("bootdevice"); break; case 3: addr = simple_strtoul(argv[1], NULL, 16); boot_device = argv[2]; break; case 4: addr = simple_strtoul(argv[1], NULL, 16); boot_device = argv[2]; offset = simple_strtoul(argv[3], NULL, 16); break; default: printf ("Usage:\n%s\n", cmdtp->usage); show_boot_progress (-35); return 1; } show_boot_progress (35); if (!boot_device) { puts ("\n** No boot device **\n"); show_boot_progress (-36); return 1; } show_boot_progress (36); dev = simple_strtoul(boot_device, &ep, 16); if ((dev >= CONFIG_SYS_MAX_DOC_DEVICE) || (doc_dev_desc[dev].ChipID == DOC_ChipID_UNKNOWN)) { printf ("\n** Device %d not available\n", dev); show_boot_progress (-37); return 1; } show_boot_progress (37); printf ("\nLoading from device %d: %s at 0x%lX (offset 0x%lX)\n", dev, doc_dev_desc[dev].name, doc_dev_desc[dev].physadr, offset); if (doc_rw (doc_dev_desc + dev, 1, offset, SECTORSIZE, NULL, (u_char *)addr)) { printf ("** Read error on %d\n", dev); show_boot_progress (-38); return 1; } show_boot_progress (38); switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; image_print_contents (hdr); cnt = image_get_image_size (hdr); break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: fit_hdr = (const void *)addr; puts ("Fit image detected...\n"); cnt = fit_get_size (fit_hdr); break; #endif default: show_boot_progress (-39); puts ("** Unknown image type\n"); return 1; } show_boot_progress (39); cnt -= SECTORSIZE; if (doc_rw (doc_dev_desc + dev, 1, offset + SECTORSIZE, cnt, NULL, (u_char *)(addr+SECTORSIZE))) { printf ("** Read error on %d\n", dev); show_boot_progress (-40); return 1; } show_boot_progress (40); #if defined(CONFIG_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)) { show_boot_progress (-130); puts ("** Bad FIT image format\n"); return 1; } show_boot_progress (131); fit_print_contents (fit_hdr); } #endif /* Loading ok, update default load address */ load_addr = addr; /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; extern int do_bootm (cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", addr); do_bootm (cmdtp, 0, 1, local_args); rcode = 1; } return rcode; }
static int splash_load_fit(struct splash_location *location, u32 bmp_load_addr) { int res; int node_offset; int splash_offset; int splash_size; struct image_header *img_header; const u32 *fit_header; u32 fit_size; const size_t header_size = sizeof(struct image_header); /* Read in image header */ res = splash_storage_read_raw(location, bmp_load_addr, header_size); if (res < 0) return res; img_header = (struct image_header *)bmp_load_addr; fit_size = fdt_totalsize(img_header); /* Read in entire FIT */ fit_header = (const u32 *)(bmp_load_addr + header_size); res = splash_storage_read_raw(location, (u32)fit_header, fit_size); if (res < 0) return res; res = fit_check_format(fit_header); if (!res) { debug("Could not find valid FIT image\n"); return -EINVAL; } node_offset = fit_image_get_node(fit_header, location->name); if (node_offset < 0) { debug("Could not find splash image '%s' in FIT\n", location->name); return -ENOENT; } res = fit_image_get_data_offset(fit_header, node_offset, &splash_offset); if (res < 0) { printf("Failed to load splash image (err=%d)\n", res); return res; } res = fit_image_get_data_size(fit_header, node_offset, &splash_size); if (res < 0) { printf("Failed to load splash image (err=%d)\n", res); return res; } /* Align data offset to 4-byte boundrary */ fit_size = fdt_totalsize(fit_header); fit_size = (fit_size + 3) & ~3; /* Read in the splash data */ location->offset = (location->offset + fit_size + splash_offset); res = splash_storage_read_raw(location, bmp_load_addr , splash_size); if (res < 0) return res; return 0; }
/**************************************************************************** * main routine do_fdcboot */ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type; FDC_COMMAND_STRUCT *pCMD = &cmd; unsigned long addr,imsize; image_header_t *hdr; /* used for fdc boot */ unsigned char boot_drive; int i,nrofblk; char *ep; int rcode = 0; #if defined(CONFIG_FIT) const void *fit_hdr = NULL; #endif switch (argc) { case 1: addr = CONFIG_SYS_LOAD_ADDR; boot_drive=CONFIG_SYS_FDC_DRIVE_NUMBER; break; case 2: addr = simple_strtoul(argv[1], NULL, 16); boot_drive=CONFIG_SYS_FDC_DRIVE_NUMBER; break; case 3: addr = simple_strtoul(argv[1], NULL, 16); boot_drive=simple_strtoul(argv[2], NULL, 10); break; default: return cmd_usage(cmdtp); } /* setup FDC and scan for drives */ if(fdc_setup(boot_drive,pCMD,pFG)==FALSE) { printf("\n** Error in setup FDC **\n"); return 1; } if(fdc_check_drive(pCMD,pFG)==FALSE) { printf("\n** Error in check_drives **\n"); return 1; } if((pCMD->flags&(1<<boot_drive))==0) { /* drive not available */ printf("\n** Drive %d not availabe **\n",boot_drive); return 1; } if((pCMD->flags&(0x10<<boot_drive))==0) { /* no disk inserted */ printf("\n** No disk inserted in drive %d **\n",boot_drive); return 1; } /* ok, we have a valid source */ pCMD->drive=boot_drive; /* read first block */ pCMD->blnr=0; if(fdc_read_data((unsigned char *)addr,1,pCMD,pFG)==FALSE) { printf("\nRead error:"); for(i=0;i<7;i++) printf("result%d: 0x%02X\n",i,pCMD->result[i]); return 1; } switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; image_print_contents (hdr); imsize = image_get_image_size (hdr); break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: fit_hdr = (const void *)addr; puts ("Fit image detected...\n"); imsize = fit_get_size (fit_hdr); break; #endif default: puts ("** Unknown image type\n"); return 1; } nrofblk=imsize/512; if((imsize%512)>0) nrofblk++; printf("Loading %ld Bytes (%d blocks) at 0x%08lx..\n",imsize,nrofblk,addr); pCMD->blnr=0; if(fdc_read_data((unsigned char *)addr,nrofblk,pCMD,pFG)==FALSE) { /* read image block */ printf("\nRead error:"); for(i=0;i<7;i++) printf("result%d: 0x%02X\n",i,pCMD->result[i]); return 1; } printf("OK %ld Bytes loaded.\n",imsize); flush_cache (addr, imsize); #if defined(CONFIG_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)) { puts ("** Bad FIT image format\n"); return 1; } fit_print_contents (fit_hdr); } #endif /* Loading ok, update default load address */ load_addr = addr; /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", addr); do_bootm (cmdtp, 0, 1, local_args); rcode ++; } return rcode; }
static int image_info (ulong addr) { void *hdr = (void *)addr; #if defined(CONFIG_ANDROID_IMG) boot_img_hdr *hdr_andr = (void *) addr; #endif printf ("\n## Checking Image at %08lx ...\n", addr); switch (genimg_get_format (hdr)) { case IMAGE_FORMAT_LEGACY: puts (" Legacy image found\n"); if (!image_check_magic (hdr)) { puts (" Bad Magic Number\n"); return 1; } if (!image_check_hcrc (hdr)) { puts (" Bad Header Checksum\n"); return 1; } image_print_contents (hdr); puts (" Verifying Checksum ... "); if (!image_check_dcrc (hdr)) { puts (" Bad Data CRC\n"); return 1; } puts ("OK\n"); return 0; #if defined(CONFIG_ANDROID_IMG) case IMAGE_FORMAT_ANDROID: puts("ANDROID!\n"); printf ("kernel addr = 0x%x\n",hdr_andr->kernel_addr); printf ("kernel size = 0x%x\n",hdr_andr->kernel_size); printf ("ramdisk addr = 0x%x\n",hdr_andr->ramdisk_addr); printf ("ramdisk size = 0x%x\n",hdr_andr->ramdisk_size); printf ("page size = 0x%x\n", hdr_andr->page_size); return 0; #endif #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: puts (" FIT image found\n"); if (!fit_check_format (hdr)) { puts ("Bad FIT image format!\n"); return 1; } fit_print_contents (hdr); if (!fit_all_image_check_hashes (hdr)) { puts ("Bad hash in FIT image!\n"); return 1; } return 0; #endif default: puts ("Unknown image format!\n"); break; } return 1; }
/** * boot_get_kernel - find kernel image * @os_data: pointer to a ulong variable, will hold os data start address * @os_len: pointer to a ulong variable, will hold os data length * * boot_get_kernel() tries to find a kernel image, verifies its integrity * and locates kernel data. * * returns: * pointer to image header if valid image was found, plus kernel start * address and length, otherwise NULL */ static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], bootm_headers_t *images, ulong *os_data, ulong *os_len) { image_header_t *hdr; ulong img_addr; #if defined(CONFIG_FIT) void *fit_hdr; const char *fit_uname_config = NULL; const char *fit_uname_kernel = NULL; const void *data; size_t len; int cfg_noffset; int os_noffset; #endif /* find out kernel image address */ if (argc < 2) { img_addr = load_addr; debug ("* kernel: default image load address = 0x%08lx\n", load_addr); #if defined(CONFIG_FIT) } else if (fit_parse_conf (argv[1], load_addr, &img_addr, &fit_uname_config)) { debug ("* kernel: config '%s' from image at 0x%08lx\n", fit_uname_config, img_addr); } else if (fit_parse_subimage (argv[1], load_addr, &img_addr, &fit_uname_kernel)) { debug ("* kernel: subimage '%s' from image at 0x%08lx\n", fit_uname_kernel, img_addr); #endif } else { img_addr = simple_strtoul(argv[1], NULL, 16); debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr); } show_boot_progress (1); /* copy from dataflash if needed */ img_addr = genimg_get_image (img_addr); /* check image type, for FIT images get FIT kernel node */ *os_data = *os_len = 0; switch (genimg_get_format ((void *)img_addr)) { case IMAGE_FORMAT_LEGACY: printf ("## Booting kernel from Legacy Image at %08lx ...\n", img_addr); hdr = image_get_kernel (img_addr, images->verify); if (!hdr) return NULL; show_boot_progress (5); /* get os_data and os_len */ switch (image_get_type (hdr)) { case IH_TYPE_KERNEL: *os_data = image_get_data (hdr); *os_len = image_get_data_size (hdr); break; case IH_TYPE_MULTI: image_multi_getimg (hdr, 0, os_data, os_len); break; default: printf ("Wrong Image Type for %s command\n", cmdtp->name); show_boot_progress (-5); return NULL; } /* * copy image header to allow for image overwrites during kernel * decompression. */ memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t)); /* save pointer to image header */ images->legacy_hdr_os = hdr; images->legacy_hdr_valid = 1; show_boot_progress (6); break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: fit_hdr = (void *)img_addr; printf ("## Booting kernel from FIT Image at %08lx ...\n", img_addr); if (!fit_check_format (fit_hdr)) { puts ("Bad FIT kernel image format!\n"); show_boot_progress (-100); return NULL; } show_boot_progress (100); if (!fit_uname_kernel) { /* * no kernel image node unit name, try to get config * node first. If config unit node name is NULL * fit_conf_get_node() will try to find default config node */ show_boot_progress (101); cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config); if (cfg_noffset < 0) { show_boot_progress (-101); return NULL; } /* save configuration uname provided in the first * bootm argument */ images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL); printf (" Using '%s' configuration\n", images->fit_uname_cfg); show_boot_progress (103); os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset); fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL); } else { /* get kernel component image node offset */ show_boot_progress (102); os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel); } if (os_noffset < 0) { show_boot_progress (-103); return NULL; } printf (" Trying '%s' kernel subimage\n", fit_uname_kernel); show_boot_progress (104); if (!fit_check_kernel (fit_hdr, os_noffset, images->verify)) return NULL; /* get kernel image data address and length */ if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) { puts ("Could not find kernel subimage data!\n"); show_boot_progress (-107); return NULL; } show_boot_progress (108); *os_len = len; *os_data = (ulong)data; images->fit_hdr_os = fit_hdr; images->fit_uname_os = fit_uname_kernel; images->fit_noffset_os = os_noffset; break; #endif default: printf ("Wrong Image Format for %s command\n", cmdtp->name); show_boot_progress (-108); return NULL; } debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n", *os_data, *os_len, *os_len); return (void *)img_addr; }
/****************************************************************************** * scsi boot command intepreter. Derived from diskboot */ int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { char *boot_device = NULL; char *ep; int dev, part = 0; ulong addr, cnt; disk_partition_t info; image_header_t *hdr; int rcode = 0; #if defined(CONFIG_FIT) const void *fit_hdr = NULL; #endif switch (argc) { case 1: addr = CONFIG_SYS_LOAD_ADDR; boot_device = getenv ("bootdevice"); break; case 2: addr = simple_strtoul(argv[1], NULL, 16); boot_device = getenv ("bootdevice"); break; case 3: addr = simple_strtoul(argv[1], NULL, 16); boot_device = argv[2]; break; default: cmd_usage(cmdtp); return 1; } if (!boot_device) { puts ("\n** No boot device **\n"); return 1; } dev = simple_strtoul(boot_device, &ep, 16); printf("booting from dev %d\n",dev); if (scsi_dev_desc[dev].type == DEV_TYPE_UNKNOWN) { printf ("\n** Device %d not available\n", dev); return 1; } if (*ep) { if (*ep != ':') { puts ("\n** Invalid boot device, use `dev[:part]' **\n"); return 1; } part = simple_strtoul(++ep, NULL, 16); } if (get_partition_info (&scsi_dev_desc[dev], part, &info)) { printf("error reading partinfo\n"); return 1; } if ((strncmp((char *)(info.type), BOOT_PART_TYPE, sizeof(info.type)) != 0) && (strncmp((char *)(info.type), BOOT_PART_COMP, sizeof(info.type)) != 0)) { printf ("\n** Invalid partition type \"%.32s\"" " (expect \"" BOOT_PART_TYPE "\")\n", info.type); return 1; } printf ("\nLoading from SCSI device %d, partition %d: " "Name: %.32s Type: %.32s\n", dev, part, info.name, info.type); debug ("First Block: %ld, # of blocks: %ld, Block Size: %ld\n", info.start, info.size, info.blksz); if (scsi_read (dev, info.start, 1, (ulong *)addr) != 1) { printf ("** Read error on %d:%d\n", dev, part); return 1; } switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; if (!image_check_hcrc (hdr)) { puts ("\n** Bad Header Checksum **\n"); return 1; } image_print_contents (hdr); cnt = image_get_image_size (hdr); break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: fit_hdr = (const void *)addr; puts ("Fit image detected...\n"); cnt = fit_get_size (fit_hdr); break; #endif default: puts ("** Unknown image type\n"); return 1; } cnt += info.blksz - 1; cnt /= info.blksz; cnt -= 1; if (scsi_read (dev, info.start+1, cnt, (ulong *)(addr+info.blksz)) != cnt) { printf ("** Read error on %d:%d\n", dev, part); return 1; } #if defined(CONFIG_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)) { puts ("** Bad FIT image format\n"); return 1; } fit_print_contents (fit_hdr); } #endif /* Loading ok, update default load address */ load_addr = addr; flush_cache (addr, (cnt+1)*info.blksz); /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; extern int do_bootm (cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", addr); rcode = do_bootm (cmdtp, 0, 1, local_args); } return rcode; }