bin2hex.c 791 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. int main( int argc, const char * argv [] )
  6. {
  7. const char * varname;
  8. int i = 0;
  9. int c;
  10. int id = 0;
  11. if(argv[1] && strcmp(argv[1],"-i")==0)
  12. {
  13. argv++;
  14. argc--;
  15. id=1;
  16. }
  17. if(argc==1)
  18. {
  19. fprintf(stderr, "bin2hex: [-i] firmware\n");
  20. exit(1);
  21. }
  22. varname = argv[1];
  23. printf( "/* automatically generated by bin2hex */\n" );
  24. printf( "static unsigned char %s [] %s =\n{\n", varname , id?"__initdata":"");
  25. while ( ( c = getchar( ) ) != EOF )
  26. {
  27. if ( i != 0 && i % 10 == 0 )
  28. printf( "\n" );
  29. printf( "0x%02lx,", c & 0xFFl );
  30. i++;
  31. }
  32. printf( "};\nstatic int %sLen = %d;\n", varname, i );
  33. return 0;
  34. }