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