Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: implement version information #90

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ qdl-ramdump
ks
compile_commands.json
.cache
.version.h
version.h
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
QDL := qdl
RAMDUMP := qdl-ramdump
GITREF := $(or $(shell git describe --dirty --always --tags), "unknown-version")

CFLAGS += -O2 -Wall -g `pkg-config --cflags libxml-2.0 libusb-1.0`
LDFLAGS += `pkg-config --libs libxml-2.0 libusb-1.0`
Expand All @@ -15,7 +16,7 @@ KS_OUT := ks
KS_SRCS := ks.c sahara.c util.c ux.c
KS_OBJS := $(KS_SRCS:.c=.o)

default: $(QDL) $(RAMDUMP) $(KS_OUT)
default: versionfile $(QDL) $(RAMDUMP) $(KS_OUT)

$(QDL): $(QDL_OBJS)
$(CC) -o $@ $^ $(LDFLAGS)
Expand All @@ -29,11 +30,18 @@ $(KS_OUT): $(KS_OBJS)
compile_commands.json: $(QDL_SRCS) $(KS_SRCS)
@echo -n $^ | jq -snR "[inputs|split(\" \")[]|{directory:\"$(PWD)\", command: \"$(CC) $(CFLAGS) -c \(.)\", file:.}]" > $@

versionfile:
@echo "#define VERSION \"$(GITREF)\"" > .version.h
@cmp -s .version.h version.h || cp .version.h version.h

util.o: version.h

clean:
rm -f $(QDL) $(QDL_OBJS)
rm -f $(RAMDUMP) $(RAMDUMP_OBJS)
rm -f $(KS_OUT) $(KS_OBJS)
rm -f compile_commands.json
rm -f version.h .version.h

install: $(QDL) $(RAMDUMP) $(KS_OUT)
install -d $(DESTDIR)$(prefix)/bin
Expand Down
13 changes: 12 additions & 1 deletion ks.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,21 @@ int main(int argc, char **argv)
int ret;

static struct option options[] = {
{"debug", no_argument, 0, 'd'},
{"version", no_argument, 0, 'v'},
{"port", required_argument, 0, 'p'},
{"sahara", required_argument, 0, 's'},
{0, 0, 0, 0}
};

while ((opt = getopt_long(argc, argv, "p:s:", options, NULL )) != -1) {
while ((opt = getopt_long(argc, argv, "dvp:s:", options, NULL )) != -1) {
switch (opt) {
case 'd':
qdl_debug = true;
break;
case 'v':
print_version();
return 0;
case 'p':
dev_node = optarg;
printf("Using port - %s\n", dev_node);
Expand Down Expand Up @@ -103,6 +111,9 @@ int main(int argc, char **argv)
return 1;
}

if (qdl_debug)
print_version();

qdl.fd = open(dev_node, O_RDWR);
if (qdl.fd < 0) {
fprintf(stderr, "Unable to open %s\n", dev_node);
Expand Down
11 changes: 9 additions & 2 deletions qdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void print_usage(void)
{
extern const char *__progname;
fprintf(stderr,
"%s [--debug] [--allow-missing] [--storage <emmc|nand|ufs>] [--finalize-provisioning] [--include <PATH>] [--serial <NUM>] [--out-chunk-size <SIZE>] <prog.mbn> [<program> <patch> ...]\n",
"%s [--debug] [--version] [--allow-missing] [--storage <emmc|nand|ufs>] [--finalize-provisioning] [--include <PATH>] [--serial <NUM>] [--out-chunk-size <SIZE>] <prog.mbn> [<program> <patch> ...]\n",
__progname);
}

Expand All @@ -125,6 +125,7 @@ int main(int argc, char **argv)

static struct option options[] = {
{"debug", no_argument, 0, 'd'},
{"version", no_argument, 0, 'v'},
{"include", required_argument, 0, 'i'},
{"finalize-provisioning", no_argument, 0, 'l'},
{"out-chunk-size", required_argument, 0, OPT_OUT_CHUNK_SIZE },
Expand All @@ -134,11 +135,14 @@ int main(int argc, char **argv)
{0, 0, 0, 0}
};

while ((opt = getopt_long(argc, argv, "dfi:S:", options, NULL )) != -1) {
while ((opt = getopt_long(argc, argv, "dvfi:S:", options, NULL )) != -1) {
switch (opt) {
case 'd':
qdl_debug = true;
break;
case 'v':
print_version();
return 0;
case 'f':
allow_missing = true;
break;
Expand Down Expand Up @@ -172,6 +176,9 @@ int main(int argc, char **argv)

ux_init();

if (qdl_debug)
print_version();

prog_mbn = argv[optind++];

do {
Expand Down
2 changes: 2 additions & 0 deletions qdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ void ux_log(const char *fmt, ...);
void ux_debug(const char *fmt, ...);
void ux_progress(const char *fmt, unsigned int value, unsigned int size, ...);

void print_version(void);

extern bool qdl_debug;

#endif
9 changes: 8 additions & 1 deletion ramdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ int main(int argc, char **argv)

static struct option options[] = {
{"debug", no_argument, 0, 'd'},
{"version", no_argument, 0, 'v'},
{"output", required_argument, 0, 'o'},
{"serial", required_argument, 0, 'S'},
{0, 0, 0, 0}
};

while ((opt = getopt_long(argc, argv, "do:S:", options, NULL )) != -1) {
while ((opt = getopt_long(argc, argv, "dvo:S:", options, NULL )) != -1) {
switch (opt) {
case 'd':
qdl_debug = true;
break;
case 'v':
print_version();
return 0;
case 'o':
ramdump_path = optarg;
break;
Expand All @@ -54,6 +58,9 @@ int main(int argc, char **argv)
if (optind != argc)
print_usage();

if (qdl_debug)
print_version();

ret = qdl_open(&qdl, serial);
if (ret)
return 1;
Expand Down
8 changes: 8 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <libxml/parser.h>
#include <libxml/tree.h>

#include "version.h"

#define MIN(x, y) ((x) < (y) ? (x) : (y))

static uint8_t to_hex(uint8_t ch)
Expand All @@ -44,6 +46,12 @@ static uint8_t to_hex(uint8_t ch)
return ch <= 9 ? '0' + ch : 'a' + ch - 10;
}

void print_version(void)
{
extern const char *__progname;
fprintf(stdout, "%s version %s\n", __progname, VERSION);
}

void print_hex_dump(const char *prefix, const void *buf, size_t len)
{
const uint8_t *ptr = buf;
Expand Down
Loading