github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/boot/kexec/kexec_linux_implemented.go (about)

     1  // Copyright 2015-2017 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  // +build linux,amd64 linux,arm64
     6  
     7  package kexec
     8  
     9  import (
    10  	"fmt"
    11  	"os"
    12  
    13  	"golang.org/x/sys/unix"
    14  )
    15  
    16  // FileLoad loads the given kernel as the new kernel with the given ramfs and
    17  // cmdline.
    18  //
    19  // The kexec_file_load(2) syscall is x86-64 and arm64 only.
    20  func FileLoad(kernel, ramfs *os.File, cmdline string) error {
    21  	var flags int
    22  	var ramfsfd int
    23  	if ramfs != nil {
    24  		ramfsfd = int(ramfs.Fd())
    25  	} else {
    26  		flags |= unix.KEXEC_FILE_NO_INITRAMFS
    27  	}
    28  
    29  	if err := unix.KexecFileLoad(int(kernel.Fd()), ramfsfd, cmdline, flags); err != nil {
    30  		return fmt.Errorf("sys_kexec(%d, %d, %s, %x) = %v", kernel.Fd(), ramfsfd, cmdline, flags, err)
    31  	}
    32  	return nil
    33  }