xref: /netbsd/sys/arch/sbmips/include/disklabel.h (revision 6550d01e)
1 /* $NetBSD: disklabel.h,v 1.7 2009/11/23 13:40:11 pooka 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	LABELSECTOR	1		/* sector containing label */
71 #define	LABELOFFSET	0		/* offset of label in sector */
72 #define	MAXPARTITIONS	16
73 #define	RAW_PART	3
74 
75 #ifdef __NetBSD__
76 /* Pull in MBR partition definitions. */
77 #if HAVE_NBTOOL_CONFIG_H
78 #include <nbinclude/sys/bootblock.h>
79 #else
80 #include <sys/bootblock.h>
81 #endif /* HAVE_NBTOOL_CONFIG_H */
82 
83 #ifndef __ASSEMBLER__
84 #if HAVE_NBTOOL_CONFIG_H
85 #include <nbinclude/sys/dkbad.h>
86 #else
87 #include <sys/dkbad.h>
88 #endif /* HAVE_NBTOOL_CONFIG_H */
89 struct cpu_disklabel {
90 	struct mbr_partition dosparts[MBR_PART_COUNT];
91 #define __HAVE_DISKLABEL_DKBAD
92 	struct dkbad bad;
93 };
94 #endif
95 #endif
96 
97 /*
98  * CFE boot block, modeled loosely on Alpha.
99  *
100  * It consists of:
101  *
102  * 		BSD disk label
103  *		<blank space>
104  *		Boot block info (5 uint_64s)
105  *
106  * The boot block portion looks like:
107  *
108  *
109  *	+-------+-------+-------+-------+-------+-------+-------+-------+
110  *	|                        BOOT_MAGIC_NUMBER                      |
111  *	+-------+-------+-------+-------+-------+-------+-------+-------+
112  *	| Flags |   Reserved    | Vers  |      Header Checksum          |
113  *	+-------+-------+-------+-------+-------+-------+-------+-------+
114  *	|             Secondary Loader Location (bytes)                 |
115  *	+-------+-------+-------+-------+-------+-------+-------+-------+
116  *	|     Loader Checksum           |     Size of loader (bytes)    |
117  *	+-------+-------+-------+-------+-------+-------+-------+-------+
118  *	|          Reserved             |    Architecture Information   |
119  *	+-------+-------+-------+-------+-------+-------+-------+-------+
120  *
121  * Boot block fields should always be read as 64-bit numbers.
122  *
123  */
124 
125 
126 struct boot_block {
127 	uint64_t cfe_bb_data[64];	/* data (disklabel, also as below) */
128 };
129 #define	cfe_bb_magic	cfe_bb_data[59]	/* magic number */
130 #define	cfe_bb_hdrinfo	cfe_bb_data[60]	/* header checksum, ver, flags */
131 #define	cfe_bb_secstart	cfe_bb_data[61]	/* secondary start (bytes) */
132 #define	cfe_bb_secsize	cfe_bb_data[62]	/* secondary size (bytes) */
133 #define	cfe_bb_archinfo	cfe_bb_data[63]	/* architecture info */
134 
135 #define	BOOT_BLOCK_OFFSET	0	/* offset of boot block. */
136 #define	BOOT_BLOCK_BLOCKSIZE	512	/* block size for sec. size/start,
137 					 * and for boot block itself
138 					 */
139 #define	BOOT_BLOCK_SIZE		40	/* 5 64-bit words */
140 
141 #define	BOOT_MAGIC_NUMBER	0x43465631424f4f54
142 #define	BOOT_HDR_CHECKSUM_MASK	0x00000000FFFFFFFF
143 #define	BOOT_HDR_VER_MASK	0x000000FF00000000
144 #define	BOOT_HDR_VER_SHIFT	32
145 #define	BOOT_HDR_FLAGS_MASK	0xFF00000000000000
146 #define	BOOT_SECSIZE_MASK	0x00000000FFFFFFFF
147 #define	BOOT_DATA_CHECKSUM_MASK 0xFFFFFFFF00000000
148 #define	BOOT_DATA_CHECKSUM_SHIFT 32
149 #define	BOOT_ARCHINFO_MASK	0x00000000FFFFFFFF
150 
151 #define	BOOT_HDR_VERSION	1
152 
153 #define	CHECKSUM_BOOT_BLOCK(bb,cksum)					\
154 	do {								\
155 		uint32_t *_ptr = (uint32_t *) (bb);			\
156 		uint32_t _cksum;					\
157 		int _i;							\
158 									\
159 		_cksum = 0;						\
160 		for (_i = 0;						\
161 		    _i < (BOOT_BLOCK_SIZE / sizeof (uint32_t));		\
162 		    _i++)						\
163 			_cksum += _ptr[_i];				\
164 		*(cksum) = _cksum;					\
165 	} while (0)
166 
167 
168 #define	CHECKSUM_BOOT_DATA(data,len,cksum)				\
169 	do {								\
170 		uint32_t *_ptr = (uint32_t *) (data);			\
171 		uint32_t _cksum;					\
172 		int _i;							\
173 									\
174 		_cksum = 0;						\
175 		for (_i = 0;						\
176 		    _i < ((len) / sizeof (uint32_t));			\
177 		    _i++)						\
178 			_cksum += _ptr[_i];				\
179 		*(cksum) = _cksum;					\
180 	} while (0)
181 
182 
183 #endif /* _MACHINE_DISKLABEL_H_ */
184