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