Skip to content

Commit

Permalink
[build] Expose build timestamp, build name, and product names
Browse files Browse the repository at this point in the history
Expose the build timestamp (measured in seconds since the Epoch) and
the build name (e.g. "rtl8139.rom" or "ipxe.efi"), and provide the
product name and product short name in a single centralised location.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Jun 24, 2014
1 parent 13a74e0 commit 8290a95
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 37 deletions.
1 change: 1 addition & 0 deletions src/Makefile
Expand Up @@ -96,6 +96,7 @@ SRCDIRS += config
# automatic build system.
#
NON_AUTO_SRCS :=
NON_AUTO_SRCS += core/version.c
NON_AUTO_SRCS += drivers/net/prism2.c

# INCDIRS lists the include path
Expand Down
37 changes: 21 additions & 16 deletions src/Makefile.housekeeping
Expand Up @@ -697,19 +697,6 @@ $(BIN)/embedded.% : override CC := env CCACHE_DISABLE=1 $(CC)
$(BIN)/certstore.% : override CC := env CCACHE_DISABLE=1 $(CC)
$(BIN)/privkey.% : override CC := env CCACHE_DISABLE=1 $(CC)

# Version number
#
CFLAGS_version += -DVERSION_MAJOR=$(VERSION_MAJOR) \
-DVERSION_MINOR=$(VERSION_MINOR) \
-DVERSION_PATCH=$(VERSION_PATCH) \
-DVERSION="\"$(VERSION)\""
# Make sure the version number gets updated on every git checkout
ifneq ($(GITVERSION),)
ifneq ($(wildcard ../.git/index),)
$(BIN)/version.o : ../.git/index
endif
endif

# Debug message autocolourisation range
#
DBGCOL_LIST := $(BIN)/.dbgcol.list
Expand Down Expand Up @@ -1004,13 +991,31 @@ blib : $(BLIB)
#
BUILD_ID_CMD := perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'

# Build timestamp
#
BUILD_TIMESTAMP := $(shell date +%s)

# Build version
#
GIT_INDEX := $(if $(GITVERSION),$(if $(wildcard ../.git/index),../.git/index))
$(BIN)/%.version.o : core/version.c $(MAKEDEPS) $(GIT_INDEX)
$(QM)$(ECHO) " [VERSION] $@"
$(Q)$(COMPILE_c) -DBUILD_NAME="\"$*\"" \
-DVERSION_MAJOR=$(VERSION_MAJOR) \
-DVERSION_MINOR=$(VERSION_MINOR) \
-DVERSION_PATCH=$(VERSION_PATCH) \
-DVERSION="\"$(VERSION)\"" \
-c $< -o $@

# Build an intermediate object file from the objects required for the
# specified target.
#
$(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
$(BIN)/%.tmp : $(BIN)/%.version.o $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
$(QM)$(ECHO) " [LD] $@"
$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $(BLIB) -o $@ \
--defsym _build_id=`$(BUILD_ID_CMD)` -Map $(BIN)/$*.tmp.map
$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $< $(BLIB) -o $@ \
--defsym _build_id=`$(BUILD_ID_CMD)` \
--defsym _build_timestamp=$(BUILD_TIMESTAMP) \
-Map $(BIN)/$*.tmp.map
$(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map

# Keep intermediate object file (useful for debugging)
Expand Down
4 changes: 2 additions & 2 deletions src/core/main.c
Expand Up @@ -17,8 +17,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stddef.h>
#include <stdio.h>
#include <ipxe/init.h>
#include <ipxe/version.h>
#include <usr/autoboot.h>
#include <config/general.h>

/**
* Main entry point
Expand All @@ -31,7 +31,7 @@ __asmcall int main ( void ) {
initialise();

/* Some devices take an unreasonably long time to initialise */
printf ( PRODUCT_SHORT_NAME " initialising devices..." );
printf ( "%s initialising devices...", product_short_name );
startup();
printf ( "ok\n" );

Expand Down
50 changes: 49 additions & 1 deletion src/core/version.c
Expand Up @@ -25,17 +25,65 @@ FILE_LICENCE ( GPL2_OR_LATER );
*
*/

#include <wchar.h>
#include <ipxe/features.h>
#include <ipxe/version.h>
#include <config/general.h>

/**
* Create wide-character version of string
*
* @v string String
* @ret wstring Wide-character version of string
*/
#define WSTRING( string ) _WSTRING ( string )
#define _WSTRING( string ) L ## string

/** Version number feature */
FEATURE_VERSION ( VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );

/** Build timestamp (generated by linker) */
extern char _build_timestamp[];

/** Build ID (generated by linker) */
extern char _build_id[];

/** Build timestamp */
unsigned long build_timestamp = ( ( unsigned long ) _build_timestamp );

/** Build ID */
unsigned long build_id = ( ( unsigned long ) _build_id );

/** Product major version */
const int product_major_version = VERSION_MAJOR;

/** Product minor version */
const int product_minor_version = VERSION_MINOR;

/** Product version string */
const char *product_version = VERSION;
const char product_version[] = VERSION;

/** Product name string */
const char product_name[] = PRODUCT_NAME;

/** Product short name string */
const char product_short_name[] = PRODUCT_SHORT_NAME;

/** Build name string */
const char build_name[] = BUILD_NAME;

/** Wide-character product version string */
const wchar_t product_wversion[] = WSTRING ( VERSION );

/** Wide-character product name string */
const wchar_t product_wname[] = WSTRING ( PRODUCT_NAME );

/** Wide-character product short name string */
const wchar_t product_short_wname[] = WSTRING ( PRODUCT_SHORT_NAME );

/** Wide-character build name string */
const wchar_t build_wname[] = WSTRING ( BUILD_NAME );

/** Copy of build name string within ".prefix" */
const char build_name_prefix[] __attribute__ (( section ( ".prefix.name" ) ))
= BUILD_NAME;
13 changes: 12 additions & 1 deletion src/include/ipxe/version.h
Expand Up @@ -9,8 +9,19 @@

FILE_LICENCE ( GPL2_OR_LATER );

#include <wchar.h>

extern unsigned long build_timestamp;
extern unsigned long build_id;
extern const int product_major_version;
extern const int product_minor_version;
extern const char *product_version;
extern const char product_version[];
extern const char product_name[];
extern const char product_short_name[];
extern const char build_name[];
extern const wchar_t product_wversion[];
extern const wchar_t product_wname[];
extern const wchar_t product_short_wname[];
extern const wchar_t build_wname[];

#endif /* _IPXE_VERSION_H */
4 changes: 2 additions & 2 deletions src/interface/efi/efi_driver.c
Expand Up @@ -23,12 +23,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/version.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/DriverBinding.h>
#include <ipxe/efi/Protocol/ComponentName2.h>
#include <ipxe/efi/efi_strings.h>
#include <ipxe/efi/efi_driver.h>
#include <config/general.h>

/** @file
*
Expand Down Expand Up @@ -207,7 +207,7 @@ int efi_driver_install ( struct efi_driver *efidrv ) {
efi_snprintf ( efidrv->wname,
( sizeof ( efidrv->wname ) /
sizeof ( efidrv->wname[0] ) ),
PRODUCT_SHORT_NAME "%s%s",
"%s%s%s", product_short_name,
( efidrv->name ? " - " : "" ),
( efidrv->name ? efidrv->name : "" ) );

Expand Down
8 changes: 4 additions & 4 deletions src/interface/efi/efi_snp.c
Expand Up @@ -28,12 +28,12 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/iobuf.h>
#include <ipxe/in.h>
#include <ipxe/pci.h>
#include <ipxe/version.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_pci.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_strings.h>
#include <ipxe/efi/efi_snp.h>
#include <config/general.h>
#include <usr/autoboot.h>

/** EFI simple network protocol GUID */
Expand Down Expand Up @@ -988,12 +988,12 @@ static int efi_snp_probe ( struct net_device *netdev ) {
efi_snprintf ( snpdev->driver_name,
( sizeof ( snpdev->driver_name ) /
sizeof ( snpdev->driver_name[0] ) ),
PRODUCT_SHORT_NAME " %s", netdev->dev->driver_name );
"%s %s", product_short_name, netdev->dev->driver_name );
efi_snprintf ( snpdev->controller_name,
( sizeof ( snpdev->controller_name ) /
sizeof ( snpdev->controller_name[0] ) ),
PRODUCT_SHORT_NAME " %s (%s)",
netdev->name, netdev_addr ( netdev ) );
"%s %s (%s)", product_short_name, netdev->name,
netdev_addr ( netdev ) );
snpdev->name2.GetDriverName = efi_snp_get_driver_name;
snpdev->name2.GetControllerName = efi_snp_get_controller_name;
snpdev->name2.SupportedLanguages = "en";
Expand Down
13 changes: 6 additions & 7 deletions src/interface/efi/efi_snp_hii.c
Expand Up @@ -59,7 +59,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/efi/efi_hii.h>
#include <ipxe/efi/efi_snp.h>
#include <ipxe/efi/efi_strings.h>
#include <config/general.h>

/** EFI configuration access protocol GUID */
static EFI_GUID efi_hii_config_access_protocol_guid
Expand Down Expand Up @@ -162,7 +161,7 @@ efi_snp_hii_package_list ( struct efi_snp_device *snpdev ) {
struct device *dev = netdev->dev;
struct efi_ifr_builder ifr;
EFI_HII_PACKAGE_LIST_HEADER *package;
const char *product_name;
const char *name;
EFI_GUID package_guid;
EFI_GUID formset_guid;
EFI_GUID varstore_guid;
Expand All @@ -173,21 +172,21 @@ efi_snp_hii_package_list ( struct efi_snp_device *snpdev ) {
efi_ifr_init ( &ifr );

/* Determine product name */
product_name = ( PRODUCT_NAME[0] ? PRODUCT_NAME : PRODUCT_SHORT_NAME );
name = ( product_name[0] ? product_name : product_short_name );

/* Generate GUIDs */
efi_snp_hii_random_guid ( &package_guid );
efi_snp_hii_random_guid ( &formset_guid );
efi_snp_hii_random_guid ( &varstore_guid );

/* Generate title string (used more than once) */
title_id = efi_ifr_string ( &ifr, "%s (%s)", product_name,
title_id = efi_ifr_string ( &ifr, "%s (%s)", name,
netdev_addr ( netdev ) );

/* Generate opcodes */
efi_ifr_form_set_op ( &ifr, &formset_guid, title_id,
efi_ifr_string ( &ifr,
"Configure " PRODUCT_SHORT_NAME),
efi_ifr_string ( &ifr, "Configure %s",
product_short_name ),
&efi_hii_platform_setup_formset_guid,
&efi_hii_ibm_ucm_compliant_formset_guid, NULL );
efi_ifr_guid_class_op ( &ifr, EFI_NETWORK_DEVICE_CLASS );
Expand All @@ -197,7 +196,7 @@ efi_snp_hii_package_list ( struct efi_snp_device *snpdev ) {
efi_ifr_text_op ( &ifr,
efi_ifr_string ( &ifr, "Name" ),
efi_ifr_string ( &ifr, "Firmware product name" ),
efi_ifr_string ( &ifr, "%s", product_name ) );
efi_ifr_string ( &ifr, "%s", name ) );
efi_ifr_text_op ( &ifr,
efi_ifr_string ( &ifr, "Version" ),
efi_ifr_string ( &ifr, "Firmware version" ),
Expand Down
4 changes: 2 additions & 2 deletions src/net/tcp/oncrpc.c
Expand Up @@ -37,7 +37,7 @@
#include <ipxe/oncrpc_iob.h>
#include <ipxe/init.h>
#include <ipxe/settings.h>
#include <config/general.h>
#include <ipxe/version.h>

/** @file
*
Expand Down Expand Up @@ -88,7 +88,7 @@ int oncrpc_init_cred_sys ( struct oncrpc_cred_sys *auth_sys ) {
fetch_string_setting_copy ( NULL, &hostname_setting,
&auth_sys->hostname );
if ( ! auth_sys->hostname )
if ( ! ( auth_sys->hostname = strdup ( PRODUCT_SHORT_NAME ) ) )
if ( ! ( auth_sys->hostname = strdup ( product_short_name ) ) )
return -ENOMEM;

auth_sys->uid = fetch_uintz_setting ( NULL, &uid_setting );
Expand Down
4 changes: 2 additions & 2 deletions src/usr/autoboot.c
Expand Up @@ -499,10 +499,10 @@ void ipxe ( struct net_device *netdev ) {
* do so.
*
*/
printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD "iPXE %s"
printf ( NORMAL "\n\n%s\n" BOLD "iPXE %s"
NORMAL " -- Open Source Network Boot Firmware -- "
CYAN "http://ipxe.org" NORMAL "\n"
"Features:", product_version );
"Features:", product_name, product_version );
for_each_table_entry ( feature, FEATURES )
printf ( " %s", feature->name );
printf ( "\n" );
Expand Down

0 comments on commit 8290a95

Please sign in to comment.