1 // Copyright 2018 The Fuchsia 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 #pragma once
6 
7 #include <fbl/unique_fd.h>
8 #include <fbl/unique_ptr.h>
9 #include <zircon/types.h>
10 
11 #include "device-partitioner.h"
12 
13 namespace paver {
14 
15 // List of commands supported by paver utility.
16 enum class Command {
17     kUnknown,
18     kInstallBootloader,
19     kInstallEfi,
20     kInstallKernc,
21     kInstallZirconA,
22     kInstallZirconB,
23     kInstallZirconR,
24     kInstallVbMetaA,
25     kInstallVbMetaB,
26     kInstallDataFile,
27     kInstallFvm,
28     kWipe,
29 };
30 
31 // Architecture of device being paved. Used for payload validation.
32 enum class Arch {
33     X64,
34     ARM64,
35 };
36 
37 struct Flags {
38     Command cmd = Command::kUnknown;
39     Arch arch = Arch::X64;
40     bool force = false;
41     fbl::unique_fd payload_fd;
42     char* path = nullptr;
43 };
44 
45 // Paves an image onto the disk.
46 extern zx_status_t PartitionPave(fbl::unique_ptr<DevicePartitioner> partitioner,
47                                  fbl::unique_fd payload_fd, Partition partition_type, Arch arch);
48 
49 // Paves |fd| to a target |data_path| within the /data partition.
50 zx_status_t DataFilePave(fbl::unique_ptr<DevicePartitioner> partitioner,
51                          fbl::unique_fd payload_fd, char* data_path);
52 
53 // Reads the entire file from supplied file descriptor. This is necessary due to
54 // implementation of streaming protocol which forces entire file to be
55 // transferred.
56 extern void Drain(fbl::unique_fd fd);
57 
58 // Implements tool commands.
59 extern zx_status_t RealMain(Flags flags);
60 
61 } // namespace paver
62