unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 1 | /* |
| 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 Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 30 | char *env_name_spec = "MG_DISK"; |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 31 | |
Igor Grinberg | 6b15566 | 2011-11-07 01:14:01 +0000 | [diff] [blame] | 32 | env_t *env_ptr; |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 36 | void env_relocate_spec(void) |
| 37 | { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 38 | char buf[CONFIG_ENV_SIZE]; |
| 39 | unsigned int err, rc; |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 40 | |
| 41 | err = mg_disk_init(); |
| 42 | if (err) { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 43 | set_default_env("!mg_disk_init error"); |
| 44 | return; |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 45 | } |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 46 | |
| 47 | err = mg_disk_read(CONFIG_ENV_ADDR, buf, CONFIG_ENV_SIZE); |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 48 | if (err) { |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 49 | set_default_env("!mg_disk_read error"); |
| 50 | return; |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 51 | } |
| 52 | |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 53 | env_import(buf, 1); |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | int saveenv(void) |
| 57 | { |
| 58 | unsigned int err; |
| 59 | |
| 60 | env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE); |
| 61 | err = mg_disk_write(CONFIG_ENV_ADDR, (u_char *)env_ptr, |
| 62 | CONFIG_ENV_SIZE); |
| 63 | if (err) |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 64 | puts("*** Warning - mg_disk_write error\n\n"); |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 65 | |
| 66 | return err; |
| 67 | } |
| 68 | |
| 69 | int env_init(void) |
| 70 | { |
| 71 | /* use default */ |
Wolfgang Denk | ea882ba | 2010-06-20 23:33:59 +0200 | [diff] [blame] | 72 | gd->env_addr = (ulong)&default_environment[0]; |
unsik Kim | 75eb82e | 2009-02-25 11:31:24 +0900 | [diff] [blame] | 73 | gd->env_valid = 1; |
| 74 | |
| 75 | return 0; |
| 76 | } |