From 8efe39f3f73ace126701dce7049355c1f888bb60 Mon Sep 17 00:00:00 2001 From: Roman Yeryomin Date: Thu, 13 Sep 2012 00:27:21 +0300 Subject: Add cvimg files to firmware-utils Signed-off-by: Roman Yeryomin --- tools/firmware-utils/src/cvimg.c | 364 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 364 insertions(+) create mode 100644 tools/firmware-utils/src/cvimg.c (limited to 'tools/firmware-utils/src/cvimg.c') diff --git a/tools/firmware-utils/src/cvimg.c b/tools/firmware-utils/src/cvimg.c new file mode 100644 index 000000000..a2b9519d5 --- /dev/null +++ b/tools/firmware-utils/src/cvimg.c @@ -0,0 +1,364 @@ +/* + * Tool to convert ELF image to be the AP downloadable binary + * + * Authors: David Hsu + * + * $Id: cvimg.c,v 1.4 2009/06/12 07:10:44 michael Exp $ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#define HOME_GATEWAY + +#define CONFIG_RTL_8196C + +#include "apmib.h" + +#define COMPACT_FILENAME_BUFFER + + +static int friendly_strcmp(const char *s1, const char *s2) +{ + if (!s1 || !s2) return (s1>s2) ? -1 : !(s1==s2); + return strcmp(s1,s2); +} + +/* 32-bit ELF base types. */ +typedef unsigned int Elf32_Addr; +typedef unsigned short Elf32_Half; +typedef unsigned int Elf32_Off; +typedef unsigned int Elf32_Word; + +#define EI_NIDENT 16 + +typedef struct elf32_hdr{ + unsigned char e_ident[EI_NIDENT]; + Elf32_Half e_type; + Elf32_Half e_machine; + Elf32_Word e_version; + Elf32_Addr e_entry; /* Entry point */ + Elf32_Off e_phoff; + Elf32_Off e_shoff; + Elf32_Word e_flags; + Elf32_Half e_ehsize; + Elf32_Half e_phentsize; + Elf32_Half e_phnum; + Elf32_Half e_shentsize; + Elf32_Half e_shnum; + Elf32_Half e_shstrndx; +} Elf32_Ehdr; + +#define DEFAULT_START_ADDR 0x80500000 +#define DEFAULT_BASE_ADDR 0x80000000 + +static unsigned short calculateChecksum(char *buf, int len); + +///////////////////////////////////////////////////////// +static unsigned int calculate_long_checksum(unsigned int *buf, int len) +{ + int i, j; + unsigned int sum=0, tmp; + + j = len/4; + + for (i=0; i input-filename output-filename start-addr burn-addr [signature]\n"); + printf("