mkpiggy.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* ----------------------------------------------------------------------- *
  2. *
  3. * Copyright (C) 2009 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version
  7. * 2 as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * H. Peter Anvin <hpa@linux.intel.com>
  20. *
  21. * -----------------------------------------------------------------------
  22. *
  23. * Outputs a small assembly wrapper with the appropriate symbols defined.
  24. *
  25. */
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <inttypes.h>
  30. #include <tools/le_byteshift.h>
  31. int main(int argc, char *argv[])
  32. {
  33. uint32_t olen;
  34. long ilen;
  35. FILE *f = NULL;
  36. int retval = 1;
  37. if (argc < 2) {
  38. fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
  39. goto bail;
  40. }
  41. /* Get the information for the compressed kernel image first */
  42. f = fopen(argv[1], "r");
  43. if (!f) {
  44. perror(argv[1]);
  45. goto bail;
  46. }
  47. if (fseek(f, -4L, SEEK_END)) {
  48. perror(argv[1]);
  49. }
  50. if (fread(&olen, sizeof(olen), 1, f) != 1) {
  51. perror(argv[1]);
  52. goto bail;
  53. }
  54. ilen = ftell(f);
  55. olen = get_unaligned_le32(&olen);
  56. printf(".section \".rodata..compressed\",\"a\",@progbits\n");
  57. printf(".globl z_input_len\n");
  58. printf("z_input_len = %lu\n", ilen);
  59. printf(".globl z_output_len\n");
  60. printf("z_output_len = %lu\n", (unsigned long)olen);
  61. printf(".globl input_data, input_data_end\n");
  62. printf("input_data:\n");
  63. printf(".incbin \"%s\"\n", argv[1]);
  64. printf("input_data_end:\n");
  65. retval = 0;
  66. bail:
  67. if (f)
  68. fclose(f);
  69. return retval;
  70. }