Wednesday, August 29, 2007

arm-linux : struct alignment

The following code examine arm structure....

#include < stdio.h >

#define PACKED __attribute__((packed))

typedef struct struct_Foo
{
char c;
int r;
long f;
} PACKED FOO;

typedef struct struct_Foo2
{
char c;
int r;
long f;
} FOO2;

int main(int argc, char* argv[])
{
printf ("Test arm...\n");
printf (" char : %2d\n", sizeof(char));
printf (" int : %2d\n", sizeof(int));
printf (" long : %2d\n", sizeof(long));
printf (" foo : %2d\n", sizeof(FOO));
printf (" foo2 : %2d\n", sizeof(FOO2));
}


and my Makefile:

# where is my tool chains for arm
BLD_NAME=greenphone
BLD_TOOL_VER = gcc-4.1.1-glibc-2.3.6
BLD_TARGET=arm-linux
BLD_PREFIX= /opt/toolchains/greenphone/$(BLD_TOOL_VER)
CROSS_COMPILE=$(BLD_PREFIX)/$(BLD_TARGET)/bin/$(BLD_TARGET)-

# tools... I am using

LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E

CFLAGS = -x c

all:
$(CC) $(CFLAGS) -o test test.c


result?

int : 4
long : 4
foo : 9
foo2 : 12

Wednesday, August 22, 2007

Book - The C Programming Language

Write a post is different then write a program, if you have nothing intested to say, be quiet. That is a rule in programming on Unix. But for write a post, I don't have to follow the rule when i don't have any interesting things to say.

I am talking about the book "The C Programming Book" by KR. Despite the high price, I bought it from Chapters. Is that good value for me? yes, I think so, a C programmer need to have such a book. C language is not too hard to follow or learn, and this book is 270 pages including the index. I have already grasp the C language, so I don't learn the language from this book. But the point is, I want to know how C inventer think about C language, how they use it, it is interested to me, so this book give me the idea.


C "wears well as one's experience with it grows".


There are several points I want to confess:

1. C language and Unix. C is invented for programming on Unix, so unix is C's target, especailly the C standard library contains the interface to Unix OS. To use a language, understand well about the target is one of the keys. Note the book does not talk about the OS, it focus on Lanuage its self.

2. Algorithm and Data structures. They are important but, the book does not cover these two area, although it has code to implement fast search. Still the focus is the language itself.

3. The way to learn a lanuage, is to write programs. This book contains a lot of asignments, to modify code, or write code with what it present. We are be certain when we write programs with the language.

4. The auther write the book on the stand of the user point, so it is not top down, but on the same level as the user.

Saturday, August 18, 2007

slackware 12 - a little update on thinkpad r61i

The past week digging into thinkpad is not easy for me --

The first problem I met is the audio did not work, I don't know when it started to mute, after do a lot of research, even reinstall the whole system--. Right now the audio works on my thinkpad, but thanks people in the internet, they have got the same trouble, I did know the mixer problem, and only volume up button works, the mute and volume down button don't work.

And I build the latest linux kernel 2.6.22.3, right now I am using the default IEEE80211 module provided by the kernel, the 1.2.17 version seems can not build for the new kernel. And there is still no ipw3945 in this kernel. But my ipw3945 -1.2.1 works with the module, so I am OK using the wireless.

Still in learning slackware 12 and my new laptop.

Thursday, August 16, 2007

gdb on arm-linux

It is a little different to debug an application on arm-linux.

First, start gdbserver from the device, 3230 is any port number that is not used by the network.

gdbserver localhost:3230 ./helloworld


Second, start arm-linux-debug from the host,

arm-linux-gdb ./helloworld
target remote 10.10.10.20:3230
b main
c

Here b identify set break point, and c identify continue, they are gdb commands.

Right now, I am debugging without emacs, still hope to configure emacs to support embedded debugging.

Wednesday, August 15, 2007

sed - basic uses

Sed is very useful.

First sample, the most basic use, find a string and replace it.
I can used to to access my bash script.

#!/bin/sed -f
s/nelly/ROCKWYOU/


# at the end of the file
# add comments
$ {
i\
# author mark.chen \
# date 2007 \
# end
}

and my script

#! /bin/bash

export MIDIFILE=/root/Desktop/nelly.mid
export PLAYER=/usr/local/RealPlayer

$PLAYER/realplay $MIDIFILE



Second, "dos2unix.sed". It may not perfect, I am still learning sed, but I used it remove "^M" or 0x0d from code. The use is "dos2unix.sed a.c > a_2.c", if the output is the same as the input, it may not work, so make sure the output is different

#! /bin/sed -f

s/\r//g
s/$//g

Tuesday, August 14, 2007

make - patsubst

Qestions: OBJS_GROUP and OBJS_GROUP2 are the same?

Here is the Makefile:

SRCS_FOO = foo1.cpp foo2.cpp
SRCS_BAR = bar.s
SRCS_GRP = $(SRCS_FOO) $(SRCS_BAR)
OBJS_FOO = $(SRCS_FOO:.cpp=.o)
OBJS_BAR = $(SRCS_BAR:.s=.o)
OBJS_GROUP = $(patsubst %.s,%.o, $(patsubst %.cpp,%.o, $(SRCS_GRP)))
OBJS_GROUP2 = $(patsubst %.s, %.o, $(SRCS_GRP:.cpp=.o))
debug:
@echo "objs list..." $(OBJS_GROUP)
@echo "objs list..." $(OBJS_GROUP2)
@echo "foos list..." $(OBJS_FOO)
@echo "bars list..." $(OBJS_BAR)


Answer: both generates "foo1.o foo2.o bar.o".

Saturday, August 11, 2007

Lenovo thinkpad R61i - install and configuration with slackware 12.0

- install slackware 12

Simple, I still do the same as I first use slackware 3 in 1996, I can not remember the exact year.

- configuration

audio : alsamixer and alsactl store
video : use default xorg.conf change resolution to 1280x800
user account: adduser markc
choose windows: kde as default.

also, to build linux kernel and I need...

# chown -R markc:root /usr/src


- setup wireless with ipw3945

That's a big story, I spent several night on it experience failure and success, another failure and another success. I am using linux kernel 2.6.21-5 from slackware 12.0 with the following packages:


ieee80211-1.2.17
ipw3945-1.2.1
ipw3945-ucode-1.14.2
ipw3945d-1.7.22

They are important, because it fails with ieee80211-1.2.18 and ipw3945-1.2.2.

1 with ieee80211, "tar, make, make install"
2 with ipw3945, "tar, make, make install, depmod"
3 with ipw3945-ucode, copy the ucode file to /lib/firmware.
4 with ipw3945d, copy ipw3945d at x86 to /sbin
5 Now goto ipw3945: do ./load debug=0,
or, modprobe ipw3945 if there is no ieee80211 and ipw3945 installed.
6 "/sbin/ipw3945d &"
7 "wpa_supplicant -Dwext -ieth1 -c /etc/wpa_supplicant.config -B"
8 dhcpcd eth1
9 ping www.google.com, happly to get successful response
10 set startup script


modprobe ipw3945
/sbin/ipw3945d

in my /etc/rc.d/rc.local

and /etc/rc.d/rc.inet1.conf

use_dhcp[1] to "yes" instead of use_dhcp[0]


- setup ACPI

The default ACPI not works on the thinkpad, the only way to fix it is to rebuild the kernel.
Here is my current setting

#
# ACPI (Advanced Configuration and Power Interface) Support
#
CONFIG_ACPI=y
CONFIG_ACPI_PROCFS=y
CONFIG_ACPI_AC=y
CONFIG_ACPI_BATTERY=y
CONFIG_ACPI_BUTTON=y
CONFIG_ACPI_VIDEO=m
CONFIG_ACPI_FAN=y
CONFIG_ACPI_DOCK=y
CONFIG_ACPI_BAY=m
CONFIG_ACPI_PROCESSOR=y
CONFIG_ACPI_THERMAL=y
# CONFIG_ACPI_ASUS is not set
CONFIG_ACPI_IBM=y
CONFIG_ACPI_IBM_BAY=y
# CONFIG_ACPI_TOSHIBA is not set
CONFIG_ACPI_BLACKLIST_YEAR=0
# CONFIG_ACPI_DEBUG is not set
CONFIG_ACPI_EC=y
CONFIG_ACPI_POWER=y
CONFIG_ACPI_SYSTEM=y
CONFIG_X86_PM_TIMER=y
CONFIG_ACPI_CONTAINER=m
# CONFIG_ACPI_SBS is not set


After rebuild the kernel, ACPI at last works, but I found the following problem.

~ # dmesg | grep 3945
ipw3945: Intel(R) PRO/Wireless 3945 Network Connection driver for Linux, 1.2.1d
ipw3945: Copyright(c) 2003-2006 Intel Corporation
ipw3945: Detected Intel PRO/Wireless 3945ABG Network Connection
ipw3945: ipw3945.ucode load failed: Reason -2
ipw3945: Could not read microcode: -2
ipw3945: probe of 0000:03:00.0 failed with error -2
~ #


So I still prefer to use my download wireless packages that I have configured before, so I did an another reconfiguration on the wireless thing to make it work. BTW, in building linux kernel, the wireless device driver may have failures, I fix it by reconfigure linux kernel, such as don't include ipw2200 etc. Build a linux kernel is most easy thing for a programmer.

At last the main things works: video card with 1200x800mode, ACPI can show battery usage, and wireless network, audio can play music.

I did not test the other things such as print, fax, cd burner, usb connection, etc.

At last, I want to thank slackware, it is a wonderful distribution, not like ubuntu and fedora they have so many people and efforts on them but still not excellent, while slackware is just simply make things done.

Wednesday, August 8, 2007

Lenovo thinkpad R61i - slackware 12.0

My new laptop was arrived to my home yesterday. I bought it from compusmart, and it is about a thousand bucks but with great performance. Detail information can be found here.

I decided to give Slackware 12 the first try, I have to say slackware runs great on my new laptop. eth0, audio and video (vesa) works very well. For audio, I have to use alsamixer to change the mute settings, and use "alsactl store" to save, the same as my old 130 thinkpad. And for video, the default vesa works on 1024x768 mode, I am quite happy with that, ctrl-atl-backsapce works, I feel I can use the laptop do things.

I also tried to configure wireless network and download the drivers to build, and tried "X -configure" for 1280x800 mode, but there is some problem, for the wireless, maybe I have to rebuild the kernel. and for the video card, the ctrl-alt-backspace still don't work.

Wednesday, August 1, 2007

slackware 12.0 - siliconmotion driver downgrade

Yesterday, I went back to download the old version of siliconmotion driver 1.3.1 and built it with my current xorg version for a test. The mouse pointer shows ok -- not the 3 mouse pointer. But it still failed on ctl-alt-backspace. Where is the problem?