blob: f18055f65f13ac48408a6547cce68cb130bad6dd [file] [log] [blame]
Alex Deymof1cbe172015-03-05 15:58:37 -08001// 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 Deymob42b98d2015-07-06 17:42:38 -070010#include <memory>
Alex Deymof1cbe172015-03-05 15:58:37 -080011#include <string>
12#include <vector>
13
Alex Deymob42b98d2015-07-06 17:42:38 -070014#include "update_engine/payload_generator/filesystem_interface.h"
Alex Deymof1cbe172015-03-05 15:58:37 -080015#include "update_engine/update_metadata.pb.h"
16
17namespace chromeos_update_engine {
18
Alex Deymo14158572015-06-13 03:37:08 -070019// The list different kind of partitions supported by the updater.
20enum class PartitionName {
21 kKernel,
22 kRootfs,
23};
24
Alex Deymo35589c22015-06-07 17:33:18 +020025struct PartitionConfig {
Alex Deymo14158572015-06-13 03:37:08 -070026 explicit PartitionConfig(PartitionName name) : name(name) {}
27
Alex Deymo35589c22015-06-07 17:33:18 +020028 // 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 Deymob42b98d2015-07-06 17:42:38 -070032 // 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 Deymo35589c22015-06-07 17:33:18 +020036 // 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 Deymo14158572015-06-13 03:37:08 -070047
Alex Deymob42b98d2015-07-06 17:42:38 -070048 // The FilesystemInterface implementation used to access this partition's
49 // files.
50 std::unique_ptr<FilesystemInterface> fs_interface;
51
Alex Deymo14158572015-06-13 03:37:08 -070052 PartitionName name;
Alex Deymo35589c22015-06-07 17:33:18 +020053};
54
Alex Deymof1cbe172015-03-05 15:58:37 -080055// 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.
58struct ImageConfig {
59 // Returns whether the ImageConfig is an empty image.
60 bool ValidateIsEmpty() const;
61
Alex Deymo35589c22015-06-07 17:33:18 +020062 // 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 Deymof1cbe172015-03-05 15:58:37 -080064 // size is detected from the filesystem.
65 // Returns whether the image size was properly detected.
66 bool LoadImageSize();
67
Alex Deymoa26432a2015-03-12 16:08:04 -070068 // Load the |rootfs_size| stored in the kernel command line in the
Alex Deymo35589c22015-06-07 17:33:18 +020069 // |kernel.path| when the kernel is using rootfs verification (dm-verity).
Alex Deymoa26432a2015-03-12 16:08:04 -070070 // Returns whether it loaded the size from the kernel command line. For
Alex Deymo35589c22015-06-07 17:33:18 +020071 // example, it would return false if no |kernel.path| was provided or the
Alex Deymoa26432a2015-03-12 16:08:04 -070072 // kernel doesn't have verity enabled.
73 bool LoadVerityRootfsSize();
74
Alex Deymof1cbe172015-03-05 15:58:37 -080075 // 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 Deymo35589c22015-06-07 17:33:18 +020082 // The updated partitions.
Alex Deymo14158572015-06-13 03:37:08 -070083 PartitionConfig rootfs = PartitionConfig{PartitionName::kRootfs};
84 PartitionConfig kernel = PartitionConfig{PartitionName::kKernel};
Alex Deymof1cbe172015-03-05 15:58:37 -080085};
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).
91struct 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 Deymo9b244df2015-03-11 21:51:18 -0700108 // 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 Deymof1cbe172015-03-05 15:58:37 -0800113 // 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 Deymo35589c22015-06-07 17:33:18 +0200119 // minimum alignment size for blocks (if needed). Algorithms should be able to
Alex Deymof1cbe172015-03-05 15:58:37 -0800120 // 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_