ubpar.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * ubparams.c
  3. *
  4. * Generate a u-boot parameter block with correct crc
  5. *
  6. * (C) 1007 Guthrie Consulting
  7. * hamish@prodigi.ch
  8. *
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #ifndef __ASSEMBLY__
  14. #define __ASSEMBLY__
  15. #endif
  16. #define __ASM_STUB_PROCESSOR_H__
  17. #include <config.h>
  18. #undef __ASSEMBLY__
  19. #include <environment.h>
  20. #define XMK_STR(x) #x
  21. #define MK_STR(x) XMK_STR(x)
  22. extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
  23. #if !defined(ENV_CRC)
  24. #define ENV_CRC ~0
  25. #endif
  26. #ifdef LAN_IP
  27. #warning LAN_IP
  28. #else
  29. #warning LAN_IP NOT DEFINED
  30. #endif
  31. #ifdef LAN_SERVERIP
  32. #warning LAN_SERVERIP
  33. #else
  34. #warning LAN_SERVERIP NOT DEFINED
  35. #endif
  36. static char *environment[] = {
  37. "bootdelay=3\0"
  38. "baudrate=115200\0"
  39. "stdin=serial\0"
  40. "stdout=serial\0"
  41. "stderr=serial\0"
  42. "fbargs=setenv bootargs root=/dev/mtdblock3 ro console=/dev/ttyS0,115200,mem=32M\0"
  43. "rdba=setenv bootargs root=/dev/ram rw initrd=0x21200000,6000000 ramdisk_size=20000 console=/dev/ttyS0,115200,mem=32M\0"
  44. "rdram=run rdba; tftp 21000000 uImage; tftp 21200000 root.squashfs; bootm 21000000\0"
  45. "flash=run fbargs; bootm 0xc0042000\0"
  46. "bootargs=setenv bootargs root=/dev/mtdblock3 ro console=/dev/ttyS0,115200,mem=32M\0"
  47. "bootcmd=bootm 0xc0042000\0"
  48. "ipaddr=" MK_STR(LAN_IP) "\0"
  49. "serverip=" MK_STR(LAN_SERVERIP) "\0"
  50. "\0"
  51. };
  52. int main(int argc, char *argv[]) {
  53. env_t *envptr;
  54. char *src, *srcptr;
  55. char *dataptr;
  56. FILE *params;
  57. int argfail = 1;
  58. char newmac[30];
  59. char newser[30];
  60. int paramlen = 0;
  61. int progmac = 0;
  62. int progser = 0;
  63. if (argc < 3) {
  64. printf ("Invalid arguments\n");
  65. return 1;
  66. }
  67. switch (argc) {
  68. case 5:
  69. if (strcmp(argv[3], "--serial") == 0) {
  70. argfail = 0;
  71. sprintf(newser, "serial#=%s", argv[4]);
  72. progser = 1;
  73. }
  74. case 3:
  75. if (strcmp(argv[1], "--mac") == 0) {
  76. argfail = 0;
  77. sprintf(newmac, "ethaddr=%s", argv[2]);
  78. progmac = 1;
  79. }
  80. else
  81. argfail = 1;
  82. }
  83. if (argfail) {
  84. printf("Invalid arguments\n");
  85. return 1;
  86. }
  87. src = srcptr = *environment;
  88. envptr = (env_t *)malloc(CFG_ENV_SIZE);
  89. dataptr = (char *)envptr + ENV_HEADER_SIZE;
  90. while(*srcptr) {
  91. //printf("%d, %s\n", strlen(srcptr), srcptr);
  92. paramlen += strlen(srcptr) + 1;
  93. srcptr += strlen(srcptr) + 1;
  94. }
  95. printf("Make u-boot params\n");
  96. printf("Params size is %d\n", CFG_ENV_SIZE);
  97. memset(envptr, 0, CFG_ENV_SIZE);
  98. memcpy(dataptr, src, paramlen);
  99. dataptr += paramlen;
  100. if (progmac) {
  101. memcpy(dataptr, newmac, strlen(newmac));
  102. dataptr += strlen(newmac) + 1;
  103. }
  104. if (progser) {
  105. memcpy(dataptr, newser, strlen(newser));
  106. dataptr += strlen(newser) + 1;
  107. }
  108. envptr->crc = crc32(0, envptr->data, ENV_SIZE);
  109. params = fopen("/dev/mtd1", "w");
  110. fwrite(envptr, CFG_ENV_SIZE, 1, params);
  111. fclose(params);
  112. free(envptr);
  113. return 0;
  114. }