blob: 1be5aba2e9459ee38739eb5d3a1fe32fb85facdf [file] [log] [blame]
Andre Schwarzba61a732009-08-31 16:18:24 +02001/*
2 * (C) Copyright 2008
3 * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.de
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Andre Schwarzba61a732009-08-31 16:18:24 +02006 */
7
8#include <common.h>
9#include <malloc.h>
10#include <environment.h>
11#include <fpga.h>
12#include <asm/io.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
Michael Jonesd61c5072011-10-20 01:37:18 +000016#ifndef CONFIG_ENV_IS_NOWHERE
Andre Schwarzba61a732009-08-31 16:18:24 +020017static 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
26void 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 Jones6baab862011-07-14 23:09:44 +000055#endif
Andre Schwarzba61a732009-08-31 16:18:24 +020056
57int 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 Simek14663652014-05-02 14:09:30 +020080 result = fpga_load(0, fpga_data, data_size, BIT_FULL);
Andre Schwarzba61a732009-08-31 16:18:24 +020081 if (!result)
Simon Glass0169e6b2012-02-13 13:51:18 +000082 bootstage_mark(BOOTSTAGE_ID_START);
Andre Schwarzba61a732009-08-31 16:18:24 +020083
84 return result;
85}
86
87u8 *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
109u8 *dhcp_vendorex_proc(u8 *popt)
110{
111 return NULL;
112}