mkpiggy.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * Compute the desired load offset from a compressed program; outputs
  24. * a small assembly wrapper with the appropriate symbols defined.
  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. unsigned long offs;
  36. FILE *f;
  37. if (argc < 2) {
  38. fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
  39. return 1;
  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. return 1;
  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. return 1;
  53. }
  54. ilen = ftell(f);
  55. olen = get_unaligned_le32(&olen);
  56. fclose(f);
  57. /*
  58. * Now we have the input (compressed) and output (uncompressed)
  59. * sizes, compute the necessary decompression offset...
  60. */
  61. offs = (olen > ilen) ? olen - ilen : 0;
  62. offs += olen >> 12; /* Add 8 bytes for each 32K block */
  63. offs += 64*1024 + 128; /* Add 64K + 128 bytes slack */
  64. offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
  65. printf(".section \".rodata..compressed\",\"a\",@progbits\n");
  66. printf(".globl z_input_len\n");
  67. printf("z_input_len = %lu\n", ilen);
  68. printf(".globl z_output_len\n");
  69. printf("z_output_len = %lu\n", (unsigned long)olen);
  70. printf(".globl z_extract_offset\n");
  71. printf("z_extract_offset = 0x%lx\n", offs);
  72. /* z_extract_offset_negative allows simplification of head_32.S */
  73. printf(".globl z_extract_offset_negative\n");
  74. printf("z_extract_offset_negative = -0x%lx\n", offs);
  75. printf(".globl input_data, input_data_end\n");
  76. printf("input_data:\n");
  77. printf(".incbin \"%s\"\n", argv[1]);
  78. printf("input_data_end:\n");
  79. return 0;
  80. }