Ynt: Bu scatter dosyasi kafayi yedirtecek.

Başlatan z, 21 Haziran 2014, 22:18:37

z

Sorunumu cozdum ama olmasi gerektigi gibi değil.

Once ne yapmak istedigimi aciklayayim.

Romun 0x0800.0000 ...... 0x0800.1000 alanina program ve datalarimi yazmak istiyorum.

Romun 0x0800.1000 ...... 0x0800.2000 alanina tablo koymak istiyorum.

Bunu tek proje icinde yapamiyorum.

Bunu ancak

1. projede

Romun 0x0800.0000 ...... 0x0800.1000 alanina program ve datalarimi yaziyorum.

2. projede

Romun 0x0800.1000 ...... 0x0800.2000 alanina tablo koyuyorum.

Ancak bu sekilde yaparsam yani projeleri ayri ayri derler ve ayri ayri roma yuklersem istedigim oluyor.

Fakat bu extra bir iscilik.

Tek projede yaparsam L6329W uyarisi aliyorum ve romun sadece 0x0800.0000 ...... 0x0800.1000 alanina veriler yerlesiyor.
Romun 0x0800.1000 ...... 0x0800.2000 alani icin tablo verileri uretilmiyor.

Fakat;

Romun 0x0800.0000 ...... 0x0800.1000 alanina yerlesecek kodlar icin first tanimi yapmazsam yani kodlarin hangi alandan calisacagini vermezsem bu durumda istedigim oluyor.
Ancak bu durumda da debug etmede zorluk cikiyor.


Tek projede bu istedigimi nasil yaparim?

Iscilik cok diyorum cunku;

Sirf asil amacima ulasmak  icin 3 proje olusturuyorum.

1. proje 0x0800.0000 adresine kodlarimi yerlestiriyor.
2. proje 0x0800.1000 adresine tablo yerlestiriyor.
3. proje 0x0800.2000 adresine bir baska program kodu yerlestiriyor.

Benim 1. ve 2. projeyi tek proje seklinde yazmam lazim.

Scatter ve basit bir kod ornegi lazim.


mesaj birleştirme:: 21 Haziran 2014, 20:30:38

L6329W hatasi icin

All sections matching this pattern have been removed from the image because they were unused.

Gibi bir aciklama yapilmis.

Halbuki

            AREA     Reset, CODE, READONLY
....
....

            AREA     Tablo, CODE, READONLY

....
....

seklinde bolumleri tanimliyorum. Scatter dosyamda Reset ve Tablo alanlarini da ayri ayri tanimlamisim.
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

ErsinErce

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0474c/BABDJCAA.html

örnekleriyle açıklamalar mevcut hocam

scatter kullanarak yada kullanmadan 2 yöntemde açıklanmış

Alıntı YapPlacing functions and data at specific addresses
Normally, the compiler produces RO, RW and ZI sections from a single source file. These regions contain all the code and data from the source file. To place a single function or data item at a fixed address, you must enable the linker to process the function or data separately from the rest of the input files.
The linker has two methods that enable you to place a section at a specific address:
You can create a scatter file that defines an execution region at the required address with a section description that selects only one section.
For a specially-named section the linker can get the placement address from the section name. These specially-named sections are called __at sections.
To place a function or variable at a specific address it must be placed in its own section. There are several ways to do this:
Place the function or data item in its own source file.
Use __attribute__((at(address))) to place variables in a separate section at a specific address.
Use __attribute__((section("name"))) to place functions and variables in a named section.
Use the AREA directive from assembly language. In assembly code, the smallest locatable unit is an AREA.
Use the --split_sections compiler option to generate one ELF section for each function in the source file.
This option results in a small increase in code size for some functions because it reduces the potential for sharing addresses, data, and string literals between functions. However, this can help to reduce the final image size overall by enabling the linker to remove unused functions when you specify armlink --remove.
Show/hideExample of placing a variable at a specific address without scatter-loading
This example shows how to modify your source code to place code and data at specific addresses, and does not require a scatter file:
Create the source file main.c containing the following code:
#include <stdio.h>

extern int sqr(int n1);
int gSquared __attribute__((at(0x5000)));  // Place at 0x5000

int main()
{
    gSquared=sqr(3);
    printf("Value squared is: %d\n", gSquared);
}
Create the source file function.c containing the following code:
int sqr(int n1)
{
    return n1*n1;
}
Compile and link the sources:
armcc -c -g function.c
armcc -c -g main.c
armlink --map function.o main.o -o squared.axf
The --map option displays the memory map of the image. Also, --autoat is the default.
In this example, __attribute__((at(0x5000))) specifies that the global variable gSquared is to be placed at the absolute address 0x20000. gSquared is placed in the execution region ER$$.ARM.__AT_0x00005000 and load region LR$$.ARM.__AT_0x00005000.
The memory map shows:
...
  Load Region LR$$.ARM.__AT_0x00005000 (Base: 0x00005000, Size: 0x00000000, Max: 0x00000004, ABSOLUTE)

    Execution Region ER$$.ARM.__AT_0x00005000 (Base: 0x00005000, Size: 0x00000004, Max: 0x00000004, ABSOLUTE, UNINIT)

    Base Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x00005000   0x00000004   Zero   RW           15    .ARM.__AT_0x00005000  main.o
Show/hideExample of placing a variable in a named section with scatter-loading
This example shows how to modify your source code to place code and data in a specific section using a scatter file:
Create the source file main.c containing the following code:
#include <stdio.h>

extern int sqr(int n1);
int gSquared __attribute__((section("foo")));  // Place in section foo

int main()
{
    gSquared=sqr(3);
    printf("Value squared is: %d\n", gSquared);
}
Create the source file function.c containing the following code:
int sqr(int n1)
{
    return n1*n1;
}

Create the scatter file scatter.scat containing the following load region:
LR1 0x0000 0x20000
{
    ER1 0x0 0x2000
    {
        *(+RO)                      ; rest of code and read-only data
    }
    ER2 0x8000 0x2000
    {
        main.o
    }
    ER3 0x10000 0x2000
    {
        function.o
        *(foo)                      ; Place gSquared in ER3
    }
    RAM 0x200000 (0x1FF00-0x2000)   ; RW & ZI data to be placed at 0x200000
    {
        *(+RW, +ZI)
    }
    ARM_LIB_STACK 0x800000 EMPTY -0x10000
    {
    }
    ARM_LIB_HEAP  +0 EMPTY 0x10000
    {
    }
}
The ARM_LIB_STACK and ARM_LIB_HEAP regions are required because the program is being linked with the semihosting libraries.
Compile and link the sources:
armcc -c -g function.c
armcc -c -g main.c
armlink --map --scatter=scatter.scat function.o main.o -o squared.axf
The --map option displays the memory map of the image. Also, --autoat is the default.
In this example, __attribute__((section("foo"))) specifies that the global variable gSquared is to be placed in a section called foo. The scatter file specifies that the section foo is to be placed in the ER3 execution region.
The memory map shows:
  Load Region LR1 (Base: 0x00000000, Size: 0x00001778, Max: 0x00020000, ABSOLUTE)
...
    Execution Region ER3 (Base: 0x00010000, Size: 0x00000004, Max: 0x00002000, ABSOLUTE)

    Base Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x00010000   0x00000004   Data   RW           15    foo                 main.o
...
Note
If you omit *(foo) from the scatter file, the section is placed in the region of the same type. That is RAM in this example.
Show/hideExample of placing a variable at a specific address with scatter-loading
This example shows how to modify your source code to place code and data at a specific address using a scatter file:
Create the source file main.c containing the following code:
#include <stdio.h>

extern int sqr(int n1);

// Place at address 0x10000
const int gValue __attribute__((section(".ARM.__at_0x10000"))) = 3;

int main()
{
    int squared;
    squared=sqr(gValue);
    printf("Value squared is: %d\n", squared);
}
Create the source file function.c containing the following code:
int sqr(int n1)
{
    return n1*n1;
}
Create the scatter file scatter.scat containing the following load region:
LR1 0x0
{
    ER1 0x0
    {
        *(+RO)                      ; rest of code and read-only data
    }
    ER2 +0
    {
        function.o
        *(.ARM.__at_0x10000)         ; Place gValue at 0x10000
    }
    RAM 0x200000 (0x1FF00-0x2000)   ; RW & ZI data to be placed at 0x200000
    {
        *(+RW, +ZI)
    }
    ARM_LIB_STACK 0x800000 EMPTY -0x10000
    {
    }
    ARM_LIB_HEAP  +0 EMPTY 0x10000
    {
    }
}
The ARM_LIB_STACK and ARM_LIB_HEAP regions are required because the program is being linked with the semihosting libraries.
Compile and link the sources:
armcc -c -g function.c
armcc -c -g main.c
armlink --no_autoat --scatter=scatter.scat --map function.o main.o -o squared.axf
The --map option displays the memory map of the image.
The memory map shows that the variable is placed in the ER2 execution region at address 0x11000:
...
    Execution Region ER2 (Base: 0x00001598, Size: 0x0000ea6c, Max: 0xffffffff, ABSOLUTE)

    Base Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x00001598   0x0000000c   Code   RO            3    .text               function.o
    0x000015a4   0x0000ea5c   PAD
    0x00010000   0x00000004   Data   RO           15    .ARM.__at_0x10000   main.o...
In this example, the size of ER1 is uknown. Therefore, gValue might be placed in ER1 or ER2. To make sure that gValue is placed in ER2, you must include the corresponding selector in ER2 and link with the --no_autoat command-line option. If you omit --no_autoat, gValue is to placed in a separate load region LR$$.ARM.__AT_0x00010000 that contains the execution region ER$$.ARM.__AT_0x00020000.

z

Yok hocam, burdaki ornekleri aynen yaptim gene olmuyor.

Kendi ornegimde scatterda kucuk bir degisiklik yaptiktan sonra uretilen map dosyasinda
ilginc bir sekilde segmentlerin istedigim adrese oturdugunu gordum.

Fakat  debug menude ilgili adreslere baktigimda 0x8002000 de olmasi gereken verilerin
0x800000 a yerlesmis en son kodun hemen arkasina yazildigini gordum.

Tam anlamiyla kafa yeme modundayim.

Bir ornek yayinlayayim. Bu sekilde soylediklerim havada kaliyor.
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

z

http://www.cncdesigner.com/wordpress/wp-content/uploads/deneme.rar

0x08000100 adresine 1,2,3,4 verilerinin yerlesmesini bekliyorum.

Fakat 0x0800009 civarina yerlesiyorlar.
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

z

Acaba keil compiler, link asamasinda bu istedigim duruma iliskin parametreleri mi koymuyor bug mi var?

Tum istedigim asagidaki yapiyi gercekelstirmek.


Bana e^st de diyebilirsiniz.   www.cncdesigner.com

Icarus

Z scatter file'ini biraz değiştirdim umarım çalışır.
Ama özetle şuna benzemeli. 1. satırdaki tanım macro processor kullanmanı sağlar. Bendeki A5 sende kendi işlemcine göre değiştir.
Bu scatter file linklenen kod XIP'dir (eXecute in place)
#! armcc -E --cpu Cortex-A5.neon

#define CODE_BASE_ADDR_START    	0x80000000
#define CODE_BASE_ADDR_END      	0x80010000
#define CODE_SIZE               	(CODE_BASE_ADDR_END - CODE_BASE_ADDR_START)

#define DATA_BASE_ADDR_START    	0x80020000
#define DATA_BASE_ADDR_END      	0x80030000
#define DATA_SIZE               	(DATA_BASE_ADDR_END - DATA_BASE_ADDR_START)

#define	MY_TABLE_ADDR				0x80001000
#define	REST_OF_MY_CODE				0x80002000

LOAD_REGION_CODE CODE_BASE_ADDR_START (CODE_BASE_ADDR_END - CODE_BASE_ADDR_START) FIXED
{
    BOOT +0 FIXED
    {
        *(STARTUP)
    }
    
	MY_TABLE MY_TABLE_ADDR FIXED ALIGN 32
	{
		Tablo.o
	}
	
    CODE REST_OF_MY_CODE FIXED
    {
        * (InRoot$$Sections)
        * (TEXT)
        * (+RO)
    }
    
    DATA DATA_BASE_ADDR_START ALIGN 32 
    {
        * (+RW, +ZI)
    }

	;Ben bunları kullanmıyorum ama kullanıyorsan mutlaka 0'dan büyük tanımlamalısın
    FIQ_STACKS +0 ALIGN 8 EMPTY FIQ_STACK_SIZE {}
    ABT_STACKS +0 ALIGN 8 EMPTY ABT_STACK_SIZE {}
    UND_STACKS +0 ALIGN 8 EMPTY UND_STACK_SIZE {}
    SYS_STACKS +0 ALIGN 8 EMPTY SYS_STACK_SIZE {}

    ARM_LIB_STACKHEAP (DATA_BASE_ADDR_END - 0x100) OVERLAY EMPTY UNINIT 0x04 
    {
    }
}

z

Tek basina scatter dosya muhtemelen isimi gormeyecek. Gene de bu scatter'i deneyecegim.

Fakat, bu segmentleri kullanan cok cok basit bir bir C program parcasinin derlenmesi sonucu olusan list dosyada asm directiveler de varsa belki daha cok fikir edinebilirim.

Cunku benim scatter dosya sanki dogru da asm dosyada bu sectionlari kullanirken bir seyleri eksik tanimliyormusum fikri gelisti.

Programi derlerken "Programinizdan kullanilmayan sectionlar uzaklastirildi" anlamina gelen  uyari aliyorum.

Scatter dosyasini ve asm dosyasini cok bilincli hazirlamiyorum. Programlarimi Keilin shirbazinin hazirladigi startup.s dosyasini modifiye ederek elde ettigim sablon uzerinden gelistiriyorum.  Keil'in standart orneklerinde benimki gibi ozel adreslere veri yerlesim amaci gudulmediginden yanlis sablon ile oynuyorum dusuncesindeyim.
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

z

X-FI sagolsun sorunu cozdum.

Bu yuce insan soyle dedi;

Tablo kodlarini ayri bir dosyaya koy ve bu dosyanin properties menusunde adresini tanimlamayi dene.
Hemen bir deneme projesi olusturup dedigini yaptim oda nesi. Oldu.

---------------

Bunun uzerine orjinal projemde de tablo verilerimi ayri bir dosyaya koydum ve bunu projeye dahil ettim.

Daha once kullandigim scatter dosyalardan birisini kullandim. Ayrica  tablo verilerimin properties'ine girmeden derleyeyim dedim.

Oda nesi oldu.

Muhtemelen linker komutunun sonuna ilave parametre koydu.

Scatter dosyam aynen asagidaki gibi.

LR1 0x08000000 0x1000
{
    ER_IROM1 0x08000000 0x1000
    {
        *(Reset,+FIRST)
        .ANY(+RO)
    }
    
    ZiosRam 0x20000000 0x00005000        ; RW data
    {
        *(+RW, +ZI)
    }
}

LR2 0x08001000 0x0800
{
    ER_IROM2 0x08001000 0x0800
    {
        *(Tablo,+FIRST)
        .ANY(+RO)
    }
}


Iki tane bolgem var. 1. Bolgemin adi Reset, diger bolgemin adi Tablo

Bu arada 1. bolgedeki programlar bolgenin tamamini kaplamiyor. Fakat bu cozum ardindan hepsi kullaniliyor gibi islem goruyor.

Bu isi beceremezken iki ayri proje ile bu sorunu getirdigim cozumde

1. Bolgede 100 Byte veri varsa iretilen hex de 100Byte oluyordu.

Bu cozumde ise birince bolge 4096 byte oldugundan tablom da 4K oldugundan kodlarim 8 K oldu.



Farkli sectionlari ayni dosyada kullanmaya kalkarsak sac bas yolduruyor. (Belki bunun da cozumu vardir.) Fakat farklis sectionlara yerlesecek kodlari farkli dosyalara koyarsak sorun bitiyor.
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

X-Fi

Çözüldüğüne sevindim hocam aynı yöntemi RAM fonksiyonlarını adreslemek için kullanıyordum asm dosya sisteminde çalışacağını ilk başda düşünmemiştim ama çalışıyormuş sayenizde öğrenmiş olduk.
http://www.coskunergan.dev/    (Yürümekle varılmaz, lakin varanlar yürüyenlerdir.)