xref: /titanic_51/usr/src/cmd/boot/installboot/i386/installboot.h (revision 4c1177a46d4d850e30806d4e27d635527bba8e90)
1*4c1177a4SToomas Soome /*
2*4c1177a4SToomas Soome  * CDDL HEADER START
3*4c1177a4SToomas Soome  *
4*4c1177a4SToomas Soome  * The contents of this file are subject to the terms of the
5*4c1177a4SToomas Soome  * Common Development and Distribution License (the "License").
6*4c1177a4SToomas Soome  * You may not use this file except in compliance with the License.
7*4c1177a4SToomas Soome  *
8*4c1177a4SToomas Soome  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*4c1177a4SToomas Soome  * or http://www.opensolaris.org/os/licensing.
10*4c1177a4SToomas Soome  * See the License for the specific language governing permissions
11*4c1177a4SToomas Soome  * and limitations under the License.
12*4c1177a4SToomas Soome  *
13*4c1177a4SToomas Soome  * When distributing Covered Code, include this CDDL HEADER in each
14*4c1177a4SToomas Soome  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*4c1177a4SToomas Soome  * If applicable, add the following below this CDDL HEADER, with the
16*4c1177a4SToomas Soome  * fields enclosed by brackets "[]" replaced with your own identifying
17*4c1177a4SToomas Soome  * information: Portions Copyright [yyyy] [name of copyright owner]
18*4c1177a4SToomas Soome  *
19*4c1177a4SToomas Soome  * CDDL HEADER END
20*4c1177a4SToomas Soome  */
21*4c1177a4SToomas Soome /*
22*4c1177a4SToomas Soome  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23*4c1177a4SToomas Soome  * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
24*4c1177a4SToomas Soome  * Copyright 2016 Toomas Soome <tsoome@me.com>
25*4c1177a4SToomas Soome  */
26*4c1177a4SToomas Soome 
27*4c1177a4SToomas Soome #ifndef	_INSTALLBOOT_H
28*4c1177a4SToomas Soome #define	_INSTALLBOOT_H
29*4c1177a4SToomas Soome 
30*4c1177a4SToomas Soome #ifdef	__cplusplus
31*4c1177a4SToomas Soome extern "C" {
32*4c1177a4SToomas Soome #endif
33*4c1177a4SToomas Soome 
34*4c1177a4SToomas Soome #include <sys/multiboot.h>
35*4c1177a4SToomas Soome #include <sys/types.h>
36*4c1177a4SToomas Soome 
37*4c1177a4SToomas Soome #define	SECTOR_SIZE	(512)
38*4c1177a4SToomas Soome 
39*4c1177a4SToomas Soome /* partitioning type for device */
40*4c1177a4SToomas Soome enum ig_devtype_t {
41*4c1177a4SToomas Soome 	IG_DEV_VTOC = 0,
42*4c1177a4SToomas Soome 	IG_DEV_MBR,
43*4c1177a4SToomas Soome 	IG_DEV_EFI
44*4c1177a4SToomas Soome };
45*4c1177a4SToomas Soome 
46*4c1177a4SToomas Soome /* file system type */
47*4c1177a4SToomas Soome enum ig_fstype_t {
48*4c1177a4SToomas Soome 	IG_FS_NONE = 0,
49*4c1177a4SToomas Soome 	IG_FS_ZFS,
50*4c1177a4SToomas Soome 	IG_FS_UFS,
51*4c1177a4SToomas Soome 	IG_FS_PCFS
52*4c1177a4SToomas Soome };
53*4c1177a4SToomas Soome 
54*4c1177a4SToomas Soome /* partition info for boot block location. */
55*4c1177a4SToomas Soome struct stage_part {
56*4c1177a4SToomas Soome 	char *path;			/* device name */
57*4c1177a4SToomas Soome 	int fd;				/* open file descriptor */
58*4c1177a4SToomas Soome 	int id;				/* partition/slice number */
59*4c1177a4SToomas Soome 	enum ig_devtype_t devtype;	/* partitioning type */
60*4c1177a4SToomas Soome 	enum ig_fstype_t fstype;	/* none or pcfs */
61*4c1177a4SToomas Soome 	uint64_t start;			/* partition LBA */
62*4c1177a4SToomas Soome 	uint64_t size;			/* partition size */
63*4c1177a4SToomas Soome 	uint64_t offset;		/* block offset */
64*4c1177a4SToomas Soome };
65*4c1177a4SToomas Soome 
66*4c1177a4SToomas Soome /* boot device data */
67*4c1177a4SToomas Soome typedef struct _ib_device {
68*4c1177a4SToomas Soome 	char		*path;			/* whole disk */
69*4c1177a4SToomas Soome 	int		fd;			/* whole disk fd */
70*4c1177a4SToomas Soome 	enum ig_devtype_t devtype;
71*4c1177a4SToomas Soome 	struct stage_part stage;		/* location of boot block */
72*4c1177a4SToomas Soome 	struct stage_part target;		/* target file system */
73*4c1177a4SToomas Soome 	char		mbr[SECTOR_SIZE];
74*4c1177a4SToomas Soome } ib_device_t;
75*4c1177a4SToomas Soome 
76*4c1177a4SToomas Soome /* stage 2 location */
77*4c1177a4SToomas Soome typedef struct _ib_bootblock {
78*4c1177a4SToomas Soome 	char			*buf;
79*4c1177a4SToomas Soome 	char			*file;
80*4c1177a4SToomas Soome 	char			*extra;
81*4c1177a4SToomas Soome 	multiboot_header_t	*mboot;
82*4c1177a4SToomas Soome 	uint32_t		mboot_off;
83*4c1177a4SToomas Soome 	uint32_t		file_size;
84*4c1177a4SToomas Soome 	uint32_t		buf_size;
85*4c1177a4SToomas Soome 	uint32_t		extra_size;
86*4c1177a4SToomas Soome } ib_bootblock_t;
87*4c1177a4SToomas Soome 
88*4c1177a4SToomas Soome typedef struct _ib_data {
89*4c1177a4SToomas Soome 	unsigned char	stage1[SECTOR_SIZE];	/* partition boot block */
90*4c1177a4SToomas Soome 	ib_device_t	device;			/* boot device */
91*4c1177a4SToomas Soome 	ib_bootblock_t	bootblock;		/* stage 2 */
92*4c1177a4SToomas Soome } ib_data_t;
93*4c1177a4SToomas Soome 
94*4c1177a4SToomas Soome #define	BBLK_BLKLIST_OFF	50	/* vtoc/disk boot offset */
95*4c1177a4SToomas Soome #define	BBLK_ZFS_BLK_OFF	1024	/* vdev boot offset */
96*4c1177a4SToomas Soome #define	BBLK_ZFS_BLK_SIZE	(7ULL << 19)	/* vdev max boot size */
97*4c1177a4SToomas Soome 
98*4c1177a4SToomas Soome /* locations of MBR parts, must be reviewd if mbr code is changed */
99*4c1177a4SToomas Soome #define	STAGE1_BPB_OFFSET	(0x3)	/* technically BPB starts at 0xb */
100*4c1177a4SToomas Soome #define	STAGE1_BPB_SIZE		(0x3b)
101*4c1177a4SToomas Soome #define	STAGE1_MBR_VERSION	(0xfa)	/* 2 bytes, not used */
102*4c1177a4SToomas Soome #define	STAGE1_STAGE2_SIZE	(0xfc)	/* 16bits */
103*4c1177a4SToomas Soome #define	STAGE1_STAGE2_LBA	(0xfe)	/* 64bits */
104*4c1177a4SToomas Soome #define	STAGE1_STAGE2_UUID	(0x106)	/* 128bits */
105*4c1177a4SToomas Soome #define	STAGE1_SIG		(0x1b8)	/* 4+2 bytes */
106*4c1177a4SToomas Soome #define	STAGE1_PARTTBL		(0x1be)	/* MBR partition table */
107*4c1177a4SToomas Soome #define	STAGE1_MAGIC		(0x1fe)	/* 0xAA55 */
108*4c1177a4SToomas Soome #ifdef	__cplusplus
109*4c1177a4SToomas Soome }
110*4c1177a4SToomas Soome #endif
111*4c1177a4SToomas Soome 
112*4c1177a4SToomas Soome #endif /* _INSTALLBOOT_H */
113