"""Assemble the removable UEFI loader and Ethernet-only GRUB configuration.""" import hashlib import struct def u16(b,o): return struct.unpack_from('=65525 size=self.fatsz*self.bps assert data[self.fatstart:self.fatstart+size]==data[self.fatstart+size:self.fatstart+2*size] def fat(self,cluster): return u32(self.data,self.fatstart+cluster*4)&0x0fffffff def offset(self,cluster): assert 2<=cluster>16); struct.pack_into('=8 and p+size<=end assert typ!=2, 'Embedded config already present' if typ==3: prefixes.append(bytes(b[base+p+8:base+p+size]).rstrip(b'\0')) p+=(size+7)//8*8 assert p==end and prefixes==[b'(,gpt3)/boot/grub'] # Retain the root-based module prefix. Load the new configuration from the # booted EFI directory, using GRUB's documented embedded-config stage. script=b'insmod fat\ninsmod normal\nnormal $cmdpath/grub.cfg\n\0' module=struct.pack('>16) checksum=(checksum&65535)+(checksum>>16) struct.pack_into('