pxe_image.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <pxe.h>
00029 #include <pxe_call.h>
00030 #include <gpxe/uaccess.h>
00031 #include <gpxe/image.h>
00032 #include <gpxe/segment.h>
00033 #include <gpxe/netdevice.h>
00034 #include <gpxe/features.h>
00035
00036 FEATURE ( FEATURE_IMAGE, "PXE", DHCP_EB_FEATURE_PXE, 1 );
00037
00038 struct image_type pxe_image_type __image_type ( PROBE_PXE );
00039
00040
00041
00042
00043
00044
00045
00046 static int pxe_exec ( struct image *image ) {
00047 struct net_device *netdev;
00048 int rc;
00049
00050
00051 if ( ( netdev = last_opened_netdev() ) == NULL ) {
00052 DBGC ( image, "IMAGE %p could not locate PXE net device\n",
00053 image );
00054 return -ENODEV;
00055 }
00056
00057
00058 pxe_activate ( netdev );
00059
00060
00061 rc = pxe_start_nbp();
00062
00063
00064 pxe_deactivate();
00065
00066 return rc;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 int pxe_load ( struct image *image ) {
00076 userptr_t buffer = real_to_user ( 0, 0x7c00 );
00077 size_t filesz = image->len;
00078 size_t memsz = image->len;
00079 int rc;
00080
00081
00082
00083
00084
00085
00086 if ( filesz > ( 0xa0000 - 0x7c00 ) )
00087 return -ENOEXEC;
00088
00089
00090
00091
00092 if ( ! filesz )
00093 return -ENOEXEC;
00094
00095
00096 if ( ! image->type )
00097 image->type = &pxe_image_type;
00098
00099
00100 if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
00101 DBGC ( image, "IMAGE %p could not prepare segment: %s\n",
00102 image, strerror ( rc ) );
00103 return rc;
00104 }
00105
00106
00107 memcpy_user ( buffer, 0, image->data, 0, filesz );
00108
00109 return 0;
00110 }
00111
00112
00113 struct image_type pxe_image_type __image_type ( PROBE_PXE ) = {
00114 .name = "PXE",
00115 .load = pxe_load,
00116 .exec = pxe_exec,
00117 };