-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathmultiboot.go
More file actions
77 lines (65 loc) · 1.92 KB
/
multiboot.go
File metadata and controls
77 lines (65 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2018 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package boot
import (
"fmt"
"io"
"strings"
"github.com/u-root/u-root/pkg/boot/ibft"
"github.com/u-root/u-root/pkg/boot/kexec"
"github.com/u-root/u-root/pkg/boot/multiboot"
)
// MultibootImage is a multiboot-formated OSImage, such as ESXi, Xen, Akaros,
// tboot.
type MultibootImage struct {
Name string
Kernel io.ReaderAt
Cmdline string
Modules []multiboot.Module
IBFT *ibft.IBFT
BootRank int
}
var _ OSImage = &MultibootImage{}
// Label returns either Name or a short description.
func (mi *MultibootImage) Label() string {
if len(mi.Name) > 0 {
return mi.Name
}
return fmt.Sprintf("Multiboot(kernel=%s cmdline=%s iBFT=%s)", stringer(mi.Kernel), mi.Cmdline, mi.IBFT)
}
// Rank for the boot menu order
func (mi *MultibootImage) Rank() int {
return mi.BootRank
}
// Edit the kernel command line.
func (mi *MultibootImage) Edit(f func(cmdline string) string) {
mi.Cmdline = f(mi.Cmdline)
}
// Load implements OSImage.Load.
func (mi *MultibootImage) Load(opts ...LoadOption) error {
loadOpts := defaultLoadOptions()
for _, opt := range opts {
opt(loadOpts)
}
entryPoint, segments, err := multiboot.PrepareLoad(loadOpts.verbose, mi.Kernel, mi.Cmdline, mi.Modules, mi.IBFT)
if err != nil {
return err
}
if !loadOpts.callKexecLoad {
return nil
}
if err := kexec.Load(entryPoint, segments, 0); err != nil {
return fmt.Errorf("kexec.Load() error: %w", err)
}
return nil
}
// String implements fmt.Stringer.
func (mi *MultibootImage) String() string {
modules := make([]string, len(mi.Modules))
for i, mod := range mi.Modules {
modules[i] = mod.Cmdline
}
return fmt.Sprintf("MultibootImage(\n Name: %s\n Kernel: %s\n Cmdline: %s\n iBFT: %s\n Modules: %s\n)",
mi.Name, stringer(mi.Kernel), mi.Cmdline, mi.IBFT, strings.Join(modules, ", "))
}