Nios II: The initramfs creation procedure

From Crashcourse Wiki

Jump to: navigation, search

As mentioned on an earlier wiki page, the default initramfs image embedded in the bootable kernel image can be examined with:

$ gunzip -c linux-2.6.x/usr/initramfs_data.cpio.gz | cpio -itv

The final contents of the initramfs are based on this line from the kernel configuration file vendors/Altera/nios2nommu/config.linux-2.6.x:

CONFIG_INITRAMFS_SOURCE="../romfs ../vendors/Altera/nios2nommu/romfs_list"

The contents of the romfs_list file should be fairly self-explanatory, while the top-level romfs/ directory is constructed in stages via the top-level romfs.subdirs target, which recursively invokes the romfs target in a small number of subdirectories.

First, there's vendors/Altera/nios2nommu (where ROMFSDIR represents the name of that top-level romfs/ directory being populated):

romfs:
        [ -d $(ROMFSDIR)/$$i ] || mkdir -p $(ROMFSDIR)
        for i in $(ROMFS_DIRS); do \
                [ -d $(ROMFSDIR)/$$i ] || mkdir -p $(ROMFSDIR)/$$i; \
        done
        chmod 777 $(ROMFSDIR)/tmp
        chmod 777 $(ROMFSDIR)/home/ftp
        $(ROMFSINST) ../../Generic/romfs /     <-- note content from here
        $(ROMFSINST) -s /bin/init /init
        $(ROMFSINST) /etc/inittab
        $(ROMFSINST) /etc/rc
        $(ROMFSINST) /etc/TZ
        $(ROMFSINST) /etc/passwd
        $(ROMFSINST) /etc/group
        $(ROMFSINST) /etc/hosts
        $(ROMFSINST) /etc/host.conf
        $(ROMFSINST) /etc/ftpwelcome
        $(ROMFSINST) /etc/ftpusers
        $(ROMFSINST) /etc/boa.conf
        $(ROMFSINST) /etc/mime.types
        $(ROMFSINST) /usr/share/udhcpc/default.script
        chmod 777 $(ROMFSDIR)/usr/share/udhcpc/default.script
        echo "$(VERSIONSTR) -- " `date` > $(ROMFSDIR)/etc/version

The next Makefile consulted is lib/Makefile which, although it has a romfs target, appears to have no effect for Nios II.

Finally, there is user/Makefile, whose romfs target:

romfs:
        for i in $(sort $(dir_y)) $(dir_p) ; do \
                [ ! -d $$i ] || $(MAKE) -C $$i romfs || exit $$? ; \
        done

is responsible for populating the top-level romfs/ directory with the selected, user-level content (things like busybox, boa and so on).

Return to Altera_Nios_II home page.