env_mgdisk.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #include <common.h>
  24. #include <command.h>
  25. #include <environment.h>
  26. #include <linux/stddef.h>
  27. #include <mg_disk.h>
  28. /* references to names in env_common.c */
  29. extern uchar default_environment[];
  30. char * env_name_spec = "MG_DISK";
  31. env_t *env_ptr = 0;
  32. DECLARE_GLOBAL_DATA_PTR;
  33. uchar env_get_char_spec(int index)
  34. {
  35. return (*((uchar *) (gd->env_addr + index)));
  36. }
  37. void env_relocate_spec(void)
  38. {
  39. unsigned int err;
  40. err = mg_disk_init();
  41. if (err) {
  42. puts ("*** Warning - mg_disk_init error");
  43. goto OUT;
  44. }
  45. err = mg_disk_read(CONFIG_ENV_ADDR, (u_char *)env_ptr, CONFIG_ENV_SIZE);
  46. if (err) {
  47. puts ("*** Warning - mg_disk_read error");
  48. goto OUT;
  49. }
  50. if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) {
  51. puts ("*** Warning - CRC error");
  52. goto OUT;
  53. }
  54. return;
  55. OUT:
  56. printf (", using default environment\n\n");
  57. set_default_env();
  58. }
  59. int saveenv(void)
  60. {
  61. unsigned int err;
  62. env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE);
  63. err = mg_disk_write(CONFIG_ENV_ADDR, (u_char *)env_ptr,
  64. CONFIG_ENV_SIZE);
  65. if (err)
  66. puts ("*** Warning - mg_disk_write error\n\n");
  67. return err;
  68. }
  69. int env_init(void)
  70. {
  71. /* use default */
  72. gd->env_addr = (ulong) & default_environment[0];
  73. gd->env_valid = 1;
  74. return 0;
  75. }