Commit e14e1fe7 authored by Adam Wujek's avatar Adam Wujek

sw/petalinux/diot-util: add version command

Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent eba8d0be
......@@ -52,6 +52,15 @@ ifeq (,$(filter $(SB_VER),1 2))
$(error SB_VER=$(SB_VER) not supported)
endif
GIT_VER = $(shell git describe --always)
GIT_USR = $(shell git config --get user.name)
# if user.name is not available from git use user@hostname
ifeq ($(GIT_USR),)
GIT_USR = $(shell whoami)@$(shell hostname)
endif
# create _done directory
$(shell mkdir -p _done)
$(shell mkdir -p build)
......@@ -560,7 +569,8 @@ rootfs_prepare: $(PETALINUX_CONFIG_BIN)
rootfs_build: rootfs_prepare $(PETALINUX_BUILD_BIN)
$(VT)echo -e "$(CO)Building rootfs...$(NC)" $(LOGT)
# compile rootfs
$(V) export SB_VER=$(SB_VER); export BB_ENV_EXTRAWHITE="$$BB_ENV_EXTRAWHITE SB_VER";\
$(V) export GIT_VER="$(GIT_VER)"; export GIT_USR="$(GIT_USR)"; export SB_VER=$(SB_VER); \
export BB_ENV_EXTRAWHITE="$$BB_ENV_EXTRAWHITE SB_VER GIT_VER GIT_USR"; \
cd "$(ROOTFS_DIR)" && petalinux-build -c rootfs $(LOG)
$(VT)echo -e "$(CO)Building rootfs... done$(NC)" $(LOGT)
$(V) echo `date` > _done/$@ $(LOG)
......
......@@ -49,4 +49,6 @@ do_install() {
do_compile_prepend() {
export SB_VER=${SB_VER}
export GIT_VER="${GIT_VER}"
export GIT_USR="${GIT_USR}"
}
......@@ -15,7 +15,10 @@ APP_OBJS = \
LDLIBS+=-lgpiod -lreadline -lsensors
CFLAGS+=-Wall -ggdb -g -O2 \
-DSB_VER=$(SB_VER)
-DSB_VER=$(SB_VER) \
-D__GIT_USR__="\"$(GIT_USR)\"" \
-D__GIT_VER__="\"$(GIT_VER)\"" \
LDFLAGS+= -ggdb -g
......
......@@ -47,12 +47,14 @@ char *command_name_generator(const char *, int);
int cmd_print_status(char *params);
int cmd_exit(char *params);
int cmd_help(char *params);
int cmd_version(char *params);
struct command_entry commands_list[] = {
{ .cmd_name = "status", .cmd_func = cmd_print_status, .cmd_help_string = "Print status\n", .cmd_params = NULL},
{ .cmd_name = "exit", .cmd_func = cmd_exit, .cmd_help_string = "quit program\n", .cmd_params = NULL},
{ .cmd_name = "quit", .cmd_func = cmd_exit, .cmd_help_string = "quit program\n", .cmd_params = NULL},
{ .cmd_name = "help", .cmd_func = cmd_help, .cmd_help_string = "Print help\n", .cmd_params = NULL},
{ .cmd_name = "version", .cmd_func = cmd_version, .cmd_help_string = "Print version information\n", .cmd_params = NULL},
{ .cmd_name = "led2", .cmd_func = cmd_led2, .cmd_help_string = "Enable/disable LED2\n", .cmd_params = "on|off"},
{ .cmd_name = "peripheral_reset", .cmd_func = cmd_peripheral_rst, .cmd_help_string = "Reset peripheral boards\n", .cmd_params = NULL},
{ .cmd_name = "power_cycle_crate", .cmd_func = cmd_power_cycle, .cmd_help_string = "Power cycle DI/OT create\n", .cmd_params = NULL},
......@@ -81,6 +83,17 @@ int cmd_help(char *params)
return 0;
}
int cmd_version(char *params)
{
printf("diot_util version information:\n");
printf("HW version: %d\n", SB_VER);
printf("GIT commit id: %s\n", __GIT_VER__);
printf("Build date: %s\n", __DATE__);
printf("Build time: %s\n", __TIME__);
printf("Built by: %s\n", __GIT_USR__);
return 0;
}
int cmd_exit(char *params)
......@@ -232,7 +245,7 @@ int main(int argc, char **argv)
printf("DIOT diagnostic tool\n\n");
while ((opt = getopt(argc, argv, "he:")) != -1) {
while ((opt = getopt(argc, argv, "he:v")) != -1) {
switch(opt)
{
case 'h':
......@@ -240,6 +253,10 @@ int main(int argc, char **argv)
cmd_help(NULL);
exit(0);
break;
case 'v':
cmd_version(NULL);
exit(0);
break;
case 'e':
next_script_cmd = script_commands = strdup(optarg);
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment