中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 在晶心平臺(tái)實(shí)作ROM patch技術(shù)分享

        在晶心平臺(tái)實(shí)作ROM patch技術(shù)分享

        作者: 時(shí)間:2012-10-16 來源:網(wǎng)絡(luò) 收藏

        筆者曾協(xié)助多家公司工程師,在AndesCore上發(fā)展firmware.我們發(fā)現(xiàn),當(dāng)客戶開發(fā)NON-OS的程序代碼,最常遇到的問題在于開發(fā)者不知如何撰寫linker script.網(wǎng)絡(luò)上有GNU ld的使用文件,但是linker script的范例太少,尤其開發(fā)者需要撰寫進(jìn)階的linker script,常常不知如何下手。

        本文引用地址:http://www.antipu.com.cn/article/148347.htm

        本篇文章我們如何實(shí)作 .使用晶心CPU建構(gòu)的embedded system,一般具有CPU、外圍IP及RAM、.部份客戶使用 code開機(jī),程序代碼放在ROM內(nèi),data secTIon放在SRAM里。ROM code的特性是成本低,跟著IC光罩一起生產(chǎn),當(dāng)IC制作完成即不可修改,若有制作上的錯(cuò)誤或是程序代碼邏輯上的錯(cuò)誤,只能用ROM 的方式修補(bǔ)。也就是將需要修補(bǔ)的程序代碼放到小容量的flash里。這就是我們今天要。

        1. 主程序架構(gòu)

        首先介紹主程序的架構(gòu)。IC的Memory layout如下圖。

        圖表1:主程序的memory layout圖

        圖表1:主程序的memory layout圖

        紅色框線的部份,為主程序編譯的范圍。主程序main會(huì)呼叫到func1、func2和func3這3個(gè)function.

        在上圖中,黃色區(qū)域是IC的ROM,這部份的程序是IC制作出來即不可以改變。綠色部份是Flash.在圖中,flash分成2區(qū),一個(gè)是jump_table,存放func1~func3的地址。剩余的空間FUNC_PATCH,預(yù)留給使用。

        為了要修補(bǔ)ROM內(nèi)的function,所以規(guī)劃出jump_table區(qū)域,原本都是指向ROM的function.如果ROM里的部份function損壞或是需要改寫,就把jump_table改為指向FUNC_PATCH里新建的function.

        1.1 源代碼

        主程序的程序代碼如下:(main.c)

        #include

        #include

        int func1(int);

        int func2(int);

        int func3(int);

        int num1=1;

        int num2=2;

        int num3=3;

        typedef struct strfunptr {

        int (*func_a)(int);

        int (*func_b)(int);

        int (*func_c)(int);

        }sfptr;

        sfptr jump_table __attribute__ ((section (FUNC_TABLE)))= {func1, func2, func3};

        int main(void) {

        printf(func1(30)=%dn,jump_table.func_a(30));

        printf(func2(30)=%dn,jump_table.func_b(30));

        printf(func3(30)=%dn,jump_table.func_c(30));

        return EXIT_SUCCESS;

        }

        int func1(int x){

        return x*num1;

        }

        int func2(int x){

        return x*num2;

        }

        int func3(int x){

        return x*num3;

        }

        上面的程序代碼中,第16行的程序代碼__attribute__ ((section (FUNC_TABLE))),作用是將jump_table放在特定的FUNC_TABLEsection里。

        1.2 主程序linker script (僅列需要修改的部份)

        FUNC_TABLE 0x510000 :

        {

        *(。FUNC_TABLE)

        }

        Flash的地址由0x510000起,將FUNC_TABLE固定在flash的最開頭,語法如上。

        1.3 主程序執(zhí)行結(jié)果

        func1(30)=30

        func2(30)=60

        func3(30)=90

        2. 經(jīng)過Patch之后的架構(gòu)圖

        假設(shè)ROM里的func2損壞,要改用flash里的func2.需要更改指向func2的指標(biāo),及func2的內(nèi)容。如下圖:

        圖表2:ROM patch的memory layout圖

        圖表2:ROM patch的memory layout圖

        用紅色框線標(biāo)起來的地方,表示為patch編譯的范圍。其中jump table在這里重新編譯,指向新的地址。

        2.1 實(shí)作方法

        (1) 導(dǎo)出主程序的symbol table.

        在主程序的Linker flags 加上-Wl,--mgen-symbol-ld-script=export.txt ,ld 會(huì)產(chǎn)生export.txt這個(gè)檔案, 這個(gè)檔案包含了一個(gè)SECTION block以及許多變數(shù)的地址。如下圖所示

        圖表3:主程序的symbol

        圖表3:主程序的symbol

        Linker script在import Main program的symbols時(shí),除了需要修改的func2不要import之外,其他的symbols全部要import進(jìn)來。(將 export.txt刪去這一行: func2 = 0x005001c4; /* ./main.o */)

        (2) patch在編譯之前,先匯入主程序的symbol table.(將export.txt檔案放在一起編譯)。Patch的linker script要匯入主程序的symbol,寫法如下面紅色字體。

        ENTRY(_start)

        /* Do we need any of these for elf?

        __DYNAMIC = 0; */

        INCLUDE export.txt

        SECTIONS

        {

        (3) patch的程序代碼里如下,沒有main function,也不要加入startup files.改寫func2.func2放在flash的FUNC_PATCH section.并且將jump_table里的func2,改成指向新的func2.

        #include

        #include

        extern int func1(int);

        extern int func3(int);

        int func2(int) __attribute__ ((section (FUNC_PATCH)));

        extern int num2;

        typedef struct strfunptr {

        int (*func_a)(int);

        int (*func_b)(int);

        int (*func_c)(int);

        }sfptr;

        sfptr jump_table __attribute__ ((section (FUNC_TABLE)))= {func1, func2, func3};

        int func2(int x){

        return x*num2*100;

        }

        (4) patch的linker script,加入FUNC_PATH在jump_table之后。

        FUNC_PATCH 0x510020 :

        {

        *(。FUNC_PATCH)

        }

        3. 如何除錯(cuò)

        首先,將程序代碼存放在IC的ROM及flash里。(本文為了示范,我們的做法是在AndeShape ADP-XC5的FPGA板上,用RAM模擬ROM及flash,分別將主程序和patch的bin文件restore到板子上。)


        上一頁 1 2 下一頁

        評(píng)論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉