blob: 5dd92e709c831982eb4d556bf94e5ae3aeb5d4b1 [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
Wolfgang Denkea882ba2010-06-20 23:33:59 +020030char *env_name_spec = "MG_DISK";
unsik Kim75eb82e2009-02-25 11:31:24 +090031
Igor Grinberg6b155662011-11-07 01:14:01 +000032env_t *env_ptr;
unsik Kim75eb82e2009-02-25 11:31:24 +090033
34DECLARE_GLOBAL_DATA_PTR;
35
36uchar env_get_char_spec(int index)
37{
Igor Grinberg6b155662011-11-07 01:14:01 +000038 return *((uchar *)(gd->env_addr + index));
unsik Kim75eb82e2009-02-25 11:31:24 +090039}
40
41void env_relocate_spec(void)
42{
Wolfgang Denkea882ba2010-06-20 23:33:59 +020043 char buf[CONFIG_ENV_SIZE];
44 unsigned int err, rc;
unsik Kim75eb82e2009-02-25 11:31:24 +090045
46 err = mg_disk_init();
47 if (err) {
Wolfgang Denkea882ba2010-06-20 23:33:59 +020048 set_default_env("!mg_disk_init error");
49 return;
unsik Kim75eb82e2009-02-25 11:31:24 +090050 }
Wolfgang Denkea882ba2010-06-20 23:33:59 +020051
52 err = mg_disk_read(CONFIG_ENV_ADDR, buf, CONFIG_ENV_SIZE);
unsik Kim75eb82e2009-02-25 11:31:24 +090053 if (err) {
Wolfgang Denkea882ba2010-06-20 23:33:59 +020054 set_default_env("!mg_disk_read error");
55 return;
unsik Kim75eb82e2009-02-25 11:31:24 +090056 }
57
Wolfgang Denkea882ba2010-06-20 23:33:59 +020058 env_import(buf, 1);
unsik Kim75eb82e2009-02-25 11:31:24 +090059}
60
61int saveenv(void)
62{
63 unsigned int err;
64
65 env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE);
66 err = mg_disk_write(CONFIG_ENV_ADDR, (u_char *)env_ptr,
67 CONFIG_ENV_SIZE);
68 if (err)
Wolfgang Denkea882ba2010-06-20 23:33:59 +020069 puts("*** Warning - mg_disk_write error\n\n");
unsik Kim75eb82e2009-02-25 11:31:24 +090070
71 return err;
72}
73
74int env_init(void)
75{
76 /* use default */
Wolfgang Denkea882ba2010-06-20 23:33:59 +020077 gd->env_addr = (ulong)&default_environment[0];
unsik Kim75eb82e2009-02-25 11:31:24 +090078 gd->env_valid = 1;
79
80 return 0;
81}