News:

Re-organized the forum to more cleanly delineate the development section, as the end user support side appears to have taken a life of its own!

Author Topic: uClinux Startup  (Read 5047 times)

  • No avatar
  • *****
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.












« Last Edit: February 08, 2011, 02:31:09 am by admin »