u-boot-2010.03在LT2440上的移植詳解 (七)

u-boot-2010.03在LT2440上的移植詳解 (七)

鄭重聲明,這系列文章改寫自博客園 黃剛先生的《嵌入式Linux之我行——u-boot-2009.08在2440上的移植詳解》

轉載時請註明出處

文章出處:http://www.lt-net.cn

編譯系統 Ubuntu10.04
交叉編譯器 arm-linux-gcc 4.3.3
硬件設備 LT2440開發板  
測試軟件 u-boot-2010.03
依賴庫
uboot下載地址:http://ftp.denx.de/pub/u-boot/u-boot-2010.03.tar.bz2

本次移植在u-boot-2010.03原有功能的基礎上增加如下特性:

  1.支持2KB  page Nand Flash讀寫
  2.支持Nand/Nor Flash啓動自動識別
  3.支持DM9000AEP 10M/100M自適應網卡
  4.支持yaffs文件系統燒寫
  5.支持USB下載功能
  6.支持一鍵式菜單
  7.支持啓動Logo
  8.支持ubifs(待續)

上接:u-boot-2010.03在LT2440上的移植詳解 (六)

USB  驅動的移植比較麻煩,它涉及到S3C2440的中斷,還有 S3C2440  USB device的驅動
首先我們增加USB device的驅動,驅動有19個文件,
請到下面的鏈接下載
http://blogimg.chinaunix.net/blog/upfile2/101209120345.bz2
解壓之後會有一個device目錄,請將這個目錄放到 drivers/usb目錄下
修改根目錄下Makefile ,加入USB device 驅動的編譯支持

#gedit Makefile  //根目錄下Makefile

LIBS += drivers/usb/phy/libusb_phy.a
LIBS += drivers/usb/device/libusb_device.a   //大約244行
LIBS += drivers/video/libvideo.a
LIBS += drivers/watchdog/libwatchdog.a
還需要一個數據類型定義文件,內容如下,請保存爲def.h 文件,放到 include 目錄下
  1. #ifndef __DEF_H__
  2. #define __DEF_H__
  3. #ifndef U32
  4. #define U32 unsigned int
  5. #endif
  6. #ifndef U16
  7. #define U16 unsigned short
  8. #endif
  9. #ifndef S32
  10. #define S32 int
  11. #endif
  12. #ifndef S16
  13. #define S16 short int
  14. #endif
  15. #ifndef U8
  16. #define U8  unsigned char
  17. #endif
  18. #ifndef S8
  19. #define S8  char
  20. #endif
  21. typedef unsigned char BOOL;
  22. typedef unsigned char UCHAR;
  23. typedef UCHAR *PUCHAR;
  24. typedef unsigned long DWORD;
  25. typedef DWORD *PDWORD;
  26. typedef unsigned long LDWORD;
  27. typedef DWORD *LPDWORD;
  28. typedef unsigned char   BYTE;
  29. typedef unsigned short  WORD;
  30. typedef unsigned long ULONG;
  31. typedef ULONG *PULONG;
  32. typedef unsigned short USHORT;
  33. typedef USHORT *PUSHORT;
  34. typedef BYTE *LPBYTE;
  35. typedef void *PVOID;
  36. typedef  char*          LPSTR;
  37. #ifndef NULL
  38. #define NULL 0
  39. #endif
  40. #define TRUE  1   
  41. #define FALSE  0
  42. #endif /*__DEF_H__*/
複製代碼


現在 include/configs/lt2440.h 添加一個使能USB設備的宏定義並且使能中斷。

#gedit
include/configs/lt2440.h

#define USE_920T_MMU  1 #define CONFIG_USB_DEVICE   1
#ifdef CONFIG_USB_DEVICE
#define CONFIG_USE_IRQ  1
#endif


修改u-boot關於s3c2440的中斷的文件,使其適應LT2440板子要求
gedit cpu/arm920t/s3c24x0/interrupts.c

#gedit cpu/arm920t/s3c24x0/interrupts.c

#if 0
#include <common.h>
#include <asm/arch/s3c24x0_cpu.h>
#include <asm/proc-armv/ptrace.h>
void do_irq (struct pt_regs *pt_regs)
{
struct s3c24x0_interrupt *irq = s3c24x0_get_base_interrupt();
u_int32_t intpnd = readl(&irq->INTPND);
}
#endif


#gedit lib_arm/interrupts.c

int interrupt_init (void)
{
/*
  * setup up stacks if necessary
  */
#ifdef CONFIG_USE_IRQ
IRQ_STACK_START = _armboot_start - CONFIG_SYS_MALLOC_LEN - CONFIG_SYS_GBL_DATA_SIZE - 4;
FIQ_STACK_START = IRQ_STACK_START - CONFIG_STACKSIZE_IRQ;
    FREE_RAM_END = FIQ_STACK_START - CONFIG_STACKSIZE_FIQ - CONFIG_STACKSIZE;
    FREE_RAM_SIZE = FREE_RAM_END - PHYS_SDRAM_1;
#else
   
    FREE_RAM_END = _armboot_start - CFG_MALLOC_LEN - CFG_GBL_DATA_SIZE - 4 - CONFIG_STACKSIZE;
    FREE_RAM_SIZE = FREE_RAM_END - PHYS_SDRAM_1;
#endif
return 0 ;// return  arch_interrupt_init();
}


上面有兩個宏沒有聲明也沒有定義FREE_RAM_END  , FREE_RAM_SIZE 下面給出聲明和定義

#gedit include/asm-arm/u-boot-arm.h

extern ulong IRQ_STACK_START; /* top of IRQ stack */
extern ulong FIQ_STACK_START; /* top of FIQ stack */
extern ulong FREE_RAM_END; /* top of free ram */
extern ulong FREE_RAM_SIZE; /* size of free ram */


#gedit cpu/arm920t/start.S

/*
* These are defined in the board-specific linker script.
*/
.globl _bss_start
_bss_start:
.word __bss_start

.globl _bss_end
_bss_end:
.word _end

.globl FREE_RAM_END
FREE_RAM_END:
.word 0x0badc0de

.globl FREE_RAM_SIZE
FREE_RAM_SIZE:
.word 0x0badc0de


#gedit   lib_arm/bootm.c

#ifdef CONFIG_USB_DEVICE
{
  extern void udc_disconnect (void);
  //
udc_disconnect (); //註釋掉這一行
}
#endif


#gedit lib_arm/board.c

/* enable exceptions */  // 約388行
Port_Init();
enable_interrupts ();
usb_init();


這些做好了之後,USB驅動已經可以正常加載了,下面加入USB下載的命令

#gedit common/cmd_usbslave.c

#include <common.h>
#include <command.h>
#include <asm/byteorder.h>
#include <def.h>

#ifdef CONFIG_USB_DEVICE

int g_bUSBWait = 1;
u32 g_dwDownloadLen = 0;
extern int download_run;
extern volatile U32 dwUSBBufBase;
extern volatile u32 dwUSBBufSize;
extern __u32 usb_receive(char *buf, size_t len, U32 wait);

int do_usbslave (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
    int i;
    size_t len = ~0UL;
    char buf[32];
    download_run = 1;
    switch (argc) {
        case 1:
        {
            break;
        }
        case 2:
        {
            g_bUSBWait = (int)simple_strtoul(argv[1], NULL, 16);
            break;
        }

        case 3:
        {
            g_bUSBWait = (int)simple_strtoul(argv[1], NULL, 16);
            load_addr = simple_strtoul(argv[2], NULL, 16);
            download_run = 0;
            break;
        }
        
        default:
        {
            printf ("Usage:/n%s/n", cmdtp->usage);
      return 1;
        }
    }

    dwUSBBufBase = load_addr;  
    dwUSBBufSize = (FREE_RAM_SIZE&(~(0x80000-1)));  
    if (g_bUSBWait)
        len = FREE_RAM_SIZE;

    g_dwDownloadLen = usb_receive(dwUSBBufBase, len, g_bUSBWait);
    sprintf(buf, "%X", g_dwDownloadLen);
    setenv("filesize", buf);
   
return 0;
}

U_BOOT_CMD(
usbslave, 3, 0, do_usbslave,
"usbslave - get file from host(PC)/n",
"[wait] [loadAddress]/n"
"/"wait/" is 0 or 1, 0 means for return immediately, not waits for the finish of transferring/n"
);

#endif


修改common目錄下Makefile

#gedit common/Makefile

//在約155行加入下面一句

COBJS-y += cmd_usbslave.o


s3c2440 USB控制器與s3c2410有區別,還有多了一個GPIO口 J 口,安裝下面修改,增加支持

#gedit include/asm-arm/arch-s3c24x0/s3c24x0.h

struct s3c24x0_usb_device {
#ifdef __BIG_ENDIAN
u8 res1[3];
u8 FUNC_ADDR_REG;
u8 res2[3];
u8 PWR_REG;
u8 res3[3];
u8 EP_INT_REG;
u8 res4[15];
u8 USB_INT_REG;
u8 res5[3];
u8 EP_INT_EN_REG;
u8 res6[15];
u8 USB_INT_EN_REG;
u8 res7[3];
u8 FRAME_NUM1_REG;
u8 res8[3];
u8 FRAME_NUM2_REG;
u8 res9[3];
u8 INDEX_REG;
u8 res10[7];
u8 MAXP_REG;
u8 res11[3];
u8 EP0_CSR_IN_CSR1_REG;
u8 res12[3];
u8 IN_CSR2_REG;
u8 res13[7];
u8 OUT_CSR1_REG;
u8 res14[3];
u8 OUT_CSR2_REG;
u8 res15[3];
u8 OUT_FIFO_CNT1_REG;
u8 res16[3];
u8 OUT_FIFO_CNT2_REG;
#else /*  little endian */
u8 FUNC_ADDR_REG;
u8 res1[3];
u8 PWR_REG;
u8 res2[3];
u8 EP_INT_REG;
u8 res3[15];
u8 USB_INT_REG;
u8 res4[3];
u8 EP_INT_EN_REG;
u8 res5[15];
u8 USB_INT_EN_REG;
u8 res6[3];
u8 FRAME_NUM1_REG;
u8 res7[3];
u8 FRAME_NUM2_REG;
u8 res8[3];
u8 INDEX_REG;
u8 res9[7];
u8 MAXP_REG;
u8 res10[3];
u8 EP0_CSR_IN_CSR1_REG;
u8 res11[3];
u8 IN_CSR2_REG;
u8 res12[7];
u8 OUT_CSR1_REG;
u8 res13[3];
u8 OUT_CSR2_REG;
u8 res14[3];
u8 OUT_FIFO_CNT1_REG;
u8 res15[3];
u8 OUT_FIFO_CNT2_REG;
u8 res16[3];
#endif /*  __BIG_ENDIAN */
u32 res17[8];
  struct s3c24x0_usb_dev_fifos fifo[5];
u32 res18[11];
struct s3c24x0_usb_dev_dmas ep1;
struct s3c24x0_usb_dev_dmas ep2;
u8 res19[16];
struct s3c24x0_usb_dev_dmas ep3;
struct s3c24x0_usb_dev_dmas ep4;
};


//增加J口支持

/* I/O PORT (see manual chapter 9) */
struct s3c24x0_gpio {
#ifdef CONFIG_S3C2400
u32 PACON;
u32 PADAT;

u32 PBCON;
u32 PBDAT;
u32 PBUP;

u32 PCCON;
u32 PCDAT;
u32 PCUP;

u32 PDCON;
u32 PDDAT;
u32 PDUP;

u32 PECON;
u32 PEDAT;
u32 PEUP;

u32 PFCON;
u32 PFDAT;
u32 PFUP;

u32 PGCON;
u32 PGDAT;
u32 PGUP;

u32 OPENCR;

u32 MISCCR;
u32 EXTINT;
#endif
#ifdef CONFIG_S3C2410
u32 GPACON;
u32 GPADAT;
u32 res1[2];
u32 GPBCON;
u32 GPBDAT;
u32 GPBUP;
u32 res2;
u32 GPCCON;
u32 GPCDAT;
u32 GPCUP;
u32 res3;
u32 GPDCON;
u32 GPDDAT;
u32 GPDUP;
u32 res4;
u32 GPECON;
u32 GPEDAT;
u32 GPEUP;
u32 res5;
u32 GPFCON;
u32 GPFDAT;
u32 GPFUP;
u32 res6;
u32 GPGCON;
u32 GPGDAT;
u32 GPGUP;
u32 res7;
u32 GPHCON;
u32 GPHDAT;
u32 GPHUP;
u32 res8;

u32 MISCCR;
u32 DCLKCON;
u32 EXTINT0;
u32 EXTINT1;
u32 EXTINT2;
u32 EINTFLT0;
u32 EINTFLT1;
u32 EINTFLT2;
u32 EINTFLT3;
u32 EINTMASK;
u32 EINTPEND;
u32 GSTATUS0;
u32 GSTATUS1;
u32 GSTATUS2;
u32 GSTATUS3;
u32 GSTATUS4;

#if defined (CONFIG_S3C2440)
u32 res9[3];
u32 MSLCON;
u32 GPJCON;
u32 GPJDAT;
u32 GPJUP;

#endif
#endif
};



#gedit include/asm-arm/arch-s3c24x0/s3c24x0.h

//在文件末尾增加下面定義
#define _ISR_STARTADDRESS   ((unsigned)isr_handle_array)
#define ISR_EINT0_OFT     0
#define ISR_EINT1_OFT     1
#define ISR_EINT2_OFT     2
#define ISR_EINT3_OFT     3
#define ISR_EINT4_7_OFT   4
#define ISR_EINT8_23_OFT  5
#define ISR_NOTUSED6_OFT  6
#define ISR_BAT_FLT_OFT   7
#define ISR_TICK_OFT      8
#define ISR_WDT_OFT       9
#define ISR_TIMER0_OFT    10
#define ISR_TIMER1_OFT    11
#define ISR_TIMER2_OFT    12
#define ISR_TIMER3_OFT    13
#define ISR_TIMER4_OFT    14
#define ISR_UART2_OFT     15
#define ISR_LCD_OFT       16
#define ISR_DMA0_OFT      17
#define ISR_DMA1_OFT      18
#define ISR_DMA2_OFT      19
#define ISR_DMA3_OFT      20
#define ISR_SDI_OFT       21
#define ISR_SPI0_OFT      22
#define ISR_UART1_OFT     23
#define ISR_NOTUSED24_OFT 24
#define ISR_USBD_OFT      25
#define ISR_USBH_OFT      26
#define ISR_IIC_OFT       27
#define ISR_UART0_OFT     28
#define ISR_SPI1_OFT      29
#define ISR_RTC_OFT       30
#define ISR_ADC_OFT       31


#endif /*__S3C2410_H__*/

#gedit cpu/arm920t/s3c24x0/Makefile
//註釋掉如下兩行,它與USB device 驅動衝突
COBJS-y += speed.o
COBJS-y += timer.o
#COBJS-y += usb.o
#COBJS-y += usb_ohci.o

重新編譯,重新燒寫u-boot。重啓LT2440開發板,可以使用 usbslave 命令傳輸文件了
有兩個格式:
#  usbslave                            //下載到板子內存的地址由DNW決定
#  usbslave  1 0x30000000  //下載到板子內存的地址由後面的地址參數決定
打開DNW,可以發現USB已經OK了
 


下面使用usbslave命令做測試,下載Linux內核

LT2440 # usbslave 1 0x30000000
USB host is connected. Waiting a download.
Now, Downloading [ADDRESS:30000000h,TOTAL:2223646]
RECEIVED FILE SIZE: 2223646 (723KB/S, 3S)
LT2440 #


說明USB功能調試成功,可以使用USB device傳輸數據了

下接:u-boot-2010.03在LT2440上的移植詳解 (八)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章