d492aa3cd65d8dd359af98a9fbc01953a814fc3f
[librecmc/librecmc.git] / target / linux / brcm63xx-2.6 / files / arch / mips / bcm963xx / info.c
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2007 OpenWrt.org
5  * Copyright (C) 2007 Gabor Juhos <juhosg@freemail.hu>
6  * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
7  *
8  * This program is free software; you can redistribute  it and/or modify it
9  * under  the terms of  the GNU General  Public License as published by the
10  * Free Software Foundation;  either version 2 of the  License, or (at your
11  * option) any later version.
12  */
13
14 #include <linux/types.h>
15 #include <linux/autoconf.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/module.h>
19
20 #include <asm/bootinfo.h>
21 #include <asm/addrspace.h>
22 #include <asm/string.h>
23 #include <asm/mach-bcm963xx/bootloaders.h>
24
25 static char *boot_loader_names[BOOT_LOADER_LAST+1] = {
26         [BOOT_LOADER_UNKNOWN]   = "Unknown",
27         [BOOT_LOADER_CFE]       = "CFE",
28         [BOOT_LOADER_REDBOOT]   = "RedBoot"
29 };
30
31 /* boot loaders specific definitions */
32 #define CFE_EPTSEAL     0x43464531 /* CFE1 is the magic number to recognize CFE from other bootloaders */
33
34 int boot_loader_type;
35 /*
36  * Boot loader detection routines
37  */
38 static int __init detect_cfe(void)
39 {
40         /*
41          * This method only works, when we are booted directly from the CFE.
42          */
43         uint32_t cfe_handle = (uint32_t) fw_arg0;
44         uint32_t cfe_a1_val = (uint32_t) fw_arg1;
45         uint32_t cfe_entry = (uint32_t) fw_arg2;
46         uint32_t cfe_seal = (uint32_t) fw_arg3;
47
48         /* Check for CFE by finding the CFE magic number */
49         if (cfe_seal != CFE_EPTSEAL)
50                 /* We are not booted from CFE */
51                 return 0;
52
53         /* cfe_a1_val must be 0, because only one CPU present in the ADM5120 SoC */
54         if (cfe_a1_val != 0)
55                 return 0;
56
57         /* The cfe_handle, and the cfe_entry must be kernel mode addresses */
58         if ((cfe_handle < KSEG0) || (cfe_entry < KSEG0))
59                 return 0;
60
61         return 1;
62 }
63
64 static int __init detect_redboot(void)
65 {
66         /* On Inventel Livebox, the boot loader is passed as a command line argument, check for it */
67         if (!strncmp(arcs_cmdline, "boot_loader=RedBoot", 19))
68                 return 1;
69         return 0;
70 }
71
72 void __init detect_bootloader(void)
73 {
74         if (detect_cfe()) {
75                 boot_loader_type = BOOT_LOADER_CFE;
76                 printk("Boot loader is : %s\n", boot_loader_names[boot_loader_type]);
77         }
78
79         if (detect_redboot()) {
80                 boot_loader_type = BOOT_LOADER_REDBOOT;
81         }
82         else
83                 boot_loader_type = BOOT_LOADER_UNKNOWN;
84 }
85
86 EXPORT_SYMBOL(boot_loader_type);