移植u-boot-2009-11->S3c44b0公板

移植u-boot-2009-11->S3c44b0公板
by [email protected]

网上有关porting u-boot for 44b0的大牛们的教程绝大多数都是以dave/B2板为模板,没办法,u-boot
上只有这块44b0的model。顺着前辈们的路,我在移植的时候遇到很多问题,有些问题前辈可能觉得太简单了
,没有提及,结果是让我们这些囫囵吞枣的小菜死的很难看!

下面请看我的中文步骤,如果你是用44b0公板的话,也想移植个最新的u-boot-2009-11,那可能要深入追究
下代码,我不敢保证我提供的是最详细的步骤说明,但很多问题还是值得深思的。



//__________________________________________________________________//
// 修改Makefile简单测试下交叉编译器//
//__________________________________________________________________//
CROSS_COMPILE = arm-none-eabi-
make B2_config
make

//__________________________________________________________________//
// 添加修改必要文件,步骤比较繁琐//
//__________________________________________________________________//
1.
copy dave/B2 dave/common ->/board/panasonic
mv B2 panasonic

2.
config.mk
TEXT_BASE = 0x0C100000->0x0c700000

3.
Makefile
COBJS    := panasonic.o flash.o
SOBJS    := lowlevel_init.o

4.
lowlevel_init.S
这个是十分十分的重要,一定要修改,具体参考ADS下的例程或者我的patch,不然会出现很多莫名其妙的问题
,实在是让人摸不着头脑,内存时序嘛,设置不好就是有时候行有时候不行,没的说。另外网卡那个bank要设
置成16bit的,你的网卡是8bit的那就改一下吧。
/* Bank 0 parameter */
.equ    B0_Tacs,      0x3 /* 0clk */
.equ    B0_Tcos,      0x3 /* 0clk */
.equ    B0_Tacc,      0x7 /* 14clk */
.equ    B0_Tcoh,      0x3 /* 0clk */
.equ    B0_Tah,       0x3 /* 0clk */
.equ    B0_Tacp,      0x1 /* 0clk */
.equ    B0_PMC,       0x0 /* normal(1data) */

5.
flash.c是高层次的代码,调用../common/flash.c,所以不用修改。但是看看这里的flash.init函数,
它在uboot的初始化队列中调用,如果你的flash未能识别,环境变量会使用默认的环境变量,这将是很大的麻烦。从flash.init函数也可以看到flash初始化的几个关键函数和流程,对,下面就是要修改它们。
unsigned long flash_init (void)
{

    /* Init: no FLASHes known */
    for (i=0; i         flash_info[i].flash_id = FLASH_UNKNOWN;
    }

    /* Static FLASH Bank configuration here - FIXME XXX */

    size_b0 = flash_get_size((vu_long *)CONFIG_SYS_FLASH_BASE, &flash_info[0]);

    if (flash_info[0].flash_id == FLASH_UNKNOWN) {
        printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
            size_b0, size_b0<<20);
    }

    /* Setup offsets */
    flash_get_offsets (0, &flash_info[0]);

    /* Monitor protection ON by default */
    (void)flash_protect(FLAG_PROTECT_SET,
                -CONFIG_SYS_MONITOR_LEN,
                0xffffffff,
                &flash_info[0]);

    flash_info[0].size = size_b0;

    return (size_b0);

6.
B2.c改名过来的panasonic.c主要有board_init和dram_init两个函数,board_init的端口初始化也要
十分注意!比如rtl8019用的片选端口要初始化为cs,不要初始化为普通IO了,具体参考ADS例程或者我的patch。

7.
回到上层目录common/flash.c,这里有几个底层flash的函数很关键,所以要大修大补!又因为涉及到flash底层,所以跟硬件相关,情况比较复杂一点,当然如果你的flash刚好是在支持列表中,那就不用做这些修改。

7.1
flash_get_offsets函数,添加flash的offsets表,这要参考你的flash的datasheet,看看扇区是怎么安排的,需要注意是top boot还是 bottom boot类型的flash。我的是AMIC的a29l160uv。
>     } else if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AMI160UV) ) {
>         /* set sector offsets for bottom boot block type    !here !这里按8位模式安排地址,然后将地址指针强制类型转换为16bit的模式*/
>         info->start[0] = base + 0x00000000;/*SA0=0-03FFF=16K*/
>         info->start[1] = base + 0x00004000;/*SA1=4000-5FFF=8K*/
>         info->start[2] = base + 0x00006000;/*SA2=6000-7FFF=8K*/
>         info->start[3] = base + 0x00008000;/*SA3=08000-FFFF=32K*/
>         for (i = 4; i < info->sector_count; i++) {
>             info->start[i] = base + (i * 0x00010000) - 0x00030000;
>         }

7.2
flash_print_info函数主要是打印flash厂商和型号。添加如下
116a127
>     case FLASH_MAN_AMI:    printf ("AMI ");
                break;
135a147,150
>     case FLASH_AMI160UV:    printf ("A29L160UV-70 (16 Mbit, bottom boot sector)\n");
>                 break;

7.3
flash_get_size函数,这里会读取flash的Manufacturer ID和Device ID,读取的命令要根据你的具体flash型号的datasheet来决定。
/* Write auto select command: read Manufacturer ID */
    addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA;
    addr2[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055;
    addr2[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00900090;
然后添加以下代码,具体也看flash型号
---
>     case (CONFIG_SYS_FLASH_WORD_SIZE)AMI_MANUFACT:
>         info->flash_id = FLASH_MAN_AMI;
>         break;

/*panasonic add 2009-12-22*/
    case (CFG_FLASH_WORD_SIZE)AMI_ID_L160UV:
        info->flash_id += FLASH_AMI160UV;
        info->sector_count = 35;
        info->size = 0x00200000;
        break;                /* => 2 MB        */

367a390,399
>     } else if (((info->flash_id & FLASH_TYPEMASK) == FLASH_AMI160UV) ) {
>         /* set sector offsets for bottom boot block type*/
>         info->start[0] = base + 0x00000000;/*SA0=0-03FFF=16K*/
>         info->start[1] = base + 0x00004000;/*SA1=4000-5FFF=8K*/
>         info->start[2] = base + 0x00006000;/*SA2=6000-7FFF=8K*/
>         info->start[3] = base + 0x00008000;/*SA3=08000-FFFF=32K*/
>         for (i = 4; i < info->sector_count; i++) {
>             info->start[i] = base + (i * 0x00010000) - 0x00030000;
>         }
>

7.4
flash_erase函数中的擦除命令,具体看flash datasheet修改。
addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA;
addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055;
addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00800080;
addr[CONFIG_SYS_FLASH_ADDR0] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00AA00AA;
addr[CONFIG_SYS_FLASH_ADDR1] = (CONFIG_SYS_FLASH_WORD_SIZE)0x00550055;

7.5
write_buff主要修改,记得要在../include/configs/panasonic.h定义。
582c617
< #ifdef CONFIG_B2
---
> #ifdef CONFIG_PANASONIC

7.6
write_word函数记得也是根据你的flash型号修改命令。

8.
../common/env_common.c
打开DEBUG_ENV这对调试环境变量很有利!等会会提到。
#undef DEBUG_ENV ->#define DEBUG_ENV

9.
进到目录../cpu/s3c44b0/start.S这个启动代码至关重要!
首先是中断向量表,如果不修改,可能启动linux kernel的时候会停留在下面画面。
/*
 * Jump vector table
 */


.globl _start

_start:    b       reset

    ldr pc,=HandleUndef

    ldr pc,=HandleSWI

    ldr pc,=HandlePabort

    ldr pc,=HandleDabort

    b .

    ldr pc,=HandleIRQ

    ldr pc,=HandleFIQ

    ldr pc,=HandleEINT0 /*mGA H/W interrupt vector table*/

    ldr pc,=HandleEINT1

    ldr pc,=HandleEINT2

    ldr pc,=HandleEINT3

    ldr pc,=HandleEINT4567

    ldr pc,=HandleTICK /*mGA*/

    b .

    b .

    ldr pc,=HandleZDMA0 /*mGB*/

    ldr pc,=HandleZDMA1

    ldr pc,=HandleBDMA0

    ldr pc,=HandleBDMA1

    ldr pc,=HandleWDT

    ldr pc,=HandleUERR01 /*mGB*/

    b .

    b .

    ldr pc,=HandleTIMER0 /*mGC*/

    ldr pc,=HandleTIMER1

    ldr pc,=HandleTIMER2

    ldr pc,=HandleTIMER3

    ldr pc,=HandleTIMER4

    ldr pc,=HandleTIMER5 /*mGC*/

    b .

    b .

    ldr pc,=HandleURXD0 /*mGD*/

    ldr pc,=HandleURXD1

    ldr pc,=HandleIIC

    ldr pc,=HandleSIO

    ldr pc,=HandleUTXD0

    ldr pc,=HandleUTXD1 /*mGD*/

    b .

    b .

    ldr pc,=HandleRTC /*mGKA*/

    b .

    b .

    b . 

    b .

    b . /*mGKA*/

    b .

    b .

    ldr pc,=HandleADC /*mGKB*/

    b .

    b .

    b .

    b .

    b . /*mGKB*/

    b .

    b .

    .equ HandleReset, 0xc000000

    .equ HandleUndef,0xc000004

    .equ HandleSWI, 0xc000008

    .equ HandlePabort, 0xc00000c

    .equ HandleDabort, 0xc000010

    .equ HandleReserved, 0xc000014

    .equ HandleIRQ, 0xc000018

    .equ HandleFIQ, 0xc00001c

    .equ HandleADC, 0xc000020

    .equ HandleRTC, 0xc000024

    .equ HandleUTXD1, 0xc000028

    .equ HandleUTXD0, 0xc00002c

    .equ HandleSIO, 0xc000030

    .equ HandleIIC, 0xc000034

    .equ HandleURXD1, 0xc000038

    .equ HandleURXD0, 0xc00003c

    .equ HandleTIMER5, 0xc000040

    .equ HandleTIMER4, 0xc000044

    .equ HandleTIMER3, 0xc000048

    .equ HandleTIMER2, 0xc00004c

    .equ HandleTIMER1, 0xc000050

    .equ HandleTIMER0, 0xc000054

    .equ HandleUERR01, 0xc000058

    .equ HandleWDT, 0xc00005c

    .equ HandleBDMA1, 0xc000060

    .equ HandleBDMA0, 0xc000064

    .equ HandleZDMA1, 0xc000068

    .equ HandleZDMA0, 0xc00006c

    .equ HandleTICK, 0xc000070

    .equ HandleEINT4567, 0xc000074

    .equ HandleEINT3, 0xc000078

    .equ HandleEINT2, 0xc00007c

    .equ HandleEINT1, 0xc000080

    .equ HandleEINT0, 0xc000084

 
    .balignl 16,0xdeadbeef

 

其次是PLLCON寄存器的cpu频率,要配置的当,不然自相矛盾就挂了。
#if CONFIG_S3C44B0_CLOCK_SPEED==60   

    ldr    r0, =0x88042 /* 60MHz (Quartz=10MHz) */
#elif CONFIG_S3C44B0_CLOCK_SPEED==66
    ldr    r0, =0x34031     /* 66MHz (Quartz=11MHz) */
#elif CONFIG_S3C44B0_CLOCK_SPEED==75
    ldr    r0, =0x610c1 /*B2: Xtal=20mhz Fclk=75MHz  */
#else
# error CONFIG_S3C44B0_CLOCK_SPEED undefined
#endif

最后,可能也是最重要的,起码在我这次移植体验中,经验教训是最大的,折腾我一个多星期!当我移植好uboot烧写到flash,开机测试,一切正常。拔了电源,放几个小时,开机,uboot检测完flash后就挂了。偶尔又很正常。比如今天一天都很正常,明天上班来到可能又挂了。但是有一点就是使用md命令的时候必然会死机!刚开始我以为是板子不稳定,初始化内存时序可能有问题,但是一直没找到原因。我找来uboot1.1.1版本的对比了大部分有关代码,没什么不一样,但是用起来很正常,我怀疑是编译器的问题,因为uboot1.1.1版本用的是arm-elf,由于版本太低2.95.3,所以没换这个试一下。只好自己追踪,啃源码。精简后的uboot第二阶段start_armboot在libarm/board.c里面定义,在打印完flash信息后进入env_relocate函数时候当机的,所以问题就可能出在这里
void start_armboot (void)
{
    init_fnc_t **init_fnc_ptr;

    monitor_flash_len = _bss_start - _armboot_start;

    for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
        if ((*init_fnc_ptr)() != 0) {
            hang ();
        }
    }

    /* armboot_start is defined in the board-specific linker script */
    mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN,
            CONFIG_SYS_MALLOC_LEN);

#ifndef CONFIG_SYS_NO_FLASH
    /* configure available FLASH banks */
    display_flash_config (flash_init ());
#endif /* CONFIG_SYS_NO_FLASH */


    /* initialize environment */
    env_relocate ();


    /* IP Address */
    gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
    stdio_init ();    /* get the devices list going. */
    jumptable_init ();
    console_init_r ();    /* fully init console as a device */

    /* enable exceptions */
    enable_interrupts ();

    eth_initialize(gd->bd);

    /* main_loop() can return to retry autoboot, if so just run it again. */
    for (;;) {
        main_loop ();
    }

}
于是追踪到../common/env_common.c里面的env_relocate函数,这里要深入理解uboot环境变量的实现,
这个可以google一下,前面提到要打开EBUG_ENV这对调试环境变量很有利的宏。
#undef DEBUG_ENV ->#define DEBUG_ENV

void env_relocate (void)
{
..........此处省略很多
    /*
     * We must allocate a buffer for the environment
     */
    env_ptr = (env_t *)malloc (CONFIG_ENV_SIZE);
    DEBUGF ("%s[%d] malloced ENV at %p\n", __FUNCTION__,__LINE__,env_ptr);
#endif

    if (gd->env_valid == 0) {
#if defined(CONFIG_GTH)    || defined(CONFIG_ENV_IS_NOWHERE)    /* Environment not changable */
        puts ("Using default environment\n\n");
#else
        puts ("*** Warning - bad CRC, using default environment\n\n");
        show_boot_progress (-60);
#endif
        set_default_env();
    }
    else {
        env_relocate_spec ();
    }
    gd->env_addr = (ulong)&(env_ptr->data);

#ifdef CONFIG_AMIGAONEG3SE
    disable_nvram();
#endif
}
重新烧写,控制台可以看到如下重要的调试信息
U-Boot 2009.11 (12鏈?23 2009 - 10:49:37)

 
U-Boot code: 0C700000 -> 0C71A298  BSS: -> 0C71E32C

RAM Configuration:

Bank #0: c0000000  8 MB

[flash_get_size, 241] Entering ...

flash_protect ON: from 0xFFFC0000 to 0xFFFFFFFF

Flash:  2 MB

Entering env_relocate!

 
(env_t *)malloc (CONFIG_ENV_SIZE) done!

 
env_relocate[257] malloced ENV at (null)

*** Warning - bad CRC, using default environment
就是说molloc函数返回NULL!就是没有分配到内存!google了下uboot的malloc函数,有大牛遇到像我这样经典的问题,以下引用他的:
而bss段的初始化由C在调用main程序前将其初始化。但是对于U-BOOT而言,这些只能由它自己去完成。
而s3c44b0 start.s中没有做这部分工作。结果便会导致所以依赖于bss段赋初值为0的函数发生问题。
比如前面的malloc函数,他的top_pad为一个随机数,如几个M/Gbytes,咱们系统中总共才那么点SDRAM,
哪够你这么挥霍的, 其结果必然是malloc分配堆失败,程序挂掉了;

原来如此,但是uboot1.1.1版本的start.S也没有对bss段初始化阿,这可能又是真的跟编译器有关了。哎呀,一个星期的折腾阿!最终的解决方案是在start.S里面添加bss段初始化代码:

vector_copy_loop:
    ldmia    r0!, {r3-r10}
    stmia    r1!, {r3-r10}
    cmp    r0, r2
    ble    vector_copy_loop
#endif    /* CONFIG_SKIP_RELOCATE_UBOOT */


/* add--- to init the bss segment*/
ldr r0, = 0
ldr r1, _bss_start
ldr r2, _bss_end
bss_init:
str r0, [r1]
add r1,r1,#4
cmp r1,r2
blt bss_init

    /* Set up the stack                            */
stack_setup:


10.
回到上层目录,进入../drivers/serial/serial_s3c44b0.c,把所有CPU频率改成60MHZ后再把所有的波特率分频因子重新计算。
    case 115200:
#if CONFIG_S3C44B0_CLOCK_SPEED==60
        divisor = 32;
#elif CONFIG_S3C44B0_CLOCK_SPEED==75
        divisor = 40;
#else
# error CONFIG_S3C44B0_CLOCK_SPEED undefined
#endif    /* break; */

11.
回到上层目录,进入../drivers/net,找到rtl8019.h/rtl8019.c,这两个文件在B2版本中都是工作在8bit模式下,需要改成16bit的模式。
11.1 rtl8019.c
    get_reg函数需要加上volatile,防止编译器优化,不然,嘿嘿,在ping的时候可能会出现packet too big!或者干脆重启的后果,还有一种可能是TFTP的时候没反应;奇怪的是在uboot1.1.1版本中这个函数也没有加上volatile,可能跟arm-elf工具链有关。
static unsigned char get_reg (unsigned int regno)
{
    return (*(volatile unsigned char *) regno);
}

static void put_reg (unsigned int regno, unsigned char val)
{
    *(volatile unsigned char *) regno = val;
}
11.2  在函数int eth_init (bd_t * bd)需要修改两个寄存器的值如下:
117c123
<     put_reg (RTL8019_MULTIADDRESS1, 0x00);
---
>     put_reg (RTL8019_MULTIADDRESS1, 0x41);
119c125
<     put_reg (RTL8019_MULTIADDRESS3, 0x00);
---
>     put_reg (RTL8019_MULTIADDRESS3, 0x80);
126c132

11.3 rtl8019.h
这里的寄存器基址需要加上偏移量1,如下
#define    ADDR_SFT        1

#define    RTL8019_REG_00                (RTL8019_BASE + (0x00< #define     RTL8019_REG_01                (RTL8019_BASE + (0x01< #define     RTL8019_REG_02                (RTL8019_BASE + (0x02< #define     RTL8019_REG_03                (RTL8019_BASE + (0x03< #define     RTL8019_REG_04                (RTL8019_BASE + (0x04< #define     RTL8019_REG_05                (RTL8019_BASE + (0x05< #define     RTL8019_REG_06                (RTL8019_BASE + (0x06< #define     RTL8019_REG_07                (RTL8019_BASE + (0x07< #define     RTL8019_REG_08                (RTL8019_BASE + (0x08< #define     RTL8019_REG_09                (RTL8019_BASE + (0x09< #define     RTL8019_REG_0a                (RTL8019_BASE + (0x0a< #define     RTL8019_REG_0b                (RTL8019_BASE + (0x0b< #define     RTL8019_REG_0c                (RTL8019_BASE + (0x0c< #define     RTL8019_REG_0d                (RTL8019_BASE + (0x0d< #define     RTL8019_REG_0e                (RTL8019_BASE + (0x0e< #define     RTL8019_REG_0f                (RTL8019_BASE + (0x0f< #define     RTL8019_REG_10                (RTL8019_BASE + (0x10< #define     RTL8019_REG_1f                (RTL8019_BASE + (0x1f<
12.
回到上层目录,进入../include,找到flash.h,添加四个预处理定义,它们用在我们前面的../board/panasonic/common/flash.c
的几个函数,这几个数值不是随便选的,比如AMI_ID_L160UV的值要看flash的datasheet确定,其他也是。这些的重要性就是说用于识别flash,当uboot中flash为未知的型号时,很多特性都用不了。当然有个简单的方法,前提是你的flash是符合CFI的标准,那么可以跳过这些繁琐的步骤,只需在config配置文件中声明使用CFI drivers。

/*-----------------------------------------------------------------------
 * Device IDs
 */

#define AMI_MANUFACT    0x00000037            /* AMI manuf. ID in D23..D16, D7..D0 */
#define AMI_ID_L160UV    0x0000B329        /* 29L160UV ID (16 M,bottom boot sector)    */
#define FLASH_AMI160UV     0x0029            /* AMI A29L160UV            */
#define FLASH_MAN_AMI       0x00110000    /* AMI                    */

13.
/include/B2.h ->panasonic.h,各个配置选项的意义可以参考我的uboot readme,修改如下

//打开调试选项,很有帮助//
#define DEBUG
/*
 * High Level Configuration Options
 * (easy to change)
 */
#define CONFIG_ARM7            1    /* This is a ARM7 CPU    */
#define CONFIG_PANASONIC    1    /* on an PANASONIC Board      */
#define CONFIG_ARM_THUMB    1    /* this is an ARM7TDMI */
#undef  CONFIG_ARM7_REVD        /* disable ARM720 REV.D Workarounds */
#define CONFIG_SYS_NO_CP15_CACHE
#define CONFIG_ARCH_CPU_INIT

#define CONFIG_S3C44B0_CLOCK_SPEED    60 /* we have a 60Mhz S3C44B0*/

#define CONFIG_IDENT_STRING "[email protected]"

#undef CONFIG_USE_IRQ            /* don't need them anymore */

//#define CONFIG_SYS_FLASH_PROTECTION 1
/*
 * Size of malloc() pool
 */
#define CONFIG_SYS_MONITOR_BASE    0x00000000
#define CONFIG_SYS_MONITOR_LEN        (256 * 1024)    /* Reserve 256 kB for Monitor    */

#define CONFIG_SYS_MALLOC_LEN        (CONFIG_ENV_SIZE + 128*1024 )
#define CONFIG_SYS_GBL_DATA_SIZE    128    /* size in bytes reserved for initial data */

/*
 * Hardware drivers
 */

#define CONFIG_DRIVER_RTL8019
#define RTL8019_BASE        0x06000300 /* base address         */
#define RTL8019_BUS32        0
#define CONFIG_SMC_USE_16_BIT
#undef  CONFIG_SHOW_ACTIVITY
#define CONFIG_NET_RETRY_COUNT        10       /* # of retries          */
/*
 * select serial console configuration
 */
#define CONFIG_S3C44B0_SERIAL
#define CONFIG_SERIAL1        1    /* we use Serial line 1 */

//#define CONFIG_S3C44B0_I2C
//#define CONFIG_RTC_S3C44B0

/* allow to overwrite serial and ethaddr */
#define CONFIG_ENV_OVERWRITE

#define CONFIG_BAUDRATE        115200

/*
 * BOOTP options
 */
//#define CONFIG_BOOTP_SUBNETMASK
//#define CONFIG_BOOTP_GATEWAY
//#define CONFIG_BOOTP_HOSTNAME
//#define CONFIG_BOOTP_BOOTPATH
//#define CONFIG_BOOTP_BOOTFILESIZE

/*
 * Command line configuration.
 */
#include

#define CONFIG_CMD_PING
#define CONFIG_CMD_NET

#define CONFIG_BOOTDELAY    10
#define CONFIG_ETHADDR    00:50:c2:1e:af:fb
#define CONFIG_BOOTARGS  "devfs=mount root=ramfs console=ttyS0,9600"
#define CONFIG_NETMASK  255.255.255.0
#define CONFIG_IPADDR   192.168.0.2
#define CONFIG_SERVERIP    192.168.0.1
#define CONFIG_BOOTFILE    "uclinux_rom.bin"
#define CONFIG_BOOTCOMMAND    "bootm 0x50000"

/*
 * Miscellaneous configurable options
 */
#define    CONFIG_SYS_LONGHELP                /* undef to save memory        */
#define    CONFIG_SYS_PROMPT        "$"    /* Monitor Command Prompt    */
#define    CONFIG_SYS_CBSIZE        256        /* Console I/O Buffer Size    */
#define    CONFIG_SYS_PBSIZE (CONFIG_SYS_CBSIZE+sizeof(CONFIG_SYS_PROMPT)+16) /* Print Buffer Size */
#define    CONFIG_SYS_MAXARGS        16        /* max number of command args    */
#define CONFIG_SYS_BARGSIZE        CONFIG_SYS_CBSIZE    /* Boot Argument Buffer Size    */

#define CONFIG_SYS_MEMTEST_START    0x0C400000    /* memtest works on    */
#define CONFIG_SYS_MEMTEST_END        0x0C800000    /* 4 ... 8 MB in DRAM    */

#define    CONFIG_SYS_LOAD_ADDR        0x0c008000    /* default load address    */

#define    CONFIG_SYS_HZ                1000        /* 1 kHz */

                        /* valid baudrates */
#define CONFIG_SYS_BAUDRATE_TABLE    { 9600, 19200, 38400, 57600, 115200 }

/*-----------------------------------------------------------------------
 * Stack sizes
 *
 * The stack sizes are set up in start.S using the settings below
 */
#define CONFIG_STACKSIZE    (128*1024)    /* regular stack */
#ifdef CONFIG_USE_IRQ
#define CONFIG_STACKSIZE_IRQ    (4*1024)    /* IRQ stack */
#define CONFIG_STACKSIZE_FIQ    (4*1024)    /* FIQ stack */
#endif

/*-----------------------------------------------------------------------
 * Physical Memory Map
 */
#define CONFIG_NR_DRAM_BANKS    1       /* we have 1 banks of DRAM */
#define PHYS_SDRAM_1        0xc0000000 /* SDRAM Bank #1 */
#define PHYS_SDRAM_1_SIZE    0x00800000 /* 8 MB */

#define PHYS_FLASH_1        0x00000000 /* Flash Bank #1 */
#define PHYS_FLASH_SIZE        0x00200000 /* 2MB */

#define CONFIG_SYS_FLASH_BASE        PHYS_FLASH_1

/*-----------------------------------------------------------------------
 * FLASH and environment organization
 */
/*-----------------------------------------------------------------------
 * FLASH organization
 */
#define CONFIG_SYS_MAX_FLASH_BANKS    1    /* max number of memory banks        */
#define CONFIG_SYS_MAX_FLASH_SECT    35    /* max number of sectors on one chip    */

#define CONFIG_SYS_FLASH_ERASE_TOUT    120000    /* Timeout for Flash Erase (in ms)    */
#define CONFIG_SYS_FLASH_WRITE_TOUT    1000    /* Timeout for Flash Write (in ms)    */

//命令序列还是要参考下flash的datasheet,VIP!
#define CONFIG_SYS_FLASH_WORD_SIZE    unsigned short    /* flash word size (width)    */
#define CONFIG_SYS_FLASH_ADDR0        0x555    /* 1st address for flash config cycles    */
#define CONFIG_SYS_FLASH_ADDR1        0x2AA    /* 2nd address for flash config cycles    */
/*
 * The following defines are added for buggy IOP480 byte interface.
 * All other boards should use the standard values (CPCI405 etc.)
 */
#define CONFIG_SYS_FLASH_READ0        0x0000    /* 0 is standard            */
#define CONFIG_SYS_FLASH_READ1        0x0001    /* 1 is standard            */
#define CONFIG_SYS_FLASH_READ2        0x0002    /* 2 is standard            */

#define CONFIG_SYS_FLASH_EMPTY_INFO        /* print 'E' for empty sector on flinfo */

/*-----------------------------------------------------------------------
 * Environment Variable setup
 */
#define CONFIG_ENV_IS_IN_FLASH      1  /* use FLASH for environment vars */
#define CONFIG_ENV_ADDR    (PHYS_FLASH_1+0x40000) 
#define CONFIG_ENV_OFFSET    0x40000
#define CONFIG_ENV_SIZE        (64*1024)        /* 64k bytes may be used for env vars*/

/*-----------------------------------------------------------------------
 * I2C EEPROM (STM24C02W6) for environment
 */
//#define CONFIG_HARD_I2C            /* I2c with hardware support */
//#define CONFIG_SYS_I2C_SPEED        400000    /* I2C speed and slave address */
//#define CONFIG_SYS_I2C_SLAVE        0xFE

//#define CONFIG_SYS_I2C_EEPROM_ADDR    0xA8    /* EEPROM STM24C02W6        */
//#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1    /* Bytes of address        */
/* mask of address bits that overflow into the "EEPROM chip address"    */
/*#define CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW    0x07*/
//#define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS 4    /* The Catalyst CAT24WC08 has    */
                    /* 16 byte page write mode using*/
                    /* last 4 bits of the address    */
//#define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS    10   /* and takes up to 10 msec */

/* Flash banks JFFS2 should use */
/*
#define CONFIG_SYS_JFFS2_FIRST_BANK    0
#define CONFIG_SYS_JFFS2_FIRST_SECTOR    2
#define CONFIG_SYS_JFFS2_NUM_BANKS     1
*/

/*
    Linux TAGs (see lib_arm/armlinux.c)
*/
#define CONFIG_CMDLINE_TAG
#undef CONFIG_SETUP_MEMORY_TAGS
#define CONFIG_INITRD_TAG

14.
最后回到根目录Makefile,添加板子的编译配置

#########################################################################
## S3C44B0 Systems
#########################################################################

B2_config    :    unconfig
    @$(MKCONFIG) $(@:_config=) arm s3c44b0 B2 dave

panasonic_config    :    unconfig
    @$(MKCONFIG) $(@:_config=) arm s3c44b0 panasonic panasonic


//__________________________________________________________________//
// 最后编译下载调试//
//__________________________________________________________________//
$make distclean
$make panasonic_config
$make
把生成的u-boot.bin烧到flash,方法很多,我用的是jlink,不管什么方法,flash型号参数很重要。J-FLASH ARM 没有AMI
A29L160UV的flash参数,这回懒得添加了,直接用自动检测,其实就是CFI接口。我的jlink配置参考如下









//__________________________________________________________________//
// 生成补丁方便他人方便自己//
//__________________________________________________________________//
$make distclean
$diff -Naur u-boot-2009-11 u-boot-panasonic-2009-11 > u-boot-panasonic-2009-11.patch
用这个补丁的测试一下
panasonic@linux-tricy:~/bootloader> cd u-boot-2009-11/
panasonic@linux-tricy:~/bootloader/u-boot-2009-11> patch -p1 < ../u-boot-panasonic-2009-11.patch
patching file board/panasonic/common/flash.c
patching file board/panasonic/panasonic/config.mk
patching file board/panasonic/panasonic/flash.c
patching file board/panasonic/panasonic/lowlevel_init.S
patching file board/panasonic/panasonic/Makefile
patching file board/panasonic/panasonic/panasonic.c
patching file common/env_common.c
patching file cpu/s3c44b0/start.S
patching file drivers/net/rtl8019.c
patching file drivers/net/rtl8019.h
patching file drivers/serial/serial_s3c44b0.c
patching file include/configs/panasonic.h
patching file include/flash.h
patching file Makefile

//__________________________________________________________________//
// 最后启动的样子差不多就是这个样了//
//__________________________________________________________________//
U-Boot 2009.11 (12鏈?22 2009 - 16:05:57)

 
DRAM:   8 MB

Flash:  2 MB

In:    serial

Out:   serial

Err:   serial

Hit any key to stop autoboot:  0

=>  flinfo

 
Bank # 1: AMI A29L160UV-70 (16 Mbit, bottom boot sector)

  Size: 2 MB in 35 Sectors

  Sector Start Addresses:

    00000000      00004000      00006000      00008000      00010000

    00020000      00030000 E    00040000      00050000 E    00060000 E

    00070000 E    00080000 E    00090000 E    000A0000 E    000B0000 E

    000C0000 E    000D0000 E    000E0000 E    000F0000 E    00100000 E

    00110000 E    00120000 E    00130000 E    00140000 E    00150000 E

    00160000 E    00170000 E    00180000 E    00190000 E    001A0000 E

    001B0000 E    001C0000 E    001D0000 E    001E0000 E    001F0000

=>  printenv

bootargs=devfs=mount root=ramfs console=ttyS0,9600

bootcmd=bootm 0x50000

baudrate=115200

ethaddr=00:50:c2:1e:af:fb

netmask=255.255.255.0

bootfile=uclinux_rom.bin

bootdelay=10

ipaddr=192.168.0.2

serverip=192.168.0.1

stdin=serial

stdout=serial

stderr=serial

 
Environment size: 256/65532 bytes

//__________________________________________________________________//
// bss段没有初始化的后果是malloc函数返回NULL!//
//__________________________________________________________________//

U-Boot 2009.11 (12鏈?23 2009 - 10:49:37)

 
U-Boot code: 0C700000 -> 0C71A298  BSS: -> 0C71E32C

RAM Configuration:

Bank #0: c0000000  8 MB

[flash_get_size, 241] Entering ...

flash_protect ON: from 0xFFFC0000 to 0xFFFFFFFF

Flash:  2 MB

Entering env_relocate!

 
(env_t *)malloc (CONFIG_ENV_SIZE) done!

 
env_relocate[257] malloced ENV at (null)

*** Warning - bad CRC, using default environment

//__________________________________________________________________//
// 打开DEBUG_ENV,bss初始化后,malloc函数返回正常值!//
//__________________________________________________________________//

U-Boot code: 0C700000 -> 0C719248  BSS: -> 0C71D2D8

RAM Configuration:

Bank #0: c0000000  8 MB

[flash_get_size, 241] Entering ...

flash_protect ON: from 0xFFFC0000 to 0xFFFFFFFF

Flash:  2 MB

Entering env_relocate!

 
(env_t *)malloc (CONFIG_ENV_SIZE) done!

 
env_relocate[257] malloced ENV at 0c6d0008

*** Warning - bad CRC, using default environment

 
set_default_env() done!

 
In:    serial

Out:   serial

Err:   serial

### main_loop entered: bootdelay=10

 
### main_loop: bootcmd="bootm 0x50000"

Hit any key to stop autoboot:  0


附本文PDF和补丁
http://space.ednchina.com/Upload/2009/12/24/8b29ea8a-072c-4bd3-a7b0-93a870a86dbf.zip

http://space.ednchina.com/Upload/2009/12/24/457f8291-b7b5-4698-aa41-00a5c6487a73.zip

你可能感兴趣的:(u-boot)