blob: 7f82e095eefce0eb42a9b43ad11ebc51e8cd522d [file] [log] [blame]
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Ajay Dudani32edd472009-11-25 14:43:14 -08004 * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -08005 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google, Inc. nor the names of its contributors
16 * may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <debug.h>
34#include <dev/keys.h>
35#include <dev/gpio_keypad.h>
36#include <lib/ptable.h>
37#include <dev/flash.h>
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080038#include <smem.h>
39
40#define LINUX_MACHTYPE_SURF 1007016
41#define LINUX_MACHTYPE_FFA 1007017
42#define LINUX_MACHTYPE_FLUID 1007018
43
44//Enum values for 7x30 target platforms.
45enum platform
46{
47 HW_PLATFORM_UNKNOWN = 0,
48 HW_PLATFORM_SURF = 1,
49 HW_PLATFORM_FFA = 2,
50 HW_PLATFORM_FLUID = 3,
51 HW_PLATFORM_32BITS = 0x7FFFFFFF
52};
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080053
54static struct ptable flash_ptable;
55
56/* for these partitions, start will be offset by either what we get from
57 * smem, or from the above offset if smem is not useful. Also, we should
58 * probably have smem_ptable code populate our flash_ptable.
59 *
60 * When smem provides us with a full partition table, we can get rid of
61 * this altogether.
62 *
63 */
64static struct ptentry board_part_list[] = {
65 {
66 .start = 0,
Chandan Uddaraju2e2908f2010-01-12 13:30:59 -080067 .length = 20 /* 5MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080068 .name = "boot",
69 },
70 {
Chandan Uddaraju2e2908f2010-01-12 13:30:59 -080071 .start = 20,
72 .length = 320 /* 80MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080073 .name = "system",
74 },
75 {
Chandan Uddaraju2e2908f2010-01-12 13:30:59 -080076 .start = 340,
77 .length = 20 /* 5MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080078 .name = "cache",
79 },
80 {
Chandan Uddaraju2e2908f2010-01-12 13:30:59 -080081 .start = 360,
82 .length = 400 /* 100MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080083 .name = "userdata",
84 },
85};
86static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
87
88void smem_ptable_init(void);
89unsigned smem_get_apps_flash_start(void);
90
91void keypad_init(void);
92
David Ng183a7422009-12-07 14:55:21 -080093static int emmc_boot = -1; /* set to uninitialized */
94int target_is_emmc_boot(void);
95
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080096void target_init(void)
97{
98 unsigned offset;
99 struct flash_info *flash_info;
100 int i;
101
102 dprintf(INFO, "target_init()\n");
103
Chandan Uddarajua0d26dd2009-12-13 01:04:38 -0800104#if (!ENABLE_NANDWRITE)
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800105 keys_init();
106 keypad_init();
Chandan Uddarajua0d26dd2009-12-13 01:04:38 -0800107#endif
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800108
David Ng183a7422009-12-07 14:55:21 -0800109 if (target_is_emmc_boot())
110 return;
111
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800112 ptable_init(&flash_ptable);
113 smem_ptable_init();
114
115 flash_init();
116 flash_info = flash_get_info();
117 ASSERT(flash_info);
118
119 offset = smem_get_apps_flash_start();
120 if (offset == 0xffffffff)
121 while(1);
122
123 for (i = 0; i < num_parts; i++) {
124 struct ptentry *ptn = &board_part_list[i];
125 unsigned len = ptn->length;
126
127 if ((len == 0) && (i == num_parts - 1))
128 len = flash_info->num_blocks - offset - ptn->start;
129 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
130 len, ptn->flags);
131 }
132
133 ptable_dump(&flash_ptable);
134 flash_set_ptable(&flash_ptable);
135}
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800136
137unsigned board_machtype(void)
138{
139 struct smem_board_info board_info;
140 unsigned int board_info_struct_len = sizeof(board_info);
141 enum platform platform_type = 0;
142 unsigned smem_status;
143
144 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
145 &board_info, board_info_struct_len );
146 if(smem_status)
147 {
148 dprintf(CRITICAL, "ERROR: unable to read shared memory for Hardware Platform\n");
149 }
150
151 if (board_info.format == 3)
152 {
153 platform_type = board_info.hw_platform;
154 switch (platform_type)
155 {
156 case HW_PLATFORM_SURF:
157 return LINUX_MACHTYPE_SURF;
158 case HW_PLATFORM_FFA:
159 return LINUX_MACHTYPE_FFA;
160 case HW_PLATFORM_FLUID:
161 return LINUX_MACHTYPE_FLUID;
162 default:
163 return LINUX_MACHTYPE_SURF;
164 }
165 }
166 return LINUX_MACHTYPE_SURF;
167}
David Ng183a7422009-12-07 14:55:21 -0800168
169int target_is_emmc_boot(void)
170{
171 struct smem_board_info board_info;
172 unsigned int board_info_struct_len = sizeof(board_info);
173 unsigned smem_status;
174
175 if (emmc_boot != -1) return emmc_boot;
176
177 emmc_boot = 0;
178
179 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
180 &board_info, board_info_struct_len );
181 if(!smem_status)
182 {
183 /* Success retrieving build info */
184 if ('S' == *((char *)board_info.build_id + 13))
185 emmc_boot = 1;
186 }
187
188 return emmc_boot;
189}
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800190
191unsigned check_reboot_mode(void)
192{
193 return 0;
194}