blob: b9de1ed0d38d0b117ddfb050109f5c2ce04e555c [file] [log] [blame]
unsik Kim75eb82e2009-02-25 11:31:24 +09001/*
2 * (C) Copyright 2009 mGine co.
3 * unsik Kim <donari75@gmail.com>
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 <command.h>
26#include <environment.h>
27#include <linux/stddef.h>
28#include <mg_disk.h>
29
30/* references to names in env_common.c */
31extern uchar default_environment[];
unsik Kim75eb82e2009-02-25 11:31:24 +090032
33char * env_name_spec = "MG_DISK";
34
35env_t *env_ptr = 0;
36
37DECLARE_GLOBAL_DATA_PTR;
38
39uchar env_get_char_spec(int index)
40{
41 return (*((uchar *) (gd->env_addr + index)));
42}
43
44void env_relocate_spec(void)
45{
46 unsigned int err;
47
48 err = mg_disk_init();
49 if (err) {
50 puts ("*** Warning - mg_disk_init error");
51 goto OUT;
52 }
53 err = mg_disk_read(CONFIG_ENV_ADDR, (u_char *)env_ptr, CONFIG_ENV_SIZE);
54 if (err) {
55 puts ("*** Warning - mg_disk_read error");
56 goto OUT;
57 }
58
59 if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) {
60 puts ("*** Warning - CRC error");
61 goto OUT;
62 }
63
64 return;
65
66OUT:
67 printf (", using default environment\n\n");
68 set_default_env();
69}
70
71int saveenv(void)
72{
73 unsigned int err;
74
75 env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE);
76 err = mg_disk_write(CONFIG_ENV_ADDR, (u_char *)env_ptr,
77 CONFIG_ENV_SIZE);
78 if (err)
79 puts ("*** Warning - mg_disk_write error\n\n");
80
81 return err;
82}
83
84int env_init(void)
85{
86 /* use default */
87 gd->env_addr = (ulong) & default_environment[0];
88 gd->env_valid = 1;
89
90 return 0;
91}