<2012 12 05> FL2440开发板的U-boot-2010.09版本移植(四)Nor Flash启动支持

          我们知道S3C2440支持从NAND Flash启动和从NOR Flash启动两种模式,先来介绍u-boot的NOR Flash启动方式吧。

一、修改NOR Flash的读写程序

        FL2440开发板中使用的NOR Flash是Intel的J3系列存储大小是4M字节,这个系列的NOR Flash支持标准的CFI指令(在最新的U-boot版本中只需要添加宏定义就可以支持CFI接口的NOR Flash了,但我们这个版本中还不行),将board/cmi/flash.c复制到board/fl2440/flash.c,这个文件中包含了我们开发板的NOR Flash读写函数,但是其中还有一点问题,需要修改flash.c文件中的函数write_buff,此函数需要将小端字节数进行short类型变换,即将低地址数放在低位,高地址数放在高位另外还要进行地址对其,因为该型号flash只支持16位写,不支持8位写,那么我们写8位时需要从flash中读取出不改写8位,在加上需要改写的8位组成16位后回写到flash中去,具体将原flash.c中的函数write_buff修改如下:

[cpp]  view plain copy
  1. int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)  
  2. {  
  3.     ulong cp, wp;  
  4.     ushort data;  
  5.     int i, rc;  
  6.   
  7.     if (info->flash_id == FLASH_UNKNOWN) {  
  8.         return 4;  
  9.     }  
  10.   
  11.     wp = (addr & ~1);   /* get lower word aligned address */  
  12.   
  13.     /* 
  14.      * handle unaligned start byte 
  15.      */  
  16.   
  17.        /* for not to modify the origin data in flash*/  
  18.   
  19.     if (addr - wp) {  
  20.         data = 0;  
  21.                 for(i = 0, cp = wp; i < 1; ++i, ++cp){  
  22.                    data = (data >> 8) | (*(uchar *) cp << 8);  
  23.                 }  
  24.                 for(; i < 2 && cnt > 0; ++i){  
  25.         data = (data >> 8) | (*src++ <<8);  
  26.         --cnt;  
  27.                 ++cp;  
  28.                 }   
  29.                 for(; cnt == 0 && i < 2; ++i, ++cp){  
  30.                 data = (data >> 8) | (*(uchar *) cp << 8);  
  31.                 }  
  32.         if ((rc = write_short(info, wp, data)) != 0) {  
  33.             return (rc);  
  34.         }  
  35.         wp += 2;  
  36.     }  
  37.   
  38.     /* 
  39.      * handle word aligned part 
  40.      */  
  41.   
  42.     while (cnt >= 2) {  
  43.         /*data = 0; 
  44.         for (i=0; i<2; ++i) { 
  45.             data = (data << 8) | *src++; 
  46.         }*/  
  47.                 data = *((vu_short *) src) ;  
  48.   
  49.         if ((rc = write_short(info, wp, data)) != 0) {  
  50.             return (rc);  
  51.         }  
  52.                 src += 2;  
  53.         wp  += 2;  
  54.         cnt -= 2;  
  55.     }  
  56.   
  57.     if (cnt == 0) {  
  58.         return (0);  
  59.     }  
  60.   
  61.     /* 
  62.      * handle unaligned tail bytes 
  63.          * read the origin high byte data and write again! 
  64.          * modified by yanghao 
  65.      */  
  66.   
  67.     data = 0;  
  68.     for (i=0, cp=wp; i<2 && cnt>0; ++i, ++cp) {  
  69.         data = (data >> 8) | (*src++ << 8);  
  70.         --cnt;  
  71.     }  
  72.     for (; i<2; ++i, ++cp) {  
  73.         data = (data >> 8) | (*(uchar *)cp << 8);  
  74.     }  
  75.   
  76.     return (write_short(info, wp, data));  
  77.   
  78. }  

还需要将flash.c文件中的NOR Flash块大小进行修改:

[cpp]  view plain copy
  1. #define FLASH_BLOCK_SIZE  0x00020000       <span style="font-family:Times New Roman;font-size:16px;">//</span>数据手册<span style="font-family:Times New Roman;">p8</span>说了<span style="font-family:Times New Roman;">32Mbit</span>有<span style="font-family:Times New Roman;">32</span>个<span style="font-family:Times New Roman;">128kBytes block</span>组成  

二、修改开发板头文件中的宏定义

为了添加对NOR Flash启动的支持,还需要在include/configs/fl2440.h头文件中添加对NOR Flash的信息描述和支持,将fl2440.h文件中159行附近:

[cpp]  view plain copy
  1. #define CONFIG_AMD_LV400    1   /* uncomment this if you have a LV400 flash */  
  2. #if 0  
  3. #define CONFIG_AMD_LV800    1   /* uncomment this if you have a LV800 flash */  
  4. #endif  
  5.   
  6. #define CONFIG_SYS_MAX_FLASH_BANKS  1   /* max number of memory banks */  
  7. #ifdef CONFIG_AMD_LV800  
  8. #define PHYS_FLASH_SIZE     0x00100000 /* 1MB */  
  9. #define CONFIG_SYS_MAX_FLASH_SECT   (19)    /* max number of sectors on one chip */  
  10. #define CONFIG_ENV_ADDR     (CONFIG_SYS_FLASH_BASE + 0x0F0000) /* addr of environment */  
  11. #endif  
  12. #ifdef CONFIG_AMD_LV400  
  13. #define PHYS_FLASH_SIZE     0x00080000 /* 512KB */  
  14. #define CONFIG_SYS_MAX_FLASH_SECT   (11)    /* max number of sectors on one chip */  
  15. #define CONFIG_ENV_ADDR     (CONFIG_SYS_FLASH_BASE + 0x070000) /* addr of environment */  
  16. #endif  

全部删除,并修改为:

[cpp]  view plain copy
  1. #define CONFIG_SYS_MAX_FLASH_BANKS  1   /* max number of memory banks */  
  2. #ifdef CONFIG_FL2440  
  3. #define PHYS_FLASH_SIZE     0x00400000 /* 4MB */  
  4. #define CONFIG_SYS_MAX_FLASH_SECT   (32)    /* max number of sectors on one chip */  
  5. #define CONFIG_ENV_ADDR     (CONFIG_SYS_FLASH_BASE + 0x0F0000) /* addr of environment */  
  6. #define CONFIG_SYS_MONITOR_BASE  TEXT_BASE  /*CMI/flash.c need*/  
  7. #define FLASH_BASE0_PRELIM      PHYS_FLASH_1      /*CMI/flash.c need*/  
  8. #endif  

并将文件中

[cpp]  view plain copy
  1. #define CONFIG_ENV_SIZE  0x10000 /* Total Size of Environment   

修改为:

[cpp]  view plain copy
  1. #define CONFIG_ENV_SIZE  0x20000 /* Total Size of Environment   

再执行make,生成的u-boot.bin就可以烧写入NOR Flash中了(可以使用JLINK软件包中的JFlash来完成烧写过程),设置开发板启动方式为NOR Flash启动,再次上电启动NOR Flash就完成u-boot的启动了。

 

source http://blog.csdn.net/yanghao23/article/details/7688301

转载于:https://www.cnblogs.com/andrew-wang/archive/2012/12/05/2803421.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值