• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdint.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <errno.h>
6 #include <gpxe/sanboot.h>
7 #include <int13.h>
8 #include <gpxe/srp.h>
9 #include <gpxe/sbft.h>
10 
11 FILE_LICENCE ( GPL2_OR_LATER );
12 
ib_srpboot(const char * root_path)13 static int ib_srpboot ( const char *root_path ) {
14 	struct scsi_device *scsi;
15 	struct int13_drive *drive;
16 	int rc;
17 
18 	scsi = zalloc ( sizeof ( *scsi ) );
19 	if ( ! scsi ) {
20 		rc = -ENOMEM;
21 		goto err_alloc_scsi;
22 	}
23 	drive = zalloc ( sizeof ( *drive ) );
24 	if ( ! drive ) {
25 		rc = -ENOMEM;
26 		goto err_alloc_drive;
27 	}
28 
29 	if ( ( rc = srp_attach ( scsi, root_path ) ) != 0 ) {
30 		printf ( "Could not attach IB_SRP device: %s\n",
31 			 strerror ( rc ) );
32 		goto err_attach;
33 	}
34 	if ( ( rc = init_scsidev ( scsi ) ) != 0 ) {
35 		printf ( "Could not initialise IB_SRP device: %s\n",
36 			 strerror ( rc ) );
37 		goto err_init;
38 	}
39 
40 	drive->blockdev = &scsi->blockdev;
41 
42 	/* FIXME: ugly, ugly hack */
43 	struct srp_device *srp =
44 		container_of ( scsi->backend, struct srp_device, refcnt );
45 	sbft_fill_data ( srp );
46 
47 	register_int13_drive ( drive );
48 	printf ( "Registered as BIOS drive %#02x\n", drive->drive );
49 	printf ( "Booting from BIOS drive %#02x\n", drive->drive );
50 	rc = int13_boot ( drive->drive );
51 	printf ( "Boot failed\n" );
52 
53 	/* Leave drive registered, if instructed to do so */
54 	if ( keep_san() )
55 		return rc;
56 
57 	printf ( "Unregistering BIOS drive %#02x\n", drive->drive );
58 	unregister_int13_drive ( drive );
59 
60  err_init:
61 	srp_detach ( scsi );
62  err_attach:
63 	free ( drive );
64  err_alloc_drive:
65 	free ( scsi );
66  err_alloc_scsi:
67 	return rc;
68 }
69 
70 struct sanboot_protocol ib_srp_sanboot_protocol __sanboot_protocol = {
71 	.prefix = "ib_srp:",
72 	.boot = ib_srpboot,
73 };
74