env_mgdisk.c 2.1 KB

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