ref: fa3e71ab808441aaf5d8cb2318f536089dafea3f
parent: 3bb7ad61aa05fca94fe508914ad5bbf4cf3a86f6
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Oct 23 20:40:09 EDT 2014
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).
--- a/sys/src/boot/efi/efi.c
+++ b/sys/src/boot/efi/efi.c
@@ -266,7 +266,7 @@
*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 @@
void
eficonfig(char **cfg)
{
- screenconf(cfg);
- acpiconf(cfg);
memconf(cfg);
+ acpiconf(cfg);
+ screenconf(cfg);
}
EFI_STATUS
@@ -290,9 +290,9 @@
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);
--- a/sys/src/boot/efi/fns.h
+++ b/sys/src/boot/efi/fns.h
@@ -7,8 +7,8 @@
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);
--- a/sys/src/boot/efi/fs.c
+++ b/sys/src/boot/efi/fs.c
@@ -83,8 +83,8 @@
eficall(((EFI_FILE_PROTOCOL*)f)->Close, f);
}
-void*
-fsinit(void)
+int
+fsinit(void **pf)
{
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
@@ -92,10 +92,10 @@
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;
@@ -102,5 +102,8 @@
close = fsclose;
open = fsopen;
- return fsopen("/plan9.ini");
+ if(pf != nil)
+ *pf = fsopen("/plan9.ini");
+
+ return 0;
}
--- a/sys/src/boot/efi/pxe.c
+++ b/sys/src/boot/efi/pxe.c
@@ -70,6 +70,11 @@
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 @@
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,7 +332,7 @@
Handles = nil;
if(eficall(ST->BootServices->LocateHandleBuffer,
ByProtocol, &EFI_PXE_BASE_CODE_PROTOCOL_GUID, nil, &Count, &Handles))
- return nil;
+ return -1;
for(i=0; i<Count; i++){
pxe = nil;
@@ -336,24 +339,39 @@
if(eficall(ST->BootServices->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;
+ return -1;
- 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';
-
+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;
}