[uClinux-dev] about kernal and user program,need your help!]

Greg Ungerer gerg at snapgear.com
Thu Mar 20 08:39:14 EST 2003


Hi Jimmy,

¹Ùá¿Ã÷ <guanzhengming at tsinghua.org.cn> wrote:
>> I am a newbie to uclinux
>> I have a coldfire5272 platform which can run uclinux,my kernel is 
>> uclinux2.0.

Is this an exitsing support 5272 board, or your own design?
Which source code base are you working from?


>> 1.my kernel is compiled to imaged.bin,which is including linux.bin and
>> romfs.img.

What mechanism do you use to combine the linux.bin and romfs.img?
Do you just cat the romfs.img onto the end of the linux.bin?


>The kernel is run from flash,this is my rom.ld

Not according to you linker script below. It has the *(.text)
being linked to run in RAM. You have this section loaded in
flash.


>> MEMORY {
>>     /* make room for VECBASE(0x400) and STACK(0x1000) */
>>     ram    : ORIGIN = 0x0000400, LENGTH = 0x1000000 - 0x0400
>>     /* rom (flash) actually starts at 0xffe00000, but linux can co-exist
>>        with the shipping product as an alternative boot mode. */
>>     rom : ORIGIN = 0xffc00000, LENGTH = 0x400000 }
>>
>> SECTIONS {
>>     
>>        .text :AT(_eromtext){
>>                _stext = . ;
>>                 _sdata = . ;
>>                __data_start = . ;
>>                *(.text)
>>                _etext = ALIGN(0x4) ;
>>                *(.rodata)
>>                *(.data)
>>                _edata = ALIGN(0x4) ;
>>        } > ram
>>
>>     .bss BLOCK(0x4) : {
>>         _sbss = . ;
>>         *(.bss)
>>         *(COMMON)
>>         _ebss = ALIGN(0x4) ;
>>         _end = ALIGN(0x4) ;
>>
>>     } > ram
>>
>>
>>        .romvec :{
>>                _romvec = .;
>>                *(.romvec)
>>     } > rom
>>
>>     .romtext 0xffc00400:{
>>                _eromvec = ALIGN(0x4);
>>                _romtext = ALIGN(0x4);
>>                *(.romtext)
>>                _eromtext = ALIGN(0x4);
>>                __data_rom_start = ALIGN(0x4) ;
>>        } > rom
>>
>> /*        .data : AT(__data_rom_start) {
>>                _sdata = . ;
>>                __data_start = . ;
>>                *(.rodata)
>>                *(.data)
>>                _edata = ALIGN(0x4) ;
>>        } > ram
>> */
>> }
>> it means copy the .text and .data from flash to sdram and run.

A linker script won't copy anything. You need to do any copying
in your startup code. Do you have any code in your crt0_xxx.S
to copy the kernel and clear bss?


>> my first question is how the romfs.img work in the memory?

Depends how/where you put it in your image.bin, and whether
you copy/move it in your kernel startup code. If you are using
the blkmem driver then you need to code it to find the romfs.img
wherever it ends up being in memory or flash.


>> does it controled by kernel ? what is the memory allocation to the romfs?

Initially it will be controlled by how you put together
the image.bin. From here the kernel can do a number of
things. One common method if you have it in flash is
to just change blkmem to find it in flash and use it from
there. Some people copy it to RAM and point blkmem at
that (usually it is stored compressed in flash if you are
using this method).


>> 2.if i have compiled a user program.
>> then how the executable file is loaded into the ram?

The kernel binfmt_flat loader takes care of loading
application code and data into RAM. Although applications
that are compiled in XIP format may not even need their
text section loaded into RAM at all.


>how can i guarantee
>> the user program doesn't crash the kernel and others user program.

You can't. That is life without a full MMU.


>> the code,data,stack of the kernel and user programs,i want know all of 
>> these's
>> map
>> but how can i know?

Excluding the stack your rom.ld linker script describes
exactly what the memory map is. If you want to see the
real numbers for your compiled kernel then use:

     m68k-elf-objdump -headers linux

(Where linux is you ELF format linked kernel).


>> 3,i have look my user.ld.
>> it define MEMORY {
>>        flatmem : ORIGIN = 0x0, LENGTH = 0x100000
>> }
>> .text,.data,.bss,all of these are>flatmem
>> i am doubt,in rom.ld the{ ram    : ORIGIN = 0x0000400, LENGTH = 
>> 0x1000000 -
>> 0x0400}
>> from 0x0000400,there are kernel's code and data,
>> and the user's code and data are placed in 0x0 ,too
>> aren't they crashed?

No. How old is your sources?
We have not had a user.ld for quite a while now...

The linking of applications is a little bit different,
the flat format file is not absolutely linked. If it
contains relocations then these are resolved by the
kernel's libfmt_flat loader and application load time
(they are patched up in RAM).

Regards
Greg


------------------------------------------------------------------------
Greg Ungerer  --  Chief Software Wizard        EMAIL:  gerg at snapgear.com
Snapgear Pty Ltd                               PHONE:    +61 7 3279 1822
825 Stanley St,                                  FAX:    +61 7 3279 1820
Woolloongabba, QLD, 4102, Australia              WEB:   www.SnapGear.com




More information about the uClinux-dev mailing list