Skip to contentSkip to conversation

startup: introduce global.endianness variable

PATCH Superseded Antony Pavlov 2 participants 5 messages Apr 26, 2021 – May 11, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 startup: introduce global.endianness variable

The global.endianness variable makes it possible
to determine current endian mode from command
line or from script on bi-endian capable system.

---
 common/globalvar.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
common/globalvar.c +10 -0
index a55b38b00f..75ce6331b7 100644
@@ -641,6 +641,8 @@ int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
 
 static int globalvar_init(void)
 {
+	const char *endianness;
+
 	register_device(&global_device);
 
 	if (IS_ENABLED(CONFIG_NVVAR))
@@ -651,6 +653,13 @@ static int globalvar_init(void)
 	if (strlen(buildsystem_version_string) > 0)
 		globalvar_add_simple("buildsystem.version", buildsystem_version_string);
 
+	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
+		endianness = "big";
+	else
+		endianness = "little";
+
+	globalvar_add_simple("endianness", endianness);
+
 	return 0;
 }
 pure_initcall(globalvar_init);
@@ -658,6 +667,7 @@ pure_initcall(globalvar_init);
 BAREBOX_MAGICVAR(global.version, "The barebox version");
 BAREBOX_MAGICVAR(global.buildsystem.version,
 		 "version of buildsystem barebox was built with");
+BAREBOX_MAGICVAR(global.endianness, "The barebox endianness");
 
 /**
  * nvvar_save - save NV variables to persistent environment
Signature · 7 lines
2.31.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

On Mon, 26 Apr 2021 17:30:25 +0300
Antony Pavlov <[email protected]> wrote:

ping

Quoted 47 lines

The global.endianness variable makes it possible
to determine current endian mode from command
line or from script on bi-endian capable system.

---
 common/globalvar.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
common/globalvar.c +10 -0
index a55b38b00f..75ce6331b7 100644
@@ -641,6 +641,8 @@ int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
 
 static int globalvar_init(void)
 {
+	const char *endianness;
+
 	register_device(&global_device);
 
 	if (IS_ENABLED(CONFIG_NVVAR))
@@ -651,6 +653,13 @@ static int globalvar_init(void)
 	if (strlen(buildsystem_version_string) > 0)
 		globalvar_add_simple("buildsystem.version", buildsystem_version_string);
 
+	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
+		endianness = "big";
+	else
+		endianness = "little";
+
+	globalvar_add_simple("endianness", endianness);
+
 	return 0;
 }
 pure_initcall(globalvar_init);
@@ -658,6 +667,7 @@ pure_initcall(globalvar_init);
 BAREBOX_MAGICVAR(global.version, "The barebox version");
 BAREBOX_MAGICVAR(global.buildsystem.version,
 		 "version of buildsystem barebox was built with");
+BAREBOX_MAGICVAR(global.endianness, "The barebox endianness");
 
 /**
  * nvvar_save - save NV variables to persistent environment
Signature · 1 line
2.31.1
Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw
In reply to Antony Pavlov

Hi Antony,

Quoted 23 lines · Antony Pavlov

The global.endianness variable makes it possible
to determine current endian mode from command
line or from script on bi-endian capable system.

---
 common/globalvar.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
common/globalvar.c +2 -0
index a55b38b00f..75ce6331b7 100644
@@ -641,6 +641,8 @@ int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
 
 static int globalvar_init(void)
 {
+	const char *endianness;
+
 	register_device(&global_device);
 
 	if (IS_ENABLED(CONFIG_NVVAR))

common/globalvar.c static int globalvar_init(void) · line 659

Quoted 7 lines
common/globalvar.c +4 -0
@@ -651,6 +653,13 @@ static int globalvar_init(void)
 	if (strlen(buildsystem_version_string) > 0)
 		globalvar_add_simple("buildsystem.version", buildsystem_version_string);
 
+	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
+		endianness = "big";
+	else
+		endianness = "little";

PowerPC is for sure big endian, but doesn't set CONFIG_CPU_BIG_ENDIAN, so will be erroneously be identified as little endian with this patch. Either you fix that or depend on something like #if __BYTE_ORDER == __LITTLE_ENDIAN

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

On Mon, 3 May 2021 13:16:43 +0200
Sascha Hauer <[email protected]> wrote:

Hi Sascha!

Quoted 27 lines · Antony Pavlov
Quoted 26 lines

The global.endianness variable makes it possible
to determine current endian mode from command
line or from script on bi-endian capable system.

---
 common/globalvar.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
common/globalvar.c +2 -0
index a55b38b00f..75ce6331b7 100644
@@ -641,6 +641,8 @@ int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
 
 static int globalvar_init(void)
 {
+	const char *endianness;
+
 	register_device(&global_device);
 
 	if (IS_ENABLED(CONFIG_NVVAR))
@@ -651,6 +653,13 @@ static int globalvar_init(void)
 	if (strlen(buildsystem_version_string) > 0)
 		globalvar_add_simple("buildsystem.version", buildsystem_version_string);
 
Quoted 9 lines

common/globalvar.c static int globalvar_init(void) · line 659

Quoted 4 lines
common/globalvar.c +4 -0
+	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
+		endianness = "big";
+	else
+		endianness = "little";

PowerPC is for sure big endian, but doesn't set CONFIG_CPU_BIG_ENDIAN, so will be erroneously be identified as little endian with this patch. Either you fix that or depend on something like #if __BYTE_ORDER == __LITTLE_ENDIAN

Barebox don't use "__BYTE_ORDER == __*_ENDIAN" solution.

Please see include/envfs.h:

#ifdef __BAREBOX__
# ifdef __LITTLE_ENDIAN
# define ENVFS_ORDER_LITTLE
# elif defined __BIG_ENDIAN
# define ENVFS_ORDER_BIG
# else
# error "could not determine byte order"
# endif
#else
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define ENVFS_ORDER_LITTLE
# elif __BYTE_ORDER == __BIG_ENDIAN
# define ENVFS_ORDER_BIG
# else
# error "could not determine byte order"
# endif
#endif

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw
Quoted 42 lines · Antony Pavlov

On Mon, 3 May 2021 13:16:43 +0200
Sascha Hauer <[email protected]> wrote:

Hi Sascha!

Quoted 27 lines · Antony Pavlov
Quoted 26 lines

The global.endianness variable makes it possible
to determine current endian mode from command
line or from script on bi-endian capable system.

---
 common/globalvar.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
common/globalvar.c +2 -0
index a55b38b00f..75ce6331b7 100644
@@ -641,6 +641,8 @@ int globalvar_add_simple_ip(const char *name, IPaddr_t *ip)
 
 static int globalvar_init(void)
 {
+	const char *endianness;
+
 	register_device(&global_device);
 
 	if (IS_ENABLED(CONFIG_NVVAR))
@@ -651,6 +653,13 @@ static int globalvar_init(void)
 	if (strlen(buildsystem_version_string) > 0)
 		globalvar_add_simple("buildsystem.version", buildsystem_version_string);
 
Quoted 9 lines

common/globalvar.c static int globalvar_init(void) · line 659

Quoted 4 lines
common/globalvar.c +4 -0
+	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
+		endianness = "big";
+	else
+		endianness = "little";

PowerPC is for sure big endian, but doesn't set CONFIG_CPU_BIG_ENDIAN, so will be erroneously be identified as little endian with this patch. Either you fix that or depend on something like #if __BYTE_ORDER == __LITTLE_ENDIAN

Quoted 3 lines

Barebox don't use "__BYTE_ORDER == __*_ENDIAN" solution.

Please see include/envfs.h:

Right, then #ifdef __LITTLE_ENDIAN would be correct.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox