makefw.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Xilinx firmware convertor program.
  2. *
  3. * Written by Jim Dixon <jim@lambdatel.com>.
  4. *
  5. * Copyright (C) 2001 Jim Dixon / Zapata Telephony.
  6. * Copyright (C) 2001-2008 Digium, Inc.
  7. *
  8. * All rights reserved.
  9. *
  10. */
  11. /*
  12. * See http://www.asterisk.org for more information about
  13. * the Asterisk project. Please do not directly contact
  14. * any of the maintainers of this project for assistance;
  15. * the project provides a web site, mailing lists and IRC
  16. * channels for your use.
  17. *
  18. * This program is free software, distributed under the terms of
  19. * the GNU General Public License Version 2 as published by the
  20. * Free Software Foundation. See the LICENSE file included with
  21. * this program for more details.
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #define SWATH 12
  27. int main(int argc, char *argv[])
  28. {
  29. FILE *fp;
  30. int i,j,nbytes;
  31. unsigned char c;
  32. char buf[300];
  33. if (argc < 3)
  34. {
  35. puts("Usage... makefw filename.rbt array_name");
  36. exit(1);
  37. }
  38. fp = fopen(argv[1],"r");
  39. if (!fp)
  40. {
  41. perror("bit file open");
  42. exit(1);
  43. }
  44. nbytes = 0;
  45. printf("static unsigned char %s[] = {\n",argv[2]);
  46. i = 0;
  47. while(fgets(buf,sizeof(buf) - 1,fp))
  48. {
  49. if (!buf[0]) continue;
  50. if (buf[strlen(buf) - 1] < ' ') buf[strlen(buf) - 1] = 0;
  51. if (!buf[0]) continue;
  52. if (buf[strlen(buf) - 1] < ' ') buf[strlen(buf) - 1] = 0;
  53. if (!buf[0]) continue;
  54. if (strlen(buf) < 32) continue;
  55. if ((buf[0] != '0') && (buf[0] != '1')) continue;
  56. c = 0;
  57. for(j = 0; buf[j]; j++)
  58. {
  59. if (buf[j] > '0') c |= 1 << (j & 7);
  60. if ((j & 7) == 7)
  61. {
  62. nbytes++;
  63. if (i) printf(",");
  64. printf("0x%02x",c);
  65. if (i++ == SWATH) {
  66. printf(",\n");
  67. i = 0;
  68. }
  69. c = 0;
  70. }
  71. }
  72. }
  73. printf("\n};\n\n");
  74. fprintf(stderr,"Loaded %d bytes from file\n",nbytes);
  75. fclose(fp);
  76. exit(0);
  77. }