blob: a69923b700f69a35be87ed3c3d5b3baf227cb559 [file] [log] [blame]
unsik Kimf0b1bdd2009-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 Kimf0b1bdd2009-02-25 11:31:24 +090032
Wolfgang Denk460a9ff2010-06-20 23:33:59 +020033char *env_name_spec = "MG_DISK";
unsik Kimf0b1bdd2009-02-25 11:31:24 +090034
35env_t *env_ptr = 0;
36
37DECLARE_GLOBAL_DATA_PTR;
38
39uchar env_get_char_spec(int index)
40{
Wolfgang Denk460a9ff2010-06-20 23:33:59 +020041 return (*((uchar *)(gd->env_addr + index)));
unsik Kimf0b1bdd2009-02-25 11:31:24 +090042}
43
44void env_relocate_spec(void)
45{
Wolfgang Denk460a9ff2010-06-20 23:33:59 +020046 char buf[CONFIG_ENV_SIZE];
47 unsigned int err, rc;
unsik Kimf0b1bdd2009-02-25 11:31:24 +090048
49 err = mg_disk_init();
50 if (err) {
Wolfgang Denk460a9ff2010-06-20 23:33:59 +020051 set_default_env("!mg_disk_init error");
52 return;
unsik Kimf0b1bdd2009-02-25 11:31:24 +090053 }
54
Wolfgang Denk460a9ff2010-06-20 23:33:59 +020055 err = mg_disk_read(CONFIG_ENV_ADDR, buf, CONFIG_ENV_SIZE);
56 if (err) {
57 set_default_env("!mg_disk_read error");
58 return;
unsik Kimf0b1bdd2009-02-25 11:31:24 +090059 }
60
Wolfgang Denk460a9ff2010-06-20 23:33:59 +020061 env_import(buf, 1);
unsik Kimf0b1bdd2009-02-25 11:31:24 +090062}
63
64int saveenv(void)
65{
66 unsigned int err;
67
68 env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE);
69 err = mg_disk_write(CONFIG_ENV_ADDR, (u_char *)env_ptr,
70 CONFIG_ENV_SIZE);
71 if (err)
Wolfgang Denk460a9ff2010-06-20 23:33:59 +020072 puts("*** Warning - mg_disk_write error\n\n");
unsik Kimf0b1bdd2009-02-25 11:31:24 +090073
74 return err;
75}
76
77int env_init(void)
78{
79 /* use default */
Wolfgang Denk460a9ff2010-06-20 23:33:59 +020080 gd->env_addr = (ulong)&default_environment[0];
unsik Kimf0b1bdd2009-02-25 11:31:24 +090081 gd->env_valid = 1;
82
83 return 0;
84}