1af28f636SEnrico Perla - Sun Microsystems /*
2af28f636SEnrico Perla - Sun Microsystems  * CDDL HEADER START
3af28f636SEnrico Perla - Sun Microsystems  *
4af28f636SEnrico Perla - Sun Microsystems  * The contents of this file are subject to the terms of the
5af28f636SEnrico Perla - Sun Microsystems  * Common Development and Distribution License (the "License").
6af28f636SEnrico Perla - Sun Microsystems  * You may not use this file except in compliance with the License.
7af28f636SEnrico Perla - Sun Microsystems  *
8af28f636SEnrico Perla - Sun Microsystems  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9af28f636SEnrico Perla - Sun Microsystems  * or http://www.opensolaris.org/os/licensing.
10af28f636SEnrico Perla - Sun Microsystems  * See the License for the specific language governing permissions
11af28f636SEnrico Perla - Sun Microsystems  * and limitations under the License.
12af28f636SEnrico Perla - Sun Microsystems  *
13af28f636SEnrico Perla - Sun Microsystems  * When distributing Covered Code, include this CDDL HEADER in each
14af28f636SEnrico Perla - Sun Microsystems  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15af28f636SEnrico Perla - Sun Microsystems  * If applicable, add the following below this CDDL HEADER, with the
16af28f636SEnrico Perla - Sun Microsystems  * fields enclosed by brackets "[]" replaced with your own identifying
17af28f636SEnrico Perla - Sun Microsystems  * information: Portions Copyright [yyyy] [name of copyright owner]
18af28f636SEnrico Perla - Sun Microsystems  *
19af28f636SEnrico Perla - Sun Microsystems  * CDDL HEADER END
20af28f636SEnrico Perla - Sun Microsystems  */
21af28f636SEnrico Perla - Sun Microsystems /*
22af28f636SEnrico Perla - Sun Microsystems  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23*9890706eSHans Rosenfeld  * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
24af28f636SEnrico Perla - Sun Microsystems  */
25af28f636SEnrico Perla - Sun Microsystems 
26af28f636SEnrico Perla - Sun Microsystems #ifndef	_INSTALLGRUB_H
27af28f636SEnrico Perla - Sun Microsystems #define	_INSTALLGRUB_H
28af28f636SEnrico Perla - Sun Microsystems 
29af28f636SEnrico Perla - Sun Microsystems #ifdef	__cplusplus
30af28f636SEnrico Perla - Sun Microsystems extern "C" {
31af28f636SEnrico Perla - Sun Microsystems #endif
32af28f636SEnrico Perla - Sun Microsystems 
33af28f636SEnrico Perla - Sun Microsystems #include <sys/multiboot.h>
34af28f636SEnrico Perla - Sun Microsystems #include "./../common/bblk_einfo.h"
35af28f636SEnrico Perla - Sun Microsystems 
36af28f636SEnrico Perla - Sun Microsystems #define	SECTOR_SIZE	(512)
37af28f636SEnrico Perla - Sun Microsystems 
38af28f636SEnrico Perla - Sun Microsystems typedef struct _device_data {
39af28f636SEnrico Perla - Sun Microsystems 	char		*path;
40af28f636SEnrico Perla - Sun Microsystems 	char		*path_p0;
41af28f636SEnrico Perla - Sun Microsystems 	uint8_t		type;
42af28f636SEnrico Perla - Sun Microsystems 	int		part_fd;
43af28f636SEnrico Perla - Sun Microsystems 	int		disk_fd;
44af28f636SEnrico Perla - Sun Microsystems 	int		slice;
45af28f636SEnrico Perla - Sun Microsystems 	int		partition;
46*9890706eSHans Rosenfeld 	uint64_t	start_sector;
47af28f636SEnrico Perla - Sun Microsystems 	char		boot_sector[SECTOR_SIZE];
48af28f636SEnrico Perla - Sun Microsystems } ig_device_t;
49af28f636SEnrico Perla - Sun Microsystems 
50af28f636SEnrico Perla - Sun Microsystems typedef struct _stage2_data {
51af28f636SEnrico Perla - Sun Microsystems 	char			*buf;
52af28f636SEnrico Perla - Sun Microsystems 	char			*file;
53af28f636SEnrico Perla - Sun Microsystems 	char			*extra;
54af28f636SEnrico Perla - Sun Microsystems 	multiboot_header_t	*mboot;
55af28f636SEnrico Perla - Sun Microsystems 	uint32_t		mboot_off;
56af28f636SEnrico Perla - Sun Microsystems 	uint32_t		file_size;
5714d44f22SHans Rosenfeld 	uint32_t		extra_size;
58af28f636SEnrico Perla - Sun Microsystems 	uint32_t		buf_size;
59af28f636SEnrico Perla - Sun Microsystems 	uint32_t		first_sector;
60af28f636SEnrico Perla - Sun Microsystems 	uint32_t		pcfs_first_sectors[2];
61af28f636SEnrico Perla - Sun Microsystems } ig_stage2_t;
62af28f636SEnrico Perla - Sun Microsystems 
63af28f636SEnrico Perla - Sun Microsystems typedef struct _ig_data {
64af28f636SEnrico Perla - Sun Microsystems 	char		stage1_buf[SECTOR_SIZE];
65af28f636SEnrico Perla - Sun Microsystems 	ig_stage2_t	stage2;
66af28f636SEnrico Perla - Sun Microsystems 	ig_device_t	device;
67af28f636SEnrico Perla - Sun Microsystems } ig_data_t;
68af28f636SEnrico Perla - Sun Microsystems 
69af28f636SEnrico Perla - Sun Microsystems enum ig_devtype_t {
70af28f636SEnrico Perla - Sun Microsystems 	IG_DEV_X86BOOTPAR = 1,
711a902ef8SHans Rosenfeld 	IG_DEV_SOLVTOC,
721a902ef8SHans Rosenfeld 	IG_DEV_EFI
73af28f636SEnrico Perla - Sun Microsystems };
74af28f636SEnrico Perla - Sun Microsystems 
75af28f636SEnrico Perla - Sun Microsystems #define	is_bootpar(type)	(type == IG_DEV_X86BOOTPAR)
761a902ef8SHans Rosenfeld #define	is_efi(type)		(type == IG_DEV_EFI)
77af28f636SEnrico Perla - Sun Microsystems 
78af28f636SEnrico Perla - Sun Microsystems #define	STAGE2_MEMADDR		(0x8000)	/* loading addr of stage2 */
79af28f636SEnrico Perla - Sun Microsystems 
80af28f636SEnrico Perla - Sun Microsystems #define	STAGE1_BPB_OFFSET	(0x3)
81af28f636SEnrico Perla - Sun Microsystems #define	STAGE1_BPB_SIZE		(0x3B)
82af28f636SEnrico Perla - Sun Microsystems #define	STAGE1_BOOT_DRIVE	(0x40)
83af28f636SEnrico Perla - Sun Microsystems #define	STAGE1_FORCE_LBA	(0x41)
84af28f636SEnrico Perla - Sun Microsystems #define	STAGE1_STAGE2_ADDRESS	(0x42)
85af28f636SEnrico Perla - Sun Microsystems #define	STAGE1_STAGE2_SECTOR	(0x44)
86af28f636SEnrico Perla - Sun Microsystems #define	STAGE1_STAGE2_SEGMENT	(0x48)
87af28f636SEnrico Perla - Sun Microsystems 
88af28f636SEnrico Perla - Sun Microsystems #define	STAGE2_BLOCKLIST	(SECTOR_SIZE - 0x8)
89af28f636SEnrico Perla - Sun Microsystems #define	STAGE2_INSTALLPART	(SECTOR_SIZE + 0x8)
90af28f636SEnrico Perla - Sun Microsystems #define	STAGE2_FORCE_LBA	(SECTOR_SIZE + 0x11)
911a902ef8SHans Rosenfeld #define	STAGE2_BLKOFF(type)	\
921a902ef8SHans Rosenfeld 	(is_efi(type) ? 1024 : 50)	/* offset from start of part */
93af28f636SEnrico Perla - Sun Microsystems 
949348d232SHans Rosenfeld /*
959348d232SHans Rosenfeld  * Maximum size of stage2 on EFI-labeled disks. Must not be larger than
969348d232SHans Rosenfeld  * VDEV_BOOT_SIZE, defined in usr/src/uts/common/fs/zfs/sys/vdev_impl.h
979348d232SHans Rosenfeld  */
989348d232SHans Rosenfeld #define	STAGE2_MAXSIZE		(1ULL << 19)
999348d232SHans Rosenfeld 
100af28f636SEnrico Perla - Sun Microsystems #ifdef	__cplusplus
101af28f636SEnrico Perla - Sun Microsystems }
102af28f636SEnrico Perla - Sun Microsystems #endif
103af28f636SEnrico Perla - Sun Microsystems 
104af28f636SEnrico Perla - Sun Microsystems #endif /* _INSTALLGRUB_H */
105