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 <sys/multiboot.h>
  35 #include <sys/types.h>
  36 
  37 #define SECTOR_SIZE     (512)
  38 
  39 /* partitioning type for device */
  40 enum ig_devtype_t {
  41         IG_DEV_VTOC = 0,
  42         IG_DEV_MBR,
  43         IG_DEV_EFI
  44 };
  45 
  46 /* file system type */
  47 enum ig_fstype_t {
  48         IG_FS_NONE = 0,
  49         IG_FS_ZFS,
  50         IG_FS_UFS,
  51         IG_FS_PCFS
  52 };
  53 
  54 /* partition info for boot block location. */
  55 struct stage_part {
  56         char *path;                     /* device name */
  57         int fd;                         /* open file descriptor */
  58         int id;                         /* partition/slice number */
  59         enum ig_devtype_t devtype;      /* partitioning type */
  60         enum ig_fstype_t fstype;        /* none or pcfs */
  61         uint64_t start;                 /* partition LBA */
  62         uint64_t size;                  /* partition size */
  63         uint64_t offset;                /* block offset */
  64 };
  65 
  66 /* boot device data */
  67 typedef struct _ib_device {
  68         char            *path;                  /* whole disk */
  69         int             fd;                     /* whole disk fd */
  70         enum ig_devtype_t devtype;
  71         struct stage_part stage;                /* location of bios bootblock */
  72         struct stage_part system;               /* system partition */
  73         struct stage_part target;               /* target file system */
  74         char            mbr[SECTOR_SIZE];
  75 } ib_device_t;
  76 
  77 /* stage 2 location */
  78 typedef struct _ib_bootblock {
  79         char                    *buf;
  80         char                    *file;
  81         char                    *extra;
  82         multiboot_header_t      *mboot;
  83         uint32_t                mboot_off;
  84         uint32_t                file_size;
  85         uint32_t                buf_size;
  86         uint32_t                extra_size;
  87 } ib_bootblock_t;
  88 
  89 typedef struct _ib_data {
  90         unsigned char   stage1[SECTOR_SIZE];    /* partition boot block */
  91         ib_device_t     device;                 /* boot device */
  92         ib_bootblock_t  bootblock;              /* bios stage 2 */
  93         ib_bootblock_t  efiblock;               /* UEFI boot program */
  94 } ib_data_t;
  95 
  96 #define BBLK_BLKLIST_OFF        50      /* vtoc/disk boot offset */
  97 #define BBLK_ZFS_BLK_OFF        1024    /* vdev boot offset */
  98 #define BBLK_ZFS_BLK_SIZE       (7ULL << 19)      /* vdev max boot size */
  99 
 100 /* locations of MBR parts, must be reviewd if mbr code is changed */
 101 #define STAGE1_BPB_OFFSET       (0x3)   /* technically BPB starts at 0xb */
 102 #define STAGE1_BPB_SIZE         (0x3b)
 103 #define STAGE1_MBR_VERSION      (0xfa)  /* 2 bytes, not used */
 104 #define STAGE1_STAGE2_SIZE      (0xfc)  /* 16bits */
 105 #define STAGE1_STAGE2_LBA       (0xfe)  /* 64bits */
 106 #define STAGE1_STAGE2_UUID      (0x106) /* 128bits */
 107 #define STAGE1_SIG              (0x1b8) /* 4+2 bytes */
 108 #define STAGE1_PARTTBL          (0x1be) /* MBR partition table */
 109 #define STAGE1_MAGIC            (0x1fe) /* 0xAA55 */
 110 #ifdef  __cplusplus
 111 }
 112 #endif
 113 
 114 #endif /* _INSTALLBOOT_H */