summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-08-14 21:54:40 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-08-16 08:40:37 +0200
commit774580c2bde4c8b126eed0a80d00cb22cbfb3193 (patch)
tree7f0fdbc28707c5211391c06ad6bca4632067d0c4
parent775ba3c093be186d345ab7132116fd0ed3e53ba2 (diff)
downloadbarebox-774580c2bde4c8b126eed0a80d00cb22cbfb3193.tar.gz
barebox-774580c2bde4c8b126eed0a80d00cb22cbfb3193.tar.xz
Make hostname available to C Code
The boards often have a sane default for the hostname. Provide a C function for setting/getting it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--common/misc.c34
-rw-r--r--include/common.h2
-rw-r--r--net/dhcp.c1
3 files changed, 36 insertions, 1 deletions
diff --git a/common/misc.c b/common/misc.c
index bb7d4479fa..4ec0e22aaa 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -19,6 +19,9 @@
#include <common.h>
#include <errno.h>
#include <malloc.h>
+#include <magicvar.h>
+#include <globalvar.h>
+#include <environment.h>
int errno;
EXPORT_SYMBOL(errno);
@@ -149,3 +152,34 @@ const char *barebox_get_model(void)
return CONFIG_BOARDINFO;
}
EXPORT_SYMBOL(barebox_get_model);
+
+BAREBOX_MAGICVAR_NAMED(global_model, global.model, "Product name of this hardware");
+
+static char *hostname;
+
+/*
+ * The hostname is supposed to be the shortname of a board. It should
+ * contain only lowercase letters, numbers, '-', '_'. No whitespaces
+ * allowed.
+ */
+void barebox_set_hostname(const char *__hostname)
+{
+ if (IS_ENABLED(CONFIG_GLOBALVAR)) {
+ globalvar_add_simple("hostname", __hostname);
+ } else {
+ free(hostname);
+ hostname = xstrdup(__hostname);
+ }
+}
+
+const char *barebox_get_hostname(void)
+{
+ if (IS_ENABLED(CONFIG_GLOBALVAR))
+ return getenv("global.hostname");
+
+ return hostname;
+}
+EXPORT_SYMBOL(barebox_get_hostname);
+
+BAREBOX_MAGICVAR_NAMED(global_hostname, global.hostname,
+ "shortname of the board. Also used as hostname for DHCP requests");
diff --git a/include/common.h b/include/common.h
index 7d05d8ba3b..7173efb10b 100644
--- a/include/common.h
+++ b/include/common.h
@@ -236,6 +236,8 @@ static inline void barebox_banner(void) {}
const char *barebox_get_model(void);
void barebox_set_model(const char *);
+const char *barebox_get_hostname(void);
+void barebox_set_hostname(const char *);
#define IOMEM(addr) ((void __force __iomem *)(addr))
diff --git a/net/dhcp.c b/net/dhcp.c
index cafefcb402..ff54924762 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -830,7 +830,6 @@ BAREBOX_CMD_START(dhcp)
BAREBOX_CMD_COMPLETE(empty_complete)
BAREBOX_CMD_END
-BAREBOX_MAGICVAR_NAMED(global_hostname, global.hostname, "hostname to send or returned from DHCP request");
BAREBOX_MAGICVAR_NAMED(global_dhcp_bootfile, global.dhcp.bootfile, "bootfile returned from DHCP request");
BAREBOX_MAGICVAR_NAMED(global_dhcp_rootpath, global.dhcp.rootpath, "rootpath returned from DHCP request");
BAREBOX_MAGICVAR_NAMED(global_dhcp_vendor_id, global.dhcp.vendor_id, "vendor id to send to the DHCP server");