示例#1
0
static int kwbimage_generate(struct image_tool_params *params,
                             struct image_type_params *tparams)
{
    int alloc_len;
    void *hdr;
    int version = 0;

    version = image_version_file(params->imagename);
    if (version == 0) {
        alloc_len = sizeof(struct main_hdr_v0) +
                    sizeof(struct ext_hdr_v0);
    } else {
        alloc_len = image_headersz_v1(params, NULL);
    }

    hdr = malloc(alloc_len);
    if (!hdr) {
        fprintf(stderr, "%s: malloc return failure: %s\n",
                params->cmdname, strerror(errno));
        exit(EXIT_FAILURE);
    }

    memset(hdr, 0, alloc_len);
    tparams->header_size = alloc_len;
    tparams->hdr = hdr;

    return 0;
}
示例#2
0
static int kwbimage_generate(struct image_tool_params *params,
			     struct image_type_params *tparams)
{
	int alloc_len;
	void *hdr;
	int version = 0;

	version = image_version_file(params->imagename);
	if (version == 0) {
		alloc_len = sizeof(struct main_hdr_v0) +
			sizeof(struct ext_hdr_v0);
	} else {
		alloc_len = image_headersz_v1(params, NULL);
#if defined(CONFIG_SYS_SPI_U_BOOT_OFFS)
		if (alloc_len > CONFIG_SYS_SPI_U_BOOT_OFFS) {
			fprintf(stderr, "Error: Image header (incl. SPL image) too big!\n");
			fprintf(stderr, "header=0x%x CONFIG_SYS_SPI_U_BOOT_OFFS=0x%x!\n",
				alloc_len, CONFIG_SYS_SPI_U_BOOT_OFFS);
			fprintf(stderr, "Increase CONFIG_SYS_SPI_U_BOOT_OFFS!\n");
		} else {
			alloc_len = CONFIG_SYS_SPI_U_BOOT_OFFS;
		}
#endif
	}

	hdr = malloc(alloc_len);
	if (!hdr) {
		fprintf(stderr, "%s: malloc return failure: %s\n",
			params->cmdname, strerror(errno));
		exit(EXIT_FAILURE);
	}

	memset(hdr, 0, alloc_len);
	tparams->header_size = alloc_len;
	tparams->hdr = hdr;

	return 0;
}
示例#3
0
static int kwbimage_generate(struct image_tool_params *params,
			     struct image_type_params *tparams)
{
	int alloc_len;
	void *hdr;
	int version = 0;

	version = image_version_file(params->imagename);
	if (version == 0) {
		alloc_len = sizeof(struct main_hdr_v0) +
			sizeof(struct ext_hdr_v0);
	} else {
		alloc_len = image_headersz_v1(params, NULL);
	}

	hdr = malloc(alloc_len);
	if (!hdr) {
		fprintf(stderr, "%s: malloc return failure: %s\n",
			params->cmdname, strerror(errno));
		exit(EXIT_FAILURE);
	}

	memset(hdr, 0, alloc_len);
	tparams->header_size = alloc_len;
	tparams->hdr = hdr;

	/*
	 * The resulting image needs to be 4-byte aligned. At least
	 * the Marvell hdrparser tool complains if its unaligned.
	 * By returning 1 here in this function, called via
	 * tparams->vrec_header() in mkimage.c, mkimage will
	 * automatically pad the the resulting image to a 4-byte
	 * size if necessary.
	 */
	return 1;
}
示例#4
0
static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
			     int payloadsz)
{
	struct image_cfg_element *e, *binarye;
	struct main_hdr_v1 *main_hdr;
	size_t headersz;
	void *image, *cur;
	int hasext = 0;
	int ret;

	/*
	 * Calculate the size of the header and the size of the
	 * payload
	 */
	headersz = image_headersz_v1(params, &hasext);
	if (headersz == 0)
		return NULL;

	image = malloc(headersz);
	if (!image) {
		fprintf(stderr, "Cannot allocate memory for image\n");
		return NULL;
	}

	memset(image, 0, headersz);

	cur = main_hdr = image;
	cur += sizeof(struct main_hdr_v1);

	/* Fill the main header */
	main_hdr->blocksize    =
		cpu_to_le32(payloadsz - headersz + sizeof(uint32_t));
	main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF);
	main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16;
	main_hdr->destaddr     = cpu_to_le32(params->addr);
	main_hdr->execaddr     = cpu_to_le32(params->ep);
	main_hdr->srcaddr      = cpu_to_le32(headersz);
	main_hdr->ext          = hasext;
	main_hdr->version      = 1;
	e = image_find_option(IMAGE_CFG_BOOT_FROM);
	if (e)
		main_hdr->blockid = e->bootfrom;
	e = image_find_option(IMAGE_CFG_NAND_BLKSZ);
	if (e)
		main_hdr->nandblocksize = e->nandblksz / (64 * 1024);
	e = image_find_option(IMAGE_CFG_NAND_BADBLK_LOCATION);
	if (e)
		main_hdr->nandbadblklocation = e->nandbadblklocation;
	e = image_find_option(IMAGE_CFG_BAUDRATE);
	if (e)
		main_hdr->options = baudrate_to_option(e->baudrate);
	e = image_find_option(IMAGE_CFG_DEBUG);
	if (e)
		main_hdr->flags = e->debug ? 0x1 : 0;

	binarye = image_find_option(IMAGE_CFG_BINARY);
	if (binarye) {
		struct opt_hdr_v1 *hdr = cur;
		uint32_t *args;
		size_t binhdrsz;
		struct stat s;
		int argi;
		FILE *bin;

		hdr->headertype = OPT_HDR_V1_BINARY_TYPE;

		bin = fopen(binarye->binary.file, "r");
		if (!bin) {
			fprintf(stderr, "Cannot open binary file %s\n",
				binarye->binary.file);
			return NULL;
		}

		fstat(fileno(bin), &s);

		binhdrsz = sizeof(struct opt_hdr_v1) +
			(binarye->binary.nargs + 2) * sizeof(uint32_t) +
			s.st_size;

		/*
		 * The size includes the binary image size, rounded
		 * up to a 4-byte boundary. Plus 4 bytes for the
		 * next-header byte and 3-byte alignment at the end.
		 */
		binhdrsz = ALIGN_SUP(binhdrsz, 4) + 4;
		hdr->headersz_lsb = cpu_to_le16(binhdrsz & 0xFFFF);
		hdr->headersz_msb = (binhdrsz & 0xFFFF0000) >> 16;

		cur += sizeof(struct opt_hdr_v1);

		args = cur;
		*args = cpu_to_le32(binarye->binary.nargs);
		args++;
		for (argi = 0; argi < binarye->binary.nargs; argi++)
			args[argi] = cpu_to_le32(binarye->binary.args[argi]);

		cur += (binarye->binary.nargs + 1) * sizeof(uint32_t);

		ret = fread(cur, s.st_size, 1, bin);
		if (ret != 1) {
			fprintf(stderr,
				"Could not read binary image %s\n",
				binarye->binary.file);
			return NULL;
		}

		fclose(bin);

		cur += ALIGN_SUP(s.st_size, 4);

		/*
		 * For now, we don't support more than one binary
		 * header, and no other header types are
		 * supported. So, the binary header is necessarily the
		 * last one
		 */
		*((uint32_t *)cur) = 0x00000000;

		cur += sizeof(uint32_t);
	}

	/* Calculate and set the header checksum */
	main_hdr->checksum = image_checksum8(main_hdr, headersz);

	*imagesz = headersz;
	return image;
}
示例#5
0
static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
                             int payloadsz)
{
    struct image_cfg_element *e, *binarye;
    struct main_hdr_v1 *main_hdr;
    size_t headersz;
    void *image, *cur;
    int hasext = 0;
    int ret;

    /*
     * Calculate the size of the header and the size of the
     * payload
     */
    headersz = image_headersz_v1(params, &hasext);
    if (headersz == 0)
        return NULL;

    image = malloc(headersz);
    if (!image) {
        fprintf(stderr, "Cannot allocate memory for image\n");
        return NULL;
    }

    memset(image, 0, headersz);

    cur = main_hdr = image;
    cur += sizeof(struct main_hdr_v1);

    /* Fill the main header */
    main_hdr->blocksize    = payloadsz - headersz + sizeof(uint32_t);
    main_hdr->headersz_lsb = headersz & 0xFFFF;
    main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16;
    main_hdr->destaddr     = params->addr;
    main_hdr->execaddr     = params->ep;
    main_hdr->srcaddr      = headersz;
    main_hdr->ext          = hasext;
    main_hdr->version      = 1;
    e = image_find_option(IMAGE_CFG_BOOT_FROM);
    if (e)
        main_hdr->blockid = e->bootfrom;
    e = image_find_option(IMAGE_CFG_NAND_BLKSZ);
    if (e)
        main_hdr->nandblocksize = e->nandblksz / (64 * 1024);
    e = image_find_option(IMAGE_CFG_NAND_BADBLK_LOCATION);
    if (e)
        main_hdr->nandbadblklocation = e->nandbadblklocation;

    binarye = image_find_option(IMAGE_CFG_BINARY);
    if (binarye) {
        struct opt_hdr_v1 *hdr = cur;
        unsigned int *args;
        size_t binhdrsz;
        struct stat s;
        int argi;
        FILE *bin;

        hdr->headertype = OPT_HDR_V1_BINARY_TYPE;

        bin = fopen(binarye->binary.file, "r");
        if (!bin) {
            fprintf(stderr, "Cannot open binary file %s\n",
                    binarye->binary.file);
            return NULL;
        }

        fstat(fileno(bin), &s);

        binhdrsz = sizeof(struct opt_hdr_v1) +
                   (binarye->binary.nargs + 1) * sizeof(unsigned int) +
                   s.st_size;
        hdr->headersz_lsb = binhdrsz & 0xFFFF;
        hdr->headersz_msb = (binhdrsz & 0xFFFF0000) >> 16;

        cur += sizeof(struct opt_hdr_v1);

        args = cur;
        *args = binarye->binary.nargs;
        args++;
        for (argi = 0; argi < binarye->binary.nargs; argi++)
            args[argi] = binarye->binary.args[argi];

        cur += (binarye->binary.nargs + 1) * sizeof(unsigned int);

        ret = fread(cur, s.st_size, 1, bin);
        if (ret != 1) {
            fprintf(stderr,
                    "Could not read binary image %s\n",
                    binarye->binary.file);
            return NULL;
        }

        fclose(bin);

        cur += s.st_size;

        /*
         * For now, we don't support more than one binary
         * header, and no other header types are
         * supported. So, the binary header is necessarily the
         * last one
         */
        *((unsigned char *)cur) = 0;

        cur += sizeof(uint32_t);
    }

    /* Calculate and set the header checksum */
    main_hdr->checksum = image_checksum8(main_hdr, headersz);

    *imagesz = headersz;
    return image;
}