Exemple #1
0
/* Check a particular volume to see if there is an automatic OTA
 * package present on it, and if so, return a path which can be
 * fed to the command line of the recovery console.
 *
 * Don't report errors if we can't mount the volume or the
 * auto-ota file doesn't exist. */
static char *detect_sw_update(Volume *vol)
{
	char *filename = NULL;
	struct stat statbuf;
	char *ret = NULL;
	char *mountpoint = NULL;

	if (asprintf(&mountpoint, "/mnt%s", vol->mount_point) < 0) {
		pr_perror("asprintf");
		die();
	}

	if (asprintf(&filename, "%s/" AUTO_UPDATE_FNAME,
				mountpoint) < 0) {
		pr_perror("asprintf");
		die();
	}
	pr_debug("Looking for %s...\n", filename);

	if (mount_partition_device(vol->device, vol->fs_type,
			mountpoint)) {
		if (!vol->device2 || mount_partition_device(vol->device2,
				vol->fs_type, mountpoint))
		{
			pr_debug("Couldn't mount %s.\n", vol->mount_point);
			goto out;
		}
	}

	if (stat(filename, &statbuf)) {
		if (errno == ENOENT)
			pr_debug("Coudln't find %s.\n", filename);
		else
			pr_perror("stat");
	} else {
		ret = strdup(filename + 4); /* Nip off leading '/mnt' */
		if (!ret) {
			pr_perror("strdup");
			die();
		}
		pr_info("OTA Update package found: %s.\n", filename);
	}
out:
	free(filename);
	umount(mountpoint);
	free(mountpoint);
	return ret;
}
void syslinux_execute(void)
{
	char *device, *diskdevice;
	char *bootimages;
	int fd;

	if (strcmp(hashmapGetPrintf(ictx.opts, "none", BASE_BOOTLOADER),
				"syslinux"))
		return;

	pr_info("Writing MBR");
        diskdevice = xasprintf("/dev/block/%s",
			hashmapGetPrintf(ictx.opts, NULL, BASE_INSTALL_DISK));
	dd(SYSLINUX_MBR, diskdevice);
        free(diskdevice);

	/* SYSLINUX complains if this isn't done */
	chmod("/tmp", 01777);

	bootimages = hashmapGetPrintf(ictx.opts, NULL, BASE_BOOT_LIST);
	device = hashmapGetPrintf(ictx.opts, NULL, "partition.bootloader:device");
	pr_info("Installing ldlinux.sys onto %s", device);
	do_install_syslinux(device);

	/* In case we die() before we are finished */
	signal(SIGABRT, sighandler);
	mount_partition_device(device, "vfat", BOOTLOADER_PATH);

	pr_info("Copying syslinux support files");
	copy_file(IMAGES_PATH "vesamenu.c32", BOOTLOADER_PATH "vesamenu.c32");
	copy_file(IMAGES_PATH "android.c32", BOOTLOADER_PATH "android.c32");

	pr_info("Constructing syslinux.cfg");
	/* Put the initial template stuff in */
	copy_file(SYSLINUX_CFG_TEM_FN, SYSLINUX_CFG_FN);
	fd = xopen(SYSLINUX_CFG_FN, O_WRONLY | O_APPEND);
	put_string(fd, "menu androidcommand %s\n",
		hashmapGetPrintf(ictx.opts, NULL, "partition.misc:index"));
	string_list_iterate(bootimages, bootimage_cb, &fd);

	xclose(fd);
	umount(BOOTLOADER_PATH);
	rmdir(BOOTLOADER_PATH);
	signal(SIGABRT, SIG_DFL);
	pr_info("SYSLINUX installation complete");
}