Procházet zdrojové kódy

[build] Expose build timestamp, build name, and product names

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>
tags/v1.20.1
Michael Brown před 10 roky
rodič
revize
8290a95513

+ 1
- 0
src/Makefile Zobrazit soubor

96
 # automatic build system.
96
 # automatic build system.
97
 #
97
 #
98
 NON_AUTO_SRCS	:=
98
 NON_AUTO_SRCS	:=
99
+NON_AUTO_SRCS	+= core/version.c
99
 NON_AUTO_SRCS	+= drivers/net/prism2.c
100
 NON_AUTO_SRCS	+= drivers/net/prism2.c
100
 
101
 
101
 # INCDIRS lists the include path
102
 # INCDIRS lists the include path

+ 21
- 16
src/Makefile.housekeeping Zobrazit soubor

697
 $(BIN)/certstore.% : override CC := env CCACHE_DISABLE=1 $(CC)
697
 $(BIN)/certstore.% : override CC := env CCACHE_DISABLE=1 $(CC)
698
 $(BIN)/privkey.% : override CC := env CCACHE_DISABLE=1 $(CC)
698
 $(BIN)/privkey.% : override CC := env CCACHE_DISABLE=1 $(CC)
699
 
699
 
700
-# Version number
701
-#
702
-CFLAGS_version += -DVERSION_MAJOR=$(VERSION_MAJOR) \
703
-		  -DVERSION_MINOR=$(VERSION_MINOR) \
704
-		  -DVERSION_PATCH=$(VERSION_PATCH) \
705
-		  -DVERSION="\"$(VERSION)\""
706
-# Make sure the version number gets updated on every git checkout
707
-ifneq ($(GITVERSION),)
708
-ifneq ($(wildcard ../.git/index),)
709
-$(BIN)/version.o : ../.git/index
710
-endif
711
-endif
712
-
713
 # Debug message autocolourisation range
700
 # Debug message autocolourisation range
714
 #
701
 #
715
 DBGCOL_LIST	:= $(BIN)/.dbgcol.list
702
 DBGCOL_LIST	:= $(BIN)/.dbgcol.list
1004
 #
991
 #
1005
 BUILD_ID_CMD	:= perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'
992
 BUILD_ID_CMD	:= perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'
1006
 
993
 
994
+# Build timestamp
995
+#
996
+BUILD_TIMESTAMP := $(shell date +%s)
997
+
998
+# Build version
999
+#
1000
+GIT_INDEX := $(if $(GITVERSION),$(if $(wildcard ../.git/index),../.git/index))
1001
+$(BIN)/%.version.o : core/version.c $(MAKEDEPS) $(GIT_INDEX)
1002
+	$(QM)$(ECHO) "  [VERSION] $@"
1003
+	$(Q)$(COMPILE_c) -DBUILD_NAME="\"$*\"" \
1004
+		-DVERSION_MAJOR=$(VERSION_MAJOR) \
1005
+		-DVERSION_MINOR=$(VERSION_MINOR) \
1006
+		-DVERSION_PATCH=$(VERSION_PATCH) \
1007
+		-DVERSION="\"$(VERSION)\"" \
1008
+		-c $< -o $@
1009
+
1007
 # Build an intermediate object file from the objects required for the
1010
 # Build an intermediate object file from the objects required for the
1008
 # specified target.
1011
 # specified target.
1009
 #
1012
 #
1010
-$(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
1013
+$(BIN)/%.tmp : $(BIN)/%.version.o $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
1011
 	$(QM)$(ECHO) "  [LD] $@"
1014
 	$(QM)$(ECHO) "  [LD] $@"
1012
-	$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $(BLIB) -o $@ \
1013
-		--defsym _build_id=`$(BUILD_ID_CMD)` -Map $(BIN)/$*.tmp.map
1015
+	$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $< $(BLIB) -o $@ \
1016
+		--defsym _build_id=`$(BUILD_ID_CMD)` \
1017
+		--defsym _build_timestamp=$(BUILD_TIMESTAMP) \
1018
+		-Map $(BIN)/$*.tmp.map
1014
 	$(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
1019
 	$(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
1015
 
1020
 
1016
 # Keep intermediate object file (useful for debugging)
1021
 # Keep intermediate object file (useful for debugging)

+ 2
- 2
src/core/main.c Zobrazit soubor

17
 #include <stddef.h>
17
 #include <stddef.h>
18
 #include <stdio.h>
18
 #include <stdio.h>
19
 #include <ipxe/init.h>
19
 #include <ipxe/init.h>
20
+#include <ipxe/version.h>
20
 #include <usr/autoboot.h>
21
 #include <usr/autoboot.h>
21
-#include <config/general.h>
22
 
22
 
23
 /**
23
 /**
24
  * Main entry point
24
  * Main entry point
31
 	initialise();
31
 	initialise();
32
 
32
 
33
 	/* Some devices take an unreasonably long time to initialise */
33
 	/* Some devices take an unreasonably long time to initialise */
34
-	printf ( PRODUCT_SHORT_NAME " initialising devices..." );
34
+	printf ( "%s initialising devices...", product_short_name );
35
 	startup();
35
 	startup();
36
 	printf ( "ok\n" );
36
 	printf ( "ok\n" );
37
 
37
 

+ 49
- 1
src/core/version.c Zobrazit soubor

25
  *
25
  *
26
  */
26
  */
27
 
27
 
28
+#include <wchar.h>
28
 #include <ipxe/features.h>
29
 #include <ipxe/features.h>
29
 #include <ipxe/version.h>
30
 #include <ipxe/version.h>
31
+#include <config/general.h>
32
+
33
+/**
34
+ * Create wide-character version of string
35
+ *
36
+ * @v string		String
37
+ * @ret wstring		Wide-character version of string
38
+ */
39
+#define WSTRING( string ) _WSTRING ( string )
40
+#define _WSTRING( string ) L ## string
30
 
41
 
31
 /** Version number feature */
42
 /** Version number feature */
32
 FEATURE_VERSION ( VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );
43
 FEATURE_VERSION ( VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH );
33
 
44
 
45
+/** Build timestamp (generated by linker) */
46
+extern char _build_timestamp[];
47
+
48
+/** Build ID (generated by linker) */
49
+extern char _build_id[];
50
+
51
+/** Build timestamp */
52
+unsigned long build_timestamp = ( ( unsigned long ) _build_timestamp );
53
+
54
+/** Build ID */
55
+unsigned long build_id = ( ( unsigned long ) _build_id );
56
+
34
 /** Product major version */
57
 /** Product major version */
35
 const int product_major_version = VERSION_MAJOR;
58
 const int product_major_version = VERSION_MAJOR;
36
 
59
 
38
 const int product_minor_version = VERSION_MINOR;
61
 const int product_minor_version = VERSION_MINOR;
39
 
62
 
40
 /** Product version string */
63
 /** Product version string */
41
-const char *product_version = VERSION;
64
+const char product_version[] = VERSION;
65
+
66
+/** Product name string */
67
+const char product_name[] = PRODUCT_NAME;
68
+
69
+/** Product short name string */
70
+const char product_short_name[] = PRODUCT_SHORT_NAME;
71
+
72
+/** Build name string */
73
+const char build_name[] = BUILD_NAME;
74
+
75
+/** Wide-character product version string */
76
+const wchar_t product_wversion[] = WSTRING ( VERSION );
77
+
78
+/** Wide-character product name string */
79
+const wchar_t product_wname[] = WSTRING ( PRODUCT_NAME );
80
+
81
+/** Wide-character product short name string */
82
+const wchar_t product_short_wname[] = WSTRING ( PRODUCT_SHORT_NAME );
83
+
84
+/** Wide-character build name string */
85
+const wchar_t build_wname[] = WSTRING ( BUILD_NAME );
86
+
87
+/** Copy of build name string within ".prefix" */
88
+const char build_name_prefix[] __attribute__ (( section ( ".prefix.name" ) ))
89
+	= BUILD_NAME;

+ 12
- 1
src/include/ipxe/version.h Zobrazit soubor

9
 
9
 
10
 FILE_LICENCE ( GPL2_OR_LATER );
10
 FILE_LICENCE ( GPL2_OR_LATER );
11
 
11
 
12
+#include <wchar.h>
13
+
14
+extern unsigned long build_timestamp;
15
+extern unsigned long build_id;
12
 extern const int product_major_version;
16
 extern const int product_major_version;
13
 extern const int product_minor_version;
17
 extern const int product_minor_version;
14
-extern const char *product_version;
18
+extern const char product_version[];
19
+extern const char product_name[];
20
+extern const char product_short_name[];
21
+extern const char build_name[];
22
+extern const wchar_t product_wversion[];
23
+extern const wchar_t product_wname[];
24
+extern const wchar_t product_short_wname[];
25
+extern const wchar_t build_wname[];
15
 
26
 
16
 #endif /* _IPXE_VERSION_H */
27
 #endif /* _IPXE_VERSION_H */

+ 2
- 2
src/interface/efi/efi_driver.c Zobrazit soubor

23
 #include <stdio.h>
23
 #include <stdio.h>
24
 #include <string.h>
24
 #include <string.h>
25
 #include <errno.h>
25
 #include <errno.h>
26
+#include <ipxe/version.h>
26
 #include <ipxe/efi/efi.h>
27
 #include <ipxe/efi/efi.h>
27
 #include <ipxe/efi/Protocol/DriverBinding.h>
28
 #include <ipxe/efi/Protocol/DriverBinding.h>
28
 #include <ipxe/efi/Protocol/ComponentName2.h>
29
 #include <ipxe/efi/Protocol/ComponentName2.h>
29
 #include <ipxe/efi/efi_strings.h>
30
 #include <ipxe/efi/efi_strings.h>
30
 #include <ipxe/efi/efi_driver.h>
31
 #include <ipxe/efi/efi_driver.h>
31
-#include <config/general.h>
32
 
32
 
33
 /** @file
33
 /** @file
34
  *
34
  *
207
 	efi_snprintf ( efidrv->wname,
207
 	efi_snprintf ( efidrv->wname,
208
 		       ( sizeof ( efidrv->wname ) /
208
 		       ( sizeof ( efidrv->wname ) /
209
 			 sizeof ( efidrv->wname[0] ) ),
209
 			 sizeof ( efidrv->wname[0] ) ),
210
-		       PRODUCT_SHORT_NAME "%s%s",
210
+		       "%s%s%s", product_short_name,
211
 		       ( efidrv->name ? " - " : "" ),
211
 		       ( efidrv->name ? " - " : "" ),
212
 		       ( efidrv->name ? efidrv->name : "" ) );
212
 		       ( efidrv->name ? efidrv->name : "" ) );
213
 
213
 

+ 4
- 4
src/interface/efi/efi_snp.c Zobrazit soubor

28
 #include <ipxe/iobuf.h>
28
 #include <ipxe/iobuf.h>
29
 #include <ipxe/in.h>
29
 #include <ipxe/in.h>
30
 #include <ipxe/pci.h>
30
 #include <ipxe/pci.h>
31
+#include <ipxe/version.h>
31
 #include <ipxe/efi/efi.h>
32
 #include <ipxe/efi/efi.h>
32
 #include <ipxe/efi/efi_pci.h>
33
 #include <ipxe/efi/efi_pci.h>
33
 #include <ipxe/efi/efi_driver.h>
34
 #include <ipxe/efi/efi_driver.h>
34
 #include <ipxe/efi/efi_strings.h>
35
 #include <ipxe/efi/efi_strings.h>
35
 #include <ipxe/efi/efi_snp.h>
36
 #include <ipxe/efi/efi_snp.h>
36
-#include <config/general.h>
37
 #include <usr/autoboot.h>
37
 #include <usr/autoboot.h>
38
 
38
 
39
 /** EFI simple network protocol GUID */
39
 /** EFI simple network protocol GUID */
988
 	efi_snprintf ( snpdev->driver_name,
988
 	efi_snprintf ( snpdev->driver_name,
989
 		       ( sizeof ( snpdev->driver_name ) /
989
 		       ( sizeof ( snpdev->driver_name ) /
990
 			 sizeof ( snpdev->driver_name[0] ) ),
990
 			 sizeof ( snpdev->driver_name[0] ) ),
991
-		       PRODUCT_SHORT_NAME " %s", netdev->dev->driver_name );
991
+		       "%s %s", product_short_name, netdev->dev->driver_name );
992
 	efi_snprintf ( snpdev->controller_name,
992
 	efi_snprintf ( snpdev->controller_name,
993
 		       ( sizeof ( snpdev->controller_name ) /
993
 		       ( sizeof ( snpdev->controller_name ) /
994
 			 sizeof ( snpdev->controller_name[0] ) ),
994
 			 sizeof ( snpdev->controller_name[0] ) ),
995
-		       PRODUCT_SHORT_NAME " %s (%s)",
996
-		       netdev->name, netdev_addr ( netdev ) );
995
+		       "%s %s (%s)", product_short_name, netdev->name,
996
+		       netdev_addr ( netdev ) );
997
 	snpdev->name2.GetDriverName = efi_snp_get_driver_name;
997
 	snpdev->name2.GetDriverName = efi_snp_get_driver_name;
998
 	snpdev->name2.GetControllerName = efi_snp_get_controller_name;
998
 	snpdev->name2.GetControllerName = efi_snp_get_controller_name;
999
 	snpdev->name2.SupportedLanguages = "en";
999
 	snpdev->name2.SupportedLanguages = "en";

+ 6
- 7
src/interface/efi/efi_snp_hii.c Zobrazit soubor

59
 #include <ipxe/efi/efi_hii.h>
59
 #include <ipxe/efi/efi_hii.h>
60
 #include <ipxe/efi/efi_snp.h>
60
 #include <ipxe/efi/efi_snp.h>
61
 #include <ipxe/efi/efi_strings.h>
61
 #include <ipxe/efi/efi_strings.h>
62
-#include <config/general.h>
63
 
62
 
64
 /** EFI configuration access protocol GUID */
63
 /** EFI configuration access protocol GUID */
65
 static EFI_GUID efi_hii_config_access_protocol_guid
64
 static EFI_GUID efi_hii_config_access_protocol_guid
162
 	struct device *dev = netdev->dev;
161
 	struct device *dev = netdev->dev;
163
 	struct efi_ifr_builder ifr;
162
 	struct efi_ifr_builder ifr;
164
 	EFI_HII_PACKAGE_LIST_HEADER *package;
163
 	EFI_HII_PACKAGE_LIST_HEADER *package;
165
-	const char *product_name;
164
+	const char *name;
166
 	EFI_GUID package_guid;
165
 	EFI_GUID package_guid;
167
 	EFI_GUID formset_guid;
166
 	EFI_GUID formset_guid;
168
 	EFI_GUID varstore_guid;
167
 	EFI_GUID varstore_guid;
173
 	efi_ifr_init ( &ifr );
172
 	efi_ifr_init ( &ifr );
174
 
173
 
175
 	/* Determine product name */
174
 	/* Determine product name */
176
-	product_name = ( PRODUCT_NAME[0] ? PRODUCT_NAME : PRODUCT_SHORT_NAME );
175
+	name = ( product_name[0] ? product_name : product_short_name );
177
 
176
 
178
 	/* Generate GUIDs */
177
 	/* Generate GUIDs */
179
 	efi_snp_hii_random_guid ( &package_guid );
178
 	efi_snp_hii_random_guid ( &package_guid );
181
 	efi_snp_hii_random_guid ( &varstore_guid );
180
 	efi_snp_hii_random_guid ( &varstore_guid );
182
 
181
 
183
 	/* Generate title string (used more than once) */
182
 	/* Generate title string (used more than once) */
184
-	title_id = efi_ifr_string ( &ifr, "%s (%s)", product_name,
183
+	title_id = efi_ifr_string ( &ifr, "%s (%s)", name,
185
 				    netdev_addr ( netdev ) );
184
 				    netdev_addr ( netdev ) );
186
 
185
 
187
 	/* Generate opcodes */
186
 	/* Generate opcodes */
188
 	efi_ifr_form_set_op ( &ifr, &formset_guid, title_id,
187
 	efi_ifr_form_set_op ( &ifr, &formset_guid, title_id,
189
-			      efi_ifr_string ( &ifr,
190
-					       "Configure " PRODUCT_SHORT_NAME),
188
+			      efi_ifr_string ( &ifr, "Configure %s",
189
+					       product_short_name ),
191
 			      &efi_hii_platform_setup_formset_guid,
190
 			      &efi_hii_platform_setup_formset_guid,
192
 			      &efi_hii_ibm_ucm_compliant_formset_guid, NULL );
191
 			      &efi_hii_ibm_ucm_compliant_formset_guid, NULL );
193
 	efi_ifr_guid_class_op ( &ifr, EFI_NETWORK_DEVICE_CLASS );
192
 	efi_ifr_guid_class_op ( &ifr, EFI_NETWORK_DEVICE_CLASS );
197
 	efi_ifr_text_op ( &ifr,
196
 	efi_ifr_text_op ( &ifr,
198
 			  efi_ifr_string ( &ifr, "Name" ),
197
 			  efi_ifr_string ( &ifr, "Name" ),
199
 			  efi_ifr_string ( &ifr, "Firmware product name" ),
198
 			  efi_ifr_string ( &ifr, "Firmware product name" ),
200
-			  efi_ifr_string ( &ifr, "%s", product_name ) );
199
+			  efi_ifr_string ( &ifr, "%s", name ) );
201
 	efi_ifr_text_op ( &ifr,
200
 	efi_ifr_text_op ( &ifr,
202
 			  efi_ifr_string ( &ifr, "Version" ),
201
 			  efi_ifr_string ( &ifr, "Version" ),
203
 			  efi_ifr_string ( &ifr, "Firmware version" ),
202
 			  efi_ifr_string ( &ifr, "Firmware version" ),

+ 2
- 2
src/net/tcp/oncrpc.c Zobrazit soubor

37
 #include <ipxe/oncrpc_iob.h>
37
 #include <ipxe/oncrpc_iob.h>
38
 #include <ipxe/init.h>
38
 #include <ipxe/init.h>
39
 #include <ipxe/settings.h>
39
 #include <ipxe/settings.h>
40
-#include <config/general.h>
40
+#include <ipxe/version.h>
41
 
41
 
42
 /** @file
42
 /** @file
43
  *
43
  *
88
 	fetch_string_setting_copy ( NULL, &hostname_setting,
88
 	fetch_string_setting_copy ( NULL, &hostname_setting,
89
 	                            &auth_sys->hostname );
89
 	                            &auth_sys->hostname );
90
 	if ( ! auth_sys->hostname )
90
 	if ( ! auth_sys->hostname )
91
-		if ( ! ( auth_sys->hostname = strdup ( PRODUCT_SHORT_NAME ) ) )
91
+		if ( ! ( auth_sys->hostname = strdup ( product_short_name ) ) )
92
 			return -ENOMEM;
92
 			return -ENOMEM;
93
 
93
 
94
 	auth_sys->uid         = fetch_uintz_setting ( NULL, &uid_setting );
94
 	auth_sys->uid         = fetch_uintz_setting ( NULL, &uid_setting );

+ 2
- 2
src/usr/autoboot.c Zobrazit soubor

499
 	 * do so.
499
 	 * do so.
500
 	 *
500
 	 *
501
 	 */
501
 	 */
502
-	printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD "iPXE %s"
502
+	printf ( NORMAL "\n\n%s\n" BOLD "iPXE %s"
503
 		 NORMAL " -- Open Source Network Boot Firmware -- "
503
 		 NORMAL " -- Open Source Network Boot Firmware -- "
504
 		 CYAN "http://ipxe.org" NORMAL "\n"
504
 		 CYAN "http://ipxe.org" NORMAL "\n"
505
-		 "Features:", product_version );
505
+		 "Features:", product_name, product_version );
506
 	for_each_table_entry ( feature, FEATURES )
506
 	for_each_table_entry ( feature, FEATURES )
507
 		printf ( " %s", feature->name );
507
 		printf ( " %s", feature->name );
508
 	printf ( "\n" );
508
 	printf ( "\n" );

Načítá se…
Zrušit
Uložit