xref: /netbsd-src/sys/arch/evbmips/include/disklabel.h (revision 63fb367835544b728c8464e97b0665182bcd6de6)
1*63fb3678Smrg /*	$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*63fb3678Smrg /*
34*63fb3678Smrg  * Copyright 2000, 2001
35*63fb3678Smrg  * Broadcom Corporation. All rights reserved.
36*63fb3678Smrg  *
37*63fb3678Smrg  * This software is furnished under license and may be used and copied only
38*63fb3678Smrg  * in accordance with the following terms and conditions.  Subject to these
39*63fb3678Smrg  * conditions, you may download, copy, install, use, modify and distribute
40*63fb3678Smrg  * modified or unmodified copies of this software in source and/or binary
41*63fb3678Smrg  * form. No title or ownership is transferred hereby.
42*63fb3678Smrg  *
43*63fb3678Smrg  * 1) Any source code used, modified or distributed must reproduce and
44*63fb3678Smrg  *    retain this copyright notice and list of conditions as they appear in
45*63fb3678Smrg  *    the source file.
46*63fb3678Smrg  *
47*63fb3678Smrg  * 2) No right is granted to use any trade name, trademark, or logo of
48*63fb3678Smrg  *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
49*63fb3678Smrg  *    used to endorse or promote products derived from this software
50*63fb3678Smrg  *    without the prior written permission of Broadcom Corporation.
51*63fb3678Smrg  *
52*63fb3678Smrg  * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
53*63fb3678Smrg  *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
54*63fb3678Smrg  *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
55*63fb3678Smrg  *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
56*63fb3678Smrg  *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
57*63fb3678Smrg  *    LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
58*63fb3678Smrg  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
59*63fb3678Smrg  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
60*63fb3678Smrg  *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
61*63fb3678Smrg  *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
62*63fb3678Smrg  *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63*63fb3678Smrg  */
64*63fb3678Smrg 
6531e40c8cSsimonb #ifndef _EVBMIPS_DISKLABEL_H_
6631e40c8cSsimonb #define _EVBMIPS_DISKLABEL_H_
67*63fb3678Smrg 
68a47e2eb7Sbouyer #ifdef _KERNEL_OPT
69a47e2eb7Sbouyer #include "opt_pmon.h"
70*63fb3678Smrg #include "opt_cputype.h"
71a47e2eb7Sbouyer #endif
72*63fb3678Smrg 
73*63fb3678Smrg #ifdef MIPS64_SB1
74*63fb3678Smrg 
75*63fb3678Smrg #define LABELUSESMBR	0		/* no MBR partitionning */
76*63fb3678Smrg #define	LABELSECTOR	1		/* sector containing label */
77*63fb3678Smrg #define	LABELOFFSET	0		/* offset of label in sector */
78*63fb3678Smrg #define	MAXPARTITIONS	16
79*63fb3678Smrg #define	RAW_PART	3
80*63fb3678Smrg 
81*63fb3678Smrg #ifdef __NetBSD__
82*63fb3678Smrg /* Pull in MBR partition definitions. */
83*63fb3678Smrg #if HAVE_NBTOOL_CONFIG_H
84*63fb3678Smrg #include <nbinclude/sys/bootblock.h>
85*63fb3678Smrg #else
86*63fb3678Smrg #include <sys/bootblock.h>
87*63fb3678Smrg #endif /* HAVE_NBTOOL_CONFIG_H */
88*63fb3678Smrg 
89*63fb3678Smrg #ifndef __ASSEMBLER__
90*63fb3678Smrg #if HAVE_NBTOOL_CONFIG_H
91*63fb3678Smrg #include <nbinclude/sys/dkbad.h>
92*63fb3678Smrg #else
93*63fb3678Smrg #include <sys/dkbad.h>
94*63fb3678Smrg #endif /* HAVE_NBTOOL_CONFIG_H */
95*63fb3678Smrg struct cpu_disklabel {
96*63fb3678Smrg 	struct mbr_partition mbrparts[MBR_PART_COUNT];
97*63fb3678Smrg #define __HAVE_DISKLABEL_DKBAD
98*63fb3678Smrg 	struct dkbad bad;
99*63fb3678Smrg };
100*63fb3678Smrg #endif
101*63fb3678Smrg #endif
102*63fb3678Smrg 
103*63fb3678Smrg /*
104*63fb3678Smrg  * CFE boot block, modeled loosely on Alpha.
105*63fb3678Smrg  *
106*63fb3678Smrg  * It consists of:
107*63fb3678Smrg  *
108*63fb3678Smrg  * 		BSD disk label
109*63fb3678Smrg  *		<blank space>
110*63fb3678Smrg  *		Boot block info (5 uint_64s)
111*63fb3678Smrg  *
112*63fb3678Smrg  * The boot block portion looks like:
113*63fb3678Smrg  *
114*63fb3678Smrg  *
115*63fb3678Smrg  *	+-------+-------+-------+-------+-------+-------+-------+-------+
116*63fb3678Smrg  *	|                        BOOT_MAGIC_NUMBER                      |
117*63fb3678Smrg  *	+-------+-------+-------+-------+-------+-------+-------+-------+
118*63fb3678Smrg  *	| Flags |   Reserved    | Vers  |      Header Checksum          |
119*63fb3678Smrg  *	+-------+-------+-------+-------+-------+-------+-------+-------+
120*63fb3678Smrg  *	|             Secondary Loader Location (bytes)                 |
121*63fb3678Smrg  *	+-------+-------+-------+-------+-------+-------+-------+-------+
122*63fb3678Smrg  *	|     Loader Checksum           |     Size of loader (bytes)    |
123*63fb3678Smrg  *	+-------+-------+-------+-------+-------+-------+-------+-------+
124*63fb3678Smrg  *	|          Reserved             |    Architecture Information   |
125*63fb3678Smrg  *	+-------+-------+-------+-------+-------+-------+-------+-------+
126*63fb3678Smrg  *
127*63fb3678Smrg  * Boot block fields should always be read as 64-bit numbers.
128*63fb3678Smrg  *
129*63fb3678Smrg  */
130*63fb3678Smrg 
131*63fb3678Smrg 
132*63fb3678Smrg struct boot_block {
133*63fb3678Smrg 	uint64_t cfe_bb_data[64];	/* data (disklabel, also as below) */
134*63fb3678Smrg };
135*63fb3678Smrg #define	cfe_bb_magic	cfe_bb_data[59]	/* magic number */
136*63fb3678Smrg #define	cfe_bb_hdrinfo	cfe_bb_data[60]	/* header checksum, ver, flags */
137*63fb3678Smrg #define	cfe_bb_secstart	cfe_bb_data[61]	/* secondary start (bytes) */
138*63fb3678Smrg #define	cfe_bb_secsize	cfe_bb_data[62]	/* secondary size (bytes) */
139*63fb3678Smrg #define	cfe_bb_archinfo	cfe_bb_data[63]	/* architecture info */
140*63fb3678Smrg 
141*63fb3678Smrg #define	BOOT_BLOCK_OFFSET	0	/* offset of boot block. */
142*63fb3678Smrg #define	BOOT_BLOCK_BLOCKSIZE	512	/* block size for sec. size/start,
143*63fb3678Smrg 					 * and for boot block itself
144*63fb3678Smrg 					 */
145*63fb3678Smrg #define	BOOT_BLOCK_SIZE		40	/* 5 64-bit words */
146*63fb3678Smrg 
147*63fb3678Smrg #define	BOOT_MAGIC_NUMBER	0x43465631424f4f54
148*63fb3678Smrg #define	BOOT_HDR_CHECKSUM_MASK	0x00000000FFFFFFFF
149*63fb3678Smrg #define	BOOT_HDR_VER_MASK	0x000000FF00000000
150*63fb3678Smrg #define	BOOT_HDR_VER_SHIFT	32
151*63fb3678Smrg #define	BOOT_HDR_FLAGS_MASK	0xFF00000000000000
152*63fb3678Smrg #define	BOOT_SECSIZE_MASK	0x00000000FFFFFFFF
153*63fb3678Smrg #define	BOOT_DATA_CHECKSUM_MASK 0xFFFFFFFF00000000
154*63fb3678Smrg #define	BOOT_DATA_CHECKSUM_SHIFT 32
155*63fb3678Smrg #define	BOOT_ARCHINFO_MASK	0x00000000FFFFFFFF
156*63fb3678Smrg 
157*63fb3678Smrg #define	BOOT_HDR_VERSION	1
158*63fb3678Smrg 
159*63fb3678Smrg #define	CHECKSUM_BOOT_BLOCK(bb,cksum)					\
160*63fb3678Smrg 	do {								\
161*63fb3678Smrg 		uint32_t *_ptr = (uint32_t *) (bb);			\
162*63fb3678Smrg 		uint32_t _cksum;					\
163*63fb3678Smrg 		int _i;							\
164*63fb3678Smrg 									\
165*63fb3678Smrg 		_cksum = 0;						\
166*63fb3678Smrg 		for (_i = 0;						\
167*63fb3678Smrg 		    _i < (BOOT_BLOCK_SIZE / sizeof (uint32_t));		\
168*63fb3678Smrg 		    _i++)						\
169*63fb3678Smrg 			_cksum += _ptr[_i];				\
170*63fb3678Smrg 		*(cksum) = _cksum;					\
171*63fb3678Smrg 	} while (0)
172*63fb3678Smrg 
173*63fb3678Smrg 
174*63fb3678Smrg #define	CHECKSUM_BOOT_DATA(data,len,cksum)				\
175*63fb3678Smrg 	do {								\
176*63fb3678Smrg 		uint32_t *_ptr = (uint32_t *) (data);			\
177*63fb3678Smrg 		uint32_t _cksum;					\
178*63fb3678Smrg 		int _i;							\
179*63fb3678Smrg 									\
180*63fb3678Smrg 		_cksum = 0;						\
181*63fb3678Smrg 		for (_i = 0;						\
182*63fb3678Smrg 		    _i < ((len) / sizeof (uint32_t));			\
183*63fb3678Smrg 		    _i++)						\
184*63fb3678Smrg 			_cksum += _ptr[_i];				\
185*63fb3678Smrg 		*(cksum) = _cksum;					\
186*63fb3678Smrg 	} while (0)
187*63fb3678Smrg 
188*63fb3678Smrg #else /* MIPS64_SB1 */
189*63fb3678Smrg 
190a47e2eb7Sbouyer #ifdef PMON
191a47e2eb7Sbouyer #define LABELUSESMBR	1			/* use MBR partitionning */
192a47e2eb7Sbouyer #else
193a47e2eb7Sbouyer #define LABELUSESMBR	0			/* no MBR partitionning */
194a47e2eb7Sbouyer #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*63fb3678Smrg #endif /* MIPS64_SB1 */
213*63fb3678Smrg 
21431e40c8cSsimonb #endif	/* !_EVBMIPS_DISKLABEL_H_ */
215