2 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
31 #include <ipxe/image.h>
32 #include <ipxe/features.h>
36 * System Deployment Image (SDI)
38 * Based on the MSDN article "RAM boot using SDI in Windows XP
39 * Embedded with Service Pack 1", available at the time of writing
42 * http://msdn.microsoft.com/en-us/library/ms838543.aspx
45 FEATURE ( FEATURE_IMAGE, "SDI", DHCP_EB_FEATURE_SDI, 1 );
48 * Parse SDI image header
51 * @v sdi SDI header to fill in
52 * @ret rc Return status code
54 static int sdi_parse_header ( struct image *image, struct sdi_header *sdi ) {
57 if ( image->len < sizeof ( *sdi ) ) {
58 DBGC ( image, "SDI %p too short for SDI header\n", image );
63 copy_from_user ( sdi, image->data, 0, sizeof ( *sdi ) );
66 if ( sdi->magic != SDI_MAGIC ) {
67 DBGC ( image, "SDI %p is not an SDI image\n", image );
78 * @ret rc Return status code
80 static int sdi_exec ( struct image *image ) {
81 struct sdi_header sdi;
85 /* Parse image header */
86 if ( ( rc = sdi_parse_header ( image, &sdi ) ) != 0 )
89 /* Check that image is bootable */
90 if ( sdi.boot_size == 0 ) {
91 DBGC ( image, "SDI %p is not bootable\n", image );
94 DBGC ( image, "SDI %p image at %08lx+%08zx\n",
95 image, user_to_phys ( image->data, 0 ), image->len );
96 DBGC ( image, "SDI %p boot code at %08lx+%llx\n", image,
97 user_to_phys ( image->data, sdi.boot_offset ), sdi.boot_size );
100 memcpy_user ( real_to_user ( SDI_BOOT_SEG, SDI_BOOT_OFF ), 0,
101 image->data, sdi.boot_offset, sdi.boot_size );
103 /* Jump to boot code */
104 sdiptr = ( user_to_phys ( image->data, 0 ) | SDI_WTF );
105 __asm__ __volatile__ ( REAL_CODE ( "ljmp %0, %1\n\t" )
106 : : "i" ( SDI_BOOT_SEG ),
107 "i" ( SDI_BOOT_OFF ),
110 /* There is no way for the image to return, since we provide
115 return -ECANCELED; /* -EIMPOSSIBLE */
122 * @ret rc Return status code
124 static int sdi_probe ( struct image *image ) {
125 struct sdi_header sdi;
129 if ( ( rc = sdi_parse_header ( image, &sdi ) ) != 0 )
135 /** SDI image type */
136 struct image_type sdi_image_type __image_type ( PROBE_NORMAL ) = {