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
13namespace paver {
14
15// List of commands supported by paver utility.
16enum class Command {
17    kUnknown,
18    kInstallBootloader,
19    kInstallEfi,
20    kInstallKernc,
21    kInstallZirconA,
22    kInstallZirconB,
23    kInstallZirconR,
24    kInstallFvm,
25    kWipe,
26};
27
28// Architecture of device being paved. Used for payload validation.
29enum class Arch {
30    X64,
31    ARM64,
32};
33
34struct Flags {
35    Command cmd = Command::kUnknown;
36    Arch arch = Arch::X64;
37    bool force = false;
38    fbl::unique_fd payload_fd;
39};
40
41// Paves a sparse_file to the underlying disk, on top partition.
42// Expects FVM partition to not exist
43extern zx_status_t FvmPave(fbl::unique_ptr<DevicePartitioner> device_partitioner,
44                           fbl::unique_fd payload_fd);
45
46// Paves an image onto the disk.
47extern zx_status_t PartitionPave(fbl::unique_ptr<DevicePartitioner> partitioner,
48                                 fbl::unique_fd payload_fd, Partition partition_type, Arch arch);
49
50// Wipes the following partitions:
51// - System
52// - Data
53// - Blob
54// - FVM
55// - EFI
56//
57// From the target, leaving it (hopefully) in a state ready for a sparse FVM
58// image to be installed.
59extern zx_status_t FvmClean(fbl::unique_ptr<DevicePartitioner> partitioner);
60
61// Reads the entire file from supplied file descriptor. This is necessary due to
62// implementation of streaming protocol which forces entire file to be
63// transfered.
64extern void Drain(fbl::unique_fd fd);
65
66// Implements tool commands.
67extern zx_status_t RealMain(Flags flags);
68
69} // namespace paver
70