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