diff options
-rw-r--r-- | payload_generator/generate_delta_main.cc | 45 | ||||
-rw-r--r-- | payload_generator/payload_file.cc | 4 | ||||
-rw-r--r-- | payload_generator/payload_file.h | 2 | ||||
-rw-r--r-- | payload_generator/payload_generation_config.h | 3 | ||||
-rwxr-xr-x | scripts/brillo_update_payload | 8 |
5 files changed, 62 insertions, 0 deletions
diff --git a/payload_generator/generate_delta_main.cc b/payload_generator/generate_delta_main.cc index 18cff4b1..dd41a29b 100644 --- a/payload_generator/generate_delta_main.cc +++ b/payload_generator/generate_delta_main.cc @@ -14,6 +14,7 @@ // limitations under the License. // +#include <map> #include <string> #include <vector> @@ -22,6 +23,7 @@ #include <base/logging.h> #include <base/strings/string_number_conversions.h> #include <base/strings/string_split.h> +#include <base/strings/string_util.h> #include <brillo/flag_helper.h> #include <brillo/key_value_store.h> #include <brillo/message_loops/base_message_loop.h> @@ -47,6 +49,7 @@ // and an output file as arguments and the path to an output file and // generates a delta that can be sent to Chrome OS clients. +using std::map; using std::string; using std::vector; @@ -294,6 +297,39 @@ bool ExtractProperties(const string& payload_path, return true; } +template <typename Key, typename Val> +string ToString(const map<Key, Val>& map) { + vector<string> result; + result.reserve(map.size()); + for (const auto& it : map) { + result.emplace_back(it.first + ": " + it.second); + } + return "{" + base::JoinString(result, ",") + "}"; +} + +bool ParsePerPartitionTimestamps(const string& partition_timestamps, + PayloadGenerationConfig* config) { + base::StringPairs pairs; + CHECK(base::SplitStringIntoKeyValuePairs( + partition_timestamps, ':', ',', &pairs)) + << "--partition_timestamps accepts commad " + "separated pairs. e.x. system:1234,vendor:5678"; + map<string, string> partition_timestamps_map{ + std::move_iterator(pairs.begin()), std::move_iterator(pairs.end())}; + for (auto&& partition : config->target.partitions) { + auto&& it = partition_timestamps_map.find(partition.name); + if (it != partition_timestamps_map.end()) { + partition.version = std::move(it->second); + partition_timestamps_map.erase(it); + } + } + if (!partition_timestamps_map.empty()) { + LOG(ERROR) << "Unused timestamps: " << ToString(partition_timestamps_map); + return false; + } + return true; +} + int Main(int argc, char** argv) { DEFINE_string(old_image, "", "Path to the old rootfs"); DEFINE_string(new_image, "", "Path to the new rootfs"); @@ -384,6 +420,11 @@ int Main(int argc, char** argv) { 0, "The maximum timestamp of the OS allowed to apply this " "payload."); + DEFINE_string( + partition_timestamps, + "", + "The per-partition maximum timestamps which the OS allowed to apply this " + "payload. Passed in comma separated pairs, e.x. system:1234,vendor:5678"); DEFINE_string(old_channel, "", @@ -709,6 +750,10 @@ int Main(int argc, char** argv) { } payload_config.max_timestamp = FLAGS_max_timestamp; + if (!FLAGS_partition_timestamps.empty()) { + CHECK(ParsePerPartitionTimestamps(FLAGS_partition_timestamps, + &payload_config)); + } if (payload_config.is_delta && payload_config.version.minor >= kVerityMinorPayloadVersion) diff --git a/payload_generator/payload_file.cc b/payload_generator/payload_file.cc index c1594c75..1388f2da 100644 --- a/payload_generator/payload_file.cc +++ b/payload_generator/payload_file.cc @@ -92,6 +92,7 @@ bool PayloadFile::AddPartition(const PartitionConfig& old_conf, part.aops = std::move(aops); part.postinstall = new_conf.postinstall; part.verity = new_conf.verity; + part.version = new_conf.version; // Initialize the PartitionInfo objects if present. if (!old_conf.path.empty()) TEST_AND_RETURN_FALSE( @@ -132,6 +133,9 @@ bool PayloadFile::WritePayload(const string& payload_file, for (const auto& part : part_vec_) { PartitionUpdate* partition = manifest_.add_partitions(); partition->set_partition_name(part.name); + if (!part.version.empty()) { + partition->set_version(part.version); + } if (part.postinstall.run) { partition->set_run_postinstall(true); if (!part.postinstall.path.empty()) diff --git a/payload_generator/payload_file.h b/payload_generator/payload_file.h index d1f8196e..3dce00fc 100644 --- a/payload_generator/payload_file.h +++ b/payload_generator/payload_file.h @@ -96,6 +96,8 @@ class PayloadFile { PostInstallConfig postinstall; VerityConfig verity; + // Per partition timestamp. + std::string version; }; std::vector<Partition> part_vec_; diff --git a/payload_generator/payload_generation_config.h b/payload_generator/payload_generation_config.h index 9abb97f3..ec630435 100644 --- a/payload_generator/payload_generation_config.h +++ b/payload_generator/payload_generation_config.h @@ -119,6 +119,9 @@ struct PartitionConfig { // Enables the on device fec data computation by default. bool disable_fec_computation = false; + + // Per-partition version, usually a number representing timestamp. + std::string version; }; // The ImageConfig struct describes a pair of binaries kernel and rootfs and the diff --git a/scripts/brillo_update_payload b/scripts/brillo_update_payload index 9bae74ef..3bc87bd6 100755 --- a/scripts/brillo_update_payload +++ b/scripts/brillo_update_payload @@ -186,6 +186,10 @@ if [[ "${COMMAND}" == "generate" ]]; then "Optional: The maximum unix timestamp of the OS allowed to apply this \ payload, should be set to a number higher than the build timestamp of the \ system running on the device, 0 if not specified." + DEFINE_string partition_timestamps "" \ + "Optional: Per-partition maximum unix timestamp of the OS allowed to \ +apply this payload. Should be a comma separated key value pairs. e.x.\ +system:1234,vendor:456" DEFINE_string disable_fec_computation "" \ "Optional: Disables the on device fec data computation for incremental \ update. This feature is enabled by default." @@ -696,6 +700,10 @@ cmd_generate() { GENERATOR_ARGS+=( --max_timestamp="${FLAGS_max_timestamp}" ) fi + if [[ -n "${FLAGS_partition_timestamps}" ]]; then + GENERATOR_ARGS+=( --partition_timestamps="${FLAGS_partition_timestamps}" ) + fi + if [[ -n "${POSTINSTALL_CONFIG_FILE}" ]]; then GENERATOR_ARGS+=( --new_postinstall_config_file="${POSTINSTALL_CONFIG_FILE}" |