From 0a280ff747b44d7a2a62206ea0c25dbcbc5ce20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=BBygowski?= Date: Thu, 29 Feb 2024 11:50:58 +0100 Subject: [PATCH 1/2] lib/rtc: Fix off-by-one error in February day count in leap year MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The month argument passed to rtc_month_days is 0-based, not 1-based. This results in the RTC being reverted to the build date constantly on 29th February 2024. Change-Id: If451e3e3471fef0d429e255cf297050a525ca1a2 Signed-off-by: Michał Żygowski Reviewed-on: https://review.coreboot.org/c/coreboot/+/80790 Reviewed-by: Sean Rhodes Reviewed-by: Paul Menzel Reviewed-by: Felix Singer Reviewed-by: Werner Zeh Tested-by: build bot (Jenkins) Reviewed-by: Felix Held Reviewed-by: Michał Kopeć (cherry picked from commit adf042f6c61e92c181171118768e4309d87146b1) Reviewed-on: https://review.coreboot.org/c/coreboot/+/80823 --- src/lib/rtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/rtc.c b/src/lib/rtc.c index d15148024d..3eeac27665 100644 --- a/src/lib/rtc.c +++ b/src/lib/rtc.c @@ -126,7 +126,7 @@ static int rtc_month_days(unsigned int month, unsigned int year) { int month_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - return month_days[month] + (LEAP_YEAR(year) && month == 2); + return month_days[month] + (LEAP_YEAR(year) && month == 1); } int rtc_invalid(const struct rtc_time *tm) From 0db9c2c827ceade8627887a723022c390f2d800b Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Sat, 16 Mar 2024 01:00:46 +0100 Subject: [PATCH 2/2] genbuild_h: Fix and harden major/minor version parsing Our major version is suddenly two digits long to represent the year. This can't be parsed with the current sed scripts. To make sure that no unparsed data ends up in our major/minor versions, we'll run sed with `-n' and only print the extracted numbers if anything. Also, to allow us to use the version numbers in C code, we strip leading zeros (a leading 0 identifies octal numbers, so for instance 08 for August is not a valid number). This can result in empty major/minor version strings, so we move the default `0' to the final variable expansion. As a bonus, this makes an explicit check if the numbers can be parsed unnecessary. Change-Id: Ie39381a8ef4b971556168b6996efeefe6adf2b14 Reported-by: Christoph Zechner Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/c/coreboot/+/81291 Reviewed-by: Martin L Roth Tested-by: build bot (Jenkins) --- util/genbuild_h/genbuild_h.sh | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/util/genbuild_h/genbuild_h.sh b/util/genbuild_h/genbuild_h.sh index 2bfcc4c3b6..b381ab2776 100755 --- a/util/genbuild_h/genbuild_h.sh +++ b/util/genbuild_h/genbuild_h.sh @@ -6,8 +6,8 @@ DATE="" GITREV="" TIMESOURCE="" XGCCPATH="${XGCCPATH:-util/crossgcc/xgcc/bin/}" -MAJOR_VER="0" -MINOR_VER="0" +MAJOR_VER="" +MINOR_VER="" COREBOOT_VERSION_FILE=".coreboot-version" export LANG=C @@ -36,19 +36,15 @@ elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then TIMESOURCE=git DATE="$(get_git_head_data %ct)" VERSION="$(git describe)" - # Only use the `git describe` output if the tag is in the expected . - # format, e.g. 4.18. Forks of coreboot may have other tags in different formats. - if echo "${VERSION}" | grep -q "^[0-9]\.[0-9][0-9]*"; then - MAJOR_VER="$(echo "${VERSION}" | sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\1/')" - MINOR_VER="$(echo "${VERSION}" | sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\2/')" - fi + MAJOR_VER="$(echo "${VERSION}" | sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\1/p')" + MINOR_VER="$(echo "${VERSION}" | sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\2/p')" else GITREV=Unknown TIMESOURCE="date" DATE=$(LANG="" LC_ALL=C TZ=UTC0 date +%s) if [ -f "${COREBOOT_VERSION_FILE}" ]; then - MAJOR_VER="$(sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\1/' "${COREBOOT_VERSION_FILE}")" - MINOR_VER="$(sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\2/' "${COREBOOT_VERSION_FILE}")" + MAJOR_VER="$(sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\1/p' "${COREBOOT_VERSION_FILE}")" + MINOR_VER="$(sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\2/p' "${COREBOOT_VERSION_FILE}")" fi fi @@ -84,8 +80,8 @@ printf "#define COREBOOT_VERSION_TIMESTAMP %s\n" "${DATE}" printf "#define COREBOOT_ORIGIN_GIT_REVISION \"%s\"\n" "${GITREV}" printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "${COREBOOT_EXTRA_VERSION}" -printf "#define COREBOOT_MAJOR_VERSION %s\n" "${MAJOR_VER}" -printf "#define COREBOOT_MINOR_VERSION %s\n" "${MINOR_VER}" +printf "#define COREBOOT_MAJOR_VERSION %s\n" "${MAJOR_VER:-0}" +printf "#define COREBOOT_MINOR_VERSION %s\n" "${MINOR_VER:-0}" printf "#define COREBOOT_BUILD \"%s\"\n" "$(our_date "${DATE}" "+%a %b %d %H:%M:%S %Z %Y")" printf "#define COREBOOT_BUILD_YEAR_BCD 0x%s\n" "$(our_date "${DATE}" "+%y")" printf "#define COREBOOT_BUILD_MONTH_BCD 0x%s\n" "$(our_date "${DATE}" "+%m")"