Commit f5847777 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Alessandro Rubini

wrdev-tools: removed obsolete V2 tools (gen_fpga_image and uboot_env)

parent 1aed354a
all:
$(MAKE) -C ./src/mch_flasher
$(MAKE) -C ./src/uboot_env
$(MAKE) -C ./src/gen_fpga_image
clean:
$(MAKE) -C ./src/mch_flasher clean
$(MAKE) -C ./src/uboot_env clean
$(MAKE) -C ./src/gen_fpga_image clean
\ No newline at end of file
CC=gcc
OBJS=gen_fpga_image.o minilzo.o md5.o
OUTPUT=../../gen_fpga_image
LDFLAGS=
all: $(OBJS)
${CC} -o $(OUTPUT) $(OBJS) $(LDFLAGS)
clean:
rm -f $(OBJS) $(OUTPUT)
\ No newline at end of file
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "minilzo.h"
#include "md5.h"
static const char IMAGE_MAGIC[4] = { 'w','r','f','i' };
struct fpga_image_header {
char magic[4];
uint32_t num_images;
};
struct fpga_image_entry {
char *fpga_name; // name of the FPGA (for example: MAIN, CLKB)
char *fw_name; // name of the firmware (for example: board_test, rtu_test)
uint32_t hash_reg; // MD5 hash of the firmware ID.
uint32_t revision;
uint32_t size;
uint32_t compressed_size;
};
void die(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "Error: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n\n");
va_end(ap);
exit(-1);
}
static char lzo_workmem[LZO1X_1_MEM_COMPRESS];
uint32_t calc_hash_reg(char *fpga_name, char *firmware_name)
{
char hash_buf[1024];
uint8_t hash_val[16];
int i;
strncpy(hash_buf, fpga_name, 256);
strcat(hash_buf,"::");
strncat(hash_buf, firmware_name, 256);
md5_checksum(hash_buf, strlen(hash_buf), hash_val);
for(i=0;i<4;i++) hash_val[i] ^= (hash_val[4+i] ^ hash_val[8+i] ^ hash_val[12+i]);
return (uint32_t) hash_val[0] |
((uint32_t) hash_val[1] << 8) |
((uint32_t) hash_val[2] << 16) |
((uint32_t) hash_val[3] << 24);
}
char *prepare_image(char *filename, char *fpga_name, char *firmware_name, int revision, struct fpga_image_entry *ent)
{
char *rbf_buf;
uint32_t size, size_cmp;
FILE *f = fopen(filename, "rb");
if(!f) die("can't open %s", filename);
fseek(f, 0, SEEK_END);
size = ftell(f);
rewind(f);
rbf_buf = malloc(size);
fread(rbf_buf, 1, size, f);
fclose(f);
char *p = malloc(size);
lzo1x_1_compress(rbf_buf, size, p, (lzo_uint *)&size_cmp, lzo_workmem);
free(rbf_buf);
ent->fpga_name = fpga_name;
ent->fw_name = firmware_name;
ent->hash_reg = calc_hash_reg(fpga_name, firmware_name);
ent->revision = revision;
ent->size = size;
ent->compressed_size = size_cmp;
return p;
}
int write_le32(FILE *f, uint32_t x)
{
#if __BYTE_ORDER==__LITTLE_ENDIAN
return fwrite(&x, 4, 1, f);
#else
#error "Big endian architectures not supported yet :("
#endif
}
int write_string(FILE *f, char *str)
{
unsigned int length = strlen(str);
write_le32(f, length);
fwrite(str, 1, length, f);
return length + 4;
}
int write_entry_header(FILE *f, struct fpga_image_entry *ent)
{
int n;
n=write_string(f, ent->fpga_name);
n+=write_string(f, ent->fw_name);
n+=write_le32(f, ent->hash_reg);
n+=write_le32(f, ent->revision);
n+=write_le32(f, ent->size);
n+=write_le32(f, ent->compressed_size);
return n;
}
main(int argc, char *argv[])
{
struct fpga_image_header hdr;
struct fpga_image_entry ent;
if(argc < 2)
{
printf("MCH FPGA image generator (c) TW, CERN BE-Co-HT 2010\n");
printf("usage: %s OUTPUT.img INPUT.rbf REVISION FPGA_NAME FIRMWARE_NAME\n",argv[0]);
printf(" %s -h FPGA_NAME FIRMWARE_NAME\n",argv[0]);
printf("-h option returns the FW_HASH register value for given FPGA/firmware names\n\n");
return 0;
}
if(!strcmp(argv[1], "-h"))
{
printf("0x%08x", calc_hash_reg(argv[2], argv[3]));
return 0;
} else if (argc < 5)
die("Not enough arguments");
FILE *fout = fopen(argv[1], "wb");
if(!fout)
die("Can't open output file: %s\n", argv[1]);
memcpy(hdr.magic, IMAGE_MAGIC, 4);
hdr.num_images = 1;
fwrite(&hdr, sizeof(struct fpga_image_header), 1, fout);
char *bitstream = prepare_image(argv[2], argv[4], argv[5], atoi(argv[3]), &ent);
write_entry_header(fout, &ent);
fwrite(bitstream, 1, ent.compressed_size, fout);
printf("Total image size: %d bytes.\n", ftell(fout));
fclose(fout);
return 0;
}
This diff is collapsed.
This diff is collapsed.
/*
* Cryptographic API.
*
* MD5 Message Digest Algorithm (RFC1321).
*
* Derived from cryptoapi implementation, originally based on the
* public domain implementation written by Colin Plumb in 1993.
*
* Copyright (c) Cryptoapi developers.
* Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "md5.h"
#define MD5_DIGEST_SIZE 16
#define MD5_HMAC_BLOCK_SIZE 64
#define MD5_BLOCK_WORDS 16
#define MD5_HASH_WORDS 4
#define F1(x, y, z) (z ^ (x & (y ^ z)))
#define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))
#define MD5STEP(f, w, x, y, z, in, s) \
(w += f(x, y, z) + in, w = (w<<s | w>>(32-s)) + x)
struct md5_ctx {
uint32_t hash[MD5_HASH_WORDS];
uint32_t block[MD5_BLOCK_WORDS];
uint64_t byte_count;
};
static void md5_transform(uint32_t *hash, uint32_t const *in)
{
uint32_t a, b, c, d;
a = hash[0];
b = hash[1];
c = hash[2];
d = hash[3];
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
hash[0] += a;
hash[1] += b;
hash[2] += c;
hash[3] += d;
}
static inline void md5_transform_helper(struct md5_ctx *ctx)
{
md5_transform(ctx->hash, ctx->block);
}
static int md5_init(struct md5_ctx *mctx)
{
mctx->hash[0] = 0x67452301;
mctx->hash[1] = 0xefcdab89;
mctx->hash[2] = 0x98badcfe;
mctx->hash[3] = 0x10325476;
mctx->byte_count = 0;
return 0;
}
static int md5_update(struct md5_ctx *mctx, const uint8_t *data, unsigned int len)
{
const uint32_t avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
mctx->byte_count += len;
if (avail > len) {
memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
data, len);
return 0;
}
memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
data, avail);
md5_transform_helper(mctx);
data += avail;
len -= avail;
while (len >= sizeof(mctx->block)) {
memcpy(mctx->block, data, sizeof(mctx->block));
md5_transform_helper(mctx);
data += sizeof(mctx->block);
len -= sizeof(mctx->block);
}
memcpy(mctx->block, data, len);
return 0;
}
static int md5_final(struct md5_ctx *mctx, uint8_t *out)
{
const unsigned int offset = mctx->byte_count & 0x3f;
char *p = (char *)mctx->block + offset;
int padding = 56 - (offset + 1);
*p++ = 0x80;
if (padding < 0) {
memset(p, 0x00, padding + sizeof (uint64_t));
md5_transform_helper(mctx);
p = (char *)mctx->block;
padding = 56;
}
memset(p, 0, padding);
mctx->block[14] = mctx->byte_count << 3;
mctx->block[15] = mctx->byte_count >> 29;
md5_transform(mctx->hash, mctx->block);
memcpy(out, mctx->hash, sizeof(mctx->hash));
memset(mctx, 0, sizeof(*mctx));
return 0;
}
int md5_checksum(uint8_t *data, int length, uint8_t *digest)
{
struct md5_ctx ctx;
md5_init(&ctx);
md5_update(&ctx, data, length);
md5_final(&ctx, digest);
return MD5_DIGEST_SIZE;
}
#ifndef __MD5_H
#define __MD5_H
#include <inttypes.h>
int md5_checksum(uint8_t *data, int length, uint8_t *digest);
#endif
This diff is collapsed.
/* minilzo.h -- mini subset of the LZO real-time data compression library
This file is part of the LZO real-time data compression library.
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
*/
/*
* NOTE:
* the full LZO package can be found at
* http://www.oberhumer.com/opensource/lzo/
*/
#ifndef __MINILZO_H
#define __MINILZO_H
#define MINILZO_VERSION 0x2030
#ifdef __LZOCONF_H
# error "you cannot use both LZO and miniLZO"
#endif
#undef LZO_HAVE_CONFIG_H
#include "lzoconf.h"
#if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION)
# error "version mismatch in header files"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/***********************************************************************
//
************************************************************************/
/* Memory required for the wrkmem parameter.
* When the required size is 0, you can also pass a NULL pointer.
*/
#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS
#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t))
#define LZO1X_MEM_DECOMPRESS (0)
/* compression */
LZO_EXTERN(int)
lzo1x_1_compress ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
/* decompression */
LZO_EXTERN(int)
lzo1x_decompress ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem /* NOT USED */ );
/* safe decompression with overrun testing */
LZO_EXTERN(int)
lzo1x_decompress_safe ( const lzo_bytep src, lzo_uint src_len,
lzo_bytep dst, lzo_uintp dst_len,
lzo_voidp wrkmem /* NOT USED */ );
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* already included */
CC=gcc
OBJS=uboot_env.o
OUTPUT=../../uboot_env
LDFLAGS = -lz
all: $(OBJS)
${CC} -o $(OUTPUT) $(OBJS) $(LDFLAGS)
clean:
rm -f $(OBJS) $(OUTPUT)
\ No newline at end of file
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
#define ENV_SIZE 0x4200
#define ENV_OFFSET 0x4200
void die(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "Error: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n\n");
va_end(ap);
exit(-1);
}
unsigned char buf[ENV_SIZE];
main(int argc, char *argv[])
{
FILE *f_image, *f_env;
char line[1024];
int pos=0;
if(argc<3)
{
printf("usage: uboot_env [flash_image] [environment file]\n");
}
f_image = fopen(argv[1],"rb+"); if(!f_image) die ("error opening image file");
f_env = fopen(argv[2],"r"); if(!f_env) die ("error opening environment file");
memset(buf, 0, ENV_SIZE);
while(!feof(f_env))
{
fgets(line, 1024, f_env);
int len = strlen(line);
if(line[len-1] == '\n')
{
line[len-1] = 0;
len--;
}
memcpy(buf+4+pos, line, len+1);
pos+=len+1;
}
unsigned int crc = crc32(0, buf+4, ENV_SIZE-4);
fseek(f_image, ENV_OFFSET, SEEK_SET);
fwrite(&crc, 4, 1, f_image);
fwrite(buf+4, 1, ENV_SIZE-4, f_image);
fclose(f_image);
fclose(f_env);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment