10c946d80SToomas Soome /* 20c946d80SToomas Soome * CDDL HEADER START 30c946d80SToomas Soome * 40c946d80SToomas Soome * The contents of this file are subject to the terms of the 50c946d80SToomas Soome * Common Development and Distribution License (the "License"). 60c946d80SToomas Soome * You may not use this file except in compliance with the License. 70c946d80SToomas Soome * 80c946d80SToomas Soome * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90c946d80SToomas Soome * or http://www.opensolaris.org/os/licensing. 100c946d80SToomas Soome * See the License for the specific language governing permissions 110c946d80SToomas Soome * and limitations under the License. 120c946d80SToomas Soome * 130c946d80SToomas Soome * When distributing Covered Code, include this CDDL HEADER in each 140c946d80SToomas Soome * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150c946d80SToomas Soome * If applicable, add the following below this CDDL HEADER, with the 160c946d80SToomas Soome * fields enclosed by brackets "[]" replaced with your own identifying 170c946d80SToomas Soome * information: Portions Copyright [yyyy] [name of copyright owner] 180c946d80SToomas Soome * 190c946d80SToomas Soome * CDDL HEADER END 200c946d80SToomas Soome */ 210c946d80SToomas Soome /* 220c946d80SToomas Soome * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 230c946d80SToomas Soome * Copyright 2012 Nexenta Systems, Inc. All rights reserved. 240c946d80SToomas Soome * Copyright 2016 Toomas Soome <tsoome@me.com> 250c946d80SToomas Soome */ 260c946d80SToomas Soome 270c946d80SToomas Soome #ifndef _INSTALLBOOT_H 280c946d80SToomas Soome #define _INSTALLBOOT_H 290c946d80SToomas Soome 300c946d80SToomas Soome #ifdef __cplusplus 310c946d80SToomas Soome extern "C" { 320c946d80SToomas Soome #endif 330c946d80SToomas Soome 34*d7802caeSToomas Soome #include <stdbool.h> 350c946d80SToomas Soome #include <sys/multiboot.h> 360c946d80SToomas Soome #include <sys/types.h> 37*d7802caeSToomas Soome #include <sys/queue.h> 380c946d80SToomas Soome 390c946d80SToomas Soome #define SECTOR_SIZE (512) 400c946d80SToomas Soome 410c946d80SToomas Soome /* partitioning type for device */ 42*d7802caeSToomas Soome typedef enum ib_devtype { 43*d7802caeSToomas Soome IB_DEV_UNKNOWN = 0, 44*d7802caeSToomas Soome IB_DEV_VTOC, 45*d7802caeSToomas Soome IB_DEV_MBR, 46*d7802caeSToomas Soome IB_DEV_EFI 47*d7802caeSToomas Soome } ib_devtype_t; 480c946d80SToomas Soome 490c946d80SToomas Soome /* file system type */ 50*d7802caeSToomas Soome typedef enum ib_fstype { 51*d7802caeSToomas Soome IB_FS_NONE = 0, 52*d7802caeSToomas Soome IB_FS_ZFS, 53*d7802caeSToomas Soome IB_FS_UFS, 54*d7802caeSToomas Soome IB_FS_PCFS 55*d7802caeSToomas Soome } ib_fstype_t; 56*d7802caeSToomas Soome 57*d7802caeSToomas Soome /* boot block type */ 58*d7802caeSToomas Soome typedef enum ib_bblktype { 59*d7802caeSToomas Soome IB_BBLK_FILE, 60*d7802caeSToomas Soome IB_BBLK_MBR, /* MBR/PMBR */ 61*d7802caeSToomas Soome IB_BBLK_STAGE1, /* BIOS stage 1 */ 62*d7802caeSToomas Soome IB_BBLK_STAGE2, /* BIOS stage 2 */ 63*d7802caeSToomas Soome IB_BBLK_EFI /* EFI Boot Program */ 64*d7802caeSToomas Soome } ib_bblktype_t; 650c946d80SToomas Soome 660c946d80SToomas Soome /* partition info for boot block location. */ 670c946d80SToomas Soome struct stage_part { 680c946d80SToomas Soome char *path; /* device name */ 69*d7802caeSToomas Soome char *mntpnt; /* mountpoint for stage fs */ 700c946d80SToomas Soome int id; /* partition/slice number */ 71*d7802caeSToomas Soome ib_devtype_t devtype; /* partitioning type */ 72*d7802caeSToomas Soome ib_fstype_t fstype; 73*d7802caeSToomas Soome uint16_t tag; /* partition tag */ 740c946d80SToomas Soome uint64_t start; /* partition LBA */ 750c946d80SToomas Soome uint64_t size; /* partition size */ 760c946d80SToomas Soome uint64_t offset; /* block offset */ 770c946d80SToomas Soome }; 780c946d80SToomas Soome 790c946d80SToomas Soome /* boot device data */ 800c946d80SToomas Soome typedef struct _ib_device { 81*d7802caeSToomas Soome ib_devtype_t devtype; 820c946d80SToomas Soome struct stage_part stage; /* location of boot block */ 830c946d80SToomas Soome struct stage_part target; /* target file system */ 840c946d80SToomas Soome } ib_device_t; 850c946d80SToomas Soome 860c946d80SToomas Soome /* stage 2 location */ 870c946d80SToomas Soome typedef struct _ib_bootblock { 880c946d80SToomas Soome char *buf; 890c946d80SToomas Soome char *file; 900c946d80SToomas Soome char *extra; 910c946d80SToomas Soome multiboot_header_t *mboot; 920c946d80SToomas Soome uint32_t mboot_off; 930c946d80SToomas Soome uint32_t file_size; 940c946d80SToomas Soome uint32_t buf_size; 950c946d80SToomas Soome uint32_t extra_size; 960c946d80SToomas Soome } ib_bootblock_t; 970c946d80SToomas Soome 98*d7802caeSToomas Soome struct partlist; 99*d7802caeSToomas Soome 100*d7802caeSToomas Soome struct part_cb { 101*d7802caeSToomas Soome bool (*read)(struct partlist *); 102*d7802caeSToomas Soome bool (*read_bbl)(struct partlist *); 103*d7802caeSToomas Soome bool (*compare)(struct partlist *); 104*d7802caeSToomas Soome void (*install)(void *, struct partlist *); 105*d7802caeSToomas Soome void (*print)(struct partlist *); 106*d7802caeSToomas Soome }; 107*d7802caeSToomas Soome 108*d7802caeSToomas Soome struct partlist { 109*d7802caeSToomas Soome char *pl_devname; 110*d7802caeSToomas Soome ib_device_t *pl_device; 111*d7802caeSToomas Soome 112*d7802caeSToomas Soome /* boot block type */ 113*d7802caeSToomas Soome ib_bblktype_t pl_type; 114*d7802caeSToomas Soome /* stage from target disk, either stage1 or stage2 */ 115*d7802caeSToomas Soome void *pl_stage; 116*d7802caeSToomas Soome /* name of the source file */ 117*d7802caeSToomas Soome const char *pl_src_name; 118*d7802caeSToomas Soome /* stage data from source file. */ 119*d7802caeSToomas Soome void *pl_src_data; 120*d7802caeSToomas Soome struct part_cb pl_cb; 121*d7802caeSToomas Soome STAILQ_ENTRY(partlist) pl_next; 122*d7802caeSToomas Soome }; 123*d7802caeSToomas Soome 124*d7802caeSToomas Soome typedef STAILQ_HEAD(part_list, partlist) part_list_t; 125*d7802caeSToomas Soome 1260c946d80SToomas Soome typedef struct _ib_data { 1270c946d80SToomas Soome ib_device_t device; /* boot device */ 1280c946d80SToomas Soome ib_bootblock_t bootblock; /* stage 2 */ 129*d7802caeSToomas Soome struct stage_part target; /* target file system */ 130*d7802caeSToomas Soome part_list_t *plist; /* boot blocks */ 1310c946d80SToomas Soome } ib_data_t; 1320c946d80SToomas Soome 1330c946d80SToomas Soome #define BBLK_BLKLIST_OFF 50 /* vtoc/disk boot offset */ 1340c946d80SToomas Soome #define BBLK_ZFS_BLK_OFF 1024 /* vdev boot offset */ 1350c946d80SToomas Soome #define BBLK_ZFS_BLK_SIZE (7ULL << 19) /* vdev max boot size */ 1360c946d80SToomas Soome 1370c946d80SToomas Soome /* locations of MBR parts, must be reviewd if mbr code is changed */ 1380c946d80SToomas Soome #define STAGE1_BPB_OFFSET (0x3) /* technically BPB starts at 0xb */ 1390c946d80SToomas Soome #define STAGE1_BPB_SIZE (0x3b) 1400c946d80SToomas Soome #define STAGE1_MBR_VERSION (0xfa) /* 2 bytes, not used */ 1410c946d80SToomas Soome #define STAGE1_STAGE2_SIZE (0xfc) /* 16bits */ 1420c946d80SToomas Soome #define STAGE1_STAGE2_LBA (0xfe) /* 64bits */ 1430c946d80SToomas Soome #define STAGE1_STAGE2_UUID (0x106) /* 128bits */ 1440c946d80SToomas Soome #define STAGE1_SIG (0x1b8) /* 4+2 bytes */ 1450c946d80SToomas Soome #define STAGE1_PARTTBL (0x1be) /* MBR partition table */ 1460c946d80SToomas Soome #define STAGE1_MAGIC (0x1fe) /* 0xAA55 */ 1470c946d80SToomas Soome #ifdef __cplusplus 1480c946d80SToomas Soome } 1490c946d80SToomas Soome #endif 1500c946d80SToomas Soome 1510c946d80SToomas Soome #endif /* _INSTALLBOOT_H */ 152