1
0

0001-upstream-Reproducible-U-Boot-build-support-using-SOURCE_DATE_.patch 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. From f3f431a712729a1af94d01bd1bfde17a252ff02c Mon Sep 17 00:00:00 2001
  2. From: Paul Kocialkowski <contact@paulk.fr>
  3. Date: Sun, 26 Jul 2015 18:48:15 +0200
  4. Subject: [PATCH] Reproducible U-Boot build support, using SOURCE_DATE_EPOCH
  5. In order to achieve reproducible builds in U-Boot, timestamps that are defined
  6. at build-time have to be somewhat eliminated. The SOURCE_DATE_EPOCH environment
  7. variable allows setting a fixed value for those timestamps.
  8. Simply by setting SOURCE_DATE_EPOCH to a fixed value, a number of targets can be
  9. built reproducibly. This is the case for e.g. sunxi devices.
  10. However, some other devices might need some more tweaks, especially regarding
  11. the image generation tools.
  12. Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
  13. ---
  14. Makefile | 7 ++++---
  15. README | 12 ++++++++++++
  16. tools/default_image.c | 21 ++++++++++++++++++++-
  17. 3 files changed, 36 insertions(+), 4 deletions(-)
  18. --- a/README
  19. +++ b/README
  20. @@ -2785,6 +2785,18 @@ Low Level (hardware related) configurati
  21. that is executed before the actual U-Boot. E.g. when
  22. compiling a NAND SPL.
  23. +Reproducible builds
  24. +-------------------
  25. +
  26. +In order to achieve reproducible builds, timestamps used in the U-Boot build
  27. +process have to be set to a fixed value.
  28. +
  29. +This is done using the SOURCE_DATE_EPOCH environment variable.
  30. +SOURCE_DATE_EPOCH is to be set on the build host's shell, not as a configuration
  31. +option for U-Boot or an environment variable in U-Boot.
  32. +
  33. +SOURCE_DATE_EPOCH should be set to a number of seconds since the epoch, in UTC.
  34. +
  35. Building the Software:
  36. ======================
  37. --- a/tools/default_image.c
  38. +++ b/tools/default_image.c
  39. @@ -101,6 +101,9 @@ static void image_set_header (void *ptr,
  40. struct mkimage_params *params)
  41. {
  42. uint32_t checksum;
  43. + char *source_date_epoch;
  44. + struct tm *time_universal;
  45. + time_t time;
  46. image_header_t * hdr = (image_header_t *)ptr;
  47. @@ -109,9 +112,25 @@ static void image_set_header (void *ptr,
  48. sizeof(image_header_t)),
  49. sbuf->st_size - sizeof(image_header_t));
  50. +source_date_epoch = getenv("SOURCE_DATE_EPOCH");
  51. + if (source_date_epoch != NULL) {
  52. + time = (time_t) strtol(source_date_epoch, NULL, 10);
  53. +
  54. + time_universal = gmtime(&time);
  55. + if (time_universal == NULL) {
  56. + fprintf(stderr, "%s: SOURCE_DATE_EPOCH is not valid\n",
  57. + __func__);
  58. + time = 0;
  59. + } else {
  60. + time = mktime(time_universal);
  61. + }
  62. + } else {
  63. + time = sbuf->st_mtime;
  64. + }
  65. +
  66. /* Build new header */
  67. image_set_magic (hdr, IH_MAGIC);
  68. - image_set_time (hdr, sbuf->st_mtime);
  69. + image_set_time(hdr, time);
  70. image_set_size (hdr, sbuf->st_size - sizeof(image_header_t));
  71. image_set_load (hdr, params->addr);
  72. image_set_ep (hdr, params->ep);