From a918e110c491cc2cf8c482bf2314b5363b68294b Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Sat, 30 Mar 2002 07:32:08 +0000 Subject: [PATCH] Add a quick and dirty way to determine where we're loaded from. We only care if it's network or not at this time. If we're loaded from the network, we set currdev (=loaddev) so that the kernel is loaded from the network as well. In all other cases we initialize to disk. This makes netbooting more convenient and can easily be enhanced to do more elaborate checking. --- sys/boot/efi/loader/main.c | 36 ++++++++++++++++++++++++++++-------- sys/boot/ia64/efi/main.c | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/sys/boot/efi/loader/main.c b/sys/boot/efi/loader/main.c index 97eea208b6f..553b7fcaa24 100644 --- a/sys/boot/efi/loader/main.c +++ b/sys/boot/efi/loader/main.c @@ -98,10 +98,15 @@ find_pal_proc(void) EFI_STATUS efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) { - int i; + static EFI_GUID imgid = LOADED_IMAGE_PROTOCOL; + static EFI_GUID netid = EFI_SIMPLE_NETWORK_PROTOCOL; EFI_PHYSICAL_ADDRESS mem; + EFI_LOADED_IMAGE *img; + EFI_SIMPLE_NETWORK *net; + EFI_STATUS status; struct ia64_pal_result res; char buf[32]; + int i; efi_init(image_handle, system_table); @@ -145,14 +150,29 @@ efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) printf("Memory: %ld k\n", memsize() / 1024); #endif - /* XXX presumes that biosdisk is first in devsw */ - currdev.d_dev = devsw[0]; + + /* + * XXX quick and dirty check to see if we're loaded from the + * network. If so, we set the default device to 'net'. In all + * other cases we set the default device to 'disk'. We presume + * fixed positions in devsw for both net and disk. + */ + BS->HandleProtocol(image_handle, &imgid, (VOID**)&img); + + status = BS->HandleProtocol(img->DeviceHandle, &netid, (VOID**)&net); + if (status == EFI_SUCCESS && net != NULL) { + currdev.d_dev = devsw[1]; /* XXX net */ + currdev.d_kind.netif.unit = 0; + } else { + currdev.d_dev = devsw[0]; /* XXX disk */ + currdev.d_kind.efidisk.unit = 0; + /* XXX should be able to detect this, default to autoprobe */ + currdev.d_kind.efidisk.slice = -1; + /* default to 'a' */ + currdev.d_kind.efidisk.partition = 0; + } + currdev.d_type = currdev.d_dev->dv_type; - currdev.d_kind.efidisk.unit = 0; - /* XXX should be able to detect this, default to autoprobe */ - currdev.d_kind.efidisk.slice = -1; - /* default to 'a' */ - currdev.d_kind.efidisk.partition = 0; #if 0 /* Create arc-specific variables */ diff --git a/sys/boot/ia64/efi/main.c b/sys/boot/ia64/efi/main.c index 97eea208b6f..553b7fcaa24 100644 --- a/sys/boot/ia64/efi/main.c +++ b/sys/boot/ia64/efi/main.c @@ -98,10 +98,15 @@ find_pal_proc(void) EFI_STATUS efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) { - int i; + static EFI_GUID imgid = LOADED_IMAGE_PROTOCOL; + static EFI_GUID netid = EFI_SIMPLE_NETWORK_PROTOCOL; EFI_PHYSICAL_ADDRESS mem; + EFI_LOADED_IMAGE *img; + EFI_SIMPLE_NETWORK *net; + EFI_STATUS status; struct ia64_pal_result res; char buf[32]; + int i; efi_init(image_handle, system_table); @@ -145,14 +150,29 @@ efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) printf("Memory: %ld k\n", memsize() / 1024); #endif - /* XXX presumes that biosdisk is first in devsw */ - currdev.d_dev = devsw[0]; + + /* + * XXX quick and dirty check to see if we're loaded from the + * network. If so, we set the default device to 'net'. In all + * other cases we set the default device to 'disk'. We presume + * fixed positions in devsw for both net and disk. + */ + BS->HandleProtocol(image_handle, &imgid, (VOID**)&img); + + status = BS->HandleProtocol(img->DeviceHandle, &netid, (VOID**)&net); + if (status == EFI_SUCCESS && net != NULL) { + currdev.d_dev = devsw[1]; /* XXX net */ + currdev.d_kind.netif.unit = 0; + } else { + currdev.d_dev = devsw[0]; /* XXX disk */ + currdev.d_kind.efidisk.unit = 0; + /* XXX should be able to detect this, default to autoprobe */ + currdev.d_kind.efidisk.slice = -1; + /* default to 'a' */ + currdev.d_kind.efidisk.partition = 0; + } + currdev.d_type = currdev.d_dev->dv_type; - currdev.d_kind.efidisk.unit = 0; - /* XXX should be able to detect this, default to autoprobe */ - currdev.d_kind.efidisk.slice = -1; - /* default to 'a' */ - currdev.d_kind.efidisk.partition = 0; #if 0 /* Create arc-specific variables */