1 /***********************license start***************
2  * Copyright (c) 2003-2010  Cavium Inc. ([email protected]). All rights
3  * reserved.
4  *
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *   * Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer.
12  *
13  *   * Redistributions in binary form must reproduce the above
14  *     copyright notice, this list of conditions and the following
15  *     disclaimer in the documentation and/or other materials provided
16  *     with the distribution.
17 
18  *   * Neither the name of Cavium Inc. nor the names of
19  *     its contributors may be used to endorse or promote products
20  *     derived from this software without specific prior written
21  *     permission.
22 
23  * This Software, including technical data, may be subject to U.S. export  control
24  * laws, including the U.S. Export Administration Act and its  associated
25  * regulations, and may be subject to export or import  regulations in other
26  * countries.
27 
28  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29  * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30  * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31  * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32  * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33  * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34  * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35  * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36  * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
37  * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38  ***********************license end**************************************/
39 
40 
41 
42 
43 #ifndef __CVMX_BOOTLOADER__
44 #define __CVMX_BOOTLOADER__
45 
46 
47 
48 /**
49  * @file
50  *
51  * Bootloader definitions that are shared with other programs
52  *
53  * <hr>$Revision: 70030 $<hr>
54  */
55 
56 
57 /* The bootloader_header_t structure defines the header that is present
58 ** at the start of binary u-boot images.  This header is used to locate the bootloader
59 ** image in NAND, and also to allow verification of images for normal NOR booting.
60 ** This structure is placed at the beginning of a bootloader binary image, and remains
61 ** in the executable code.
62 */
63 #define BOOTLOADER_HEADER_MAGIC 0x424f4f54  /* "BOOT" in ASCII */
64 
65 #define BOOTLOADER_HEADER_COMMENT_LEN  64
66 #define BOOTLOADER_HEADER_VERSION_LEN  64
67 #define BOOTLOADER_HEADER_MAX_SIZE      0x200 /* limited by the space to the next exception handler */
68 
69 #define BOOTLOADER_HEADER_CURRENT_MAJOR_REV 1
70 #define BOOTLOADER_HEADER_CURRENT_MINOR_REV 2
71 /* Revision history
72 * 1.1  Initial released revision. (SDK 1.9)
73 * 1.2  TLB based relocatable image (SDK 2.0)
74 *
75 *
76 */
77 
78 /* offsets to struct bootloader_header fields for assembly use */
79 #define GOT_ADDRESS_OFFSET       48
80 
81 #define LOOKUP_STEP (64*1024)
82 
83 #ifndef __ASSEMBLY__
84 typedef struct bootloader_header
85 {
86     uint32_t    jump_instr; /* Jump to executable code following the
87                             ** header.  This allows this header to
88                             ** be (and remain) part of the executable image)
89                             */
90     uint32_t    nop_instr;  /* Must be 0x0 */
91     uint32_t    magic; /* Magic number to identify header */
92     uint32_t    hcrc;  /* CRC of all of header excluding this field */
93 
94     uint16_t    hlen;  /* Length of header in bytes */
95     uint16_t    maj_rev;  /* Major revision */
96     uint16_t    min_rev;  /* Minor revision */
97     uint16_t    board_type;  /* Board type that the image is for */
98 
99     uint32_t    dlen;  /* Length of data (immediately following header) in bytes */
100     uint32_t    dcrc;  /* CRC of data */
101     uint64_t    address;  /* Mips virtual address */
102     uint32_t    flags;
103     uint16_t    image_type;  /* Defined in bootloader_image_t enum */
104     uint16_t    resv0;       /* pad */
105 
106     uint32_t    reserved1;
107     uint32_t    reserved2;
108     uint32_t    reserved3;
109     uint32_t    reserved4;
110 
111     char        comment_string[BOOTLOADER_HEADER_COMMENT_LEN];  /* Optional, for descriptive purposes */
112     char        version_string[BOOTLOADER_HEADER_VERSION_LEN];  /* Optional, for descriptive purposes */
113 } __attribute__((packed)) bootloader_header_t;
114 
115 
116 
117 /* Defines for flag field */
118 #define BL_HEADER_FLAG_FAILSAFE         (1)
119 
120 
121 typedef enum
122 {
123     BL_HEADER_IMAGE_UNKNOWN = 0x0,
124     BL_HEADER_IMAGE_STAGE2,  /* Binary bootloader stage2 image (NAND boot) */
125     BL_HEADER_IMAGE_STAGE3,  /* Binary bootloader stage3 image (NAND boot)*/
126     BL_HEADER_IMAGE_NOR,     /* Binary bootloader for NOR boot */
127     BL_HEADER_IMAGE_PCIBOOT,     /* Binary bootloader for PCI boot */
128     BL_HEADER_IMAGE_UBOOT_ENV,  /* Environment for u-boot */
129     BL_HEADER_IMAGE_MAX,
130     /* Range for customer private use.  Will not be used by Cavium Inc. */
131     BL_HEADER_IMAGE_CUST_RESERVED_MIN = 0x1000,
132     BL_HEADER_IMAGE_CUST_RESERVED_MAX = 0x1fff
133 } bootloader_image_t;
134 
135 #endif /* __ASSEMBLY__ */
136 
137 /* Maximum address searched for NAND boot images and environments.  This is used
138 ** by stage1 and stage2. */
139 #define MAX_NAND_SEARCH_ADDR   0x400000
140 
141 /* Maximum address to look for start of normal bootloader */
142 #define MAX_NOR_SEARCH_ADDR   0x200000
143 
144 /* Defines for RAM based environment set by the host or the previous bootloader
145 ** in a chain boot configuration. */
146 
147 #define U_BOOT_RAM_ENV_ADDR     (0x1000)
148 #define U_BOOT_RAM_ENV_SIZE     (0x1000)
149 #define U_BOOT_RAM_ENV_CRC_SIZE (0x4)
150 #define U_BOOT_RAM_ENV_ADDR_2	(U_BOOT_RAM_ENV_ADDR + U_BOOT_RAM_ENV_SIZE)
151 
152 #endif /* __CVMX_BOOTLOADER__ */
153