github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/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  
    10  	"github.com/vtolstov/go-ioctl"
    11  	"golang.org/x/sys/unix"
    12  )
    13  
    14  const (
    15  	_IOC_NVRAM = 'p'
    16  )
    17  
    18  // ioctl to clear whole CMOS/NV-RAM
    19  var _NVRAM_INIT = ioctl.IO(_IOC_NVRAM, 0x40)
    20  
    21  func cmosClear() error {
    22  	f, err := os.OpenFile("/dev/nvram", os.O_RDWR, 0)
    23  	if err != nil {
    24  		return err
    25  	}
    26  	defer f.Close()
    27  
    28  	return unix.IoctlSetPointerInt(int(f.Fd()), uint(_NVRAM_INIT), 0)
    29  }
    30  
    31  func reboot() error {
    32  	return unix.Reboot(unix.LINUX_REBOOT_CMD_RESTART)
    33  }