[adm5120] fix mac address setup on RouterBOARDs
[openwrt.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
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25 #include <linux/types.h>
26 #include <linux/autoconf.h>
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/string.h>
30 #include <linux/module.h>
31
32 #include <asm/bootinfo.h>
33 #include <asm/addrspace.h>
34
35 #include <adm5120_defs.h>
36 #include <prom/routerboot.h>
37 #include "prom_read.h"
38
39 struct rb_hard_settings rb_hs;
40 static int rb_found;
41
42 static int __init routerboot_load_hs(u8 *buf, u16 buflen)
43 {
44 u16 id, len;
45 u8 *mac;
46 int i, j;
47
48 memset(&rb_hs, 0, sizeof(rb_hs));
49
50 if (buflen < 4)
51 return -1;
52
53 if (prom_read_le32(buf) != RB_MAGIC_HARD)
54 return -1;
55
56 /* skip magic value */
57 buf += 4;
58 buflen -= 4;
59
60 while (buflen > 2) {
61 id = prom_read_le16(buf);
62 buf += 2;
63 buflen -= 2;
64 if (id == RB_ID_TERMINATOR || buflen < 2)
65 break;
66
67 len = prom_read_le16(buf);
68 buf += 2;
69 buflen -= 2;
70
71 if (buflen < len)
72 break;
73
74 switch (id) {
75 case RB_ID_BIOS_VERSION:
76 rb_hs.bios_ver = (char *)buf;
77 break;
78 case RB_ID_BOARD_NAME:
79 rb_hs.name = (char *)buf;
80 break;
81 case RB_ID_MEMORY_SIZE:
82 rb_hs.mem_size = prom_read_le32(buf);
83 break;
84 case RB_ID_MAC_ADDRESS_COUNT:
85 rb_hs.mac_count = prom_read_le32(buf);
86 break;
87 case RB_ID_MAC_ADDRESS_PACK:
88 if ((len / RB_MAC_SIZE) > 0)
89 rb_hs.mac_base = buf;
90 break;
91 }
92
93 buf += len;
94 buflen -= len;
95
96 }
97
98 return 0;
99 }
100
101 #define RB_BS_OFFS 0x14
102 #define RB_OFFS_MAX (128*1024)
103
104 int __init routerboot_present(void)
105 {
106 struct rb_bios_settings *bs;
107 u8 *base;
108 u32 off, len;
109
110 if (rb_found)
111 goto out;
112
113 base = (u8 *)KSEG1ADDR(ADM5120_SRAM0_BASE);
114 bs = (struct rb_bios_settings *)(base + RB_BS_OFFS);
115
116 off = prom_read_le32(&bs->hs_offs);
117 len = prom_read_le32(&bs->hs_size);
118 if (off > RB_OFFS_MAX)
119 goto out;
120
121 if (routerboot_load_hs(base+off, len) != 0)
122 goto out;
123
124 rb_found = 1;
125
126 out:
127 return rb_found;
128 }
129
130 char *routerboot_get_boardname(void)
131 {
132 if (rb_found == 0)
133 return NULL;
134
135 return rb_hs.name;
136 }
This page took 0.06708 seconds and 5 git commands to generate.