payload_generation_config.h revision 14158570d3995008dc93a628004118b87a6bca01
1// Copyright 2015 The Chromium OS Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_GENERATION_CONFIG_H_ 6#define UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_GENERATION_CONFIG_H_ 7 8#include <cstddef> 9 10#include <string> 11#include <vector> 12 13#include "update_engine/update_metadata.pb.h" 14 15namespace chromeos_update_engine { 16 17// The list different kind of partitions supported by the updater. 18enum class PartitionName { 19 kKernel, 20 kRootfs, 21}; 22 23struct PartitionConfig { 24 explicit PartitionConfig(PartitionName name) : name(name) {} 25 26 // Returns whether the PartitionConfig is not an empty image and all the 27 // fields are set correctly to a valid image file. 28 bool ValidateExists() const; 29 30 // The path to the partition file. This can be a regular file or a block 31 // device such as a loop device. 32 std::string path; 33 34 // The size of the data in |path|. If rootfs verification is used (verity) 35 // this value should match the size of the verity device for the rootfs, and 36 // the size of the whole kernel. This value could be smaller than the 37 // partition and is the size of the data update_engine assumes verified for 38 // the source image, and the size of that data it should generate for the 39 // target image. 40 uint64_t size = 0; 41 42 PartitionName name; 43}; 44 45// The ImageConfig struct describes a pair of binaries kernel and rootfs and the 46// metadata associated with the image they are part of, like build number, size, 47// etc. 48struct ImageConfig { 49 // Returns whether the ImageConfig is an empty image. 50 bool ValidateIsEmpty() const; 51 52 // Load |rootfs_size| and |kernel.size| from the respective image files. For 53 // the kernel, the whole |kernel.path| file is assumed. For the rootfs, the 54 // size is detected from the filesystem. 55 // Returns whether the image size was properly detected. 56 bool LoadImageSize(); 57 58 // Load the |rootfs_size| stored in the kernel command line in the 59 // |kernel.path| when the kernel is using rootfs verification (dm-verity). 60 // Returns whether it loaded the size from the kernel command line. For 61 // example, it would return false if no |kernel.path| was provided or the 62 // kernel doesn't have verity enabled. 63 bool LoadVerityRootfsSize(); 64 65 // Returns whether the |image_info| field is empty. 66 bool ImageInfoIsEmpty() const; 67 68 // The ImageInfo message defined in the update_metadata.proto file describes 69 // the metadata of the image. 70 ImageInfo image_info; 71 72 // The updated partitions. 73 PartitionConfig rootfs = PartitionConfig{PartitionName::kRootfs}; 74 PartitionConfig kernel = PartitionConfig{PartitionName::kKernel}; 75}; 76 77// The PayloadGenerationConfig struct encapsulates all the configuration to 78// build the requested payload. This includes information about the old and new 79// image as well as the restrictions applied to the payload (like minor-version 80// and full/delta payload). 81struct PayloadGenerationConfig { 82 // Returns whether the PayloadGenerationConfig is valid. 83 bool Validate() const; 84 85 // Image information about the new image that's the target of this payload. 86 ImageConfig target; 87 88 // Image information pertaining the old image, if any. This is only valid 89 // if is_full is false, so we are requested a delta payload. 90 ImageConfig source; 91 92 // Wheter the requested payload is a delta payload. 93 bool is_delta = false; 94 95 // The minor_version of the requested payload. 96 uint32_t minor_version; 97 98 // The size of the rootfs partition, that not necessarily is the same as the 99 // filesystem in either source or target version, since there is some space 100 // after the partition used to store the verity hashes and or the bootcache. 101 uint64_t rootfs_partition_size = 0; 102 103 // The chunk size is the maximum size that a single operation should write in 104 // the destination. Operations bigger than chunk_size should be split. A value 105 // of -1 means no chunk_size limit. 106 off_t chunk_size = -1; 107 108 // TODO(deymo): Remove the block_size member and maybe replace it with a 109 // minimum alignment size for blocks (if needed). Algorithms should be able to 110 // pick the block_size they want, but for now only 4 KiB is supported. 111 112 // The block size used for all the operations in the manifest. 113 size_t block_size = 4096; 114}; 115 116} // namespace chromeos_update_engine 117 118#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_GENERATION_CONFIG_H_ 119