[U-Boot] [U-Boot, v2] Reproducible U-Boot build support, using SOURCE_DATE_EPOCH

Chris Packham
2015-07-31T05:25:29Z

On Fri, Jul 31, 2015 at 2:54 PM, Bin Meng <bmeng.cn@gmail.com> wrote:
> Hi,
>
> On Tue, Jul 28, 2015 at 11:00 PM, Tom Rini <trini@konsulko.com> wrote:
>> On Sun, Jul 26, 2015 at 06:48:15PM +0200, Paul Kocialkowski wrote:
>>
>>> In order to achieve reproducible builds in U-Boot, timestamps that are defined
>>> at build-time have to be somewhat eliminated. The SOURCE_DATE_EPOCH environment
>>> variable allows setting a fixed value for those timestamps.
>>>
>>> Simply by setting SOURCE_DATE_EPOCH to a fixed value, a number of targets can be
>>> built reproducibly. This is the case for e.g. sunxi devices.
>>>
>>> However, some other devices might need some more tweaks, especially regarding
>>> the image generation tools.
>>>
>>> Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
>>
>> Applied to u-boot/master, thanks!
>>
>> --
>
> This commit breaks the following commit:
>
> commit f3f431a712729a1af94d01bd1bfde17a252ff02c
> Author: Chris Packham <judge.packham@gmail.com>
> Date: Sun May 10 21:02:09 2015 +1200
>
> Makefile: Add U_BOOT_TZ and include in version
>
> Define U_BOOT_TZ alongside U_BOOT_TIME and U_BOOT_DATE and use it to
> include the timezone in the version output.
>
> Acked-by: Simon Glass <sjg@chromium.org>
> Signed-off-by: Chris Packham <judge.packham@gmail.com>
>
> Before this commit I have:
> U-Boot 2015.07-00345-g9c57487 (Jul 31 2015 - 10:49:31 +0800)
>
> After this commit I have:
> U-Boot 2015.07-00346-gf3f431a (Jul 31 2015 - 02:50:54 +0000)
>
> As you see: the timezone information is missing, and U-Boot's
> timestamp is now GMT+0 (the correct one should be GMT+8)
>
> Is this intended behavior? Or if not, please fix it.
>
> Regards,
> Bin

The problem is that date -u implies UTC. So +0000 is right if you do
want the time to be displayed in UTC (for me living at +12/+13 UTC
makes my head hurt because all the dates are yesterday).

The intent of f3f431a7 was to reflect the timezone that the build
machine was set to. Dropping the -u would probably be sufficient but
perhaps it would be better to make whole lot conditional on
SOURCE_DATE_EPOCH being set. Something like this (untested, apologies
gmail web interface)

ifneq ($(SOURCE_DATE_EPOCH),)
define filechk_timestamp.h
(SOURCE_DATE="$(SOURCE_DATE_EPOCH)"; \
LC_ALL=C date -u -d "$${SOURCE_DATE}" +'#define U_BOOT_DATE "%b
%d %C%y"'; \
LC_ALL=C date -u -d "$${SOURCE_DATE}" +'#define U_BOOT_TIME "%T"'; \
LC_ALL=C date -u -d "$${SOURCE_DATE}" +'#define U_BOOT_TZ "%z"' )
endef
else
define filechk_timestamp.h
(LC_ALL=C date +'#define U_BOOT_DATE "%b %d %C%y"'; \
LC_ALL=C date +'#define U_BOOT_TIME "%T"'; \
LC_ALL=C date +'#define U_BOOT_TZ "%z"')
endef
endif