Skip to contentSkip to conversation

u-boot: Add UBOOT_LOCALVERSION_AUTO support

PATCH In review Otavio Salvador 3 participants 5 messages Mar 31, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 u-boot: Add UBOOT_LOCALVERSION_AUTO support

Add the Git revision used for the build. It is very useful especially when using custom or vendor U-Boot forks so we can map a binary to a specific source revision. Valid values are "0" or "1".

This is based on a class which has been in use in meta-freescale BSP for years and has been very useful especially for custom U-Boot releases as it allow we to know the exact Git revision used for the binary.

---

 meta/recipes-bsp/u-boot/u-boot.inc | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
meta/recipes-bsp/u-boot/u-boot.inc +18 -6
index b13db224732..39d35500e11 100644
@@ -24,6 +24,11 @@ PACKAGECONFIG[openssl] = ",,openssl-native"
 # file already exists it will not be overwritten.
 UBOOT_LOCALVERSION ?= ""
 
+# Add the Git revision used for the build. It is very useful especially when
+# using custom or vendor U-Boot forks so we can map a binary to a specific
+# source revision. Valid values are "0" or "1".
+UBOOT_LOCALVERSION_AUTO ?= "0"
+
 # Some versions of u-boot use .bin and others use .img.  By default use .bin
 # but enable individual recipes to change this value.
 UBOOT_SUFFIX ??= "bin"
@@ -84,6 +89,19 @@ do_configure () {
             oe_runmake -C ${S} O=${B} oldconfig
         fi
         merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
+
+        if [ ! -e ${B}/.scmversion -a ! -e ${S}/.scmversion ]; then
+            if [ "${UBOOT_LOCALVERSION_AUTO}" = "1" ]; then
+                # Add GIT revision to the local version
+                head=`cd ${S} ; git rev-parse --verify --short HEAD 2> /dev/null`
+                printf "%s%s%s" "${UBOOT_LOCALVERSION}" +g $head > ${S}/.scmversion
+                printf "%s%s%s" "${UBOOT_LOCALVERSION}" +g $head > ${B}/.scmversion
+            else
+                printf "%s" "${UBOOT_LOCALVERSION}" > ${S}/.scmversion
+                printf "%s" "${UBOOT_LOCALVERSION}" > ${B}/.scmversion
+            fi
+        fi
+
         cml1_do_configure
     else
         DEVTOOL_DISABLE_MENUCONFIG=true
@@ -99,12 +117,6 @@ do_compile () {
 	unset CFLAGS
 	unset CPPFLAGS
 
-	if [ ! -e ${B}/.scmversion -a ! -e ${S}/.scmversion ]
-	then
-		echo ${UBOOT_LOCALVERSION} > ${B}/.scmversion
-		echo ${UBOOT_LOCALVERSION} > ${S}/.scmversion
-	fi
-
     if [ -n "${UBOOT_CONFIG}" ]
     then
         unset i j k
Signature · 1 line
2.26.0
#1 lore raw
Quoted 3 lines · Otavio Salvador

Add the Git revision used for the build. It is very useful especially when using custom or vendor U-Boot forks so we can map a binary to a specific source revision. Valid values are "0" or "1".

Well, UBOOT_LOCALVERSION was originally added specifically for this purpose - to be able to append git hash.

Quoted 3 lines

This is based on a class which has been in use in meta-freescale BSP for years and has been very useful especially for custom U-Boot releases as it allow we to know the exact Git revision used for the binary.

And in meta-ti BSP we've used for many years:
UBOOT_LOCALVERSION = "-g${@get_git_revision('${S}')}"

And get_git_revision() just calls "git rev-parse HEAD"

So, it seems a bit redundant to add another variable for this...

Signature · 1 line
Denys
Quoted 60 lines

---

 meta/recipes-bsp/u-boot/u-boot.inc | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
meta/recipes-bsp/u-boot/u-boot.inc +18 -6
index b13db224732..39d35500e11 100644
@@ -24,6 +24,11 @@ PACKAGECONFIG[openssl] = ",,openssl-native"
 # file already exists it will not be overwritten.
 UBOOT_LOCALVERSION ?= ""
 
+# Add the Git revision used for the build. It is very useful especially when
+# using custom or vendor U-Boot forks so we can map a binary to a specific
+# source revision. Valid values are "0" or "1".
+UBOOT_LOCALVERSION_AUTO ?= "0"
+
 # Some versions of u-boot use .bin and others use .img.  By default use .bin
 # but enable individual recipes to change this value.
 UBOOT_SUFFIX ??= "bin"
@@ -84,6 +89,19 @@ do_configure () {
             oe_runmake -C ${S} O=${B} oldconfig
         fi
         merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
+
+        if [ ! -e ${B}/.scmversion -a ! -e ${S}/.scmversion ]; then
+            if [ "${UBOOT_LOCALVERSION_AUTO}" = "1" ]; then
+                # Add GIT revision to the local version
+                head=`cd ${S} ; git rev-parse --verify --short HEAD 2> /dev/null`
+                printf "%s%s%s" "${UBOOT_LOCALVERSION}" +g $head > ${S}/.scmversion
+                printf "%s%s%s" "${UBOOT_LOCALVERSION}" +g $head > ${B}/.scmversion
+            else
+                printf "%s" "${UBOOT_LOCALVERSION}" > ${S}/.scmversion
+                printf "%s" "${UBOOT_LOCALVERSION}" > ${B}/.scmversion
+            fi
+        fi
+
         cml1_do_configure
     else
         DEVTOOL_DISABLE_MENUCONFIG=true
@@ -99,12 +117,6 @@ do_compile () {
 	unset CFLAGS
 	unset CPPFLAGS
 
-	if [ ! -e ${B}/.scmversion -a ! -e ${S}/.scmversion ]
-	then
-		echo ${UBOOT_LOCALVERSION} > ${B}/.scmversion
-		echo ${UBOOT_LOCALVERSION} > ${S}/.scmversion
-	fi
-
     if [ -n "${UBOOT_CONFIG}" ]
     then
         unset i j k
Signature · 1 line
2.26.0
#2 lore raw

Hello Denys,

Quoted 7 lines · Denys Dmytriyenko
Quoted 3 lines · Otavio Salvador

Add the Git revision used for the build. It is very useful especially when using custom or vendor U-Boot forks so we can map a binary to a specific source revision. Valid values are "0" or "1".

Well, UBOOT_LOCALVERSION was originally added specifically for this purpose - to be able to append git hash.

Not really; it kinda of maps to what Linux kernel provides and it is a "suffix" for the version. For example "-ti" to imply it came from a Texas Instruments fork.

Quoted 10 lines
Quoted 3 lines

This is based on a class which has been in use in meta-freescale BSP for years and has been very useful especially for custom U-Boot releases as it allow we to know the exact Git revision used for the binary.

And in meta-ti BSP we've used for many years:
UBOOT_LOCALVERSION = "-g${@get_git_revision('${S}')}"

And get_git_revision() just calls "git rev-parse HEAD"

So, it seems a bit redundant to add another variable for this...

How I use this is:

UBOOT_LOCALVERSION = "-updatehub"
UBOOT_LOCALVERSION_AUTO = "1"

I think it is way easier for users to do that. Using inline Python code is possible but it is not something I qualify as user friendly.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9 9981-7854          Mobile: +1 (347) 903-9750
#3 lore raw
Quoted 8 lines · Otavio Salvador

Hello Denys,

Quoted 5 lines · Denys Dmytriyenko
Quoted 3 lines · Otavio Salvador

Add the Git revision used for the build. It is very useful especially when using custom or vendor U-Boot forks so we can map a binary to a specific source revision. Valid values are "0" or "1".

Quoted 6 lines
Quoted 2 lines

Well, UBOOT_LOCALVERSION was originally added specifically for this purpose - to be able to append git hash.

Not really; it kinda of maps to what Linux kernel provides and it is a "suffix" for the version. For example "-ti" to imply it came from a Texas Instruments fork.

There are multiple uses and you can append anything you want. Here's the original patch that specifically mentions adding git hash, as an example:
https://lists.openembedded.org/g/openembedded-core/topic/72204283

Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

This is based on a class which has been in use in meta-freescale BSP for years and has been very useful especially for custom U-Boot releases as it allow we to know the exact Git revision used for the binary.

And in meta-ti BSP we've used for many years:
UBOOT_LOCALVERSION = "-g${@get_git_revision('${S}')}"

And get_git_revision() just calls "git rev-parse HEAD"

So, it seems a bit redundant to add another variable for this...

Quoted 7 lines

How I use this is:

UBOOT_LOCALVERSION = "-updatehub"
UBOOT_LOCALVERSION_AUTO = "1"

I think it is way easier for users to do that. Using inline Python code is possible but it is not something I qualify as user friendly.

UBOOT_LOCALVERSION = "-updatehub-g${SRCPV}"

Signature · 1 line
Denys
#4 lore raw
Quoted 31 lines · Denys Dmytriyenko
Quoted 6 lines · Otavio Salvador
Quoted 5 lines · Denys Dmytriyenko
Quoted 3 lines · Otavio Salvador

Add the Git revision used for the build. It is very useful especially when using custom or vendor U-Boot forks so we can map a binary to a specific source revision. Valid values are "0" or "1".

Quoted 6 lines
Quoted 2 lines

Well, UBOOT_LOCALVERSION was originally added specifically for this purpose - to be able to append git hash.

Not really; it kinda of maps to what Linux kernel provides and it is a "suffix" for the version. For example "-ti" to imply it came from a Texas Instruments fork.

There are multiple uses and you can append anything you want. Here's the original patch that specifically mentions adding git hash, as an example:
https://lists.openembedded.org/g/openembedded-core/topic/72204283

Quoted 13 lines
Quoted 10 lines
Quoted 3 lines

This is based on a class which has been in use in meta-freescale BSP for years and has been very useful especially for custom U-Boot releases as it allow we to know the exact Git revision used for the binary.

And in meta-ti BSP we've used for many years:
UBOOT_LOCALVERSION = "-g${@get_git_revision('${S}')}"

And get_git_revision() just calls "git rev-parse HEAD"

So, it seems a bit redundant to add another variable for this...

How I use this is:

Quoted 7 lines
Quoted 5 lines

UBOOT_LOCALVERSION = "-updatehub"
UBOOT_LOCALVERSION_AUTO = "1"

I think it is way easier for users to do that. Using inline Python code is possible but it is not something I qualify as user friendly.

UBOOT_LOCALVERSION = "-updatehub-g${SRCPV}"

U-Boot 2020.01-updatehub-AUTOINC+d228123da8 (Mar 20 2020 - 17:05:55 +0000)

This is kinda ugly. Also the old behaviour is still supported.

Let's see what others from community think about it.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9 9981-7854          Mobile: +1 (347) 903-9750