blob: 16991ceab6fbe371868b98dc2475fa4fea784713 [file] [log] [blame]
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -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>
37
38static struct ptable flash_ptable;
39
40/* for these partitions, start will be offset by either what we get from
41 * smem, or from the above offset if smem is not useful. Also, we should
42 * probably have smem_ptable code populate our flash_ptable.
43 *
44 * When smem provides us with a full partition table, we can get rid of
45 * this altogether.
46 *
47 */
48static struct ptentry board_part_list[] = {
49 {
50 .start = 0,
51 .length = 40,
52 .name = "boot",
53 },
54 {
55 .start = 56,
56 .length = 608 /* 76MB */,
57 .name = "system",
58 },
59 {
60 .start = 664,
61 .length = 608 /* 76MB */,
62 .name = "cache",
63 },
64 {
65 .start = 1272,
66 .length = 0,
67 .name = "userdata",
68 },
69};
70static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
71
72void smem_ptable_init(void);
73unsigned smem_get_apps_flash_start(void);
74
75void keypad_init(void);
76
77void target_init(void)
78{
79 unsigned offset;
80 struct flash_info *flash_info;
81 int i;
82
83 dprintf(INFO, "target_init()\n");
84
85 keys_init();
86 keypad_init();
87
88 ptable_init(&flash_ptable);
89 smem_ptable_init();
90
91 flash_init();
92 flash_info = flash_get_info();
93 ASSERT(flash_info);
94
95 offset = smem_get_apps_flash_start();
96 if (offset == 0xffffffff)
97 while(1);
98
99 for (i = 0; i < num_parts; i++) {
100 struct ptentry *ptn = &board_part_list[i];
101 unsigned len = ptn->length;
102
103 if ((len == 0) && (i == num_parts - 1))
104 len = flash_info->num_blocks - offset - ptn->start;
105 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
106 len, ptn->flags);
107 }
108
109 ptable_dump(&flash_ptable);
110 flash_set_ptable(&flash_ptable);
111}