github.com/jlowellwofford/u-root@v1.0.0/cmds/rsdp/rsdp.go (about) 1 // Copyright 2012-2018 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 // rsdp allows to determine the ACPI RSDP structure address which could 6 // be pass to the boot command later on 7 // It must be executed at the system init as it relies on scanning 8 // the kernel messages which could be quickly filled up in some cases 9 10 // 11 // Synopsis: 12 // rsdp 13 // 14 // Description: 15 // Look for rsdp value into kernel messages 16 // 17 // Example: 18 // rsdp - Start the script and save the founded value into /tmp/rsdp 19 20 package main 21 22 import ( 23 "bufio" 24 "fmt" 25 "log" 26 "os" 27 "strings" 28 "time" 29 ) 30 31 func getRSDP(path string) (string, error) { 32 33 file, err := os.Open(path) 34 if err != nil { 35 log.Fatal(err) 36 } 37 defer file.Close() 38 39 var returnValue string 40 channel := make(chan string) 41 42 go func() { 43 scanner := bufio.NewScanner(file) 44 for scanner.Scan() { 45 mystring := scanner.Text() 46 channel <- mystring 47 } 48 close(channel) 49 if err := scanner.Err(); err != nil { 50 log.Fatal(err) 51 } 52 }() 53 54 var dataRead int 55 var exit int 56 dataRead = 1 57 exit = 0 58 for dataRead == 1 && exit == 0 { 59 select { 60 case res := <-channel: 61 if strings.Contains(res, "RSDP") { 62 returnValue = strings.Split(res, " ")[2] 63 exit = 0 64 } 65 66 case <-time.After(1 * time.Second): 67 dataRead = 0 68 } 69 } 70 return returnValue, err 71 } 72 73 func main() { 74 rsdp_value, _ := getRSDP("/dev/kmsg") 75 f, err := os.Create("/tmp/rsdp") 76 if err != nil { 77 log.Fatal(err) 78 } 79 defer f.Close() 80 _, _ = fmt.Fprintf(f, " acpi_rsdp=%s ", rsdp_value) 81 }