github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/cmds/boot/fitboot/main.go (about) 1 // Copyright 2017-2019 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "flag" 9 "fmt" 10 "log" 11 "os" 12 13 "github.com/mvdan/u-root-coreutils/pkg/acpi" 14 "github.com/mvdan/u-root-coreutils/pkg/boot" 15 "github.com/mvdan/u-root-coreutils/pkg/boot/fit" 16 "github.com/mvdan/u-root-coreutils/pkg/vfile" 17 ) 18 19 var ( 20 dryRun = flag.Bool("dryrun", false, "Do not actually kexec into the boot config") 21 debug = flag.Bool("d", false, "Print debug output") 22 cmdline = flag.String("c", "earlyprintk=ttyS0,115200,keep console=ttyS0", "command line") 23 config = flag.String("config", "", "FIT configuration to use") 24 kernel = flag.String("k", "", "Kernel image node name.") 25 initramfs = flag.String("i", "", "InitRAMFS node name -- default none") 26 ringPath = flag.String("r", "", "Path to PGP keyring. Enforces signature if non-empty path") 27 rsdpLookup = flag.Bool("rsdp", false, "Derrive RSDP table pointer from environment") 28 ) 29 30 var v = func(string, ...interface{}) {} 31 32 func main() { 33 flag.Parse() 34 35 if *debug { 36 v = log.Printf 37 } 38 39 if len(flag.Args()) != 1 { 40 log.Fatal("Usage: fitboot <file>") 41 } 42 f, err := fit.New(flag.Args()[0]) 43 if err != nil { 44 log.Fatal(err) 45 } 46 47 f.Cmdline, f.Kernel, f.InitRAMFS, f.ConfigOverride = *cmdline, *kernel, *initramfs, *config 48 49 kn, in, err := f.LoadConfig() 50 if err == nil { 51 f.Kernel, f.InitRAMFS = kn, in 52 } else { 53 v("Configuration is not available: %v", err) 54 } 55 56 if f.Kernel == "" { 57 log.Fatal("kernel name is not found in fit configuration or pass through -k.") 58 } 59 60 v("Kernel name=%s, initramfs=%s", f.Kernel, f.InitRAMFS) 61 62 kernelCmd := *cmdline 63 if *rsdpLookup { 64 r, err := acpi.GetRSDP() 65 if err != nil { 66 log.Fatal("Unable to find acpi table in the environment.") 67 } 68 v("Found an RSDP at %#x", r.RSDPAddr()) 69 kernelCmd = fmt.Sprintf("acpi_rsdp=%x %s", r.RSDPAddr(), kernelCmd) 70 } 71 72 f.Cmdline = kernelCmd 73 74 if *ringPath != "" { 75 ring, err := vfile.GetKeyRing(*ringPath) 76 if err != nil { 77 log.Fatal(err) 78 } 79 f.KeyRing = ring 80 } 81 82 if err := f.Load(*debug); err != nil { 83 log.Fatal(err) 84 } 85 86 if *dryRun { 87 v("Not trying to boot since this is a dry run") 88 os.Exit(0) 89 } 90 91 if err := boot.Execute(); err != nil { 92 log.Fatal(err) 93 } 94 }