Ejemplo n.º 1
0
/*
 * Replaces the default shell in xload configuration
 */
int run_shell(void)
{
	int (*func)(void) = NULL;

	switch (omap_bootsrc())
	{
	case OMAP_BOOTSRC_MMC1:
		printf("booting from MMC1\n");
		func = omap_xload_boot_mmc();
		break;
	case OMAP_BOOTSRC_UNKNOWN:
		printf("unknown boot source. Fall back to nand\n");
	case OMAP_BOOTSRC_NAND:
		printf("booting from NAND\n");
		func = omap_xload_boot_nand(SZ_128K, SZ_256K);
		break;
	}

	if (!func) {
		printf("booting failed\n");
		while (1);
	}

	shutdown_barebox();
	func();

	while (1);
}
Ejemplo n.º 2
0
static int do_bootm_kwbimage_v0_v1(struct image_data *data)
{
	int fd, ret;
	loff_t offset;
	char header[0x20];
	u32 image_size, image_source;
	void (*barebox)(void);

	fd = open(data->os_file, O_RDONLY);
	if (fd < 0)
		return fd;

	ret = read_full(fd, header, 0x20);
	if (ret < 0x20) {
		pr_err("Failed to read header\n");
		if (ret >= 0)
			return -EINVAL;
		return -errno;
	}

	image_size = header[4] | header[5] << 8 | header[6] << 16 | header[7] << 24;
	image_source = header[0xc] | header[0xd] << 8 |
		header[0xe] << 16 | header[0xf] << 24;

	if (data->verbose)
		pr_info("size: %u\noffset: %u\n", image_size, image_source);

	offset = lseek(fd, image_source, SEEK_SET);
	if (offset < 0) {
		pr_err("Failed to seek to image (%lld, %d)\n", offset, errno);
		return -errno;
	}

	barebox = xzalloc(image_size);

	ret = read_full(fd, barebox, image_size);
	if (ret < image_size) {
		pr_err("Failed to read image\n");
		if (ret >= 0)
			ret = -EINVAL;
		else
			ret = -errno;
		goto out_free;
	}

	if (is_barebox_arm_head((void *)barebox))
		put_unaligned_le32(MVEBU_REMAP_INT_REG_BASE, barebox + 0x30);

	shutdown_barebox();

	barebox();

	restart_machine();

out_free:
	free(barebox);
	return ret;
}
Ejemplo n.º 3
0
static void __noreturn pxa2xx_poweroff(struct poweroff_handler *handler)
{
	shutdown_barebox();

	/* Clear last reset source */
	pxa_clear_reset_source();
	pxa_suspend(PWRMODE_DEEPSLEEP);
	unreachable();
}
Ejemplo n.º 4
0
void __noreturn omap_start_barebox(void *barebox)
{
	int (*func)(void *) = barebox;
	void *sramadr = omap_sram_start();
	void *scratch = omap_scratch_space_start();

	memcpy(sramadr, scratch, sizeof(uint32_t) * 3);

	shutdown_barebox();
	func(sramadr);
	hang();
}
Ejemplo n.º 5
0
void __noreturn poweroff()
{
	u32 ctrl;

	shutdown_barebox();

	do {
		ctrl = readl((u32 *)RTC_RCR);
	} while (!(ctrl & RTC_RCR_WRDY));

	writel(RTC_HCR_PD, (u32 *)RTC_HCR);
	jz4750d_halt();
}
Ejemplo n.º 6
0
static int do_bootm_barebox(struct image_data *data)
{
	void (*barebox)(void);

	barebox = read_file(data->os_file, NULL);
	if (!barebox)
		return -EINVAL;

	shutdown_barebox();

	barebox();

	reset_cpu(0);
}
Ejemplo n.º 7
0
static int do_go(int argc, char *argv[])
{
	void	*addr;
	int     rcode = 1;
	int	fd = -1;
	int	(*func)(int argc, char *argv[]);

	if (argc < 2)
		return COMMAND_ERROR_USAGE;

	if (!isdigit(*argv[1])) {
		fd = open(argv[1], O_RDONLY);
		if (fd < 0) {
			perror("open");
			goto out;
		}

		addr = memmap(fd, PROT_READ);
		if (addr == (void *)-1) {
			perror("memmap");
			goto out;
		}
	} else
		addr = (void *)simple_strtoul(argv[1], NULL, 16);

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

	console_flush();

	func = addr;

	shutdown_barebox();

	if (do_execute)
		do_execute(func, argc - 1, &argv[1]);
	else
		func(argc - 1, &argv[1]);

	/*
	 * The application returned. Since we have shutdown barebox and
	 * we know nothing about the state of the cpu/memory we can't
	 * do anything here.
	 */
	while (1);
out:
	if (fd > 0)
		close(fd);

	return rcode;
}
Ejemplo n.º 8
0
static int do_bootm_barebox(struct image_data *data)
{
	void (*barebox)(void);

	barebox = read_file(data->os_file, NULL);
	if (!barebox)
		return -EINVAL;

	if (data->dryrun) {
		free(barebox);
		return 0;
	}

	shutdown_barebox();

	barebox();

	restart_machine();
}
Ejemplo n.º 9
0
static int do_at91_boot_test(int argc, char *argv[])
{
	int opt;
	u32 *buf32;
	void *buf;
	void (*jump)(void) = NULL;
	int fd;
	int ret = 1;
	char *sram = "/dev/sram0";
	u32 read_size, write_size;
	u32 tmp = 0;

	while ((opt = getopt(argc, argv, "j:s:")) > 0) {
		switch (opt) {
		case 'j':
			jump = (void*)simple_strtoul(optarg, NULL, 0);
			break;
		case 's':
			sram = optarg;
			break;
		default:
			return COMMAND_ERROR_USAGE;
		}
	}

	if (argc < optind + 1)
		return COMMAND_ERROR_USAGE;

	buf32 = buf = read_file(argv[optind], &read_size);
	if (!buf)
		return -EINVAL;

	write_size = buf32[5];

	printf("size of the size %d\n", read_size);
	printf("size to load in sram %d\n", write_size);

	if (write_size > read_size) {
		printf("file smaller than requested sram loading size (%d < %d)\n", write_size, read_size);
		goto err;
	}

	fd = open(sram, O_WRONLY);
	if (fd < 0) {
		printf("could not open %s: %s\n", sram, errno_str());
		ret = fd;
		goto err;
	}

	while (write_size) {
		tmp = write(fd, buf, write_size);
		if (tmp < 0) {
			perror("write");
			goto err_open;
		}
		buf += tmp;
		write_size -= tmp;
	}

	shutdown_barebox();

	jump();

err_open:
	close(fd);
err:
	free(buf);
	return ret;
}
Ejemplo n.º 10
0
static int do_bootm_aimage(struct image_data *data)
{
	struct resource *snd_stage_res;
	int fd, ret;
	struct android_header __header, *header;
	void *buf;
	int to_read;
	struct android_header_comp *cmp;
	unsigned long mem_free;
	unsigned long mem_start, mem_size;

	ret = sdram_start_and_size(&mem_start, &mem_size);
	if (ret)
		return ret;

	fd = open(data->os_file, O_RDONLY);
	if (fd < 0) {
		perror("open");
		return 1;
	}

	header = &__header;
	ret = read(fd, header, sizeof(*header));
	if (ret < sizeof(*header)) {
		printf("could not read %s\n", data->os_file);
		goto err_out;
	}

	printf("Android Image for '%s'\n", header->name);

	/*
	 * As on tftp we do not support lseek and we will just have to seek
	 * for the size of a page - 1 max just buffer instead to read to dummy
	 * data
	 */
	buf = xmalloc(header->page_size);

	to_read = header->page_size - sizeof(*header);
	ret = read_full(fd, buf, to_read);
	if (ret < 0) {
		printf("could not read dummy %d from %s\n", to_read, data->os_file);
		goto err_out;
	}

	cmp = &header->kernel;
	data->os_res = request_sdram_region("akernel", cmp->load_addr, cmp->size);
	if (!data->os_res) {
		pr_err("Cannot request region 0x%08x - 0x%08x, using default load address\n",
				cmp->load_addr, cmp->size);

		data->os_address = mem_start + PAGE_ALIGN(cmp->size * 4);
		data->os_res = request_sdram_region("akernel", data->os_address, cmp->size);
		if (!data->os_res) {
			pr_err("Cannot request region 0x%08x - 0x%08x\n",
					cmp->load_addr, cmp->size);
			ret = -ENOMEM;
			goto err_out;
		}
	}

	ret = aimage_load_resource(fd, data->os_res, buf, header->page_size);
	if (ret < 0) {
		perror("could not read kernel");
		goto err_out;
	}

	/*
	 * fastboot always expect a ramdisk
	 * in barebox we can be less restrictive
	 */
	cmp = &header->ramdisk;
	if (cmp->size) {
		data->initrd_res = request_sdram_region("ainitrd", cmp->load_addr, cmp->size);
		if (!data->initrd_res) {
			ret = -ENOMEM;
			goto err_out;
		}

		ret = aimage_load_resource(fd, data->initrd_res, buf, header->page_size);
		if (ret < 0) {
			perror("could not read initrd");
			goto err_out;
		}
	}

	if (!getenv("aimage_noverwrite_bootargs"))
		linux_bootargs_overwrite(header->cmdline);

	if (!getenv("aimage_noverwrite_tags"))
		armlinux_set_bootparams((void*)header->tags_addr);

	cmp = &header->second_stage;
	if (cmp->size) {
		void (*second)(void);

		snd_stage_res = request_sdram_region("asecond", cmp->load_addr, cmp->size);
		if (!snd_stage_res) {
			ret = -ENOMEM;
			goto err_out;
		}

		ret = aimage_load_resource(fd, snd_stage_res, buf, header->page_size);
		if (ret < 0) {
			perror("could not read initrd");
			goto err_out;
		}

		second = (void*)snd_stage_res->start;
		shutdown_barebox();

		second();

		restart_machine();
	}

	close(fd);

	/*
	 * Put devicetree right after initrd if present or after the kernel
	 * if not.
	 */
	if (data->initrd_res)
		mem_free = PAGE_ALIGN(data->initrd_res->end);
	else
		mem_free = PAGE_ALIGN(data->os_res->end + SZ_1M);

	return __do_bootm_linux(data, mem_free, 0);

err_out:
	linux_bootargs_overwrite(NULL);
	close(fd);

	return ret;
}
Ejemplo n.º 11
0
static int do_bootm_aimage(struct image_data *data)
{
	struct resource *snd_stage_res;
	int fd, ret;
	struct android_header __header, *header;
	void *buf;
	int to_read;
	struct android_header_comp *cmp;

	fd = open(data->os_file, O_RDONLY);
	if (fd < 0) {
		perror("open");
		return 1;
	}

	header = &__header;
	ret = read(fd, header, sizeof(*header));
	if (ret < sizeof(*header)) {
		printf("could not read %s\n", data->os_file);
		goto err_out;
	}

	printf("Android Image for '%s'\n", header->name);

	/*
	 * As on tftp we do not support lseek and we will just have to seek
	 * for the size of a page - 1 max just buffer instead to read to dummy
	 * data
	 */
	buf = xmalloc(header->page_size);

	to_read = header->page_size - sizeof(*header);
	ret = read_full(fd, buf, to_read);
	if (ret < 0) {
		printf("could not read dummy %d from %s\n", to_read, data->os_file);
		goto err_out;
	}

	cmp = &header->kernel;
	data->os_res = request_sdram_region("akernel", cmp->load_addr, cmp->size);
	if (!data->os_res) {
		ret = -ENOMEM;
		goto err_out;
	}

	ret = aimage_load_resource(fd, data->os_res, buf, header->page_size);
	if (ret < 0) {
		perror("could not read kernel");
		goto err_out;
	}

	/*
	 * fastboot always expect a ramdisk
	 * in barebox we can be less restrictive
	 */
	cmp = &header->ramdisk;
	if (cmp->size) {
		data->initrd_res = request_sdram_region("ainitrd", cmp->load_addr, cmp->size);
		if (!data->initrd_res) {
			ret = -ENOMEM;
			goto err_out;
		}

		ret = aimage_load_resource(fd, data->initrd_res, buf, header->page_size);
		if (ret < 0) {
			perror("could not read initrd");
			goto err_out;
		}
	}

	if (!getenv("aimage_noverwrite_bootargs"))
		linux_bootargs_overwrite(header->cmdline);

	if (!getenv("aimage_noverwrite_tags"))
		armlinux_set_bootparams((void*)header->tags_addr);

	cmp = &header->second_stage;
	if (cmp->size) {
		void (*second)(void);

		snd_stage_res = request_sdram_region("asecond", cmp->load_addr, cmp->size);
		if (!snd_stage_res) {
			ret = -ENOMEM;
			goto err_out;
		}

		ret = aimage_load_resource(fd, snd_stage_res, buf, header->page_size);
		if (ret < 0) {
			perror("could not read initrd");
			goto err_out;
		}

		second = (void*)snd_stage_res->start;
		shutdown_barebox();

		second();

		reset_cpu(0);
	}

	close(fd);
	return __do_bootm_linux(data, 0);

err_out:
	linux_bootargs_overwrite(NULL);
	close(fd);

	return ret;
}