[pxe] Provide PXENV_FILE_EXIT_HOOK only for ipxelinux.0 builds

PXENV_FILE_EXIT_HOOK is designed to allow ipxelinux.0 to unload both
the iPXE and pxelinux components without affecting the underlying PXE
stack.  Unfortunately, it causes unexpected behaviour in other
situations, such as when loading a non-embedded pxelinux.0 via
undionly.kpxe.  For example:

  PXE ROM -> undionly.kpxe -> pxelinux.0 -> chain.c32 to boot hd0

would cause control to return to iPXE instead of booting from the hard
disk.  In some cases, this would result in a harmless but confusing
"No more network devices" message; in other cases stranger things
would happen, such as being returned to the iPXE shell prompt.

The fundamental problem is that when pxelinux detects
PXENV_FILE_EXIT_HOOK, it may attempt to specify an exit hook and then
exit back to iPXE, assuming that iPXE will in turn exit cleanly via
the specified exit hook.  This is not a valid assumption in the
general case, since the action of exiting back to iPXE does not
directly cause iPXE to exit itself.  (In the specific case of
ipxelinux.0, this will work since the embedded script exits as soon as
pxelinux.0 exits.)

Fix the unexpected behaviour in the non-ipxelinux.0 cases by including
support for PXENV_FILE_EXIT_HOOK only when using a new .kkkpxe format.
The ipxelinux.0 build process should therefore now use undionly.kkkpxe
instead of undionly.kkpxe.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2011-12-11 02:11:45 +00:00
parent fa410e0a41
commit 9a93db3f09
6 changed files with 120 additions and 55 deletions

View File

@@ -0,0 +1,19 @@
/*****************************************************************************
* PXE prefix that keeps the whole PXE stack present and provides an exit hook
*
* This prefix is essentially intended solely for the case of ipxelinux.0
*****************************************************************************
*/
FILE_LICENCE ( GPL2_OR_LATER )
/* Since we have the whole stack, we can use cached DHCP information */
REQUIRE_OBJECT ( pxeparent_dhcp )
/* Provide the PXENV_FILE_EXIT_HOOK API call */
REQUIRE_OBJECT ( pxe_exit_hook )
#define PXELOADER_KEEP_UNDI
#define PXELOADER_KEEP_PXE
#define _pxe_start _kkkpxe_start
#include "pxeprefix.S"

View File

@@ -721,11 +721,7 @@ run_ipxe:
.section ".text16", "ax", @progbits
1:
/* Update the exit hook */
movw %cs,pxe_exit_hook+2
push %ax
mov $2f,%ax
mov %ax,pxe_exit_hook
pop %ax
movw %cs, ( pxe_exit_hook + 2 )
/* Run main program */
pushl $main
@@ -743,7 +739,14 @@ run_ipxe:
/* Jump to hook if applicable */
ljmpw *pxe_exit_hook
2: /* Check PXE stack magic */
.section ".data16", "aw", @progbits
.globl pxe_exit_hook
pxe_exit_hook:
.word exit_ipxe, 0
.previous
exit_ipxe:
/* Check PXE stack magic */
popl %eax
cmpl $STACK_MAGIC, %eax
jne 1f