歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> FL2440的U-boot-2010.09移植(四) 添加NOR FLash啟動支持

FL2440的U-boot-2010.09移植(四) 添加NOR FLash啟動支持

日期:2017/3/1 10:18:21   编辑:Linux編程
我們知道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修改如下:

相關閱讀:

U-Boot源代碼下載地址 http://www.linuxidc.com/Linux/2011-07/38897.htm

FL2440的U-boot-2010.09移植(一)http://www.linuxidc.com/Linux/2012-06/63755.htm
FL2440的U-boot-2010.09移植(二)http://www.linuxidc.com/Linux/2012-06/63756.htm
FL2440的U-boot-2010.09移植(三)DM9000網卡及開發板相關配置 http://www.linuxidc.com/Linux/2012-07/64155.htm
FL2440的U-boot-2010.09移植(四) 添加NOR FLash啟動支持 http://www.linuxidc.com/Linux/2012-07/64156.htm
FL2440的U-boot-2010.09移植(五)uboot架構中NAND FLash驅動修改 http://www.linuxidc.com/Linux/2012-07/64157.htm
FL2440的U-boot-2010.09移植(六)NAND FLash啟動支持 http://www.linuxidc.com/Linux/2012-07/641587.htm
FL2440的U-boot-2010.09移植(七)LCD的支持 http://www.linuxidc.com/Linux/2012-07/641587.htm
針對FL2440開發板的u-boot-2010.09版本補丁 http://www.linuxidc.com/Linux/2012-07/64116.htm

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

還需要將flash.c文件中的NOR Flash塊大小進行修改:

  1. #define FLASH_BLOCK_SIZE 0x00020000 //數據手冊p8說了32Mbit有32個128kBytes block組成
Copyright © Linux教程網 All Rights Reserved