2007-09-05 10:53:07 +00:00
|
|
|
/*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2012-04-27 09:32:24 +00:00
|
|
|
#include <io.h>
|
2009-10-22 12:21:25 +00:00
|
|
|
#include <mach/netx-regs.h>
|
2007-09-05 10:53:07 +00:00
|
|
|
#include "eth_firmware.h"
|
|
|
|
|
|
|
|
struct fw_header {
|
2007-09-13 14:06:02 +00:00
|
|
|
unsigned int magic;
|
|
|
|
unsigned int type;
|
|
|
|
unsigned int version;
|
2007-09-05 10:53:07 +00:00
|
|
|
unsigned int table_size;
|
2007-09-13 14:06:02 +00:00
|
|
|
unsigned int reserved[4];
|
2007-09-05 10:53:07 +00:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
static int xc_check_ptr(int xcno, unsigned long adr, unsigned int size)
|
|
|
|
{
|
2012-04-20 13:06:12 +00:00
|
|
|
if (adr >= NETX_PA_XMAC(xcno) &&
|
2007-09-05 10:53:07 +00:00
|
|
|
adr + size < NETX_PA_XMAC(xcno) + XMAC_MEM_SIZE)
|
|
|
|
return 0;
|
|
|
|
|
2012-04-20 13:06:12 +00:00
|
|
|
if (adr >= NETX_PA_XPEC(xcno) &&
|
2007-09-05 10:53:07 +00:00
|
|
|
adr + size < NETX_PA_XPEC(xcno) + XPEC_MEM_SIZE)
|
|
|
|
return 0;
|
|
|
|
|
2011-01-07 10:37:02 +00:00
|
|
|
printf("%s: illegal pointer 0x%08lx\n", __func__ ,adr);
|
2007-09-05 10:53:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-04-27 09:32:24 +00:00
|
|
|
static int xc_patch(int xcno, const u32 *patch, int count)
|
2007-09-05 10:53:07 +00:00
|
|
|
{
|
2012-04-27 09:32:23 +00:00
|
|
|
unsigned int adr, val;
|
2007-09-05 10:53:07 +00:00
|
|
|
|
2007-09-13 14:06:02 +00:00
|
|
|
int i;
|
2012-04-20 13:06:12 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2012-04-27 09:32:24 +00:00
|
|
|
adr = *patch++;
|
|
|
|
val = *patch++;
|
2012-04-20 13:06:12 +00:00
|
|
|
if (xc_check_ptr(xcno, adr, 1) < 0)
|
2007-09-05 10:53:07 +00:00
|
|
|
return -1;
|
2012-04-27 09:32:24 +00:00
|
|
|
writel(val, adr);
|
2007-09-13 14:06:02 +00:00
|
|
|
}
|
2007-09-05 10:53:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void memset32(void *s, int c, int n)
|
|
|
|
{
|
|
|
|
int i;
|
2012-04-20 13:06:13 +00:00
|
|
|
u32 *t = s;
|
2007-09-05 10:53:07 +00:00
|
|
|
|
2012-04-20 13:06:12 +00:00
|
|
|
for (i = 0; i < (n >> 2); i++)
|
2007-09-05 10:53:07 +00:00
|
|
|
*t++ = 0;
|
|
|
|
}
|
|
|
|
|
2012-04-27 09:32:23 +00:00
|
|
|
static void memcpy32(void *trg, const void *src, int size)
|
2007-09-05 10:53:07 +00:00
|
|
|
{
|
|
|
|
int i;
|
2012-04-20 13:06:13 +00:00
|
|
|
u32 *t = trg;
|
2012-04-27 09:32:23 +00:00
|
|
|
const u32 *s = src;
|
2012-04-20 13:06:12 +00:00
|
|
|
for (i = 0; i < (size >> 2); i++)
|
2007-09-05 10:53:07 +00:00
|
|
|
*t++ = *s++;
|
|
|
|
}
|
|
|
|
|
2012-04-20 13:06:12 +00:00
|
|
|
int loadxc(int xcno)
|
|
|
|
{
|
2007-09-05 10:53:07 +00:00
|
|
|
/* stop xmac / xpec */
|
|
|
|
XMAC_REG(xcno, XMAC_RPU_HOLD_PC) = RPU_HOLD_PC;
|
|
|
|
XMAC_REG(xcno, XMAC_TPU_HOLD_PC) = TPU_HOLD_PC;
|
|
|
|
XPEC_REG(xcno, XPEC_XPU_HOLD_PC) = XPU_HOLD_PC;
|
|
|
|
|
|
|
|
XPEC_REG(xcno, XPEC_PC) = 0;
|
|
|
|
|
|
|
|
/* load firmware */
|
|
|
|
memset32((void*)NETX_PA_XPEC(xcno) + XPEC_RAM_START, 0, 0x2000);
|
|
|
|
memset32((void*)NETX_PA_XMAC(xcno), 0, 0x800);
|
|
|
|
|
2009-12-15 08:11:09 +00:00
|
|
|
/* can't use barebox memcpy here, we need 32bit accesses */
|
2012-04-20 13:06:12 +00:00
|
|
|
if (xcno == 0) {
|
2007-09-05 10:53:07 +00:00
|
|
|
memcpy32((void*)(NETX_PA_XMAC(xcno) + XMAC_RPU_PROGRAM_START), rpu_eth0, sizeof(rpu_eth0));
|
|
|
|
memcpy32((void*)(NETX_PA_XMAC(xcno) + XMAC_TPU_PROGRAM_START), tpu_eth0, sizeof(tpu_eth0));
|
|
|
|
memcpy32((void*)NETX_PA_XPEC(xcno) + XPEC_RAM_START, xpec_eth0_mac, sizeof(xpec_eth0_mac));
|
|
|
|
xc_patch(xcno, rpu_eth0_patch, ARRAY_SIZE(rpu_eth0_patch) >> 1);
|
|
|
|
xc_patch(xcno, tpu_eth0_patch, ARRAY_SIZE(tpu_eth0_patch) >> 1);
|
|
|
|
xc_patch(xcno, xpec_eth0_mac_patch, ARRAY_SIZE(xpec_eth0_mac_patch) >> 1);
|
|
|
|
} else {
|
|
|
|
memcpy32((void*)(NETX_PA_XMAC(xcno) + XMAC_RPU_PROGRAM_START), rpu_eth1, sizeof(rpu_eth1));
|
|
|
|
memcpy32((void*)(NETX_PA_XMAC(xcno) + XMAC_TPU_PROGRAM_START), tpu_eth1, sizeof(tpu_eth1));
|
|
|
|
memcpy32((void*)NETX_PA_XPEC(xcno) + XPEC_RAM_START, xpec_eth1_mac, sizeof(xpec_eth1_mac));
|
|
|
|
xc_patch(xcno, rpu_eth1_patch, ARRAY_SIZE(rpu_eth1_patch) >> 1);
|
|
|
|
xc_patch(xcno, tpu_eth1_patch, ARRAY_SIZE(tpu_eth1_patch) >> 1);
|
|
|
|
xc_patch(xcno, xpec_eth1_mac_patch, ARRAY_SIZE(xpec_eth1_mac_patch) >> 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start xmac / xpec */
|
|
|
|
XPEC_REG(xcno, XPEC_XPU_HOLD_PC) = 0;
|
|
|
|
XMAC_REG(xcno, XMAC_TPU_HOLD_PC) = 0;
|
|
|
|
XMAC_REG(xcno, XMAC_RPU_HOLD_PC) = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-21 13:18:57 +00:00
|
|
|
int do_loadxc(int argc, char *argv[])
|
2007-09-05 10:53:07 +00:00
|
|
|
{
|
|
|
|
int xcno;
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
xcno = simple_strtoul(argv[1], NULL, 16);
|
|
|
|
|
|
|
|
printf("loading xc%d\n",xcno);
|
|
|
|
|
|
|
|
/* There is a bug in the netx internal firmware. For now we have to call this twice */
|
|
|
|
loadxc(xcno);
|
|
|
|
loadxc(xcno);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failure:
|
2009-10-17 10:44:19 +00:00
|
|
|
return COMMAND_ERROR_USAGE;
|
2007-09-05 10:53:07 +00:00
|
|
|
}
|
|
|
|
|
2010-03-30 08:16:47 +00:00
|
|
|
void __noreturn reset_cpu(unsigned long addr)
|
2007-09-05 10:53:07 +00:00
|
|
|
{
|
|
|
|
SYSTEM_REG(SYSTEM_RES_CR) = 0x01000008;
|
2010-03-30 08:16:47 +00:00
|
|
|
|
|
|
|
/* Not reached */
|
|
|
|
while (1);
|
2007-09-05 10:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 08:11:09 +00:00
|
|
|
BAREBOX_CMD_START(loadxc)
|
2007-09-05 10:53:07 +00:00
|
|
|
.cmd = do_loadxc,
|
|
|
|
.usage = "load xmac/xpec engine with ethernet firmware",
|
2009-12-15 08:11:09 +00:00
|
|
|
BAREBOX_CMD_END
|
2007-09-05 10:53:07 +00:00
|
|
|
|