Andre Schwarz | 632a6dd | 2009-08-31 16:18:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 |
| 3 | * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.de |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <malloc.h> |
| 26 | #include <environment.h> |
| 27 | #include <fpga.h> |
| 28 | #include <asm/io.h> |
| 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
Michael Jones | a1d88f4 | 2011-10-20 01:37:18 +0000 | [diff] [blame] | 32 | #ifndef CONFIG_ENV_IS_NOWHERE |
Andre Schwarz | 632a6dd | 2009-08-31 16:18:24 +0200 | [diff] [blame] | 33 | static char* entries_to_keep[] = { |
| 34 | "serial#", "ethaddr", "eth1addr", "model_info", "sensor_cnt", |
| 35 | "fpgadatasize", "ddr_size", "use_dhcp", "use_static_ipaddr", |
| 36 | "static_ipaddr", "static_netmask", "static_gateway", |
| 37 | "syslog", "watchdog", "netboot", "evo8serialnumber" }; |
| 38 | |
| 39 | #define MV_MAX_ENV_ENTRY_LENGTH 64 |
| 40 | #define MV_KEEP_ENTRIES ARRAY_SIZE(entries_to_keep) |
| 41 | |
| 42 | void mv_reset_environment(void) |
| 43 | { |
| 44 | int i; |
| 45 | char *s[MV_KEEP_ENTRIES]; |
| 46 | char entries[MV_KEEP_ENTRIES][MV_MAX_ENV_ENTRY_LENGTH]; |
| 47 | |
| 48 | printf("\n*** RESET ENVIRONMENT ***\n"); |
| 49 | |
| 50 | memset(entries, 0, MV_KEEP_ENTRIES * MV_MAX_ENV_ENTRY_LENGTH); |
| 51 | for (i = 0; i < MV_KEEP_ENTRIES; i++) { |
| 52 | s[i] = getenv(entries_to_keep[i]); |
| 53 | if (s[i]) { |
| 54 | printf("save '%s' : %s\n", entries_to_keep[i], s[i]); |
| 55 | strncpy(entries[i], s[i], MV_MAX_ENV_ENTRY_LENGTH); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | gd->env_valid = 0; |
| 60 | env_relocate(); |
| 61 | |
| 62 | for (i = 0; i < MV_KEEP_ENTRIES; i++) { |
| 63 | if (s[i]) { |
| 64 | printf("restore '%s' : %s\n", entries_to_keep[i], s[i]); |
| 65 | setenv(entries_to_keep[i], s[i]); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | saveenv(); |
| 70 | } |
Michael Jones | 12b5723 | 2011-07-14 23:09:44 +0000 | [diff] [blame] | 71 | #endif |
Andre Schwarz | 632a6dd | 2009-08-31 16:18:24 +0200 | [diff] [blame] | 72 | |
| 73 | int mv_load_fpga(void) |
| 74 | { |
| 75 | int result; |
| 76 | size_t data_size = 0; |
| 77 | void *fpga_data = NULL; |
| 78 | char *datastr = getenv("fpgadata"); |
| 79 | char *sizestr = getenv("fpgadatasize"); |
| 80 | |
| 81 | if (getenv("skip_fpga")) { |
| 82 | printf("found 'skip_fpga' -> FPGA _not_ loaded !\n"); |
| 83 | return -1; |
| 84 | } |
| 85 | printf("loading FPGA\n"); |
| 86 | |
| 87 | if (datastr) |
| 88 | fpga_data = (void *)simple_strtoul(datastr, NULL, 16); |
| 89 | if (sizestr) |
| 90 | data_size = (size_t)simple_strtoul(sizestr, NULL, 16); |
| 91 | if (!data_size) { |
| 92 | printf("fpgadatasize invalid -> FPGA _not_ loaded !\n"); |
| 93 | return -1; |
| 94 | } |
| 95 | |
| 96 | result = fpga_load(0, fpga_data, data_size); |
| 97 | if (!result) |
Simon Glass | 770605e | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 98 | bootstage_mark(BOOTSTAGE_ID_START); |
Andre Schwarz | 632a6dd | 2009-08-31 16:18:24 +0200 | [diff] [blame] | 99 | |
| 100 | return result; |
| 101 | } |
| 102 | |
| 103 | u8 *dhcp_vendorex_prep(u8 *e) |
| 104 | { |
| 105 | char *ptr; |
| 106 | |
| 107 | /* DHCP vendor-class-identifier = 60 */ |
| 108 | if ((ptr = getenv("dhcp_vendor-class-identifier"))) { |
| 109 | *e++ = 60; |
| 110 | *e++ = strlen(ptr); |
| 111 | while (*ptr) |
| 112 | *e++ = *ptr++; |
| 113 | } |
| 114 | /* DHCP_CLIENT_IDENTIFIER = 61 */ |
| 115 | if ((ptr = getenv("dhcp_client_id"))) { |
| 116 | *e++ = 61; |
| 117 | *e++ = strlen(ptr); |
| 118 | while (*ptr) |
| 119 | *e++ = *ptr++; |
| 120 | } |
| 121 | |
| 122 | return e; |
| 123 | } |
| 124 | |
| 125 | u8 *dhcp_vendorex_proc(u8 *popt) |
| 126 | { |
| 127 | return NULL; |
| 128 | } |