Saturday, May 25, 2013

Setup arm tool chain for RaspBerry-Pi (with MacOSX host)

Installing the ARM Toolchain

1) Simply download the tool chain package from the link.

https://github.com/downloads/UnhandledException/ARMx/ARMx-2009q3-67.tar.bz2

2) un-tar the package /opt/arm-linux-tools

3) add the tool chain path to the system path env & update the PATH env, e.g.
export PATH=/opt/arm-linux-tools/bin:$PATH

4) This is an option to install the eclipse as a IDE. http://www.eclipse.org/downloads/
Any Eclipse IDE for C / C + + Developers are OK. My version is


Eclipse IDE for C/C++ Developers
Version: Juno Service Release 2


5) After the eclipse, simply go to the HELP menu and checks for the update.

6) Now you could new a C project and set up the cross compile env.

7) Go to the project explorer & select the properties. Set up the cross compiler to "arm-none-linux-gnueabi-" & the cross compiler path.


8) You could add your source codes by New command & then Source File. e.g. main.c

#include
int main(void) {
printf("Hello World!\n");
return 0;
}


9) Then you could compile the program by Build command & verify the compiled codes with command  "arm-none-linux-gnueabi-objdump -t filename" on your host console.

10) You could not run your code in the host as it is a arm executable. 

11) You have to ftp the code to your lovely RPi & you have to setup the ftp server on the RPi but it is not difficult. And then execute the program on the target.



12) You could even setup the remote debugger in the eclipse ^_^


Saturday, September 8, 2012

Ubuntu 12.04 stuck at VMware easy install screen!

The issue happened right just after the Ubuntu 12.04 LTS installation, it stuck at VMware Easy install screen.




******************************************************************
******************************************************************
Vmware Easy Install

PLEASE WAIT! VMware Tools is currently being
installed on your system. Depending on the
version of Ubuntu you are installing, you may
log in below and use the system during
intallation. Otherwise, please wait for the
graphical environment to launch. Thank you.

******************************************************************
******************************************************************

  This is the note to fix the issue.

  1. Restore the /etc/issue file:
    sudo mv /etc/issue.backup /etc/issue*
  2. Restore the /etc/rc.local file:
    sudo mv /etc/rc.local.backup /etc/rc.local
  3. Restore the /etc/init/lightdm.conf file:
    sudo mv /opt/vmware-tools-installer/lightdm.conf /etc/init
Then reboot.

Highlight to setup Android build environment with Ubuntu 12.04

  This is a note how to setup the build environment on top of the Ubuntu 12.04.

  I am not going to write down all the details here as most of the steps & details could be found in http://source.android.com/source/initializing.html. Instead I just highlight some common errors here.

i) Install the Java run time engine.

  As the Ubuntu 12.04 is came with the OpenJava run-time & the android build environment is requested a java6 runtime, it will be a problem. Some websites mentioned that user could re-install the jdk with the repo but it just doesn't work. Anyway, the solution is to download it directly from the Java_Archive. You may choose the rpm or bin version. My suggestion is to pick up the bin version as you may need to install the rpm before.

  This is the installation procedures for the jdk.

#change to /opt
#chmod a+x jdk-6u35-linux-x64.bin
#./jdk-6u35-linux-x64.bin

  The above command will unzip the packages. Then what you need is to add the JAVA HOME path to the system. This is a suggestion.

#sudo gedit /etc/profile

  Then add the following lines at the end of the file.

export JAVA_HOME=/opt/jdk1.6.0_35
CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/ft.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOE/bin:$PATH

  Save the file & reboot the system, it should be fine now.

  To check the jdk version, simply use the following commands.

java -version & u will see the below response.


alexyu@ubuntu:/opt/jdk-6u/jdk1.6.0_35$ java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)
alexyu@ubuntu:/opt/jdk-6u/jdk1.6.0_35$

Wednesday, February 29, 2012

how to write fb?

This is an example showing how to verify the functionality of a embedded system fb. To compile the below code, this is the command.

"$CROSS_COMPILE"gcc fbapp.c -o fbapp

#include ...

#define ERROR(x) printf("fbtest error in line %s:%d: %s\n", __FUNCTION__, __LINE__, strerror(errno));

#define FBCTL(cmd, arg) \
if(ioctl(fd, cmd, arg) == -1) { \
ERROR("ioctl failed"); \
exit(1); }

#define FBCTL0(cmd) \
if(ioctl(fd, cmd) == -1) { \
ERROR("ioctl failed"); \
exit(1); }

struct fb_var_screeninfo var;
struct fb_fix_screeninfo fix;

int open_fb(const char* dev)
{
int fd = -1;
fd = open(dev, O_RDWR);
if(fd == -1)
{
printf("Error opening device %s : %s\n", dev, strerror(errno));
exit(-1);
}

return fd;
}

static void draw_pixel(void *fbmem, int x, int y, unsigned color)
{
if (var.bits_per_pixel == 16) {
unsigned short c;
unsigned r = (color >> 16) & 0xff;
unsigned g = (color >> 8) & 0xff;
unsigned b = (color >> 0) & 0xff;
unsigned short *p;

r = r * 32 / 256;
g = g * 64 / 256;
b = b * 32 / 256;

c = (r << 11) | (g << 5) | (b << 0);

fbmem += fix.line_length * y;

p = fbmem;

p += x;

*p = c;
} else {
unsigned int *p;

fbmem += fix.line_length * y;

p = fbmem;

p += x;

*p = color;
}
}

void fill_screen(void *fbmem)
{
unsigned x, y;
unsigned h = var.yres; //yres_virtual;
unsigned w = var.xres; //xres_virtual;
  // int color;
  for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
  draw_pixel(fbmem, x, y, (y? 0x00FFFFFF:0));}
        }
}
}
}

int main(int argc, char** argv)
{
int fb_num;
char str[64];
int fd;

if (argc == 2)
fb_num = atoi(argv[1]);
else
fb_num = 0;

sprintf(str, "/dev/graphics/fb%d", fb_num);
printf("opening %s\n", str);

fd = open(str, O_RDWR);

FBCTL(FBIOGET_VSCREENINFO, &var);
FBCTL(FBIOGET_FSCREENINFO, &fix);

printf("res %d,%d virtual %d,%d, line_len %d, bits_per_pixel %d\n",
var.xres, var.yres,
var.xres_virtual, var.yres_virtual,
fix.line_length,
var.bits_per_pixel);

void* ptr = mmap(0, var.yres_virtual * fix.line_length,
PROT_WRITE | PROT_READ,
MAP_SHARED, fd, 0);

if(ptr == MAP_FAILED) {
perror("mmap failed");
exit(1);
}

fill_screen(ptr);
return 0;
}

how-to setup busy box ?


The busybox could be cross compiled for arm-none-linux-gnueabi-gcc.
It is cross compiled with static link option.
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-
User could cp the busybox to /system/bin of the target sd card.

//install manually
adb shell
su
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
exit
adb push busybox /data/local
adb shell
cd /system
ls -al


cd /data/local
chmod busybox 755
/data/local/busybox cp /data/local/busybox /system/xbin/busybox
cd /system/xbin
chmod busybox 755
./busybox --install -s /system/xbin
rm /data/local/busybox

Sunday, June 20, 2010

UBIFS how to ^_^

UBIFS howto:


STEP 1:Install UBIFS tools with the follow packages. If you have the mkfs.ubifs then go to

Step 2 Use UBI
1. config kernel option and compile UBI / UBIFS /ext2 into the kernel
(1) Enable UBI and Emulate MTD devices
Path:
"Device Drivers"
-> "Memory Technology Device (MTD) support"
-> "UBI - Unsorted block images",

(2) Enable UBIFS
Path:
"File systems"
-> "Miscellaneous filesystems"
-> "UBIFS file system support"
(2) Enable Ext2
Path:
"File systems"
-> " Second extended fs support "

2. make image
(1)create UBIFS rootfs image
mkfs.ubifs -r filesys/ -m 4096 -e 516096 -c 2047 -o ubifs.img
ubinize -o ubi.img -m 4096 -p 512KiB ubinize.cfg

where ubinize.cfg contains:
[ubifs]
mode=ubi
image=ubifs.img --rootfs image name
vol_id=0
vol_size=128MiB --volume size
vol_type=dynamic
vol_name=ubifs ---UBI volume name
vol_flags=autoresize


3. mount rootfs
(1) mount ubifs root file system on redboot
fis load kernel
exec -c "noinitrd console=ttymxc0,115200 ubi.mtd=2 root=ubi0:ubifs rootfstype=ubifs rw"

(*assume the kernel had 5 partitions. But the UBI will create new partition when attach the UBI ,so root=/dev/mtdblock6)

4 mount a partition via UBI
(1) ubifs
ubiformat /dev/mtdXX
ubiattach /dev/ubi_ctrl -m XX
ubimkvol /dev/ubi0 -N ubi_name -s 512MiB
mount -t ubifs ubi0:ubi_name /mnt/ubifs
ubiupdatevol /dev/ubi0_0 –t - wipe out an existing UBI volume


Note:
About -o sync option in mount, this will make UBIFS to run in synchronous mode, which will disable write-back cache and small write buffers.
If -o sync is not used in mount, then we should run “sync” (symbolic link to BusyBox), to sync write-back cache and small write buffers to NAND, before we reset Dickens.
Above being said, as we don’t have a mechanism to power down gracefully, UBIFS synchronous mode (-o sync) is recommended at this moment.

Monday, June 14, 2010

how to build mtd-utilities

1) Download mtd-utils from the link.

ftp://ftp.infradead.org/pub/mtd-utils/

(PS: Reference link http://elinux.org/CompilingMTDUtils)

2) Preparation for x86 build.

i) zlib
ii) lzo
iii) uuid

(PS: For ubuntu 10.04, user can install the packages from "Synaptic Package Manager" or "apt-get".)

3) Build with the following command.

WITHOUT_XATTR=1 make
sudo su
DESTDIR=/usr/local make install

To compile external mtd-utils-1.3.x, build e2fsprogs, lzo, zlib in ltib first. No need to modify the Makefile.

Then run the following:

Setting the following flags.

ZLIBCPPFLAGS="-I/home/usr/include" ZLIBLDFLAGS="-L/home/usr/lib" CROSS=arm-none-linux-gnueabi- WITHOUT_XATTR=1 make