#include <sys/fcntl.h>
#include <sys/stat.h>
+#include <file/file.h>
#include <talloc/talloc.h>
#include <list/list.h>
#include <log/log.h>
return rc;
}
+static int get_sysinfo(struct platform *p, struct system_info *sysinfo)
+{
+ struct platform_powerpc *platform = p->platform_data;
+ int len, rc;
+ char *buf;
+
+ rc = read_file(platform, "/proc/device_tree/model", &buf, &len);
+ if (rc == 0)
+ sysinfo->type = talloc_steal(sysinfo, buf);
+
+ rc = read_file(platform, "/proc/device_tree/system-id", &buf, &len);
+ if (rc == 0)
+ sysinfo->identifier = talloc_steal(sysinfo, buf);
+
+ return 0;
+}
+
static bool probe(struct platform *p, void *ctx)
{
struct platform_powerpc *platform;
return true;
}
+
static struct platform platform_powerpc = {
.name = "powerpc",
.dhcp_arch_id = 0x000e,
.probe = probe,
.load_config = load_config,
.save_config = save_config,
+ .get_sysinfo = get_sysinfo,
};
register_platform(platform_powerpc);
return platform;
}
+int platform_get_sysinfo(struct system_info *info)
+{
+ if (platform && platform->get_sysinfo)
+ return platform->get_sysinfo(platform, info);
+ return -1;
+}
+
int config_set(struct config *newconfig)
{
int rc;
bool (*probe)(struct platform *, void *);
int (*load_config)(struct platform *, struct config *);
int (*save_config)(struct platform *, struct config *);
+ int (*get_sysinfo)(struct platform *, struct system_info *);
uint16_t dhcp_arch_id;
void *platform_data;
};
int platform_init(void *ctx);
int platform_fini(void);
const struct platform *platform_get(void);
+int platform_get_sysinfo(struct system_info *info);
/* configuration interface */
const struct config *config_get(void);
#include <process/process.h>
#include "discover-server.h"
+#include "platform.h"
#include "sysinfo.h"
static struct system_info *sysinfo;
static struct discover_server *server;
-static const char *sysinfo_helper = PKG_LIBEXEC_DIR "/pb-sysinfo";
-
const struct system_info *system_info_get(void)
{
return sysinfo;
discover_server_notify_system_info(server, sysinfo);
}
-static void system_info_set_identifier(struct system_info *info)
-{
- struct process *process;
- int rc;
- const char *argv[] = {
- sysinfo_helper, NULL, NULL,
- };
-
- process = process_create(info);
- process->path = sysinfo_helper;
- process->argv = argv;
- process->keep_stdout = true;
-
- argv[1] = "--type";
- rc = process_run_sync(process);
-
- if (!rc) {
- info->type = talloc_strndup(info, process->stdout_buf,
- process->stdout_len);
- }
-
- argv[1] = "--id";
- rc = process_run_sync(process);
-
- if (!rc) {
- info->identifier = talloc_strndup(info, process->stdout_buf,
- process->stdout_len);
- }
-
- process_release(process);
-}
-
void system_info_init(struct discover_server *s)
{
server = s;
sysinfo = talloc_zero(server, struct system_info);
- system_info_set_identifier(sysinfo);
+ platform_get_sysinfo(sysinfo);
}
#!/bin/sh
case "$1" in
-'--type')
- tr -d '\0' < /proc/device-tree/model
- ;;
-'--id')
- tr -d '\0' < /proc/device-tree/system-id
- ;;
'--debug-enabled')
exec >/dev/null 2>&1
nvram --print-config=petitboot,debug? | grep -q true && exit 0