1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Boot Block				File: cfe_bootblock.h
5    *
6    *  The structure of the boot block used on block-style devices
7    *  like disks and CDROMs
8    *
9    *  Author:  Mitch Lichtenberg
10    *
11    *********************************************************************
12    *
13    *  Copyright 2000,2001,2002,2003
14    *  Broadcom Corporation. All rights reserved.
15    *
16    *  This software is furnished under license and may be used and
17    *  copied only in accordance with the following terms and
18    *  conditions.  Subject to these conditions, you may download,
19    *  copy, install, use, modify and distribute modified or unmodified
20    *  copies of this software in source and/or binary form.  No title
21    *  or ownership is transferred hereby.
22    *
23    *  1) Any source code used, modified or distributed must reproduce
24    *     and retain this copyright notice and list of conditions
25    *     as they appear in the source file.
26    *
27    *  2) No right is granted to use any trade name, trademark, or
28    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
29    *     name may not be used to endorse or promote products derived
30    *     from this software without the prior written permission of
31    *     Broadcom Corporation.
32    *
33    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
34    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
35    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
37    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
38    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
39    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
43    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
45    *     THE POSSIBILITY OF SUCH DAMAGE.
46    ********************************************************************* */
47
48
49/*
50 * CFE boot block, modeled loosely on Alpha.
51 *
52 * It consists of:
53 *
54 * 		BSD disk label
55 *		<blank space>
56 *		Boot block info (5 u_int_64s)
57 *
58 * The boot block portion looks like:
59 *
60 *
61 *      +-------+-------+-------+-------+-------+-------+-------+-------+
62 *      |                        BOOT_MAGIC_NUMBER                      |
63 *      +-------+-------+-------+-------+-------+-------+-------+-------+
64 *      | Flags |   Reserved    | Vers  |      Header Checksum          |
65 *      +-------+-------+-------+-------+-------+-------+-------+-------+
66 *      |             Secondary Loader Location (bytes)                 |
67 *      +-------+-------+-------+-------+-------+-------+-------+-------+
68 *      |     Loader Checksum           |     Size of loader (bytes)    |
69 *      +-------+-------+-------+-------+-------+-------+-------+-------+
70 *      |          Reserved             |    Architecture Information   |
71 *      +-------+-------+-------+-------+-------+-------+-------+-------+
72 *
73 * Boot block fields should always be read as 64-bit numbers.
74 *
75 */
76
77
78struct boot_block {
79	uint64_t bb_data[64];		/* data (disklabel, also as below) */
80};
81#define bb_magic	bb_data[59]	/* magic number */
82#define bb_hdrinfo	bb_data[60]	/* header checksum, ver, flags */
83#define bb_secstart	bb_data[61]	/* secondary start (bytes) */
84#define bb_secsize	bb_data[62]	/* secondary size (bytes) */
85#define bb_archinfo	bb_data[63]	/* architecture info */
86
87#define	BOOT_BLOCK_OFFSET	0	/* offset of boot block. */
88#define	BOOT_BLOCK_BLOCKSIZE	512	/* block size for sec. size/start,
89					 * and for boot block itself
90					 */
91#define BOOT_BLOCK_SIZE		40	/* 5 64-bit words */
92
93/*
94 * This is the highest block number that we look at when
95 * searching for a valid boot block
96 */
97#define BOOT_BLOCK_MAXLOC	16
98
99/*
100 * Fields within the boot block
101 */
102#define _U64(x) ((uint64_t) x)
103#define BOOT_MAGIC_NUMBER	_U64(0x43465631424f4f54ULL)
104#define BOOT_HDR_CHECKSUM_MASK	_U64(0x00000000FFFFFFFFULL)
105#define BOOT_HDR_VER_MASK       _U64(0x000000FF00000000ULL)
106#define BOOT_HDR_VER_SHIFT	32
107#define BOOT_HDR_FLAGS_MASK	_U64(0xFF00000000000000ULL)
108#define BOOT_SECSIZE_MASK	_U64(0x00000000FFFFFFFFULL)
109#define BOOT_DATA_CHECKSUM_MASK _U64(0xFFFFFFFF00000000ULL)
110#define BOOT_DATA_CHECKSUM_SHIFT 32
111#define BOOT_ARCHINFO_MASK	_U64(0x00000000FFFFFFFFULL)
112
113#define BOOT_HDR_VERSION	1
114
115#define	CHECKSUM_BOOT_DATA(data,len,cksum)				\
116	do {								\
117		uint32_t *_ptr = (uint32_t *) (data);                   \
118		uint32_t _cksum;					\
119		int _i;							\
120									\
121		_cksum = 0;						\
122		for (_i = 0;						\
123		    _i < ((len) / sizeof (uint32_t));       		\
124		    _i++)						\
125			_cksum += _ptr[_i];				\
126		*(cksum) =  _cksum;					\
127	} while (0)
128
129#define	CHECKSUM_BOOT_DATA_HS(data,len,cksum)				\
130	do {								\
131		hsaddr_t _ptr = (data);                                 \
132		uint32_t _cksum;					\
133		int _i;							\
134									\
135		_cksum = 0;						\
136		for (_i = 0;						\
137		    _i < ((len) / sizeof (uint32_t));       		\
138		    _i++)						\
139			_cksum += hs_read8(_ptr+_i);			\
140		*(cksum) =  _cksum;					\
141	} while (0)
142
143
144