News:

Registered a URL and setup a forum as the IPCam stuff really needed its own site vs my irregular blog posts about IPCam hacking at http://www.computersolutions.cn/blog

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - admin

Pages: 1 ... 4 5 [6]
76
uCLinux / uClinux Startup
« on: February 07, 2011, 06:23:46 pm »
I'm sure that people who've been reading this have looked at boot logs from actual devices.
(I hope you have, anyway   ::) )

Lets look at a typical boot log from the ipcamera.

Code: [Select]
Processing image 1 ...
Processing image 2 ...
Processing image 3 ...
Processing image 4 ...
Processing image 5 ...
Processing image 6 ...
Processing image 7 ...
Unzip image 7 ...
Executing image 7 ...
Linux version 2.4.20-uc0 (root@maverick-linux) (gcc version 3.0) #1013 Èý 12ÔÂ 2 13:17:32 CST 2009
Processor: Winbond W90N745 revision 1
Architecture: W90N745
On node 0 totalpages: 4096
zone(0): 0 pages.
zone(1): 4096 pages.
zone(2): 0 pages.
Kernel command line: root=/dev/rom0 rw
Calibrating delay loop... 39.83 BogoMIPS
Memory: 16MB = 16MB total
Memory: 14376KB available (1435K code, 288K data, 40K init)
Dentry cache hash table entries: 2048 (order: 2, 16384 bytes)
Inode cache hash table entries: 1024 (order: 1, 8192 bytes)
Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer-cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 4096 (order: 2, 16384 bytes)
POSIX conformance testing by UNIFIX
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Initializing RT netlink socket
Starting kswapd
Winbond W90N745 Serial driver version 1.0 (2005-08-15) with no serial options enabled
ttyS00 at 0xfff80000 (irq = 9) is a W90N745
Winbond W90N7451 Serial driver version 1.0 (2005-08-15) with no serial options enabled
ttyS00 at 0xfff80100 (irq = 10) is a W90N7451
I2C Bus Driver has been installed successfully.
Blkmem copyright 1998,1999 D. Jeff Dionne
Blkmem copyright 1998 Kenneth Albanowski
Blkmem 1 disk images:
0: 7F0E0000-7F16D3FF [VIRTUAL 7F0E0000-7F16D3FF] (RO)
AM29LV160DB Flash Detected
01 eth0 initial ok!
which:0
PPP generic driver version 2.4.2
Linux video capture interface: v1.00
Winbond Audio Driver v1.0 Initialization successfully.
usb.c: registered new driver hub
add a static ohci host controller device
: USB OHCI at membase 0xfff05000, IRQ 15
hc_alloc_ohci
usb-ohci.c: AMD756 erratum 4 workaround
hc_reset
usb.c: new USB bus registered, assigned bus number 1
hub.c: USB hub found
hub.c: 2 ports detected
usb.c: registered new driver audio
audio.c: v1.0.0:USB Audio Class driver
usb.c: registered new driver serial
usbserial.c: USB Serial Driver core v1.4

_____ ____ _ ____
|__ / _| _ \ / \ / ___|
/ / | | | | | |/ _ \ \___ \
/ /| |_| | |_| / ___ \ ___) |
/____\__, |____/_/ \_\____/
|___/
ZD1211B - version 2.24.0.0
usb.c: registered new driver zd1211b
main_usb.c: VIA Networking Wireless LAN USB Driver 1.13
usb.c: registered new driver vntwusb
usb.c: registered new driver rt73
dvm usb cam driver 0.0.0.0 by Maverick Gao in 2006-8-12
usb.c: registered new driver dvm
dvm usb cam driver 0.1 for sonix288 by Maverick Gao in 2009-4-20
usb.c: registered new driver dvm usb cam driver for sonix288
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP
IP: routing cache hash table of 512 buckets, 4Kbytes
TCP: Hash tables configured (established 1024 bind 2048)
VFS: Mounted root (romfs filesystem) readonly.
Freeing init memory: 40K
BINFMT_FLAT: bad magic/rev (0x74202d74, need 0x4)
BINFMT_FLAT: bad magic/rev (0x74202d74, need 0x4)
Shell invoked to run file: /bin/init
Command: mount -t proc none /proc
Command: mount -t ramfs none /usr
Command: mount -t ramfs none /swap
Command: mount -t ramfs none /var/run
Command: mount -t ramfs none /etc
Command: mount -t ramfs none /flash
Command: mount -t ramfs none /home
Command: camera&
[8]
Command: sh
no support


Why do we see a message about BINFMT_FLAT: bad magic/rev (0x74202d74, need 0x4)?
Good question.

ucLinux expects to have startup files available in that gets decided in our kernel init code. Lets take a look at that quickly.

In our 2.4.x kernel folder, this sits in /home/N745/W90N745-uClinux/uClinux-dist/linux-2.4.x/init/main.c
The code we're looking for is right at the end, and looks like this:

Code: [Select]
tail main.c
if (execute_command)
execve(execute_command,argv_init,envp_init);
execve("/sbin/init",argv_init,envp_init);
execve("/etc/init",argv_init,envp_init);
execve("/bin/init",argv_init,envp_init);
execve("/bin/busybox",argv_busybox,envp_init);
execve("/bin/sh",argv_sh,envp_init);
execve("/bin/sh.exe",argv_sh,envp_init);
panic("No init found.  Try passing init= option to kernel.");
}


We can quickly see that it looks for these startup files in order of preference

Code: [Select]
/sbin/init
/etc/init
/bin/init
/bin/busybox
/bin/sh
/bin/sh.exe

/sbin/init gets run first and should contain the startup scripts for the hardware.
On our system, it could look something similar to this:

#cat /sbin/init

Code: [Select]
#!/bin/sh
mount -t proc none /proc
mount -t ramfs none /usr
mount -t ramfs none /swap
mount -t ramfs none /var
mount -t ramfs none /flash
mount -t ramfs none /home

In the default ipcam build we don't actually have a /sbin/init or /etc/init file.

uClinux then looks at the /bin/init file, and tries to execute that.
Lets look at that in the ipcam build

Code: [Select]
mount -t proc none /proc
mount -t ramfs none /usr
mount -t ramfs none /swap
mount -t ramfs none /var/run
mount -t ramfs none /etc
mount -t ramfs none /flash
mount -t ramfs none /home
camera&
sh

Hmm, our init code looks more like an rc script, and its also missing the mandatory #!/bin/sh at the top so it knows its a shell script.

This still doesn't answer the question of the error message though.
Lets take a look at that error again.

Code: [Select]
BINFMT_FLAT: bad magic/rev (0x74202d74, need 0x4)?

...and lets do a quick hexdump of the first line of the init file.
Code: [Select]
hex init
0x00000000: 6d 6f 75 6e 74 20 2d 74 - 20 70 72 6f 63 20 6e 6f mount -t proc no


If you recall from my other posts, a bFlt header usually consists of bFLT, then a file identifier long.
Heres an example first line from a proper bFLT file

Code: [Select]
hex camera |more
0x00000000: 62 46 4c 54 00 00 00 04 - 00 00 00 40 00 03 4a a0 bFLT.......@..J

Notice anything interesting yet?

Our error tells us it thinks the file version is 0x74 20 2d 74.
Our hexdump says

0x00000000: 6d 6f 75 6e 74 20 2d 74

We have a match.

uClinux is expecting a bFLT binary file, but we have a not quite formatted shell script there instead.
Is it because we're missing the magic identifier  #!/bin/sh ?

Lets take a look.













77
uCLinux / elf compressed files tip
« on: February 07, 2011, 04:19:44 pm »
As our flash is only 2M (4M on some devices), we have quite limited space.
The kernel is roughly 1.1M in size, so we have approximately 900kb free to play with on the smaller sized flash units.

What to do?

Compress things!

Post compile we can compress our elf files using the handy fltheader tools

Code: [Select]
flthdr
No/Too many files provided
usage: flthdr [options] flat-file
       Allows you to change an existing flat file

       -p      : print current settings
       -z      : compressed flat file
       -Z      : un-compressed flat file
       -r      : ram load
       -R      : do not RAM load
       -s size : stack size
       -o file : output-file
                 (default is to modify input file)


Lets have a look at how compression can help with an example

Code: [Select]
# ls -alh ftpd
-rwxr-xr-x 1 root root 109K Feb  7 22:52 ftpd
# file ftpd
ftpd: BFLT executable - version 4 ram

Above, you can see our ftp daemon is 109kb.    If we use the file command to check the filetype, you'll note its not compressed.

Lets see what compression does for us

Code: [Select]
#flthdr -z ftpd
compressing file ...

If we check the filetype, you'll see that its now reported compressed

Code: [Select]
#file ftpd
ftpd: BFLT executable - version 4 ram gzip


So what does that give us?

Code: [Select]
# ls -alh ftpd
-rwxr-xr-x 1 root root 58K Feb  7 22:54 ftpd


Nice, a 51kb reduction in size!

78
If you've been following in the series of posts that no-one reads, you'll see that we have quite an old GCC toolchain for our BSP.

Lots of software that we want to compile really wants a newer toolchain, so what to do?

As a special gift for those of you who bother to actually read these posts, I've obtained an ARM gcc 3.3.4 toolchain (from MCUOS).

Lets download that.

Code: [Select]
su
mkdir /home/downloads
cd /home/downloads
axel http://www.openipcam.com/files/uCLinux/arm_tools_3.3MCUOS.tar.bz2
cd /usr/local
tar -xjvf /home/downloads/arm_tools_3.3MCUOS.tar.bz2

At this point, we should have a copy of the tools in arm_tools_3.3 in /usr/local
Lets rename the existing gcc 3.0 tools to something else, and make this our toolchain of choice.
(We could also change the compiler preference in our config.arch or set a new path, but this is quicker)

Code: [Select]
mv arm_tools arm_tools_3.0
mv arm_tools_3.3 arm_tools

Lets head back to the BSP now

Code: [Select]
cd /home/N745/W90N745-uClinux/uClinux-dist
make clean
make dep
make

If you've followed the above, you'll soon see that gcc borks at the checksum.h file.
The first place we'll look is the ucLinux cvs to see what they think

http://cvs.uclinux.org/cgi-bin/cvsweb.cgi/uClinux-2.4.x/include/asm-armnommu/checksum.h


Ahah!  revision 1.3 says - "the last gcc-3 changes broke the asm so that networking would not work,
get it right this time."

There is a newer revision however, so lets grab that, and see if its good.

Code: [Select]
cd uClinux-2.4.x/include/asm-armnommu
mv checksum.h checksum.h.2.4.20.orig
pico checksum.h

Copy and paste the code from http://cvs.uclinux.org/cgi-bin/cvsweb.cgi/uClinux-2.4.x/include/asm-armnommu/checksum.h?rev=1.4;content-type=text%2Fplain, and save the file.

Lets return to our folder and continue the make.

Code: [Select]
cd /home/N745/W90N745-uClinux/uClinux-dist
make

Sweet, it got further.

What does it complain about now?

Code: [Select]
cc1: error: invalid option `no-fpu'
Lets see what causes that

Code: [Select]
grep "\-mno\-fpu" * -R
linux-2.4.x/arch/armnommu/Makefile:AFLAGS += $(apcs-y) $(proc-y) -mno-fpu
linux-2.4.x/arch/arm/Makefile:AFLAGS +=$(apcs-y) $(arch-y) -mno-fpu -msoft-float

Ok, its the armnommu makefile. (as we don't use the arm architecture)

Lets check the CVS - http://cvs.uclinux.org/cgi-bin/cvsweb.cgi/uClinux-2.4.x/include/asm-armnommu.
Hmm, no Makefile.

Ok, back to google.
Interestingly we get zero results for -mno-fpu
This is obviously as its interpreting the -'s incorrectly.  Silly google.
Search for "-mno-fpu" instead, and we soon see that, its been depreciated, and we should be using -mfpu=softfpa

http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00593.html
... Pass -mfpu=softfpa
   instead of -mno-fpu.

Lets make that change, and recompile.
Isn't life wonderful.

Oh wait, that didn't work either.

Code: [Select]
cc1: error: invalid option `fpu=softfpa'
Note to the gcc people, a fucking manual on when options were depreciated and their replacements would be of help.
Further googling ensues.

Ok, the same Nick now says this

http://readlist.com/lists/gcc.gnu.org/gcc/4/22911.html
There should be no need to recompile libgcc. Just change your build
script to use the -mfpu=softvfp switch instead of -mno-fpu.

Oh joy of joys.  Lets try that then shall we.
Guess what?

Code: [Select]
cc1: error: invalid option `fpu=softvfp'
Arghh.

Lets take a look at the compiler, and double check

Code: [Select]
arm-elf-gcc -dumpspecs
*subtarget_asm_float_spec:
%{mapcs-float:-mfloat} %{msoft-float:-mno-fpu}

Lets try -msoft-float shall we?

Grumble, shitty gcc documentation, grumble etc moan..  :-X

Yay, that worked.  Now onto our next issue.

Code: [Select]
process.c:390: error: parse error before "mov"
Lets just be lazy and copy the newer process.c from the 2.4.36 uClinux current kernel over and see if that will compile.

Woohoo, that works.

Lets continue to our next issue.

Code: [Select]
semaphore.c:221: error: request for member `align' in something not a structure or union
We'll do the same for that..

Run make again..., sweet we got a *lot* further there

Code: [Select]
setup.c:422: error: core_tagtable causes a section type conflict
Lets copy that over, and remake.

So close...

Code: [Select]
setup.c:430: error: `ATAG_INITRD2' undeclared here (not in a function)
Now we're hitting stuff thats been added to the kernel, and isn't in ours.
Lets grep to see where ATAG_INITRD2 was added.

Code: [Select]
grep ATAG_INITRD2 * -R
linux-2.4.x/arch/armnommu/kernel/setup.c:__tagtable(ATAG_INITRD2, parse_tag_initrd2);
linux-2.4.x/arch/arm/kernel/setup.c:__tagtable(ATAG_INITRD2, parse_tag_initrd2);
linux-2.4.x/include/asm-arm/setup.h:#define ATAG_INITRD2 0x54420005
linux-2.4.x/include/asm-armnommu/setup.h:#define ATAG_INITRD2 0x54420005

- Looks like we'll need to add this line in our setup.h file
 #define ATAG_INITRD2   0x54420005

Code: [Select]
pico /home/N745/W90N745-uClinux/uClinux-dist/linux-2.4.x/include/asm-armnommu/setup.h

Add that line under the ATAG_INITRD line.


Recompile, and we're almost there. (Famous last words haha).

Code: [Select]
/usr/local/arm_tools/bin/arm-elf-ld.real: ERROR: irq.o uses hardware FP, whereas kernel.o uses software FP
/usr/local/arm_tools/bin/arm-elf-ld.real: failed to merge target specific data of file irq.o

So, it looks like our edit of the kernel makefile to remove the fp stuff didn't quite work.
Lets just remove that and recheck.

Code: [Select]
make clean
make dep
make

Almost there...


Ok, now we compile fine, but have linker problems.

As we have a different linker available - the 3.3.4 buildchain from the BSP, lets try building with that.
I'll save you the trouble and cut to the chase.

That one also breaks in the same place.

Lets retrace our steps a bit then.

We've made changes to

semaphore.c
setup.c
process.c

and the Makefile

as well as setup.h

Lets try compile using our original 3.0 gcc compiler, and see what happens.
If we roll back the setup.c and process.c files, it will compile.

So, we know that the changes that cause issues are in either of those 2 files.

Lets take a closer look at the files, and see if we can spot why.






79
uCLinux / Compiler Tips for uClinux
« on: February 03, 2011, 11:55:22 am »
uClinux beginners often get frustrated when things don't work.
The documentation is rather outdated, and googling isn't that helpful.


First off, lets look at whats needed for Linux 2.4 compiler wise. (from http://www.linux-mips.org/wiki/Kernel_Build )

The recommended compiler for building Linux 2.4 is gcc 2.95 however the large majority of developers is probably user a more modern GCC. New compilers up to gcc 3.3 have been used successfully to build the kernel and only the latest 2.4 kernels have fixed the issues with gcc 3.4. GCC 4.x can not be used and with Linux 2.4 being in deep freeze mode we generally don't intend to fix such problems but rather recommend to use an older compiler for the kernel.

The latest official GCC 2 is version 2.95.3[1]. GCC 2.96[2] is an unofficial, massively patched version. It provides more efficient optimization with -O2, more strict syntax checking and supports more recent C++ standards. Unfortunately the C++ ABI is not fully compatible[3] with the official 2.95.3 nor 3.0. This is not a concern for building the kernel or modules as those are written in plain C but is a consideration if using a single toolchain for an entire distribution or product.

We have an existing working gcc compiler chain - aka arm_tools which comes with gcc 3.0, this can compile our kernel 2.4.20 version, but its quite old. We also have a gcc 3.3.4 version with the BSP which is supposed to be used to compile the userland (romfs) code.

Ideally we should be using one compiler chain to do it all, but doesn't work straight out of the box.
There is a mailing list for uClinux, but they really need better documentation (which is pretty much what I'm doing here ;) )

So, lets talk about how things compile under uClinux.

If you've been following my previous examples on how to setup a BSP, you'll note that we have 2 compiler environments, and 2 uClinux distributions.

The smarter readers will probably have a question at this point.

How does each distribution know what compiler to use?

Good question  ;)

uClinux has a number of folders in its structure.
The main one we'll be looking at in this post is the vendors folder.

In both the BSP and the current uClinux we see a list of vendors in the vendors folder.
The vendors folder contains the build instructions for each given architecture and cpu type.

Lets take a look at the BSP folder first, as its cleaner.

Code: [Select]
cd /home/N745/W90N745-uClinux/uClinux-dist/vendors/
minty vendors # ls -al
total 16
drwxr-xr-x  4 root root 4096 May 23  2008 .
drwxr-xr-x 10 root root 4096 May 26  2008 ..
drwxr-xr-x  3 root root 4096 May 23  2008 config
drwxr-xr-x  3 root root 4096 May 23  2008 Winbond

As you see, we have 2 folders.  One for the manufacturer, and one called config.
The config folder is the one we'll look at next

Code: [Select]
cd config/
minty config # ls -al
total 12
drwxr-xr-x 3 root root 4096 May 23  2008 .
drwxr-xr-x 4 root root 4096 May 23  2008 ..
drwxr-xr-x 2 root root 4096 May 23  2008 armnommu
minty config # cd armnommu/
minty armnommu # ls -al
total 24
drwxr-xr-x 2 root root 4096 May 23  2008 .
drwxr-xr-x 3 root root 4096 May 23  2008 ..
-rwxr-xr-x 1 root root 4401 May 23  2008 config.arch
-rwxr-xr-x 1 root root 4198 May 23  2008 config_old.arch

As you can see, we have a subfolder called armnommu.
armnommu refers to our cpu type.

We're running on an ARM7TDMI based chip, which is arm based, and has no mmu (no memory management unit).
Hence the cunningly named armnommu folder

The config.arch file is what tells the compiler how to build for our architecture.
Lets take a look inside

Code: [Select]
cat config.arch

...
MACHINE       = arm
ARCH          = armnommu
CROSS_COMPILE = arm-elf-
CROSS         = $(CROSS_COMPILE)

CC        = $(CROSS_COMPILE)gcc $(CPUFLAGS)

I've excerpted the relevant bits we need to look at.

CROSS_COMPILE = arm-elf-
CROSS = $(CROSS_COMPILE)
CC = $(CROSS_COMPILE)gcc $(CPUFLAGS)

Those 3 lines mean that our compiler call will look something like this

arm-elf-gcc

Essentially we've added a prefix to all the compiler code so it looks for arm-elf-XXX

Lets look at the config.arch for our ucLinux latest.

Code: [Select]
cd /home/uClinux-dist/vendors/config/armnommu
cat config.arch

This is a little more complicated, but it boils down to this.

It looks for these versions of the arm compiler in order of preference:
 arm-linux-20061213-gcc
 arm-linux-20070808-gcc

If it can't find them, it defaults to using this as a prefix.
 arm-linux-

We can find appropriate compiler chains which match those preferences over here -  http://ftp.snapgear.org/pub/snapgear/tools/arm-linux/

Lets take a look at our /usr/local/ folder now, and see whats in there.
If you remember from above, the BSP is looking for arm-elf-XXX filenames
...and the latest uClinux is looking for arm-linux-XXX filenames.

Our path should include the folders for both sets of build utilities.  Lets check.

Code: [Select]
echo $PATH
/usr/local/arm_tools/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

The BSP put our build tools in /usr/local/arm_tools/bin
It should contain arm-elf-xxx files, lets check

Code: [Select]
cd /usr/local/arm_tools/bin
 ls -al
total 23140
drwxr-xr-x 2 root root    4096 May 26  2008 .
drwxrwxr-x 9 root root    4096 May  7  2003 ..
-rwxrwxr-x 1 root root 1043382 Aug  3  2001 arm-elf-addr2line
-rwxrwxr-x 2 root root  943208 Aug  3  2001 arm-elf-ar
-rwxrwxr-x 2 root root 1479964 Aug  3  2001 arm-elf-as
-rwxrwxr-x 2 root root  267769 Aug  8  2001 arm-elf-c++
-rwxrwxr-x 1 root root  195997 Aug  8  2001 arm-elf-c++filt
-rwxrwxr-x 1 root root  267880 Aug  8  2001 arm-elf-cpp
-rwxrwxr-x 1 root root   70692 Aug  7  2003 arm-elf-depmod
-rwxr-xr-x 1 root root  592520 Mar 24  2005 arm-elf-elf2flt
-rwxr-xr-x 1 root root  390012 Mar 24  2005 arm-elf-flthdr
-rwxrwxr-x 2 root root  267769 Aug  8  2001 arm-elf-g++
-rwxrwxr-x 1 root root  272426 Aug  8  2001 arm-elf-g77
-rwxrwxr-x 1 root root  211109 Aug  3  2001 arm-elf-gasp
-rwxrwxr-x 1 root root  264177 Aug  8  2001 arm-elf-gcc
-rwxrwxr-x 1 root root  274191 Aug  8  2001 arm-elf-gcj
-rwxr-xr-x 1 root root    4746 Mar 24  2005 arm-elf-ld
-rwxrwxr-x 1 root root 1416491 Nov  1  2001 arm-elf-ld.real
-rwxrwxr-x 2 root root 1037487 Aug  3  2001 arm-elf-nm
-rwxrwxr-x 1 root root 1442773 Aug  3  2001 arm-elf-objcopy
-rwxrwxr-x 1 root root 1573662 Aug  3  2001 arm-elf-objdump
-rwxrwxr-x 2 root root  943207 Aug  3  2001 arm-elf-ranlib
-rwxrwxr-x 1 root root  445502 Aug  3  2001 arm-elf-readelf
-rwxrwxr-x 1 root root  884019 Aug  3  2001 arm-elf-size
-rwxrwxr-x 1 root root  883237 Aug  3  2001 arm-elf-strings
-rwxrwxr-x 2 root root 1442772 Aug  3  2001 arm-elf-strip
-rwxrwxr-x 1 root root 2685109 Nov  1  2001 elf2flt
-rwxrwxr-x 1 root root 1708896 Nov  1  2001 flthdr
-rwxrwxr-x 1 root root   16764 Aug  8  2001 gccbug
-rwxrwxr-x 1 root root  285104 Aug  8  2001 gcjh
-rwxrwxr-x 1 root root  109914 Aug  8  2001 gcov
-rwxrwxr-x 1 root root   19562 Jun 12  2003 genbin
-rwxrwxr-x 1 root root   15568 Feb 10  2003 genromfs
-rwxrwxr-x 1 root root  182342 Aug  8  2001 jar
-rwxrwxr-x 1 root root  305247 Aug  8  2001 jcf-dump
-rwxrwxr-x 1 root root  187871 Aug  8  2001 jv-scan
-rwxrwxr-x 1 root root    2006 Nov  2  2001 ld-elf2flt
-rwxrwxr-x 1 root root 1416491 Nov  1  2001 ld-elf2flt.real
-rwxrwxr-x 1 root root   16708 Feb 19  2003 makeimg
-rwxrwxr-x 1 root root   23279 Jun 18  2003 mkrom
-rwxrwxr-x 1 root root   19594 Oct 31  2003 mkupgfw


Yup, that looks good.

Now lets check our other folder (/usr/local/bin)

Code: [Select]
cd /usr/local/bin
minty bin # ls -al
total 9228
drwxr-xr-x  2 root root    4096 Feb  3 15:53 .
drwxrwsr-x 15 root staff   4096 Feb  3 17:25 ..
-rwxr-xr-x  1 root root    4275 Oct  4 16:30 apt
-rwxr-xr-x  1 root root  433320 Jun 23  2008 arm-linux-addr2line
-rwxr-xr-x  1 root root    1022 Jun 20  2008 arm-linux-addr2name.awk
-rwxr-xr-x  2 root root  454852 Jun 23  2008 arm-linux-ar
-rwxr-xr-x  2 root root  787160 Jun 23  2008 arm-linux-as
-rwxr-xr-x  2 root root  178660 Jun 23  2008 arm-linux-c++
-rwxr-xr-x  1 root root  433752 Jun 23  2008 arm-linux-c++filt
-rwxr-xr-x  1 root root  177956 Jun 23  2008 arm-linux-cpp
-rwxr-xr-x  1 root root  430000 Jun 23  2008 arm-linux-elf2flt
-rwxr-xr-x  1 root root   10064 Jun 23  2008 arm-linux-flthdr
-rwxr-xr-x  2 root root  178660 Jun 23  2008 arm-linux-g++
-rwxr-xr-x  2 root root  176612 Jun 23  2008 arm-linux-gcc
-rwxr-xr-x  2 root root  176612 Jun 23  2008 arm-linux-gcc-4.2.4
-rwxr-xr-x  1 root root   15934 Jun 20  2008 arm-linux-gccbug
-rwxr-xr-x  1 root root  181796 Jun 23  2008 arm-linux-gcj
-rwxr-xr-x  1 root root   77056 Jun 23  2008 arm-linux-gcjh
-rwxr-xr-x  1 root root   22788 Jun 23  2008 arm-linux-gcov
-rwxr-xr-x  1 root root  179780 Jun 23  2008 arm-linux-gfortran
-rwxr-xr-x  1 root root   77060 Jun 23  2008 arm-linux-gjnih
-rwxr-xr-x  1 root root  488840 Jun 23  2008 arm-linux-gprof
-rwxr-xr-x  1 root root   94764 Jun 23  2008 arm-linux-jcf-dump
-rwxr-xr-x  1 root root   68004 Jun 23  2008 arm-linux-jv-scan
-rwxr-xr-x  1 root root    5467 Jun 23  2008 arm-linux-ld
-rwxr-xr-x  2 root root  837008 Jun 23  2008 arm-linux-ld.real
-rwxr-xr-x  2 root root  442952 Jun 23  2008 arm-linux-nm
-rwxr-xr-x  2 root root  571412 Jun 23  2008 arm-linux-objcopy
-rwxr-xr-x  2 root root  685736 Jun 23  2008 arm-linux-objdump
-rwxr-xr-x  2 root root  454884 Jun 23  2008 arm-linux-ranlib
-rwxr-xr-x  1 root root  226000 Jun 23  2008 arm-linux-readelf
-rwxr-xr-x  1 root root  435032 Jun 23  2008 arm-linux-size
-rwxr-xr-x  1 root root  434600 Jun 23  2008 arm-linux-strings
-rwxr-xr-x  2 root root  571412 Jun 23  2008 arm-linux-strip
-rwxr-xr-x  1 root root   27126 May 20  2003 genext2fs
-rwxr-xr-x  1 root root   11384 Jun 26  2008 genromfs

Yup, that also looks good.

Now, lets try to compile the BSP with a newer toolchain, and see what happens.

Code: [Select]
cd /home/N745/W90N745-uClinux/uClinux-dist/vendors/config/armnommu
pico config.arch

Change the CROSS_COMPILE line as follows:

Code: [Select]
CROSS_COMPILE = arm-linux-

Save, and exit

Lets clean up our build folder in preparation for our build.
Code: [Select]
cd /home/N745/W90N745-uClinux/uClinux-dist
make clean
make dep

Finally, lets try to make the build

Code: [Select]
make

What happened?

Lets look at the output
Code: [Select]
make
make ARCH=armnommu CROSS_COMPILE=arm-linux- -C linux-2.4.x  || exit 1
make[1]: Entering directory `/home/N745/W90N745-uClinux/uClinux-dist/linux-2.4.x'
arm-linux-gcc -D__KERNEL__ -I/home/N745/W90N745-uClinux/uClinux-dist/linux-2.4.x/include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -fno-common -pipe -fno-builtin -D__linux__ -D__WB_EVB__ -DNO_MM -mapcs-32 -march=armv4 -mtune=arm7tdmi -mshort-load-bytes   -DKBUILD_BASENAME=main -c -o init/main.o init/main.c
cc1: error: unrecognized command line option "-mapcs-32"
cc1: error: unrecognized command line option "-mshort-load-bytes"
make[1]: *** [init/main.o] Error 1
make[1]: Leaving directory `/home/N745/W90N745-uClinux/uClinux-dist/linux-2.4.x'
make: *** [linux] Error 1

Looks like our newer gcc compiler doesn't support the -mapcs-32 or mshort-load-bytes command.

Lets take a look at the compiler documentation for GCC
http://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/ARM-Options.html

Seems thats only supported in older versions of GCC.

Lets take a look at our original compiler binary.

Code: [Select]
./arm-elf-gcc  -v
Reading specs from ./../lib/gcc-lib/arm-elf/3.0/specs
Configured with: ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib
Thread model: single
gcc version 3.0

Yikes, its ancient - gcc 3.0!

What version of gcc is the newer compiler version?

Code: [Select]
./arm-linux-gcc -v
Using built-in specs.
Target: arm-linux
Configured with: ../configure --target=arm-linux --disable-shared --prefix=/usr/local --with-headers=/home/gerg/src/gnu/arm-linux/linux-2.6.25/include --with-gnu-as --with-gnu-ld --enable-multilib
Thread model: posix
gcc version 4.2.4

Hmm, the newer version is 4.2.4, much newer. (and also not going to work, as its made for the 2.6.x kernel, not 2.4!).  Lets continue anyway and follow through this example.

So, what to do?

Lets go back to the error


Code: [Select]
cc1: error: unrecognized command line option "-mapcs-32"
cc1: error: unrecognized command line option "-mshort-load-bytes"

The gcc compiler doesn't recognize those commands anymore, so lets see what replaced those.

Some googling shows that this can be fixed by using -mabi=apcs-gnu instead of -mapcs-32
and -mshort-load-bytes can fixed by changing it to -malignment-traps

Would be nice if the gcc compiler documentation mentioned this, but, it doesn't.  Sigh.
Now we know that,  lets go find where its adding that and fix it.

Code: [Select]
cd /home/N745/W90N745-uClinux/uClinux-dist/linux-2.4.x
grep mapcs * -R
arch/arm/Makefile:CFLAGS :=$(CFLAGS:-fomit-frame-pointer=-mapcs -mno-sched-prolog)
arch/arm/Makefile:apcs-y :=-mapcs-32
arch/arm/Makefile:apcs-$(CONFIG_CPU_26) :=-mapcs-26 -mcpu=arm3 -Os
arch/armnommu/Makefile:apcs-$(CONFIG_CPU_26) :=-mapcs-26 -mcpu=arm3 -Os
arch/armnommu/Makefile:apcs-$(CONFIG_CPU_32) :=-mapcs-32
drivers/block/doc/Makefile.sa: -Wno-trigraphs -mapcs -fno-strict-aliasing -fno-common -pipe -mapcs-32 \

Looks like its set in a few places.  Lets start with the appropriate one - arch/armnommu/Makefile

Change

apcs-$(CONFIG_CPU_32) so it uses the new compiler command.

Code: [Select]
apcs-$(CONFIG_CPU_32)           :=-mabi=apcs-gnu         

and change
Code: [Select]
CFLAGS          += $(apcs-y) $(arch-y) $(tune-y) -mshort-load-bytes
to

Code: [Select]
CFLAGS          += $(apcs-y) $(arch-y) $(tune-y) $(call cc-option,$(call cc-option,-malignment-traps,))
Save, and try to compile.

You'll get further this time, but it will still break.
However, we have fixed that particular compiler build issue.

Now you have an idea of why things don't work, and what to do to fix them.

If you want to continue with this, the next error is this:

Code: [Select]
init/do_mounts.c:56: error: static declaration of ‘root_device_name’ follows non-static declaration
/home/N745/W90N745-uClinux/uClinux-dist/linux-2.4.x/include/linux/fs.h:1488: error: previous declaration of ‘root_device_name’ was here

...

Google shows this as the issue - http://lkml.org/lkml/2005/6/12/58

So, which file are you going to edit, and why?

I know the answer, but do you?

 8)


80
uCLinux / Setting up a build environment for the N745 BSP
« on: February 03, 2011, 10:47:11 am »
Note that this differs from our instructions on building a dev environment for uClinux.
See here for instructions on that [ http://www.openipcam.com/forum/index.php?topic=6.0 ]

If you've followed our previous examples, you'll note that we should already have a compiler chain and uClinux installed.

We'll be installing another compiler chain for the older 2.4.20 based N745 BSP, so we can compile.

We need both the current uClinux, and the older 2.4.20 version, as we'll need to borrow files from the newer version in order to install certain drivers.

Lets start.

First off, we'll need to download the BSP (Board Support Package) for the CPU.
I've placed a copy of that here: http://www.openipcam.com/files/BSP/W90N745BSP05262008.tar.gz
Open up a terminal window, and enter the following:

Code: [Select]
sudo su
mkdir -p /home/downloads
cd /home/downloads
apt-get install axel
axel http://www.openipcam.com/files/BSP/W90N745BSP05262008.tar.gz

That will download the BSP into /home/downloads.
Lets decompress it now

Code: [Select]
tar -xzvf W90N745BSP05262008.tar.gz
cd W90N745BSP/BSP
tar -xzvf W90N745.tar.gz
cd W90N745_PR
./install.sh

This will decompress the BSP, and start the installer.
We'll need to tell the installer where to put our files (I recommend /home/N745)

Code: [Select]
...
successfully finished installing arm_tools.tar.gz
now begin to install build.tar.gz,TestApps.tar.gz and uClinux-dist.tar.gz
Please enter your absolute path for installing build.tar.gz, TestApps.tar.gz and uClinux-dist.tar.gz:
/home/N745

If you see warnings about usleep not found during the install process, feel free to ignore them.

Assuming you followed my recommendations, we should have a copy of the BSP installed at

/home/N745/W90N745-uClinux/uClinux-dist

In order to make sure that we start from a clean slate, we'll need to clean the BSP build folder (which imho should have been done by Winbond prior to compressing the BSP.)

We'll also need to add the build-tools to our PATH.  The BSP has put them into /usr/local/arm_tools

Lets test to see if they work

Code: [Select]
/usr/local/arm_tools/bin/arm-elf-gcc

If you see this -
 arm-elf-gcc: No input files
It means we're good to go.

If, however you get an error saying something like
bash arm-elf-gcc no such file or directory
You're probably running on a 64bit OS, and haven't installed a 32bit dynamic loader.

If thats the case, install libc6-i386

Code: [Select]
su
apt-get install libc6-i386


Lets continue.

Code: [Select]
cd /home/N745/W90N745-uClinux/uClinux-dist
PATH=/usr/local/arm_tools/bin:$PATH
make clean

In the above, we change to the BSP folder, add the compile tools to our path, and then clean out the old .depend, .o files from our BSP folder, so we have a nice clean slate to start from.
This does not however remove the vendor configuration for the board, so don't worry about that!


For test purposes lets make sure that it compiles (as a just in case test).
Linux 2.4.x requires a make dep prior to compiling, so we need to run that first.

Code: [Select]
make dep
make

You should see a few hundred pages scroll by rather quickly (depending on the speed of your computer!), and if all goes well,we should see a new linux.bin generated in ../image


Code: [Select]
ls -al ../image/
total 2480
drwxr-xr-x 2 root root    4096 May 26  2008 .
drwxr-xr-x 6 root root    4096 Feb  3 17:25 ..
-rwxr-xr-x 1 root root 1065308 Feb  3 17:37 linux.bin
-rw-r--r-- 1 root root  514896 May 26  2008 linux.zip
-rw-r--r-- 1 root root  618496 May 26  2008 romfs.img
-rw-r--r-- 1 root root  326900 May 26  2008 romfs.zip

If you look closely, the compile time for our linux.bin above is newer than the rest of the files, which means its fresh from our make compile..

At this point, we have 2 compiler environments running; one for our BSP, and one for the latest uClinux.

[I've added these instructions to the wiki also]


81
uCLinux / Web Server recommendations for our Firmware
« on: February 03, 2011, 09:53:18 am »
Reading the overview here http://www.cnx-software.com/2010/12/22/http-server-for-uclinux/ for http://www.mathopd.org/, it looks like that Webserver would make a good solution to use in a rebuilt firmware.  Its small, and it does what is needed.  It also runs as a single process (good for small embedded systems like ours).
There are other choices - like litettpd, boa, but this is smaller, and compiles cleanly.


Looks fairly straightforward to implement too.

The cgi implementation part looks especially perfect -

http://www.mathopd.org/wiki?CGI/Example

Some patches here - http://opensource.stobor.net/mathopd/

..and lastly an example of how to use it in a shell script  (as a cgi)

http://linuxgazette.net/155/lg_tips.html


Call this something appropriate like

zipfolder.cgi

Code: [Select]
#!/bin/bash
echo Content-Type: application/zip
echo "Content-Disposition: attachment; filename=files.zip"
echo
zip -9r - *

You'll also need to ensure zip is compiled in, for that example, but it shows what can be done easily.



82
uCLinux / Setting up a build environment
« on: February 03, 2011, 04:28:32 am »
While the uClinux developers have done a great job of making an updated embedded OS based on the Linux kernel, they haven't done such a great job on documenting it.

I'm going to assume a debian based OS for the following.

Suggest download a prebuilt Debian GUI based OS if you aren't familiar with Debian, Linux Mint is a good clean version that has its heart in the right place.

Download that here: http://www.linuxmint.com/download_lmde.php

Assuming you now have that installed, we can continue.

In order to compile uClinux, we first need to install a cross compiler.
Unfortunately there are many different incompatible arm gcc cross-compilers, so we need one that works with our uClinux version.  Unfortunately this seems to be a bit trial and error, which is sucky.


The most current arm cross compiler's are located here -
http://ftp.snapgear.org/pub/snapgear/tools/arm-linux/arm-linux-tools-20080623.tar.gz
and here
http://www.codesourcery.com/sgpp/lite/arm/portal/package7795/public/arm-uclinuxeabi/arm-2010.09-58-arm-uclinuxeabi.bin


So, our first step is to download one, and install.
As this is a large file, we're going to use a download accelerator called Axel.
Open up a terminal window, and type in the following


Code: [Select]
sudo su
mkdir /home/downloads
cd /home/downloads
apt-get install axel
axel http://ftp.snapgear.org/pub/snapgear/tools/arm-linux/arm-linux-tools-20080623.tar.gz

sudo su - tells the computer that we want to run as root user.  We need to do this as the tools require us to be root to install.
mkdir /home/downloads, cd /home/downloads - we make our download folder, and change into it.
apt-get install axel - we install axel (our download accelerator).
Lastly, we download the ucLinux compiler tools.  This will take a while as its quite large.

Go have a cup of coffee and come back  :D

As uClinux has changed the way they do their xwindows configuration, we also need to install some extra libraries in our OS to cater for this.  Install tk, ncurses, and libglade2 with the following command.

Code: [Select]
apt-get install tk  libglade2-dev ncurses-dev
This will also add a whole bunch of other prerequisites to be downloaded.  Say yes, and go get another coffee while this all downloads and installs.

Lastly, we need the most current uClinux files.
Go here - http://sourceforge.net/projects/uclinux/files/  and copy the link for the latest version.
At time of writing, this was http://sourceforge.net/projects/uclinux/files/uClinux%20Stable/dist-20090618/uClinux-dist-20101026.tar.bz2/download 
Copy the link, and click back in the terminal window.

Code: [Select]
axel http://downloads.sourceforge.net/project/uclinux/uClinux%20Stable/dist-20090618/uClinux-dist-20101026.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fuclinux%2Ffiles%2F&ts=1296724513&use_mirror=ufpr
Quote
Note:  You can also get the CVS version of uClinux, but I recommend compiling from the Stable edition.

If you've been following, so far we should have the ARM compiler tools, uClinux distribution in our /home/downloads folder.  We've also installed a few required bits and pieces into our OS.

Our next step is to start installing..
Just to be safe, I make sure that we're root, and in the correct folder prior to starting (the arm-linux-tools expects to be run from the root folder)

Code: [Select]
sudo su
cd /
tar -xzvf /home/downloads/arm-linux-tools-20080623.tar.gz

You'll see a whole lot of lines flying by the terminal window, and eventually it will complete.
This will have installed the arm compiler tools into /usr/local/bin for you.

Next, we'll need to decompress the uClinux distribution somewhere appropriate.  I use /home/uClinux-dist, so lets use that.

Code: [Select]
cd /home
tar -xjvf downloads/uClinux-dist-20101026.tar.bz2

You should have a folder under home called uClinux-dist now.
Lets change into that folder.

Code: [Select]
cd uClinux-dist
ls -al

You should see something similar to the following:

minty uClinux-dist # ls -al
total 152
drwxrwxr-x  17  500  500  4096 Feb  3 13:33 .
drwxr-xr-x   6 root root  4096 Feb  3 13:33 ..
drwxrwxr-x   2  500  500  4096 Oct 26 12:02 bin
drwxrwxr-x   3  500  500  4096 Oct 26 12:02 config
-rw-rw-r--   1  500  500 18007 Nov 22  1999 COPYING
drwxrwxr-x   3  500  500  4096 Oct 26 11:59 Documentation
drwxrwxr-x  11  500  500  4096 Oct 26 12:00 freeswan
drwxrwxr-x   2  500  500  4096 Oct 26 12:00 glibc
drwxrwxr-x   2  500  500  4096 Oct 26 12:01 include
-rw-r--r--   1 root root 26903 Feb  3 13:00 Kconfig
drwxrwxr-x  51  500  500  4096 Oct 26 12:02 lib
drwxrwxr-x  15  500  500  4096 Oct 26 11:59 linux-2.0.x
drwxrwxr-x  16  500  500  4096 Oct 26 11:59 linux-2.4.x
drwxrwxr-x  23  500  500  4096 Oct 26 12:02 linux-2.6.x
-rw-rw-r--   1  500  500 15412 Oct 21 08:28 Makefile
drwxrwxr-x  18  500  500  4096 Oct 26 12:00 openswan
-rw-rw-r--   1  500  500  5613 Apr 10  2008 README
-rw-rw-r--   1  500  500  1743 Jan 21  2004 SOURCE
drwxrwxr-x   8  500  500  4096 Oct 26 12:01 tools
drwxrwxr-x  17  500  500  4096 Oct 26 12:00 uClibc
drwxrwxr-x 283  500  500 12288 Oct 26 12:02 user
drwxrwxr-x  71  500  500  4096 Oct 26 12:02 vendors


Lets check if everything is setup.

Code: [Select]
make xconfig

You should see a few lines of compiler code, and a new window popup on the desktop, saying uClinux Distribution.
If you do, well done, our environment is setup.

Take a look at the configuration options in the window to see whats available (but don't save any changes yet!).

If you don't see a window popup, check you've added the tk and libglade2 libraries, and have downloaded all the items above.  The terminal window should show you what went wrong.  If you're having issues, reply, and I'll see if I can help.

Assuming all went well though, we now have a build environment setup.

Well done!

83
Firmware / Firmware Recovery Tool
« on: February 02, 2011, 11:14:52 am »
Ramon van Bruggen's firmware download tool for IP-Cam's with uBoot
This is a Windows Tool, and requires .Net

Recovery Tool /files/FoscamCloneRecovery.zip

.NET 4.0 Installer /files/dotNetFx40_Full_x86_x64.exe

Ramon's site http://blog.morrison.nl/

Pages: 1 ... 4 5 [6]