移植u-boot-2012.04.01到jz2440开发板
今天我給大家分享一下如何移植一個純凈的uboot到jz2440開發大版,通過記錄學習分享,與大家一起進步!!!
1.首先我們在uboot官網下載u-boot-2012.04.01.tar.bz2,建立source insight工程。將下載好的uboot通過FTP服務器傳送到虛擬機中的linux系統下。
解壓uboot:
tar xjf u-boot-2012.04.01.tar.bz2
cd u-boot-2012.04.01
make smdk2410_config
make
將得到的u-boot.bin文件下載到開發板(下載方式不唯一),連接至串口,發現沒有輸出。所以我們下載的uboot不支持我們的jz2440開發板,我們接下來應該通過修改uboot源碼使它支持我們的開發板。
2.分析u-boot: 得知大概的啟動過程如下:
-初始化硬件:關看門狗、設置時鐘、設置SDRAM、初始化NAND FLASH
-如果bootloader較大,要把它重定位到SDRAM
-把內核從NAND FLASH 讀到 SDRAM
-設置“設置要傳給內核的參數”
-跳轉要執行的內核
3.修改U-BOOT代碼
3.1 建一個單板
cd board/samsung/
cp smdk2410 smdk2440 -rf
cd ../../include/configs/
cp smdk2410.h smdk2440.h
修改boards.cfg:
仿照:
smdk2410 arm arm920t - samsung s3c24x0
添加:
smdk2440 arm arm920t - samsung s3c24x0
重新編譯燒寫看結果:串口還是沒有輸出.
閱讀代碼發現不足:UBOOT里先以60MHZ的時鐘計算參數來設置內存控制器,但是MPLL還未設置
處理措施:把MPLL的設置放到start.S里,取消board_early_init_f里對MPLL的設置
操作如下:
在uboot中的start.s中170行有代碼如下:
這是設置時鐘的,我們將這一部分刪掉,然后換成如下代碼:
/* 2. 設置時鐘 */ldr r0, =0x4c000014// mov r1, #0x03; // FCLK:HCLK:PCLK=1:2:4, HDIVN=1,PDIVN=1mov r1, #0x05; // FCLK:HCLK:PCLK=1:4:8str r1, [r0]/* 如果HDIVN非0,CPU的總線模式應該從“fast bus mode”變為“asynchronous bus mode” */mrc p15, 0, r1, c1, c0, 0 /* 讀出控制寄存器 */ orr r1, r1, #0xc0000000 /* 設置為“asynchronous bus mode” */mcr p15, 0, r1, c1, c0, 0 /* 寫入控制寄存器 */#define S3C2440_MPLL_400MHZ ((0x5c<<12)|(0x01<<4)|(0x01))/* MPLLCON = S3C2440_MPLL_200MHZ */ldr r0, =0x4c000004ldr r1, =S3C2440_MPLL_400MHZstr r1, [r0]/* 啟動ICACHE */mrc p15, 0, r0, c1, c0, 0 @ read control regorr r0, r0, #(1<<12)mcr p15, 0, r0, c1, c0, 0 @ write it back在lowlevel_init.S中最后有如下代碼:
SMRDATA:.word (0+(B1_BWSCON<<4)+(B2_BWSCON<<8)+(B3_BWSCON<<12)+(B4_BWSCON<<16)+(B5_BWSCON<<20)+(B6_BWSCON<<24)+(B7_BWSCON<<28)).word ((B0_Tacs<<13)+(B0_Tcos<<11)+(B0_Tacc<<8)+(B0_Tcoh<<6)+(B0_Tah<<4)+(B0_Tacp<<2)+(B0_PMC)).word ((B1_Tacs<<13)+(B1_Tcos<<11)+(B1_Tacc<<8)+(B1_Tcoh<<6)+(B1_Tah<<4)+(B1_Tacp<<2)+(B1_PMC)).word ((B2_Tacs<<13)+(B2_Tcos<<11)+(B2_Tacc<<8)+(B2_Tcoh<<6)+(B2_Tah<<4)+(B2_Tacp<<2)+(B2_PMC)).word ((B3_Tacs<<13)+(B3_Tcos<<11)+(B3_Tacc<<8)+(B3_Tcoh<<6)+(B3_Tah<<4)+(B3_Tacp<<2)+(B3_PMC)).word ((B4_Tacs<<13)+(B4_Tcos<<11)+(B4_Tacc<<8)+(B4_Tcoh<<6)+(B4_Tah<<4)+(B4_Tacp<<2)+(B4_PMC)).word ((B5_Tacs<<13)+(B5_Tcos<<11)+(B5_Tacc<<8)+(B5_Tcoh<<6)+(B5_Tah<<4)+(B5_Tacp<<2)+(B5_PMC)).word ((B6_MT<<15)+(B6_Trcd<<2)+(B6_SCAN)).word ((B7_MT<<15)+(B7_Trcd<<2)+(B7_SCAN)).word ((REFEN<<23)+(TREFMD<<22)+(Trp<<20)+(Trc<<18)+(Tchr<<16)+REFCNT).word 0x32.word 0x30.word 0x30將其刪掉改為:
.long 0x22011110 //BWSCON.long 0x00000700 //BANKCON0.long 0x00000700 //BANKCON1.long 0x00000700 //BANKCON2.long 0x00000700 //BANKCON3 .long 0x00000700 //BANKCON4.long 0x00000700 //BANKCON5.long 0x00018005 //BANKCON6.long 0x00018005 //BANKCON7.long 0x008C04F4 // REFRESH.long 0x000000B1 //BANKSIZE.long 0x00000030 //MRSRB6.long 0x00000030 //MRSRB7重新編譯燒寫看看什么情況:編譯燒寫成功,啟動串口,輸出打印亂碼如下(至少有打印了,說明我們已經成功了第一步,哈哈哈):
3.1下面解決串口打印亂碼問題:
查看串口波特率的設置,在arch\arm\lib中有函數board_init_f,其中有一個結構體init_sequence:
跳轉到這個結構體:
init_fnc_t *init_sequence[] = { #if defined(CONFIG_ARCH_CPU_INIT)arch_cpu_init, /* basic arch cpu dependent setup */ #endif #if defined(CONFIG_BOARD_EARLY_INIT_F)board_early_init_f, #endif #ifdef CONFIG_OF_CONTROLfdtdec_check_fdt, #endiftimer_init, /* initialize timer */ #ifdef CONFIG_FSL_ESDHCget_clocks, #endifenv_init, /* initialize environment */init_baudrate, /* initialze baudrate settings */serial_init, /* serial communications setup */console_init_f, /* stage 1 init of console */display_banner, /* say that we are here */ #if defined(CONFIG_DISPLAY_CPUINFO)print_cpuinfo, /* display cpu info (and speed) */ #endif #if defined(CONFIG_DISPLAY_BOARDINFO)checkboard, /* display board info */ #endif #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)init_func_i2c, #endifdram_init, /* configure available RAM banks */NULL, };里面是各種初始化,找到串口初始化:serial_init,跳轉到這里:
int serial_init(void) {return serial_init_dev(UART_NR); } #endif然后跳轉到這里:serial_init_dev
/* Initialise the serial port. The settings are always 8 data bits, no parity,* 1 stop bit, no start bits.*/ static int serial_init_dev(const int dev_index) {struct s3c24x0_uart *uart = s3c24x0_get_base_uart(dev_index);#ifdef CONFIG_HWFLOWhwflow = 0; /* turned off by default */ #endif/* FIFO enable, Tx/Rx FIFO clear */writel(0x07, &uart->ufcon);writel(0x0, &uart->umcon);/* Normal,No parity,1 stop,8 bit */writel(0x3, &uart->ulcon);/** tx=level,rx=edge,disable timeout int.,enable rx error int.,* normal,interrupt or polling*/writel(0x245, &uart->ucon);#ifdef CONFIG_HWFLOWwritel(0x1, &uart->umcon); /* rts up */ #endif/* FIXME: This is sooooooooooooooooooo ugly */ #if defined(CONFIG_ARCH_GTA02_v1) || defined(CONFIG_ARCH_GTA02_v2)/* we need auto hw flow control on the gsm and gps port */if (dev_index == 0 || dev_index == 1)writel(0x10, &uart->umcon); #endif_serial_setbrg(dev_index);return (0); }然后跳轉到這里:_serial_setbrg
void _serial_setbrg(const int dev_index)
{
struct s3c24x0_uart *uart = s3c24x0_get_base_uart(dev_index);
unsigned int reg = 0;
int i;
}
跳轉到:get_PCLK
跳轉到這里:get_HCLK
ulong get_HCLK(void) {struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power(); #ifdef CONFIG_S3C2440switch (readl(&clk_power->clkdivn) & 0x6) {default:case 0:return get_FCLK();case 2:return get_FCLK() / 2;case 4:return (readl(&clk_power->camdivn) & (1 << 9)) ?get_FCLK() / 8 : get_FCLK() / 4;case 6:return (readl(&clk_power->camdivn) & (1 << 8)) ?get_FCLK() / 6 : get_FCLK() / 3;}我們會發現#ifdef CONFIG_S3C2440 這一句是黑色的,說明沒有定義這個CONFIG_S3C2440,
處理措施:
在include/configs/smdk2440.h: 去掉CONFIG_S3C2410 ,換成CONFIG_S3C2440
#define CONFIG_S3C2440
定義好這個之后,重新編譯,發現編譯有錯誤如下:
錯誤顯示有大量關于nand的錯誤,猜想原因應該是此uboot暫時不支持該單板,我決定先把nand去掉,先看看串口是否可以正常打印出不是亂碼的消息,之后再加入nand的支持,要一步一步來嘛!我們把關于nand的編譯選項去掉,查看/drivers/mtd/nand/Makefile,找到只一句:
COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o
說明編譯s3c2410_nand.c以來的定義是:CONFIG_NAND_S3C2410,在源碼中搜索CONFIG_NAND_S3C2410,在smdk2440.h中找到:
說明定義了CONFIG_CMD_NAND則CONFIG_NAND_S3C2410就被定義,我們只需要讓CONFIG_CMD_NAND不被定義即可,搜索到如下:
#define CONFIG_CMD_NAND
將其改為:
//#define CONFIG_CMD_NAND
重新編譯,沒有出現錯誤,燒寫測試串口輸出為:
哈哈哈!!!!,串口終于輸出而且不是亂碼了,我們已經走出了第一步,接下來就是讓它支持nand flash了,也不是容易的事情啊,已經寫了這么多了,就放到下一篇 博客中吧!!!
想跟我一起交流學的加我
qq:1126137994
二維碼:
微信:liu1126137994
二維碼:
備注:交流學習哦
另外我這里有大量的學習資料,以及現成的項目的經驗總結,歡迎叨擾!!!
總結
以上是生活随笔為你收集整理的移植u-boot-2012.04.01到jz2440开发板的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: db2 版本发布历史_数据库各厂商的发展
- 下一篇: 计算机的电子报表模板,Excel记账本