NetWalker kernels boot again.

* Enable __HAVE_MM_MD_DIRECT_MAPPED_PHYS
* Change VM layout
* Use common start-up routine
This commit is contained in:
hkenken 2014-04-09 04:00:50 +00:00
parent a86b8eb298
commit 59f1bd2b6a
5 changed files with 142 additions and 149 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mk.netwalker,v 1.3 2014/03/07 12:35:14 hkenken Exp $
# $NetBSD: mk.netwalker,v 1.4 2014/04/09 04:00:50 hkenken Exp $
CPPFLAGS+= -mcpu=cortex-a8 -mfpu=neon
@ -6,7 +6,7 @@ SYSTEM_FIRST_OBJ= netwalker_start.o
SYSTEM_FIRST_SFILE= ${THISARM}/netwalker/netwalker_start.S
KERNEL_BASE_PHYS=0x90100000
KERNEL_BASE_VIRT=0xc0100000
KERNEL_BASE_VIRT=0x80100000
SYSTEM_LD_TAIL_EXTRA+=; \
echo ${OBJCOPY} -S -O binary $@ $@.bin; \

View File

@ -1,4 +1,4 @@
# $NetBSD: std.netwalker,v 1.8 2014/03/07 12:35:14 hkenken Exp $
# $NetBSD: std.netwalker,v 1.9 2014/04/09 04:00:50 hkenken Exp $
#
# standard NetBSD/evbarm options for Sharp NetWalker
@ -11,11 +11,12 @@ include "arch/evbarm/conf/files.netwalker"
options MODULAR
options __HAVE_FAST_SOFTINTS # should be in types.h
options __HAVE_CPU_COUNTER
options __HAVE_MM_MD_DIRECT_MAPPED_PHYS
options ARM_HAS_VBAR
options TPIDRPRW_IS_CURCPU
options CORTEX_PMC
options CORTEX_PMC_CCNT_HZ=800000000
options KERNEL_BASE_EXT=0xc0000000
options KERNEL_BASE_EXT=0x80000000
options EVBARM_BOARDTYPE="netwalker"
options FPU_VFP

View File

@ -0,0 +1,38 @@
/* $NetBSD: netwalker.h,v 1.1 2014/04/09 04:00:50 hkenken Exp $ */
/*
* Copyright (c) 2014 Genetec Corporation. All rights reserved.
* Written by Hashimoto Kenichi for Genetec Corporation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _EVBARM_NETWALKER_NETWALKER_H
#define _EVBARM_NETWALKER_NETWALKER_H
/*
* Kernel VM space: 512MB at KERNEL_VM_BASE
*/
#define KERNEL_VM_BASE 0xc0000000
#define KERNEL_VM_SIZE 0x20000000
#endif /* _EVBARM_NETWALKER_NETWALKER_H */

View File

@ -1,4 +1,4 @@
/* $NetBSD: netwalker_machdep.c,v 1.14 2014/03/29 12:00:27 hkenken Exp $ */
/* $NetBSD: netwalker_machdep.c,v 1.15 2014/04/09 04:00:50 hkenken Exp $ */
/*
* Copyright (c) 2002, 2003, 2005, 2010 Genetec Corporation.
@ -102,7 +102,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netwalker_machdep.c,v 1.14 2014/03/29 12:00:27 hkenken Exp $");
__KERNEL_RCSID(0, "$NetBSD: netwalker_machdep.c,v 1.15 2014/04/09 04:00:50 hkenken Exp $");
#include "opt_evbarm_boardtype.h"
#include "opt_cputypes.h"
@ -137,7 +137,9 @@ __KERNEL_RCSID(0, "$NetBSD: netwalker_machdep.c,v 1.14 2014/03/29 12:00:27 hkenk
#include <arm/imx/imxuartreg.h>
#include <arm/imx/imxuartvar.h>
#include <arm/imx/imx51_iomuxreg.h>
#include <evbarm/netwalker/netwalker_reg.h>
#include <evbarm/netwalker/netwalker.h>
#include "ukbd.h"
#if (NUKBD > 0)
@ -146,20 +148,12 @@ __KERNEL_RCSID(0, "$NetBSD: netwalker_machdep.c,v 1.14 2014/03/29 12:00:27 hkenk
/* Kernel text starts 1MB in from the bottom of the kernel address space. */
#define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00100000)
#define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
/*
* The range 0xc1000000 - 0xccffffff is available for kernel VM space
* Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
*/
#define KERNEL_VM_SIZE 0x0C000000
BootConfig bootconfig; /* Boot config storage */
static char bootargs[MAX_BOOT_STRING];
char *boot_args = NULL;
extern char KERNEL_BASE_phys[];
extern char KERNEL_BASE_virt[];
extern int cpu_do_powersave;
@ -167,12 +161,7 @@ extern int cpu_do_powersave;
* Macros to translate between physical and virtual for a subset of the
* kernel address space. *Not* for general use.
*/
#define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys)
#define KERNEL_BASE_VIRT ((vaddr_t)&KERNEL_BASE_virt)
#define KERN_VTOPHYS(va) \
((paddr_t)((vaddr_t)va - KERNEL_BASE_VIRT + KERNEL_BASE_PHYS))
#define KERN_PHYSTOV(pa) \
((vaddr_t)((paddr_t)pa - KERNEL_BASE_PHYS + KERNEL_BASE_VIRT))
#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys)
/* Prototypes */
@ -212,14 +201,18 @@ int comcnmode = CONMODE;
static const struct pmap_devmap netwalker_devmap[] = {
{
/* for UART1, IOMUXC */
NETWALKER_IO_VBASE0,
_A(NETWALKER_IO_PBASE0),
L1_S_SIZE * 4,
VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE
.pd_va = _A(NETWALKER_IO_VBASE0),
.pd_pa = _A(NETWALKER_IO_PBASE0),
.pd_size = _S(L1_S_SIZE * 4),
.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
.pd_cache = PTE_NOCACHE
},
{0, 0, 0, 0, 0 }
{0}
};
#undef _A
#undef _S
#ifndef MEMSTART
#define MEMSTART 0x90000000
#endif
@ -274,6 +267,10 @@ initarm(void *arg)
/* Talk to the user */
printf("\nNetBSD/evbarm (" ___STRING(EVBARM_BOARDTYPE) ") booting ...\n");
#ifdef BOOT_ARGS
char mi_bootargs[] = BOOT_ARGS;
parse_mi_bootargs(mi_bootargs);
#endif
bootargs[0] = '\0';
#if defined(VERBOSE_INIT_ARM) || 1
@ -288,7 +285,7 @@ initarm(void *arg)
* Physical Address Range Description
* ----------------------- ----------------------------------
*
* 0x90000000 - 0x97FFFFFF DDR SDRAM (128MByte)
* 0x90000000 - 0xAFFFFFFF DDR SDRAM (512MByte)
*
* The initarm() has the responsibility for creating the kernel
* page tables.
@ -305,11 +302,29 @@ initarm(void *arg)
bootconfig.dram[0].address = MEMSTART;
bootconfig.dram[0].pages = (MEMSIZE * 1024 * 1024) / PAGE_SIZE;
arm32_bootmem_init(bootconfig.dram[0].address,
bootconfig.dram[0].pages * PAGE_SIZE, (uintptr_t)KERNEL_BASE_PHYS);
psize_t ram_size = bootconfig.dram[0].pages * PAGE_SIZE;
#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) {
printf("%s: dropping RAM size from %luMB to %uMB\n",
__func__, (unsigned long) (ram_size >> 20),
(KERNEL_VM_BASE - KERNEL_BASE) >> 20);
ram_size = KERNEL_VM_BASE - KERNEL_BASE;
}
#endif
arm32_bootmem_init(bootconfig.dram[0].address, ram_size,
KERNEL_BASE_PHYS);
#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
const bool mapallmem_p = true;
KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE);
#else
const bool mapallmem_p = false;
#endif
arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0,
netwalker_devmap, false);
netwalker_devmap, mapallmem_p);
/* disable power down counter in watch dog,
This must be done within 16 seconds of start-up. */
@ -609,22 +624,6 @@ setup_ioports(void)
ioreg_write(NETWALKER_IOMUXC_VBASE + p->reg,
p->val);
}
#if 0 /* already done by bootloader */
/* GPIO2[22,23]: input (left/right button)
GPIO2[21]: input (power button) */
ioreg_write(NETWALKER_GPIO_VBASE(2) + GPIO_DIR,
~__BITS(21,23) &
ioreg_read(NETWALKER_GPIO_VBASE(2) + GPIO_DIR));
#endif
#if 0 /* already done by bootloader */
/* GPIO4[12]: input (cover switch) */
ioreg_write(NETWALKER_GPIO_VBASE(4) + GPIO_DIR,
~__BIT(12) &
ioreg_read(NETWALKER_GPIO_VBASE(4) + GPIO_DIR));
#endif
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: netwalker_start.S,v 1.2 2011/01/31 06:28:05 matt Exp $ */
/* $NetBSD: netwalker_start.S,v 1.3 2014/04/09 04:00:50 hkenken Exp $ */
/*-
* Copyright (c) 2009 SHIMIZU Ryo <ryo@nerv.org>
@ -54,8 +54,11 @@
#include "opt_imx.h"
#include "opt_com.h"
#include "opt_cpuoptions.h"
#include "opt_cputypes.h"
#include "opt_arm_debug.h"
#include <machine/asm.h>
#include <arm/asm.h>
#include <arm/armreg.h>
#include "assym.h"
@ -63,19 +66,13 @@
#include <arm/imx/imxuartreg.h>
#include <evbarm/netwalker/netwalker_reg.h>
RCSID("$NetBSD: netwalker_start.S,v 1.2 2011/01/31 06:28:05 matt Exp $")
RCSID("$NetBSD: netwalker_start.S,v 1.3 2014/04/09 04:00:50 hkenken Exp $")
#if 0
#define CPWAIT_BRANCH \
sub pc, pc, #4
#define CPWAIT(tmp) \
mrc p15, 0, tmp, c2, c0, 0 /* arbitrary read of CP15 */ ;\
mov tmp, tmp /* wait for it to complete */ ;\
CPWAIT_BRANCH /* branch to next insn */
#if defined(VERBOSE_INIT_ARM)
#define DEBUG_STARTUP
#define XPUTC(n) mov r0, n; bl _C_LABEL(debugputc)
#else
#define CPWAIT_BRANCH /* nothing to do */
#define CPWAIT(tmp) /* nothing to do */
#define XPUTC(n)
#endif
#ifndef SDRAM_START
@ -83,6 +80,9 @@ RCSID("$NetBSD: netwalker_start.S,v 1.2 2011/01/31 06:28:05 matt Exp $")
#endif
#define KERNEL_TEXT_ADDR (SDRAM_START+0x00100000)
#define INIT_MEMSIZE 128
#define TEMP_L1_TABLE (SDRAM_START + INIT_MEMSIZE * 0x100000 - L1_TABLE_SIZE)
#ifdef DEBUG_STARTUP
#define CHECKPOINT(n) CHECKPOINT2(n,r0,r1)
#define CHECKPOINT2(n,ra,rb) \
@ -101,7 +101,6 @@ RCSID("$NetBSD: netwalker_start.S,v 1.2 2011/01/31 06:28:05 matt Exp $")
.global _C_LABEL(netwalker_start)
_C_LABEL(netwalker_start):
CHECKPOINT(0)
CHECKPOINT(0)
#ifdef DEBUG_STARTUP
ldr sp,=SDRAM_START+0x4000
@ -157,7 +156,7 @@ _C_LABEL(netwalker_start):
/*
* move me to RAM
*/
ldr r1, Lcopy_size
ldr r1, .Lcopy_size
add r1, r1, #3
mov r1, r1, LSR #2
mov r4, r2
@ -187,121 +186,75 @@ _C_LABEL(netwalker_start):
* Okay, we are finished relocating the text segment. Now
* we need to leap to the next instruction.
*/
ldr r0, Lrelocate_address
ldr r1, Lrelocate_offset
ldr r0, .Lrelocate_address
ldr r1, .Lrelocate_offset
add pc, r0, r1
Lrelocate_offset: .word relocated-_C_LABEL(netwalker_start)
.Lrelocate_offset: .word relocated-_C_LABEL(netwalker_start)
relocated:
CHECKPOINT(5)
CHECKPOINT(1)
/* Move into supervisor mode and disable IRQs/FIQs. */
mrs r0, cpsr
bic r0, r0, #PSR_MODE
orr r0, r0, #(I32_bit | F32_bit | PSR_SVC32_MODE)
msr cpsr, r0
cpsid if, #PSR_SVC32_MODE
mrc p15, 0, r0, c2, c0, 0 /* get ttb prepared by bootloader */
adr r4, mmu_init_table
b 3f
movw r0, #:lower16:TEMP_L1_TABLE
movt r0, #:upper16:TEMP_L1_TABLE
adr r1, .Lmmu_init_table
bl arm_boot_l1pt_init
2:
str r3, [r0, r2]
add r2, r2, #4
add r3, r3, #(L1_S_SIZE)
adds r1, r1, #-1
bhi 2b
3:
ldmia r4!, {r1,r2,r3} /* # of sections, PA|attr, VA */
cmp r1, #0
bne 2b
CHECKPOINT(2)
/*
* Turn on the MMU, Caches, etc.
*/
movw r0, #:lower16:TEMP_L1_TABLE
movt r0, #:upper16:TEMP_L1_TABLE
bl arm_cpuinit
CHECKPOINT(3)
CHECKPOINT2(6,r3,r4)
#if 0
/* XXX: clean and invalidate Dcache. */
#endif
mcr p15, 0, r0, c7, c10, 5 /* DMB */
CPWAIT(r0)
movw ip, #:lower16:start
movt ip, #:upper16:start
bx ip /* Jump to start (flushes pipeline). */
mcr p15, 0, r0, c7, c5, 0 /* invalied Icache */
mcr p15, 0, r0, c2, c0, 0 /* Set TTB */
mcr p15, 0, r0, c8, c7, 0 /* Flush TLB */
CHECKPOINT(7)
/* Set the Domain Access register. Very important! */
mov r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
mcr p15, 0, r0, c3, c0, 0
CHECKPOINT(8)
/* Enable MMU */
mrc p15, 0, r0, c1, c0, 0
orr r0, r0, #CPU_CONTROL_MMU_ENABLE|CPU_CONTROL_AFLT_ENABLE|CPU_CONTROL_DC_ENABLE
orr r0, r0, #CPU_CONTROL_IC_ENABLE|CPU_CONTROL_BPRD_ENABLE
mcr p15, 0, r0, c1, c0, 0
CPWAIT(r0)
nop
nop
nop
nop
#ifdef DEBUG_STARTUP
CHECKPOINT(9)
bl newline
#endif
ldr pc, =start
nop
nop
nop
nop
/* NOTREACHED */
/*
* Calculate size of kernel to copy. Don't bother to copy bss,
* although I guess the CPU could use the warmup exercise ...
*/
Lcopy_size:
.Lcopy_size:
.word _edata - _C_LABEL(netwalker_start)
Lrelocate_address:
.Lrelocate_address:
.word KERNEL_BASE_phys
#define MMU_INIT(va,pa,n_sec,attr) \
.word n_sec ; \
.word 4*((va)>>L1_S_SHIFT) ; \
.word (pa)|(attr) ;
#include <arm/cortex/a9_mpsubr.S>
mmu_init_table:
.Lmmu_init_table:
/* fill all table VA==PA */
MMU_INIT(0x00000000, 0x00000000,
1 << (32 - L1_S_SHIFT),
L1_S_PROTO | L1_S_APv7_KRW)
MMU_INIT(0x00000000, 0x00000000, 1 << (32 - L1_S_SHIFT),
L1_S_PROTO_armv7 | L1_S_APv7_KRW)
/* Map KERNEL_BASE VA to SDRAM PA, write-back cacheable */
MMU_INIT(SDRAM_START, SDRAM_START,
512,
L1_S_PROTO | L1_S_APv7_KRW | L1_S_B | L1_S_C)
/* Map memory 1:1 VA to PA, write-back cacheable, shareable */
MMU_INIT(SDRAM_START, SDRAM_START, 512,
L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_CACHEABLE)
/* map VA 0xc0000000..0xdfffffff to PA 0x90000000..0xafffffff */
MMU_INIT(0xc0000000, SDRAM_START,
512, L1_S_PROTO | L1_S_APv7_KRW | L1_S_B | L1_S_C)
/* Map all 256KB of L4 WAKEUP (so console will work) */
MMU_INIT(NETWALKER_IO_VBASE0, NETWALKER_IO_PBASE0,
4,
L1_S_PROTO | L1_S_APv7_KRW)
/* Map KERNEL_BASE VA to SDRAM PA, write-back cacheable, shareable */
MMU_INIT(KERNEL_BASE, SDRAM_START, INIT_MEMSIZE,
L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_CACHEABLE)
/*
* In case of early start debugging it might be useful to map
* SoC registers (for UART access).
*/
MMU_INIT(NETWALKER_IO_VBASE0, NETWALKER_IO_PBASE0, 4,
L1_S_PROTO | L1_S_APv7_KRW | L1_S_V6_XN)
/* end of table */
MMU_INIT(0, 0, 0, 0)
#ifdef DEBUG_STARTUP
Luart0adr:
.Luart0adr:
.word UART1_BASE
.global _C_LABEL(debugprintx)
@ -350,7 +303,7 @@ print_r3:
_C_LABEL(debugputc):
stmfd sp!, {r0, r1, r2, lr}
ldr r1, Luart0adr
ldr r1, .Luart0adr
1: /* wait */
ldr r2, [r1, #0x98]
@ -371,3 +324,5 @@ newline:
b _C_LABEL(debugputc)
#endif /* DEBUG_STARTUP */
END(_C_LABEL(netwalker_start))