Skip to content

Commit 74d22ad

Browse files
authored
Merge pull request #62 from n1tehawk/20161021_autoversion
Add support for version information
2 parents f0a15f4 + 99942a6 commit 74d22ad

12 files changed

Lines changed: 58 additions & 14 deletions

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
sunxi-fexc
21
bin2fex
32
fex2bin
43
sunxi-bootinfo
54
sunxi-fel
6-
sunxi-pio
5+
sunxi-fexc
76
sunxi-nand-part
7+
sunxi-pio
8+
version.h
89
*.o
910
*.swp

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ all: tools target-tools
6161
tools: $(TOOLS) $(FEXC_LINKS)
6262
target-tools: $(TARGET_TOOLS)
6363

64-
misc: $(MISC_TOOLS)
64+
misc: version.h $(MISC_TOOLS)
6565

6666
binfiles: $(BINFILES)
6767

@@ -85,9 +85,9 @@ install-target-tools: $(TARGET_TOOLS)
8585

8686
clean:
8787
@rm -vf $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) $(MISC_TOOLS)
88-
@rm -vf *.o *.elf *.sunxi *.bin *.nm *.orig
88+
@rm -vf version.h *.o *.elf *.sunxi *.bin *.nm *.orig
8989

90-
$(TOOLS) $(TARGET_TOOLS): Makefile common.h
90+
$(TOOLS) $(TARGET_TOOLS): Makefile common.h version.h
9191

9292
fex2bin bin2fex: sunxi-fexc
9393
ln -nsf $< $@
@@ -158,7 +158,10 @@ sunxi-meminfo: meminfo.c
158158
sunxi-script_extractor: script_extractor.c
159159
$(CROSS_COMPILE)gcc -g -O0 -Wall -static -o $@ $^
160160

161+
version.h:
162+
@./autoversion.sh > $@
163+
161164
.gitignore: Makefile
162-
@for x in $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) '*.o' '*.swp'; do \
165+
@for x in $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) version.h '*.o' '*.swp'; do \
163166
echo "$$x"; \
164-
done > $@
167+
done | sort -V > $@

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# sunxi-tools
22
[![License](http://img.shields.io/badge/License-GPL-green.svg)](LICENSE.md)
33
[![Build Status](https://travis-ci.org/linux-sunxi/sunxi-tools.svg?branch=master)](https://travis-ci.org/linux-sunxi/sunxi-tools)
4+
[![Releases](https://img.shields.io/github/release/linux-sunxi/sunxi-tools.svg)](https://github.com/linux-sunxi/sunxi-tools/releases)
45

56
Copyright (C) 2012 Alejandro Mery <amery@geeks.cl>
67
<br>For a full list of contributors, see

autoversion.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# This script auto-updates a VERSION string definition.
3+
# It outputs informational messages to stderr, while the actual
4+
# output (on stdout) can easily be redirected to a file.
5+
#
6+
7+
LATEST_RELEASE="v1.3"
8+
9+
if VER=`git describe --tags --dirty --always`; then
10+
echo "Setting version information: ${VER}" >&2
11+
else
12+
VER=${LATEST_RELEASE}
13+
echo "Unable to determine current version (using \"${VER}\" as fallback)" >&2
14+
fi
15+
echo >&2
16+
17+
echo "/* Auto-generated information. DO NOT EDIT */"
18+
echo "#define VERSION \"${VER}\""

bootinfo.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,13 @@ void print_boot1_file_head(boot1_file_head_t *hdr, loader_type type)
336336
printf("Unknown boot0 header version\n");
337337
}
338338

339+
static void usage(const char *cmd)
340+
{
341+
puts("sunxi-bootinfo " VERSION "\n");
342+
printf("Usage: %s [<filename>]\n", cmd);
343+
printf(" With no <filename> given, will read from stdin instead\n");
344+
}
345+
339346
int main(int argc, char * argv[])
340347
{
341348
FILE *in = stdin;
@@ -352,8 +359,11 @@ int main(int argc, char * argv[])
352359
}
353360
if (argc > 1) {
354361
in = fopen(argv[1], "rb");
355-
if (!in)
356-
fail("open input: ");
362+
if (!in) {
363+
if (*argv[1] == '-')
364+
usage(argv[0]);
365+
fail("open input");
366+
}
357367
}
358368
int len;
359369

common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include <stddef.h> /* offsetof */
2121

22+
#include "version.h" /* auto-generated VERSION string */
23+
2224
/** flag function argument as unused */
2325
#ifdef UNUSED
2426
#elif defined(__GNUC__)

fel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <unistd.h>
2929
#include <sys/stat.h>
3030

31+
#include "common.h"
3132
#include "portable_endian.h"
3233
#include "progress.h"
3334

@@ -1582,6 +1583,7 @@ int main(int argc, char **argv)
15821583
#endif
15831584

15841585
if (argc <= 1) {
1586+
puts("sunxi-fel " VERSION "\n");
15851587
printf("Usage: %s [options] command arguments... [command...]\n"
15861588
" -v, --verbose Verbose logging\n"
15871589
" -p, --progress \"write\" transfers show a progress bar\n"

fexc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ static inline int script_generate(enum script_format format,
215215
*/
216216
static inline void app_usage(const char *arg0, int mode)
217217
{
218+
fputs("sunxi-fexc " VERSION "\n\n", stderr);
218219
errf("Usage: %s [-vq]%s[<input> [<output>]]\n", arg0,
219220
mode ? " " : " [-I <infmt>] [-O <outfmt>] ");
220221

nand-image-builder.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <errno.h>
4040
#include <getopt.h>
4141

42+
#include "common.h"
4243
#include "portable_endian.h"
4344

4445
#if defined(CONFIG_BCH_CONST_PARAMS)
@@ -62,7 +63,6 @@
6263

6364
#define cpu_to_be32 htobe32
6465
#define kfree free
65-
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
6666

6767
#define BCH_PRIMITIVE_POLY 0x5803
6868

@@ -916,7 +916,9 @@ static int create_image(const struct image_info *info)
916916
static void display_help(int status)
917917
{
918918
fprintf(status == EXIT_SUCCESS ? stdout : stderr,
919-
"Usage: sunxi-nand-image-builder [OPTIONS] source-image output-image\n"
919+
"sunxi-nand-image-builder %s\n"
920+
"\n"
921+
"Usage: sunxi-nand-image-builder [OPTIONS] source-image output-image\n"
920922
"\n"
921923
"Creates a raw NAND image that can be read by the sunxi NAND controller.\n"
922924
"\n"
@@ -960,8 +962,8 @@ static void display_help(int status)
960962
" A normal image can be generated with\n"
961963
" sunxi-nand-image-builder -p 16384 -o 1280 -e 0x400000 -s -c 40/1024\n"
962964
" A boot0 image can be generated with\n"
963-
" sunxi-nand-image-builder -p 16384 -o 1280 -e 0x400000 -s -b -u 4096 -c 64/1024\n"
964-
);
965+
" sunxi-nand-image-builder -p 16384 -o 1280 -e 0x400000 -s -b -u 4096 -c 64/1024\n",
966+
VERSION);
965967
exit(status);
966968
}
967969

nand-part-main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
#include <strings.h>
2525
#include <fcntl.h>
2626
#include "nand-common.h"
27+
#include "common.h"
2728

2829
void usage(const char *cmd)
2930
{
31+
puts("sunxi-nand-part " VERSION "\n");
3032
printf("usage: %s [-f a10|a20] nand-device\n", cmd);
3133
printf(" %s nand-device 'name2 len2 [usertype2]' ['name3 len3 [usertype3]'] ...\n", cmd);
3234
printf(" %s [-f a10|a20] nand-device start1 'name1 len1 [usertype1]' ['name2 len2 [usertype2]'] ...\n", cmd);

0 commit comments

Comments
 (0)