github.com/zaolin/u-root@v0.0.0-20200428085104-64aaafd46c6d/cmds/boot/systemboot/systemboot_linux.go (about)

     1  // Copyright 2020 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  	"os"
     9  	"syscall"
    10  	"unsafe"
    11  
    12  	"github.com/u-root/u-root/pkg/ipmi"
    13  )
    14  
    15  const (
    16  	_IOC_NVRAM = 'p'
    17  )
    18  
    19  // ioctl to clear whole CMOS/NV-RAM
    20  var _NVRAM_INIT = ipmi.IO(_IOC_NVRAM, 0x40)
    21  
    22  func cmosClear() error {
    23  	f, err := os.OpenFile("/dev/nvram", os.O_RDWR, 0)
    24  	if err != nil {
    25  		return err
    26  	}
    27  	defer f.Close()
    28  	var i = 0
    29  	if errno := ipmi.Ioctl(uintptr(f.Fd()), _NVRAM_INIT, unsafe.Pointer(&i)); errno != 0 {
    30  		return errno
    31  	}
    32  	return nil
    33  }
    34  
    35  func reboot() error {
    36  	return syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
    37  }