Andre Schwarz | ba61a73 | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Andre Schwarz | ba61a73 | 2009-08-31 16:18:24 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <malloc.h> |
| 10 | #include <environment.h> |
| 11 | #include <fpga.h> |
| 12 | #include <asm/io.h> |
| 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Michael Jones | d61c507 | 2011-10-20 01:37:18 +0000 | [diff] [blame] | 16 | #ifndef CONFIG_ENV_IS_NOWHERE |
Andre Schwarz | ba61a73 | 2009-08-31 16:18:24 +0200 | [diff] [blame] | 17 | static char* entries_to_keep[] = { |
| 18 | "serial#", "ethaddr", "eth1addr", "model_info", "sensor_cnt", |
| 19 | "fpgadatasize", "ddr_size", "use_dhcp", "use_static_ipaddr", |
| 20 | "static_ipaddr", "static_netmask", "static_gateway", |
| 21 | "syslog", "watchdog", "netboot", "evo8serialnumber" }; |
| 22 | |
| 23 | #define MV_MAX_ENV_ENTRY_LENGTH 64 |
| 24 | #define MV_KEEP_ENTRIES ARRAY_SIZE(entries_to_keep) |
| 25 | |
| 26 | void mv_reset_environment(void) |
| 27 | { |
| 28 | int i; |
| 29 | char *s[MV_KEEP_ENTRIES]; |
| 30 | char entries[MV_KEEP_ENTRIES][MV_MAX_ENV_ENTRY_LENGTH]; |
| 31 | |
| 32 | printf("\n*** RESET ENVIRONMENT ***\n"); |
| 33 | |
| 34 | memset(entries, 0, MV_KEEP_ENTRIES * MV_MAX_ENV_ENTRY_LENGTH); |
| 35 | for (i = 0; i < MV_KEEP_ENTRIES; i++) { |
| 36 | s[i] = getenv(entries_to_keep[i]); |
| 37 | if (s[i]) { |
| 38 | printf("save '%s' : %s\n", entries_to_keep[i], s[i]); |
| 39 | strncpy(entries[i], s[i], MV_MAX_ENV_ENTRY_LENGTH); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | gd->env_valid = 0; |
| 44 | env_relocate(); |
| 45 | |
| 46 | for (i = 0; i < MV_KEEP_ENTRIES; i++) { |
| 47 | if (s[i]) { |
| 48 | printf("restore '%s' : %s\n", entries_to_keep[i], s[i]); |
| 49 | setenv(entries_to_keep[i], s[i]); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | saveenv(); |
| 54 | } |
Michael Jones | 6baab86 | 2011-07-14 23:09:44 +0000 | [diff] [blame] | 55 | #endif |
Andre Schwarz | ba61a73 | 2009-08-31 16:18:24 +0200 | [diff] [blame] | 56 | |
| 57 | int mv_load_fpga(void) |
| 58 | { |
| 59 | int result; |
| 60 | size_t data_size = 0; |
| 61 | void *fpga_data = NULL; |
| 62 | char *datastr = getenv("fpgadata"); |
| 63 | char *sizestr = getenv("fpgadatasize"); |
| 64 | |
| 65 | if (getenv("skip_fpga")) { |
| 66 | printf("found 'skip_fpga' -> FPGA _not_ loaded !\n"); |
| 67 | return -1; |
| 68 | } |
| 69 | printf("loading FPGA\n"); |
| 70 | |
| 71 | if (datastr) |
| 72 | fpga_data = (void *)simple_strtoul(datastr, NULL, 16); |
| 73 | if (sizestr) |
| 74 | data_size = (size_t)simple_strtoul(sizestr, NULL, 16); |
| 75 | if (!data_size) { |
| 76 | printf("fpgadatasize invalid -> FPGA _not_ loaded !\n"); |
| 77 | return -1; |
| 78 | } |
| 79 | |
Michal Simek | 1466365 | 2014-05-02 14:09:30 +0200 | [diff] [blame] | 80 | result = fpga_load(0, fpga_data, data_size, BIT_FULL); |
Andre Schwarz | ba61a73 | 2009-08-31 16:18:24 +0200 | [diff] [blame] | 81 | if (!result) |
Simon Glass | 0169e6b | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 82 | bootstage_mark(BOOTSTAGE_ID_START); |
Andre Schwarz | ba61a73 | 2009-08-31 16:18:24 +0200 | [diff] [blame] | 83 | |
| 84 | return result; |
| 85 | } |
| 86 | |
| 87 | u8 *dhcp_vendorex_prep(u8 *e) |
| 88 | { |
| 89 | char *ptr; |
| 90 | |
| 91 | /* DHCP vendor-class-identifier = 60 */ |
| 92 | if ((ptr = getenv("dhcp_vendor-class-identifier"))) { |
| 93 | *e++ = 60; |
| 94 | *e++ = strlen(ptr); |
| 95 | while (*ptr) |
| 96 | *e++ = *ptr++; |
| 97 | } |
| 98 | /* DHCP_CLIENT_IDENTIFIER = 61 */ |
| 99 | if ((ptr = getenv("dhcp_client_id"))) { |
| 100 | *e++ = 61; |
| 101 | *e++ = strlen(ptr); |
| 102 | while (*ptr) |
| 103 | *e++ = *ptr++; |
| 104 | } |
| 105 | |
| 106 | return e; |
| 107 | } |
| 108 | |
| 109 | u8 *dhcp_vendorex_proc(u8 *popt) |
| 110 | { |
| 111 | return NULL; |
| 112 | } |