Tuesday, December 23, 2008

quick removable drive with omap3

One neat little trick of having an OTG port is the capability to have the board act as any type of device you'd want it to be.. in my case, I wanted to emulate a disk drive for the heck of it..
I found this link particularly useful. g_file_storage.ko which is generated once you enable file storage gadget as a module in the kernel build.
Step 1: create the "disk" - essentially a file
dd bs=1M count=64 if=/dev/zero of=fs
fdisk fs (follow the steps in the link)
fdisk -lu fs
sudo losetup -o 4096 /dev/loop0 fs
sudo mkdosfs /dev/loop0
mkdir r
sudo mount -t vfat /dev/loop0 r
vim r/hellow.txt (put what ever files we want here)
sudo umount r
sudo losetup -d /dev/loop0

ensure that fs file exists in the filesystem of the target
Step 2: load it up..
insmod g_file_storage.ko file=./fs stall=n

where fs is the file which we created in the first place.. and that'z it.. once you connect the musb to a windows PC, it appears as a disk ;)...

Thursday, December 04, 2008

Towards creating a beagleboard NAND recovery script

NOTE: This is a work in progress yet..

Get Code base:
x-loader:
git clone git://www.sakoman.net/git/x-load-omap3.git

u-boot-v1 - omap3:
git clone git://www.sakoman.net/git/u-boot-omap3.git
cd u-boot-omap3
git checkout --track -b omap3-dev origin/omap3-dev
Updated: see here if this did not work..

u-boot-v2:
git clone git://git.denx.de/u-boot-v2.git

omap-uboot-utils:
git clone git://github.com/nmenon/omap-u-boot-utils.git

signGP tool:
wget http://beagleboard.googlecode.com/files/signGP.c

Compilers:
Cross compiler: arm-none-eabi-gcc: 2007q3-53 (4.2.1)
Host compiler: x64bit: (Ubuntu 4.3.2-1ubuntu11)

Build commands:
Before starting the build process, lets set up a simple alias command:
alias mymake='make ARCH=arm CROSS_COMPILE=arm-none-eabi- V=1'

U-boot-arm:
mymake omap3_beagle_config
mymake

U-Boot-v2:
mymake omap3530_beagle_per_uart_defconfig
mymake

X-Loader:
mymake omap3530beagle_config
mymake

[Update: 2008-12-13 - I completely forgot that we need to sign an image for it to boot from nand flash.. :(
once you have the x-load.bin, you need the signGP.c. Build this by the command:
gcc -o signgp signGP.c
Then run signgp from the same directory that x-load.bin is present. this generates a x-load.bin. Let me know if you feel signGP.c should be moved into omap-u-boot-utils..
]

Omap-Uboot-utils:

make

Copy Images:
Assuming a directory structure as in:
omap-u-boot-utils u-boot-arm u-boot-v2 x-load-omap3
Run the following commands:
cp u-boot-arm/u-boot.bin omap-u-boot-utils/images/u-boot-v1.bin
cp x-load-omap3/x-load.bin omap-u-boot-utils/images/
cp u-boot-v2/uboot.bin omap-u-boot-utils/images/u-boot-v2-serial.bin

Execution script file:


#!/bin/bash
if [ ! -w "$1" ]; then
echo "Usage: $0 path/to/ttyDevice"
exit 1
fi
set -x
export PATH=$PATH:.
pserial -p $1 -f images/u-boot-v2-serial.bin
ucmd -p $1 -c "loadb -f /dev/ram0" -e "bps..."
ukermit -p $1 -f images/u-boot-v1.bin
ucmd -p $1 -c "go 0x80000000" -e "autoboot"
ucmd -p $1 -c "help" -e "#"
ucmd -p $1 -c "loadb 0x80000000" -e "bps..."
ukermit -p $1 -f images/x-load.bin.ift
ucmd -p $1 -c "nand unlock" -e "#"
ucmd -p $1 -c "nandecc hw" -e "#"
ucmd -p $1 -c "nand erase 0 80000" -e "#"
ucmd -p $1 -c "nand write 80000000 0 80000" -e "#"

[Note: 2008-12-04 22:50hrs:
1. I just started up my laptop and connected my usb2serial
connector -> just found that pserial did not work out of the box.. ran minicom once and it started working.. will debug this later..
2. The nand erase and nand write seems to tell me my entire nand is filled with badblocks.. need to debug this a little more :(
Update 2008-12-11: Khasim has a patch for u-boot-v1 here which is supposedly working now.

Update: 2008-12-13: it seems to work automatically for zoom MDK

Interesting note: on zoom MDK, nand unlock is required before doing a saveenv!! :( need to fix this sometime..
]

Things to do:
a) introduce hw ecc for x-loader.. it should simplify things a lot..
b) Dirk,Steve and others are planning on sending the u-boot patches for mainline tree this weekend.

Send a git patch with gmail

The following is thanks to Dirk Behme (based on ubuntu 8.10):
Install packages:
On Ubuntu, I have done: sudo apt-get install git git-email

Stage1: development:
set up your GIT variables(probably in ~/.bashrc)
export GIT_COMMITTER_EMAIL=yourEmail@somewhere.com
export GIT_COMMITTER_NAME='YourName'
export GIT_AUTHOR_EMAIL=yourEmail@somewhere.com
export GIT_AUTHOR_NAME='YourName'

git clone ... or git pull.. etc to get to the latest code.
git branch branch_name
git checkout branch_name

Do changes
git commit with commit message in incremental stages..

Stage 2: Generate email-able patch files.
git-format-patch -s -n -o origin..
-s will generate the signed of-by
-n will generate numbered patches (if you have just a single patch, you can ignore it) - but if you have multiple ones, this is a good idea to use to generate subject auto numbered 1/2, 2/2 etc..
-o is where the output patch files will be stored -> each commit is a separate file.

Stage3: Email the patches:(for gmail)
Simple one (no mail threads):
git-send-email --from "My Name " --to "Some One " --cc "If I wantACC " --smtp-server smtp.gmail.com --smtp-user MyMailID@gmail.com --smtp-pass WONTTellPassword --smtp-ssl --subject "usually the result of grep Subject PatchFile" PatchFile

See --thread in man git-send-email for further info.. this is a pretty versatile tool.. just need to get used to it I guess

omap-uboot-utils supports usb2serial device

It has been a long time desire to use usb2serial convertors for pserial application. :(.. Anyways, yesterday night, I looped back my usb2serial back to my PCI serial port and tried to write a bit of loopback code.. to figure out the issue with pserial, I wrote a simple little app to print the ttySx flags:


#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

/************* VARS ***************/
static int fd;
static struct termios oldtio;

int main(int argc,char * argv[])
{
int ret;
int i;
if (argc!=2){
printf ("error no args..%d\n",argc);
return 1;
}
printf ("port: %s\n",argv[1]);
fd = open(argv[1], O_RDWR | O_NOCTTY);
if (!fd) {
printf("terminal is not open!\n");
return 1;
}
/* save current port settings */
ret = tcgetattr(fd, &oldtio);
if (ret < 0) {
printf("failed to get old attribs\n");
ret= 1;
goto quit;
}
ret = 0;
printf ("c_iflag = 0x%04X\n",oldtio.c_iflag);
printf ("c_oflag = 0x%04X\n",oldtio.c_oflag);
printf ("c_cflag = 0x%04X\n",oldtio.c_cflag);
printf ("c_lflag = 0x%04X\n",oldtio.c_lflag);
printf ("c_line = 0x%02X\n",oldtio.c_line);
printf ("c_ispeed = 0x%04X\n",oldtio.c_ispeed);
printf ("c_ospeed = 0x%04X\n",oldtio.c_ospeed);
for (i=0;i<NCCS;i++){
printf(" c_cc[%d]=0x%02X\n",i,oldtio.c_cc[i]);
}
quit:
close(fd);
return ret;

}




Comparing the vals with /usr/include/bits/termios.h, it was educational to first use minicom to communicate with even parity bit, then try the same with my pserial mods.. Initially found few flag setting issues, later found a fundamental error in my assumption in s_close function -> i assumed that it will happen at the end of transmission, in the case of a pci serial port, this would be true, but in the case of a usb2serial convertor, it looks like the data is send to the device but not actually transmitted on the lines :(.. a delay solved the issue..

bah!!! something silly!!! anyways, the patches are pushed to mainline omap-uboot-utils now.. you can get the source here . Will tag and make a binary zip for upload here a week from now if folks could let me know if things are working fine.... Meanwhile, I will try and create an beagle nand recovery tool updater later tonight.. just a bunch of wgets and ucmds I assume..