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