Root/target/linux/adm5120/files/arch/mips/adm5120/prom/routerboot.c

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

Archive Download this file



interactive