From fa3e71ab808441aaf5d8cb2318f536089dafea3f Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 24 Oct 2014 00:40:09 +0200 Subject: [PATCH] efi: change eficonfig ordering so memconf() is first, dont fallback to fs when /cfg/pxe/ file isnt there having the memconf() (*e820=) last clutters the screen. do it first, so we can read *acpi= and *bootscreen= prints. we want to continue using tftp even when the /cfg/pxe/$ether file is not found. only when we detect no pxe/dhcp session, then we switch to local filesystem (non-network boot). --- sys/src/boot/efi/efi.c | 12 ++++---- sys/src/boot/efi/fns.h | 4 +-- sys/src/boot/efi/fs.c | 13 +++++---- sys/src/boot/efi/pxe.c | 64 +++++++++++++++++++++++++++--------------- 4 files changed, 57 insertions(+), 36 deletions(-) diff --git a/sys/src/boot/efi/efi.c b/sys/src/boot/efi/efi.c index 38df155de..ae9055c92 100644 --- a/sys/src/boot/efi/efi.c +++ b/sys/src/boot/efi/efi.c @@ -266,7 +266,7 @@ Found: *s++ = ' '; *s++ = '0', *s++ = 'x'; - s = hexfmt(s, 16, gop->Mode->FrameBufferBase), *s++ = '\n'; + s = hexfmt(s, 0, gop->Mode->FrameBufferBase), *s++ = '\n'; *s = '\0'; print(*cfg); @@ -276,9 +276,9 @@ Found: void eficonfig(char **cfg) { - screenconf(cfg); - acpiconf(cfg); memconf(cfg); + acpiconf(cfg); + screenconf(cfg); } EFI_STATUS @@ -290,9 +290,9 @@ efimain(EFI_HANDLE ih, EFI_SYSTEM_TABLE *st) IH = ih; ST = st; - f = pxeinit(); - if(f == nil) - f = fsinit(); + f = nil; + if(pxeinit(&f) && fsinit(&f)) + print("no boot devices\n"); for(;;){ kern = configure(f, path); diff --git a/sys/src/boot/efi/fns.h b/sys/src/boot/efi/fns.h index c249dd5ce..58dbe32e6 100644 --- a/sys/src/boot/efi/fns.h +++ b/sys/src/boot/efi/fns.h @@ -7,8 +7,8 @@ extern char hex[]; void usleep(int t); void jump(void *pc); -void* pxeinit(void); -void* fsinit(void); +int pxeinit(void **pf); +int fsinit(void **pf); void* (*open)(char *name); int (*read)(void *f, void *data, int len); diff --git a/sys/src/boot/efi/fs.c b/sys/src/boot/efi/fs.c index 04d9114a0..7850a5e81 100644 --- a/sys/src/boot/efi/fs.c +++ b/sys/src/boot/efi/fs.c @@ -83,8 +83,8 @@ fsclose(void *f) eficall(((EFI_FILE_PROTOCOL*)f)->Close, f); } -void* -fsinit(void) +int +fsinit(void **pf) { EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; @@ -92,15 +92,18 @@ fsinit(void) fsroot = nil; if(eficall(ST->BootServices->LocateProtocol, &EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, nil, &fs)) - return nil; + return -1; if(eficall(fs->OpenVolume, fs, &fsroot)){ fsroot = nil; - return nil; + return -1; } read = fsread; close = fsclose; open = fsopen; - return fsopen("/plan9.ini"); + if(pf != nil) + *pf = fsopen("/plan9.ini"); + + return 0; } diff --git a/sys/src/boot/efi/pxe.c b/sys/src/boot/efi/pxe.c index 9c7af88bc..87d7a7e2b 100644 --- a/sys/src/boot/efi/pxe.c +++ b/sys/src/boot/efi/pxe.c @@ -70,6 +70,11 @@ typedef struct { UINT8 DhcpDiscover[1472]; UINT8 DhcpAck[1472]; + UINT8 ProxyOffer[1472]; + UINT8 PxeDiscover[1472]; + UINT8 PxeReply[1472]; + UINT8 PxeBisReply[1472]; + } EFI_PXE_BASE_CODE_MODE; typedef struct { @@ -308,19 +313,17 @@ pxeopen(char *name) memmove(&t->dip, dhcp->BootpSiAddr, 4); memmove(&t->sip, pxe->Mode->StationIp, 4); - if(tftpopen(t, name) == 0) - return t; - return nil; + if(tftpopen(t, name)) + return nil; + return t; } -void* -pxeinit(void) +int +pxeinit(void **pf) { + EFI_PXE_BASE_CODE_MODE *mode; EFI_HANDLE *Handles; UINTN Count; - char ini[24]; - uchar *mac; - void *f; int i; pxe = nil; @@ -329,31 +332,46 @@ pxeinit(void) Handles = nil; if(eficall(ST->BootServices->LocateHandleBuffer, ByProtocol, &EFI_PXE_BASE_CODE_PROTOCOL_GUID, nil, &Count, &Handles)) - return nil; + return -1; for(i=0; iBootServices->HandleProtocol, Handles[i], &EFI_PXE_BASE_CODE_PROTOCOL_GUID, &pxe)) continue; - if(pxe->Mode != nil && pxe->Mode->Started) - break; + mode = pxe->Mode; + if(mode == nil || mode->UsingIpv6 || mode->Started == 0) + continue; + if(mode->DhcpAckReceived){ + dhcp = (EFI_PXE_BASE_CODE_DHCPV4_PACKET*)mode->DhcpAck; + goto Found; + } + if(mode->PxeReplyReceived){ + dhcp = (EFI_PXE_BASE_CODE_DHCPV4_PACKET*)mode->PxeReply; + goto Found; + } } - dhcp = (EFI_PXE_BASE_CODE_DHCPV4_PACKET*)pxe->Mode->DhcpAck; - - mac = dhcp->BootpHwAddr; - memmove(ini, "/cfg/pxe/", 9); - for(i=0; i<6; i++){ - ini[9+i*2+0] = hex[mac[i] >> 4]; - ini[9+i*2+1] = hex[mac[i] & 0xF]; - } - ini[9+12] = '\0'; + return -1; +Found: open = pxeopen; read = pxeread; close = pxeclose; - if((f = pxeopen(ini)) != nil) - return f; - return pxeopen("/cfg/pxe/default"); + if(pf != nil){ + char ini[24]; + uchar *mac; + + mac = dhcp->BootpHwAddr; + memmove(ini, "/cfg/pxe/", 9); + for(i=0; i<6; i++){ + ini[9+i*2+0] = hex[mac[i] >> 4]; + ini[9+i*2+1] = hex[mac[i] & 0xF]; + } + ini[9+12] = '\0'; + if((*pf = pxeopen(ini)) == nil) + *pf = pxeopen("/cfg/pxe/default"); + } + + return 0; }