pibs.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * 2004-2005 (c) MontaVista, Software, Inc. This file is licensed under
  3. * the terms of the GNU General Public License version 2. This program
  4. * is licensed "as is" without any warranty of any kind, whether express
  5. * or implied.
  6. */
  7. #include <linux/types.h>
  8. #include <linux/string.h>
  9. #include <linux/ctype.h>
  10. #include <asm/ppcboot.h>
  11. #include <asm/ibm4xx.h>
  12. extern unsigned long decompress_kernel(unsigned long load_addr, int num_words,
  13. unsigned long cksum);
  14. /* We need to make sure that this is before the images to ensure
  15. * that it's in a mapped location. - Tom */
  16. bd_t hold_resid_buf __attribute__ ((__section__ (".data.boot")));
  17. bd_t *hold_residual = &hold_resid_buf;
  18. /* String functions lifted from lib/vsprintf.c and lib/ctype.c */
  19. unsigned char _ctype[] = {
  20. _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
  21. _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
  22. _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */
  23. _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */
  24. _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */
  25. _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */
  26. _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */
  27. _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */
  28. _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */
  29. _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */
  30. _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */
  31. _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */
  32. _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */
  33. _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */
  34. _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */
  35. _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */
  36. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */
  37. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */
  38. _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */
  39. _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */
  40. _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */
  41. _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */
  42. _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */
  43. _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */
  44. /**
  45. * simple_strtoull - convert a string to an unsigned long long
  46. * @cp: The start of the string
  47. * @endp: A pointer to the end of the parsed string will be placed here
  48. * @base: The number base to use
  49. */
  50. unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base)
  51. {
  52. unsigned long long result = 0,value;
  53. if (!base) {
  54. base = 10;
  55. if (*cp == '0') {
  56. base = 8;
  57. cp++;
  58. if ((toupper(*cp) == 'X') && isxdigit(cp[1])) {
  59. cp++;
  60. base = 16;
  61. }
  62. }
  63. } else if (base == 16) {
  64. if (cp[0] == '0' && toupper(cp[1]) == 'X')
  65. cp += 2;
  66. }
  67. while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
  68. ? toupper(*cp) : *cp)-'A'+10) < base) {
  69. result = result*base + value;
  70. cp++;
  71. }
  72. if (endp)
  73. *endp = (char *)cp;
  74. return result;
  75. }
  76. void *
  77. load_kernel(unsigned long load_addr, int num_words, unsigned long cksum,
  78. void *ign1, void *ign2)
  79. {
  80. unsigned long long mac64;
  81. decompress_kernel(load_addr, num_words, cksum);
  82. mac64 = simple_strtoull((char *)PIBS_MAC_BASE, 0, 16);
  83. memcpy(hold_residual->bi_enetaddr, (char *)&mac64+2, 6);
  84. #if defined(CONFIG_440GX) || defined(CONFIG_440EP)
  85. mac64 = simple_strtoull((char *)(PIBS_MAC_BASE+PIBS_MAC_OFFSET), 0, 16);
  86. memcpy(hold_residual->bi_enet1addr, (char *)&mac64+2, 6);
  87. #endif
  88. #ifdef CONFIG_440GX
  89. mac64 = simple_strtoull((char *)(PIBS_MAC_BASE+PIBS_MAC_OFFSET*2), 0, 16);
  90. memcpy(hold_residual->bi_enet2addr, (char *)&mac64+2, 6);
  91. mac64 = simple_strtoull((char *)(PIBS_MAC_BASE+PIBS_MAC_OFFSET*3), 0, 16);
  92. memcpy(hold_residual->bi_enet3addr, (char *)&mac64+2, 6);
  93. #endif
  94. return (void *)hold_residual;
  95. }