0025-firmware-utils-allow-passing-a-specific-MBR-signature-to-ptgen.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Sun, 15 Mar 2015 18:06:49 +0100
  3. Subject: firmware-utils: allow passing a specific MBR signature to ptgen
  4. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
  5. diff --git a/tools/firmware-utils/src/ptgen.c b/tools/firmware-utils/src/ptgen.c
  6. index 0247fd0..6379ed7 100644
  7. --- a/tools/firmware-utils/src/ptgen.c
  8. +++ b/tools/firmware-utils/src/ptgen.c
  9. @@ -28,6 +28,7 @@
  10. #include <stdio.h>
  11. #include <ctype.h>
  12. #include <fcntl.h>
  13. +#include <stdint.h>
  14. #if __BYTE_ORDER == __BIG_ENDIAN
  15. #define cpu_to_le16(x) bswap_16(x)
  16. @@ -124,7 +125,7 @@ static inline unsigned long round_to_kb(long sect) {
  17. }
  18. /* check the partition sizes and write the partition table */
  19. -static int gen_ptable(int nr)
  20. +static int gen_ptable(uint32_t signature, int nr)
  21. {
  22. struct pte pte[4];
  23. unsigned long sect = 0;
  24. @@ -159,6 +160,12 @@ static int gen_ptable(int nr)
  25. return -1;
  26. }
  27. + lseek(fd, 440, SEEK_SET);
  28. + if (write(fd, &signature, sizeof(signature)) != sizeof(signature)) {
  29. + fprintf(stderr, "write failed.\n");
  30. + goto fail;
  31. + }
  32. +
  33. lseek(fd, 446, SEEK_SET);
  34. if (write(fd, pte, sizeof(struct pte) * 4) != sizeof(struct pte) * 4) {
  35. fprintf(stderr, "write failed.\n");
  36. @@ -187,8 +194,9 @@ int main (int argc, char **argv)
  37. char type = 0x83;
  38. int ch;
  39. int part = 0;
  40. + uint32_t signature = 0x5452574F; /* 'OWRT' */
  41. - while ((ch = getopt(argc, argv, "h:s:p:a:t:o:vl:")) != -1) {
  42. + while ((ch = getopt(argc, argv, "h:s:p:a:t:o:vl:S:")) != -1) {
  43. switch (ch) {
  44. case 'o':
  45. filename = optarg;
  46. @@ -221,6 +229,9 @@ int main (int argc, char **argv)
  47. case 'l':
  48. kb_align = (int) strtoul(optarg, NULL, 0) * 2;
  49. break;
  50. + case 'S':
  51. + signature = strtoul(optarg, NULL, 0);
  52. + break;
  53. case '?':
  54. default:
  55. usage(argv[0]);
  56. @@ -229,6 +240,6 @@ int main (int argc, char **argv)
  57. argc -= optind;
  58. if (argc || (heads <= 0) || (sectors <= 0) || !filename)
  59. usage(argv[0]);
  60. -
  61. - return gen_ptable(part);
  62. +
  63. + return gen_ptable(signature, part);
  64. }