Revert r12510. Remove -rpath-link form TARGET_LDFLAGS as it breaks some
[openwrt/svn-archive/archive.git] / target / linux / adm5120 / files / arch / mips / adm5120 / prom / routerboot.c
1 /*
2 * $Id$
3 *
4 * Mikrotik's RouterBOOT specific prom routines
5 *
6 * Copyright (C) 2007 OpenWrt.org
7 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 *
13 */
14
15 #include <linux/types.h>
16 #include <linux/autoconf.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/string.h>
20 #include <linux/module.h>
21
22 #include <asm/bootinfo.h>
23 #include <asm/addrspace.h>
24
25 #include <adm5120_defs.h>
26 #include <prom/routerboot.h>
27 #include "prom_read.h"
28
29 struct rb_hard_settings rb_hs;
30 static int rb_found;
31
32 static int __init routerboot_load_hs(u8 *buf, u16 buflen)
33 {
34 u16 id, len;
35
36 memset(&rb_hs, 0, sizeof(rb_hs));
37
38 if (buflen < 4)
39 return -1;
40
41 if (prom_read_le32(buf) != RB_MAGIC_HARD)
42 return -1;
43
44 /* skip magic value */
45 buf += 4;
46 buflen -= 4;
47
48 while (buflen > 2) {
49 id = prom_read_le16(buf);
50 buf += 2;
51 buflen -= 2;
52 if (id == RB_ID_TERMINATOR || buflen < 2)
53 break;
54
55 len = prom_read_le16(buf);
56 buf += 2;
57 buflen -= 2;
58
59 if (buflen < len)
60 break;
61
62 switch (id) {
63 case RB_ID_BIOS_VERSION:
64 rb_hs.bios_ver = (char *)buf;
65 break;
66 case RB_ID_BOARD_NAME:
67 rb_hs.name = (char *)buf;
68 break;
69 case RB_ID_MEMORY_SIZE:
70 rb_hs.mem_size = prom_read_le32(buf);
71 break;
72 case RB_ID_MAC_ADDRESS_COUNT:
73 rb_hs.mac_count = prom_read_le32(buf);
74 break;
75 case RB_ID_MAC_ADDRESS_PACK:
76 if ((len / RB_MAC_SIZE) > 0)
77 rb_hs.mac_base = buf;
78 break;
79 }
80
81 buf += len;
82 buflen -= len;
83
84 }
85
86 return 0;
87 }
88
89 #define RB_BS_OFFS 0x14
90 #define RB_OFFS_MAX (128*1024)
91
92 int __init routerboot_present(void)
93 {
94 struct rb_bios_settings *bs;
95 u8 *base;
96 u32 off, len;
97
98 if (rb_found)
99 goto out;
100
101 base = (u8 *)KSEG1ADDR(ADM5120_SRAM0_BASE);
102 bs = (struct rb_bios_settings *)(base + RB_BS_OFFS);
103
104 off = prom_read_le32(&bs->hs_offs);
105 len = prom_read_le32(&bs->hs_size);
106 if (off > RB_OFFS_MAX)
107 goto out;
108
109 if (routerboot_load_hs(base+off, len) != 0)
110 goto out;
111
112 rb_found = 1;
113
114 out:
115 return rb_found;
116 }
117
118 char *routerboot_get_boardname(void)
119 {
120 if (rb_found == 0)
121 return NULL;
122
123 return rb_hs.name;
124 }