blob: 8a57d569025dd426aa9ccd75b9e5d9465fa2eec6 [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>
38
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080039#define LINUX_MACHTYPE 1007014
40
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080041static struct ptable flash_ptable;
42
43/* for these partitions, start will be offset by either what we get from
44 * smem, or from the above offset if smem is not useful. Also, we should
45 * probably have smem_ptable code populate our flash_ptable.
46 *
47 * When smem provides us with a full partition table, we can get rid of
48 * this altogether.
49 *
50 */
51static struct ptentry board_part_list[] = {
52 {
53 .start = 0,
54 .length = 40,
55 .name = "boot",
56 },
57 {
58 .start = 56,
59 .length = 608 /* 76MB */,
60 .name = "system",
61 },
62 {
63 .start = 664,
Chandan Uddaraju56228922009-12-11 21:48:48 -080064 .length = 40 /* 5MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080065 .name = "cache",
66 },
67 {
Chandan Uddaraju56228922009-12-11 21:48:48 -080068 .start = 704,
69 .length = 720 /* 90MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080070 .name = "userdata",
71 },
72};
73static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
74
75void smem_ptable_init(void);
76unsigned smem_get_apps_flash_start(void);
77
78void keypad_init(void);
79
David Ngbf2eb3c2009-12-09 23:48:07 -080080int target_is_emmc_boot(void);
81
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080082void target_init(void)
83{
84 unsigned offset;
85 struct flash_info *flash_info;
86 int i;
87
88 dprintf(INFO, "target_init()\n");
89
Chandan Uddaraju852cd2c2009-12-17 14:28:28 -080090#if (!ENABLE_NANDWRITE)
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080091 keys_init();
92 keypad_init();
Chandan Uddaraju852cd2c2009-12-17 14:28:28 -080093#endif
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080094
David Ngbf2eb3c2009-12-09 23:48:07 -080095 if (target_is_emmc_boot())
96 return;
97
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080098 ptable_init(&flash_ptable);
99 smem_ptable_init();
100
101 flash_init();
102 flash_info = flash_get_info();
103 ASSERT(flash_info);
104
105 offset = smem_get_apps_flash_start();
106 if (offset == 0xffffffff)
107 while(1);
108
109 for (i = 0; i < num_parts; i++) {
110 struct ptentry *ptn = &board_part_list[i];
111 unsigned len = ptn->length;
112
113 if ((len == 0) && (i == num_parts - 1))
114 len = flash_info->num_blocks - offset - ptn->start;
115 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
116 len, ptn->flags);
117 }
118
119 ptable_dump(&flash_ptable);
120 flash_set_ptable(&flash_ptable);
121}
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800122
123unsigned board_machtype(void)
124{
125 return LINUX_MACHTYPE;
126}