payload_generation_config.h revision 46e9b1735a16518d563b3c7e7227408f8fc3e891
1// 2// Copyright (C) 2015 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15// 16 17#ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_GENERATION_CONFIG_H_ 18#define UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_GENERATION_CONFIG_H_ 19 20#include <cstddef> 21 22#include <memory> 23#include <string> 24#include <vector> 25 26#include "update_engine/payload_generator/filesystem_interface.h" 27#include "update_engine/update_metadata.pb.h" 28 29namespace chromeos_update_engine { 30 31// The list different kind of partitions supported by the updater. 32enum class PartitionName { 33 kKernel, 34 kRootfs, 35}; 36 37// Return a string name for the PartitionName. 38std::string PartitionNameString(PartitionName name); 39 40struct PartitionConfig { 41 explicit PartitionConfig(PartitionName name) : name(name) {} 42 43 // Returns whether the PartitionConfig is not an empty image and all the 44 // fields are set correctly to a valid image file. 45 bool ValidateExists() const; 46 47 // Open then filesystem stored in this partition and stores it in 48 // |fs_interface|. Returns whether opening the filesystem worked. 49 bool OpenFilesystem(); 50 51 // The path to the partition file. This can be a regular file or a block 52 // device such as a loop device. 53 std::string path; 54 55 // The size of the data in |path|. If rootfs verification is used (verity) 56 // this value should match the size of the verity device for the rootfs, and 57 // the size of the whole kernel. This value could be smaller than the 58 // partition and is the size of the data update_engine assumes verified for 59 // the source image, and the size of that data it should generate for the 60 // target image. 61 uint64_t size = 0; 62 63 // The FilesystemInterface implementation used to access this partition's 64 // files. 65 std::unique_ptr<FilesystemInterface> fs_interface; 66 67 PartitionName name; 68}; 69 70// The ImageConfig struct describes a pair of binaries kernel and rootfs and the 71// metadata associated with the image they are part of, like build number, size, 72// etc. 73struct ImageConfig { 74 // Returns whether the ImageConfig is an empty image. 75 bool ValidateIsEmpty() const; 76 77 // Load |rootfs_size| and |kernel.size| from the respective image files. For 78 // the kernel, the whole |kernel.path| file is assumed. For the rootfs, the 79 // size is detected from the filesystem. 80 // Returns whether the image size was properly detected. 81 bool LoadImageSize(); 82 83 // Load the |rootfs_size| stored in the kernel command line in the 84 // |kernel.path| when the kernel is using rootfs verification (dm-verity). 85 // Returns whether it loaded the size from the kernel command line. For 86 // example, it would return false if no |kernel.path| was provided or the 87 // kernel doesn't have verity enabled. 88 bool LoadVerityRootfsSize(); 89 90 // Returns whether the |image_info| field is empty. 91 bool ImageInfoIsEmpty() const; 92 93 // The ImageInfo message defined in the update_metadata.proto file describes 94 // the metadata of the image. 95 ImageInfo image_info; 96 97 // The updated partitions. 98 PartitionConfig rootfs = PartitionConfig{PartitionName::kRootfs}; 99 PartitionConfig kernel = PartitionConfig{PartitionName::kKernel}; 100}; 101 102// The PayloadGenerationConfig struct encapsulates all the configuration to 103// build the requested payload. This includes information about the old and new 104// image as well as the restrictions applied to the payload (like minor-version 105// and full/delta payload). 106struct PayloadGenerationConfig { 107 // Returns whether the PayloadGenerationConfig is valid. 108 bool Validate() const; 109 110 // Image information about the new image that's the target of this payload. 111 ImageConfig target; 112 113 // Image information pertaining the old image, if any. This is only valid 114 // if is_full is false, so we are requested a delta payload. 115 ImageConfig source; 116 117 // Wheter the requested payload is a delta payload. 118 bool is_delta = false; 119 120 // The major_version of the requested payload. 121 uint64_t major_version; 122 123 // The minor_version of the requested payload. 124 uint32_t minor_version; 125 126 // The size of the rootfs partition, that not necessarily is the same as the 127 // filesystem in either source or target version, since there is some space 128 // after the partition used to store the verity hashes and or the bootcache. 129 uint64_t rootfs_partition_size = 0; 130 131 // The |hard_chunk_size| is the maximum size that a single operation should 132 // write in the destination. Operations bigger than chunk_size should be 133 // split. A value of -1 means no hard chunk size limit. A very low limit 134 // means more operations, and less of a chance to reuse the data. 135 ssize_t hard_chunk_size = -1; 136 137 // The |soft_chunk_size| is the preferred chunk size to use when there's no 138 // significant impact to the operations. For example, REPLACE, MOVE and 139 // SOURCE_COPY operations are not significantly impacted by the chunk size, 140 // except for a few bytes overhead in the manifest to describe extra 141 // operations. On the other hand, splitting BSDIFF operations impacts the 142 // payload size since it is not possible to use the redundancy *between* 143 // chunks. 144 size_t soft_chunk_size = 2 * 1024 * 1024; 145 146 // TODO(deymo): Remove the block_size member and maybe replace it with a 147 // minimum alignment size for blocks (if needed). Algorithms should be able to 148 // pick the block_size they want, but for now only 4 KiB is supported. 149 150 // The block size used for all the operations in the manifest. 151 size_t block_size = 4096; 152}; 153 154} // namespace chromeos_update_engine 155 156#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_GENERATION_CONFIG_H_ 157