Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 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 | // |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 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 | |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 22 | #include <memory> |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 23 | #include <string> |
| 24 | #include <vector> |
| 25 | |
Sen Jiang | 05feee0 | 2015-11-11 15:59:49 -0800 | [diff] [blame] | 26 | #include <brillo/key_value_store.h> |
| 27 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 28 | #include "update_engine/payload_consumer/payload_constants.h" |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 29 | #include "update_engine/payload_generator/filesystem_interface.h" |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 30 | #include "update_engine/update_metadata.pb.h" |
| 31 | |
| 32 | namespace chromeos_update_engine { |
| 33 | |
Sen Jiang | 05feee0 | 2015-11-11 15:59:49 -0800 | [diff] [blame] | 34 | struct PostInstallConfig { |
| 35 | // Whether the postinstall config is empty. |
| 36 | bool IsEmpty() const; |
| 37 | |
| 38 | // Whether this partition carries a filesystem with post-install program that |
| 39 | // must be run to finalize the update process. |
| 40 | bool run = false; |
| 41 | |
| 42 | // The path to the post-install program relative to the root of this |
| 43 | // filesystem. |
| 44 | std::string path; |
| 45 | |
| 46 | // The filesystem type used to mount the partition in order to run the |
| 47 | // post-install program. |
| 48 | std::string filesystem_type; |
| 49 | }; |
| 50 | |
Alex Deymo | 35589c2 | 2015-06-07 17:33:18 +0200 | [diff] [blame] | 51 | struct PartitionConfig { |
Sen Jiang | 625406c | 2015-09-16 16:35:23 -0700 | [diff] [blame] | 52 | explicit PartitionConfig(std::string name) : name(name) {} |
Alex Deymo | 1415857 | 2015-06-13 03:37:08 -0700 | [diff] [blame] | 53 | |
Alex Deymo | 35589c2 | 2015-06-07 17:33:18 +0200 | [diff] [blame] | 54 | // Returns whether the PartitionConfig is not an empty image and all the |
| 55 | // fields are set correctly to a valid image file. |
| 56 | bool ValidateExists() const; |
| 57 | |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 58 | // Open then filesystem stored in this partition and stores it in |
| 59 | // |fs_interface|. Returns whether opening the filesystem worked. |
| 60 | bool OpenFilesystem(); |
| 61 | |
Alex Deymo | 35589c2 | 2015-06-07 17:33:18 +0200 | [diff] [blame] | 62 | // The path to the partition file. This can be a regular file or a block |
| 63 | // device such as a loop device. |
| 64 | std::string path; |
| 65 | |
| 66 | // The size of the data in |path|. If rootfs verification is used (verity) |
| 67 | // this value should match the size of the verity device for the rootfs, and |
| 68 | // the size of the whole kernel. This value could be smaller than the |
| 69 | // partition and is the size of the data update_engine assumes verified for |
| 70 | // the source image, and the size of that data it should generate for the |
| 71 | // target image. |
| 72 | uint64_t size = 0; |
Alex Deymo | 1415857 | 2015-06-13 03:37:08 -0700 | [diff] [blame] | 73 | |
Alex Deymo | b42b98d | 2015-07-06 17:42:38 -0700 | [diff] [blame] | 74 | // The FilesystemInterface implementation used to access this partition's |
| 75 | // files. |
| 76 | std::unique_ptr<FilesystemInterface> fs_interface; |
| 77 | |
Sen Jiang | 625406c | 2015-09-16 16:35:23 -0700 | [diff] [blame] | 78 | std::string name; |
Sen Jiang | 05feee0 | 2015-11-11 15:59:49 -0800 | [diff] [blame] | 79 | |
| 80 | PostInstallConfig postinstall; |
Alex Deymo | 35589c2 | 2015-06-07 17:33:18 +0200 | [diff] [blame] | 81 | }; |
| 82 | |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 83 | // The ImageConfig struct describes a pair of binaries kernel and rootfs and the |
| 84 | // metadata associated with the image they are part of, like build number, size, |
| 85 | // etc. |
| 86 | struct ImageConfig { |
| 87 | // Returns whether the ImageConfig is an empty image. |
| 88 | bool ValidateIsEmpty() const; |
| 89 | |
Alex Deymo | 35589c2 | 2015-06-07 17:33:18 +0200 | [diff] [blame] | 90 | // Load |rootfs_size| and |kernel.size| from the respective image files. For |
| 91 | // the kernel, the whole |kernel.path| file is assumed. For the rootfs, the |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 92 | // size is detected from the filesystem. |
| 93 | // Returns whether the image size was properly detected. |
| 94 | bool LoadImageSize(); |
| 95 | |
Sen Jiang | 05feee0 | 2015-11-11 15:59:49 -0800 | [diff] [blame] | 96 | // Load postinstall config from a key value store. |
| 97 | bool LoadPostInstallConfig(const brillo::KeyValueStore& store); |
| 98 | |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 99 | // Returns whether the |image_info| field is empty. |
| 100 | bool ImageInfoIsEmpty() const; |
| 101 | |
| 102 | // The ImageInfo message defined in the update_metadata.proto file describes |
| 103 | // the metadata of the image. |
| 104 | ImageInfo image_info; |
| 105 | |
Alex Deymo | 35589c2 | 2015-06-07 17:33:18 +0200 | [diff] [blame] | 106 | // The updated partitions. |
Sen Jiang | 981eb11 | 2015-08-25 17:03:18 -0700 | [diff] [blame] | 107 | std::vector<PartitionConfig> partitions; |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | // The PayloadGenerationConfig struct encapsulates all the configuration to |
| 111 | // build the requested payload. This includes information about the old and new |
| 112 | // image as well as the restrictions applied to the payload (like minor-version |
| 113 | // and full/delta payload). |
| 114 | struct PayloadGenerationConfig { |
| 115 | // Returns whether the PayloadGenerationConfig is valid. |
| 116 | bool Validate() const; |
| 117 | |
| 118 | // Image information about the new image that's the target of this payload. |
| 119 | ImageConfig target; |
| 120 | |
| 121 | // Image information pertaining the old image, if any. This is only valid |
| 122 | // if is_full is false, so we are requested a delta payload. |
| 123 | ImageConfig source; |
| 124 | |
| 125 | // Wheter the requested payload is a delta payload. |
| 126 | bool is_delta = false; |
| 127 | |
Sen Jiang | 55c4f9b | 2016-02-10 11:26:20 -0800 | [diff] [blame] | 128 | // Wheter the IMGDIFF operation is allowed. |
| 129 | bool imgdiff_allowed = false; |
| 130 | |
Sen Jiang | 46e9b17 | 2015-08-31 14:11:01 -0700 | [diff] [blame] | 131 | // The major_version of the requested payload. |
| 132 | uint64_t major_version; |
| 133 | |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 134 | // The minor_version of the requested payload. |
| 135 | uint32_t minor_version; |
| 136 | |
Alex Deymo | 9b244df | 2015-03-11 21:51:18 -0700 | [diff] [blame] | 137 | // The size of the rootfs partition, that not necessarily is the same as the |
| 138 | // filesystem in either source or target version, since there is some space |
| 139 | // after the partition used to store the verity hashes and or the bootcache. |
| 140 | uint64_t rootfs_partition_size = 0; |
| 141 | |
Alex Deymo | 2d3b2d6 | 2015-07-17 17:34:36 -0700 | [diff] [blame] | 142 | // The |hard_chunk_size| is the maximum size that a single operation should |
| 143 | // write in the destination. Operations bigger than chunk_size should be |
| 144 | // split. A value of -1 means no hard chunk size limit. A very low limit |
| 145 | // means more operations, and less of a chance to reuse the data. |
| 146 | ssize_t hard_chunk_size = -1; |
| 147 | |
| 148 | // The |soft_chunk_size| is the preferred chunk size to use when there's no |
| 149 | // significant impact to the operations. For example, REPLACE, MOVE and |
| 150 | // SOURCE_COPY operations are not significantly impacted by the chunk size, |
| 151 | // except for a few bytes overhead in the manifest to describe extra |
| 152 | // operations. On the other hand, splitting BSDIFF operations impacts the |
| 153 | // payload size since it is not possible to use the redundancy *between* |
| 154 | // chunks. |
| 155 | size_t soft_chunk_size = 2 * 1024 * 1024; |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 156 | |
| 157 | // TODO(deymo): Remove the block_size member and maybe replace it with a |
Alex Deymo | 35589c2 | 2015-06-07 17:33:18 +0200 | [diff] [blame] | 158 | // minimum alignment size for blocks (if needed). Algorithms should be able to |
Alex Deymo | f1cbe17 | 2015-03-05 15:58:37 -0800 | [diff] [blame] | 159 | // pick the block_size they want, but for now only 4 KiB is supported. |
| 160 | |
| 161 | // The block size used for all the operations in the manifest. |
| 162 | size_t block_size = 4096; |
| 163 | }; |
| 164 | |
| 165 | } // namespace chromeos_update_engine |
| 166 | |
| 167 | #endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_GENERATION_CONFIG_H_ |