From: <bob...@us...> - 2007-01-13 09:43:41
|
Revision: 756 http://svn.sourceforge.net/hackndev/?rev=756&view=rev Author: bobofdoom Date: 2007-01-13 01:43:38 -0800 (Sat, 13 Jan 2007) Log Message: ----------- tools: Added primitive (on-device) phone console tool. Added Paths: ----------- linux4palm/tools/phone/ linux4palm/tools/phone/atcons.py Added: linux4palm/tools/phone/atcons.py =================================================================== --- linux4palm/tools/phone/atcons.py (rev 0) +++ linux4palm/tools/phone/atcons.py 2007-01-13 09:43:38 UTC (rev 756) @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# +# Experimental AT command console for the Treo 650 GSM +# + +import serial, sys, threading, termios, tty + +import os,sys +import sys +import termios + +FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)]) + +def dump(src, length=8): + N=0; result='' + while src: + s,src = src[:length],src[length:] + hexa = ' '.join(["%02X"%ord(x) for x in s]) + s = s.translate(FILTER) + result += "%04X %-*s %s\n" % (N, length*3, hexa, s) + N+=length + return result + +def getchar(): + ''' + Equivale al comando getchar() di C + http://www.bigbold.com/snippets/posts/show/3084 + ''' + + fd = sys.stdin.fileno() + + if os.isatty(fd): + + old = termios.tcgetattr(fd) + new = termios.tcgetattr(fd) + new[3] = new[3] & ~termios.ICANON & ~termios.ECHO + new[6] [termios.VMIN] = 1 + new[6] [termios.VTIME] = 0 + + try: + termios.tcsetattr(fd, termios.TCSANOW, new) + termios.tcsendbreak(fd,0) + ch = os.read(fd,7) + + finally: + termios.tcsetattr(fd, termios.TCSAFLUSH, old) + else: + ch = os.read(fd,7) + + return(ch) + + +readbuf = '' + +def read_thread(ser): + global readbuf + while 1: + c = ser.read() + readbuf += c + if c != '\r': + sys.stdout.write(c) + sys.stdout.flush() + +def main(): + if len(sys.argv) > 1: + port = sys.argv[1] + else: + port = '/dev/ttyS0' + ser = serial.Serial(port, 460800) #460800) + try: + ser.setRTS(1) + except IOError, e: + print 'Unable set RTS high:', e + t = threading.Thread(target=read_thread, args=(ser,)) + t.setDaemon(True) + t.start() + + while 1: + c = getchar() + if c == '\x01': print dump(readbuf); continue + if c == '\x7f': c = chr(8) # send BS not DEL + if c == '\n': ser.write('\r') + ser.write(c) + +if __name__ == '__main__': main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <z7...@us...> - 2007-05-04 09:15:56
|
Revision: 969 http://svn.sourceforge.net/hackndev/?rev=969&view=rev Author: z72ka Date: 2007-05-04 02:15:49 -0700 (Fri, 04 May 2007) Log Message: ----------- Added modified bcm2035-tool to SVN. Now is the baddr of BT chip as argument. Added Paths: ----------- linux4palm/tools/bcm2035-tool/ linux4palm/tools/bcm2035-tool/Makefile linux4palm/tools/bcm2035-tool/README linux4palm/tools/bcm2035-tool/bcm2035-tool.c linux4palm/tools/bcm2035-tool/bcm2035-tool.h linux4palm/tools/bcm2035-tool/motorola_patches.h Added: linux4palm/tools/bcm2035-tool/Makefile =================================================================== --- linux4palm/tools/bcm2035-tool/Makefile (rev 0) +++ linux4palm/tools/bcm2035-tool/Makefile 2007-05-04 09:15:49 UTC (rev 969) @@ -0,0 +1,9 @@ +P=arm-none-linux-gnueabi- + +bcm2035-tool: bcm2035-tool.c bcm2035-tool.h + ${P}gcc bcm2035-tool.c -o bcm2035-tool + +clean: + rm -f bcm2035-tool + + Property changes on: linux4palm/tools/bcm2035-tool/Makefile ___________________________________________________________________ Name: svn:executable + * Added: linux4palm/tools/bcm2035-tool/README =================================================================== --- linux4palm/tools/bcm2035-tool/README (rev 0) +++ linux4palm/tools/bcm2035-tool/README 2007-05-04 09:15:49 UTC (rev 969) @@ -0,0 +1,106 @@ +BCM2035-tool +************ + + This package contains a small utility to initialize and to update +the firmware of the bcm2035 bluetooth chip on the Motorola EZX Platform and +Palm devices with this chip. + + This chip has some custom HCI commands, to change the BDADDR and to +patch the original firmware. This tool can make use of both. + +Instructions: +------------- + + + You can use the motorola firmware by #defining PATCH_FIRMWARE, and the +Broadcom original firmware by leaving it commented. The chip works fine with +both firmwares, and i havent found yet what difference the motorola version +does. + Turn on the chip by sending "AT+EBTP=1\r" to BP, and run the tool. + + +Regards, + +Daniel Ribeiro + +-------- + +Extension by 72ka - Jan Herman <2h...@se...>: + +usage: bcm2035-tool <dev> <bdaddr> + +MAC address is as command. Remember original MAC addres from PalmOS and use in argument <bdaddr> + +e.g. + +bcm2035-tool /dev/ttyS1 00:07:8a:78:e3:23 + +------- + +wyrm@vault:~/bcm2035-tool$ make upload +/ezx/cross/bin/arm-angstrom-linux-gnueabi-gcc bcm2035-tool.c -o bcm2035-tool +scp bcm2035-tool root@a780: +root@a780's password: +bcm2035-tool 100% 15KB 15.3KB/s 00:00 +wyrm@vault:~/bcm2035-tool$ a780 +root@a780's password: +root@a780:~$ echo -e "AT+EBTP=1\r" | nc localhost 7104 + +OK + +root@a780:~$ ./bcm2035-tool /dev/ttyS1 +Set baud: 921600 +Patching Firmware... +:0: Wrote 17 bytes +:1: Wrote 33 bytes +:2: Wrote 78 bytes +:3: Wrote 15 bytes +:4: Wrote 76 bytes +:5: Wrote 25 bytes +:6: Wrote 127 bytes +:7: Wrote 13 bytes +:8: Wrote 185 bytes +:9: Wrote 572 bytes +:10: Wrote 31 bytes +:11: Wrote 76 bytes +:12: Wrote 41 bytes +:13: Wrote 113 bytes +:14: Wrote 56 bytes +:15: Wrote 39 bytes +:16: Wrote 29 bytes +:17: Wrote 56 bytes +:18: Wrote 39 bytes +:19: Wrote 82 bytes +:20: Wrote 33 bytes +:21: Wrote 29 bytes +:22: Wrote 43 bytes +:23: Wrote 86 bytes +:24: Wrote 146 bytes +:25: Wrote 11 bytes +@0: Wrote 82 bytes +@1: Wrote 6170 bytes +Set baud: 460800 +root@a780:~$ hciconfig hci0 up +root@a780:~$ hciconfig hci0 +hci0: Type: UART + BD Address: 01:23:45:67:89:AB ACL MTU: 377:10 SCO MTU: 64:0 + UP RUNNING PSCAN ISCAN + RX bytes:79 acl:0 sco:0 events:8 errors:0 + TX bytes:39 acl:0 sco:0 commands:8 errors:0 + +root@a780:~$ hciconfig hci0 version +hci0: Type: UART + BD Address: 01:23:45:67:89:AB ACL MTU: 377:10 SCO MTU: 64:0 + HCI Ver: 1.1 (0x1) HCI Rev: 0x3 LMP Ver: 1.1 (0x1) LMP Subver: 0x700 + Manufacturer: Broadcom Corporation (15) +root@a780:~$ hciconfig hci0 revision + hci0: Type: UART + BD Address: 01:23:45:67:89:AB ACL MTU: 377:10 SCO MTU: 64:0 + Firmware 3.7 / 0 +root@a780:~$ hcitool dev +Devices: + hci0 01:23:45:67:89:AB +root@a780:~$ hcitool scan +Scanning ... + 00:07:A4:58:05:B0 Motorola HS810 + Property changes on: linux4palm/tools/bcm2035-tool/README ___________________________________________________________________ Name: svn:executable + * Added: linux4palm/tools/bcm2035-tool/bcm2035-tool.c =================================================================== --- linux4palm/tools/bcm2035-tool/bcm2035-tool.c (rev 0) +++ linux4palm/tools/bcm2035-tool/bcm2035-tool.c 2007-05-04 09:15:49 UTC (rev 969) @@ -0,0 +1,268 @@ +/* bcm2035-tool + * + * (C) 2007 by Daniel Ribeiro <dr...@gm...> + * + * MAC address as argument extension by: Jan Herman <2h...@se...> + * + * 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 + * + * 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 + * + */ + +/* Default MAC address is 01:02:03:04:05:06 */ +#define BDADDR "\x06\x05\x04\x03\x02\x01" + +//#define PATCH_FIRMWARE + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include <linux/types.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <termios.h> +#include "bcm2035-tool.h" +#include "bluetooth.h" + +#ifdef PATCH_FIRMWARE +#include "motorola_patches.h" + +__u8 checksum(char *data, int size) +{ + __u8 ret = 0; + int i; + + for(i=0; i<size; i++) + ret-=data[i]; + return(ret); +} + + +char a_buffer[43]; +char *generate_packet(__u8 kind, __u16 address, __u8 flag, __u8 size, char *data) +{ + char b_buffer[21]; + char t_buffer[2]; + __u8 y, i; + __u8 x = 0; + + b_buffer[x++] = size; + b_buffer[x++] = (__u8) (address >> 8); + b_buffer[x++] = (__u8) address; + if (kind) + b_buffer[x++] = flag; + memcpy((char *)b_buffer + x, data, size); + x+=size; + b_buffer[x] = checksum(b_buffer, x); + x++; + + for(i=0,y=0;i<x;i++) + { + sprintf(t_buffer, "%.2X", (__u8) b_buffer[i]); + a_buffer[y++] = t_buffer[0]; + a_buffer[y++] = t_buffer[1]; + } + a_buffer[y] = 0; + return((char *)a_buffer); +} + +int send_patch(int fd, struct patch p, __u8 kind) +{ + int n; + char t[50]; + int ret = 0; + // p.size == 0 has special treatment + if (p.size == 0) { + sprintf (t, ":%s", generate_packet(kind, p.address, p.flag, + p.size, p.data)); + ret += write(fd, t, strlen(t)); + read (fd, t, 8); + if (t[0] != '.') + exit(-2); + + } + else for (n=0;n<p.size;n+=MAXWRITESIZE) { + sprintf (t, "%s%s", (kind?":":"@00"), generate_packet(kind, + p.address + n, p.flag, (p.size - n > MAXWRITESIZE ? + MAXWRITESIZE : p.size - n), p.data + n)); + ret += write(fd, t, strlen(t)); + read (fd, t, 8); + if (!kind && strncmp(t, "@01", 3)) + exit (-3); + if (kind && t[0] != '.') + exit (-2); + + + } + return(ret); +} +#endif // PATCH_FIRMWARE + +int send_cmd (int fd, char *cmd, char *arg, int argsize) +{ + char buf[16]; + int x = 0; + buf[x++] = 0x01; + memcpy(buf + x, cmd, 2); + x+=2; + buf[x++] = (__u8) argsize; + if(argsize > 0) + { + memcpy(buf + x, arg, argsize); + x+=argsize; + } + write(fd, buf, x); + read(fd, buf, 8); + if (strncmp(buf, REP, 3) != 0 || buf[3] != 1 || + strncmp(buf+4, cmd, 2) != 0 || buf[6] != 0) { + printf(" unexpected reply\n"); + exit(-10); + } + +} + +#ifdef PATCH_FIRMWARE +int patch_fw(int fd, struct patch p1[], struct patch p2[]) +{ + int i; + char buf[8]; + + printf("Patching Firmware...\n"); + send_cmd(fd, CMD_PATCH_FW, NULL, 0); + + read(fd, buf, 8); + + for (i=0;p1[i].data!=NULL;i++) + printf(":%d: Wrote %d bytes\n", i, send_patch(fd, p1[i], 1)); + + for (i=0;p2[i].data!=NULL;i++) + printf("@%d: Wrote %d bytes\n", i, send_patch(fd, p2[i], 0)); + + write(fd, "Z", 1); +} +#endif + +int set_baud(int fd, int baud) +{ + struct termios t; + char buf[8]; + + printf("Set baud: %d\n", baud); + tcgetattr(fd, &t); + switch (baud) { + case 115200: + send_cmd(fd, CMD_SET_BAUD, BAUD115200, 2); + cfsetospeed(&t, B115200); + break; + case 460800: + send_cmd(fd, CMD_SET_BAUD, BAUD460800, 2); + cfsetospeed(&t, B460800); + break; + case 921600: + send_cmd(fd, CMD_SET_BAUD, BAUD921600, 2); + cfsetospeed(&t, B921600); + break; + default: + printf ("invalid baud rate!\n"); + return(-1); + } + return tcsetattr(fd, TCSANOW, &t); + +} + +void mac2hex(const char *mac, u_char *dst) +{ + + int i; + long l; + char *pp; + + while (isspace(*mac)) + mac++; + + /* expect 6 hex octets separated by ':' or space/NUL if last octet */ + for (i = 0; i < 6; i++) { + l = strtol(mac, &pp, 16); + if (pp == mac || l > 0xFF || l < 0) + return; + if (!(*pp == ':' || (i == 5 && (isspace(*pp) || *pp == '\0')))) + return; + /* 5-i swaps hex chars */ + dst[5-i] = (u_char) l; + mac = pp + 1; + } + } + +char *bdaddr[6]; + +int main(int argc, char **argv) +{ + int fd, i; + struct termios term; + char buf[1024]; + + if (argc < 3) { + printf("BCM2035 Tool:\n"); + printf("Usage: %s <device> <bdaddr>\n", argv[0]); + exit(1); + } + + /* MAC address is required */ + + if (strlen(argv[2]) < 17) { + printf("invalid argument %s!\n", argv[2]); + exit(1); + } + + /* Converts MAC address to swapped HEX */ + mac2hex(argv[2], &bdaddr); + + fd = open (argv[1], O_RDWR | O_NOCTTY ); + + if(fd < 0) exit(-1); + + term.c_iflag=0x5; + term.c_oflag=0; + term.c_cflag=0x1cb2; + term.c_lflag=0; + term.c_line=0; + memcpy(term.c_cc, "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", NCCS); + ioctl (fd, TCSETS, &term); + + send_cmd(fd, CMD_RESET, NULL, 0); +#ifdef PATCH_FIRMWARE + set_baud(fd, 921600); + patch_fw(fd, motorola_patches, motorola_firmware); + sleep(5); +#endif + set_baud(fd, 460800); + + send_cmd(fd, CMD_SET_BDADDR, bdaddr, 6); + + i = N_HCI; + if (ioctl(fd, TIOCSETD, &i) < 0) { + perror("Can't set line discipline"); + exit(1); + } + if (ioctl(fd, HCIUARTSETPROTO, 0) < 0) { + perror("Can't set device"); + exit(1); + } + if (fork()) + return 0; + while (1) sleep(999999999); + return 0; +} Property changes on: linux4palm/tools/bcm2035-tool/bcm2035-tool.c ___________________________________________________________________ Name: svn:executable + * Added: linux4palm/tools/bcm2035-tool/bcm2035-tool.h =================================================================== --- linux4palm/tools/bcm2035-tool/bcm2035-tool.h (rev 0) +++ linux4palm/tools/bcm2035-tool/bcm2035-tool.h 2007-05-04 09:15:49 UTC (rev 969) @@ -0,0 +1,49 @@ +/* bcm2035-tool - bcm2035 tool for Motorola EZX phones + * + * (C) 2007 by Daniel Ribeiro <dr...@gm...> + * + * 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 + * + * 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 + * + */ + + +#define HCIUARTSETPROTO _IOW('U', 200, int) + +#define MAXWRITESIZE 16 + +struct cmd { + char *cmd; + int size; + char *reply; +}; + +struct patch { + __u16 address; + __u8 flag; + int size; + char *data; +}; + +#define REP "\x04\x0e\x04" + +#define BAUD115200 "\x00\xf3" +#define BAUD460800 "\x22\xfd" +#define BAUD921600 "\x55\xff" + +#define CMD_SET_BAUD "\x18\xfc" +#define CMD_RESET "\x03\x0c" +#define CMD_PATCH_FW "\x2e\xfc" +#define CMD_SET_BDADDR "\x01\xfc" + + Property changes on: linux4palm/tools/bcm2035-tool/bcm2035-tool.h ___________________________________________________________________ Name: svn:executable + * Added: linux4palm/tools/bcm2035-tool/motorola_patches.h =================================================================== --- linux4palm/tools/bcm2035-tool/motorola_patches.h (rev 0) +++ linux4palm/tools/bcm2035-tool/motorola_patches.h 2007-05-04 09:15:49 UTC (rev 969) @@ -0,0 +1,10 @@ +/* + * This file contains binary firmware code and cant be freely distributed. + * If you own an ezx phone and wants this file i can tell you how to + * create it based on the "dload" app of the motorola firmware. + */ + +#error This file cant be distributed on OpenEZX servers. + +struct patch motorola_patches[]; +struct patch motorola_firmware[]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <far...@us...> - 2007-05-30 14:39:43
|
Revision: 1015 http://svn.sourceforge.net/hackndev/?rev=1015&view=rev Author: farcaller Date: 2007-05-30 07:39:41 -0700 (Wed, 30 May 2007) Log Message: ----------- hexterm: Initial import Added Paths: ----------- linux4palm/tools/hexterm/ linux4palm/tools/hexterm/Makefile linux4palm/tools/hexterm/hexterm.c Added: linux4palm/tools/hexterm/Makefile =================================================================== --- linux4palm/tools/hexterm/Makefile (rev 0) +++ linux4palm/tools/hexterm/Makefile 2007-05-30 14:39:41 UTC (rev 1015) @@ -0,0 +1,7 @@ +all: hexterm + +hexterm: hexterm.c + $(CC) -g -std=c99 -o hexterm hexterm.c -lreadline + +clean: + rm -f hexterm *.o Added: linux4palm/tools/hexterm/hexterm.c =================================================================== --- linux4palm/tools/hexterm/hexterm.c (rev 0) +++ linux4palm/tools/hexterm/hexterm.c 2007-05-30 14:39:41 UTC (rev 1015) @@ -0,0 +1,221 @@ +/******************************************************************************* + * + * hexterm - stupid hex i/o terminal + * + * (C) 2007 by Vladimir "Farcaller" Pouzanov <far...@gm...> + * Parts of code from bcm-tool by Daniel Ribeiro + * + * 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 + * + * 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 <stdlib.h> +#include <string.h> +#include <readline/readline.h> +#include <readline/history.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <termios.h> +#include <unistd.h> +#include <errno.h> + +#define MAX_REQUEST 1024 +#define TRUE 1 +#define FALSE 0 + +/*** parser and console i/o ***/ + +char parse_char(const char *c) +{ + long int i; + if(strlen(c)>2) + return 0; + i = strtol(c, NULL, 16); + if(i>255) + return 0; + return i; +} + +char * parse_line(char *line, int *len) +{ + char *p, *s; + char b[4]; + char *buff, *bp; + char byte; + int done = FALSE; + int cnt = 0; + + s = p = line; + buff = malloc(MAX_REQUEST); + bp = buff; + while (*p != '\0' && !done) { + while (*p != '\0' && *p != ' ') + p++; + if (*p == '\0') { + done = TRUE; + } else { + *p = '\0'; + p++; + } + strncpy(b, s, 3); + b[3] = '\0'; + byte = parse_char(b); + *bp = byte; + bp++; + cnt++; + s = p; + } + *len = cnt; + return buff; +} + +/*** serial i/o ***/ + +int set_baud(int fd, int baud) +{ + struct termios t; + char buf[8]; + + printf("< set baud: %d\n", baud); + tcgetattr(fd, &t); + switch (baud) { + case 115200: + //send_cmd(fd, CMD_SET_BAUD, BAUD115200, 2); + cfsetospeed(&t, B115200); + break; + case 460800: + //send_cmd(fd, CMD_SET_BAUD, BAUD460800, 2); + cfsetospeed(&t, B460800); + break; + case 921600: + //send_cmd(fd, CMD_SET_BAUD, BAUD921600, 2); + cfsetospeed(&t, B921600); + break; + default: + printf ("invalid baud rate!\n"); + return(-1); + } + return tcsetattr(fd, TCSANOW, &t); +} + + +void send_data(int fd, char *bytes, int len) +{ + if (len == 0) { + printf("==> ...\n"); + return; + } + printf("==[%d][", len); + char *p; + int i; + ssize_t sz; + sz = write(fd, bytes, len); + if (sz == -1) { + fprintf(stderr, "write() failed: %d\n", errno); + exit(10); + } + printf("%d]=> ", sz); + for(p=bytes, i=0;i<len;i++,p++) + printf("%02hhX ", *p); + printf("\n"); + +} + +void recv_and_print(int fd) +{ + ssize_t sz=0; + int cnt = 0; + char buf; + printf("<== "); + while (sz != -1) { + sz = read(fd, &buf, 1); + if (sz == -1) { + if (errno == EAGAIN) { + //printf("[%u]==\n", cnt); + break; + } else { + printf("?? %d\n", errno); + } + return; + } else { + printf("%02hhX ", buf); + cnt++; + } + } + + printf("[%u]==\n", cnt); +} + +/*** main code ***/ + +void main_loop(int fd) +{ + char *rl = 0; + char *bytes; + int len; + while (TRUE) { + rl = readline("> "); + if (rl == 0) { + return; + } + add_history(rl); + if (strncmp(rl, "baud ", 5) == 0) { + long int l; + char *p = rl+5; + l = atoi(p); + set_baud(fd, l); + free(rl); + rl = 0; + continue; + } + bytes = parse_line(rl, &len); + free(rl); + rl = 0; + send_data(fd, bytes, len); + free(bytes); + recv_and_print(fd); + } +} + +int main(int argc, char *argv[]) +{ + int fd; + struct termios term; + if (argc != 2) { + fprintf(stderr, "Usage: %s device\n", argv[0]); + return 2; + } + fd = open(argv[1], O_RDWR | O_NOCTTY | O_NONBLOCK); + if(fd < 0) { + fprintf(stderr, "can't open %s\n", argv[1]); + return 1; + } + printf("< opened %s\n", argv[1]); + + term.c_iflag=0x5; + term.c_oflag=0; + term.c_cflag=0x1cb2; + term.c_lflag=0; + term.c_line=0; + memcpy(term.c_cc, "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", NCCS); + ioctl (fd, TCSETS, &term); + printf("< configured port\n"); + main_loop(fd); + close(fd); + return 0; +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bob...@us...> - 2007-07-07 04:08:43
|
Revision: 1110 http://svn.sourceforge.net/hackndev/?rev=1110&view=rev Author: bobofdoom Date: 2007-07-06 21:08:39 -0700 (Fri, 06 Jul 2007) Log Message: ----------- TOOLS: Initial revision of a quick and dirty bootloader for the palmld's "sandal" serial recovery console. Added Paths: ----------- linux4palm/tools/serial-loader/ linux4palm/tools/serial-loader/Makefile linux4palm/tools/serial-loader/README linux4palm/tools/serial-loader/bin2sandal.py linux4palm/tools/serial-loader/ql.py linux4palm/tools/serial-loader/quickload.S linux4palm/tools/serial-loader/quickload.lds Added: linux4palm/tools/serial-loader/Makefile =================================================================== --- linux4palm/tools/serial-loader/Makefile (rev 0) +++ linux4palm/tools/serial-loader/Makefile 2007-07-07 04:08:39 UTC (rev 1110) @@ -0,0 +1,21 @@ +CROSS_COMPILE?=arm-softfloat-linux-gnueabi- +CC=${CROSS_COMPILE}gcc +OBJCOPY=${CROSS_COMPILE}objcopy +LDFLAGS=-nostdlib -Wall -pipe -Tquickload.lds -g -O2 +CFLAGS=-g -O2 + +SRCS=quickload.S #quickload.c + +all: quickload.sandal + +quickload.sandal: quickload.bin + ./bin2sandal.py quickload.bin quickload.sandal + +quickload.bin: quickload.elf + ${OBJCOPY} -O binary quickload.elf quickload.bin + +quickload.elf: ${SRCS} quickload.lds + ${CC} $(LDFLAGS) ${SRCS} -o quickload.elf + +clean: + rm -f quickload.bin quickload.elf quickload.sandal *.s Added: linux4palm/tools/serial-loader/README =================================================================== --- linux4palm/tools/serial-loader/README (rev 0) +++ linux4palm/tools/serial-loader/README 2007-07-07 04:08:39 UTC (rev 1110) @@ -0,0 +1,55 @@ +-------------------- +Serial Loading Tools +-------------------- + +This collection of tools enables you to boot Linux on a palmld PDA via the +'Sandal' recovery console on the serial port. They may also be useful for other +devices. + +Usage +----- + +Connect PDA to PC's serial port. You'll need to convert between the PDA's TTL +level serial port and your PCs RS232. Alternatively you can get a something +like a Nokia DKU-5 data cable which does TTL serial -> USB conversion. + +Open the serial port using something like minicom at a baud rate of 115200 with +both software and hardware flow control disabled. + +Reset the PDA while holding down the hotsync button. The LCD should remain off +indicating the recovery console has been entered. On the PC you should see the +Sandal prompt. Check to make sure the link is working by typing a command such +as "w 0". + +Compile the 'quickload' bootloader by typing 'make'. Upload the bootloader to +the PDA using a command like: + + ./bin2sandal.py -d quickload.bin > /dev/ttyUSB0 + +In minicom you should see a bunch memory write commands hopefully ending in +quickload's prompt "Q?" . + +Upload your kernel image using ql.py: + + ./ql.py < zImage > /dev/ttyUSB0 + +This may take a while, ql.py will print the progress percentage and you should +see the bootloader replying with lots of dots in minicom. When the upload is +complete ql.py will exit and the bootloader will print 'G' and then attempt to +jump to the image. + + +Kernel Note +----------- + +Quickload doesn't support passing a kernel command line at the moment so you'll +want to compile one into kernel itself. Normally you'll want to at least +specify the RAM size of the device and put the console on the serial port like +this: + + mem=32M console=ttyS0,115200 + + +---- +Alex Osborne +<alex at-sign hackndev dot com> Added: linux4palm/tools/serial-loader/bin2sandal.py =================================================================== --- linux4palm/tools/serial-loader/bin2sandal.py (rev 0) +++ linux4palm/tools/serial-loader/bin2sandal.py 2007-07-07 04:08:39 UTC (rev 1110) @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# +# This script takes an executable binary image (such as a zImage) and spits out +# a bunch of commands for the "Sandal" recovery console on the LD which loads +# the image into RAM and then executes it. +# +# eg. ./bin2sandal -d quickload.bin > /dev/ttyUSB0 +# +# The -d option introduces a short delay to prevent the Sandal console from being +# overwhelmed. +# +# Author: Alex Osborne <alex at-sign hackndev dot com> +# Created: Jul 2007 + +LOAD_ADDR=0xa0000000 + +import sys +import struct +import time + +if len(sys.argv) > 1 and sys.argv[1] in ['-h', '--help']: + print 'Usage: %s [-d] [input binary file] [output sandal commands file]' % sys.argv[0] + sys.exit(1) + +inf = sys.stdin +outf = sys.stdout +delay = False + +if len(sys.argv) > 1 and sys.argv[1] == '-d': + delay = True + sys.argv.pop(1) + +if len(sys.argv) > 1: + inf = file(sys.argv[1], 'rb') + +if len(sys.argv) > 2: + outf = file(sys.argv[2], 'wb') + +address = LOAD_ADDR + +while 1: + data = inf.read(4) + if not data: break + + data += '\0' * (4 - len(data)) # pad with zeros to make full dword + + value, = struct.unpack('<I', data) + + outf.write('w 0x%x=0x%x\r\n' % (address, value)) + + address += 4 + + if delay: + outf.flush() + time.sleep(0.02) + +outf.write('x 0x%x\r\n' % LOAD_ADDR) Property changes on: linux4palm/tools/serial-loader/bin2sandal.py ___________________________________________________________________ Name: svn:executable + * Added: linux4palm/tools/serial-loader/ql.py =================================================================== --- linux4palm/tools/serial-loader/ql.py (rev 0) +++ linux4palm/tools/serial-loader/ql.py 2007-07-07 04:08:39 UTC (rev 1110) @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# +# Quick and dirty script for sending an image to the 'quickload' serial +# bootloader. +# +# eg. ./ql.py < zImage > /dev/ttyUSB0 +# +# Author: Alex Osborne <alex at-sign hackndev dot com> +# Created: July 2007 + +import sys +import struct +import time + +image = sys.stdin.read() + +# anything before a 'G' will be echoed by bootloader +sys.stdout.write('ql.py: uploading image...\r\n') + +# notify bootloader to begin listening +sys.stdout.write('G') + +# output the size of the image +sys.stdout.write(struct.pack('<I', len(image))) + +# write out image +i = 0 +for c in image: + sys.stdout.write(c) + sys.stdout.flush() + + # print progress percentage + i += 1 + if (i % 1000) == 0: + sys.stderr.write('%f\n' % (i / float(len(image)) * 100)) + sys.stderr.flush() Property changes on: linux4palm/tools/serial-loader/ql.py ___________________________________________________________________ Name: svn:executable + * Added: linux4palm/tools/serial-loader/quickload.S =================================================================== --- linux4palm/tools/serial-loader/quickload.S (rev 0) +++ linux4palm/tools/serial-loader/quickload.S 2007-07-07 04:08:39 UTC (rev 1110) @@ -0,0 +1,138 @@ +@ quickload.S - primitive serial bootloader for pxa devices +@ +@ This bootloader enables you to load and execute a kernel image via the serial +@ port using a very simple transfer protocol. The bootloader expects the system +@ to have the MMU disabled. +@ +@ Protocol: +@ +@ Upon starting the bootloader will output the prompt 'Q?'. It will then read +@ echo characters until it encounters a 'G' character. This echo mode is to +@ allow reliability testing of the link and to soak up any stray characters that +@ may have been received. Upon receiving 'G' the bootloader will read a DWORD +@ which it treats as the length of the kernel image. It will then read that +@ many bytes loading them into RAM starting at 0xA0008000. It prints a '.' +@ character every 256 or so bytes. After the image loading is complete it +@ prints 'D' and jumps to the start of the image. +@ +@ Author: Alex Osborne <alex at-sign hackndev dot com> +@ Created: July 2007 +@ + +.text +.globl _start +_start: + b _copier + +@ magic number for tools to recognize us (currently unused) + .word 0xb007104d + +@ here we store how many bytes will be uploaded +data_length: + .word 0x0 + +_copier: +@ figure out where we are loaded + mov r7, pc + sub r7, #(_copier-_start+8) + +@ r5 := FFUART base + mov r5, #0x40000000 + orr r5, #0x00100000 + +@ show our ready prompt "Q?" + mov r0, #'Q' + bl ffuart_putc + mov r0, #'?' + bl ffuart_putc + +@ echo until we get a 'G' indicating start of transmission +wait_ready: + bl ffuart_getc + bl ffuart_putc + cmp r0, #'G' + bne wait_ready + +@ read in the length of the image + mov r0, #0 + str r0, [r7, #8] + + bl ffuart_getc + strb r0, [r7, #8] + bl ffuart_getc + strb r0, [r7, #8 + 1] + bl ffuart_getc + strb r0, [r7, #8 + 2] + bl ffuart_getc + strb r0, [r7, #8 + 3] + + +@ start loading in the image + mov r1, #0xa0000000 + orr r1, #0x00008000 + ldr r2, [r7, #8] @ remaining bytes + +_loop: + @ if no remaining bytes, goto done + cmp r2, #0 + beq done + + @ decrement remaining bytes + sub r2, #1 + + @ print '.' every now and then + and r0, r2, #0xff + cmp r0, #0 + mov r0, #'.' + bleq ffuart_putc + + @ get a character + bl ffuart_getc + + @ store it in RAM + strb r0, [r1] + + @ increment our storage location + add r1, #1 + + + b _loop + +done: + mov r0, #'D' + bl ffuart_putc + + @ setup the kernel parameters + mov r0, #0 + mov r1, #0x340 @ mach id + orr r1, #0x003 @ 0x343 = palmld + mov r2, #0 @ atag base + + @ jump to the kernel image + mov r3, #0xa0000000 + orr r3, #0x00008000 + mov pc, r3 + +ffuart_putc: +@ wait for LSR to show we're ready to transmit + ldr r6, [r5, #0x14] @ get LSR + and r6, #0x32 @ is TDRQ set? + cmp r6, #0 + beq ffuart_putc + + str r0, [r5] @ put character into THR + + mov pc, lr + +ffuart_getc: +@ wait for LSR to show we're ready to receive + ldr r6, [r5, #0x14] @ get LSR + and r6, #1 @ is DR set? + cmp r6, #0 + beq ffuart_getc + + ldr r0, [r5] @ get character from RBR + + mov pc, lr + + Added: linux4palm/tools/serial-loader/quickload.lds =================================================================== --- linux4palm/tools/serial-loader/quickload.lds (rev 0) +++ linux4palm/tools/serial-loader/quickload.lds 2007-07-07 04:08:39 UTC (rev 1110) @@ -0,0 +1,14 @@ +SECTIONS +{ + /* This is the location that bootmenu will be copied to. + Set it to a safe place that will not squash any PalmOS + data. + */ + . = 0xa0100000; + + .text : { *(.text) } + .data : { *(.data) } + .bss : { *(.bss) } + _end = .; + _length = _end - _start; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hap...@us...> - 2007-09-12 16:47:10
|
Revision: 1308 http://hackndev.svn.sourceforge.net/hackndev/?rev=1308&view=rev Author: happy-slapin Date: 2007-09-12 09:47:07 -0700 (Wed, 12 Sep 2007) Log Message: ----------- Adding script to clean tags Added Paths: ----------- linux4palm/tools/tags-cleanup/ linux4palm/tools/tags-cleanup/splitpatch.py Added: linux4palm/tools/tags-cleanup/splitpatch.py =================================================================== --- linux4palm/tools/tags-cleanup/splitpatch.py (rev 0) +++ linux4palm/tools/tags-cleanup/splitpatch.py 2007-09-12 16:47:07 UTC (rev 1308) @@ -0,0 +1,125 @@ +#!/usr/bin/env python +import sys, sre + +class Hunk: + def __init__(self, hunk): + self.hunk = hunk + self.lines = self.hunk.split("\n") + self.linecount = len(self.lines) + self.insertions = 0 + self.deletions = 0 + self.added = [] + self.removed = [] + self.ID = sre.compile("\$Id:{0,1}.*\$") + self.Revision = sre.compile("\$Revision:{0,1}.*\$") + self.Author = sre.compile("\$Author:{0,1}.*\$") + self.Date = sre.compile("\$Date:{0,1}.*\$") + self.ok = 0 + for i in range(0, self.linecount): + if self.lines[i].startswith("+"): + self.insertions += 1 + self.added.append(self.lines[i]) + if self.lines[i].startswith("-"): + self.deletions += 1 + self.removed.append(self.lines[i]) + self.checkhunk() + def rm_ident(self, string): + string = self.Revision.sub("", string) + string = self.ID.sub("", string) + string = self.Author.sub("", string) + string = self.Date.sub("", string) + return string + def checkhunk(self): + if self.insertions != self.deletions: + self.ok = 1 + return self.ok + + for i in range(0, self.insertions): + tmp1 = self.rm_ident(self.added[i][1:]) + tmp2 = self.rm_ident(self.removed[i][1:]) + if tmp1 != tmp2: + self.ok = 1 + break + return self.ok + + +class Patch: + def __init__(self, patch): + self.hunks = [] + self.okhunks = [] + self.hunkno = -1 + self.patch = patch + self.lines = patch.split("\n") + self.patchhead = "" + self.ignored = "" + for i in range(0, len(self.lines)): + if self.lines[i].startswith("+++ ") or self.lines[i].startswith("--- ") or self.lines[i].startswith("diff "): + self.patchhead += self.lines[i] + "\n" + elif self.lines[i].startswith("@"): + self.hunkno += 1 + self.hunks.append(self.lines[i] + "\n") + elif self.lines[i].startswith(" ") or self.lines[i].startswith("+") \ + or self.lines[i].startswith("-") or self.lines[i].startswith("\\"): + self.hunks[self.hunkno] += self.lines[i] + "\n" + else: + if len(self.lines[i]) > 0: + self.ignored += "WARNING: |%s|\n" % (self.lines[i]) + for i in range(0, len(self.hunks)): + n = Hunk(self.hunks[i]) + if n.ok: + self.okhunks.append(n.hunk) + self.hunks = self.okhunks + self.okhunks = [] + +class ParsePatch: + def __init__(self, patch): + self.data = "" + self.head = "" + self.name = "" + self.patch = Patch(patch) + if len(self.patch.hunks) > 0: + self.data = self.patch.patchhead + "\n".join(self.patch.hunks) + self.head = self.patch.patchhead.split("\n")[2].split(" ")[1].split("\t")[0] + namelist = self.head.split("/") + self.name = "-".join(namelist[1:2]) + ".diff" + self.ignored = self.patch.ignored + +class PatchCollection: + def __init__(self): + self.patches = [] + + def append(self, patch): + self.patches.append(ParsePatch(patch)) + + def flushfiles(self): + data = {} + for g in self.patches: + if data.has_key(g.name): + data[g.name] += g.data + g.ignored + else: + data[g.name] = g.data + g.ignored + for f, d in data.items(): + print "New file " + f + fd = open(f, "w") + fd.write(d) + fd.close() + +fd = open(sys.argv[1], "r") + +lines = fd.read().split("\n") +patches = [] +patchno = -1 + +for i in range(0, len(lines)): + if lines[i].startswith("diff "): + patchno += 1 + patches.append(lines[i] + "\n") + else: + patches[patchno] += lines[i] + "\n" + +pcol = PatchCollection() +for i in range(0, len(patches)): + pcol.append(patches[i]) + +pcol.flushfiles() +fd.close() Property changes on: linux4palm/tools/tags-cleanup/splitpatch.py ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |