Skip to content
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ VERSION:=${MKBOOTIMAGE_NAME} ${VERSION_MAJOR}-${VERSION_MINOR}
MKBOOTIMAGE_SRCS:=$(wildcard src/*.c) $(wildcard src/arch/*c) $(wildcard src/file/*c)
MKBOOTIMAGE_OBJS:=${MKBOOTIMAGE_SRCS:.c=.o}

MKBOOTIMAGE_INCLUDE_DIRS:=src
MKBOOTIMAGE_INCLUDE_DIRS:=src $(EXTRA_INCLUDES)

CFLAGS += $(foreach includedir,$(MKBOOTIMAGE_INCLUDE_DIRS),-I$(includedir)) \
-DMKBOOTIMAGE_VER="\"$(VERSION)\"" \
Expand All @@ -24,7 +24,7 @@ LDLIBS = -lpcre -lelf
all: $(MKBOOTIMAGE_NAME)

$(MKBOOTIMAGE_NAME): $(MKBOOTIMAGE_OBJS)
$(CC) $(CFLAGS) $(MKBOOTIMAGE_OBJS) -o $(MKBOOTIMAGE_NAME) $(LDLIBS)
$(CC) $(CFLAGS) $(LDFLAGS) $(MKBOOTIMAGE_OBJS) -o $(MKBOOTIMAGE_NAME) $(LDLIBS) $(LDPATHS)

clean:
@- $(RM) $(MKBOOTIMAGE_NAME)
Expand Down
18 changes: 15 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@ It is written entirely in C.

Required C libraries: pcre, libelf.

To build this application run:
make
Supports Linux and FreeBSD host platforms.

To build this application on Linux run:

make

and on FreeBSD run:

gmake CC=cc EXTRA_INCLUDES=/usr/local/include LDPATHS=-L/usr/local/lib

If you need a stand alone executable to move to different versions of your
operating system add to the make command line:

LDFLAGS=-static

To use it, type in:
./mkbootimage [--zynqmp|-u] <input_bif_file> <output_bin_file>
./mkbootimage [--zynqmp|-u] [--quiet|-q] <input_bif_file> <output_bin_file>

Zynq Support:
Currently it supports creating boot image containing fsbl, bitstream,
Expand Down
3 changes: 3 additions & 0 deletions src/bif.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <limits.h>
#ifdef __linux__
#include <linux/limits.h>
#endif

#define BIF_SUCCESS 0
#define BIF_ERROR_NOFILE 1
Expand Down
1 change: 0 additions & 1 deletion src/bootrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <libgen.h>
#include <byteswap.h>

#include <bif.h>
#include <bootrom.h>
Expand Down
140 changes: 69 additions & 71 deletions src/mkbootimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,111 +23,109 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <argp.h>

#include <getopt.h>

#include <bif.h>
#include <bootrom.h>

#include <arch/zynq.h>
#include <arch/zynqmp.h>

/* Prepare global variables for arg parser */
const char *argp_program_version = MKBOOTIMAGE_VER;
/* Program info */
const char *program_version = MKBOOTIMAGE_VER;
static char doc[] = "Generate bootloader images for Xilinx Zynq based platforms.";
static char args_doc[] = "[--zynqmp|-u] <input_bif_file> <output_bin_file>";

static struct argp_option argp_options[] = {
{"zynqmp", 'u', 0, 0, "Generate files for ZyqnMP (default is Zynq)", 0},
{ 0 }
};
static char args_doc[] = "[--zynqmp|-u] [--quiet|-q] <input_bif_file> <output_bin_file>";

/* Prapare struct for holding parsed arguments */
struct arguments {
uint8_t zynqmp;
char *bif_filename;
char *bin_filename;
static struct option longopts[] = {
{ "zynqmp", no_argument, NULL, 'u' },
{ "quiet", no_argument, NULL, 'q' },
{ NULL, 0, NULL, 0 }
};

/* Define argument parser */
static error_t argp_parser(int key, char *arg, struct argp_state *state) {
struct arguments *arguments = state->input;

switch (key) {
case 'u':
arguments->zynqmp = 0xFF;
break;
case ARGP_KEY_ARG:
switch(state->arg_num) {
case 0:
arguments->bif_filename = arg;
break;
case 1:
arguments->bin_filename = arg;
break;
default:
argp_usage(state);
}
break;
case ARGP_KEY_END:
if (state->arg_num < 2)
argp_usage (state);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
void usage(const char* prog) {
fprintf(stderr, "%s %s\n", prog, args_doc);
fprintf(stderr, "%s\n (%s)\n", doc, program_version);
fprintf(stderr, " -u : Generate files for ZyqnMP (default is Zynq). Also --zynqmp.\n");
fprintf(stderr, " -q : Quiet, no status output (default prints status). Also --quiet.\n");
exit(1);
}

/* Finally initialize argp struct */
static struct argp argp = {argp_options, argp_parser, args_doc, doc, 0, 0, 0 };

/* Declare the main function */
int main(int argc, char *argv[]) {
FILE *ofile;
const char* prog_name;
const char *bif_filename, *bin_filename;
uint32_t ofile_size;
uint32_t *file_data;
uint32_t esize, esize_aligned;
struct arguments arguments;
bootrom_ops_t *bops;
bif_cfg_t cfg;
bool quiet = false;
int ret;
int i;
int ch;

/* Init non-string arguments */
arguments.zynqmp = 0;
/* Defaults for the parser the info about arch */
cfg.arch = BIF_ARCH_ZYNQ;
bops = &zynq_bops;

prog_name = argv[0];

/* Parse program arguments */
argp_parse(&argp, argc, argv, 0, 0, &arguments);
while ((ch = getopt_long(argc, argv, "uq", longopts, NULL)) != -1) {
switch (ch) {
case 'u':
cfg.arch = BIF_ARCH_ZYNQMP;
bops = &zynqmp_bops;
break;
case 'q':
quiet = true;
break;
default:
usage(prog_name);
}
}

argc -= optind;
argv += optind;

if (argc != 2)
usage(prog_name);

bif_filename = argv[0];
bin_filename = argv[1];

/* Print program version info */
printf("%s\n", MKBOOTIMAGE_VER);
if (!quiet)
printf("%s\n", MKBOOTIMAGE_VER);

init_bif_cfg(&cfg);

/* Give bif parser the info about arch */
cfg.arch = (arguments.zynqmp) ? BIF_ARCH_ZYNQMP : BIF_ARCH_ZYNQ;
bops = (arguments.zynqmp) ? &zynqmp_bops : &zynq_bops;

ret = parse_bif(arguments.bif_filename, &cfg);
ret = parse_bif(bif_filename, &cfg);
if (ret != BIF_SUCCESS || cfg.nodes_num == 0) {
fprintf(stderr, "Error parsing %s file.\n", arguments.bif_filename);
fprintf(stderr, "Error parsing %s file.\n", bif_filename);
return EXIT_FAILURE;
}

printf("Nodes found in the %s file:\n", arguments.bif_filename);
for (i = 0; i < cfg.nodes_num; i++) {
printf(" %s", cfg.nodes[i].fname);
if (cfg.nodes[i].bootloader)
printf(" (bootloader)\n");
else
printf("\n");
if (cfg.nodes[i].load)
printf(" load: %08x\n", cfg.nodes[i].load);
if (cfg.nodes[i].offset)
printf(" offset: %08x\n", cfg.nodes[i].offset);
if (!quiet) {
printf("Nodes found in the %s file:\n", bif_filename);
for (i = 0; i < cfg.nodes_num; i++) {
printf(" %s", cfg.nodes[i].fname);
if (cfg.nodes[i].bootloader)
printf(" (bootloader)\n");
else
printf("\n");
if (cfg.nodes[i].load)
printf(" load: %08x\n", cfg.nodes[i].load);
if (cfg.nodes[i].offset)
printf(" offset: %08x\n", cfg.nodes[i].offset);
}
}

/* Estimate memory required to fit all the binaries */
Expand All @@ -154,10 +152,10 @@ int main(int argc, char *argv[]) {
return ofile_size;
}

ofile = fopen(arguments.bin_filename, "wb");
ofile = fopen(bin_filename, "wb");

if (ofile == NULL ) {
fprintf(stderr, "Could not open output file: %s\n", arguments.bin_filename);
fprintf(stderr, "Could not open output file: %s\n", bin_filename);
return EXIT_FAILURE;
}

Expand All @@ -167,7 +165,7 @@ int main(int argc, char *argv[]) {
free(file_data);
deinit_bif_cfg(&cfg);

printf("All done, quitting\n");
if (!quiet)
printf("All done, quitting\n");
return EXIT_SUCCESS;
}