Example #1
0
static int install_from_file(char *fname, int check)
{
	int fdsw;
	off_t pos;
	int ret;


	if (!strlen(fname)) {
		ERROR("Image not found...please reboot");
		exit(EXIT_FAILURE);
	}

	fdsw = open(fname, O_RDONLY);
	if (fdsw < 0) {
		fdsw = searching_for_image(fname);
		if (fdsw < 0) {
			ERROR("Image Software cannot be read...exiting !");
			exit(EXIT_FAILURE);
		}
	}

	pos = 0;
	ret = extract_sw_description(fdsw, SW_DESCRIPTION_FILENAME, &pos);
#ifdef CONFIG_SIGNED_IMAGES
	ret |= extract_sw_description(fdsw, SW_DESCRIPTION_FILENAME ".sig",
		&pos);
#endif
	/*
	 * Check if files could be extracted
	 */
	if (ret) {
		ERROR("Failed to extract meta information");
		exit(EXIT_FAILURE);
	}

	char* swdescfilename = alloca(strlen(get_tmpdir())+strlen(SW_DESCRIPTION_FILENAME)+1);
	sprintf(swdescfilename, "%s%s", get_tmpdir(), SW_DESCRIPTION_FILENAME);
	ret = parse(&swcfg, swdescfilename);
	if (ret) {
		ERROR("failed to parse " SW_DESCRIPTION_FILENAME "!");
		exit(EXIT_FAILURE);
	}

	if (check_hw_compatibility(&swcfg)) {
		ERROR("SW not compatible with hardware");
		exit(EXIT_FAILURE);
	}

	if (cpio_scan(fdsw, &swcfg, pos) < 0) {
		ERROR("failed to scan for pos '%ld'!", pos);
		close(fdsw);
		exit(EXIT_FAILURE);
	}

	/*
	 * Check if all files described in sw-description
	 * are in the image
	 */
	ret = check_provided(&swcfg.images);
	if (ret) {
		ERROR("failed to check images!");
		exit(EXIT_FAILURE);
	}
	ret = check_provided(&swcfg.scripts);
	if (ret) {
		ERROR("failed to check scripts!");
		exit(EXIT_FAILURE);
	}

	if (check) {
		fprintf(stdout, "successfully checked '%s'\n", fname);
		exit(EXIT_SUCCESS);
	}

#ifdef CONFIG_MTD
		mtd_cleanup();
		scan_mtd_devices();
#endif
	/*
	 * Set "recovery_status" as begin of the transaction"
	 */
	if (swcfg.bootloader_transaction_marker) {
		bootloader_env_set(BOOTVAR_TRANSACTION, "in_progress");
	}

	ret = install_images(&swcfg, fdsw, 1);

	swupdate_progress_end(ret == 0 ? SUCCESS : FAILURE);

	close(fdsw);

	if (ret) {
		fprintf(stdout, "Software updated failed\n");
		return EXIT_FAILURE;
	}

	if (swcfg.bootloader_transaction_marker) {
		bootloader_env_unset(BOOTVAR_TRANSACTION);
	}
	fprintf(stdout, "Software updated successfully\n");
	fprintf(stdout, "Please reboot the device to start the new software\n");

	return EXIT_SUCCESS;
}
Example #2
0
static int install_from_file(char *fname)
{
	int fdsw;
	off_t pos;
	int ret;


	if (!strlen(fname)) {
		ERROR("Image not found...please reboot\n");
		exit(1);
	}

	fdsw = open(fname, O_RDONLY);
	if (fdsw < 0) {
		fdsw = searching_for_image(fname);
		if (fdsw < 0) {
			ERROR("Image Software cannot be read...exiting !\n");
			exit(1);
		}
	}

	pos = extract_sw_description(fdsw);
	ret = parse(&swcfg, TMPDIR SW_DESCRIPTION_FILENAME);
	if (ret) {
		exit(1);
	}


	if (check_hw_compatibility(&swcfg)) {
		ERROR("SW not compatible with hardware\n");
		exit(1);
	}

	if (cpio_scan(fdsw, &swcfg, pos) < 0) {
		close(fdsw);
		exit(1);
	}

	/*
	 * Check if all files described in sw-description
	 * are in the image
	 */
	ret = check_provided(&swcfg.images);
	ret |= check_provided(&swcfg.scripts);
	if (ret)
		exit(1);

#ifdef CONFIG_MTD
		mtd_cleanup();
		scan_mtd_devices();
#endif
	/* copy images */
	ret = install_images(&swcfg, fdsw, 1);

	close(fdsw);

	if (ret) {
		fprintf(stdout, "Software updated failed\n");
		exit(1);
	}

	fprintf(stdout, "Software updated successfully\n");
	fprintf(stdout, "Please reboot the device to start the new software\n");

	return 0;
}