blob: 8e01a08a0022d9e7b5e4e8459b651bd96454ef21 [file] [log] [blame]
Dima Zavind0850132009-01-26 20:02:33 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google, Inc. nor the names of its contributors
15 * may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <debug.h>
33#include <dev/keys.h>
34#include <dev/gpio_keypad.h>
35#include <lib/ptable.h>
36#include <dev/flash.h>
Greg Griscod6250552011-06-29 14:40:23 -070037#include <platform.h>
Dima Zavind0850132009-01-26 20:02:33 -080038
39#define BOARD_FLASH_OFFSET 378
40
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080041#define LINUX_MACHTYPE 0x0000059F
42
Dima Zavind0850132009-01-26 20:02:33 -080043static struct ptable flash_ptable;
44
45/* for these partitions, start will be offset by either what we get from
46 * smem, or from the above offset if smem is not useful. Also, we should
47 * probably have smem_ptable code populate our flash_ptable.
48 *
49 * When smem provides us with a full partition table, we can get rid of
50 * this altogether.
51 *
52 */
53static struct ptentry board_part_list[] = {
54 {
55 .start = 0,
Dima Zavind0850132009-01-26 20:02:33 -080056 .length = 40,
57 .name = "boot",
58 },
59 {
Dima Zavin1cf23632009-03-02 17:24:59 -080060 .start = 56,
Dima Zavind0850132009-01-26 20:02:33 -080061 .length = 608 /* 76MB */,
62 .name = "system",
63 },
64 {
Dima Zavin1cf23632009-03-02 17:24:59 -080065 .start = 664,
66 .length = 608 /* 76MB */,
67 .name = "cache",
Dima Zavind0850132009-01-26 20:02:33 -080068 },
69 {
Dima Zavin1cf23632009-03-02 17:24:59 -080070 .start = 1272,
71 .length = 0,
72 .name = "userdata",
Dima Zavind0850132009-01-26 20:02:33 -080073 },
74};
Dima Zavin1cf23632009-03-02 17:24:59 -080075static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
Dima Zavind0850132009-01-26 20:02:33 -080076
77void smem_ptable_init(void);
78unsigned smem_get_apps_flash_start(void);
79
80void keypad_init(void);
81
82void target_init(void)
83{
Dima Zavind0850132009-01-26 20:02:33 -080084 unsigned offset;
Dima Zavin1cf23632009-03-02 17:24:59 -080085 struct flash_info *flash_info;
86 int i;
Dima Zavind0850132009-01-26 20:02:33 -080087
88 dprintf(INFO, "target_init()\n");
89
90 keys_init();
91 keypad_init();
92
93 ptable_init(&flash_ptable);
94 smem_ptable_init();
95
Dima Zavine5f64352009-03-02 16:04:20 -080096 flash_init();
Dima Zavin1cf23632009-03-02 17:24:59 -080097 flash_info = flash_get_info();
98 ASSERT(flash_info);
Dima Zavine5f64352009-03-02 16:04:20 -080099
Dima Zavind0850132009-01-26 20:02:33 -0800100 offset = smem_get_apps_flash_start();
101 if (offset == 0xffffffff)
102 offset = BOARD_FLASH_OFFSET;
103
Dima Zavin1cf23632009-03-02 17:24:59 -0800104 for (i = 0; i < num_parts; i++) {
105 struct ptentry *ptn = &board_part_list[i];
106 unsigned len = ptn->length;
107
108 if ((len == 0) && (i == num_parts - 1))
109 len = flash_info->num_blocks - offset - ptn->start;
Dima Zavind0850132009-01-26 20:02:33 -0800110 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
Dima Zavin1cf23632009-03-02 17:24:59 -0800111 len, ptn->flags);
Dima Zavind0850132009-01-26 20:02:33 -0800112 }
113
114 ptable_dump(&flash_ptable);
Dima Zavine5f64352009-03-02 16:04:20 -0800115 flash_set_ptable(&flash_ptable);
Dima Zavind0850132009-01-26 20:02:33 -0800116}
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800117
118unsigned board_machtype(void)
119{
120 return LINUX_MACHTYPE;
121}