• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/cfe/cfe/arch/mips/cpu/sb1250/src/
1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  SB1250 PCI Device-mode downloader	File: cfe_device_ldr.c
5    *
6    *  This invokes the CFE loader to retrieve an elf binary from the
7    *  PCI host using the host0 device.
8    *
9    *********************************************************************
10    *
11    *  Copyright 2000,2001,2002,2003
12    *  Broadcom Corporation. All rights reserved.
13    *
14    *  This software is furnished under license and may be used and
15    *  copied only in accordance with the following terms and
16    *  conditions.  Subject to these conditions, you may download,
17    *  copy, install, use, modify and distribute modified or unmodified
18    *  copies of this software in source and/or binary form.  No title
19    *  or ownership is transferred hereby.
20    *
21    *  1) Any source code used, modified or distributed must reproduce
22    *     and retain this copyright notice and list of conditions
23    *     as they appear in the source file.
24    *
25    *  2) No right is granted to use any trade name, trademark, or
26    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
27    *     name may not be used to endorse or promote products derived
28    *     from this software without the prior written permission of
29    *     Broadcom Corporation.
30    *
31    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
32    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
33    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
34    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
35    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
36    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
37    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
39    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
40    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
41    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
42    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
43    *     THE POSSIBILITY OF SUCH DAMAGE.
44    ********************************************************************* */
45
46
47#include "sbmips.h"
48#include "lib_types.h"
49#include "lib_printf.h"
50
51#include "cfe_loader.h"
52#include "cfe_timer.h"
53#include "sb1250_defs.h"
54#include "sb1250_regs.h"
55#define K1_PTR64(pa) ((uint64_t *)(PHYS_TO_K1(pa)))
56
57extern cfe_loadargs_t cfe_loadargs;
58
59#define MBOX_ARG_WORD  0
60#define MBOX_CMD_WORD  1
61
62int cfe_device_download(int boot, char *options);
63int
64cfe_device_download(int boot, char *options)
65{
66    cfe_loadargs_t *la = &cfe_loadargs;
67    int res;
68    uint64_t *mbox_p = K1_PTR64 (A_IMR_REG(NULL, ISTER(0, R_IMR_MAILBOX_CPU));
69    uint64_t *mbox_clr = K1_PTR64 (A_IMR_REG(NULL, ISTER(0, R_IMR_MAILBOX_CLR_CPU));
70    uint64_t *mbox_set = K1_PTR64 (A_IMR_REG(NULL, ISTER(0, R_IMR_MAILBOX_SET_CPU));
71    uint32_t *cmd_p = ((uint32_t *)mbox_p) + MBOX_CMD_WORD;
72
73    xprintf("Loader:elf Filesys:raw Dev:host0");
74
75    /* Wait for the host to supply any host-selected options.  There
76       is no timeout here because we don't know the host's timing and,
77       on a real device card, probably wouldn't have anything to do
78       until downloaded. */
79
80    while ((*cmd_p & 0x3) == 0) {
81	POLL();
82	}
83
84    /* Fill out the loadargs */
85
86    la->la_flags = LOADFLG_NOISY;
87
88    la->la_device = "host0";
89    la->la_filesys = "raw";
90    la->la_filename = NULL;
91
92    if ((*cmd_p & 0x2) != 0) la->la_flags |= LOADFLG_COMPRESSED;
93    la->la_options = options;
94
95    xprintf(" Options:%s\n", la->la_options);
96
97    res = cfe_boot("elf", la);
98
99    /* First supply the result code */
100    *((uint32_t *)mbox_clr + MBOX_ARG_WORD) = 0xffffffff;
101    *((uint32_t *)mbox_set + MBOX_ARG_WORD) = (uint32_t)res;
102
103    /* Then the ack (0x0) */
104    *((uint32_t *)mbox_clr + MBOX_CMD_WORD) = 0xffffff;
105
106    if (res < 0) {
107	xprintf("Could not download from %s:\n", la->la_device);
108	return res;
109	}
110
111    if (boot && la->la_entrypt != 0) {
112	cfe_go(la);
113	/* We won't actually return to here */
114	}
115
116    return res;
117}
118