1*d81ad5bdSmrg /* $NetBSD: disklabel.h,v 1.6 2017/07/24 10:04:09 mrg Exp $ */ 231e40c8cSsimonb 331e40c8cSsimonb /* 431e40c8cSsimonb * Copyright (c) 1994 Christopher G. Demetriou 531e40c8cSsimonb * All rights reserved. 631e40c8cSsimonb * 731e40c8cSsimonb * Redistribution and use in source and binary forms, with or without 831e40c8cSsimonb * modification, are permitted provided that the following conditions 931e40c8cSsimonb * are met: 1031e40c8cSsimonb * 1. Redistributions of source code must retain the above copyright 1131e40c8cSsimonb * notice, this list of conditions and the following disclaimer. 1231e40c8cSsimonb * 2. Redistributions in binary form must reproduce the above copyright 1331e40c8cSsimonb * notice, this list of conditions and the following disclaimer in the 1431e40c8cSsimonb * documentation and/or other materials provided with the distribution. 1531e40c8cSsimonb * 3. All advertising materials mentioning features or use of this software 1631e40c8cSsimonb * must display the following acknowledgement: 1731e40c8cSsimonb * This product includes software developed by Christopher G. Demetriou. 1831e40c8cSsimonb * 4. The name of the author may not be used to endorse or promote products 1931e40c8cSsimonb * derived from this software without specific prior written permission 2031e40c8cSsimonb * 2131e40c8cSsimonb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2231e40c8cSsimonb * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2331e40c8cSsimonb * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2431e40c8cSsimonb * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2531e40c8cSsimonb * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2631e40c8cSsimonb * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2731e40c8cSsimonb * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2831e40c8cSsimonb * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2931e40c8cSsimonb * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3031e40c8cSsimonb * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3131e40c8cSsimonb */ 3231e40c8cSsimonb 33*d81ad5bdSmrg /* 34*d81ad5bdSmrg * Copyright 2000, 2001 35*d81ad5bdSmrg * Broadcom Corporation. All rights reserved. 36*d81ad5bdSmrg * 37*d81ad5bdSmrg * This software is furnished under license and may be used and copied only 38*d81ad5bdSmrg * in accordance with the following terms and conditions. Subject to these 39*d81ad5bdSmrg * conditions, you may download, copy, install, use, modify and distribute 40*d81ad5bdSmrg * modified or unmodified copies of this software in source and/or binary 41*d81ad5bdSmrg * form. No title or ownership is transferred hereby. 42*d81ad5bdSmrg * 43*d81ad5bdSmrg * 1) Any source code used, modified or distributed must reproduce and 44*d81ad5bdSmrg * retain this copyright notice and list of conditions as they appear in 45*d81ad5bdSmrg * the source file. 46*d81ad5bdSmrg * 47*d81ad5bdSmrg * 2) No right is granted to use any trade name, trademark, or logo of 48*d81ad5bdSmrg * Broadcom Corporation. The "Broadcom Corporation" name may not be 49*d81ad5bdSmrg * used to endorse or promote products derived from this software 50*d81ad5bdSmrg * without the prior written permission of Broadcom Corporation. 51*d81ad5bdSmrg * 52*d81ad5bdSmrg * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED 53*d81ad5bdSmrg * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF 54*d81ad5bdSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR 55*d81ad5bdSmrg * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE 56*d81ad5bdSmrg * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE 57*d81ad5bdSmrg * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 58*d81ad5bdSmrg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 59*d81ad5bdSmrg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 60*d81ad5bdSmrg * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 61*d81ad5bdSmrg * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 62*d81ad5bdSmrg * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 63*d81ad5bdSmrg */ 64*d81ad5bdSmrg 6531e40c8cSsimonb #ifndef _EVBMIPS_DISKLABEL_H_ 6631e40c8cSsimonb #define _EVBMIPS_DISKLABEL_H_ 67*d81ad5bdSmrg 68509fd41bSbouyer #ifdef _KERNEL_OPT 69509fd41bSbouyer #include "opt_pmon.h" 70*d81ad5bdSmrg #include "opt_cputype.h" 71509fd41bSbouyer #endif 72*d81ad5bdSmrg 73*d81ad5bdSmrg #ifdef MIPS64_SB1 74*d81ad5bdSmrg 75*d81ad5bdSmrg #define LABELUSESMBR 0 /* no MBR partitionning */ 76*d81ad5bdSmrg #define LABELSECTOR 1 /* sector containing label */ 77*d81ad5bdSmrg #define LABELOFFSET 0 /* offset of label in sector */ 78*d81ad5bdSmrg #define MAXPARTITIONS 16 79*d81ad5bdSmrg #define RAW_PART 3 80*d81ad5bdSmrg 81*d81ad5bdSmrg #ifdef __NetBSD__ 82*d81ad5bdSmrg /* Pull in MBR partition definitions. */ 83*d81ad5bdSmrg #if HAVE_NBTOOL_CONFIG_H 84*d81ad5bdSmrg #include <nbinclude/sys/bootblock.h> 85*d81ad5bdSmrg #else 86*d81ad5bdSmrg #include <sys/bootblock.h> 87*d81ad5bdSmrg #endif /* HAVE_NBTOOL_CONFIG_H */ 88*d81ad5bdSmrg 89*d81ad5bdSmrg #ifndef __ASSEMBLER__ 90*d81ad5bdSmrg #if HAVE_NBTOOL_CONFIG_H 91*d81ad5bdSmrg #include <nbinclude/sys/dkbad.h> 92*d81ad5bdSmrg #else 93*d81ad5bdSmrg #include <sys/dkbad.h> 94*d81ad5bdSmrg #endif /* HAVE_NBTOOL_CONFIG_H */ 95*d81ad5bdSmrg struct cpu_disklabel { 96*d81ad5bdSmrg struct mbr_partition mbrparts[MBR_PART_COUNT]; 97*d81ad5bdSmrg #define __HAVE_DISKLABEL_DKBAD 98*d81ad5bdSmrg struct dkbad bad; 99*d81ad5bdSmrg }; 100*d81ad5bdSmrg #endif 101*d81ad5bdSmrg #endif 102*d81ad5bdSmrg 103*d81ad5bdSmrg /* 104*d81ad5bdSmrg * CFE boot block, modeled loosely on Alpha. 105*d81ad5bdSmrg * 106*d81ad5bdSmrg * It consists of: 107*d81ad5bdSmrg * 108*d81ad5bdSmrg * BSD disk label 109*d81ad5bdSmrg * <blank space> 110*d81ad5bdSmrg * Boot block info (5 uint_64s) 111*d81ad5bdSmrg * 112*d81ad5bdSmrg * The boot block portion looks like: 113*d81ad5bdSmrg * 114*d81ad5bdSmrg * 115*d81ad5bdSmrg * +-------+-------+-------+-------+-------+-------+-------+-------+ 116*d81ad5bdSmrg * | BOOT_MAGIC_NUMBER | 117*d81ad5bdSmrg * +-------+-------+-------+-------+-------+-------+-------+-------+ 118*d81ad5bdSmrg * | Flags | Reserved | Vers | Header Checksum | 119*d81ad5bdSmrg * +-------+-------+-------+-------+-------+-------+-------+-------+ 120*d81ad5bdSmrg * | Secondary Loader Location (bytes) | 121*d81ad5bdSmrg * +-------+-------+-------+-------+-------+-------+-------+-------+ 122*d81ad5bdSmrg * | Loader Checksum | Size of loader (bytes) | 123*d81ad5bdSmrg * +-------+-------+-------+-------+-------+-------+-------+-------+ 124*d81ad5bdSmrg * | Reserved | Architecture Information | 125*d81ad5bdSmrg * +-------+-------+-------+-------+-------+-------+-------+-------+ 126*d81ad5bdSmrg * 127*d81ad5bdSmrg * Boot block fields should always be read as 64-bit numbers. 128*d81ad5bdSmrg * 129*d81ad5bdSmrg */ 130*d81ad5bdSmrg 131*d81ad5bdSmrg 132*d81ad5bdSmrg struct boot_block { 133*d81ad5bdSmrg uint64_t cfe_bb_data[64]; /* data (disklabel, also as below) */ 134*d81ad5bdSmrg }; 135*d81ad5bdSmrg #define cfe_bb_magic cfe_bb_data[59] /* magic number */ 136*d81ad5bdSmrg #define cfe_bb_hdrinfo cfe_bb_data[60] /* header checksum, ver, flags */ 137*d81ad5bdSmrg #define cfe_bb_secstart cfe_bb_data[61] /* secondary start (bytes) */ 138*d81ad5bdSmrg #define cfe_bb_secsize cfe_bb_data[62] /* secondary size (bytes) */ 139*d81ad5bdSmrg #define cfe_bb_archinfo cfe_bb_data[63] /* architecture info */ 140*d81ad5bdSmrg 141*d81ad5bdSmrg #define BOOT_BLOCK_OFFSET 0 /* offset of boot block. */ 142*d81ad5bdSmrg #define BOOT_BLOCK_BLOCKSIZE 512 /* block size for sec. size/start, 143*d81ad5bdSmrg * and for boot block itself 144*d81ad5bdSmrg */ 145*d81ad5bdSmrg #define BOOT_BLOCK_SIZE 40 /* 5 64-bit words */ 146*d81ad5bdSmrg 147*d81ad5bdSmrg #define BOOT_MAGIC_NUMBER 0x43465631424f4f54 148*d81ad5bdSmrg #define BOOT_HDR_CHECKSUM_MASK 0x00000000FFFFFFFF 149*d81ad5bdSmrg #define BOOT_HDR_VER_MASK 0x000000FF00000000 150*d81ad5bdSmrg #define BOOT_HDR_VER_SHIFT 32 151*d81ad5bdSmrg #define BOOT_HDR_FLAGS_MASK 0xFF00000000000000 152*d81ad5bdSmrg #define BOOT_SECSIZE_MASK 0x00000000FFFFFFFF 153*d81ad5bdSmrg #define BOOT_DATA_CHECKSUM_MASK 0xFFFFFFFF00000000 154*d81ad5bdSmrg #define BOOT_DATA_CHECKSUM_SHIFT 32 155*d81ad5bdSmrg #define BOOT_ARCHINFO_MASK 0x00000000FFFFFFFF 156*d81ad5bdSmrg 157*d81ad5bdSmrg #define BOOT_HDR_VERSION 1 158*d81ad5bdSmrg 159*d81ad5bdSmrg #define CHECKSUM_BOOT_BLOCK(bb,cksum) \ 160*d81ad5bdSmrg do { \ 161*d81ad5bdSmrg uint32_t *_ptr = (uint32_t *) (bb); \ 162*d81ad5bdSmrg uint32_t _cksum; \ 163*d81ad5bdSmrg int _i; \ 164*d81ad5bdSmrg \ 165*d81ad5bdSmrg _cksum = 0; \ 166*d81ad5bdSmrg for (_i = 0; \ 167*d81ad5bdSmrg _i < (BOOT_BLOCK_SIZE / sizeof (uint32_t)); \ 168*d81ad5bdSmrg _i++) \ 169*d81ad5bdSmrg _cksum += _ptr[_i]; \ 170*d81ad5bdSmrg *(cksum) = _cksum; \ 171*d81ad5bdSmrg } while (0) 172*d81ad5bdSmrg 173*d81ad5bdSmrg 174*d81ad5bdSmrg #define CHECKSUM_BOOT_DATA(data,len,cksum) \ 175*d81ad5bdSmrg do { \ 176*d81ad5bdSmrg uint32_t *_ptr = (uint32_t *) (data); \ 177*d81ad5bdSmrg uint32_t _cksum; \ 178*d81ad5bdSmrg int _i; \ 179*d81ad5bdSmrg \ 180*d81ad5bdSmrg _cksum = 0; \ 181*d81ad5bdSmrg for (_i = 0; \ 182*d81ad5bdSmrg _i < ((len) / sizeof (uint32_t)); \ 183*d81ad5bdSmrg _i++) \ 184*d81ad5bdSmrg _cksum += _ptr[_i]; \ 185*d81ad5bdSmrg *(cksum) = _cksum; \ 186*d81ad5bdSmrg } while (0) 187*d81ad5bdSmrg 188*d81ad5bdSmrg #else /* MIPS64_SB1 */ 189*d81ad5bdSmrg 190509fd41bSbouyer #ifdef PMON 191509fd41bSbouyer #define LABELUSESMBR 1 /* use MBR partitionning */ 192509fd41bSbouyer #else 193509fd41bSbouyer #define LABELUSESMBR 0 /* no MBR partitionning */ 194509fd41bSbouyer #endif 19531e40c8cSsimonb #define LABELSECTOR 0 /* sector containing label */ 19631e40c8cSsimonb #define LABELOFFSET 64 /* offset of label in sector */ 19731e40c8cSsimonb #define MAXPARTITIONS 16 /* number of partitions */ 19831e40c8cSsimonb #define RAW_PART 2 /* raw partition: xx?c */ 19931e40c8cSsimonb 200a37289dbSdyoung #if HAVE_NBTOOL_CONFIG_H 201a37289dbSdyoung #include <nbinclude/sys/dkbad.h> 202a37289dbSdyoung #else 20331e40c8cSsimonb #include <sys/dkbad.h> 204a37289dbSdyoung #endif /* HAVE_NBTOOL_CONFIG_H */ 20531e40c8cSsimonb 20631e40c8cSsimonb /* Just a dummy */ 20731e40c8cSsimonb struct cpu_disklabel { 20809dbb89bSpooka #define __HAVE_DISKLABEL_DKBAD 20931e40c8cSsimonb struct dkbad bad; /* must have one element. */ 21031e40c8cSsimonb }; 21131e40c8cSsimonb 212*d81ad5bdSmrg #endif /* MIPS64_SB1 */ 213*d81ad5bdSmrg 21431e40c8cSsimonb #endif /* !_EVBMIPS_DISKLABEL_H_ */ 215