Skip to content

Commit d726f22

Browse files
masahir0ytrini
authored andcommitted
cmd: rework "license" command
The previous commit ("add a new command to show .config contents") improves the basic infrastructure of "embed a compressed file into the U-Boot image, and print it by a command". The same pattern for the "license" command. This commit reworks the command to improve the following: [1] Improve log style Kbuild style log GZIP cmd/license_data.gz CHK cmd/license_data_gz.h UPD cmd/license_data_gz.h CHK cmd/license_data_size.h UPD cmd/license_data_size.h instead of the bare Make log: cat ./Licenses/gpl-2.0.txt | gzip -9 -c | \ tools/bin2header license_gzip > ./include/license.h [2] Collect related code into the "cmd" directory Prior to this commit, the license.h was created by tools/Makefile, placed under the "include" directory, included from cmd/license.c, and deleted by the top-level Makefile. It is not a good idea to scatter related code. [3] Drop the fixed-malloc size LICENSE_MAX Just allocate the minimum required size of buffer because we know the size of the original gpl-2.0.txt. [4] Fix more issues Terminate the buffer with zero to prevent puts() from over-running. Add "static" to do_license. Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Simon Glass <[email protected]>
1 parent 61304db commit d726f22

File tree

8 files changed

+39
-66
lines changed

8 files changed

+39
-66
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ CLEAN_DIRS += $(MODVERDIR) \
14251425
$(foreach d, spl tpl, $(patsubst %,$d/%, \
14261426
$(filter-out include, $(shell ls -1 $d 2>/dev/null))))
14271427

1428-
CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h include/license.h \
1428+
CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h \
14291429
boot* u-boot* MLO* SPL System.map
14301430

14311431
# Directories & files removed with 'make mrproper'

cmd/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
config_data.gz
22
config_data_gz.h
33
config_data_size.h
4+
license_data.gz
5+
license_data_gz.h
6+
license_data_size.h

cmd/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ config CMD_CPU
154154

155155
config CMD_LICENSE
156156
bool "license"
157+
select BUILD_BIN2C
157158
help
158159
Print GPL license text
159160

cmd/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,18 @@ $(obj)/config_data_gz.h: $(obj)/config_data.gz FORCE
187187
targets += config_data_size.h
188188
$(obj)/config_data_size.h: $(KCONFIG_CONFIG) FORCE
189189
$(call filechk,data_size)
190+
191+
# "license" command
192+
$(obj)/license.o: $(obj)/license_data_gz.h $(obj)/license_data_size.h
193+
194+
targets += license_data.gz
195+
$(obj)/license_data.gz: $(srctree)/Licenses/gpl-2.0.txt FORCE
196+
$(call if_changed,gzip)
197+
198+
targets += license_data_gz.h
199+
$(obj)/license_data_gz.h: $(obj)/license_data.gz FORCE
200+
$(call filechk,data_gz)
201+
202+
targets += license_data_size.h
203+
$(obj)/license_data_size.h: $(srctree)/Licenses/gpl-2.0.txt FORCE
204+
$(call filechk,data_size)

cmd/license.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,36 @@
66
*/
77

88
#include <common.h>
9-
10-
/* Licenses/gpl-2.0.txt is currently 18092 bytes in size */
11-
#define LICENSE_MAX 20480
12-
139
#include <command.h>
1410
#include <malloc.h>
15-
#include <license.h>
1611

17-
int do_license(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
12+
#include "license_data_gz.h"
13+
#include "license_data_size.h"
14+
15+
static int do_license(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1816
{
19-
char *dst = malloc(LICENSE_MAX);
20-
unsigned long len = LICENSE_MAX;
17+
char *dst;
18+
unsigned long len = data_size;
19+
int ret = CMD_RET_SUCCESS;
2120

21+
dst = malloc(data_size + 1);
2222
if (!dst)
23-
return -1;
23+
return CMD_RET_FAILURE;
2424

25-
if (gunzip(dst, LICENSE_MAX, license_gzip, &len) != 0) {
25+
ret = gunzip(dst, data_size, (unsigned char *)data_gz, &len);
26+
if (ret) {
2627
printf("Error uncompressing license text\n");
27-
free(dst);
28-
return -1;
28+
ret = CMD_RET_FAILURE;
29+
goto free;
2930
}
31+
32+
dst[data_size] = 0;
3033
puts(dst);
34+
35+
free:
3136
free(dst);
3237

33-
return 0;
38+
return ret;
3439
}
3540

3641
U_BOOT_CMD(

include/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
/bmp_logo.h
33
/bmp_logo_data.h
44
/config.h
5-
/license.h

tools/Makefile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ CONFIG_BUILD_ENVCRC ?= $(ENVCRC-y)
3232

3333
hostprogs-$(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER) += atmel_pmecc_params
3434

35-
hostprogs-$(CONFIG_CMD_LICENSE) += bin2header
3635
hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo
3736
hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo
3837
HOSTCFLAGS_bmp_logo.o := -pedantic
@@ -233,10 +232,6 @@ endif
233232

234233
endif # !LOGO_BMP
235234

236-
# Generated gziped GPL-2.0 license text
237-
LICENSE_H = $(objtree)/include/license.h
238-
LICENSE-$(CONFIG_CMD_LICENSE) += $(LICENSE_H)
239-
240235
#
241236
# Use native tools and options
242237
# Define __KERNEL_STRICT_NAMES to prevent typedef overlaps
@@ -251,18 +246,14 @@ HOST_EXTRACFLAGS += -include $(srctree)/include/libfdt_env.h \
251246
-D__KERNEL_STRICT_NAMES \
252247
-D_GNU_SOURCE
253248

254-
__build: $(LOGO-y) $(LICENSE-y)
249+
__build: $(LOGO-y)
255250

256251
$(LOGO_H): $(obj)/bmp_logo $(LOGO_BMP)
257252
$(obj)/bmp_logo --gen-info $(LOGO_BMP) > $@
258253

259254
$(LOGO_DATA_H): $(obj)/bmp_logo $(LOGO_BMP)
260255
$(obj)/bmp_logo --gen-data $(LOGO_BMP) > $@
261256

262-
$(LICENSE_H): $(obj)/bin2header $(srctree)/Licenses/gpl-2.0.txt
263-
cat $(srctree)/Licenses/gpl-2.0.txt | gzip -9 -c | \
264-
$(obj)/bin2header license_gzip > $(LICENSE_H)
265-
266257
# Let clean descend into subdirs
267258
subdir- += env
268259

tools/bin2header.c

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)