/** * image_get_ramdisk - get and verify ramdisk image * @rd_addr: ramdisk image start address * @arch: expected ramdisk architecture * @verify: checksum verification flag * * image_get_ramdisk() returns a pointer to the verified ramdisk image * header. Routine receives image start address and expected architecture * flag. Verification done covers data and header integrity and os/type/arch * fields checking. * * If dataflash support is enabled routine checks for dataflash addresses * and handles required dataflash reads. * * returns: * pointer to a ramdisk image header, if image was found and valid * otherwise, return NULL */ static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch, int verify) { const image_header_t *rd_hdr = (const image_header_t *)rd_addr; if (!image_check_magic(rd_hdr)) { puts("Bad Magic Number\n"); bootstage_error(BOOTSTAGE_ID_RD_MAGIC); return NULL; } if (!image_check_hcrc(rd_hdr)) { puts("Bad Header Checksum\n"); bootstage_error(BOOTSTAGE_ID_RD_HDR_CHECKSUM); return NULL; } bootstage_mark(BOOTSTAGE_ID_RD_MAGIC); image_print_contents(rd_hdr); if (verify) { puts(" Verifying Checksum ... "); if (!image_check_dcrc(rd_hdr)) { puts("Bad Data CRC\n"); bootstage_error(BOOTSTAGE_ID_RD_CHECKSUM); return NULL; } puts("OK\n"); } bootstage_mark(BOOTSTAGE_ID_RD_HDR_CHECKSUM); if (!image_check_os(rd_hdr, IH_OS_LINUX) || !image_check_arch(rd_hdr, arch) || !image_check_type(rd_hdr, IH_TYPE_RAMDISK)) { printf("No Linux %s Ramdisk Image\n", genimg_get_arch_name(arch)); bootstage_error(BOOTSTAGE_ID_RAMDISK); return NULL; } return rd_hdr; }
static int mpl_prg_image(uchar *ld_addr) { unsigned long len; uchar *data; image_header_t *hdr = (image_header_t *)ld_addr; int rc; #if defined(CONFIG_FIT) if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } #endif if (!image_check_magic (hdr)) { puts("Bad Magic Number\n"); return 1; } image_print_contents (hdr); if (!image_check_os (hdr, IH_OS_U_BOOT)) { puts("No U-Boot Image\n"); return 1; } if (!image_check_type (hdr, IH_TYPE_FIRMWARE)) { puts("No Firmware Image\n"); return 1; } if (!image_check_hcrc (hdr)) { puts("Bad Header Checksum\n"); return 1; } puts("Verifying Checksum ... "); if (!image_check_dcrc (hdr)) { puts("Bad Data CRC\n"); return 1; } puts("OK\n"); data = (uchar *)image_get_data (hdr); len = image_get_data_size (hdr); if (image_get_comp (hdr) != IH_COMP_NONE) { uchar *buf; /* reserve space for uncompressed image */ if ((buf = malloc(IMAGE_SIZE)) == NULL) { puts("Insufficient space for decompression\n"); return 1; } switch (image_get_comp (hdr)) { case IH_COMP_GZIP: puts("Uncompressing (GZIP) ... "); rc = gunzip ((void *)(buf), IMAGE_SIZE, data, &len); if (rc != 0) { puts("GUNZIP ERROR\n"); free(buf); return 1; } puts("OK\n"); break; #ifdef CONFIG_BZIP2 case IH_COMP_BZIP2: puts("Uncompressing (BZIP2) ... "); { uint retlen = IMAGE_SIZE; rc = BZ2_bzBuffToBuffDecompress ((char *)(buf), &retlen, (char *)data, len, 0, 0); len = retlen; } if (rc != BZ_OK) { printf ("BUNZIP2 ERROR: %d\n", rc); free(buf); return 1; } puts("OK\n"); break; #endif default: printf ("Unimplemented compression type %d\n", image_get_comp (hdr)); free(buf); return 1; } rc = mpl_prg(buf, len); free(buf); } else { rc = mpl_prg(data, len); } return(rc); }
int bootm_image(const image_header_t *header) { const char * failure = NULL; const char * type_name = NULL; uint32_t load, image_start, image_len; /* Display to standard output the image contents. */ image_print_contents(header); /* Validate the image header and image data CRCs */ puts(" Verifying Checksum ... "); { if (!image_check_hcrc(header)) { failure = "Header Invalid\n"; goto fail; } if (!image_check_dcrc(header)) { failure = "Data Invalid\n"; goto fail; } } puts("OK\n"); /* We ONLY support uncompressed ARM U-Boot firmware images. Check * to make sure that's what we are going to boot. */ if (!image_check_type(header, IH_TYPE_FIRMWARE)) { failure = "Image is not a firmware image\n"; goto fail; } if (!image_check_os(header, IH_OS_U_BOOT)) { failure = "Image is not u-boot firmware\n"; goto fail; } if (image_get_comp(header) != IH_COMP_NONE) { failure = "Image is compressed\n"; goto fail; } if (!image_check_target_arch(header)) { failure = "Image is not built for this processor\n"; goto fail; } type_name = genimg_get_type_name(image_get_type(header)); printf(" Loading %s ... ", type_name); { load = image_get_load(header); image_start = image_get_data(header); image_len = image_get_data_size(header); memmove_wd((void *)load, (void *)image_start, image_len, CHUNKSZ); } puts("OK\n"); /* This should never return. */ exec(load, type_name); /* However, if it does, return failed status. */ fail: puts(failure); return (BOOTM_STATUS_FAILURE); }