Commit 1dfa8cf0 authored by Pat Wood's avatar Pat Wood
Browse files

Merge branch 'master' of git://github.com/linux-sunxi/sunxi-tools

Conflicts:
	nand-part.c
parents 5f258215 c66667ff
...@@ -58,14 +58,14 @@ jtag-loop.bin: jtag-loop.elf ...@@ -58,14 +58,14 @@ jtag-loop.bin: jtag-loop.elf
jtag-loop.sunxi: jtag-loop.bin jtag-loop.sunxi: jtag-loop.bin
mksunxiboot jtag-loop.bin jtag-loop.sunxi mksunxiboot jtag-loop.bin jtag-loop.sunxi
fel-boot.elf: fel-boot.c fel-boot.lds fel-sdboot.elf: fel-sdboot.c fel-sdboot.lds
$(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder fel-boot.c -nostdlib -o fel-boot.elf -T fel-boot.lds -Wl,-N $(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder fel-sdboot.c -nostdlib -o fel-sdboot.elf -T fel-sdboot.lds -Wl,-N
fel-boot.bin: fel-boot.elf fel-sdboot.bin: fel-sdboot.elf
$(CROSS_COMPILE)objcopy -O binary fel-boot.elf fel-boot.bin $(CROSS_COMPILE)objcopy -O binary fel-sdboot.elf fel-sdboot.bin
fel-boot.sunxi: fel-boot.bin fel-sdboot.sunxi: fel-sdboot.bin
mksunxiboot fel-boot.bin fel-boot.sunxi mksunxiboot fel-sdboot.bin fel-sdboot.sunxi
boot_head_sun3i.elf: boot_head_sun3i.S boot_head_sun3i.lds boot_head_sun3i.elf: boot_head_sun3i.S boot_head_sun3i.lds
$(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder boot_head.S -nostdlib -o boot_head_sun3i.elf -T boot_head.lds -Wl,-N -DMACHID=0x1094 $(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder boot_head.S -nostdlib -o boot_head_sun3i.elf -T boot_head.lds -Wl,-N -DMACHID=0x1094
......
...@@ -26,11 +26,18 @@ fel: ...@@ -26,11 +26,18 @@ fel:
th CPU. You activate FEL mode by pushing the usboot/recovery th CPU. You activate FEL mode by pushing the usboot/recovery
button at poweron. button at poweron.
usb-boot:
Simple wrapper to automate USB booting in FEL mode
See http://linux-sunxi.org/FEL/USBBoot for details
fel-gpio: fel-gpio:
Simple wrapper around fel-pio and fel to allos GPIO manipulations Simple wrapper around fel-pio and fel to allos GPIO manipulations
via FEL via FEL
fel-sdboot:
ARM native sdcard bootloader forcing the device into FEL mode
fel-pio.bin: fel-pio:
ARM native helper for fel-gpio ARM native helper for fel-gpio
pio: pio:
......
File added
#!/bin/sh #!/bin/sh -e
pio_to_sram=0x2000 pio_to_sram=0x2000
sram_to_pio=0x2004 sram_to_pio=0x2004
...@@ -13,6 +13,7 @@ fi ...@@ -13,6 +13,7 @@ fi
./fel read 0x3000 0x228 pio.reg ./fel read 0x3000 0x228 pio.reg
./pio -i pio.reg print > pio.old ./pio -i pio.reg print > pio.old
cat pio.old | fgrep -v '<0><0><0><0>' cat pio.old | fgrep -v '<0><0><0><0>'
while read cmd; do while read cmd; do
./pio -i pio.reg -o pio.reg $cmd ./pio -i pio.reg -o pio.reg $cmd
./fel write 0x3000 pio.reg ./fel write 0x3000 pio.reg
...@@ -20,6 +21,6 @@ while read cmd; do ...@@ -20,6 +21,6 @@ while read cmd; do
./fel exe 0x2000 ./fel exe 0x2000
./fel read 0x3000 0x228 pio.reg ./fel read 0x3000 0x228 pio.reg
./pio -i pio.reg print > pio.new ./pio -i pio.reg print > pio.new
diff -U0 pio.old pio.new diff -U0 pio.old pio.new || true
mv -f pio.new pio.old mv -f pio.new pio.old
done done
...@@ -138,7 +138,7 @@ void aw_fel_get_version(libusb_device_handle *usb) ...@@ -138,7 +138,7 @@ void aw_fel_get_version(libusb_device_handle *usb)
{ {
struct aw_fel_version { struct aw_fel_version {
char signature[8]; char signature[8];
uint32_t unknown_08; /* 0x00162300 */ uint32_t soc_id; /* 0x00162300 */
uint32_t unknown_0a; /* 1 */ uint32_t unknown_0a; /* 1 */
uint16_t protocol; /* 1 */ uint16_t protocol; /* 1 */
uint8_t unknown_12; /* 0x44 */ uint8_t unknown_12; /* 0x44 */
...@@ -151,14 +151,22 @@ void aw_fel_get_version(libusb_device_handle *usb) ...@@ -151,14 +151,22 @@ void aw_fel_get_version(libusb_device_handle *usb)
aw_usb_read(usb, &buf, sizeof(buf)); aw_usb_read(usb, &buf, sizeof(buf));
aw_read_fel_status(usb); aw_read_fel_status(usb);
buf.unknown_08 = le32toh(buf.unknown_08); buf.soc_id = le32toh(buf.soc_id);
buf.unknown_0a = le32toh(buf.unknown_0a); buf.unknown_0a = le32toh(buf.unknown_0a);
buf.protocol = le32toh(buf.protocol); buf.protocol = le32toh(buf.protocol);
buf.scratchpad = le16toh(buf.scratchpad); buf.scratchpad = le16toh(buf.scratchpad);
buf.pad[0] = le32toh(buf.pad[0]); buf.pad[0] = le32toh(buf.pad[0]);
buf.pad[1] = le32toh(buf.pad[1]); buf.pad[1] = le32toh(buf.pad[1]);
printf("%.8s %08x %08x ver=%04x %02x %02x scratchpad=%08x %08x %08x\n", buf.signature, buf.unknown_08, buf.unknown_0a, buf.protocol, buf.unknown_12, buf.unknown_13, buf.scratchpad, buf.pad[0], buf.pad[1]); const char *soc_name="unknown";
switch ((buf.soc_id >> 8) & 0xFFFF) {
case 0x1623: soc_name="A10";break;
case 0x1625: soc_name="A13";break;
case 0x1633: soc_name="A31";break;
case 0x1651: soc_name="A20";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]);
} }
void aw_fel_read(libusb_device_handle *usb, uint32_t offset, void *buf, size_t len) void aw_fel_read(libusb_device_handle *usb, uint32_t offset, void *buf, size_t len)
...@@ -271,6 +279,7 @@ int main(int argc, char **argv) ...@@ -271,6 +279,7 @@ int main(int argc, char **argv)
{ {
int rc; int rc;
libusb_device_handle *handle = NULL; libusb_device_handle *handle = NULL;
int iface_detached = -1;
rc = libusb_init(NULL); rc = libusb_init(NULL);
assert(rc == 0); assert(rc == 0);
...@@ -290,10 +299,17 @@ int main(int argc, char **argv) ...@@ -290,10 +299,17 @@ int main(int argc, char **argv)
handle = libusb_open_device_with_vid_pid(NULL, 0x1f3a, 0xefe8); handle = libusb_open_device_with_vid_pid(NULL, 0x1f3a, 0xefe8);
if (!handle) { if (!handle) {
fprintf(stderr, "A10 USB FEL device not found!"); fprintf(stderr, "ERROR: Allwinner USB FEL device not found!\n");
exit(1); exit(1);
} }
rc = libusb_claim_interface(handle, 0); rc = libusb_claim_interface(handle, 0);
#if defined(__linux__)
if (rc != LIBUSB_SUCCESS) {
libusb_detach_kernel_driver(handle, 0);
iface_detached = 0;
rc = libusb_claim_interface(handle, 0);
}
#endif
assert(rc == 0); assert(rc == 0);
while (argc > 1 ) { while (argc > 1 ) {
...@@ -338,5 +354,10 @@ int main(int argc, char **argv) ...@@ -338,5 +354,10 @@ int main(int argc, char **argv)
argv+=skip; argv+=skip;
} }
#if defined(__linux__)
if (iface_detached >= 0)
libusb_attach_kernel_driver(handle, iface_detached);
#endif
return 0; return 0;
} }
...@@ -49,12 +49,15 @@ ...@@ -49,12 +49,15 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/mount.h> /* BLKRRPART */ #include <sys/mount.h> /* BLKRRPART */
#include "nand-part.h" #include "nand-part.h"
#define MAX_NAME 16 #define MAX_NAME 16
void printmbrheader(MBR *mbr);
typedef struct tag_CRC32_DATA typedef struct tag_CRC32_DATA
{ {
__u32 CRC; //int的大小是32位 __u32 CRC; //int的大小是32位
...@@ -94,6 +97,8 @@ __u32 calc_crc32(void * buffer, __u32 length) ...@@ -94,6 +97,8 @@ __u32 calc_crc32(void * buffer, __u32 length)
MBR *_get_mbr(int fd, int mbr_num) MBR *_get_mbr(int fd, int mbr_num)
{ {
MBR *mbr; MBR *mbr;
const char * magic = "softw311";
unsigned version = 0x100;
/*request mbr space*/ /*request mbr space*/
mbr = malloc(sizeof(MBR)); mbr = malloc(sizeof(MBR));
...@@ -109,6 +114,17 @@ MBR *_get_mbr(int fd, int mbr_num) ...@@ -109,6 +114,17 @@ MBR *_get_mbr(int fd, int mbr_num)
{ {
/*checksum*/ /*checksum*/
printf("check partition table copy %d: ", mbr_num); printf("check partition table copy %d: ", mbr_num);
printmbrheader(mbr);
if(strncmp((char *)mbr->magic, magic, 8))
{
printf("magic %8.8s is not %8s\n", mbr->magic, magic);
return NULL;
}
if(mbr->version != version)
{
printf("version 0x%08x is not 0x%08x\n", mbr->version, version);
return NULL;
}
if(*(__u32 *)mbr == calc_crc32((__u32 *)mbr + 1,MBR_SIZE - 4)) if(*(__u32 *)mbr == calc_crc32((__u32 *)mbr + 1,MBR_SIZE - 4))
{ {
printf("OK\n"); printf("OK\n");
...@@ -130,6 +146,30 @@ __s32 _free_mbr(MBR *mbr) ...@@ -130,6 +146,30 @@ __s32 _free_mbr(MBR *mbr)
return 0; return 0;
} }
void printmbrheader(MBR *mbr)
{
printf("mbr: version 0x%08x, magic %8.8s\n", mbr->version, mbr->magic);
}
void printmbr(MBR *mbr)
{
int part_cnt;
printmbrheader(mbr);
for(part_cnt = 0; part_cnt < mbr->PartCount && part_cnt < MAX_PART_COUNT; part_cnt++)
{
if(1 || (mbr->array[part_cnt].user_type == 2) || (mbr->array[part_cnt].user_type == 0))
{
printf("partition %2d: class = %12s, name = %12s, partition start = %8d, partition size = %8d user_type=%d\n",
part_cnt,
mbr->array[part_cnt].classname,
mbr->array[part_cnt].name,
mbr->array[part_cnt].addrlo,
mbr->array[part_cnt].lenlo,
mbr->array[part_cnt].user_type);
}
}
}
void checkmbrs(int fd) void checkmbrs(int fd)
{ {
int part_cnt = 0; int part_cnt = 0;
......
...@@ -392,7 +392,7 @@ int main(int argc, char **argv) ...@@ -392,7 +392,7 @@ int main(int argc, char **argv)
} }
} }
if (in) { if (in) {
if (fread(buf, sizeof(buf), 1, in) != 1) { if (fread(buf, PIO_REG_SIZE, 1, in) != 1) {
perror("read input"); perror("read input");
exit(1); exit(1);
} }
...@@ -414,7 +414,7 @@ int main(int argc, char **argv) ...@@ -414,7 +414,7 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
} }
if (fwrite(buf, sizeof(buf), 1, out) != 1) { if (fwrite(buf, PIO_REG_SIZE, 1, out) != 1) {
perror("write output"); perror("write output");
exit(1); exit(1);
} }
......
...@@ -326,7 +326,7 @@ int script_parse_fex(FILE *in, const char *filename, struct script *script) ...@@ -326,7 +326,7 @@ int script_parse_fex(FILE *in, const char *filename, struct script *script)
perror("malloc"); perror("malloc");
} }
} }
} else if (isdigit(*p)) { } else if (isdigit(*p) || (*p == '-' && isdigit(*(p+1)))) {
long long v = 0; long long v = 0;
char *end; char *end;
v = strtoll(p, &end, 0); v = strtoll(p, &end, 0);
......
#!/bin/sh -e
top=`dirname $0`
if [ $# -lt 2 ]; then
echo "Usage: $0 board u-boot.bin [boot.scr|-] [kernel script.bin [initramfs]]"
exit 1
fi
board=$1; shift || (echo "ERROR: Board must be specified"; exit 1;)
uboot=$1; shift || (echo "ERROR: u-boot.bin must be specified"; exit 1;)
bootscr=$top/felboot/ramboot.scr
if [ ! -f $bootscr ]; then
bootscr=$top/bin/ramboot.scr
fi
case "$1" in
*.scr) bootscr="$1"; shift
;;
esac
kernel=$1; shift || true
scriptbin=$1; shift || true
initramfs=$1; shift || true
fel() {
echo fel "$@"
$top/fel $@
}
case $board in
*/*) felboot=$board
;;
*)
felboot=$top/felboot/fel-boot-${board}.bin
if [ ! -f $felboot ]; then
felboot=$top/bin/fel-boot-${board}.bin
fi
;;
esac
if [ ! -f $felboot ]; then
echo "ERROR: Can't find fel-boot binary for ${board}"
exit 1
fi
if [ ! -f $bootscr ]; then
echo "ERROR: Can't fint boot script '${bootscr}'"
exit 1
fi
fel write 0x2000 $felboot
fel exe 0x2000
sleep 1 # Wait for DRAM initialization to complete
if [ -n "$uboot" ]; then
fel write 0x4a000000 $uboot
fi
if [ -n "$bootscr" ]; then
fel write 0x41000000 $bootscr
fi
if [ -n "$kernel" ]; then
if [ -n "$scriptbin" ]; then
fel write 0x43000000 $scriptbin
fi
fel write 0x44000000 $kernel
if [ -n "$initramfs" ]; then
fel write 0x4c000000 $initramfs
fi
fi
fel exe 0x4a000000
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