aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2009-02-27 10:09:20 +0000
committerGabor Juhos <juhosg@openwrt.org>2009-02-27 10:09:20 +0000
commit197a6f29351cfeb3b925b1c2d6ff7402812c45cc (patch)
tree6d717ddffe6f41e74e9052f7dbc36a8ffa0b9b2c /target/linux
parent23dad045d45c79121353fb7adfef5369b62d92ea (diff)
downloadupstream-197a6f29351cfeb3b925b1c2d6ff7402812c45cc.tar.gz
upstream-197a6f29351cfeb3b925b1c2d6ff7402812c45cc.tar.bz2
upstream-197a6f29351cfeb3b925b1c2d6ff7402812c45cc.zip
[ar71xx] move 'ar71xx_add_device_usb' definition into devices.h
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@14680 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux')
-rw-r--r--target/linux/ar71xx/files/arch/mips/ar71xx/devices.h2
-rw-r--r--target/linux/ar71xx/files/arch/mips/include/asm/mach-ar71xx/ar71xx.h2
2 files changed, 2 insertions, 2 deletions
diff --git a/target/linux/ar71xx/files/arch/mips/ar71xx/devices.h b/target/linux/ar71xx/files/arch/mips/ar71xx/devices.h
index 4f6e2a60375..b0119753db9 100644
--- a/target/linux/ar71xx/files/arch/mips/ar71xx/devices.h
+++ b/target/linux/ar71xx/files/arch/mips/ar71xx/devices.h
@@ -40,6 +40,8 @@ void ar71xx_add_device_gpio_buttons(int id,
unsigned nbuttons,
struct gpio_button *buttons) __init;
+void ar71xx_add_device_usb(void) __init;
+
#ifdef CONFIG_AR71XX_EARLY_SERIAL
static inline void ar71xx_add_device_uart(void) {}
#else
diff --git a/target/linux/ar71xx/files/arch/mips/include/asm/mach-ar71xx/ar71xx.h b/target/linux/ar71xx/files/arch/mips/include/asm/mach-ar71xx/ar71xx.h
index ae4e3891f76..f6acb11991b 100644
--- a/target/linux/ar71xx/files/arch/mips/include/asm/mach-ar71xx/ar71xx.h
+++ b/target/linux/ar71xx/files/arch/mips/include/asm/mach-ar71xx/ar71xx.h
@@ -195,8 +195,6 @@ static inline u32 ar71xx_usb_ctrl_rr(unsigned reg)
return __raw_readl(ar71xx_usb_ctrl_base + reg);
}
-extern void ar71xx_add_device_usb(void) __init;
-
/*
* GPIO block
*/
> 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
/*
 *  Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
 *  Copyright (C) 2016 Stijn Tintel <stijn@linux-ipv6.be>
 *
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License version 2 as published
 *  by the Free Software Foundation.
 *
 */

#define _ANSI_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <libgen.h>
#include <getopt.h>
#include <stdarg.h>
#include <errno.h>
#include <sys/stat.h>

#include "md5.h"

#define ERR(fmt, ...) do { \
	fflush(0); \
	fprintf(stderr, "[%s] *** error: " fmt "\n", \
			progname, ## __VA_ARGS__ ); \
} while (0)

#define ERRS(fmt, ...) do { \
	int save = errno; \
	fflush(0); \
	fprintf(stderr, "[%s] *** error: " fmt ", %s\n", \
			progname, ## __VA_ARGS__, strerror(save)); \
} while (0)

#define WRGG03_MAGIC	0x20080321

struct wrgg03_header {
	char		signature[32];
	uint32_t	magic1;
	uint32_t	magic2;
	char		version[16];
	char		model[16];
	uint32_t	flag[2];
	uint32_t	reserve[2];
	char		buildno[16];
	uint32_t	size;
	uint32_t	offset;
	char		devname[32];
	char		digest[16];
} __attribute__ ((packed));

static char *progname;
static char *ifname;
static char *ofname;
static char *signature;
static char *version;
static char *model;
static uint32_t flag = 0;
static uint32_t reserve = 0;
static char *buildno;
static uint32_t offset;
static char *devname;
static int big_endian;

void usage(int status)
{
	FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout;

	fprintf(stream, "Usage: %s [OPTIONS...]\n", progname);
	fprintf(stream,
"\n"
"Options:\n"
"  -b              create image in big endian format\n"
"  -B <buildno>    build number\n"
"  -i <file>       read input from the file <file>\n"
"  -d <name>       set device name to <name>\n"
"  -m <model>      model name\n"
"  -o <file>       write output to the file <file>\n"
"  -O <offset>     set offset to <offset>\n"
"  -s <sig>        set image signature to <sig>\n"
"  -h              show this screen\n"
	);

	exit(status);
}

static void put_u32(void *data, uint32_t val, int swap)
{
	unsigned char *p = data;

	if (swap) {
		p[0] = (val >> 24) & 0xff;
		p[1] = (val >> 16) & 0xff;
		p[2] = (val >> 8) & 0xff;
		p[3] = val & 0xff;
	} else {
		p[3] = (val >> 24) & 0xff;
		p[2] = (val >> 16) & 0xff;
		p[1] = (val >> 8) & 0xff;
		p[0] = val & 0xff;
	}
}

static void get_digest(struct wrgg03_header *header, char *data, int size)
{
	MD5_CTX ctx;

	MD5_Init(&ctx);

	MD5_Update(&ctx, (char *)&header->offset, sizeof(header->offset));
	MD5_Update(&ctx, (char *)&header->devname, sizeof(header->devname));
	MD5_Update(&ctx, data, size);

	MD5_Final(header->digest, &ctx);
}

int main(int argc, char *argv[])
{
	struct wrgg03_header *header;
	char *buf;
	struct stat st;
	int buflen;
	int err;
	int res = EXIT_FAILURE;

	FILE *outfile, *infile;

	progname = basename(argv[0]);

	while ( 1 ) {
		int c;

		c = getopt(argc, argv, "bd:i:m:o:s:v:B:O:h");
		if (c == -1)
			break;

		switch (c) {
		case 'b':
			big_endian = 1;
			break;
		case 'B':
			buildno = optarg;
			break;
		case 'd':
			devname = optarg;
			break;
		case 'i':
			ifname = optarg;
			break;
		case 'm':
			model = optarg;
			break;
		case 'o':
			ofname = optarg;
			break;
		case 's':
			signature = optarg;
			break;
		case 'v':
			version = optarg;
			break;
		case 'O':
			offset = strtoul(optarg, NULL, 0);
			break;
		case 'h':
			usage(EXIT_SUCCESS);
			break;

		default:
			usage(EXIT_FAILURE);
			break;
		}
	}

	if (signature == NULL) {
		ERR("no signature specified");
		goto err;
	}

	if (ifname == NULL) {
		ERR("no input file specified");
		goto err;
	}

	if (ofname == NULL) {
		ERR("no output file specified");
		goto err;
	}

	if (devname == NULL) {
		ERR("no device name specified");
		goto err;
	}

	if (model == NULL) {
		ERR("no model name specified");
		goto err;
	}

	if (buildno == NULL) {
		ERR("no build number specified");
		goto err;
	}

	if (version == NULL) {
		ERR("no version specified");
		goto err;
	}

	err = stat(ifname, &st);
	if (err){
		ERRS("stat failed on %s", ifname);
		goto err;
	}

	buflen = st.st_size + sizeof(struct wrgg03_header);
	buf = malloc(buflen);
	if (!buf) {
		ERR("no memory for buffer\n");
		goto err;
	}

	infile = fopen(ifname, "r");
	if (infile == NULL) {
		ERRS("could not open \"%s\" for reading", ifname);
		goto err_free;
	}

	errno = 0;
	fread(buf + sizeof(struct wrgg03_header), st.st_size, 1, infile);
	if (errno != 0) {
		ERRS("unable to read from file %s", ifname);
		goto close_in;
	}

	header = (struct wrgg03_header *) buf;
	memset(header, '\0', sizeof(struct wrgg03_header));

	strncpy(header->signature, signature, sizeof(header->signature));
	put_u32(&header->magic1, WRGG03_MAGIC, 0);
	put_u32(&header->magic2, WRGG03_MAGIC, 0);
	strncpy(header->version, version, sizeof(header->version));
	strncpy(header->model, model, sizeof(header->model));
	put_u32(&header->flag, flag, 0);
	put_u32(&header->reserve, reserve, 0);
	strncpy(header->buildno, buildno, sizeof(header->buildno));
	put_u32(&header->size, st.st_size, big_endian);
	put_u32(&header->offset, offset, big_endian);
	strncpy(header->devname, devname, sizeof(header->devname));

	get_digest(header, buf + sizeof(struct wrgg03_header), st.st_size);

	outfile = fopen(ofname, "w");
	if (outfile == NULL) {
		ERRS("could not open \"%s\" for writing", ofname);
		goto close_in;
	}

	errno = 0;
	fwrite(buf, buflen, 1, outfile);
	if (errno) {
		ERRS("unable to write to file %s", ofname);
		goto close_out;
	}

	fflush(outfile);

	res = EXIT_SUCCESS;

close_out:
	fclose(outfile);
	if (res != EXIT_SUCCESS)
		unlink(ofname);
close_in:
	fclose(infile);
err_free:
	free(buf);
err:
	return res;
}