eeprom.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * (C) Copyright 2007
  3. * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
  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 <dm9000.h>
  26. static int do_read_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {
  27. unsigned int i;
  28. u8 data[2];
  29. for (i=0; i < 0x40; i++) {
  30. if (!(i % 0x10))
  31. printf("\n%08x:", i);
  32. dm9000_read_srom_word(i, data);
  33. printf(" %02x%02x", data[1], data[0]);
  34. }
  35. printf ("\n");
  36. return (0);
  37. }
  38. static int do_write_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {
  39. int offset,value;
  40. if (argc < 4) {
  41. cmd_usage(cmdtp);
  42. return 1;
  43. }
  44. offset=simple_strtoul(argv[2],NULL,16);
  45. value=simple_strtoul(argv[3],NULL,16);
  46. if (offset > 0x40) {
  47. printf("Wrong offset : 0x%x\n",offset);
  48. cmd_usage(cmdtp);
  49. return 1;
  50. }
  51. dm9000_write_srom_word(offset, value);
  52. return (0);
  53. }
  54. int do_dm9000_eeprom ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {
  55. if (argc < 2) {
  56. cmd_usage(cmdtp);
  57. return 1;
  58. }
  59. if (strcmp (argv[1],"read") == 0) {
  60. return (do_read_dm9000_eeprom(cmdtp,flag,argc,argv));
  61. } else if (strcmp (argv[1],"write") == 0) {
  62. return (do_write_dm9000_eeprom(cmdtp,flag,argc,argv));
  63. } else {
  64. cmd_usage(cmdtp);
  65. return 1;
  66. }
  67. }
  68. U_BOOT_CMD(
  69. dm9000ee,4,1,do_dm9000_eeprom,
  70. "Read/Write eeprom connected to Ethernet Controller",
  71. "\ndm9000ee write <word offset> <value> \n"
  72. "\tdm9000ee read \n"
  73. "\tword:\t\t00-02 : MAC Address\n"
  74. "\t\t\t03-07 : DM9000 Configuration\n"
  75. "\t\t\t08-63 : User data\n");