Index: head/sys/conf/files.mips =================================================================== --- head/sys/conf/files.mips +++ head/sys/conf/files.mips @@ -86,6 +86,7 @@ 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 Index: head/sys/dev/nvram2env/nvram2env.h =================================================================== --- head/sys/dev/nvram2env/nvram2env.h +++ head/sys/dev/nvram2env/nvram2env.h @@ -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_ */ Index: head/sys/dev/nvram2env/nvram2env.c =================================================================== --- head/sys/dev/nvram2env/nvram2env.c +++ head/sys/dev/nvram2env/nvram2env.c @@ -46,50 +46,7 @@ #include -#include -#include -#include - -#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 +#include "nvram2env.h" static void nvram2env_identify(driver_t * drv, device_t parent) @@ -100,34 +57,55 @@ 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; - - if (resource_int_value("nvram", device_get_unit(dev), "maxsize", - &sc->maxsize) != 0 || sc->maxsize == 0) - sc->maxsize = NVRAM_MAX_SIZE; - - if (resource_int_value("nvram", device_get_unit(dev), "flags", - &sc->flags) != 0 || sc->flags == 0) - sc->flags = NVRAM_FLAGS_GENERIC; + /* + * Please ensure that your implementation of NVRAM->ENV specifies + * bus tag + */ + if (sc->bst == NULL) + return (ENXIO); + + 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 (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; + break; + default: + break; + } - sc->addr = ivar; + if (sc->addr == 0) + continue; if (bootverbose) device_printf(dev, "base=0x%08x sig=0x%08x " @@ -172,15 +150,6 @@ } -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) @@ -190,7 +159,7 @@ } -static int +int nvram2env_attach(device_t dev) { struct nvram2env_softc *sc; @@ -209,10 +178,11 @@ 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; @@ -265,12 +235,12 @@ 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) { @@ -313,12 +283,10 @@ 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_mips.c =================================================================== --- head/sys/dev/nvram2env/nvram2env_mips.c +++ head/sys/dev/nvram2env/nvram2env_mips.c @@ -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);