[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [microblaze-uclinux] bootstrap code



On Tue, 11 May 2004, John Williams wrote:
> The critical one is the same problem that most uClinux systems face with
> elf bootloaders.  That is, the romfs filesystem is copied into the
> kernel elf image (post-linking) with the following bit of shell script:
>
>          mb-objcopy --add-section=.romfs=$(ROMFSIMG) \
>            --adjust-section-vma=.romfs=$${ADDR} --no-adjust-warnings \
>            --set-section-flags=.romfs=alloc,load,data   \
>            $(ROOTDIR)/$(LINUXDIR)/linux $(ELFIMAGE)
>
> I've never got a straight answer, but it's either a bug in objcopy, or a
> "bug" (feature?) in elf loaders, that this new romfs section is not
> allocated into a segment, and most elf loaders don't "see it".
exactly: the problem is that the program heders does not get updated, so
the elf loader does not even know about the romfs. i think it should not
be considered as a bug in the elf loader: an elf loader should do what the
program headers say.

nevertheless you can solve the problem by creating correct program
headers. surely there is a way to do it in post-link, but i had no time
to create a linker script for that, so i modified the kernel
link script instead.

you just have to wrap the romfs into elf format and link this elf with the
kernel using the appropiate linker sript.

1, to wrap the romfs image:

	echo | mb-as -o romfs.elf -
	mb-objcopy --add-section=.romfs=romfs.img \
		--set-section-flags=.romfs=alloc,load,data --only-section=.romfs romfs.elf


this will crate romfs.elf with one lodable segment, named ".romfs".


2, now you have to modify the template linker script
linux-2.4.x/arch/microblaze/mbvanilla.ld . add a new section at the end of
file, right after the .bss section:


        .romfs : {
                _myromfs_start = . ;
                        *(.romfs)
                _myromfs_end = . ;
                _end = . ;
        } > OPB

and delete linux-2.4.x/linux.ld so it will get regenerated.


3, you also have to add romfs.elf to the object files that make up the
kernel. in my case:

mb-ld -T linux.ld --defsym _STACK_SIZE=0x00  arch/microblaze/kernel/head.o
	init/main.o init/version.o init/do_mounts.o \
        --start-group \
        arch/microblaze/kernel/kernel.o kernel/kernel.o mmnommu/mmnommu.o \
	fs/fs.o ipc/ipc.o arch/microblaze/xilinx_ocp/xilinx_ocp.o \
        drivers/char/char.o drivers/block/block.o drivers/misc/misc.o \
	drivers/net/net.o drivers/mtd/mtdlink.o drivers/media/media.o \
        net/network.o \
        /nfsroot/development/20040330-fpga-project-2/uClinux-dist/linux-2.4.x/lib/lib.a \
	arch/microblaze/lib/lib.a  \
        --end-group \
        /home/mazsi/fpga-project-2/uClinux-dist/images/romfs.elf \
        -o linux

now you should mb-strip the resulting kernel (unless you have an extra
9 MB of flash for the debug symbols.. :), and flash it to one of the
partitions.

i'm sorry for not providing you with nice patches instead of this lousy
semi-tutorial. :(




with some more tweaking on the linking you can remove the entire
mach_early_init(): this function copies the romfs into the right
place (solved above), zeroes out the bss and sbss data sections (done by
the loader code if a bug i left in it gets corrected :), and sets up the
reset, interrupt, etc vectors at 0x00000000 (you just have to modify the
linker script to put .intv section into LMB instead of OPB). some might
want to play around with the tricks mentioned in the head of mbvanilla.ld
too. :)




> The "nice-to-have" would be to reduce the total size of the bootloader
> down to 2048 bytes, so we can squeeze it into a nice small BRAM block.
i think if all of the unused code and the long message strings get removed
it will surely fit into 2k.



-- 
mazsi

----------------------------------------------------------------
Strawberry fields forever!  Jozsef.Imrek@strawberry.dnsalias.org
----------------------------------------------------------------
___________________________
microblaze-uclinux mailing list
microblaze-uclinux@itee.uq.edu.au
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive : http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/