Android-cuttlefish cvd tool
boot_image.h
Go to the documentation of this file.
1//
2// Copyright (C) 2026 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
18#include <stdint.h>
19
20#include <variant>
21
22#include "bootimg.h"
23
25#include "cuttlefish/io/io.h"
28
29namespace cuttlefish {
30
31inline constexpr uint32_t kBootImagePageSize = 4096;
32
33class BootImage {
34 public:
35 static Result<BootImage> Read(std::unique_ptr<ReaderSeeker>);
36
37 std::string KernelCommandLine() const;
38
39 ReadWindowView Kernel() const;
40 ReadWindowView Ramdisk() const;
41 std::optional<ReadWindowView> Signature() const;
42 uint32_t OsVersion() const;
43
45
46 private:
48 std::variant<boot_img_hdr_v0, boot_img_hdr_v1, boot_img_hdr_v2,
49 boot_img_hdr_v3, boot_img_hdr_v4>;
50
51 BootImage(std::unique_ptr<ReaderSeeker>, HeaderVariant);
52
53 uint32_t PageSize() const;
54 uint64_t KernelPages() const;
55 uint64_t RamdiskPages() const;
56
57 std::unique_ptr<ReaderSeeker> reader_;
59};
60
61} // namespace cuttlefish
Definition: boot_image.h:33
Result< void > Unpack(ReadWriteFilesystem &)
Definition: boot_image.cc:143
ReadWindowView Kernel() const
Definition: boot_image.cc:108
uint64_t RamdiskPages() const
Definition: boot_image.cc:121
BootImage(std::unique_ptr< ReaderSeeker >, HeaderVariant)
Definition: boot_image.cc:69
std::optional< ReadWindowView > Signature() const
Definition: boot_image.cc:134
ReadWindowView Ramdisk() const
Definition: boot_image.cc:127
uint32_t PageSize() const
Definition: boot_image.cc:94
std::string KernelCommandLine() const
Definition: boot_image.cc:82
HeaderVariant header_
Definition: boot_image.h:58
std::variant< boot_img_hdr_v0, boot_img_hdr_v1, boot_img_hdr_v2, boot_img_hdr_v3, boot_img_hdr_v4 > HeaderVariant
Definition: boot_image.h:49
uint64_t KernelPages() const
Definition: boot_image.cc:102
static Result< BootImage > Read(std::unique_ptr< ReaderSeeker >)
Definition: boot_image.cc:47
std::unique_ptr< ReaderSeeker > reader_
Definition: boot_image.h:57
uint32_t OsVersion() const
Definition: boot_image.cc:168
Definition: read_window_view.h:29
Definition: filesystem.h:37
Definition: alloc_driver.h:20
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30
constexpr uint32_t kBootImagePageSize
Definition: boot_image.h:31