futility/updater_archive.c
/*
 * Creates a new manifest object by scanning files in archive.
 * Returns the manifest on success, otherwise NULL for failure.
 */
Creates a new manifest object by scanning files in archive.
Returns the manifest on success, otherwise NULL for failure.
Creates a new manifest object by scanning files in archive . Returns the manifest on success otherwise NULL for failure .
struct manifest *new_manifest_from_archive(struct archive *archive)
{
	struct manifest manifest = {0}, *new_manifest;
	struct model_config model = {0};
	const char * const host_image_name = "image.bin",
		   * const old_host_image_name = "bios.bin",
	           * const ec_name = "ec.bin",
		   * const pd_name = "pd.bin";
	manifest.archive = archive;
	manifest.default_model = -1;
	archive_walk(archive, &manifest, manifest_scan_entries);
	if (manifest.num == 0) {
		const char *image_name = NULL;
		struct firmware_image image = {0};
		if (archive_has_entry(archive, old_host_image_name))
			image_name = old_host_image_name;
		else if (archive_has_entry(archive, host_image_name))
			image_name = host_image_name;
		else
			return 0;
		model.image = strdup(image_name);
		if (archive_has_entry(archive, ec_name))
			model.ec_image = strdup(ec_name);
		if (archive_has_entry(archive, pd_name))
			model.pd_image = strdup(pd_name);
		if (!load_firmware_image(&image, image_name, archive)) {
			char *token = NULL;
			if (strtok(image.ro_version, "_"))
				token = strtok(NULL, ".");
			if (token && *token) {
				str_convert(token, tolower);
				model.name = strdup(token);
			}
			free_firmware_image(&image);
		}
		if (!model.name)
			model.name = strdup(DEFAULT_MODEL_NAME);
		if (manifest.has_keyset)
			model.is_white_label = 1;
		manifest_add_model(&manifest, &model);
		manifest.default_model = manifest.num - 1;
	}
	VB2_DEBUG("%d model(s) loaded.\n", manifest.num);
	if (!manifest.num) {
		ERROR("No valid configurations found from archive.\n");
		return NULL;
	}
	new_manifest = (struct manifest *)malloc(sizeof(manifest));
	if (!new_manifest) {
		ERROR("Internal error: memory allocation error.\n");
		return NULL;
	}
	memcpy(new_manifest, &manifest, sizeof(manifest));
	return new_manifest;
}
struct manifest * new_manifest_from_archive ( struct archive * archive ) { struct manifest manifest = { 0 } , * new_manifest ; struct model_config model = { 0 } ; const char * const host_image_name = " " , * const old_host_image_name = " " , * const ec_name = " " , * const pd_name = " " ; manifest . archive = archive ; manifest . default_model = -1 ; archive_walk ( archive , & manifest , manifest_scan_entries ) ; if ( manifest . num == 0 ) { const char * image_name = NULL ; struct firmware_image image = { 0 } ; if ( archive_has_entry ( archive , old_host_image_name ) ) image_name = old_host_image_name ; else if ( archive_has_entry ( archive , host_image_name ) ) image_name = host_image_name ; else return 0 ; model . image = strdup ( image_name ) ; if ( archive_has_entry ( archive , ec_name ) ) model . ec_image = strdup ( ec_name ) ; if ( archive_has_entry ( archive , pd_name ) ) model . pd_image = strdup ( pd_name ) ; if ( ! load_firmware_image ( & image , image_name , archive ) ) { char * token = NULL ; if ( strtok ( image . ro_version , " " ) ) token = strtok ( NULL , " " ) ; if ( token && * token ) { str_convert ( token , tolower ) ; model . name = strdup ( token ) ; } free_firmware_image ( & image ) ; } if ( ! model . name ) model . name = strdup ( DEFAULT_MODEL_NAME ) ; if ( manifest . has_keyset ) model . is_white_label = 1 ; manifest_add_model ( & manifest , & model ) ; manifest . default_model = manifest . num - 1 ; } VB2_DEBUG ( " \n " , manifest . num ) ; if ( ! manifest . num ) { ERROR ( " \n " ) ; return NULL ; } new_manifest = ( struct manifest * ) malloc ( sizeof ( manifest ) ) ; if ( ! new_manifest ) { ERROR ( " \n " ) ; return NULL ; } memcpy ( new_manifest , & manifest , sizeof ( manifest ) ) ; return new_manifest ; }
Creates a new manifest object by scanning files in archive.
Creates a new manifest object by scanning files in archive .
/* Try to load from current folder. */ /* Extract model name from FWID: $Vendor_$Platform.$Version */