/// Constructs up-to four FVM files. Calling this function generates
/// a default FVM, a sparse FVM, a sparse blob-only FVM, and optionally a FVM
/// ready for fastboot flashing. This function returns the paths to each
/// generated FVM.
///
/// If the |fvm_config| includes information for an EMMC, then an EMMC-supported
/// sparse FVM will also be generated for fastboot flashing.
///
/// If the |fvm_config| includes information for a NAND, then an NAND-supported
/// sparse FVM will also be generated for fastboot flashing.
Constructs up-to four FVM files. Calling this function generates
a default FVM, a sparse FVM, a sparse blob-only FVM, and optionally a FVM
ready for fastboot flashing. This function returns the paths to each
generated FVM.

If the |fvm_config| includes information for an EMMC, then an EMMC-supported
sparse FVM will also be generated for fastboot flashing.

If the |fvm_config| includes information for a NAND, then an NAND-supported
sparse FVM will also be generated for fastboot flashing.
Constructs up - to four FVM files . Calling this function generates a default FVM a sparse FVM a sparse blob - only FVM and optionally a FVM ready for fastboot flashing . This function returns the paths to each generated FVM . If the |fvm_config| includes information for an EMMC then an EMMC - supported sparse FVM will also be generated for fastboot flashing . If the |fvm_config| includes information for a NAND then an NAND - supported sparse FVM will also be generated for fastboot flashing .
pub fn construct_fvm(
    fvm_tool: impl AsRef<Path>,
    minfs_tool: impl AsRef<Path>,
    outdir: impl AsRef<Path>,
    fvm_config: &FvmConfig,
    blobfs_path: Option<impl AsRef<Path>>,
) -> Result<Fvms> {
    // Gather details for each partition.
    let mut filesystems: Vec<Filesystem> = Vec::new();
    for entry in &fvm_config.filesystems {
        match entry {
            FvmFilesystemEntry::BlobFS { attributes } => {
                let path = match &blobfs_path {
                    Some(path) => path.as_ref(),
                    None => {
                        anyhow::bail!("BlobFS configuration exists, but BlobFS was not generated");
                    }
                };
                filesystems
                    .push(Filesystem { path: path.to_path_buf(), attributes: attributes.clone() });
            }
            FvmFilesystemEntry::MinFS { attributes } => {
                let minfs_path = outdir.as_ref().join("data.blk");
                let builder = MinFSBuilder::new(&minfs_tool);
                builder.build(&minfs_path)?;
                filesystems.push(Filesystem {
                    path: minfs_path.to_path_buf(),
                    attributes: attributes.clone(),
                });
            }
        };
    }
    // Build a default FVM that is non-sparse.
    let default_path = outdir.as_ref().join("fvm.blk");
    let mut fvm_builder = FvmBuilder::new(
        &fvm_tool,
        &default_path,
        fvm_config.slice_size,
        fvm_config.reserved_slices,
        None,
        FvmType::Default,
    );
    for fs in &filesystems {
        fvm_builder.filesystem(fs.clone());
    }
    fvm_builder.build()?;
    // Build a sparse FVM for paving.
    let sparse_path = outdir.as_ref().join("fvm.sparse.blk");
    let mut sparse_fvm_builder = FvmBuilder::new(
        &fvm_tool,
        &sparse_path,
        fvm_config.slice_size,
        fvm_config.reserved_slices,
        fvm_config.max_disk_size,
        FvmType::Sparse { empty_minfs: false },
    );
    for fs in &filesystems {
        sparse_fvm_builder.filesystem(fs.clone());
    }
    sparse_fvm_builder.build()?;
    // Build a sparse FVM with an empty minfs.
    let sparse_blob_path = outdir.as_ref().join("fvm.blob.sparse.blk");
    let mut sparse_blob_fvm_builder = FvmBuilder::new(
        &fvm_tool,
        &sparse_blob_path,
        fvm_config.slice_size,
        fvm_config.reserved_slices,
        fvm_config.max_disk_size,
        FvmType::Sparse { empty_minfs: true },
    );
    // In this case we have set the "empty_minfs" flag above which causes FVM to create an empty
    // minfs partition named "data". We must strip that partition out of the filesystems we pass
    // through such that FVM does not attempt to create two partitions with the same name.
    //
    // TODO(fxbug.dev/85165): Generate an empty image instead of a standard minfs image for this
    // case. This empty image could be passed through directly as a filesystem and the special
    // "with-empty-minfs" could be removed.
    for fs in &filesystems {
        if fs.attributes.name != "data" {
            sparse_blob_fvm_builder.filesystem(fs.clone());
        }
    }
    sparse_blob_fvm_builder.build()?;
    // Build a sparse fastboot-supported FVM if needed.
    let fastboot_path: Option<PathBuf> = match &fvm_config.fastboot {
        // EMMC formatted FVM.
        Some(FastbootConfig::Emmc { compression, length }) => {
            let emmc_path = outdir.as_ref().join("fvm.fastboot.blk");
            let mut emmc_fvm_builder = FvmBuilder::new(
                &fvm_tool,
                &emmc_path,
                fvm_config.slice_size,
                fvm_config.reserved_slices,
                fvm_config.max_disk_size,
                FvmType::Emmc { compression: compression.clone(), length: *length },
            );
            for fs in &filesystems {
                emmc_fvm_builder.filesystem(fs.clone());
            }
            emmc_fvm_builder.build()?;
            Some(emmc_path)
        }
        // NAND formatted FVM.
        Some(FastbootConfig::Nand {
            compression,
            page_size,
            oob_size,
            pages_per_block,
            block_count,
        }) => {
            let nand_path = outdir.as_ref().join("fvm.fastboot.blk");
            let nand_fvm_builder = NandFvmBuilder {
                tool: fvm_tool.as_ref().to_path_buf(),
                output: nand_path.clone(),
                sparse_blob_fvm: sparse_blob_path.clone(),
                max_disk_size: fvm_config.max_disk_size,
                compression: compression.clone(),
                page_size: *page_size,
                oob_size: *oob_size,
                pages_per_block: *pages_per_block,
                block_count: *block_count,
            };
            nand_fvm_builder.build()?;
            Some(nand_path)
        }
        None => None,
    };
    Ok(Fvms {
        default: default_path,
        sparse: sparse_path,
        sparse_blob: sparse_blob_path,
        fastboot: fastboot_path,
    })
}
pub fn construct_fvm ( fvm_tool : impl AsRef < Path > , minfs_tool : impl AsRef < Path > , outdir : impl AsRef < Path > , fvm_config : & FvmConfig , blobfs_path : Option < impl AsRef < Path > > , ) -> Result < Fvms > { // Gather details for each partition. let mut filesystems : Vec < Filesystem > = Vec :: new ( ) ; for entry in & fvm_config . filesystems { match entry { FvmFilesystemEntry :: BlobFS { attributes } => { let path = match & blobfs_path { Some ( path ) => path . as_ref ( ) , None => { anyhow :: bail ! ( " " ) ; } } ; filesystems . push ( Filesystem { path : path . to_path_buf ( ) , attributes : attributes . clone ( ) } ) ; } FvmFilesystemEntry :: MinFS { attributes } => { let minfs_path = outdir . as_ref ( ) . join ( " " ) ; let builder = MinFSBuilder :: new ( & minfs_tool ) ; builder . build ( & minfs_path ) ? ; filesystems . push ( Filesystem { path : minfs_path . to_path_buf ( ) , attributes : attributes . clone ( ) , } ) ; } } ; } // Build a default FVM that is non-sparse. let default_path = outdir . as_ref ( ) . join ( " " ) ; let mut fvm_builder = FvmBuilder :: new ( & fvm_tool , & default_path , fvm_config . slice_size , fvm_config . reserved_slices , None , FvmType :: Default , ) ; for fs in & filesystems { fvm_builder . filesystem ( fs . clone ( ) ) ; } fvm_builder . build ( ) ? ; // Build a sparse FVM for paving. let sparse_path = outdir . as_ref ( ) . join ( " " ) ; let mut sparse_fvm_builder = FvmBuilder :: new ( & fvm_tool , & sparse_path , fvm_config . slice_size , fvm_config . reserved_slices , fvm_config . max_disk_size , FvmType :: Sparse { empty_minfs : false } , ) ; for fs in & filesystems { sparse_fvm_builder . filesystem ( fs . clone ( ) ) ; } sparse_fvm_builder . build ( ) ? ; // Build a sparse FVM with an empty minfs. let sparse_blob_path = outdir . as_ref ( ) . join ( " " ) ; let mut sparse_blob_fvm_builder = FvmBuilder :: new ( & fvm_tool , & sparse_blob_path , fvm_config . slice_size , fvm_config . reserved_slices , fvm_config . max_disk_size , FvmType :: Sparse { empty_minfs : true } , ) ; // In this case we have set the "empty_minfs" flag above which causes FVM to create an empty // minfs partition named "data". We must strip that partition out of the filesystems we pass // through such that FVM does not attempt to create two partitions with the same name. // // TODO(fxbug.dev/85165): Generate an empty image instead of a standard minfs image for this // case. This empty image could be passed through directly as a filesystem and the special // "with-empty-minfs" could be removed. for fs in & filesystems { if fs . attributes . name != " " { sparse_blob_fvm_builder . filesystem ( fs . clone ( ) ) ; } } sparse_blob_fvm_builder . build ( ) ? ; // Build a sparse fastboot-supported FVM if needed. let fastboot_path : Option < PathBuf > = match & fvm_config . fastboot { // EMMC formatted FVM. Some ( FastbootConfig :: Emmc { compression , length } ) => { let emmc_path = outdir . as_ref ( ) . join ( " " ) ; let mut emmc_fvm_builder = FvmBuilder :: new ( & fvm_tool , & emmc_path , fvm_config . slice_size , fvm_config . reserved_slices , fvm_config . max_disk_size , FvmType :: Emmc { compression : compression . clone ( ) , length : * length } , ) ; for fs in & filesystems { emmc_fvm_builder . filesystem ( fs . clone ( ) ) ; } emmc_fvm_builder . build ( ) ? ; Some ( emmc_path ) } // NAND formatted FVM. Some ( FastbootConfig :: Nand { compression , page_size , oob_size , pages_per_block , block_count , } ) => { let nand_path = outdir . as_ref ( ) . join ( " " ) ; let nand_fvm_builder = NandFvmBuilder { tool : fvm_tool . as_ref ( ) . to_path_buf ( ) , output : nand_path . clone ( ) , sparse_blob_fvm : sparse_blob_path . clone ( ) , max_disk_size : fvm_config . max_disk_size , compression : compression . clone ( ) , page_size : * page_size , oob_size : * oob_size , pages_per_block : * pages_per_block , block_count : * block_count , } ; nand_fvm_builder . build ( ) ? ; Some ( nand_path ) } None => None , } ; Ok ( Fvms { default : default_path , sparse : sparse_path , sparse_blob : sparse_blob_path , fastboot : fastboot_path , } ) }
Constructs up-to four FVM files.
Constructs up - to four FVM files .
fvm_tool
impl AsRef<Path>
minfs_tool
impl AsRef<Path>
outdir
impl AsRef<Path>
fvm_config
&FvmConfig
blobfs_path
Option<impl AsRef<Path>>