コード例 #1
0
ファイル: wim.c プロジェクト: twwbond/wimlib
/* API function documented in wimlib.h  */
WIMLIBAPI void
wimlib_print_available_images(const WIMStruct *wim, int image)
{
    int first;
    int last;
    int i;
    int n;
    if (image == WIMLIB_ALL_IMAGES) {
        n = tprintf(T("Available Images:\n"));
        first = 1;
        last = wim->hdr.image_count;
    } else if (image >= 1 && image <= wim->hdr.image_count) {
        n = tprintf(T("Information for Image %d\n"), image);
        first = image;
        last = image;
    } else {
        tprintf(T("wimlib_print_available_images(): Invalid image %d"),
                image);
        return;
    }
    for (i = 0; i < n - 1; i++)
        tputchar(T('-'));
    tputchar(T('\n'));
    for (i = first; i <= last; i++)
        print_image_info(wim->wim_info, i);
}
コード例 #2
0
/* Validates the M0/M4 image at address image_addr */
static int CheckImages(uint32_t image_addr, const struct image_sig *m4)
{
	const uint32_t *addr = (uint32_t *) image_addr + 8;
	const struct image_sig *m0;

	uint32_t val, usbprob;

	/* Check for validity of M0 Image */
	if (*addr != 0xAA55DEAD) {
		DEBUGOUT("ERROR: Unable to find signature1 of M0 Image at %p\r\n",
				 ((uint32_t *) image_addr + 4));
		booting_m0_failure(20);
		return -1;
	}

	/* Do sanity check */
	addr++;
	if ((image_addr & 0xFFF00000UL) != (*addr & 0xFFF00000UL)) {
		DEBUGOUT("ERROR: M0 Image at 0x%08X, Infostruct at "
				 "0x%08X not is same region\r\n", image_addr, *addr);
		booting_m0_failure(20);
		return -1;
	}

	/* Valid structure is found */
	m0 = (const struct image_sig *) *addr;
	if (m0->signature != SIGNATURE_M0_MAGIC) {
		DEBUGSTR("M0_IMAGE: ERROR: M0 image signature 2 not found!\r\n");
		booting_m0_failure(20);
		return -1;
	}

	/* This should never happen, kept only for completeness */
	if (m4->signature != SIGNATURE_M4_MAGIC) {
		DEBUGSTR("M0_IMAGE: ERROR: M4 image signature 2 not found!\r\n");
		booting_m0_failure(10000);
		return -1;
	}
	print_image_info("M0_IMAGE", m0);
	print_image_info("M4_IMAGE", m4);
	val = m0->capability & m4->capability;
	usbprob = (m0->capability & (EX_USBHOST | EX_USBDEV)) &&
			  (m4->capability & (EX_USBHOST | EX_USBDEV));

	/* TODO: Check on possibility of running device on one core
	 * and host stack on another
	 **/
	if (usbprob) {
		DEBUGSTR("ERROR: Running USB Host/Device stack on both"
				 " cores is not supported yet!\r\n");
		booting_m0_failure(2000);
		return -1;
	}

	if (val & EX_LWIP) {
		DEBUGSTR("ERROR: Running lwIP on both core is not supported!\r\n");
		booting_m0_failure(2000);
		return -1;
	}

	if (val & EX_EMWIN) {
		DEBUGSTR("ERROR: Running emWIN on both core is not supported!\r\n");
		booting_m0_failure(2000);
		return -1;
	}
	return 0;
}
コード例 #3
0
ファイル: mkfwimage2.c プロジェクト: 2812015651/openwrt
int main(int argc, char* argv[])
{
	int o, rc;

	memset(&im, 0, sizeof(im));

	strcpy(im.outputfile, DEFAULT_OUTPUT_FILE);
	strcpy(im.version, DEFAULT_VERSION);
	memcpy(im.magic, MAGIC_HEADER, MAGIC_LENGTH);
	im.flash_baseaddr = DEFAULT_FLASH_BASE;

	while ((o = getopt(argc, argv, "f:hm:o:p:v:z")) != -1)
	{
		switch (o) {
		case 'f':
			if (optarg)
				if (str2u32(optarg, &im.flash_baseaddr)) {
					ERROR("Invalid flash start address %s\n", optarg);
					return -1;
				}
			break;
		case 'h':
			usage(argv[0]);
			return -1;
		case 'm':
			if (optarg) {
				if (strlen(optarg) != MAGIC_LENGTH) {
					ERROR("Invalid magic %s\n", optarg);
					return -1;
				}

				memcpy(im.magic, optarg, MAGIC_LENGTH);
			}
			break;
		case 'o':
			if (optarg)
				strncpy(im.outputfile, optarg, sizeof(im.outputfile));
			break;
		case 'p':
			if (optarg) {
				if (image_layout_add_partition(optarg))
					return -1;
			}
			break;
		case 'v':
			if (optarg)
				strncpy(im.version, optarg, sizeof(im.version));
			break;
		case 'z':
			zero_part_baseaddr = 1;
			break;
		}
	}

	rc = image_layout_verify();
	if (rc)	{
		ERROR("Failed validating firmware layout - error code: %d\n",
				rc);
		return -4;
	}

	print_image_info();

	rc = build_image();
	if (rc)	{
		ERROR("Failed building image file '%s' - error code: %d\n",
				im.outputfile, rc);
		return -5;
	}

	return 0;
}
コード例 #4
0
int main(int argc, char* argv[])
{
	char kernelfile[PATH_MAX];
	char rootfsfile[PATH_MAX];
	int o, rc;
	image_info_t im;

	memset(&im, 0, sizeof(im));
	memset(kernelfile, 0, sizeof(kernelfile));
	memset(rootfsfile, 0, sizeof(rootfsfile));

	strcpy(im.outputfile, DEFAULT_OUTPUT_FILE);
	strcpy(im.version, DEFAULT_VERSION);

	while ((o = getopt(argc, argv, OPTIONS)) != -1)
	{
		switch (o) {
		case 'v':
			if (optarg)
				strncpy(im.version, optarg, sizeof(im.version));
			break;
		case 'o':
			if (optarg)
				strncpy(im.outputfile, optarg, sizeof(im.outputfile));
			break;
		case 'h':
			usage(argv[0]);
			return -1;
		case 'k':
			if (optarg)
				strncpy(kernelfile, optarg, sizeof(kernelfile));
			break;
		case 'r':
			if (optarg)
				strncpy(rootfsfile, optarg, sizeof(rootfsfile));
			break;
		case 's':
			if (optarg)
				#undef partition_startaddr
				#define partition_startaddr	(optarg)
			break;
		}
	}

	if (strlen(kernelfile) == 0)
	{
		ERROR("Kernel file is not specified, cannot continue\n");
		usage(argv[0]);
		return -2;
	}

	if (strlen(rootfsfile) == 0)
	{
		ERROR("Root FS file is not specified, cannot continue\n");
		usage(argv[0]);
		return -2;
	}

	if ((rc = create_image_layout(kernelfile, rootfsfile, &im)) != 0)
	{
		ERROR("Failed creating firmware layout description - error code: %d\n", rc);
		return -3;
	}

	if ((rc = validate_image_layout(&im)) != 0)
	{
		ERROR("Failed validating firmware layout - error code: %d\n", rc);
		return -4;
	}

	print_image_info(&im);

	if ((rc = build_image(&im)) != 0)
	{
		ERROR("Failed building image file '%s' - error code: %d\n", im.outputfile, rc);
		return -5;
	}

	return 0;
}
コード例 #5
0
int main(int argc, char* argv[])
{
	char inputfile[PATH_MAX];
	int o, rc;
	image_info_t im;

	memset(&im, 0, sizeof(im));
	memset(inputfile, 0, sizeof(inputfile));

	strcpy(im.outputfile, DEFAULT_OUTPUT_FILE);
	strcpy(im.version, DEFAULT_VERSION);

	while ((o = getopt(argc, argv, OPTIONS)) != -1)
	{
		switch (o) {
		case 'v':
			if (optarg)
				strncpy(im.version, optarg, sizeof(im.version));
			break;
		case 'o':
			if (optarg)
				strncpy(im.outputfile, optarg, sizeof(im.outputfile));
			break;
		case 'i':
			if (optarg)
				strncpy(inputfile, optarg, sizeof(inputfile));
			break;
		case 'h':
			usage(argv[0]);
			return -1;
		}
	}

	if (strlen(inputfile) == 0)
	{
		ERROR("Input file is not specified, cannot continue\n");
		usage(argv[0]);
		return -2;
	}

	if ((rc = parse_image_layout(inputfile, &im)) != 0)
	{
		ERROR("Failed parsing firmware layout file '%s' - error code: %d\n", 
			inputfile, rc);
		return -3;
	}

	if ((rc = validate_image_layout(&im)) != 0)
	{
		ERROR("Failed validating firmware layout - error code: %d\n", rc);
		return -4;
	}

	print_image_info(&im);

	if ((rc = build_image(&im)) != 0)
	{
		ERROR("Failed building image file '%s' - error code: %d\n", im.outputfile, rc);
		return -5;
	}

	return 0;
}
コード例 #6
0
/*----------------------------------------------------------------------------*/
int main(int argc, char* argv[])
{
	int loop, test = 0, error = 0, command = COMMAND_NONE;
	int gray = 0, view = 1, help = 0;
	char *psave = 0x0, *pname = 0x0, *pdata = 0x0;
	my1Image currimage, tempimage, *pimage;
	my1IFrame currframe, tempframe;

	/* print tool info */
	printf("\n%s - %s (%s)\n",MY1APP_PROGNAME,MY1APP_PROGINFO,MY1APP_PROGVERS);
	printf("  => by [email protected]\n\n");

	/* check program arguments */
	if(argc>1)
	{
		for(loop=1;loop<argc;loop++)
		{
			if(argv[loop][0]=='-') /* options! */
			{
				if(!strcmp(argv[loop],"--save"))
				{
					loop++;
					if(loop<argc)
						psave = argv[loop];
					else
						printf("Cannot get save file name - NOT saving!\n");
				}
				else if(!strcmp(argv[loop],"--cdata"))
				{
					loop++;
					if(loop<argc)
						pdata = argv[loop];
					else
						printf("Cannot get C data file name - NOT writing!\n");
				}
				else if(!strcmp(argv[loop],"--gray"))
				{
					gray = 1;
				}
				else if(!strcmp(argv[loop],"--hide"))
				{
					view = 0;
				}
				else if(!strcmp(argv[loop],"--help"))
				{
					help = 1;
				}
				else
				{
					printf("Unknown option '%s'!\n",argv[loop]);
				}
			}
			else /* not an option? */
			{
				/* first non-option must be file name! */
				if(!pname)
				{
					pname = argv[loop];
					continue;
				}
				/* then check for command! */
				if(!strcmp(argv[loop],"laplace1"))
				{
					command = COMMAND_LAPLACE1;
					gray = 1;
				}
				else if(!strcmp(argv[loop],"sobelx"))
				{
					command = COMMAND_SOBELX;
					gray = 1;
				}
				else if(!strcmp(argv[loop],"sobely"))
				{
					command = COMMAND_SOBELY;
					gray = 1;
				}
				else if(!strcmp(argv[loop],"sobelall"))
				{
					command = COMMAND_SOBELALL;
					gray = 1;
				}
				else if(!strcmp(argv[loop],"laplace2"))
				{
					command = COMMAND_LAPLACE2;
					gray = 1;
				}
				else if(!strcmp(argv[loop],"gauss"))
				{
					command = COMMAND_GAUSS;
					gray = 1;
				}
				else
				{
					printf("Unknown parameter %s!\n",argv[loop]);
					continue;
				}
				/* warn if overriding previous command! */
				if(command)
				{
					printf("Warning! Command '%s' overrides '%s'!\n",
						argv[loop],argv[test]);
				}
				test = loop;
			}
		}
	}

	/* check if user requested help */
	if(help)
	{
		about();
		return 0;
	}

	/** check input filename */
	if(!pname)
	{
		printf("No filename given! Aborting!\n");
		return ERROR_GENERAL;
	}

	/* initialize image & frame*/
	initimage(&currimage);
	initimage(&tempimage);
	initframe(&currframe);
	initframe(&tempframe);

	/* try to open file */
	if((error=load_image(&currimage,pname))<0)
	{
		return error;
	}

	/* display basic info */
	printf("Input image: %s\n",pname);
	print_image_info(&currimage);

	/* convert grayscale if requested/required */
	if(gray) grayscale_image(&currimage);

	/* process command */
	switch(command)
	{
		case COMMAND_LAPLACE1:
		{
			createimage(&tempimage,currimage.height,currimage.width);
			laplace_image(&currimage,&tempimage);
			break;
		}
		case COMMAND_SOBELX:
		{
			createimage(&tempimage,currimage.height,currimage.width);
			sobel_x_image(&currimage,&tempimage);
			break;
		}
		case COMMAND_SOBELY:
		{
			createimage(&tempimage,currimage.height,currimage.width);
			sobel_y_image(&currimage,&tempimage);
			break;
		}
		case COMMAND_SOBELALL:
		{
			createimage(&tempimage,currimage.height,currimage.width);
			sobel_image(&currimage,&tempimage,0x0);
			break;
		}
		case COMMAND_LAPLACE2:
		{
			createimage(&tempimage,currimage.height,currimage.width);
			createframe(&currframe,currimage.height,currimage.width);
			createframe(&tempframe,currimage.height,currimage.width);
			image2frame(&currimage,&currframe,0);
			laplace_frame(&currframe,&tempframe);
			frame2image(&tempframe,&tempimage,1);
			break;
		}
		case COMMAND_GAUSS:
		{
			createimage(&tempimage,currimage.height,currimage.width);
			createframe(&currframe,currimage.height,currimage.width);
			createframe(&tempframe,currimage.height,currimage.width);
			image2frame(&currimage,&currframe,0);
			gauss_frame(&currframe,&tempframe,1.0,0x0);
			frame2image(&tempframe,&tempimage,1);
			break;
		}
	}

	if(!tempimage.length)
		pimage = &currimage;
	else
		pimage = &tempimage;
	printf("Check image:\n");
	print_image_info(pimage);

	/** save results if requested */
	if(psave)
	{
		printf("Saving image data to %s...\n",psave);
		error=save_image(pimage,psave);
		view = 0;
	}

	if(pdata)
	{
		printf("Saving C data to %s...\n",pdata);
		error=cdata_image(pimage,pdata);
	}

	/* view image if no request to hide! .. and NOT saving! */
	if(view) view_image(pimage);

	/* cleanup */
	freeframe(&currframe);
	freeframe(&tempframe);
	freeimage(&currimage);
	freeimage(&tempimage);

	return error;
}
コード例 #7
0
ファイル: package.c プロジェクト: 4doe/openembedded
static int pack_firmware(FILE *fp_w, uint32 offst, int num, char *name[])
{
    FILE *fp_r;
    int i, j;
    uint32 curptr, extcrc;
    char ch;
    package_header_t *phd = &p_head;
    image_info_t     *iif;

    /* read version file */
    if ((fp_r = fopen(UBOOT_VER_FILE, "rb")) == NULL)
    {
        printf("Can't open uboot version file: %s\n", UBOOT_VER_FILE);
        return(-1);
    }
    j=0;
    while (1)
    {
        if (feof(fp_r)) break;
        if (j > VER_LIMIT_LEN+1)
        {
            printf("uboot version can't be longer than 14\n");
            goto bail;
        }
        phd->p_vuboot[j] = fgetc(fp_r);
        if ((phd->p_vuboot[j]==0x0d) || (phd->p_vuboot[j]==0x0a))
            phd->p_vuboot[j] = '\0';
        j++;
    }
    fclose(fp_r);

    if ((fp_r = fopen(KERNEL_VER_FILE, "rb")) == NULL)
    {
        printf("Can't open kernel version file: %s\n", KERNEL_VER_FILE);
        return(-1);
    }
    j=0;
    while (1)
    {
        if (feof(fp_r)) break;
        if (j > VER_LIMIT_LEN+1)
        {
            printf("kernel version can't be longer than 14\n");
            goto bail;
        }
        phd->p_vkernel[j]=fgetc(fp_r);
        if ((phd->p_vkernel[j]==0x0d) || (phd->p_vkernel[j]==0x0a))
            phd->p_vkernel[j] = '\0';
        j++; 
    }
    fclose(fp_r);

    if ((fp_r = fopen(ROOTFS_VER_FILE, "rb")) == NULL)
    {
        printf("Can't open rootfs version file: %s\n", ROOTFS_VER_FILE);
        return(-1);
    }
    j=0;
    while (1)
    {
        if (feof(fp_r)) break;
        if (j > VER_LIMIT_LEN+1)
        {
            printf("rootfs version can't be longer than 14\n");
            goto bail;
        }
        phd->p_vrootfs[j] = fgetc(fp_r);
        if ((phd->p_vrootfs[j]==0x0d) ||(phd->p_vrootfs[j]==0x0a))
            phd->p_vrootfs[j] = '\0';
        j++;
    }
    fclose(fp_r);

    phd->p_imagenum = (uint8)num;
    phd->p_headsize = sizeof(package_header_t) + phd->p_imagenum * sizeof(image_info_t);

    /* Bit[3] use to indicate osd2.0 package */
    phd->p_reserve = 0x08;

    phd->p_datasize = 0;
    phd->p_datacrc  = 0;
    phd->p_headcrc  = 0;

    curptr = phd->p_headsize + sizeof(version_info);

    for (i=0; i < phd->p_imagenum; i++)
    {
        /* image info */
        iif = &i_info[i];
        if (strncmp(name[i], ROOTFS_FILE_NAME, strlen(ROOTFS_FILE_NAME)) == 0)
        {
            iif->i_type = IH_TYPE_ROOTFS;
            strncpy((char *)iif->i_name, ROOTFS_FILE_NAME, NAMELEN-1);

            if ((fp_r = fopen(ROOTFS_VER_FILE, "rb")) == NULL)
            {
                printf("Can't open kernel version file: %s\n", ROOTFS_VER_FILE);
                break;
            }
            for (j = 0; j < sizeof(iif->i_version); j++)
            {
                if (feof(fp_r)) break;
                iif->i_version[j] = fgetc(fp_r);
                if ((iif->i_version[j]==0x0d) || (iif->i_version[j]==0x0a))
                    iif->i_version[j] = '\0';
            }
            fclose(fp_r);
        }
        else if (strncmp(name[i], KERNEL_FILE_NAME, strlen(KERNEL_FILE_NAME)) == 0)
        {
            iif->i_type = IH_TYPE_KERNEL;
            strncpy((char *)iif->i_name, KERNEL_FILE_NAME, NAMELEN-1);

            if ((fp_r = fopen(KERNEL_VER_FILE, "rb")) == NULL)
            {
                printf("Can't open kernel version file: %s\n", KERNEL_VER_FILE);
                break;
            }
            for (j = 0; j < sizeof(iif->i_version); j++)
            {
                if (feof(fp_r)) break;
                iif->i_version[j] = fgetc(fp_r);
                if ((iif->i_version[j]==0x0d) ||(iif->i_version[j]==0x0a))
                    iif->i_version[j] = '\0';
            }
            fclose(fp_r);
        }
        else if (strncmp(name[i], UBOOT_FILE_NAME, strlen(UBOOT_FILE_NAME)) == 0)
        {
            iif->i_type = IH_TYPE_UBOOT;
            strncpy((char *)iif->i_name, UBOOT_FILE_NAME, NAMELEN-1);

            if ((fp_r = fopen(UBOOT_VER_FILE, "rb")) == NULL)
            {
                printf("Can't open uboot version file: %s\n", UBOOT_VER_FILE);
                break;
            }
            for (j = 0; j < sizeof(iif->i_version); j++)
            {
                if (feof(fp_r)) break;
                iif->i_version[j] = fgetc(fp_r);
                if ((iif->i_version[j]==0x0d)|| (iif->i_version[j]==0x0a))
                    iif->i_version[j] = '\0';
            }
            fclose(fp_r);
        }
        else if (strncmp(name[i], SCRIPT_FILE_NAME, strlen(SCRIPT_FILE_NAME)) == 0)
        {
            iif->i_type = IH_TYPE_SCRIPT;
            strncpy((char *)iif->i_name, SCRIPT_FILE_NAME, NAMELEN-1);
        }

        /* address in flash*/
        switch (iif->i_type)
        {
        case IH_TYPE_ROOTFS:
            iif->i_startaddr_f = ROOTFS_ADDR_START;
            iif->i_endaddr_f   = ROOTFS_ADDR_END;
            break;
        case IH_TYPE_KERNEL:
            iif->i_startaddr_f = KERNEL_ADDR_START;
            iif->i_endaddr_f   = KERNEL_ADDR_END;
            break;       
        case IH_TYPE_UBOOT:
            iif->i_startaddr_f = UBOOT_ADDR_START;
            iif->i_endaddr_f   = UBOOT_ADDR_END;
            break;
        case IH_TYPE_SCRIPT:
            break;
        default:
            printf("un-handle image type\n");
            break;
        }

        /* write whole image to package and calculate the imagesize*/
        iif->i_imagesize = 0;
        /* images file */
        if ((fp_r = fopen(name[i], "rb")) == NULL)
        {
            printf("can't open file: %s\n", name[i]);
            break;
        }

        fseek(fp_w, offst+curptr,SEEK_SET);
        extcrc = 0;
        while (!feof(fp_r))
        {
            ch = fgetc(fp_r);
            fputc(ch, fp_w);
            phd->p_datacrc = crc32(phd->p_datacrc,(uint8 *)&ch, 1);
            iif->i_imagesize ++;
        }
        fclose(fp_r);

        iif->i_startaddr_p = curptr-sizeof(version_info);
        curptr += iif->i_imagesize;
        phd->p_datasize += iif->i_imagesize;

        print_image_info(iif); /* print iff*/

        /*write image info */
        fseek(fp_w, offst+sizeof(version_info)+sizeof(package_header_t)+i*sizeof(image_info_t), SEEK_SET);
        if (fwrite(iif, sizeof(image_info_t), 1, fp_w) != 1)
        {
            printf("can not write iif into package\n");
            break;
        }
    }

    /* write package head*/
    phd->p_headcrc = crc32(phd->p_headcrc, (uint8 *)phd, sizeof(package_header_t));
    phd->p_headcrc = crc32(phd->p_headcrc, (uint8 *)i_info, phd->p_imagenum*sizeof(image_info_t));

    print_head_info();  /* print phd */

    fseek(fp_w, offst+sizeof(version_info), SEEK_SET);
    if (fwrite((uint8 *)phd, sizeof(package_header_t), 1, fp_w) != 1)
    {
        printf("can not write head into package");
        return(-1);
    }
    return 0;

    bail:
    fclose(fp_r);

    return -1;
}