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