Index: head/sys/conf/files.mips =================================================================== --- head/sys/conf/files.mips (revision 303257) +++ head/sys/conf/files.mips (revision 303258) @@ -1,103 +1,104 @@ # This file tells config what files go into building a kernel, # files marked standard are always included. # # $FreeBSD$ # # Arch dependent files mips/mips/autoconf.c standard mips/mips/bus_space_generic.c standard mips/mips/busdma_machdep.c standard mips/mips/cache.c standard mips/mips/cache_mipsNN.c standard mips/mips/cpu.c standard mips/mips/db_disasm.c optional ddb mips/mips/db_interface.c optional ddb mips/mips/db_trace.c optional ddb mips/mips/dump_machdep.c standard mips/mips/elf_machdep.c standard mips/mips/exception.S standard mips/mips/fp.S standard mips/mips/freebsd32_machdep.c optional compat_freebsd32 mips/mips/gdb_machdep.c standard mips/mips/in_cksum.c optional inet mips/mips/libkern_machdep.c standard mips/mips/locore.S standard no-obj mips/mips/machdep.c standard mips/mips/mem.c optional mem mips/mips/minidump_machdep.c standard mips/mips/mp_machdep.c optional smp mips/mips/mpboot.S optional smp mips/mips/nexus.c standard mips/mips/ofw_machdep.c optional fdt mips/mips/pm_machdep.c standard mips/mips/pmap.c standard mips/mips/ptrace_machdep.c standard mips/mips/sc_machdep.c standard mips/mips/stack_machdep.c optional ddb | stack mips/mips/stdatomic.c standard \ compile-with "${NORMAL_C:N-Wmissing-prototypes}" mips/mips/support.S standard mips/mips/bcopy.S standard mips/mips/swtch.S standard mips/mips/sys_machdep.c standard mips/mips/tlb.c standard mips/mips/trap.c standard mips/mips/uio_machdep.c standard mips/mips/uma_machdep.c standard mips/mips/vm_machdep.c standard # misc opt-in bits kern/kern_clocksource.c standard kern/link_elf_obj.c standard kern/subr_busdma_bufalloc.c standard kern/subr_dummy_vdso_tc.c standard kern/subr_sfbuf.c optional mips | mipsel | mipsn32 # gcc/clang runtime libkern/ffsl.c standard libkern/ffsll.c standard libkern/fls.c standard libkern/flsl.c standard libkern/flsll.c standard libkern/memmove.c standard libkern/cmpdi2.c optional mips | mipsel libkern/ucmpdi2.c optional mips | mipsel libkern/ashldi3.c standard libkern/ashrdi3.c standard # cfe support dev/cfe/cfe_api.c optional cfe dev/cfe/cfe_console.c optional cfe_console dev/cfe/cfe_env.c optional cfe_env # syscons support dev/fb/fb.c optional sc dev/syscons/scgfbrndr.c optional sc dev/syscons/scterm-teken.c optional sc dev/syscons/scvtb.c optional sc mips/mips/sc_machdep.c optional sc # FDT support dev/uart/uart_cpu_fdt.c optional uart fdt # crypto support -- use generic crypto/blowfish/bf_enc.c optional crypto | ipsec crypto/des/des_enc.c optional crypto | ipsec | netsmb # AP common nvram interface MIPS specific, but maybe should be more generic +dev/nvram2env/nvram2env_mips.c optional nvram2env dev/nvram2env/nvram2env.c optional nvram2env # hwpmc support dev/hwpmc/hwpmc_mips.c optional hwpmc dev/hwpmc/hwpmc_mips24k.c optional hwpmc_mips24k dev/hwpmc/hwpmc_mips74k.c optional hwpmc_mips74k # ofw support dev/ofw/ofwpci.c optional fdt pci # DTrace cddl/compat/opensolaris/kern/opensolaris_atomic.c optional zfs | dtrace compile-with "${CDDL_C}" cddl/dev/dtrace/mips/dtrace_asm.S optional dtrace compile-with "${DTRACE_S}" cddl/dev/dtrace/mips/dtrace_subr.c optional dtrace compile-with "${DTRACE_C}" cddl/dev/fbt/mips/fbt_isa.c optional dtrace_fbt | dtraceall compile-with "${FBT_C}" Index: head/sys/dev/nvram2env/nvram2env.c =================================================================== --- head/sys/dev/nvram2env/nvram2env.c (revision 303257) +++ head/sys/dev/nvram2env/nvram2env.c (revision 303258) @@ -1,324 +1,292 @@ /*- * Copyright (c) 2010 Aleksandr Rybalko. * All rights reserved. * * 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 THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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. */ /* * Pseudo driver to copy the NVRAM settings from various sources * into the kernel environment. * * Drivers (such as ethernet devices) can then use environment * variables to set default parameters. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include -#include -#include -#include +#include "nvram2env.h" -#define nvram2env_read_1(sc, reg) \ - bus_space_read_1((sc)->sc_bt, (sc)->sc_bh,(reg)) - -#define nvram2env_read_2(sc, reg) \ - bus_space_read_2((sc)->sc_bt, (sc)->sc_bh,(reg)) - -#define nvram2env_read_4(sc, reg) \ - bus_space_read_4((sc)->sc_bt, (sc)->sc_bh,(reg)) - -#define nvram2env_write_1(sc, reg, val) \ - bus_space_write_1((sc)->sc_bt, (sc)->sc_bh, \ - (reg), (val)) - -#define nvram2env_write_2(sc, reg, val) \ - bus_space_write_2((sc)->sc_bt, (sc)->sc_bh, \ - (reg), (val)) - -#define nvram2env_write_4(sc, reg, val) \ - bus_space_write_4((sc)->sc_bt, (sc)->sc_bh, \ - (reg), (val)) - -struct nvram2env_softc { - bus_space_tag_t bst; - bus_space_handle_t bsh; - bus_addr_t addr; - int need_swap; - uint32_t sig; - uint32_t flags; -#define NVRAM_FLAGS_NOCHECK 0x0001 /* Do not check(CRC or somthing else)*/ -#define NVRAM_FLAGS_GENERIC 0x0002 /* Format Generic, skip 4b and read */ -#define NVRAM_FLAGS_BROADCOM 0x0004 /* Format Broadcom, use struct nvram */ -#define NVRAM_FLAGS_UBOOT 0x0008 /* Format Generic, skip 4b of CRC and read */ - uint32_t maxsize; - uint32_t crc; -}; - -static int nvram2env_attach(device_t); -static int nvram2env_probe(device_t); - -#define NVRAM_MAX_SIZE 0x10000 - static void nvram2env_identify(driver_t * drv, device_t parent) { int i, ivar; for (i = 0; !resource_int_value("nvram", i, "base", &ivar); i++) BUS_ADD_CHILD(parent, 0, "nvram2env", i); } -static int +int nvram2env_probe(device_t dev) { uint32_t i, ivar, sig; struct nvram2env_softc * sc = device_get_softc(dev); - sc->bst = mips_bus_space_generic; - if (resource_int_value("nvram", device_get_unit(dev), "sig", - &sc->sig) != 0 || sc->sig == 0) - sc->sig = 0x48534c46; + /* + * Please ensure that your implementation of NVRAM->ENV specifies + * bus tag + */ + if (sc->bst == NULL) + return (ENXIO); - if (resource_int_value("nvram", device_get_unit(dev), "maxsize", - &sc->maxsize) != 0 || sc->maxsize == 0) - sc->maxsize = NVRAM_MAX_SIZE; + if (sc->sig == 0) + if (resource_int_value("nvram", device_get_unit(dev), "sig", + &sc->sig) != 0 || sc->sig == 0) + sc->sig = CFE_NVRAM_SIGNATURE; - if (resource_int_value("nvram", device_get_unit(dev), "flags", - &sc->flags) != 0 || sc->flags == 0) - sc->flags = NVRAM_FLAGS_GENERIC; + if (sc->maxsize == 0) + if (resource_int_value("nvram", device_get_unit(dev), "maxsize", + &sc->maxsize) != 0 || sc->maxsize == 0) + sc->maxsize = NVRAM_MAX_SIZE; + if (sc->flags == 0) + if (resource_int_value("nvram", device_get_unit(dev), "flags", + &sc->flags) != 0 || sc->flags == 0) + sc->flags = NVRAM_FLAGS_GENERIC; + for (i = 0; i < 2; i ++) { - if (resource_int_value("nvram", device_get_unit(dev), - (!i)?"base":"fallbackbase", &ivar) != 0 || - ivar == 0) - continue; + switch (i) { + case 0: + break; + case 1: + case 2: + if (resource_int_value("nvram", device_get_unit(dev), + (i == 1) ? "base" : "fallbackbase", &ivar) != 0 || + ivar == 0) + continue; - sc->addr = ivar; + sc->addr = ivar; + break; + default: + break; + } + if (sc->addr == 0) + continue; + if (bootverbose) device_printf(dev, "base=0x%08x sig=0x%08x " "maxsize=0x%08x flags=0x%08x\n", sc->addr, sc->sig, sc->maxsize, sc->flags); if (bus_space_map(sc->bst, sc->addr, sc->maxsize, 0, &sc->bsh) != 0) continue; sig = bus_space_read_4(sc->bst, sc->bsh, 0); if ( sig == sc->sig /*FLSH*/) { device_printf(dev, "Found NVRAM at %#x\n", (uint32_t)ivar); sc->need_swap = 0; goto unmap_done; } else if ( htole32(sig) == sc->sig /*HSLF*/) { device_printf(dev, "Found NVRAM at %#x\n", (uint32_t)ivar); sc->need_swap = 1; goto unmap_done; } else if (sc->flags & NVRAM_FLAGS_UBOOT) { device_printf(dev, "Use NVRAM at %#x\n", (uint32_t)ivar); sc->crc = sig; goto unmap_done; } bus_space_unmap(sc->bst, sc->bsh, NVRAM_MAX_SIZE); } sc->bst = 0; sc->bsh = 0; sc->addr = 0; return (ENXIO); unmap_done: bus_space_unmap(sc->bst, sc->bsh, NVRAM_MAX_SIZE); device_set_desc(dev, "NVRAM to ENV pseudo-device"); return (BUS_PROBE_SPECIFIC); } -struct nvram { - u_int32_t sig; - u_int32_t size; - u_int32_t unknown1; - u_int32_t unknown2; - u_int32_t unknown3; - char data[]; -}; - static uint32_t read_4(struct nvram2env_softc * sc, int offset) { if (sc->need_swap) return (bswap32(bus_space_read_4(sc->bst, sc->bsh, offset))); else return (bus_space_read_4(sc->bst, sc->bsh, offset)); } -static int +int nvram2env_attach(device_t dev) { struct nvram2env_softc *sc; struct nvram *nv; char *pair, *value, *assign; uint32_t sig, size, i, *tmp; sc = device_get_softc(dev); if (sc->bst == 0 || sc->addr == 0) return (ENXIO); if (bus_space_map(sc->bst, sc->addr, NVRAM_MAX_SIZE, 0, &sc->bsh) != 0) return (ENXIO); sig = read_4(sc, 0); size = read_4(sc, 4); -#if 1 + if (bootverbose) - device_printf(dev, " size=0x%05x maxsize=0x%05x\n", size, sc->maxsize); -#endif + device_printf(dev, " size=0x%05x maxsize=0x%05x\n", size, + sc->maxsize); + size = (size > sc->maxsize)?sc->maxsize:size; if (sig == sc->sig || (sc->flags & NVRAM_FLAGS_UBOOT)) { /* align size to 32bit size*/ size += 3; size &= ~3; nv = malloc(size, M_DEVBUF, M_WAITOK | M_ZERO); if (!nv) return (ENOMEM); /* set tmp pointer to begin of NVRAM */ tmp = (uint32_t *) nv; /* use read_4 to swap bytes if it's required */ for (i = 0; i < size; i += 4) { *tmp = read_4(sc, i); tmp++; } /* now tmp pointer is end of NVRAM */ if (sc->flags & NVRAM_FLAGS_BROADCOM) { device_printf(dev, "sig = %#x\n", nv->sig); device_printf(dev, "size = %#x\n", nv->size); } if (!(sc->flags & NVRAM_FLAGS_NOCHECK)) { /* TODO: need checksum verification */ } if (sc->flags & NVRAM_FLAGS_GENERIC) pair = (char*)nv+4; if (sc->flags & NVRAM_FLAGS_UBOOT) pair = (char*)nv+4; else if (sc->flags & NVRAM_FLAGS_BROADCOM) pair = (char*)nv+20; else pair = (char*)nv+4; /* iterate over buffer till end. tmp points to end of NVRAM */ for ( ; pair < (char*)tmp; pair += strlen(pair) + strlen(value) + 2 ) { if (!pair || (strlen(pair) == 0)) break; /* hint.nvram.0. */ assign = strchr(pair,'='); assign[0] = '\0'; value = assign+1; -#if 1 + if (bootverbose) - printf("ENV: %s=%s\n", pair, value); -#else - printf("ENV: %s\n", pair); -#endif + printf("ENV[%p]: %s=%s\n", + (void*)((char*)pair - (char*)nv), + pair, value); + kern_setenv(pair, value); if (strcasecmp(pair, "WAN_MAC_ADDR") == 0) { /* Alias for MAC address of eth0 */ if (bootverbose) printf("ENV: aliasing " "WAN_MAC_ADDR to ethaddr" " = %s\n", value); kern_setenv("ethaddr", value); } else if (strcasecmp(pair, "LAN_MAC_ADDR") == 0){ /* Alias for MAC address of eth1 */ if (bootverbose) printf("ENV: aliasing " "LAN_MAC_ADDR to eth1addr" " = %s\n", value); kern_setenv("eth1addr", value); } if (strcmp(pair, "bootverbose") == 0) bootverbose = strtoul(value, 0, 0); if (strcmp(pair, "boothowto" ) == 0) boothowto = strtoul(value, 0, 0); } free(nv, M_DEVBUF); } bus_space_unmap(sc->bst, sc->bsh, NVRAM_MAX_SIZE); return (0); } static device_method_t nvram2env_methods[] = { /* Device interface */ DEVMETHOD(device_identify, nvram2env_identify), DEVMETHOD(device_probe, nvram2env_probe), DEVMETHOD(device_attach, nvram2env_attach), DEVMETHOD_END }; -static driver_t nvram2env_driver = { +driver_t nvram2env_driver = { "nvram2env", nvram2env_methods, sizeof(struct nvram2env_softc), }; -static devclass_t nvram2env_devclass; -DRIVER_MODULE(nvram2env, nexus, nvram2env_driver, nvram2env_devclass, 0, 0); - +devclass_t nvram2env_devclass; Index: head/sys/dev/nvram2env/nvram2env.h =================================================================== --- head/sys/dev/nvram2env/nvram2env.h (nonexistent) +++ head/sys/dev/nvram2env/nvram2env.h (revision 303258) @@ -0,0 +1,88 @@ +/*- + * Copyright (c) 2010 Aleksandr Rybalko. + * Copyright (c) 2016 Michael Zhilin. + * All rights reserved. + * + * 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 THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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. + * + * $FreeBSD$ + */ + + +#ifndef NVRAM2ENV_NVRAM2ENV_H_ +#define NVRAM2ENV_NVRAM2ENV_H_ + +#define nvram2env_read_1(sc, reg) \ + bus_space_read_1((sc)->sc_bt, (sc)->sc_bh,(reg)) + +#define nvram2env_read_2(sc, reg) \ + bus_space_read_2((sc)->sc_bt, (sc)->sc_bh,(reg)) + +#define nvram2env_read_4(sc, reg) \ + bus_space_read_4((sc)->sc_bt, (sc)->sc_bh,(reg)) + +#define nvram2env_write_1(sc, reg, val) \ + bus_space_write_1((sc)->sc_bt, (sc)->sc_bh, \ + (reg), (val)) + +#define nvram2env_write_2(sc, reg, val) \ + bus_space_write_2((sc)->sc_bt, (sc)->sc_bh, \ + (reg), (val)) + +#define nvram2env_write_4(sc, reg, val) \ + bus_space_write_4((sc)->sc_bt, (sc)->sc_bh, \ + (reg), (val)) + +struct nvram2env_softc { + bus_space_tag_t bst; + bus_space_handle_t bsh; + bus_addr_t addr; + int need_swap; + uint32_t sig; + uint32_t flags; +#define NVRAM_FLAGS_NOCHECK 0x0001 /* Do not check(CRC or somthing else)*/ +#define NVRAM_FLAGS_GENERIC 0x0002 /* Format Generic, skip 4b and read */ +#define NVRAM_FLAGS_BROADCOM 0x0004 /* Format Broadcom, use struct nvram */ +#define NVRAM_FLAGS_UBOOT 0x0008 /* Format Generic, skip 4b of CRC and read */ + uint32_t maxsize; + uint32_t crc; +}; + +#define NVRAM_MAX_SIZE 0x10000 +#define CFE_NVRAM_SIGNATURE 0x48534c46 + +struct nvram { + u_int32_t sig; + u_int32_t size; + u_int32_t unknown1; + u_int32_t unknown2; + u_int32_t unknown3; + char data[]; +}; + +int nvram2env_attach(device_t); +int nvram2env_probe(device_t); + +extern devclass_t nvram2env_devclass; +extern driver_t nvram2env_driver; + +#endif /* SYS_DEV_NVRAM2ENV_NVRAM2ENV_H_ */ Property changes on: head/sys/dev/nvram2env/nvram2env.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/sys/dev/nvram2env/nvram2env_mips.c =================================================================== --- head/sys/dev/nvram2env/nvram2env_mips.c (nonexistent) +++ head/sys/dev/nvram2env/nvram2env_mips.c (revision 303258) @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 2010 Aleksandr Rybalko. + * Copyright (c) 2016 Michael Zhilin. + * All rights reserved. + * + * 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 THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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. + */ + +/* + * Implementation of pseudo driver for MIPS to copy the NVRAM settings + * from various sources into the kernel environment. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include + +#include "nvram2env.h" + +static int +nvram2env_mips_probe(device_t dev) +{ + struct nvram2env_softc *sc; + + sc = device_get_softc(dev); + sc->bst = mips_bus_space_generic; + + return (nvram2env_probe(dev)); +} + +static device_method_t nvram2env_mips_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, nvram2env_mips_probe), + + DEVMETHOD_END +}; + +DEFINE_CLASS_1(nvram2env, nvram2env_mips_driver, nvram2env_mips_methods, + sizeof(struct nvram2env_softc), nvram2env_driver); +DRIVER_MODULE(nvram2env_mips, nexus, nvram2env_mips_driver, nvram2env_devclass, + NULL, NULL); + +MODULE_VERSION(nvram2env_mips, 1); +MODULE_DEPEND(nvram2env_mips, nvram2env, 1, 1, 1); Property changes on: head/sys/dev/nvram2env/nvram2env_mips.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property