Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ cf_cc_library(
"//cuttlefish/host/commands/assemble_cvd/disk:image_file",
"//cuttlefish/host/commands/assemble_cvd/flags:boot_image",
"//cuttlefish/host/libs/config:cuttlefish_config",
"//cuttlefish/host/libs/image_aggregator:sparse_image",
"//cuttlefish/posix:rename",
"//cuttlefish/posix:strerror",
"//cuttlefish/result:expect",
"//cuttlefish/result:result_type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "cuttlefish/host/commands/assemble_cvd/flags/boot_image.h"
#include "cuttlefish/host/commands/assemble_cvd/vendor_dlkm_utils.h"
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
#include "cuttlefish/host/libs/image_aggregator/sparse_image.h"
#include "cuttlefish/posix/rename.h"
#include "cuttlefish/posix/strerror.h"
#include "cuttlefish/result/expect.h"
#include "cuttlefish/result/result_type.h"
Expand Down Expand Up @@ -83,9 +85,15 @@ Result<void> RepackSuperAndVbmeta(
const auto new_super_img = instance.new_super_image();
// This file may have already been created by super_image_mixer.cc
if (!FileExists(new_super_img)) {
CF_EXPECTF(Copy(instance.super_image(), new_super_img),
"Failed to copy super image '{}' to '{}': '{}'",
instance.super_image(), new_super_img, StrError(errno));
if (CF_EXPECT(IsSparseImage(instance.super_image()))) {
const auto tmp_super_img = new_super_img + ".tmp";
CF_EXPECT(ConvertSparseImageToRaw(instance.super_image(), tmp_super_img));
CF_EXPECT(Rename(tmp_super_img, new_super_img));
} else {
CF_EXPECTF(Copy(instance.super_image(), new_super_img),
"Failed to copy super image '{}' to '{}': '{}'",
instance.super_image(), new_super_img, StrError(errno));
}
}

CF_EXPECT(RepackSuperWithPartition(new_super_img, new_vendor_dlkm_img,
Expand Down
19 changes: 12 additions & 7 deletions base/cvd/cuttlefish/host/libs/image_aggregator/sparse_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ Result<bool> IsSparseImage(const std::string& image_path) {
return buffer == kAndroidSparseImageMagic;
}

Result<void> ConvertSparseImageToRaw(const std::string& source_path,
const std::string& destination_path) {
CF_EXPECT(IsSparseImage(source_path),
"Source image is not an Android sparse image");
int status = Execute({Simg2ImgBinary(), source_path, destination_path});
CF_EXPECT_EQ(status, 0, "Unable to convert Android sparse image '"
<< source_path << "' to raw image '"
<< destination_path << "': " << status);
return {};
}

Result<void> ForceRawImage(const std::string& image_path) {
if (!CF_EXPECT(IsSparseImage(image_path))) {
return {};
Expand All @@ -78,13 +89,7 @@ Result<void> ForceRawImage(const std::string& image_path) {
}

std::string tmp_raw_image_path = image_path + ".raw";
// Use simg2img to convert sparse image to raw images.
int simg2img_status =
Execute({Simg2ImgBinary(), image_path, tmp_raw_image_path});

CF_EXPECT_EQ(simg2img_status, 0,
"Unable to convert Android sparse image '"
<< image_path << "' to raw image: " << simg2img_status);
CF_EXPECT(ConvertSparseImageToRaw(image_path, tmp_raw_image_path));

// Replace the original sparse image with the raw image.
// `rename` can fail if these are on different mounts, but they are files
Expand Down
2 changes: 2 additions & 0 deletions base/cvd/cuttlefish/host/libs/image_aggregator/sparse_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace cuttlefish {

Result<void> ForceRawImage(const std::string& image_path);
Result<bool> IsSparseImage(const std::string& image_path);
Result<void> ConvertSparseImageToRaw(const std::string& source_path,
const std::string& destination_path);

/** Image file format comprised of a list of chunks of "raw data" and "fill
* data" that is a repeated byte string. */
Expand Down
Loading