搜尋此網誌

Linux kernel initramfs with busybox ,boot form uboot How to...

     Since  2.6.13 ,the kernel support initramfs, it reduce generate a image to merge rootfs and kernel.

    Follow is required (Example for kernel image in gzip compression)


  1. Kernel enable

/**/
CONFIG_INITRAMFS_SOURCE=""
CONFIG_INITRAMFS_ROOT_UID=0
CONFIG_INITRAMFS_ROOT_GID=0
# CONFIG_INITRAMFS_COMPRESSION_NONE is not set
CONFIG_INITRAMFS_COMPRESSION_GZIP=y
#CONFIG_INITRAMFS_COMPRESSION_BZIP2 is not set
# CONFIG_INITRAMFS_COMPRESSION_LZMA is not set

/*Here We DON''T need ANY RAMDISK CONFIG*/
# CONFIG_BLK_DEV is not set
# CONFIG_BLK_DEV_RAM is not set
# CONFIG_BLK_DEV_RAM_COUNT is not set
# CONFIG_BLK_DEV_RAM_SIZE is not set


/*IMPORTANT :  using mdev to gen device nodes in run time,else you need create
device nodes at run time or compiler time*/
CONFIG_HOTPLUG=y

   /*Follow is 16 M ram disk to link with kernel for example.*/
CONFIG_CMDLINE="console=ttyS0,115200 rootfstype=ramfs root=01:00  rd_start=0x802d0000 rd_size=16777216"

2. Busybox Config
Nothing special, only we want enable
CONFIG_MDEV=y
CONFIG_FEATURE_MDEV_CONF=y
CONFIG_FEATURE_MDEV_RENAME=y
CONFIG_FEATURE_MDEV_RENAME_REGEXP=y
CONFIG_FEATURE_MDEV_EXEC=y
CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y

    Here ,if your busybox was too old,upgrade the version that support MDEV,
else you need create device nodes at run time or compiler time.

3. Add patch point to easy link rootfs to kernel
Modify
YOUR KERNEL SOURCE ROOT/usr/Makefile
.............................................................................................................
.............................................................................................................
# initramfs_data.o contains the compressed initramfs_data.cpio image.
# The image is included using .incbin, a dependency which is not
# tracked automatically.
$(obj)/initramfs_data$(suffix_y).o: $(obj)/initramfs_data.cpio$(suffix_y) FORCE


#Add follow lines on Makefile on proper position.
export CONFIG_INITRAMFS_ROOT_UID=$(MY_CONFIG_INITRAMFS_ROOT_UID)
export CONFIG_INITRAMFS_ROOT_GID=$(MY_CONFIG_INITRAMFS_ROOT_GID)
export CONFIG_INITRAMFS_SOURCE=$(MY_RAMFS_ROOOT_PATH)
.....................................................................................................
.....................................................................................................
.....................................................................................................
$(deps_initramfs): klibcdirs
# We rebuild initramfs_data.cpio if:
# 1) Any included file is newer then initramfs_data.cpio
# 2) There are changes in which files are included (added or deleted)
# 3) If gen_init_cpio are newer than initramfs_data.cpio
# 4) arguments to gen_initramfs.sh changes
$(obj)/initramfs_data.cpio$(suffix_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
@echo " BUILD RAMFS ----LIST PARAMETER.."
@echo " CONFIG_INITRAMFS_ROOT_UID :"$(CONFIG_INITRAMFS_ROOT_UID)
@echo " CONFIG_INITRAMFS_ROOT_GID :"$(CONFIG_INITRAMFS_ROOT_GID)
@echo -e " CONFIG_INITRAMFS_SOURCE   :\n-------->"$(CONFIG_INITRAMFS_SOURCE)"<-------- font="" n="">
$(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.d
$(call if_changed,initfs)

4. Now only require ADD actual MY_CONFIG_INITRAMFS_ROOT_UID, MY_CONFIG_INITRAMFS_ROOT_GID and MY_RAMFS_ROOOT_PATH on your PROJECT's ROOT MAKEFILE.

and rebuild the kernel image,

    You should get a image call "vmlinux.gz.uImage"

ok, place it to your tftp server root,and enable tftp server now.


5. On uboot prompt,
   set bootargs console=ttyS0,115200 rootfstype=ramfs rdinit=/sbin/init rw mem=64m ; set serverip 192.168.1.12;tftp 0x81000000 vmlinux.gz.uImage;bootm 0x81000000

       the 0x81000000 is safe palce to load our image without u-boot interference.

---------------------------------------------------------------------------------------------------------------------
Starting kernel ...

Booting QCA955x
Linux version 2.6.31--LSDK-10.1.436-svn424 (jackyxue@DNISW2-F14-03) (gcc version 4.3.3 (GCC) ) #2 Fri Nov 1 08:57:34 CST 2013
flash_size passed from bootloader = 16
arg 1: console=ttyS0,115200
arg 2: rootfstype=ramfs
arg 3: rdinit=/sbin/init
arg 4: rw
arg 5: mem=64m
arg 6: mtdparts=ath-nor0:256k(u-boot)ro,64k(u-boot-env),14528k(rootfs),1472k(kernel),64k(art)
CPU revision is: 00019750 (MIPS 74Kc)
cpu apb ddr apb ath_sys_frequency: cpu 720 ddr 600 ahb 200
Determined physical RAM map:
 memory: 02000000 @ 00000000 (usable)
User-defined physical RAM map:
 memory: 04000000 @ 00000000 (usable)
Initrd not found or empty - disabling initrd
Zone PFN ranges:
  Normal   0x00000000 -> 0x00004000
Movable zone start PFN for each node
early_node_map[1] active PFN ranges
    0: 0x00000000 -> 0x00004000
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
Kernel command line: console=ttyS0,115200 rootfstype=ramfs rdinit=/sbin/init rw mem=64m mtdparts=ath-nor0:256k(u-boot)ro,64k(u-boot-env),14528k(rootfs),1472k(kernel),64k(art)
PID hash table entries: 256 (order: 8, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
Writing ErrCtl register=00000000
Readback ErrCtl register=00000000
Memory: 43164k/65536k available (2167k kernel code, 22296k reserved, 533k data, 4540k init, 0k highmem)
NR_IRQS:128
plat_time_init: plat time init done
Console: colour dummy device 80x25
Calibrating delay loop... 359.42 BogoMIPS (lpj=718848)
Mount-cache hash table entries: 512

****************ALLOC***********************
 Packet mem: 8072f860 (0xe00000 bytes)
********************************************

NET: Registered protocol family 16
ath_pcibios_init: bus 0
***** Warning PCIe 0 H/W not found !!!
registering PCI controller with io_map_base unset
ath_pcibios_init: bus 1
***** Warning PCIe 1 H/W not found !!!
registering PCI controller with io_map_base unset
bio: create slab at 0
SCSI subsystem initialized
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
ATH GPIOC major 0
squashfs: version 4.0 (2009/01/31) Phillip Lougher
JFFS2 version 2.2 (NAND) (ZLIB) (RTIME) (c) 2001-2006 Red Hat, Inc.
fuse init (API version 7.12)
msgmni has been set to 84
io scheduler noop registered
io scheduler deadline registered (default)
Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
serial8250.0: ttyS0 at MMIO 0xb8020000 (irq = 19) is a 16550A
console [ttyS0] enabled
loop: module loaded
nbd: registered device at major 43
5 cmdlinepart partitions found on MTD device ath-nor0
Creating 5 MTD partitions on "ath-nor0":
0x000000000000-0x000000040000 : "u-boot"
0x000000040000-0x000000050000 : "u-boot-env"
0x000000050000-0x000000e80000 : "rootfs"
0x000000e80000-0x000000ff0000 : "kernel"
0x000000ff0000-0x000001000000 : "art"
TCP cubic registered
NET: Registered protocol family 10
IPv6 over IPv4 tunneling driver
NET: Registered protocol family 17
802.1Q VLAN Support v1.8 Ben Greear
All bugs added by David S. Miller
arch/mips/atheros/gpio.c (ath_simple_config_init) JUMPSTART_GPIO: 16
athwdt_init: Registering WDT success
ath_otp_init: Registering OTP success
Freeing unused kernel memory: 4540k freed
Please be patient, while OpenWrt loads ...
qca955x_GMAC: Length per segment 1536
955x_GMAC: qca955x_gmac_attach
955x_GMAC: qca955x_set_gmac_caps
Currently in polling mode unit0
mac:0 Registering S17....
qca955x_GMAC: RX TASKLET - Pkts per Intr:160
qca955x_GMAC: Mac address for unit 0:bfff0000
qca955x_GMAC: ff:ff:ff:ff:ff:ff
qca955x_GMAC: Max segments per packet :   1
qca955x_GMAC: Max tx descriptor count :   128
qca955x_GMAC: Max rx descriptor count :   224
qca955x_GMAC: Mac capability flags    :   2002A00
955x_GMAC: qca955x_gmac_attach
955x_GMAC: qca955x_set_gmac_caps
Currently in polling mode unit1
mac:1 Registering S17....
qca955x_GMAC: RX TASKLET - Pkts per Intr:160
qca955x_GMAC: Mac address for unit 1:bfff0006
qca955x_GMAC: ff:ff:ff:ff:ff:ff
qca955x_GMAC: Max segments per packet :   1
qca955x_GMAC: Max tx descriptor count :   128
qca955x_GMAC: Max rx descriptor count :   224
qca955x_GMAC: Mac capability flags    :   2200
955x_GMAC: Serdes PLL is locked value 0x18818116
To set s17 LOOKUP_CTRL_REG registers, flag 0
athr_gmac_ring_alloc Allocated 2048 at 0x82aa3800
sram_desc_cnt 1536,mac Unit 1,Tx r->ring_desc 0xbd000000
athr_gmac_ring_alloc Allocated 3584 at 0x8381e000
sram_desc_cnt 4224,mac Unit 1,Rx r->ring_desc 0xbd000600
955x_GMAC: eth1 in RGMII MODE
Scorpion -----> S17 PHY
athrs17_reg_init_wan done
Setting Drop CRC Errors, Pause Frames and Length Error frames
Setting PHY...
Phy setup Complete
To set s17 LOOKUP_CTRL_REG registers, flag 1
ADDRCONF(NETDEV_UP): eth1: link is not ready
To set s17 LOOKUP_CTRL_REG registers, flag 0
athr_gmac_ring_alloc Allocated 2048 at 0x82aa3000
sram_desc_cnt 5760,mac Unit 0,Tx r->ring_desc 0xbd001080
athr_gmac_ring_alloc Allocated 3584 at 0x82aba000
sram_desc_cnt 8448,mac Unit 0,Rx r->ring_desc 0xbd001680
955x_GMAC: eth0 in SGMII MODE
Scorpion -----> S17 PHY
athrs17_reg_init:done
955x_SGMII::athr_gmac_sgmii_setup  Done
Setting Drop CRC Errors, Pause Frames and Length Error frames
Setting PHY...
Phy setup Complete
To set s17 LOOKUP_CTRL_REG registers, flag 1
ADDRCONF(NETDEV_UP): eth0: link is not ready
device eth0 entered promiscuous mode
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
Port Status 1c000004
ath-ehci ath-ehci.0: ATH EHCI
ath-ehci ath-ehci.0: new USB bus registered, assigned bus number 1
ehci_reset Intialize USB CONTROLLER in host mode: 13
ehci_reset Port Status 1c000000
ath-ehci ath-ehci.0: irq 3, io mem 0x1b000000
ehci_reset Intialize USB CONTROLLER in host mode: 13
ehci_reset Port Status 1c000000
ath-ehci ath-ehci.0: USB 2.0 started, EHCI 1.00
usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb1: Product: ATH EHCI
usb usb1: Manufacturer: Linux 2.6.31--LSDK-10.1.436-svn424 ehci_hcd
usb usb1: SerialNumber: platform
usb usb1: configuration #1 chosen from 1 choice

Enet:0 port2 up
955x_GMAC: enet unit:0 is up...
eth0  SGMII  1000Mbps  full duplex
955x_GMAC: qca955x_soc_gmac_set_mac_duplex
955x_GMAC: qca955x_soc_gmac_set_link Done
955x_GMAC: done cfg2 0x7215 ifctl 0x0 miictrl
ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
br0: port 1(eth0) entering learning state
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
Port Status 1c000000
ath-ehci1 ath-ehci1.1: ATH EHCI
ath-ehci1 ath-ehci1.1: new USB bus registered, assigned bus number 2
ehci_reset Intialize USB CONTROLLER in host mode: 13
ehci_reset Port Status 1c000000
ath-ehci1 ath-ehci1.1: irq 3, io mem 0x1b400000
ehci_reset Intialize USB CONTROLLER in host mode: 13
ehci_reset Port Status 1c000000
ath-ehci1 ath-ehci1.1: USB 2.0 started, EHCI 1.00
usb usb2: New USB device found, idVendor=1d6b, idProduct=0002
usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb2: Product: ATH EHCI
usb usb2: Manufacturer: Linux 2.6.31--LSDK-10.1.436-svn424 ehci_hcd
usb usb2: SerialNumber: platform
usb usb2: configuration #1 chosen from 1 choice
hub 2-0:1.0: USB hub found
hub 2-0:1.0: 1 port detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver cdc_ether



BusyBox v1.15.0 (2013-11-01 08:56:04 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/ # br0: port 1(eth0) entering forwarding state

/ # cat /proc/filesystems
nodev   sysfs
nodev   rootfs
nodev   bdev
nodev   proc
nodev   sockfs
nodev   pipefs
nodev   tmpfs
nodev   devpts
        ext2
        cramfs
        squashfs
nodev   ramfs
        vfat
        msdos
nodev   jffs2
nodev   autofs
nodev   fuse
        fuseblk
nodev   fusectl
    





Openwrt feed a packet not on openwrt default build trunk HOW TO.

   After You had complete build the openwrt firmware from openwrt source ,you may found you need some package but not on your source build root/packages

       Then you figure out the required package is on openwrt svn feeds floder.
Seems now you  need install these packages ,but how ?
          you may just checkout  these packages from SVN feeds ,it should be work but it's too slow.

   So how about follow openwrt's recommand method to feed more packages you need
Just do floow steps:

    go to your Openwrt Build root , mostly it would be trunk/, and must have a file called feeds.conf.default
 or feeds.conf

     Ok ,do follow steps first
      (1.) ./scripts/feeds update -a
      (2.) ./scripts/feeds install -a

        after these steps,your build root floder will have a new floder name feeds,  and it contain ,many
packages...

          now for example add libpam  (Now your path still on build root   trunk/  )
        (1) scripts/feeds install -p libpam
        (2) make  package/feeds/packages/libpam/compile V=99
        (3) make  package/feeds/packages/libpam/install V=99
 
             on  step (3) ,if you see :
           WARNING: skipping libpam -- package not selected
            you may need make menuconfig ARCH=xxx to select the libpam.
            after slect the libpam, repeat the step (3) .

               ok ! done !
       

How to fix cannot find -lc

1. check if libc.a exist but PATH not correct,if so, using symblic link to access.
    try locate libc.a to check libc.a directory.
2. if you can find the libc.a on your linux system, then you need install glib static library.
     For example.  fedora 14 ,yum install install glibc-static
   or get rpm from ftp://ftp.pbone.net/mirror/archive.fedoraproject.org/fedora/linux/updates/14/i386/glibc-static-2.13-2.i686.rpm

      then using rpm -ihv to install this rpm package.

insmod: error inserting 'xxxx.ko' Invalid module format

Insert module ,the driver complain follow message.
insmod drv_tapi.ko
module drv_tapi: relocation overflow
insmod: error inserting 'drv_tapi.ko': -1 Invalid module format


(1) trace to driver source , check Kbuild ,the CFLAGS_MODULE (which is my kernel module build's cflags ,some other linux kernel may be using EXTRA_CFLAGS) 
it indedded lacking " -mlong-calls" .
(2) check the configure option ,find i using wrong configure switch to add driver cflags
(3) using correct configure option to add driver's cflags  , check Kbuild again,
 now it  include the  "-mlong-calls" mips gcc option.

Ok~ bug fixed.


Linux make external module,add extra include path how to.

 1. Just simple to check the linux kernel source ,the module include flag.
example 1 : some kernel source using "EXTRA_FLAGS" to add include path or macro when kernel module build.

example 1 : some kernel source using "CFLAGS_MODULE" to add include path or macro when kernel module build.

  2. Check the kernel driver source , there must have some example to add extra include path example,especially those driver which have multiple floder/path.