Skip to contentSkip to conversation

startup: introduce global.endianness variable

PATCH In review Antony Pavlov 2 participants 3 messages Apr 6, 2020 – Apr 14, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 startup: introduce global.endianness variable

The global.endianness variable make 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 c87f2c9339..264833f88c 100644
@@ -591,6 +591,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))
@@ -598,11 +600,19 @@ static int globalvar_init(void)
 
 	globalvar_add_simple("version", UTS_RELEASE);
 
+	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
+		endianness = "big";
+	else
+		endianness = "little";
+
+	globalvar_add_simple("endianness", endianness);
+
 	return 0;
 }
 pure_initcall(globalvar_init);
 
 BAREBOX_MAGICVAR_NAMED(global_version, global.version, "The barebox version");
+BAREBOX_MAGICVAR_NAMED(global_endianness, global.endianness, "The barebox endianness");
 
 /**
  * nvvar_save - save NV variables to persistent environment
Signature · 7 lines
2.25.0


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

On Mon, 6 Apr 2020 15:13:25 +0300
Antony Pavlov <[email protected]> wrote:

Hi Sascha,

The global.version (and global.endianness) variable can be easely modified by user.
Can we make it immutable?

Signature · 2 lines
Best regards,
  Antony Pavlov
Quoted 45 lines

The global.endianness variable make 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 c87f2c9339..264833f88c 100644
@@ -591,6 +591,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))
@@ -598,11 +600,19 @@ static int globalvar_init(void)
 
 	globalvar_add_simple("version", UTS_RELEASE);
 
+	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
+		endianness = "big";
+	else
+		endianness = "little";
+
+	globalvar_add_simple("endianness", endianness);
+
 	return 0;
 }
 pure_initcall(globalvar_init);
 
 BAREBOX_MAGICVAR_NAMED(global_version, global.version, "The barebox version");
+BAREBOX_MAGICVAR_NAMED(global_endianness, global.endianness, "The barebox endianness");
 
 /**
  * nvvar_save - save NV variables to persistent environment
Signature · 1 line
2.25.0

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

#2 lore raw
Quoted 8 lines · Antony Pavlov

On Mon, 6 Apr 2020 15:13:25 +0300
Antony Pavlov <[email protected]> wrote:

Hi Sascha,

The global.version (and global.endianness) variable can be easely modified by user.
Can we make it immutable?

There's currently no way to make variables registered with globalvar_add_* readonly. What you can do is:

	dev_add_param_fixed(&global_device, "version", UTS_RELEASE);

It would be nice to have a little globalvar_add_fixed() function which does that. Besides the endianess it would be good to use it for the version string as well.

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