Skip to content

Commit

Permalink
lk2nd: Add version module for VCS tag reporting
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Travkin <[email protected]>
  • Loading branch information
TravMurav committed Aug 30, 2023
1 parent 9390f66 commit 787b85f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arch/arm/compile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ $(BUILDDIR)/%.o: %.c $(SRCDEPS)
@echo compiling $<
$(NOECHO)$(CC) $(CFLAGS) $(THUMBCFLAGS) --std=c99 $(INCLUDES) -c $< -MD -MT $@ -MF $(@:%o=%d) -o $@

$(BUILDDIR)/%.o: $(BUILDDIR)/%.c $(SRCDEPS)
@$(MKDIR)
@echo compiling $<
$(NOECHO)$(CC) $(CFLAGS) $(THUMBCFLAGS) --std=c99 $(INCLUDES) -c $< -MD -MT $@ -MF $(@:%o=%d) -o $@

$(BUILDDIR)/%.o: %.cpp $(SRCDEPS)
@$(MKDIR)
@echo compiling $<
Expand Down
6 changes: 6 additions & 0 deletions lk2nd/include/lk2nd/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef LK2ND_VERSION_H
#define LK2ND_VERSION_H

extern const char* LK2ND_VERSION;

#endif /* LK2ND_VERSION_H */
1 change: 1 addition & 0 deletions lk2nd/project/base.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ MODULES += \
lk2nd/serialno \
lk2nd/smp \
lk2nd/smp/spin-table \
lk2nd/version \

# Disable SMP spin table if unsupported (without throwing errors)
LK2ND_SMP_OPTIONAL := 1
Expand Down
24 changes: 24 additions & 0 deletions lk2nd/version/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: BSD-3-Clause
LOCAL_DIR := $(GET_LOCAL_DIR)

OBJS += \
$(LOCAL_DIR)/version.o \

# Generate the version tag from VCS

LK2ND_VERSION := $(shell $(LK_TOP_DIR)/lk2nd/scripts/describe-version.sh)
VERSION_FILE := $(BUILDDIR)/$(LOCAL_DIR)/tag.c

FORCE:

$(VERSION_FILE): FORCE
@$(MKDIR)
@echo "const char* LK2ND_VERSION = \"$(LK2ND_VERSION)\";" > $@.tmp
@if ! cmp -s $@.tmp $@; then \
echo generating $@ for lk2nd $(LK2ND_VERSION); \
mv $@.tmp $@; \
fi

OBJS += \
$(LOCAL_DIR)/tag.o \

49 changes: 49 additions & 0 deletions lk2nd/version/version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright (c) 2023, Nikita Travkin <[email protected]> */

#include <boot.h>
#include <libfdt.h>
#include <fastboot.h>

#include <lk2nd/version.h>

/*
* version.c - Pass lk2nd build information to the OS.
*
* Per DT spec /chosen is used for various firmware
* parameters so we place our version here in case OS wants
* to use these to i.e. OTA update the lk2nd.
*/

#define xstr(s) str(s)
#define str(s) #s

static int lk2nd_version_dt_update(void *dtb, const char *cmdline,
enum boot_type boot_type)
{
int ret, offset;

if (boot_type & (BOOT_DOWNSTREAM | BOOT_LK2ND))
return 0;

offset = fdt_path_offset(dtb, "/chosen");
if (offset < 0)
return 0;

ret = fdt_setprop_string(dtb, offset, "lk2nd,project", xstr(BOARD));
if (ret < 0)
return 0;

ret = fdt_setprop_string(dtb, offset, "lk2nd,version", LK2ND_VERSION);
if (ret < 0)
return 0;

return 0;
}
DEV_TREE_UPDATE(lk2nd_version_dt_update);

static void lk2nd_version_publish(void)
{
fastboot_publish("lk2nd:version", LK2ND_VERSION);
}
FASTBOOT_INIT(lk2nd_version_publish);

0 comments on commit 787b85f

Please sign in to comment.