Commit f03cd03d authored by Alejandro Mery's avatar Alejandro Mery
Browse files

Merge branch 'master' into autotools

Conflicts:
	Makefile.am
parents 7a0112f0 346bbff6
AUTOMAKE_OPTIONS = foreign
CFLAGS = -g -O0 -Wall -Wextra -std=c99 -D_POSIX_C_SOURCE=200112L -Iinclude/
TOOLS = fexc bin2fex fex2bin bootinfo fel pio nand-part nand-part-a20 phoenix_info
TOOLS = fexc bin2fex fex2bin bootinfo fel pio nand-part phoenix_info
BINARIES = fel-pio.bin jtag-loop.bin fel-sdboot.bin boot_head_sun4i.bin boot_head_sun5i.bin adb-devprobe.sh fel-gpio usb-boot
bin_PROGRAMS = $(TOOLS)
......@@ -13,7 +13,6 @@ EXTRA_DIST = boot_head.S jtag-loop.S boot_head.lds fel-pio.lds fel-sdboot.lds jt
nodist_bin2fex_SOURCES = bin2fex.c
nodist_fex2bin_SOURCES = fex2bin.c
nodist_nand_part_a20_SOURCES = nand-part-a20.c
man_MANS = sunxi-tools.7
......@@ -33,12 +32,15 @@ bin2fex: fexc
fel: fel.c
$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS) $(LIBUSB_LIBS)
nand-part: nand-part-main.c nand-part.c nand-part-a10.h nand-part-a20.h
$(CC) $(CFLAGS) -c -o nand-part-main.o nand-part-main.c
$(CC) $(CFLAGS) -c -o nand-part-a10.o nand-part.c -D A10
$(CC) $(CFLAGS) -c -o nand-part-a20.o nand-part.c -D A20
$(CC) $(LDFLAGS) -o $@ nand-part-main.o nand-part-a10.o nand-part-a20.o $(LIBS)
%: %.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS)
nand-part-a20: nand-part.c nand-part-a20.h
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ nand-part.c -D A20 $(LIBS)
fel-pio.bin: fel-pio.elf fel-pio.nm
$(CROSS_COMPILE)objcopy -O binary fel-pio.elf fel-pio.bin
......
......@@ -17,6 +17,7 @@
/* Needs _BSD_SOURCE for htole and letoh */
#define _BSD_SOURCE
#define _NETBSD_SOURCE
#include <libusb.h>
#include <stdint.h>
......@@ -27,6 +28,7 @@
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include "endian_compat.h"
......@@ -164,6 +166,7 @@ void aw_fel_get_version(libusb_device_handle *usb)
case 0x1625: soc_name="A13";break;
case 0x1633: soc_name="A31";break;
case 0x1651: soc_name="A20";break;
case 0x1650: soc_name="A23";break;
}
printf("%.8s soc=%08x(%s) %08x ver=%04x %02x %02x scratchpad=%08x %08x %08x\n", buf.signature, buf.soc_id, soc_name, buf.unknown_0a, buf.protocol, buf.unknown_12, buf.unknown_13, buf.scratchpad, buf.pad[0], buf.pad[1]);
......@@ -221,7 +224,10 @@ int save_file(const char *name, void *data, size_t size)
{
FILE *out = fopen(name, "wb");
int rc;
assert(out);
if (!out) {
perror("Failed to open output file: ");
exit(1);
}
rc = fwrite(data, size, 1, out);
fclose(out);
return rc;
......@@ -237,7 +243,10 @@ void *load_file(const char *name, size_t *size)
in = stdin;
else
in = fopen(name, "rb");
assert(in);
if (!in) {
perror("Failed to open input file: ");
exit(1);
}
while(1) {
ssize_t len = bufsize - offset;
......@@ -299,7 +308,14 @@ int main(int argc, char **argv)
handle = libusb_open_device_with_vid_pid(NULL, 0x1f3a, 0xefe8);
if (!handle) {
fprintf(stderr, "ERROR: Allwinner USB FEL device not found!\n");
switch (errno) {
case EACCES:
fprintf(stderr, "ERROR: You don't have permission to access Allwinner USB FEL device\n");
break;
default:
fprintf(stderr, "ERROR: Allwinner USB FEL device not found!\n");
break;
}
exit(1);
}
rc = libusb_claim_interface(handle, 0);
......
/*
* (C) Copyright 2013
* Patrick H Wood, All rights reserved.
*
* 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*/
#include "types.h"
extern int nand_part_a10 (int argc, char **argv, const char *cmd, int fd, int force);
extern int nand_part_a20 (int argc, char **argv, const char *cmd, int fd, int force);
extern int checkmbrs_a10 (int fd);
extern int checkmbrs_a20 (int fd);
extern void usage (const char *cmd);
extern __u32 calc_crc32(void * buffer, __u32 length);
......@@ -27,6 +27,8 @@
#define MBR_MAGIC "softw311"
#define MBR_VERSION 0x100
#define nand_part nand_part_a10
#define checkmbrs checkmbrs_a10
#define MAX_PART_COUNT 15 //max part count
#define MBR_COPY_NUM 4 //mbr backup count
......
......@@ -27,6 +27,8 @@
#define MBR_MAGIC "softw411"
#define MBR_VERSION 0x200
#define nand_part nand_part_a20
#define checkmbrs checkmbrs_a20
#define MAX_PART_COUNT 120 //max part count
#define MBR_COPY_NUM 4 //mbr backup count
......
/*
* (C) Copyright 2013
* Patrick H Wood, All rights reserved.
*
* 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*/
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <fcntl.h>
#include "nand-common.h"
void usage(const char *cmd)
{
printf("usage: %s [-f a10|a20] nand-device\n", cmd);
printf(" %s nand-device 'name2 len2 [usertype2]' ['name3 len3 [usertype3]'] ...\n", cmd);
printf(" %s [-f a10|a20] nand-device start1 'name1 len1 [usertype1]' ['name2 len2 [usertype2]'] ...\n", cmd);
}
typedef struct tag_CRC32_DATA
{
__u32 CRC; //int的大小是32位
__u32 CRC_32_Tbl[256]; //用来保存码表
}CRC32_DATA_t;
__u32 calc_crc32(void * buffer, __u32 length)
{
__u32 i, j;
CRC32_DATA_t crc32; //
__u32 CRC32 = 0xffffffff; //设置初始值
crc32.CRC = 0;
for( i = 0; i < 256; ++i)//用++i以提高效率
{
crc32.CRC = i;
for( j = 0; j < 8 ; ++j)
{
//这个循环实际上就是用"计算法"来求取CRC的校验码
if(crc32.CRC & 1)
crc32.CRC = (crc32.CRC >> 1) ^ 0xEDB88320;
else //0xEDB88320就是CRC-32多项表达式的值
crc32.CRC >>= 1;
}
crc32.CRC_32_Tbl[i] = crc32.CRC;
}
CRC32 = 0xffffffff; //设置初始值
for( i = 0; i < length; ++i)
{
CRC32 = crc32.CRC_32_Tbl[(CRC32^((unsigned char*)buffer)[i]) & 0xff] ^ (CRC32>>8);
}
//return CRC32;
return CRC32^0xffffffff;
}
int main (int argc, char **argv)
{
char *nand = "/dev/nand";
const char *cmd = argv[0];
int fd;
int force = 0; // force write even if magics and CRCs don't match
argc--;
argv++;
if (argc > 1) {
if (!strcmp(argv[0], "-f")) {
if (!strcasecmp(argv[1], "a10"))
force = 10;
else if (!strcasecmp(argv[1], "a20"))
force = 20;
else {
usage(cmd);
return -1;
}
argc -= 2;
argv += 2;
}
}
if (argc > 0) {
nand = argv[0];
argc--;
argv++;
}
fd = open(nand, O_RDWR);
if (fd < 0) {
usage(cmd);
return -2;
}
if (force == 10)
return nand_part_a10 (argc, argv, cmd, fd, force);
if (force == 20)
return nand_part_a20 (argc, argv, cmd, fd, force);
if (checkmbrs_a10(fd))
return nand_part_a10 (argc, argv, cmd, fd, force);
if (checkmbrs_a20(fd))
return nand_part_a20 (argc, argv, cmd, fd, force);
}
......@@ -52,10 +52,13 @@
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h> /* BLKRRPART */
#ifdef A20
#include "nand-common.h"
// so far, only known formats are for A10 and A20
#if defined(A10)
# include "nand-part-a10.h"
#elif defined(A20)
# include "nand-part-a20.h"
#else
# include "nand-part.h"
#endif
#define MAX_NAME 16
......@@ -65,43 +68,7 @@ static void printmbrheader(MBR *mbr)
printf("mbr: version 0x%08x, magic %8.8s\n", mbr->version, mbr->magic);
}
typedef struct tag_CRC32_DATA
{
__u32 CRC; //int的大小是32位
__u32 CRC_32_Tbl[256]; //用来保存码表
}CRC32_DATA_t;
__u32 calc_crc32(void * buffer, __u32 length)
{
__u32 i, j;
CRC32_DATA_t crc32; //
__u32 CRC32 = 0xffffffff; //设置初始值
crc32.CRC = 0;
for( i = 0; i < 256; ++i)//用++i以提高效率
{
crc32.CRC = i;
for( j = 0; j < 8 ; ++j)
{
//这个循环实际上就是用"计算法"来求取CRC的校验码
if(crc32.CRC & 1)
crc32.CRC = (crc32.CRC >> 1) ^ 0xEDB88320;
else //0xEDB88320就是CRC-32多项表达式的值
crc32.CRC >>= 1;
}
crc32.CRC_32_Tbl[i] = crc32.CRC;
}
CRC32 = 0xffffffff; //设置初始值
for( i = 0; i < length; ++i)
{
CRC32 = crc32.CRC_32_Tbl[(CRC32^((unsigned char*)buffer)[i]) & 0xff] ^ (CRC32>>8);
}
//return CRC32;
return CRC32^0xffffffff;
}
MBR *_get_mbr(int fd, int mbr_num, int force)
static MBR *_get_mbr(int fd, int mbr_num, int force)
{
MBR *mbr;
......@@ -145,7 +112,7 @@ MBR *_get_mbr(int fd, int mbr_num, int force)
return NULL;
}
__s32 _free_mbr(MBR *mbr)
static __s32 _free_mbr(MBR *mbr)
{
if(mbr)
{
......@@ -156,7 +123,7 @@ __s32 _free_mbr(MBR *mbr)
return 0;
}
void printmbr(MBR *mbr)
static void printmbr(MBR *mbr)
{
unsigned int part_cnt;
......@@ -173,7 +140,7 @@ void printmbr(MBR *mbr)
mbr->array[part_cnt].user_type);
}
}
void checkmbrs(int fd)
int checkmbrs(int fd)
{
int i;
MBR *mbrs[MBR_COPY_NUM];
......@@ -191,7 +158,7 @@ void checkmbrs(int fd)
if (mbrs[i])
_free_mbr(mbrs[i]);
}
return;
return 0;
}
printmbr(mbr);
......@@ -199,9 +166,10 @@ void checkmbrs(int fd)
if (mbrs[i])
_free_mbr(mbrs[i]);
}
return 1;
}
int writembrs(int fd, char names[][MAX_NAME], __u32 start, __u32 *lens, unsigned int *user_types, int nparts, int partoffset, int force)
static int writembrs(int fd, char names[][MAX_NAME], __u32 start, __u32 *lens, unsigned int *user_types, int nparts, int partoffset, int force)
{
unsigned int part_cnt = 0;
int i;
......@@ -287,46 +255,15 @@ int writembrs(int fd, char names[][MAX_NAME], __u32 start, __u32 *lens, unsigned
return 1;
}
void usage(const char *cmd)
{
printf("usage: %s nand-device 'name2 len2 [usertype2]' ['name3 len3 [usertype3]'] ...\n", cmd);
printf("or %s nand-device [-f] start1 'name1 len1 [usertype1]' ['name2 len2 [usertype2]'] ...\n", cmd);
}
int main (int argc, char **argv)
int nand_part (int argc, char **argv, const char *cmd, int fd, int force)
{
int fd;
int force = 0; // force write even if magics and CRCs don't match
int partoffset = 0;
int i;
char *nand = "/dev/nand";
char *cmd = argv[0];
char names[MAX_PART_COUNT][MAX_NAME];
__u32 lens[MAX_PART_COUNT];
unsigned int user_types[MAX_PART_COUNT];
__u32 start;
argc--;
argv++;
if (argc > 0) {
if (!strcmp(argv[0], "-f")) {
force++;
argc--;
argv++;
}
}
if (argc > 0) {
nand = argv[0];
argc--;
argv++;
}
fd = open(nand, O_RDWR);
if (fd < 0) {
usage(cmd);
return -1;
}
// parse name/len arguments
memset((void *) user_types, 0, sizeof(user_types));
......
......@@ -167,8 +167,11 @@ static const char *argv0;
static void usage(int rc )
{
fprintf(stderr, "usage: %s [-m|-i input] [-o output] pin..\n", argv0);
fprintf(stderr, "usage: %s -m|-i input [-o output] pin..\n", argv0);
fprintf(stderr," -m mmap - read pin state from system\n");
fprintf(stderr," -i read pin state from file\n");
fprintf(stderr," -o save pin state data to file\n");
fprintf(stderr," print Show all pins\n");
fprintf(stderr," Pxx Show pin\n");
fprintf(stderr," Pxx<mode><pull><drive><data> Configure pin\n");
......@@ -179,7 +182,7 @@ static void usage(int rc )
fprintf(stderr, "\n mode 0-7, 0=input, 1=ouput, 2-7 I/O function\n");
fprintf(stderr, " pull 0=none, 1=up, 2=down\n");
fprintf(stderr, " drive 0-3, I/O drive level\n");
exit(rc);
}
......
......@@ -147,8 +147,8 @@ static int generate_dram_struct(FILE *out, struct script_section *sp)
}
fprintf(out, "};\n");
fputs("\nint sunxi_dram_init(void)\n"
"{\n\treturn DRAMC_init(&dram_para);\n}\n",
fputs("\nunsigned long sunxi_dram_init(void)\n"
"{\n\treturn dramc_init(&dram_para);\n}\n",
out);
return ret;
......
#!/bin/sh -e
top=`dirname $0`
if [ $# -lt 2 ]; then
echo "Usage: $0 u-boot-spl.bin u-boot.bin [boot.scr|-] [kernel script.bin [initramfs]]"
echo "Usage: $0 u-boot-spl.bin u-boot.bin [boot.scr] [kernel script.bin [initramfs]]"
exit 1
fi
board=$1; shift || (echo "ERROR: u-boot-spl.bin must be specified"; exit 1;)
......
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