xref: /illumos-gate/usr/src/cmd/boot/installboot/i386/installboot.h (revision fa4a3e77edc40df6d92e8da6fc4961d275e9896d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
24  * Copyright 2016 Toomas Soome <tsoome@me.com>
25  */
26 
27 #ifndef	_INSTALLBOOT_H
28 #define	_INSTALLBOOT_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <stdbool.h>
35 #include <sys/multiboot.h>
36 #include <sys/types.h>
37 #include <sys/queue.h>
38 
39 #define	SECTOR_SIZE	(512)
40 
41 /* partitioning type for device */
42 typedef enum ib_devtype {
43 	IB_DEV_UNKNOWN = 0,
44 	IB_DEV_VTOC,
45 	IB_DEV_MBR,
46 	IB_DEV_EFI
47 } ib_devtype_t;
48 
49 /* file system type */
50 typedef enum ib_fstype {
51 	IB_FS_NONE = 0,
52 	IB_FS_ZFS,
53 	IB_FS_UFS,
54 	IB_FS_PCFS
55 } ib_fstype_t;
56 
57 /* boot block type */
58 typedef enum ib_bblktype {
59 	IB_BBLK_FILE,
60 	IB_BBLK_MBR,		/* MBR/PMBR */
61 	IB_BBLK_STAGE1,		/* BIOS stage 1 */
62 	IB_BBLK_STAGE2,		/* BIOS stage 2 */
63 	IB_BBLK_EFI		/* EFI Boot Program */
64 } ib_bblktype_t;
65 
66 /* partition info for boot block location. */
67 struct stage_part {
68 	char *path;			/* device name */
69 	char *mntpnt;			/* mountpoint for stage fs */
70 	int id;				/* partition/slice number */
71 	ib_devtype_t devtype;		/* partitioning type */
72 	ib_fstype_t fstype;
73 	uint16_t tag;			/* partition tag */
74 	uint64_t start;			/* partition LBA */
75 	uint64_t size;			/* partition size */
76 	uint64_t offset;		/* block offset */
77 };
78 
79 /* boot device data */
80 typedef struct _ib_device {
81 	ib_devtype_t devtype;
82 	struct stage_part stage;		/* location of boot block */
83 	struct stage_part target;		/* target file system */
84 } ib_device_t;
85 
86 /* stage 2 location */
87 typedef struct _ib_bootblock {
88 	char			*buf;
89 	char			*file;
90 	char			*extra;
91 	multiboot_header_t	*mboot;
92 	uint32_t		mboot_off;
93 	uint32_t		file_size;
94 	uint32_t		buf_size;
95 	uint32_t		extra_size;
96 } ib_bootblock_t;
97 
98 struct partlist;
99 
100 struct part_cb {
101 	bool (*read)(struct partlist *);
102 	bool (*read_bbl)(struct partlist *);
103 	bool (*compare)(struct partlist *);
104 	void (*install)(void *, struct partlist *);
105 	void (*print)(struct partlist *);
106 };
107 
108 struct partlist {
109 	char			*pl_devname;
110 	ib_device_t		*pl_device;
111 
112 	/* boot block type */
113 	ib_bblktype_t		pl_type;
114 	/* stage from target disk, either stage1 or stage2 */
115 	void			*pl_stage;
116 	/* name of the source file */
117 	const char		*pl_src_name;
118 	/* stage data from source file. */
119 	void			*pl_src_data;
120 	struct part_cb		pl_cb;
121 	STAILQ_ENTRY(partlist)	pl_next;
122 };
123 
124 typedef STAILQ_HEAD(part_list, partlist) part_list_t;
125 
126 typedef struct _ib_data {
127 	ib_device_t	device;			/* boot device */
128 	ib_bootblock_t	bootblock;		/* stage 2 */
129 	struct stage_part target;		/* target file system */
130 	part_list_t	*plist;			/* boot blocks */
131 } ib_data_t;
132 
133 #define	BBLK_BLKLIST_OFF	50	/* vtoc/disk boot offset */
134 #define	BBLK_ZFS_BLK_OFF	1024	/* vdev boot offset */
135 #define	BBLK_ZFS_BLK_SIZE	(7ULL << 19)	/* vdev max boot size */
136 
137 /* locations of MBR parts, must be reviewd if mbr code is changed */
138 #define	STAGE1_BPB_OFFSET	(0x3)	/* technically BPB starts at 0xb */
139 #define	STAGE1_BPB_SIZE		(0x3b)
140 #define	STAGE1_MBR_VERSION	(0xfa)	/* 2 bytes, not used */
141 #define	STAGE1_STAGE2_SIZE	(0xfc)	/* 16bits */
142 #define	STAGE1_STAGE2_LBA	(0xfe)	/* 64bits */
143 #define	STAGE1_STAGE2_UUID	(0x106)	/* 128bits */
144 #define	STAGE1_SIG		(0x1b8)	/* 4+2 bytes */
145 #define	STAGE1_PARTTBL		(0x1be)	/* MBR partition table */
146 #define	STAGE1_MAGIC		(0x1fe)	/* 0xAA55 */
147 #ifdef	__cplusplus
148 }
149 #endif
150 
151 #endif /* _INSTALLBOOT_H */
152