예제 #1
0
파일: gui.c 프로젝트: artemav/kexecboot
struct gui_t *gui_init(int angle)
{
	struct gui_t *gui;
	FB *fb;

	gui = malloc(sizeof(*gui));
	if (NULL == gui) {
		DPRINTF("Can't allocate memory for GUI structure");
		return NULL;
	}

	/* init framebuffer */
	fb = fb_new(angle);

	if (NULL == fb) {
		log_msg(lg, "Can't initialize framebuffer");
		free(gui);
		return NULL;
	}

	gui->fb = fb;

	/* Tune GUI size */
#ifdef USE_FBUI_WIDTH
	if (fb->width > USE_FBUI_WIDTH)
		gui->width = USE_FBUI_WIDTH;
	else
#endif
		gui->width = fb->width;

#ifdef USE_FBUI_HEIGHT
	if (fb->height > USE_FBUI_HEIGHT)
		gui->height = USE_FBUI_HEIGHT;
	else
#endif
		gui->height = fb->height;

	gui->x = (fb->width - gui->width)/2;
	gui->y = (fb->height - gui->height)/2;

#ifdef USE_ICONS
	/* Parse compiled images.
	 * We don't care about result because drawing code is aware
	 */
	int bpp;
	bpp = fb->bpp;

	gui->icons = malloc(sizeof(*(gui->icons)) * ICON_ARRAY_SIZE);

	gui->icons[ICON_LOGO] = xpm_parse_image(logo_xpm, ROWS(logo_xpm), bpp);
	gui->icons[ICON_STORAGE] = xpm_parse_image(storage_xpm, ROWS(storage_xpm), bpp);
	gui->icons[ICON_MMC] = xpm_parse_image(mmc_xpm, ROWS(mmc_xpm), bpp);
	gui->icons[ICON_MEMORY] = xpm_parse_image(memory_xpm, ROWS(memory_xpm), bpp);
	gui->icons[ICON_SYSTEM] = xpm_parse_image(system_xpm, ROWS(system_xpm), bpp);
	gui->icons[ICON_BACK] = xpm_parse_image(back_xpm, ROWS(back_xpm), bpp);
	gui->icons[ICON_RESCAN] = xpm_parse_image(rescan_xpm, ROWS(rescan_xpm), bpp);
	gui->icons[ICON_DEBUG] = xpm_parse_image(debug_xpm, ROWS(debug_xpm), bpp);
	gui->icons[ICON_REBOOT] = xpm_parse_image(reboot_xpm, ROWS(reboot_xpm), bpp);
	gui->icons[ICON_SHUTDOWN] = xpm_parse_image(shutdown_xpm, ROWS(shutdown_xpm), bpp);
	gui->icons[ICON_EXIT] = xpm_parse_image(exit_xpm, ROWS(exit_xpm), bpp);
#endif

#ifdef USE_BG_BUFFER
	/* Pre-draw background and store it in special buffer */
	draw_background_low(gui);
	gui->bg_buffer = fb_dump(fb);
#endif

	return gui;
}
예제 #2
0
int scan_devices(struct params_t *params)
{
	struct charlist *fl;
	struct bootconf_t *bootconf;
	struct device_t dev;
	struct cfgdata_t cfgdata;
	int rc,n;
	FILE *f;

	char mount_dev[16];
	char mount_fstype[16];
	char str_mtd_id[3];

#ifdef USE_ICONS
	kx_cfg_section *sc;
	int i;
	int rows;
	char **xpm_data;

#endif

	bootconf = create_bootcfg(4);
	if (NULL == bootconf) {
		DPRINTF("Can't allocate bootconf structure");
		return -1;
	}

	f = devscan_open(&fl);
	if (NULL == f) {
		log_msg(lg, "Can't initiate device scan");
		return -1;
	}

#ifdef USE_ZAURUS
	struct zaurus_partinfo_t pinfo;
	int zaurus_error = 0;
	zaurus_error = zaurus_read_partinfo(&pinfo);
	if (0 == zaurus_error) {
		/* Fix mtdparts tag */
		dispose(params->cfg->mtdparts);
		params->cfg->mtdparts = zaurus_mtdparts(&pinfo);
	}
#endif

	for (;;) {
		rc = devscan_next(f, fl, &dev);
		if (rc < 0) continue;	/* Error */
		if (0 == rc) break;		/* EOF */

		/* initialize with defaults */
		strcpy(mount_dev, dev.device);
		strcpy(mount_fstype, dev.fstype);

		/* We found an ubi erase counter */
		if (!strncmp(dev.fstype, "ubi",3)) {

			/* attach ubi boot device - mtd id [0-15] */
			if(isdigit(atoi(dev.device+strlen(dev.device)-2))) {
				strcpy(str_mtd_id, dev.device+strlen(dev.device)-2);
				strcat(str_mtd_id, dev.device+strlen(dev.device)-1);
			} else {
				strcpy(str_mtd_id, dev.device+strlen(dev.device)-1);
			}
			n = ubi_attach(str_mtd_id);

			/* we have attached ubiX and we mount /dev/ubiX_0  */
			sprintf(mount_dev, "/dev/ubi%d", n);
			 /* HARDCODED: first volume */
			strcat(mount_dev, "_0");

			/* HARDCODED: we assume it's ubifs */
			strcpy(mount_fstype, "ubifs");
		}

		/* Mount device */
		if (-1 == mount(mount_dev, MOUNTPOINT, mount_fstype, MS_RDONLY, NULL)) {
			log_msg(lg, "+ can't mount device %s: %s", mount_dev, ERRMSG);
			goto free_device;
		}

		/* NOTE: Don't go out before umount'ing */

		/* Search boot method and return boot info */
		rc = get_bootinfo(&cfgdata);

		if (-1 == rc) {	/* Error */
			goto umount;
		}

#ifdef USE_ICONS
		/* Iterate over sections found */
		if (params->gui) {
			for (i = 0; i < cfgdata.count; i++) {
				sc = cfgdata.list[i];
				if (!sc) continue;

				/* Load custom icon */
				if (sc->iconpath) {
					rows = xpm_load_image(&xpm_data, sc->iconpath);
					if (-1 == rows) {
						log_msg(lg, "+ can't load xpm icon %s", sc->iconpath);
						continue;
					}

					sc->icondata = xpm_parse_image(xpm_data, rows);
					if (!sc->icondata) {
						log_msg(lg, "+ can't parse xpm icon %s", sc->iconpath);
						continue;
					}
					xpm_destroy_image(xpm_data, rows);
				}
			}
		}
#endif

umount:
		/* Umount device */
		if (-1 == umount(MOUNTPOINT)) {
			log_msg(lg, "+ can't umount device: %s", ERRMSG);
			goto free_cfgdata;
		}

		if (-1 == rc) {	/* Error */
			goto free_cfgdata;
		}

#ifdef USE_ZAURUS
		/* Fix partition sizes. We can have kernel in root and home partitions on NAND */
		/* HACK: mtdblock devices are hardcoded */
		if (0 == zaurus_error) {
			if (0 == strcmp(dev.device, "/dev/mtdblock2")) {	/* root */
				log_msg(lg, "+ [zaurus root] size of %s will be changed from %llu to %lu",
						dev.device, dev.blocks, pinfo.root);
				dev.blocks = pinfo.root;
			} else if (0 == strcmp(dev.device, "/dev/mtdblock3")) {	/* home */
				log_msg(lg, "+ [zaurus home] size of %s will be changed from %llu to %lu",
						dev.device, dev.blocks, pinfo.home);
				dev.blocks = pinfo.home;
			}
		}
#endif

		/* Now we have something in cfgdata */
		rc = addto_bootcfg(bootconf, &dev, &cfgdata);

free_cfgdata:
		destroy_cfgdata(&cfgdata);
free_device:
		free(dev.device);
	}

	free_charlist(fl);
	params->bootcfg = bootconf;
	return 0;
}