xref: /netbsd-src/sys/arch/sbmips/include/disklabel.h (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /* $NetBSD: disklabel.h,v 1.6 2005/12/11 12:18:51 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	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 	struct dkbad bad;
92 };
93 #endif
94 #endif
95 
96 /*
97  * CFE boot block, modeled loosely on Alpha.
98  *
99  * It consists of:
100  *
101  * 		BSD disk label
102  *		<blank space>
103  *		Boot block info (5 uint_64s)
104  *
105  * The boot block portion looks like:
106  *
107  *
108  *	+-------+-------+-------+-------+-------+-------+-------+-------+
109  *	|                        BOOT_MAGIC_NUMBER                      |
110  *	+-------+-------+-------+-------+-------+-------+-------+-------+
111  *	| Flags |   Reserved    | Vers  |      Header Checksum          |
112  *	+-------+-------+-------+-------+-------+-------+-------+-------+
113  *	|             Secondary Loader Location (bytes)                 |
114  *	+-------+-------+-------+-------+-------+-------+-------+-------+
115  *	|     Loader Checksum           |     Size of loader (bytes)    |
116  *	+-------+-------+-------+-------+-------+-------+-------+-------+
117  *	|          Reserved             |    Architecture Information   |
118  *	+-------+-------+-------+-------+-------+-------+-------+-------+
119  *
120  * Boot block fields should always be read as 64-bit numbers.
121  *
122  */
123 
124 
125 struct boot_block {
126 	uint64_t cfe_bb_data[64];	/* data (disklabel, also as below) */
127 };
128 #define	cfe_bb_magic	cfe_bb_data[59]	/* magic number */
129 #define	cfe_bb_hdrinfo	cfe_bb_data[60]	/* header checksum, ver, flags */
130 #define	cfe_bb_secstart	cfe_bb_data[61]	/* secondary start (bytes) */
131 #define	cfe_bb_secsize	cfe_bb_data[62]	/* secondary size (bytes) */
132 #define	cfe_bb_archinfo	cfe_bb_data[63]	/* architecture info */
133 
134 #define	BOOT_BLOCK_OFFSET	0	/* offset of boot block. */
135 #define	BOOT_BLOCK_BLOCKSIZE	512	/* block size for sec. size/start,
136 					 * and for boot block itself
137 					 */
138 #define	BOOT_BLOCK_SIZE		40	/* 5 64-bit words */
139 
140 #define	BOOT_MAGIC_NUMBER	0x43465631424f4f54
141 #define	BOOT_HDR_CHECKSUM_MASK	0x00000000FFFFFFFF
142 #define	BOOT_HDR_VER_MASK	0x000000FF00000000
143 #define	BOOT_HDR_VER_SHIFT	32
144 #define	BOOT_HDR_FLAGS_MASK	0xFF00000000000000
145 #define	BOOT_SECSIZE_MASK	0x00000000FFFFFFFF
146 #define	BOOT_DATA_CHECKSUM_MASK 0xFFFFFFFF00000000
147 #define	BOOT_DATA_CHECKSUM_SHIFT 32
148 #define	BOOT_ARCHINFO_MASK	0x00000000FFFFFFFF
149 
150 #define	BOOT_HDR_VERSION	1
151 
152 #define	CHECKSUM_BOOT_BLOCK(bb,cksum)					\
153 	do {								\
154 		uint32_t *_ptr = (uint32_t *) (bb);			\
155 		uint32_t _cksum;					\
156 		int _i;							\
157 									\
158 		_cksum = 0;						\
159 		for (_i = 0;						\
160 		    _i < (BOOT_BLOCK_SIZE / sizeof (uint32_t));		\
161 		    _i++)						\
162 			_cksum += _ptr[_i];				\
163 		*(cksum) = _cksum;					\
164 	} while (0)
165 
166 
167 #define	CHECKSUM_BOOT_DATA(data,len,cksum)				\
168 	do {								\
169 		uint32_t *_ptr = (uint32_t *) (data);			\
170 		uint32_t _cksum;					\
171 		int _i;							\
172 									\
173 		_cksum = 0;						\
174 		for (_i = 0;						\
175 		    _i < ((len) / sizeof (uint32_t));			\
176 		    _i++)						\
177 			_cksum += _ptr[_i];				\
178 		*(cksum) = _cksum;					\
179 	} while (0)
180 
181 
182 #endif /* _MACHINE_DISKLABEL_H_ */
183