1
0
mirror of git://projects.qi-hardware.com/openwrt-xburst.git synced 2024-11-27 17:15:00 +02:00

[tools/firmware-utils] imagetag: Significantly updated brcm63xx imagetag writing tool.

* Rewrote commandline parsing code using gengetopt
		- We now get long options
		- We have more options including use of the info section for 
			board information (e.g. to add the same boardid but
			different GPIOs on different routers)
	* Added back the ability to write stock images (this is useful, for example,
		when copying the firmware from the in-memory flash, and then being
		able to create an image that will let you revert to/test stock firmware
	* Fixed copying of CRCs to use memcpy instead of strncpy (strncpy stops at 0)
	* Added ability to use all sections of the imagetag, including custom magic 
	 	signatures (e.g. for the Telsey router I'm adding soon), info sections,
		and reserved sections
	* Added putting the router type (as defined in the image generating Makefile)
		into the info1 section and the filesystem type in the info2 section.
		This will be used by mtd (when I add the code) to return the name of
		image used to flash this router.  (As requested by Jo, as well as being
		useful for same boardid different board scenario described above).



git-svn-id: svn://svn.openwrt.org/openwrt/trunk@24011 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
cshore 2010-11-16 06:46:53 +00:00
parent 038dd5fbe6
commit 33d20e9dce
6 changed files with 1809 additions and 245 deletions

View File

@ -30,30 +30,32 @@ endef
define Image/Build/CFE
# Generate the tagged image
$(STAGING_DIR_HOST)/bin/imagetag -i $(KDIR)/vmlinux.lzma.cfe -f $(KDIR)/root.$(1) \
-o $(BIN_DIR)/openwrt-$(4)-$(1)-cfe.bin \
-b $(2) -c $(3) -e $(LOADADDR) -l $(LOADADDR) \
-r "$(5)" $(6)
# -b $(2) -c $(3) -e $(KERNEL_ENTRY) -l $(LOADADDR)
--output $(BIN_DIR)/openwrt-$(4)-$(1)-cfe.bin \
--boardid $(2) --chipid $(3) --entry $(KERNEL_ENTRY) \
--load-addr $(LOADADDR) --rsa-signature "$(5)" \
--info1 "$(4) $(REVISION)" --info2 $(1) \
$(6) $(7) $(8) $(9)
endef
define Image/Build/CFEAGPF
# Generate the tagged image
$(STAGING_DIR_HOST)/bin/imagetag -i $(KDIR)/vmlinux.lzma.cfe -f $(KDIR)/root.$(1) \
-o $(BIN_DIR)/openwrt-$(5)-$(1)-cfe.bin \
-b $(2) -c $(3) -e $(LOADADDR) -l $(LOADADDR) \
-v 8 -m IMAGE -k 0x20000 -n $(4)
--output $(BIN_DIR)/openwrt-$(5)-$(1)-cfe.bin \
--boardid $(2) --chipid $(3) --entry $(LOADADDR) \
--load-addr $(LOADADDR) --tag-version 8 \
--signature2 IMAGE --block-size 0x20000 \
--image-offset $(4) --info1 "$(5) $(REVISION)" --info2 $(1)
endef
define Image/Build/RG100A
# Generate the tagged image
$(STAGING_DIR_HOST)/bin/imagetag -i $(KDIR)/vmlinux.lzma.cfe -f $(KDIR)/root.$(1) \
-o $(BIN_DIR)/openwrt-$(5)-$(1)-cfe.bin \
-b $(2) -c $(3) -e $(LOADADDR) -l $(LOADADDR) \
-k 0x20000 -n $(4)
--output $(BIN_DIR)/openwrt-$(5)-$(1)-cfe.bin \
--boardid $(2) --chipid $(3) --entry $(LOADADDR) \
--load-addr $(LOADADDR) --block-size 0x20000 \
--image-offset $(4) --info1 "$(5) $(REVISION)" --info2 $(1)
endef
define Image/Build/RedBoot
cp $(KDIR)/vmlinux.elf $(BIN_DIR)/openwrt-$(1)-vmlinux.elf
gzip -9 -c $(KDIR)/vmlinux > $(KDIR)/vmlinux.bin.gz
@ -106,29 +108,29 @@ define Image/Build
dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
# Various routers
$(call Image/Build/CFE,$(1),96345GW2,6345,96345GW2-generic)
$(call Image/Build/CFE,$(1),96345GW2,6345,96348GW2-bc221,,-y 5)
$(call Image/Build/CFE,$(1),96345GW2,6345,96348GW2-bc221,,--layoutver 5)
$(call Image/Build/CFE,$(1),96345GW2,6345,92345GW2-revision,OpenWRT-$(REVISION))
$(call Image/Build/CFE,$(1),96348GW,6348,96348GW-generic,,)
$(call Image/Build/CFE,$(1),96348GW,6348,96348GW-bc221,,-y 5)
$(call Image/Build/CFE,$(1),96348GW,6348,96348GW-bc221,,--layoutver 5)
$(call Image/Build/CFE,$(1),6338GW,6338,6338GW-generic,,)
$(call Image/Build/CFE,$(1),6338W,6338,6338W-generic,,)
# BT Voyager V210_BTR
$(call Image/Build/CFE,$(1),V210_BB,6348,BTV210_BTR,,-y 5)
$(call Image/Build/CFE,$(1),V210_BB,6348,BTV210_BTR,,--layoutver 5)
# BT Voyager V210_ROI, V210_WB
$(call Image/Build/CFE,$(1),V210,6348,BTV210_ROI_WB,,-y 5)
$(call Image/Build/CFE,$(1),V210,6348,BTV210_ROI_WB,,--layoutver 5)
# BT Voyager V2091_BTR
$(call Image/Build/CFE,$(1),V2091_BB,6348,BTV2091_BTR,,y 5)
$(call Image/Build/CFE,$(1),V2091_BB,6348,BTV2091_BTR,,--layoutver 5)
# BT Voyager V2091_ROI, V2091_WB
$(call Image/Build/CFE,$(1),V2091,6348,BTV2091_ROI_WB,,-y 5)
$(call Image/Build/CFE,$(1),V2091,6348,BTV2091_ROI_WB,,--layoutver 5)
# BT Voyager V220V, V220V_MGCP_BTR
$(call Image/Build/CFE,$(1),RTA1052V,6348,BTV220V_MGCP_BTR,,-y 5)
$(call Image/Build/CFE,$(1),RTA1052V,6348,BTV220V_MGCP_BTR,,--layoutver 5)
# BT Voyager V2110, V2110_AA, V2110_ROI
$(call Image/Build/CFE,$(1),V2110,6348,BTV2110,,-y 5)
$(call Image/Build/CFE,$(1),V2110,6348,BTV2110,,--layoutver 5)
# BT Voyager V2500V, V2500V_SIP_CLUB, V2500V_AA
$(call Image/Build/CFE,$(1),V2500V_BB,6348,BTV2500V,,-y 5)
$(call Image/Build/CFE,$(1),V2500V_BB,6348,BTV2500V,,--layoutver 5)
# RTA1025W_16 (numerous routers)
$(call Image/Build/CFE,$(1),RTA1025W_16,6348,RTA1025W_16,,-y 5)
$(call Image/Build/CFE,$(1),RTA1025W_16,6348,RTA1025W_16,,--layoutver 5)
# Tecom GW6000
$(call Image/Build/CFE,$(1),96348GW,6348,GW6000)
# Tecom GW6200
@ -166,7 +168,7 @@ define Image/Build
# Pirelli A226G
$(call Image/Build/CFEAGPF,$(1),DWV-S0,6358,0x10000,A226G-cfe)
$(call Image/Build/CFEAGPF,$(1),DWV-S0,6358,0x10000,A226G)
# RG100A,DB120 etc.
$(call Image/Build/RG100A,$(1),96358VW2,6358,0x20000,RG100A_DB120)

View File

@ -15,7 +15,6 @@ define cc
$(CC) $(HOST_CFLAGS) -include endian.h -o $(HOST_BUILD_DIR)/bin/$(firstword $(1)) $(foreach src,$(1),src/$(src).c) $(2)
endef
define Host/Compile
mkdir -p $(HOST_BUILD_DIR)/bin
$(call cc,addpattern)
@ -33,7 +32,7 @@ define Host/Compile
$(call cc,mkcasfw)
$(call cc,mkfwimage,-lz)
$(call cc,mkfwimage2,-lz)
$(call cc,imagetag)
$(call cc,imagetag imagetag_cmdline)
$(call cc,add_header)
$(call cc,makeamitbin)
$(call cc,encode_crc)

View File

@ -4,7 +4,7 @@
* for more details.
*
* Copyright (C) 2008 Axel Gembe <ago@bastart.eu.org>
* Copyright (C) 2009 Daniel Dickinson <crazycshore@gmail.com>
* Copyright (C) 2009-2010 Daniel Dickinson <openwrt@cshore.neomailbox.net>
*/
#include <stdio.h>
@ -17,25 +17,10 @@
#include <netinet/in.h>
#include "bcm_tag.h"
#include "imagetag_cmdline.h"
#define IMAGETAG_MAGIC1 "Broadcom Corporatio"
#define IMAGETAG_MAGIC2 "ver. 2.0"
#define IMAGETAG_VER "6"
#define IMAGETAG_DEFAULT_LOADADDR 0x80010000
#define DEFAULT_FW_OFFSET 0x10000
#define DEFAULT_FLASH_START 0xBFC00000
#define DEFAULT_FLASH_BS (64 * 1024)
#define DEADCODE 0xDEADC0DE
union int2char {
uint32_t input;
char output[4];
};
/* Convert uint32_t CRC to bigendian and copy it into a character array */
#define int2tag(tag, value) intchar.input = htonl(value); \
memcpy(tag, intchar.output, sizeof(union int2char))
/* Kernel header */
struct kernelhdr {
uint32_t loadaddr; /* Kernel load address */
@ -80,6 +65,11 @@ static uint32_t crc32tab[256] = {
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
};
void int2tag(char *tag, uint32_t value) {
uint32_t network = htonl(value);
memcpy(tag, (char *)(&network), 4);
}
uint32_t crc32(uint32_t crc, uint8_t *data, size_t len)
{
while (len--)
@ -126,39 +116,30 @@ size_t getlen(FILE *fp)
return retval;
}
int tagfile(const char *kernel, const char *rootfs, const char *bin,
const char *boardid, const char *chipid, const uint32_t fwaddr,
const uint32_t loadaddr, const uint32_t entry,
const char *ver, const char *magic2, const uint32_t flash_bs,
const char *rsignature, const char *layoutver)
int tagfile(const char *kernel, const char *rootfs, const char *bin, \
const struct gengetopt_args_info *args, \
uint32_t flash_start, uint32_t image_offset, \
uint32_t block_size, uint32_t load_address, uint32_t entry)
{
struct bcm_tag tag;
struct kernelhdr khdr;
FILE *kernelfile = NULL, *rootfsfile = NULL, *binfile;
size_t kerneloff, kernellen, rootfsoff, rootfslen, read, imagelen, rootfsoffpadlen, kernelfslen;
FILE *kernelfile = NULL, *rootfsfile = NULL, *binfile = NULL, *cfefile = NULL;
size_t cfeoff, cfelen, kerneloff, kernellen, rootfsoff, rootfslen, \
read, imagelen, rootfsoffpadlen = 0, kernelfslen, kerneloffpadlen = 0, oldrootfslen;
uint8_t readbuf[1024];
uint32_t imagecrc = IMAGETAG_CRC_START;
uint32_t kernelcrc = IMAGETAG_CRC_START;
uint32_t rootfscrc = IMAGETAG_CRC_START;
uint32_t kernelfscrc = IMAGETAG_CRC_START;
uint32_t fwaddr = 0;
uint8_t crc_val;
const uint32_t deadcode = htonl(DEADCODE);
union int2char intchar;
int i;
int is_pirelli = 0;
int i;
int is_pirelli = 0;
memset(&tag, 0, sizeof(struct bcm_tag));
if (strlen(boardid) >= sizeof(tag.boardid)) {
fprintf(stderr, "Board id is too long!\n");
return 1;
}
/* Likewise chipid */
if (strlen(chipid) >= sizeof(tag.chipid)) {
fprintf(stderr, "Chip id is too long!\n");
return 1;
}
if (!kernel || !rootfs) {
fprintf(stderr, "imagetag can't create an image without both kernel and rootfs\n");
}
@ -178,122 +159,253 @@ int tagfile(const char *kernel, const char *rootfs, const char *bin,
return 1;
}
/* Build the kernel address and length (doesn't need to be aligned, read only) */
kerneloff = fwaddr + sizeof(tag);
kernellen = getlen(kernelfile);
if ((args->cfe_given) && (args->cfe_arg)) {
if (!(cfefile = fopen(args->cfe_arg, "rb"))) {
fprintf(stderr, "Unable to open CFE file \"%s\"\n", args->cfe_arg);
}
}
/* Build the kernel header */
khdr.loadaddr = htonl(loadaddr);
khdr.entry = htonl(entry);
khdr.lzmalen = htonl(kernellen);
fwaddr = flash_start + image_offset;
if (cfefile) {
cfeoff = flash_start;
cfelen = getlen(cfefile);
/* Seek to the start of the file after tag */
fseek(binfile, sizeof(tag), SEEK_SET);
/* Write the cfe */
while (cfefile && !feof(cfefile) && !ferror(cfefile)) {
read = fread(readbuf, sizeof(uint8_t), sizeof(readbuf), cfefile);
fwrite(readbuf, sizeof(uint8_t), read, binfile);
}
/* Increase the kernel size by the header size */
kernellen += sizeof(khdr);
} else {
cfeoff = 0;
cfelen = 0;
}
/* Build the rootfs address and length (start and end do need to be aligned on flash erase block boundaries */
rootfsoff = kerneloff + kernellen;
rootfsoff = (rootfsoff % flash_bs) > 0 ? (((rootfsoff / flash_bs) + 1) * flash_bs) : rootfsoff;
rootfslen = getlen(rootfsfile);
rootfslen = ( (rootfslen % flash_bs) > 0 ? (((rootfslen / flash_bs) + 1) * flash_bs) : rootfslen );
imagelen = rootfsoff + rootfslen - kerneloff + sizeof(deadcode);
rootfsoffpadlen = rootfsoff - (kerneloff + kernellen);
/* Seek to the start of the kernel */
fseek(binfile, kerneloff - fwaddr, SEEK_SET);
/* Write the kernel header */
fwrite(&khdr, sizeof(khdr), 1, binfile);
/* Write the kernel */
while (kernelfile && !feof(kernelfile) && !ferror(kernelfile)) {
if (!args->root_first_flag) {
/* Build the kernel address and length (doesn't need to be aligned, read only) */
kerneloff = fwaddr + sizeof(tag);
kernellen = getlen(kernelfile);
if (!args->kernel_file_has_header_flag) {
/* Build the kernel header */
khdr.loadaddr = htonl(load_address);
khdr.entry = htonl(entry);
khdr.lzmalen = htonl(kernellen);
/* Increase the kernel size by the header size */
kernellen += sizeof(khdr);
}
/* Build the rootfs address and length (start and end do need to be aligned on flash erase block boundaries */
rootfsoff = kerneloff + kernellen;
rootfsoff = (rootfsoff % block_size) > 0 ? (((rootfsoff / block_size) + 1) * block_size) : rootfsoff;
rootfslen = getlen(rootfsfile);
rootfslen = ( (rootfslen % block_size) > 0 ? (((rootfslen / block_size) + 1) * block_size) : rootfslen );
imagelen = rootfsoff + rootfslen - kerneloff + sizeof(deadcode);
rootfsoffpadlen = rootfsoff - (kerneloff + kernellen);
/* Seek to the start of the kernel */
fseek(binfile, kerneloff - fwaddr + cfelen, SEEK_SET);
/* Write the kernel header */
fwrite(&khdr, sizeof(khdr), 1, binfile);
/* Write the kernel */
while (kernelfile && !feof(kernelfile) && !ferror(kernelfile)) {
read = fread(readbuf, sizeof(uint8_t), sizeof(readbuf), kernelfile);
fwrite(readbuf, sizeof(uint8_t), read, binfile);
}
}
/* Write the RootFS */
fseek(binfile, rootfsoff - fwaddr, SEEK_SET);
while (rootfsfile && !feof(rootfsfile) && !ferror(rootfsfile)) {
/* Write the RootFS */
fseek(binfile, rootfsoff - fwaddr + cfelen, SEEK_SET);
while (rootfsfile && !feof(rootfsfile) && !ferror(rootfsfile)) {
read = fread(readbuf, sizeof(uint8_t), sizeof(readbuf), rootfsfile);
fwrite(readbuf, sizeof(uint8_t), read, binfile);
}
/* Align image to specified erase block size and append deadc0de */
printf("Data alignment to %dk with 'deadc0de' appended\n", block_size/1024);
fseek(binfile, rootfsoff + rootfslen - fwaddr + cfelen, SEEK_SET);
fwrite(&deadcode, sizeof(uint32_t), 1, binfile);
/* Flush the binfile buffer so that when we read from file, it contains
* everything in the buffer
*/
fflush(binfile);
/* Compute the crc32 of the entire image (deadC0de included) */
imagecrc = compute_crc32(imagecrc, binfile, kerneloff - fwaddr + cfelen, imagelen);
/* Compute the crc32 of the kernel and padding between kernel and rootfs) */
kernelcrc = compute_crc32(kernelcrc, binfile, kerneloff - fwaddr + cfelen, kernellen + rootfsoffpadlen);
/* Compute the crc32 of the kernel and padding between kernel and rootfs) */
kernelfscrc = compute_crc32(kernelfscrc, binfile, kerneloff - fwaddr + cfelen, kernellen + rootfsoffpadlen + rootfslen + sizeof(deadcode));
/* Compute the crc32 of the flashImageStart to rootLength.
* The broadcom firmware assumes the rootfs starts the image,
* therefore uses the rootfs start to determine where to flash
* the image. Since we have the kernel first we have to give
* it the kernel address, but the crc uses the length
* associated with this address, which is added to the kernel
* length to determine the length of image to flash and thus
* needs to be rootfs + deadcode
*/
rootfscrc = compute_crc32(rootfscrc, binfile, kerneloff - fwaddr + cfelen, rootfslen + sizeof(deadcode));
} else {
/* Build the kernel address and length (doesn't need to be aligned, read only) */
rootfsoff = fwaddr + sizeof(tag);
oldrootfslen = getlen(rootfsfile);
rootfslen = oldrootfslen;
rootfslen = ( (rootfslen % block_size) > 0 ? (((rootfslen / block_size) + 1) * block_size) : rootfslen );
kerneloffpadlen = rootfslen - oldrootfslen;
kerneloff = rootfsoff + rootfslen;
kernellen = getlen(kernelfile);
imagelen = cfelen + rootfslen + kernellen;
/* Seek to the start of the kernel */
fseek(binfile, kerneloff - fwaddr + cfelen, SEEK_SET);
if (!args->kernel_file_has_header_flag) {
/* Build the kernel header */
khdr.loadaddr = htonl(load_address);
khdr.entry = htonl(entry);
khdr.lzmalen = htonl(kernellen);
/* Write the kernel header */
fwrite(&khdr, sizeof(khdr), 1, binfile);
/* Increase the kernel size by the header size */
kernellen += sizeof(khdr);
}
/* Write the kernel */
while (kernelfile && !feof(kernelfile) && !ferror(kernelfile)) {
read = fread(readbuf, sizeof(uint8_t), sizeof(readbuf), kernelfile);
fwrite(readbuf, sizeof(uint8_t), read, binfile);
}
/* Write the RootFS */
fseek(binfile, rootfsoff - fwaddr + cfelen, SEEK_SET);
while (rootfsfile && !feof(rootfsfile) && !ferror(rootfsfile)) {
read = fread(readbuf, sizeof(uint8_t), sizeof(readbuf), rootfsfile);
fwrite(readbuf, sizeof(uint8_t), read, binfile);
}
/* Flush the binfile buffer so that when we read from file, it contains
* everything in the buffer
*/
fflush(binfile);
/* Compute the crc32 of the entire image (deadC0de included) */
imagecrc = compute_crc32(imagecrc, binfile, sizeof(tag), imagelen);
/* Compute the crc32 of the kernel and padding between kernel and rootfs) */
kernelcrc = compute_crc32(kernelcrc, binfile, kerneloff - fwaddr + cfelen, kernellen + rootfsoffpadlen);
kernelfscrc = compute_crc32(kernelfscrc, binfile, rootfsoff - fwaddr + cfelen, kernellen + rootfslen);
rootfscrc = compute_crc32(rootfscrc, binfile, rootfsoff - fwaddr + cfelen, rootfslen);
}
/* Align image to specified erase block size and append deadc0de */
printf("Data alignment to %dk with 'deadc0de' appended\n", flash_bs/1024);
fseek(binfile, rootfsoff + rootfslen - fwaddr, SEEK_SET);
fwrite(&deadcode, sizeof(uint32_t), 1, binfile);
/* Flush the binfile buffer so that when we read from file, it contains
* everything in the buffer
*/
fflush(binfile);
/* Compute the crc32 of the entire image (deadC0de included) */
imagecrc = compute_crc32(imagecrc, binfile, kerneloff - fwaddr, imagelen);
/* Compute the crc32 of the kernel and padding between kernel and rootfs) */
kernelcrc = compute_crc32(kernelcrc, binfile, kerneloff - fwaddr, kernellen + rootfsoffpadlen);
/* Compute the crc32 of the kernel and padding between kernel and rootfs) */
kernelfscrc = compute_crc32(kernelfscrc, binfile, kerneloff - fwaddr, kernellen + rootfsoffpadlen + rootfslen + sizeof(deadcode));
/* Compute the crc32 of the flashImageStart to rootLength.
* The broadcom firmware assumes the rootfs starts the image,
* therefore uses the rootfs start to determine where to flash
* the image. Since we have the kernel first we have to give
* it the kernel address, but the crc uses the length
* associated with this address, which is added to the kernel
* length to determine the length of image to flash and thus
* needs to be rootfs + deadcode
*/
rootfscrc = compute_crc32(rootfscrc, binfile, kerneloff - fwaddr, rootfslen + sizeof(deadcode));
/* Close the files */
if (cfefile) {
fclose(cfefile);
}
fclose(kernelfile);
fclose(rootfsfile);
/* Build the tag */
strncpy(tag.tagVersion, ver, TAGVER_LEN);
strncpy(tag.sig_1, IMAGETAG_MAGIC1, sizeof(tag.sig_1) - 1);
strncpy(tag.sig_2, magic2, sizeof(tag.sig_2) - 1);
strcpy(tag.chipid, chipid);
strcpy(tag.boardid, boardid);
strncpy(tag.tagVersion, args->tag_version_arg, sizeof(tag.tagVersion) - 1);
strncpy(tag.sig_1, args->signature_arg, sizeof(tag.sig_1) - 1);
strncpy(tag.sig_2, args->signature2_arg, sizeof(tag.sig_2) - 1);
strncpy(tag.chipid, args->chipid_arg, sizeof(tag.chipid) - 1);
strncpy(tag.boardid, args->boardid_arg, sizeof(tag.boardid) - 1);
strcpy(tag.big_endian, "1");
sprintf(tag.totalLength, "%lu", imagelen);
/* We don't include CFE */
strcpy(tag.cfeAddress, "0");
strcpy(tag.cfeLength, "0");
sprintf(tag.kernelAddress, "%lu", kerneloff);
sprintf(tag.kernelLength, "%lu", kernellen + rootfsoffpadlen);
sprintf(tag.flashImageStart, "%lu", kerneloff);
sprintf(tag.rootLength, "%lu", rootfslen + sizeof(deadcode));
if (rsignature) {
strncpy(tag.rsa_signature, rsignature, RSASIG_LEN);
if (args->cfe_given) {
sprintf(tag.cfeAddress, "%lu", flash_start);
sprintf(tag.cfeLength, "%lu", cfelen);
} else {
/* We don't include CFE */
strcpy(tag.cfeAddress, "0");
strcpy(tag.cfeLength, "0");
}
if (layoutver) {
strncpy(tag.flashLayoutVer, layoutver, TAGLAYOUT_LEN);
sprintf(tag.kernelAddress, "%lu", kerneloff);
sprintf(tag.kernelLength, "%lu", kernellen + rootfsoffpadlen);
if (args->root_first_flag) {
sprintf(tag.flashImageStart, "%lu", rootfsoff);
sprintf(tag.rootLength, "%lu", rootfslen);
} else {
sprintf(tag.flashImageStart, "%lu", kerneloff);
sprintf(tag.rootLength, "%lu", rootfslen + sizeof(deadcode));
}
if (args->rsa_signature_given) {
strncpy(tag.rsa_signature, args->rsa_signature_arg, RSASIG_LEN);
}
if (args->layoutver_given) {
strncpy(tag.flashLayoutVer, args->layoutver_arg, TAGLAYOUT_LEN);
}
if (args->info1_given) {
strncpy(tag.information1, args->info1_arg, TAGINFO1_LEN);
}
if (args->info2_given) {
strncpy(tag.information2, args->info2_arg, TAGINFO2_LEN);
}
if (args->reserved1_given) {
strncpy(tag.reserved1, args->reserved1_arg, 8);
}
if (args->reserved2_given) {
strncpy(tag.reserved2, args->reserved2_arg, 16);
}
if (args->altinfo_given) {
strncpy(&tag.information1[0], args->altinfo_arg, ALTTAGINFO_LEN);
}
if (args->second_image_flag_given) {
if (strncmp(args->second_image_flag_arg, "2", DUALFLAG_LEN) != 0) {
strncpy(tag.dualImage, args->second_image_flag_arg, DUALFLAG_LEN);
}
}
if (args->inactive_given) {
if (strncmp(args->inactive_arg, "2", INACTIVEFLAG_LEN) != 0) {
strncpy(tag.inactiveFlag, args->second_image_flag_arg, INACTIVEFLAG_LEN);
}
}
for (i = 0; i < NUM_PIRELLI; i++) {
if (strncmp(boardid, pirellitab[i], BOARDID_LEN) == 0) {
if (strncmp(args->boardid_arg, pirellitab[i], BOARDID_LEN) == 0) {
is_pirelli = 1;
break;
}
}
if ( !is_pirelli ) {
int2tag(tag.imageCRC, imagecrc);
int2tag(tag.imageCRC, kernelfscrc);
} else {
int2tag(tag.imageCRC, kernelcrc);
int2tag(tag.imageCRC, kernelcrc);
}
int2tag(tag.kernelCRC, kernelcrc);
int2tag(tag.rootfsCRC, rootfscrc);
int2tag(&(tag.rootfsCRC[0]), rootfscrc);
int2tag(tag.kernelCRC, kernelcrc);
int2tag(tag.fskernelCRC, kernelfscrc);
int2tag(tag.headerCRC, crc32(IMAGETAG_CRC_START, (uint8_t*)&tag, sizeof(tag) - 20));
fseek(binfile, 0L, SEEK_SET);
fwrite(&tag, sizeof(uint8_t), sizeof(tag), binfile);
fflush(binfile);
fclose(binfile);
return 0;
@ -301,122 +413,93 @@ int tagfile(const char *kernel, const char *rootfs, const char *bin,
int main(int argc, char **argv)
{
int c, i;
char *kernel, *rootfs, *bin, *boardid, *chipid, *magic2, *ver, *tagid, *rsignature, *layoutver;
uint32_t flashstart, fwoffset, loadaddr, entry;
uint32_t fwaddr, flash_bs;
int tagidfound = 0;
int c, i;
char *kernel, *rootfs, *bin;
uint32_t flash_start, image_offset, block_size, load_address, entry;
flash_start = image_offset = block_size = load_address = entry = 0;
struct gengetopt_args_info parsed_args;
kernel = rootfs = bin = boardid = chipid = magic2 = ver = rsignature = layoutver = NULL;
entry = 0;
kernel = rootfs = bin = NULL;
flashstart = DEFAULT_FLASH_START;
fwoffset = DEFAULT_FW_OFFSET;
loadaddr = IMAGETAG_DEFAULT_LOADADDR;
flash_bs = DEFAULT_FLASH_BS;
if (cmdline_parser(argc, argv, &parsed_args)) {
exit(1);
}
printf("Broadcom image tagger - v1.0.0\n");
printf("Broadcom 63xx image tagger - v2.0.0\n");
printf("Copyright (C) 2008 Axel Gembe\n");
printf("Copyright (C) 2009-2010 Daniel Dickinson\n");
printf("Licensed under the terms of the Gnu General Public License\n");
while ((c = getopt(argc, argv, "i:f:o:b:c:s:n:v:m:k:l:e:h:r:y:")) != -1) {
switch (c) {
case 'i':
kernel = optarg;
break;
case 'f':
rootfs = optarg;
break;
case 'o':
bin = optarg;
break;
case 'b':
boardid = optarg;
break;
case 'c':
chipid = optarg;
break;
case 's':
flashstart = strtoul(optarg, NULL, 16);
break;
case 'n':
fwoffset = strtoul(optarg, NULL, 16);
break;
case 'v':
ver = optarg;
break;
case 'm':
magic2 = optarg;
break;
case 'k':
flash_bs = strtoul(optarg, NULL, 16);
break;
case 'l':
loadaddr = strtoul(optarg, NULL, 16);
break;
case 'e':
entry = strtoul(optarg, NULL, 16);
break;
case 'r':
rsignature = optarg;
break;
case 'y':
layoutver = optarg;
break;
case 'h':
default:
fprintf(stderr, "Usage: imagetag <parameters>\n\n");
fprintf(stderr, " -i <kernel> - The LZMA compressed kernel file to include in the image\n");
fprintf(stderr, " -f <rootfs> - The RootFS file to include in the image\n");
fprintf(stderr, " -o <bin> - The output file\n");
fprintf(stderr, " -b <boardid> - The board id to set in the image (i.e. \"96345GW2\")\n");
fprintf(stderr, " -c <chipid> - The chip id to set in the image (i.e. \"6345\")\n");
fprintf(stderr, " -s <flashstart> - Flash start address (i.e. \"0xBFC00000\"\n");
fprintf(stderr, " -n <fwoffset> - \n");
fprintf(stderr, " -v <version> - \n");
fprintf(stderr, " -m <magic2> - \n");
fprintf(stderr, " -k <flash_bs> - flash erase block size\n");
fprintf(stderr, " -l <loadaddr> - Address where the kernel expects to be loaded (defaults to 0x80010000)\n");
fprintf(stderr, " -e <entry> - Address where the kernel entry point will end up\n");
fprintf(stderr, " -r <signature> - vendor specific signature, for those that need it");
fprintf(stderr, " -y <layoutver> - Flash Layout Version (2.2x code versions need this)");
fprintf(stderr, " -h - Displays this text\n\n");
return 1;
}
kernel = parsed_args.kernel_arg;
rootfs = parsed_args.rootfs_arg;
bin = parsed_args.output_arg;
if (strlen(parsed_args.tag_version_arg) >= TAGVER_LEN) {
fprintf(stderr, "Error: Tag Version (tag_version,v) too long.\n");
exit(1);
}
if (strlen(parsed_args.boardid_arg) >= BOARDID_LEN) {
fprintf(stderr, "Error: Board ID (boardid,b) too long.\n");
exit(1);
}
if (strlen(parsed_args.chipid_arg) >= CHIPID_LEN) {
fprintf(stderr, "Error: Chip ID (chipid,c) too long.\n");
exit(1);
}
if (strlen(parsed_args.signature_arg) >= SIG1_LEN) {
fprintf(stderr, "Error: Magic string (signature,a) too long.\n");
exit(1);
}
if (strlen(parsed_args.signature2_arg) >= SIG2_LEN) {
fprintf(stderr, "Error: Second magic string (signature2,m) too long.\n");
exit(1);
}
if (parsed_args.layoutver_given) {
if (strlen(parsed_args.layoutver_arg) > FLASHLAYOUTVER_LEN) {
fprintf(stderr, "Error: Flash layout version (layoutver,y) too long.\n");
exit(1);
}
}
if (parsed_args.rsa_signature_given) {
if (strlen(parsed_args.rsa_signature_arg) > RSASIG_LEN) {
fprintf(stderr, "Error: RSA Signature (rsa_signature,r) too long.\n");
exit(1);
}
}
if (!boardid || !chipid) {
fprintf(stderr, "You need to specify the board (-b) and chip id (-c)!\n");
return 1;
if (parsed_args.info1_given) {
if (strlen(parsed_args.info1_arg) >= TAGINFO1_LEN) {
fprintf(stderr, "Error: Vendor Information 1 (info1) too long.\n");
exit(1);
}
}
if (entry == 0) {
fprintf(stderr, "You need to specify the kernel entry (-e)\n");
return 1;
if (parsed_args.info2_given) {
if (strlen(parsed_args.info2_arg) >= TAGINFO2_LEN) {
fprintf(stderr, "Error: Vendor Information 2 (info2) too long.\n");
exit(1);
}
}
/* Fallback to defaults */
fwaddr = flashstart + fwoffset;
if (!magic2) {
magic2 = malloc(sizeof(char) * 14);
if (!magic2) {
perror("malloc");
return 1;
}
strcpy(magic2, IMAGETAG_MAGIC2);
if (parsed_args.altinfo_given) {
if (strlen(parsed_args.altinfo_arg) >= ALTTAGINFO_LEN) {
fprintf(stderr, "Error: Vendor Information 1 (info1) too long.\n");
exit(1);
}
}
flash_start = strtoul(parsed_args.flash_start_arg, NULL, 16);
image_offset = strtoul(parsed_args.image_offset_arg, NULL, 16);
block_size = strtoul(parsed_args.block_size_arg, NULL, 16);
if (!ver) {
ver = malloc(sizeof(char) * 4);
if (!ver) {
perror("malloc");
return 1;
}
strcpy(ver, IMAGETAG_VER);
if (!parsed_args.kernel_file_has_header_flag) {
load_address = strtoul(parsed_args.load_addr_arg, NULL, 16);
entry = strtoul(parsed_args.entry_arg, NULL, 16);
if (load_address == 0) {
fprintf(stderr, "Error: Invalid value for load address\n");
}
if (entry == 0) {
fprintf(stderr, "Error: Invalid value for entry\n");
}
}
return tagfile(kernel, rootfs, bin, boardid, chipid, fwaddr, loadaddr, entry, ver, magic2, flash_bs, rsignature, layoutver);
return tagfile(kernel, rootfs, bin, &parsed_args, flash_start, image_offset, block_size, load_address, entry);
}

View File

@ -0,0 +1,45 @@
# Command line option parsing generator file for imagetag
# Supplied-To: gengetopt
#
# Copyright 2010 Daniel Dickinson <openwrt@cshore.neomailbox.net>
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive
# for more details.
#
package "imagetag"
version "2.0.0"
purpose "Generate image with CFE imagetag for Broadcom 63xx routers."
description "Copyright (C) 2008 Axel Gembe
Copyright (C) 2009-2010 Daniel Dickinson
Licensed unter the terms of the Gnu General Public License.
Given a root filesystem, a linux kernel, and an optional CFE, generates an image with an imagetag for a Broadcom 63xx-based router. Additional parameters to be specified depend on the specfic brand and model of router."
args "--file-name=imagetag_cmdline"
option "kernel" i "File with LZMA compressed kernel to include in the image." string typestr="filename" required
option "rootfs" f "File with RootFS to include in the image." string typestr="filename" required
option "output" o "Name of output file." string typestr="filename" required
option "cfe" - "File with CFE to include in the image." string typestr="filename" optional
option "boardid" b "Board ID to set in the image (must match what router expects, e.g. \"96345GW2\")." string required
option "chipid" c "Chip ID to set in the image (must match the actual hardware, e.g. \"6345\")." string required
option "flash-start" s "Flash start address." string typestr="address" optional default="0xBFC00000"
option "image-offset" n "Offset from start address for the first byte after the CFE (in memory)." string typestr="offset" default="0x10000" optional
option "tag-version" v "Version number for imagetag format." string default="6" optional
option "signature" a "Magic string (signature), for boards that need it." string default="Broadcom Corporatio" optional
option "signature2" m "Second magic string (signature2)." string default="ver. 2.0" optional
option "block-size" k "Flash erase block size." string optional default="0x10000"
option "load-addr" l "Kernel load address." string typestr="address" required
option "entry" e "Address where the kernel entry point will be for booting." string typestr="address" required
option "layoutver" y "Flash layout version (version 2.2x of the Broadcom code requires this)." string optional
option "info1" 1 "String for first vendor information section." string optional
option "altinfo" - "String for vendor information section (alternate/pirelli)." string optional
option "info2" 2 "String for second vendor information section." string optional
option "root-first" - "Put the rootfs before the kernel (only for stock images, e.g. captured from the router's flash memory)." flag off
option "rsa-signature" r "String for RSA Signature section." string optional
option "second-image-flag" - "Dual Image Flag (2=not-specified)." values="0", "1", "2" default="2" typestr="flag-value" optional
option "inactive" - "Inactive Flag (2=not-specified)." values="0", "1", "2" default="2" typestr="flag-value" optional
option "reserved1" - "String for first reserved section." string optional
option "reserved2" - "String for second reserved section." string optional
option "kernel-file-has-header" - "Indicates that the kernel file includes the kernel header with correct load address and entry point, so no changes are needed" flag off

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,272 @@
/** @file imagetag_cmdline.h
* @brief The header file for the command line option parser
* generated by GNU Gengetopt version 2.22.4
* http://www.gnu.org/software/gengetopt.
* DO NOT modify this file, since it can be overwritten
* @author GNU Gengetopt by Lorenzo Bettini */
#ifndef IMAGETAG_CMDLINE_H
#define IMAGETAG_CMDLINE_H
/* If we use autoconf. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h> /* for FILE */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifndef CMDLINE_PARSER_PACKAGE
/** @brief the program name (used for printing errors) */
#define CMDLINE_PARSER_PACKAGE "imagetag"
#endif
#ifndef CMDLINE_PARSER_PACKAGE_NAME
/** @brief the complete program name (used for help and version) */
#define CMDLINE_PARSER_PACKAGE_NAME "imagetag"
#endif
#ifndef CMDLINE_PARSER_VERSION
/** @brief the program version */
#define CMDLINE_PARSER_VERSION "2.0.0"
#endif
/** @brief Where the command line options are stored */
struct gengetopt_args_info
{
const char *help_help; /**< @brief Print help and exit help description. */
const char *version_help; /**< @brief Print version and exit help description. */
char * kernel_arg; /**< @brief File with LZMA compressed kernel to include in the image.. */
char * kernel_orig; /**< @brief File with LZMA compressed kernel to include in the image. original value given at command line. */
const char *kernel_help; /**< @brief File with LZMA compressed kernel to include in the image. help description. */
char * rootfs_arg; /**< @brief File with RootFS to include in the image.. */
char * rootfs_orig; /**< @brief File with RootFS to include in the image. original value given at command line. */
const char *rootfs_help; /**< @brief File with RootFS to include in the image. help description. */
char * output_arg; /**< @brief Name of output file.. */
char * output_orig; /**< @brief Name of output file. original value given at command line. */
const char *output_help; /**< @brief Name of output file. help description. */
char * cfe_arg; /**< @brief File with CFE to include in the image.. */
char * cfe_orig; /**< @brief File with CFE to include in the image. original value given at command line. */
const char *cfe_help; /**< @brief File with CFE to include in the image. help description. */
char * boardid_arg; /**< @brief Board ID to set in the image (must match what router expects, e.g. \"96345GW2\").. */
char * boardid_orig; /**< @brief Board ID to set in the image (must match what router expects, e.g. \"96345GW2\"). original value given at command line. */
const char *boardid_help; /**< @brief Board ID to set in the image (must match what router expects, e.g. \"96345GW2\"). help description. */
char * chipid_arg; /**< @brief Chip ID to set in the image (must match the actual hardware, e.g. \"6345\").. */
char * chipid_orig; /**< @brief Chip ID to set in the image (must match the actual hardware, e.g. \"6345\"). original value given at command line. */
const char *chipid_help; /**< @brief Chip ID to set in the image (must match the actual hardware, e.g. \"6345\"). help description. */
char * flash_start_arg; /**< @brief Flash start address. (default='0xBFC00000'). */
char * flash_start_orig; /**< @brief Flash start address. original value given at command line. */
const char *flash_start_help; /**< @brief Flash start address. help description. */
char * image_offset_arg; /**< @brief Offset from start address for the first byte after the CFE (in memory). (default='0x10000'). */
char * image_offset_orig; /**< @brief Offset from start address for the first byte after the CFE (in memory). original value given at command line. */
const char *image_offset_help; /**< @brief Offset from start address for the first byte after the CFE (in memory). help description. */
char * tag_version_arg; /**< @brief Version number for imagetag format. (default='6'). */
char * tag_version_orig; /**< @brief Version number for imagetag format. original value given at command line. */
const char *tag_version_help; /**< @brief Version number for imagetag format. help description. */
char * signature_arg; /**< @brief Magic string (signature), for boards that need it. (default='Broadcom Corporatio'). */
char * signature_orig; /**< @brief Magic string (signature), for boards that need it. original value given at command line. */
const char *signature_help; /**< @brief Magic string (signature), for boards that need it. help description. */
char * signature2_arg; /**< @brief Second magic string (signature2). (default='ver. 2.0'). */
char * signature2_orig; /**< @brief Second magic string (signature2). original value given at command line. */
const char *signature2_help; /**< @brief Second magic string (signature2). help description. */
char * block_size_arg; /**< @brief Flash erase block size. (default='0x10000'). */
char * block_size_orig; /**< @brief Flash erase block size. original value given at command line. */
const char *block_size_help; /**< @brief Flash erase block size. help description. */
char * load_addr_arg; /**< @brief Kernel load address.. */
char * load_addr_orig; /**< @brief Kernel load address. original value given at command line. */
const char *load_addr_help; /**< @brief Kernel load address. help description. */
char * entry_arg; /**< @brief Address where the kernel entry point will be for booting.. */
char * entry_orig; /**< @brief Address where the kernel entry point will be for booting. original value given at command line. */
const char *entry_help; /**< @brief Address where the kernel entry point will be for booting. help description. */
char * layoutver_arg; /**< @brief Flash layout version (version 2.2x of the Broadcom code requires this).. */
char * layoutver_orig; /**< @brief Flash layout version (version 2.2x of the Broadcom code requires this). original value given at command line. */
const char *layoutver_help; /**< @brief Flash layout version (version 2.2x of the Broadcom code requires this). help description. */
char * info1_arg; /**< @brief String for first vendor information section.. */
char * info1_orig; /**< @brief String for first vendor information section. original value given at command line. */
const char *info1_help; /**< @brief String for first vendor information section. help description. */
char * altinfo_arg; /**< @brief String for vendor information section (alternate/pirelli).. */
char * altinfo_orig; /**< @brief String for vendor information section (alternate/pirelli). original value given at command line. */
const char *altinfo_help; /**< @brief String for vendor information section (alternate/pirelli). help description. */
char * info2_arg; /**< @brief String for second vendor information section.. */
char * info2_orig; /**< @brief String for second vendor information section. original value given at command line. */
const char *info2_help; /**< @brief String for second vendor information section. help description. */
int root_first_flag; /**< @brief Put the rootfs before the kernel (only for stock images, e.g. captured from the router's flash memory). (default=off). */
const char *root_first_help; /**< @brief Put the rootfs before the kernel (only for stock images, e.g. captured from the router's flash memory). help description. */
char * rsa_signature_arg; /**< @brief String for RSA Signature section.. */
char * rsa_signature_orig; /**< @brief String for RSA Signature section. original value given at command line. */
const char *rsa_signature_help; /**< @brief String for RSA Signature section. help description. */
char * second_image_flag_arg; /**< @brief Dual Image Flag (2=not-specified). (default='2'). */
char * second_image_flag_orig; /**< @brief Dual Image Flag (2=not-specified). original value given at command line. */
const char *second_image_flag_help; /**< @brief Dual Image Flag (2=not-specified). help description. */
char * inactive_arg; /**< @brief Inactive Flag (2=not-specified). (default='2'). */
char * inactive_orig; /**< @brief Inactive Flag (2=not-specified). original value given at command line. */
const char *inactive_help; /**< @brief Inactive Flag (2=not-specified). help description. */
char * reserved1_arg; /**< @brief String for first reserved section.. */
char * reserved1_orig; /**< @brief String for first reserved section. original value given at command line. */
const char *reserved1_help; /**< @brief String for first reserved section. help description. */
char * reserved2_arg; /**< @brief String for second reserved section.. */
char * reserved2_orig; /**< @brief String for second reserved section. original value given at command line. */
const char *reserved2_help; /**< @brief String for second reserved section. help description. */
int kernel_file_has_header_flag; /**< @brief Indicates that the kernel file includes the kernel header with correct load address and entry point, so no changes are needed (default=off). */
const char *kernel_file_has_header_help; /**< @brief Indicates that the kernel file includes the kernel header with correct load address and entry point, so no changes are needed help description. */
unsigned int help_given ; /**< @brief Whether help was given. */
unsigned int version_given ; /**< @brief Whether version was given. */
unsigned int kernel_given ; /**< @brief Whether kernel was given. */
unsigned int rootfs_given ; /**< @brief Whether rootfs was given. */
unsigned int output_given ; /**< @brief Whether output was given. */
unsigned int cfe_given ; /**< @brief Whether cfe was given. */
unsigned int boardid_given ; /**< @brief Whether boardid was given. */
unsigned int chipid_given ; /**< @brief Whether chipid was given. */
unsigned int flash_start_given ; /**< @brief Whether flash-start was given. */
unsigned int image_offset_given ; /**< @brief Whether image-offset was given. */
unsigned int tag_version_given ; /**< @brief Whether tag-version was given. */
unsigned int signature_given ; /**< @brief Whether signature was given. */
unsigned int signature2_given ; /**< @brief Whether signature2 was given. */
unsigned int block_size_given ; /**< @brief Whether block-size was given. */
unsigned int load_addr_given ; /**< @brief Whether load-addr was given. */
unsigned int entry_given ; /**< @brief Whether entry was given. */
unsigned int layoutver_given ; /**< @brief Whether layoutver was given. */
unsigned int info1_given ; /**< @brief Whether info1 was given. */
unsigned int altinfo_given ; /**< @brief Whether altinfo was given. */
unsigned int info2_given ; /**< @brief Whether info2 was given. */
unsigned int root_first_given ; /**< @brief Whether root-first was given. */
unsigned int rsa_signature_given ; /**< @brief Whether rsa-signature was given. */
unsigned int second_image_flag_given ; /**< @brief Whether second-image-flag was given. */
unsigned int inactive_given ; /**< @brief Whether inactive was given. */
unsigned int reserved1_given ; /**< @brief Whether reserved1 was given. */
unsigned int reserved2_given ; /**< @brief Whether reserved2 was given. */
unsigned int kernel_file_has_header_given ; /**< @brief Whether kernel-file-has-header was given. */
} ;
/** @brief The additional parameters to pass to parser functions */
struct cmdline_parser_params
{
int override; /**< @brief whether to override possibly already present options (default 0) */
int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */
int check_required; /**< @brief whether to check that all required options were provided (default 1) */
int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */
int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */
} ;
/** @brief the purpose string of the program */
extern const char *gengetopt_args_info_purpose;
/** @brief the usage string of the program */
extern const char *gengetopt_args_info_usage;
/** @brief all the lines making the help output */
extern const char *gengetopt_args_info_help[];
/**
* The command line parser
* @param argc the number of command line options
* @param argv the command line options
* @param args_info the structure where option information will be stored
* @return 0 if everything went fine, NON 0 if an error took place
*/
int cmdline_parser (int argc, char **argv,
struct gengetopt_args_info *args_info);
/**
* The command line parser (version with additional parameters - deprecated)
* @param argc the number of command line options
* @param argv the command line options
* @param args_info the structure where option information will be stored
* @param override whether to override possibly already present options
* @param initialize whether to initialize the option structure my_args_info
* @param check_required whether to check that all required options were provided
* @return 0 if everything went fine, NON 0 if an error took place
* @deprecated use cmdline_parser_ext() instead
*/
int cmdline_parser2 (int argc, char **argv,
struct gengetopt_args_info *args_info,
int override, int initialize, int check_required);
/**
* The command line parser (version with additional parameters)
* @param argc the number of command line options
* @param argv the command line options
* @param args_info the structure where option information will be stored
* @param params additional parameters for the parser
* @return 0 if everything went fine, NON 0 if an error took place
*/
int cmdline_parser_ext (int argc, char **argv,
struct gengetopt_args_info *args_info,
struct cmdline_parser_params *params);
/**
* Save the contents of the option struct into an already open FILE stream.
* @param outfile the stream where to dump options
* @param args_info the option struct to dump
* @return 0 if everything went fine, NON 0 if an error took place
*/
int cmdline_parser_dump(FILE *outfile,
struct gengetopt_args_info *args_info);
/**
* Save the contents of the option struct into a (text) file.
* This file can be read by the config file parser (if generated by gengetopt)
* @param filename the file where to save
* @param args_info the option struct to save
* @return 0 if everything went fine, NON 0 if an error took place
*/
int cmdline_parser_file_save(const char *filename,
struct gengetopt_args_info *args_info);
/**
* Print the help
*/
void cmdline_parser_print_help(void);
/**
* Print the version
*/
void cmdline_parser_print_version(void);
/**
* Initializes all the fields a cmdline_parser_params structure
* to their default values
* @param params the structure to initialize
*/
void cmdline_parser_params_init(struct cmdline_parser_params *params);
/**
* Allocates dynamically a cmdline_parser_params structure and initializes
* all its fields to their default values
* @return the created and initialized cmdline_parser_params structure
*/
struct cmdline_parser_params *cmdline_parser_params_create(void);
/**
* Initializes the passed gengetopt_args_info structure's fields
* (also set default values for options that have a default)
* @param args_info the structure to initialize
*/
void cmdline_parser_init (struct gengetopt_args_info *args_info);
/**
* Deallocates the string fields of the gengetopt_args_info structure
* (but does not deallocate the structure itself)
* @param args_info the structure to deallocate
*/
void cmdline_parser_free (struct gengetopt_args_info *args_info);
/**
* Checks that all the required options were specified
* @param args_info the structure to check
* @param prog_name the name of the program that will be used to print
* possible errors
* @return
*/
int cmdline_parser_required (struct gengetopt_args_info *args_info,
const char *prog_name);
extern const char *cmdline_parser_second_image_flag_values[]; /**< @brief Possible values for second-image-flag. */
extern const char *cmdline_parser_inactive_values[]; /**< @brief Possible values for inactive. */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* IMAGETAG_CMDLINE_H */