예제 #1
0
파일: main.c 프로젝트: AirBrowse/RetroArch
void app_booter_main(void)
{
	void *exeBuffer = (void *) EXECUTABLE_MEM_ADDR;
	u32 exeEntryPointAddress = 0;
	entrypoint exeEntryPoint;

	if (valid_elf_image(exeBuffer) == 1)
		exeEntryPointAddress = load_elf_image(exeBuffer);
	else
		exeEntryPointAddress = load_dol_image(exeBuffer);

	exeEntryPoint = (entrypoint) exeEntryPointAddress;

	if (!exeEntryPoint)
		return;

	if (SYSTEM_ARGV->argvMagic == ARGV_MAGIC)
	{
		void *new_argv = (void *) (exeEntryPointAddress + 8);
		memcpy(new_argv, SYSTEM_ARGV, sizeof(struct __argv));
		sync_before_exec(new_argv, sizeof(struct __argv));
	}

	exeEntryPoint ();
}
예제 #2
0
/* Interpreter command to boot an arbitrary ELF image from memory */
int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	unsigned long addr; /* Address of the ELF image */
	unsigned long rc; /* Return value from user code */
	char *sload, *saddr;
	const char *ep = getenv("autostart");

	int rcode = 0;

	sload = saddr = NULL;
	if (argc == 3) {
		sload = argv[1];
		saddr = argv[2];
	} else if (argc == 2) {
		if (argv[1][0] == '-')
			sload = argv[1];
		else
			saddr = argv[1];
	}

	if (saddr)
		addr = simple_strtoul(saddr, NULL, 16);
	else
		addr = load_addr;

	if (!valid_elf_image(addr))
		return 1;

	if (sload && sload[1] == 'p')
		addr = load_elf_image_phdr(addr);
	else
		addr = load_elf_image_shdr(addr);

	if (ep && !strcmp(ep, "no"))
		return rcode;

	printf("## Starting application at 0x%08lx ...\n", addr);

	/*
	 * pass address parameter as argv[0] (aka command name),
	 * and all remaining args
	 */
	rc = do_bootelf_exec((void *)addr, argc - 1, argv + 1);
	if (rc != 0)
		rcode = 1;

	printf("## Application terminated, rc = 0x%lx\n", rc);

	return rcode;
}
예제 #3
0
파일: elf.c 프로젝트: axxia/axxia_u-boot
/* Interpreter command to boot an arbitrary ELF image from memory */
int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	unsigned long addr; /* Address of the ELF image */
	unsigned long rc; /* Return value from user code */
	char *sload = NULL;
	const char *ep = env_get("autostart");
	int rcode = 0;

	/* Consume 'bootelf' */
	argc--; argv++;

	/* Check for flag. */
	if (argc >= 1 && (argv[0][0] == '-' && \
				(argv[0][1] == 'p' || argv[0][1] == 's'))) {
		sload = argv[0];
		/* Consume flag. */
		argc--; argv++;
	}
	/* Check for address. */
	if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) {
		/* Consume address */
		argc--; argv++;
	} else
		addr = load_addr;

	if (!valid_elf_image(addr))
		return 1;

	if (sload && sload[1] == 'p')
		addr = load_elf_image_phdr(addr);
	else
		addr = load_elf_image_shdr(addr);

	if (ep && !strcmp(ep, "no"))
		return rcode;

	printf("## Starting application at 0x%08lx ...\n", addr);

	/*
	 * pass address parameter as argv[0] (aka command name),
	 * and all remaining args
	 */
	rc = do_bootelf_exec((void *)addr, argc, argv);
	if (rc != 0)
		rcode = 1;

	printf("## Application terminated, rc = 0x%lx\n", rc);

	return rcode;
}
예제 #4
0
int BootHomebrewFromMem() {
	loadStub();
	if (Set_Stub_Split(0x00010001,"UNEO")<0)
		Set_Stub_Split(0x00010001,"ULNR");
    entrypoint entry;
    u32 cpu_isr;

    if (!innetbuffer) {
        SDCard_deInit();
		USBDevice_deInit();
        SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
    }

    struct __argv args;

    int ret = valid_elf_image(innetbuffer);
    if (ret == 1)
        entry = (entrypoint) load_elf_image(innetbuffer);
    else
        entry = (entrypoint) load_dol(innetbuffer, &args);

    free(innetbuffer);

    if (!entry) {
        SDCard_deInit();
        SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
    }

    SDCard_deInit();

    WPAD_Flush(0);
    WPAD_Disconnect(0);
    WPAD_Shutdown();

    SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
    _CPU_ISR_Disable (cpu_isr);
    __exception_closeall();
    entry();
    _CPU_ISR_Restore (cpu_isr);

    return 0;
}
예제 #5
0
/* ======================================================================
 * Interpreter command to boot an arbitrary ELF image from memory.
 * ====================================================================== */
int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	unsigned long addr;		/* Address of the ELF image     */
	unsigned long rc;		/* Return value from user code  */

	/* -------------------------------------------------- */
	int rcode = 0;

	if (argc < 2)
		addr = load_addr;
	else
		addr = simple_strtoul (argv[1], NULL, 16);

	if (!valid_elf_image (addr))
		return 1;

	addr = load_elf_image (addr);

	printf ("## Starting application at 0x%08lx ...\n", addr);

	/*
	 * QNX images require the data cache is disabled.
	 * Data cache is already flushed, so just turn it off.
	 */
	if (dcache_status ())
		dcache_disable ();

	/*
	 * pass address parameter as argv[0] (aka command name),
	 * and all remaining args
	 */
	rc = ((ulong (*)(int, char *[])) addr) (--argc, &argv[1]);
	if (rc != 0)
		rcode = 1;

	printf ("## Application terminated, rc = 0x%lx\n", rc);
	return rcode;
}
예제 #6
0
int main(int argc, char **argv)
{
	u32 cookie;
	FILE *exeFile = NULL;
	void *exeBuffer          = (void *)EXECUTABLE_MEM_ADDR;
	int exeSize              = 0;
	u32 exeEntryPointAddress = 0;
	entrypoint exeEntryPoint;
	
	/* int videomod */
	InitVideo();
	/* get imagedata */
	u8 * imgdata = GetImageData();
	/* fadein of image */
	for(int i = 0; i < 255; i = i+10)
	{
		if(i>255) i = 255;
		Background_Show(0, 0, 0, imgdata, 0, 1, 1, i);
		Menu_Render();
	}
	
	/* check devices */
	SDCard_Init();
	USBDevice_Init();
	
	char cfgpath[256];
	
	/* Open dol File and check exist */
	sprintf(cfgpath, PATH1);
	exeFile = fopen (cfgpath ,"rb");
	if (exeFile==NULL)
	{
		sprintf(cfgpath, PATH2);
		exeFile = fopen (cfgpath ,"rb");
	}
	if (exeFile==NULL)
	{
		sprintf(cfgpath, PATH3);
		exeFile = fopen (cfgpath ,"rb");
	}
	if (exeFile==NULL)
	{
		sprintf(cfgpath, PATH4);
		exeFile = fopen (cfgpath ,"rb");
	}
	
	if (PACK2)
	{
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH5);
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH6);
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH7);
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH8);
			exeFile = fopen (cfgpath ,"rb");
		}
	}
	
	if (PACK3)
	{
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH9);
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH10);
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH11);
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH12);
			exeFile = fopen (cfgpath ,"rb");
		}
	}
	
	if (PACK4)
	{
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH13);
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH14);
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH15);
			exeFile = fopen (cfgpath ,"rb");
		}
		if (exeFile==NULL)
		{
			sprintf(cfgpath, PATH16);
			exeFile = fopen (cfgpath ,"rb");
		}
	}
	
	// if nothing found exiting
	if (exeFile==NULL) {
           printf("\n\n\t\tCan't find DOL File...\n");
           Menu_Render();
           sleep(3);
           fclose (exeFile);
           SDCard_deInit();
           USBDevice_deInit();
           StopGX();
		SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	}

	fseek (exeFile, 0, SEEK_END);
	exeSize = ftell(exeFile);
	fseek (exeFile, 0, SEEK_SET);

	if(fread (exeBuffer, 1, exeSize, exeFile) != (unsigned int) exeSize)
	{
		printf("\n\n\t\tCan't open DOL File...\n");
		Menu_Render();
        fclose (exeFile);
		sleep(3);
        SDCard_deInit();
        USBDevice_deInit();
        StopGX();
		SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	}
	fclose (exeFile);

	/* load entry point */
	struct __argv args;
	bzero(&args, sizeof(args));
	args.argvMagic = ARGV_MAGIC;
	args.length = strlen(cfgpath) + 2;
	args.commandLine = (char*)malloc(args.length);
	if (!args.commandLine) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
	strcpy(args.commandLine, cfgpath);
	args.commandLine[args.length - 1] = '\0';
	args.argc = 1;
	args.argv = &args.commandLine;
	args.endARGV = args.argv + 1;

	int ret = valid_elf_image(exeBuffer);
	if (ret == 1)
		exeEntryPointAddress = load_elf_image(exeBuffer);
	else
		exeEntryPointAddress = load_dol_image(exeBuffer, &args);

	/* fadeout of image */
	for(int i = 255; i > 1; i = i-7)
	{
		if(i < 0) i = 0;
		Background_Show(0, 0, 0, imgdata, 0, 1, 1, i);
		Menu_Render();
	}
	SDCard_deInit();
	USBDevice_deInit();
	StopGX();
	if (exeEntryPointAddress == 0) {
		printf("EntryPointAddress  failed...\n");
        Menu_Render();
        sleep(3);
        fclose (exeFile);
        SDCard_deInit();
        USBDevice_deInit();
        StopGX();
		SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);;
	}
	exeEntryPoint = (entrypoint) exeEntryPointAddress;
	/* cleaning up and load dol */
	SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
	_CPU_ISR_Disable (cookie);
	__exception_closeall ();
	exeEntryPoint ();
	_CPU_ISR_Restore (cookie);
	return 0;
}
예제 #7
0
int BootHomebrew(char * path) {
	loadStub();
	if (Set_Stub_Split(0x00010001,"UNEO")<0)
		Set_Stub_Split(0x00010001,"ULNR");
    void *buffer = NULL;
    u32 filesize = 0;
    entrypoint entry;
    u32 cpu_isr;

    FILE * file = fopen(path, "rb");
    if (!file) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);

    fseek (file, 0, SEEK_END);
    filesize = ftell(file);
    rewind(file);

    buffer = malloc(filesize);

    if (fread (buffer, 1, filesize, file) != filesize) {
        fclose (file);
        free(buffer);
        SDCard_deInit();
		USBDevice_deInit();
        SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
    }
    fclose (file);

    struct __argv args;
    bzero(&args, sizeof(args));
    args.argvMagic = ARGV_MAGIC;
    args.length = strlen(path) + 2;
    args.commandLine = (char*)malloc(args.length);
    if (!args.commandLine) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
    strcpy(args.commandLine, path);
    args.commandLine[args.length - 1] = '\0';
    args.argc = 1;
    args.argv = &args.commandLine;
    args.endARGV = args.argv + 1;

    int ret = valid_elf_image(buffer);
    if (ret == 1)
        entry = (entrypoint) load_elf_image(buffer);
    else
        entry = (entrypoint) load_dol(buffer, &args);

    free(buffer);

    SDCard_deInit();
	USBDevice_deInit();

    if (!entry) {
        SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
    }

    WPAD_Flush(0);
    WPAD_Disconnect(0);
    WPAD_Shutdown();

    SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
    _CPU_ISR_Disable (cpu_isr);
    __exception_closeall();
    entry();
    _CPU_ISR_Restore (cpu_isr);

    return 0;
}
예제 #8
0
파일: main.c 프로젝트: 4nh51rk/mailboxbomb
int main(void)
{
	// slot LED
	write32(0xcd8000c0, 0x20);

	dsp_reset();

	exception_init();

	// Install trampoline at 80001800; some payloads like to jump
	// there to restart.  Sometimes this can even work.
	//memcpy(trampoline_buffer, reboot_trampoline, sizeof(reboot_trampoline));

	// Clear interrupt mask.
	write32(0x0c003004, 0);

	// Unlock EXI.
	write32(0x0d00643c, 0);

	video_init();
	usbgecko_init();

	printf("savezelda\n%s\n", version);

	printf("\n");
	printf("Copyright 2008,2009  Segher Boessenkool\n");
	printf("Copyright 2008  Haxx Enterprises\n");
	printf("Copyright 2008  Hector Martin (\"marcan\")\n");
	printf("Copyright 2003,2004  Felix Domke\n");
	printf("\n");
	printf("This code is licensed to you under the terms of the\n");
	printf("GNU GPL, version 2; see the file COPYING\n");
	printf("\n");
	printf("Font and graphics by Freddy Leitner\n");
	printf("\n");
	printf("\n");

	printf("Cleaning up environment... ");

	reset_ios();

	printf("OK.\n");


	int err;

 restart:
	err = try_sd_load();

	if (err) {
		err = try_usbgecko_load();

		if (err) {
			printf("No code found to load, hanging.\n");
			for (;;)
				;
		}
	}

	if (valid_elf_image(code_buffer)) {
		printf("Valid ELF image detected.\n");
		void (*entry)() = load_elf_image(code_buffer);
		entry();
		printf("Program returned to loader, reloading.\n");
	} else
		printf("No valid ELF image detected, retrying.\n");

	goto restart;
}
예제 #9
0
/*
 * FIXME: Add code to test image and it's header.
 */
static int
image_check(ulong addr)
{
    return valid_elf_image(addr);
}
예제 #10
0
/*
 * Interpreter command to boot VxWorks from a memory image.  The image can
 * be either an ELF image or a raw binary.  Will attempt to setup the
 * bootline and other parameters correctly.
 */
int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	unsigned long addr; /* Address of image */
	unsigned long bootaddr; /* Address to put the bootline */
	char *bootline; /* Text of the bootline */
	char *tmp; /* Temporary char pointer */
	char build_buf[128]; /* Buffer for building the bootline */
	int ptr = 0;
#ifdef CONFIG_X86
	struct e820info *info;
	struct e820entry *data;
#endif

	/*
	 * Check the loadaddr variable.
	 * If we don't know where the image is then we're done.
	 */
	if (argc < 2)
		addr = load_addr;
	else
		addr = simple_strtoul(argv[1], NULL, 16);

#if defined(CONFIG_CMD_NET)
	/*
	 * Check to see if we need to tftp the image ourselves
	 * before starting
	 */
	if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
		if (net_loop(TFTPGET) <= 0)
			return 1;
		printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
			addr);
	}
#endif

	/*
	 * This should equate to
	 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
	 * from the VxWorks BSP header files.
	 * This will vary from board to board
	 */
#if defined(CONFIG_WALNUT)
	tmp = (char *)CONFIG_SYS_NVRAM_BASE_ADDR + 0x500;
	eth_getenv_enetaddr("ethaddr", (uchar *)build_buf);
	memcpy(tmp, &build_buf[3], 3);
#elif defined(CONFIG_SYS_VXWORKS_MAC_PTR)
	tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
	eth_getenv_enetaddr("ethaddr", (uchar *)build_buf);
	memcpy(tmp, build_buf, 6);
#else
	puts("## Ethernet MAC address not copied to NV RAM\n");
#endif

	/*
	 * Use bootaddr to find the location in memory that VxWorks
	 * will look for the bootline string. The default value is
	 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
	 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
	 */
	tmp = getenv("bootaddr");
	if (!tmp) {
		printf("## VxWorks bootline address not specified\n");
	} else {
		bootaddr = simple_strtoul(tmp, NULL, 16);

		/*
		 * Check to see if the bootline is defined in the 'bootargs'
		 * parameter. If it is not defined, we may be able to
		 * construct the info.
		 */
		bootline = getenv("bootargs");
		if (bootline) {
			memcpy((void *)bootaddr, bootline,
			       max(strlen(bootline), (size_t)255));
			flush_cache(bootaddr, max(strlen(bootline),
						  (size_t)255));
		} else {
			tmp = getenv("bootdev");
			if (tmp)
				ptr = sprintf(build_buf, tmp);
			else
				printf("## VxWorks boot device not specified\n");

			tmp = getenv("bootfile");
			if (tmp)
				ptr += sprintf(build_buf + ptr,
					       "host:%s ", tmp);
			else
				ptr += sprintf(build_buf + ptr,
					       "host:vxWorks ");

			/*
			 * The following parameters are only needed if 'bootdev'
			 * is an ethernet device, otherwise they are optional.
			 */
			tmp = getenv("ipaddr");
			if (tmp) {
				ptr += sprintf(build_buf + ptr, "e=%s", tmp);
				tmp = getenv("netmask");
				if (tmp) {
					u32 mask = getenv_ip("netmask").s_addr;
					ptr += sprintf(build_buf + ptr,
						       ":%08x ", ntohl(mask));
				} else {
					ptr += sprintf(build_buf + ptr, " ");
				}
			}

			tmp = getenv("serverip");
			if (tmp)
				ptr += sprintf(build_buf + ptr, "h=%s ", tmp);

			tmp = getenv("gatewayip");
			if (tmp)
				ptr += sprintf(build_buf + ptr, "g=%s ", tmp);

			tmp = getenv("hostname");
			if (tmp)
				ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);

			tmp = getenv("othbootargs");
			if (tmp)
				ptr += sprintf(build_buf + ptr, tmp);

			memcpy((void *)bootaddr, build_buf,
			       max(strlen(build_buf), (size_t)255));
			flush_cache(bootaddr, max(strlen(build_buf),
						  (size_t)255));
		}

		printf("## Using bootline (@ 0x%lx): %s\n", bootaddr,
		       (char *)bootaddr);
	}

#ifdef CONFIG_X86
	/*
	 * Since E820 information is critical to the kernel, if we don't
	 * specify these in the environments, use a default one.
	 */
	tmp = getenv("e820data");
	if (tmp)
		data = (struct e820entry *)simple_strtoul(tmp, NULL, 16);
	else
		data = (struct e820entry *)VXWORKS_E820_DATA_ADDR;
	tmp = getenv("e820info");
	if (tmp)
		info = (struct e820info *)simple_strtoul(tmp, NULL, 16);
	else
		info = (struct e820info *)VXWORKS_E820_INFO_ADDR;

	memset(info, 0, sizeof(struct e820info));
	info->sign = E820_SIGNATURE;
	info->entries = install_e820_map(E820MAX, data);
	info->addr = (info->entries - 1) * sizeof(struct e820entry) +
		     VXWORKS_E820_DATA_ADDR;
#endif

	/*
	 * If the data at the load address is an elf image, then
	 * treat it like an elf image. Otherwise, assume that it is a
	 * binary image.
	 */
	if (valid_elf_image(addr))
		addr = load_elf_image_shdr(addr);
	else
		puts("## Not an ELF image, assuming binary\n");

	printf("## Starting vxWorks at 0x%08lx ...\n", addr);

	dcache_disable();
#ifdef CONFIG_X86
	/* VxWorks on x86 uses stack to pass parameters */
	((asmlinkage void (*)(int))addr)(0);
#else
	((void (*)(int))addr)(0);
#endif

	puts("## vxWorks terminated\n");

	return 1;
}
예제 #11
0
/* ======================================================================
 * Interpreter command to boot VxWorks from a memory image.  The image can
 * be either an ELF image or a raw binary.  Will attempt to setup the
 * bootline and other parameters correctly.
 * ====================================================================== */
int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	unsigned long addr;		/* Address of image            */
	unsigned long bootaddr;	/* Address to put the bootline */
	char *bootline;			/* Text of the bootline        */
	char *tmp;			/* Temporary char pointer      */
	char build_buf[128];		/* Buffer for building the bootline */

	/* ---------------------------------------------------
	 *
	 * Check the loadaddr variable.
	 * If we don't know where the image is then we're done.
	 */

	if (argc < 2)
		addr = load_addr;
	else
		addr = simple_strtoul(argv[1], NULL, 16);

#if defined(CONFIG_CMD_NET)
	/*
	 * Check to see if we need to tftp the image ourselves before starting
	 */
	if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
		if (NetLoop(TFTPGET) <= 0)
			return 1;
		printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
			addr);
	}
#endif

	/* This should equate
	 * to NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
	 * from the VxWorks BSP header files.
	 * This will vary from board to board
	 */

#if defined(CONFIG_WALNUT)
	tmp = (char *) CONFIG_SYS_NVRAM_BASE_ADDR + 0x500;
	eth_getenv_enetaddr("ethaddr", (uchar *)build_buf);
	memcpy(tmp, &build_buf[3], 3);
#elif defined(CONFIG_SYS_VXWORKS_MAC_PTR)
	tmp = (char *) CONFIG_SYS_VXWORKS_MAC_PTR;
	eth_getenv_enetaddr("ethaddr", (uchar *)build_buf);
	memcpy(tmp, build_buf, 6);
#else
	puts("## Ethernet MAC address not copied to NV RAM\n");
#endif

	/*
	 * Use bootaddr to find the location in memory that VxWorks
	 * will look for the bootline string. The default value for
	 * PowerPC is LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET which
	 * defaults to 0x4200
	 */
	tmp = getenv("bootaddr");
	if (tmp)
		bootaddr = CONFIG_SYS_VXWORKS_BOOT_ADDR;
	else
		bootaddr = simple_strtoul(tmp, NULL, 16);

	/*
	 * Check to see if the bootline is defined in the 'bootargs'
	 * parameter. If it is not defined, we may be able to
	 * construct the info
	 */
	bootline = getenv("bootargs");
	if (bootline) {
		memcpy((void *) bootaddr, bootline,
			max(strlen(bootline), 255));
		flush_cache(bootaddr, max(strlen(bootline), 255));
	} else {
		sprintf(build_buf, CONFIG_SYS_VXWORKS_BOOT_DEVICE);
		tmp = getenv("bootfile");
		if (tmp)
			sprintf(&build_buf[strlen(build_buf)],
				 "%s:%s ", CONFIG_SYS_VXWORKS_SERVERNAME, tmp);
		else
			sprintf(&build_buf[strlen(build_buf)],
				 "%s:file ", CONFIG_SYS_VXWORKS_SERVERNAME);

		tmp = getenv("ipaddr");
		if (tmp)
			sprintf(&build_buf[strlen(build_buf)], "e=%s ", tmp);

		tmp = getenv("serverip");
		if (tmp)
			sprintf(&build_buf[strlen(build_buf)], "h=%s ", tmp);

		tmp = getenv("hostname");
		if (tmp)
			sprintf(&build_buf[strlen(build_buf)], "tn=%s ", tmp);

#ifdef CONFIG_SYS_VXWORKS_ADD_PARAMS
		sprintf(&build_buf[strlen(build_buf)],
			 CONFIG_SYS_VXWORKS_ADD_PARAMS);
#endif

		memcpy((void *) bootaddr, build_buf,
			max(strlen(build_buf), 255));
		flush_cache(bootaddr, max(strlen(build_buf), 255));
	}

	/*
	 * If the data at the load address is an elf image, then
	 * treat it like an elf image. Otherwise, assume that it is a
	 * binary image
	 */

	if (valid_elf_image(addr)) {
		addr = load_elf_image_shdr(addr);
	} else {
		puts("## Not an ELF image, assuming binary\n");
		/* leave addr as load_addr */
	}

	printf("## Using bootline (@ 0x%lx): %s\n", bootaddr,
			(char *) bootaddr);
	printf("## Starting vxWorks at 0x%08lx ...\n", addr);

	dcache_disable();
	((void (*)(int)) addr) (0);

	puts("## vxWorks terminated\n");
	return 1;
}
예제 #12
0
int BootHomebrew()
{

    char* abuf;
    size_t asize;

    if(homebrewsize == 0)
        return -1;

    entrypoint entry;
    u32 cpu_isr;

	arg_init();

	if (wiiload_args)
	{
		abuf = temp_arg;
		asize = strlen(abuf);
		while (asize != 0)
		{
			xprintf("argument = %s\n",abuf);
			arg_add(abuf);
			abuf+=asize;
			abuf+=1;
			asize = strlen(abuf);
		}
	}
	else
	{
		arg_add(filepath.c_str()); // argv[0] = filepath
		while(parser(Settings.forwarder_arg, "<arg>", "</arg>") != "")
		{
			arg_add(parser(Settings.forwarder_arg, "<arg>", "</arg>").c_str());
			Settings.forwarder_arg.erase(0, Settings.forwarder_arg.find("</arg>") +1);
		}
	}

	if ( valid_elf_image(homebrewbuffer) == 1 )
		entry = (entrypoint) load_elf_image(homebrewbuffer);
	else
		entry = (entrypoint) load_dol(homebrewbuffer, &args);

    if (!entry)
        return -1;

	//ExitApp();
//we can't use check_uneek_fs
//as we already shut down the uneek_fs system
//so it will always return false

	if (in_neek == false)
	{
		xprintf("Booting Homebrew");
		if(wiiload)
		{
			xprintf(" via wiiload\n");

			if(Options.wiiload_ahb == 2)
			{
				xprintf("with HW_AHBPROT\n");
				Patch_ahbprot();
			}

			if(Options.wiiload_ahb != 0)
			{
				xprintf("with IOS reload\n");
				IOS_ReloadIOS(Options.wiiload_ios);
			}
			else
				xprintf("without reloading IOS\n");
		}
		else
		{
			xprintf(" from storage device\n");
			if(Settings.force_reload == "HW_AHBPROT")
			{
				xprintf("with HW_AHBPROT\n");
				Patch_ahbprot();
			}

			if(Settings.force_reload != "NORELOAD")
			{
				xprintf("with IOS reload\n");
				IOS_ReloadIOS(SelectedIOS());
			}
			else
				xprintf("without IOS reload\n");
		}
	}

	wiiload_args = 0;

	/*this will also be called when wiiloading an application
	will need to check if it's expected behavour? */

/*
	if(!wiiload_args)
	{

		if(SelectedIOS() != IOS_GetVersion() || Settings.force_reload != "")
		{
			//keep ahbprot rights in new ios
			Patch_ahbprot();
			IOS_ReloadIOS(SelectedIOS());
		}
	}
    wiiload_args = 0;
*/
    SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
    _CPU_ISR_Disable (cpu_isr);
    __exception_closeall();
    entry();
    _CPU_ISR_Restore (cpu_isr);

    return 0;
}
예제 #13
0
/* ======================================================================
 * Interpreter command to boot VxWorks from a memory image.  The image can
 * be either an ELF image or a raw binary.  Will attempt to setup the
 * bootline and other parameters correctly.
 * ====================================================================== */
int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	unsigned long addr;		/* Address of image            */
	unsigned long bootaddr;		/* Address to put the bootline */
	char *bootline;			/* Text of the bootline        */
	char *tmp;			/* Temporary char pointer      */

#if defined(CONFIG_4xx) || defined(CONFIG_IOP480)
	char build_buf[80];		/* Buffer for building the bootline */
#endif
	/* -------------------------------------------------- */

	/*
	 * Check the loadaddr variable.
	 * If we don't know where the image is then we're done.
	 */

	if (argc < 2)
		addr = load_addr;
	else
		addr = simple_strtoul (argv[1], NULL, 16);

#if (CONFIG_COMMANDS & CFG_CMD_NET)
	/* Check to see if we need to tftp the image ourselves before starting */

	if ((argc == 2) && (strcmp (argv[1], "tftp") == 0)) {
		if (NetLoop (TFTP) <= 0)
			return 1;
		printf ("Automatic boot of VxWorks image at address 0x%08lx ... \n", addr);
	}
#endif

	/* This should equate
	 * to NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
	 * from the VxWorks BSP header files.
	 * This will vary from board to board
	 */

#if defined(CONFIG_WALNUT)
	tmp = (char *) CFG_NVRAM_BASE_ADDR + 0x500;
	memcpy ((char *) tmp, (char *) &gd->bd->bi_enetaddr[3], 3);
#elif defined(CFG_VXWORKS_MAC_PTR)
	tmp = (char *) CFG_VXWORKS_MAC_PTR;
	memcpy ((char *) tmp, (char *) &gd->bd->bi_enetaddr[0], 6);
#else
	puts ("## Ethernet MAC address not copied to NV RAM\n");
#endif

	/*
	 * Use bootaddr to find the location in memory that VxWorks
	 * will look for the bootline string. The default value for
	 * PowerPC is LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET which
	 * defaults to 0x4200
	 */

	if ((tmp = getenv ("bootaddr")) == NULL)
		bootaddr = 0x4200;
	else
		bootaddr = simple_strtoul (tmp, NULL, 16);

	/*
	 * Check to see if the bootline is defined in the 'bootargs'
	 * parameter. If it is not defined, we may be able to
	 * construct the info
	 */

	if ((bootline = getenv ("bootargs")) != NULL) {
		memcpy ((void *) bootaddr, bootline, MAX(strlen(bootline), 255));
		flush_cache (bootaddr, MAX(strlen(bootline), 255));
	} else {
#if defined(CONFIG_4xx)
		sprintf (build_buf, "ibmEmac(0,0)");

		if ((tmp = getenv ("hostname")) != NULL) {
			sprintf (&build_buf[strlen (build_buf - 1)],
				"host:%s ", tmp);
		} else {
			sprintf (&build_buf[strlen (build_buf - 1)],
				": ");
		}

		if ((tmp = getenv ("ipaddr")) != NULL) {
			sprintf (&build_buf[strlen (build_buf - 1)],
				"e=%s ", tmp);
		}
		memcpy ((void *)bootaddr, build_buf, MAX(strlen(build_buf), 255));
		flush_cache (bootaddr, MAX(strlen(build_buf), 255));
#elif defined(CONFIG_IOP480)
		sprintf (build_buf, "dc(0,0)");

		if ((tmp = getenv ("hostname")) != NULL) {
			sprintf (&build_buf[strlen (build_buf - 1)],
				"host:%s ", tmp);
		} else {
			sprintf (&build_buf[strlen (build_buf - 1)],
				": ");
		}

		if ((tmp = getenv ("ipaddr")) != NULL) {
			sprintf (&build_buf[strlen (build_buf - 1)],
				"e=%s ", tmp);
		}
		memcpy ((void *) bootaddr, build_buf, MAX(strlen(build_buf), 255));
		flush_cache (bootaddr, MAX(strlen(build_buf), 255));
#else

		/*
		 * I'm not sure what the device should be for other
		 * PPC flavors, the hostname and ipaddr should be ok
		 * to just copy
		 */

		puts ("No bootargs defined\n");
		return 1;
#endif
	}

	/*
	 * If the data at the load address is an elf image, then
	 * treat it like an elf image. Otherwise, assume that it is a
	 * binary image
	 */

	if (valid_elf_image (addr)) {
		addr = load_elf_image (addr);
	} else {
		puts ("## Not an ELF image, assuming binary\n");
		/* leave addr as load_addr */
	}

	printf ("## Using bootline (@ 0x%lx): %s\n", bootaddr,
			(char *) bootaddr);
	printf ("## Starting vxWorks at 0x%08lx ...\n", addr);

	((void (*)(void)) addr) ();

	puts ("## vxWorks terminated\n");
	return 1;
}
예제 #14
0
파일: elf.c 프로젝트: axxia/axxia_u-boot
/*
 * Interpreter command to boot VxWorks from a memory image.  The image can
 * be either an ELF image or a raw binary.  Will attempt to setup the
 * bootline and other parameters correctly.
 */
int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	unsigned long addr; /* Address of image */
	unsigned long bootaddr = 0; /* Address to put the bootline */
	char *bootline; /* Text of the bootline */
	char *tmp; /* Temporary char pointer */
	char build_buf[128]; /* Buffer for building the bootline */
	int ptr = 0;
#ifdef CONFIG_X86
	ulong base;
	struct e820_info *info;
	struct e820_entry *data;
	struct efi_gop_info *gop;
	struct vesa_mode_info *vesa = &mode_info.vesa;
#endif

	/*
	 * Check the loadaddr variable.
	 * If we don't know where the image is then we're done.
	 */
	if (argc < 2)
		addr = load_addr;
	else
		addr = simple_strtoul(argv[1], NULL, 16);

#if defined(CONFIG_CMD_NET)
	/*
	 * Check to see if we need to tftp the image ourselves
	 * before starting
	 */
	if ((argc == 2) && (strcmp(argv[1], "tftp") == 0)) {
		if (net_loop(TFTPGET) <= 0)
			return 1;
		printf("Automatic boot of VxWorks image at address 0x%08lx ...\n",
			addr);
	}
#endif

	/*
	 * This should equate to
	 * NV_RAM_ADRS + NV_BOOT_OFFSET + NV_ENET_OFFSET
	 * from the VxWorks BSP header files.
	 * This will vary from board to board
	 */
#if defined(CONFIG_SYS_VXWORKS_MAC_PTR)
	tmp = (char *)CONFIG_SYS_VXWORKS_MAC_PTR;
	eth_env_get_enetaddr("ethaddr", (uchar *)build_buf);
	memcpy(tmp, build_buf, 6);
#else
	puts("## Ethernet MAC address not copied to NV RAM\n");
#endif

#ifdef CONFIG_X86
	/*
	 * Get VxWorks's physical memory base address from environment,
	 * if we don't specify it in the environment, use a default one.
	 */
	base = env_get_hex("vx_phys_mem_base", VXWORKS_PHYS_MEM_BASE);
	data = (struct e820_entry *)(base + E820_DATA_OFFSET);
	info = (struct e820_info *)(base + E820_INFO_OFFSET);

	memset(info, 0, sizeof(struct e820_info));
	info->sign = E820_SIGNATURE;
	info->entries = install_e820_map(E820MAX, data);
	info->addr = (info->entries - 1) * sizeof(struct e820_entry) +
		     E820_DATA_OFFSET;

	/*
	 * Explicitly clear the bootloader image size otherwise if memory
	 * at this offset happens to contain some garbage data, the final
	 * available memory size for the kernel is insane.
	 */
	*(u32 *)(base + BOOT_IMAGE_SIZE_OFFSET) = 0;

	/*
	 * Prepare compatible framebuffer information block.
	 * The VESA mode has to be 32-bit RGBA.
	 */
	if (vesa->x_resolution && vesa->y_resolution) {
		gop = (struct efi_gop_info *)(base + EFI_GOP_INFO_OFFSET);
		gop->magic = EFI_GOP_INFO_MAGIC;
		gop->info.version = 0;
		gop->info.width = vesa->x_resolution;
		gop->info.height = vesa->y_resolution;
		gop->info.pixel_format = EFI_GOT_RGBA8;
		gop->info.pixels_per_scanline = vesa->bytes_per_scanline / 4;
		gop->fb_base = vesa->phys_base_ptr;
		gop->fb_size = vesa->bytes_per_scanline * vesa->y_resolution;
	}
#endif

	/*
	 * Use bootaddr to find the location in memory that VxWorks
	 * will look for the bootline string. The default value is
	 * (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
	 * VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
	 */
	tmp = env_get("bootaddr");
	if (!tmp) {
#ifdef CONFIG_X86
		bootaddr = base + X86_BOOT_LINE_OFFSET;
#else
		printf("## VxWorks bootline address not specified\n");
		return 1;
#endif
	}

	if (!bootaddr)
		bootaddr = simple_strtoul(tmp, NULL, 16);

	/*
	 * Check to see if the bootline is defined in the 'bootargs' parameter.
	 * If it is not defined, we may be able to construct the info.
	 */
	bootline = env_get("bootargs");
	if (!bootline) {
		tmp = env_get("bootdev");
		if (tmp) {
			strcpy(build_buf, tmp);
			ptr = strlen(tmp);
		} else {
			printf("## VxWorks boot device not specified\n");
		}

		tmp = env_get("bootfile");
		if (tmp)
			ptr += sprintf(build_buf + ptr, "host:%s ", tmp);
		else
			ptr += sprintf(build_buf + ptr, "host:vxWorks ");

		/*
		 * The following parameters are only needed if 'bootdev'
		 * is an ethernet device, otherwise they are optional.
		 */
		tmp = env_get("ipaddr");
		if (tmp) {
			ptr += sprintf(build_buf + ptr, "e=%s", tmp);
			tmp = env_get("netmask");
			if (tmp) {
				u32 mask = env_get_ip("netmask").s_addr;
				ptr += sprintf(build_buf + ptr,
					       ":%08x ", ntohl(mask));
			} else {
				ptr += sprintf(build_buf + ptr, " ");
			}
		}

		tmp = env_get("serverip");
		if (tmp)
			ptr += sprintf(build_buf + ptr, "h=%s ", tmp);

		tmp = env_get("gatewayip");
		if (tmp)
			ptr += sprintf(build_buf + ptr, "g=%s ", tmp);

		tmp = env_get("hostname");
		if (tmp)
			ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);

		tmp = env_get("othbootargs");
		if (tmp) {
			strcpy(build_buf + ptr, tmp);
			ptr += strlen(tmp);
		}

		bootline = build_buf;
	}

	memcpy((void *)bootaddr, bootline, max(strlen(bootline), (size_t)255));
	flush_cache(bootaddr, max(strlen(bootline), (size_t)255));
	printf("## Using bootline (@ 0x%lx): %s\n", bootaddr, (char *)bootaddr);

	/*
	 * If the data at the load address is an elf image, then
	 * treat it like an elf image. Otherwise, assume that it is a
	 * binary image.
	 */
	if (valid_elf_image(addr))
		addr = load_elf_image_phdr(addr);
	else
		puts("## Not an ELF image, assuming binary\n");

	printf("## Starting vxWorks at 0x%08lx ...\n", addr);

	dcache_disable();
#if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
	armv8_setup_psci();
	smp_kick_all_cpus();
#endif

#ifdef CONFIG_X86
	/* VxWorks on x86 uses stack to pass parameters */
	((asmlinkage void (*)(int))addr)(0);
#else
	((void (*)(int))addr)(0);
#endif

	puts("## vxWorks terminated\n");

	return 1;
}
예제 #15
0
//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

	#ifdef DEBUG
		init_video_and_wpad();
		printf("::: Configurable USB Loader - Forwarder Universal [SD/USB] by Narolez :::\n\n");
	#endif

	// create a buffer for the elf/dol content
	void* myBuffer;
	
	// read elf/dol from given path:
	FILE* inputFile;

	// try loading from SD
	inputFile = tryOpenDolFromSD();
	
	// dol file on SD not found
	if(inputFile == NULL) 
	{
		// try loading from USB
		inputFile = tryOpenDolFromUSB();
	}

	// dol file on SD or USB not found
	if(inputFile == NULL) 
	{
		init_video_and_wpad();
		printf("\nError: Couldn't open file!\n");
		printf("Press any button to reboot Wii...\n");
		press_button_to_reboot();
	}
	
	#ifdef DEBUG	
	printf("\n[+] Loading %s to buffer ... ", filename);
	#endif
	
	int pos = ftell(inputFile);
	fseek(inputFile, 0, SEEK_END);
	int size = ftell(inputFile);
	fseek(inputFile, pos, SEEK_SET); //return to previous position

	myBuffer = malloc(size);
	fread( myBuffer, 1, size, inputFile);

	fclose(inputFile);

	#ifdef DEBUG	
	printf("OK!\n");
	#endif
	
	release_storage();
	
	#ifdef DEBUG	
	printf("\n[+] Running ... ");
	#endif

	//Check if valid elf file:
	s32 res;
	res = valid_elf_image(myBuffer);
    if(res == 1) 
	{
		//elf ok! -> Load entry point of elf file:
		void (*ep)();
		ep = (void(*)())load_elf_image(myBuffer);

		// code from geckoloader
		u32 level;
		__IOS_ShutdownSubsystems ();
		//printf("IOS_ShutdownSubsystems() done\n");
		_CPU_ISR_Disable (level);
		//printf("_CPU_ISR_Disable() done\n");
		__exception_closeall ();
		//printf("__exception_closeall() done. Jumping to ep now...\n");
		
		ep();
		_CPU_ISR_Restore (level);
	} else 
	{
		//Elf not valid, load dol:
		
		//Stuff for arguments
		struct __argv argv;
		bzero(&argv, sizeof(argv));
		argv.argvMagic = ARGV_MAGIC;
		argv.length = strlen(filename) + 2;
		argv.commandLine = malloc(argv.length);
		if (!argv.commandLine)
		{
			init_video_and_wpad();
			printf("Error creating arguments, could not allocate memory for commandLine\n");
			printf("Press any button to reboot Wii...\n");
			press_button_to_reboot();
		}
		strcpy(argv.commandLine, filename);
		argv.commandLine[argv.length - 1] = '\x00';
		argv.argc = 1;
		argv.argv = &argv.commandLine;
		argv.endARGV = argv.argv + 1;

		run_dol(myBuffer, &argv);		
	}
	
	#ifdef DEBUG	
	printf("HAVE FUN!");
	#endif
	
	return 0;
}