Exemple #1
0
void moboot_init(const struct app_descriptor *app)
{
	int rv, keys_pressed;
	unsigned act;
	char *entries[10];

	keys_pressed = 0;

	if (gpiokeys_poll(KEY_ALL)) {
		keys_pressed = 1;
		printf("\nPlease release key(s)...\n");
		while (1) {
			thread_sleep(20);
			if (!gpiokeys_poll(KEY_ALL)) {
				break;
			}
		}
	}

	fbcon_clear();
	fbcon_setpos(0,0);
	printf("welcome to moboot\n");

	entries[0] = "Recover";
	entries[1] = "Reboot";
	entries[2] = "Shutdown";

	act = moboot_menu(0, 2, entries, 0, 3, keys_pressed ? 0 : 9);

	fbcon_setpos(0, 2 + 3 + 2); /* y_start + num_entries + 2 */

	if (act == 0) {
		reboot_device(RESTART_REASON_RECOVER);
	} else if (act == 1) {
		reboot_device(RESTART_REASON_REBOOT);
	} else if (act == 2) {
		reboot_device(RESTART_REASON_SHUTDOWN);
	}

}
Exemple #2
0
void moboot_init(const struct app_descriptor *app)
{
	int rv, keys_pressed;
	unsigned act;
	menu_entry_t *real_entries[32];

	char *ptr;
	int rc;
	char path[256];
	char *newpath;
	char *newtitle;
	char *newname;

	unsigned xoff, yoff;

	unsigned ramdisk_mounted, ramdisk_start, ramdisk_size;

	unsigned i, j;

	unsigned default_menu_entry = 0;
	unsigned next_menu_entry = 0;

	char default_image[256];
	char next_image[256];

	unsigned default_timeout;
	unsigned counted_images;
	unsigned use_next;
	ssize_t splash_sz;
	void *splash_ptr = NULL;
	ssize_t background_sz;
	void *background_ptr;
	ssize_t tile_sz;
	void *tile_ptr;
	char splash_path[256];

	unsigned boot_flags;

	ssize_t rdmsgsz;
	char *rdmsg;

	keys_pressed = 0;

	display_surface = NULL;

	entries = real_entries;

	gfx_trans = 0;

	gfxconsole_clear();
	gfxconsole_setpos(0,0);

	ramdisk_mounted = 0;
	atags_get_ramdisk(&ramdisk_start, &ramdisk_size);
	if (ramdisk_size && ramdisk_start) {
		ramdisk_init((void*)ramdisk_start, ramdisk_size);
		if (fs_mount("/ramdisk", "/dev/ramdisk")) {
			printf("Ramdisk start=%08x size=%08x\n", ramdisk_start, ramdisk_size);
			printf("Unable to mount /ramdisk\n");
			printf("Press SELECT to continue\n");
			gpiokeys_wait_select();
		} else {
			ramdisk_mounted = 1;
		}
	}


    if (fs_mount("/boot", "/dev/mmcblk0p13")) {
		printf("\nUnable to mount /boot, exiting.\n");
		while (1) {
			thread_sleep(20);
		}
	}

	default_timeout = 5;
	if ((rv = fs_load_file("/boot/moboot.timeout", &default_image, 256)) > 0) {
		default_image[rv] = 0;
		if (default_image[rv - 1] == '\n') default_image[rv - 1] = 0;
		default_timeout = atoui(default_image);
	}
	default_image[0] = 0;
	rv = fs_load_file("/boot/moboot.default", &default_image, 256);
	if (rv > 0) {
		default_image[rv] = 0;
		if (default_image[rv - 1] == '\n') default_image[rv - 1] = 0;
	}
	use_next = 0;
	next_image[0] = 0;
	rv = fs_load_file("/boot/moboot.next", &next_image, 256);
	if (rv > 0) {
		next_image[rv] = 0;
		if (next_image[rv - 1] == '\n') next_image[rv - 1] = 0;
	}

	tile_sz = fs_load_file_mem("/boot/moboot.background.tga", &tile_ptr);

	background_surface = NULL;
	tile_surface = NULL;

	if (tile_sz > 0) {
		tile_surface = tga_decode(tile_ptr, tile_sz,
									GFX_FORMAT_RGB_x888);
		struct display_info disp_info;
		if (!display_surface) {
			display_get_info(&disp_info);
			display_surface = gfx_create_surface_from_display(&disp_info);
		}
		background_surface = gfx_create_surface(NULL,
								display_surface->width,
								display_surface->height,
								display_surface->stride,
								display_surface->format);
		for (i = 0; i < display_surface->width; i += tile_surface->width) {
			for (j = 0; j < display_surface->height;
							j += tile_surface->height) {
				gfx_surface_blend(background_surface,
									tile_surface,
									i, j);
			}
		}
	}


	num_menu_entries = 0;

	i = 0;
	counted_images = 0;
	while ((rc = fs_dirent("/boot", i, &ptr)) > 0) {
		sprintf(path, "/boot/%s", ptr);
		if (strncmp("uImage.", ptr, 7) == 0) {
			if (strncmp("uImage.moboot", ptr, 13) != 0) {
				newtitle = malloc(strlen(ptr) - 7 + 5 + 1);
				sprintf(newtitle, "boot %s", ptr + 7);
				newpath = malloc(strlen(ptr) + 6 + 1);
				sprintf(newpath, "/boot/%s", ptr);
				newname = malloc(strlen(ptr) - 7 + 1);
				sprintf(newname, "%s", ptr + 7);
				if (strcmp(default_image, ptr + 7) == 0) {
					default_menu_entry = num_menu_entries;
				}
				if (strcmp(next_image, ptr + 7) == 0) {
					next_menu_entry = num_menu_entries;
					use_next = 1;
				}
				set_menu_entry(newtitle, BOOT_FS, newpath, newname);
				counted_images++;
			}
		}
		free(ptr);
		i++;
	}
	if (rc < 0) {
		dprintf(SPEW, "/boot dirList ERROR rc = %d\n", rc);
	}
	i = 0;
	while ((rc = fs_dirent("/ramdisk/boot", i, &ptr)) > 0) {
		sprintf(path, "/ramdisk/boot/%s", ptr);
		if (strncmp("uImage.", ptr, 7) == 0) {
			if (strncmp("uImage.moboot", ptr, 13) != 0) {
				newtitle = malloc(strlen(ptr) - 7 + 5 + 1);
				sprintf(newtitle, "boot %s", ptr + 7);
				newpath = malloc(strlen(ptr) + 14 + 1);
				sprintf(newpath, "/ramdisk/boot/%s", ptr);
				newname = malloc(strlen(ptr) - 7 + 1);
				sprintf(newname, "%s", ptr + 7);
				if (strcmp(default_image, ptr + 7) == 0) {
					default_menu_entry = num_menu_entries;
				}
				if (strcmp(next_image, ptr + 7) == 0) {
					next_menu_entry = num_menu_entries;
					use_next = 1;
				}
				set_menu_entry(newtitle, BOOT_FS, newpath, newname);
				counted_images++;
			}
		}
		free(ptr);
		i++;
	}
	if (rc < 0) {
		dprintf(SPEW, "/ramdisk/boot dirList ERROR rc = %d\n", rc);
	}
	
	if (counted_images == 0) {
		set_menu_entry("boot", BOOT_FS, "/boot/uImage-2.6.35-palm-tenderloin", "default");
	}


	if (gpiokeys_poll(KEY_ALL)) {
		keys_pressed = 1;
		printf("\nPlease release key(s)...");
		while (1) {
			thread_sleep(20);
			if (!gpiokeys_poll(KEY_ALL)) {
				break;
			}
		}
	}

	gfx_trans = 0;
	if (tile_surface) {
		gfx_trans = 1;
	}


	set_menu_entry("boot webOS Recovery", BOOT_RECOVER, "", "recover");
	set_menu_entry("reboot", BOOT_REBOOT, "", "reboot");
	// set_menu_entry("DFU", BOOT_DFU, "", "");
	set_menu_entry("shutdown", BOOT_SHUTDOWN, "", "shutdown");

	xoff = (gfxconsole_getwidth() - 16 ) / 2;
	if (num_menu_entries < 10) {
		yoff = (gfxconsole_getheight() - 12) / 2;
	} else {
		yoff = (gfxconsole_getheight() - (num_menu_entries + 4)) / 2;
	}

#if 0
	tgasz = fs_load_file_mem("/boot/moboot.tga", &tgaptr);

	tga_surface = NULL;

	if (tgasz > 0) {
		tga_surface = tga_decode(tgaptr, tgasz, GFX_FORMAT_RGB_x888);
		struct display_info disp_info;
		if (!display_surface) {
			display_get_info(&disp_info);
			display_surface = gfx_create_surface_from_display(&disp_info);
		}
	}
#endif

	while (1) {
		gfxconsole_clear();

		show_background();

		if (background_surface) {
			gfxconsole_setbackground(background_surface);
		}

		gfxconsole_settrans(gfx_trans);

		gfxconsole_setpos(xoff,yoff);
		if (gfx_trans) {
			gfxconsole_set_colors(0xffffffff, 0x00000000);
			printf("moboot %s", MOBOOT_VERSION);
			gfxconsole_setpos(xoff,yoff);
			gfxconsole_set_colors(0x00000000, 0x00000000);
		} else {
			gfxconsole_set_colors(0x00000000, 0xffffffff);
			printf("moboot %s", MOBOOT_VERSION);
			gfxconsole_set_colors(0x00000000, 0x000000ff);
		}

		if (!use_next || keys_pressed) {
			act = moboot_menu(xoff, yoff + 2, entries, default_menu_entry, num_menu_entries, keys_pressed ? 0 : default_timeout);
		} else {
			act = next_menu_entry;
			use_next = 0;
		}

		keys_pressed = 1;

		gfxconsole_setpos(xoff, yoff + 2 + num_menu_entries + 2);

		boot_flags = BOOTLINUX_NOFLAGS;

		switch (entries[act]->type) {
			case BOOT_RECOVER:
				reboot_device(RESTART_REASON_RECOVER);
				break;
			case BOOT_REBOOT:
				reboot_device(RESTART_REASON_REBOOT);
				break;
			case BOOT_DFU:
				reboot_device(RESTART_REASON_DFU);
				break;
			case BOOT_SHUTDOWN:
				reboot_device(RESTART_REASON_SHUTDOWN);
				break;
			case BOOT_FS:
				gfxconsole_clear();
				gfxconsole_settrans(gfx_trans);
				show_background();
				gfxconsole_setpos(0,0);

				if (gfx_trans) {
					gfxconsole_set_colors(0x00000000, 0x00000000);
				} else {
					gfxconsole_set_colors(0x00000000, 0x000000ff);
				}

				printf("Selected: '%s'\n\n", entries[act]->title);
				printf("Loading '%s'... ", entries[act]->arg);
				if ((rv = fs_load_file(entries[act]->arg,
							(void *)SCRATCH_ADDR, 
							SCRATCH_SIZE * 1024 * 1024)) < 0) {
					printf("FAILED\n");
				} else {
					printf("OK\n");

					/* check for verbose boot */
					sprintf(splash_path, "/boot/moboot.verbose.%s", 
								entries[act]->name);

					splash_sz = fs_load_file_mem(splash_path, &splash_ptr);

					if (splash_sz > 0) {
						if (strncmp(splash_ptr, "yes", 3) == 0) {
							boot_flags |= BOOTLINUX_VERBOSE;
						}
					}

					/* check for sercon boot */
					sprintf(splash_path, "/boot/moboot.sercon.%s", 
								entries[act]->name);

					splash_sz = fs_load_file_mem(splash_path, &splash_ptr);

					if (splash_sz > 0) {
						if (strncmp(splash_ptr, "yes", 3) == 0) {
							boot_flags |= BOOTLINUX_SERCON;
						}
					}

					if (splash_ptr) free(splash_ptr);

					/* check for splash image */
					sprintf(splash_path, "/boot/moboot.splash.%s.tga", 
								entries[act]->name);

					splash_sz = fs_load_file_mem(splash_path, &splash_ptr);

					splash_surface = NULL;

					if (splash_sz > 0) {
						splash_surface = tga_decode(splash_ptr, splash_sz,
													GFX_FORMAT_RGB_x888);
						struct display_info disp_info;
						if (!display_surface) {
							display_get_info(&disp_info);
							display_surface = gfx_create_surface_from_display(
													&disp_info);
						}
					}

					/* do it to it! */
					bootlinux_uimage_mem((void *)SCRATCH_ADDR, rv, boot_splash,
							boot_flags);
				}

				gfxconsole_set_colors(0x00000000, 0x00ff0000);
				printf("\n\nBOOT FAILED!\n\nPress SELECT to continue\n");
				gfxconsole_set_colors(0x00000000, 0x000000ff);
				gpiokeys_wait_select();
				break;
		}
	}
}