From 2c151caae78a21a45196df85f889d8350c69d1e0 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 8 Jul 2020 16:01:27 -0400 Subject: [PATCH] Add a sample script for making uefi netboot entries This may be handy for manually configuring uefi network boot entries locally --- misc/makeuefinetbootentry.py | 82 ++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 misc/makeuefinetbootentry.py diff --git a/misc/makeuefinetbootentry.py b/misc/makeuefinetbootentry.py new file mode 100644 index 00000000..861e0e06 --- /dev/null +++ b/misc/makeuefinetbootentry.py @@ -0,0 +1,82 @@ +import argparse +import struct +import os +import sys + +# This script will create a PXE or HTTP boot entry specific for a linux nic using +# convenience of the linux interface name. It can help produce precise network boot order +# configuration more easily if that is useful + +# only tested with Lenovo system firmware on PCIe network adapters + +parser = argparse.ArgumentParser(description='Generate an efivars boot entry file') +parser.add_argument('interface', help='Current linux interface name to boot from') +parser.add_argument('outfile', help='The file to write, e.g. /sys/firmware/efi/efivars/Boot0007-8be4df61-93ca-11d2-aa0d-00e098032b8c') +parser.add_argument('-u', help='The HTTP url to boot, "" for generic HTTP boot instead of PXE') +args = parser.parse_args() +with open('/sys/class/net/{0}/address'.format(sys.argv[1])) as macaddr: + macaddr = macaddr.read() + macaddr = macaddr.split(':') + macaddr = [ int(x, 16) for x in macaddr ] + macaddr = bytes(macaddr) + +olddir = os.getcwd() +os.chdir('/sys/class/net/{0}'.format(sys.argv[1])) +devdir = os.readlink('/sys/class/net/{0}/device'.format(sys.argv[1])) +os.chdir(devdir) +pcipath = os.getcwd() +pcipath = pcipath.split('/') +os.chdir('/'.join(pcipath[:4])) +acpiid = os.readlink('firmware_node') +os.chdir(acpiid) +hid = '0A03' # do not adapt, always say pciroot, pcieroot doesn't work open('hid').read().replace('PNP', '') +hid = int(hid, 16) << 16 | 0x41d0 +hid = struct.pack('