【Linux 移植 】——3、移植 u-boot-2012.04.01 之 修改代码(时钟,SDRAM,UART)

时间:2022-09-27 16:34:36

(韦东山毕业班视频)


二、移植 u-boot.2012.04.01 之修改代码(时钟、SDRAM,UART)

1、新 建一个单板

<pre name="code" class="cpp">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


 
<span style="font-size: 12px; font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">2 、烧写看结果,不成功</span>

make smdk2440_config
make
成功生成的u-boot.bin并不能让TQ2440启动


3 、调试: 

a. 阅读代码发现不足:UBOOT里先以60MHZ的时钟计算参数来设置内存控制器,但是MPLL还未设置处理措施: 把MPLL的设置放到start.S里,取消board_early_init_f里对MPLL的设置

int board_early_init_f(void)
{
	struct s3c24x0_clock_power * const clk_power =
					s3c24x0_get_base_clock_power();
	struct s3c24x0_gpio * const gpio = s3c24x0_get_base_gpio();

	/* to reduce PLL lock time, adjust the LOCKTIME register */
	//writel(0xFFFFFF, &clk_power->locktime);  取消

	/* configure MPLL */
	//writel((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV,  取消
	 //      &clk_power->mpllcon);  取消

	/* some delay between MPLL and UPLL */
	pll_delay(4000);

	/* configure UPLL */
	writel((U_M_MDIV << 12) + (U_M_PDIV << 4) + U_M_SDIV,
	       &clk_power->upllcon);


 /* 2. 设置时钟 */
	ldr r0, =0x4c000014
	//	mov r1, #0x03;			  // FCLK:HCLK:PCLK=1:2:4, HDIVN=1,PDIVN=1
	mov r1, #0x05;			  // FCLK:HCLK:PCLK=1:4:8
	str 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, =0x4c000004
	ldr r1, =S3C2440_MPLL_400MHZ
	str r1, [r0]

	/* 启动ICACHE */
	mrc p15, 0, r0, c1, c0, 0	@ read control reg
	orr r0, r0, #(1<<12)
	mcr	p15, 0, r0, c1, c0, 0   @ write it back


   
   编译出来的uboot非常大,可以先烧写主光盘里的u-boot.bin到nor,然后用这个uboot来烧写新的uboot !我是用Jlink-Flasher 烧写的,就没有像韦东山老师那样!下面是烧写结果:

【Linux 移植 】——3、移植 u-boot-2012.04.01 之 修改代码(时钟,SDRAM,UART)


4、 乱码,查看串口波特率的设置,发现在get_HCLK里没有定义CONFIG_S3C2440

board.c (z:\u-boot-2012.04.01\arch\arm\lib\Board.c)
               serial_init(z:\u-boot-2012.04.01\drivers\serial\Serial_s3c24x0.c)
                   serial_init_dev
                          _serial_setbrg
                                 get_PCLK(z:\u-boot-2012.04.01\arch\arm\cpu\arm920t\s3c24x0\Speed.c)
                                        get_HCLK
                                        发现没有定义CONFIG_S3C2440,它用2410的那套

    处理措施:include/configs/smdk2440.h: 去掉CONFIG_S3C2410
                                          #define CONFIG_S3C2440

                                          //#define CONFIG_CMD_NAND


更改之后重新 make ,发现如下问题:

s3c2410_nand.c: In function 's3c2410_hwcontrol':
s3c2410_nand.c:57: warning: implicit declaration of function 's3c2410_get_base_nand'
s3c2410_nand.c:57: warning: initialization makes pointer from integer without a cast
s3c2410_nand.c:72: error: dereferencing pointer to incomplete type
s3c2410_nand.c:72: error: dereferencing pointer to incomplete type
s3c2410_nand.c:75: error: dereferencing pointer to incomplete type
s3c2410_nand.c:75: error: dereferencing pointer to incomplete type
s3c2410_nand.c: In function 's3c2410_dev_ready':
s3c2410_nand.c:85: warning: initialization makes pointer from integer without a cast
s3c2410_nand.c:87: error: dereferencing pointer to incomplete type
s3c2410_nand.c: In function 'board_nand_init':
s3c2410_nand.c:129: warning: initialization makes pointer from integer without a cast
s3c2410_nand.c:150: error: dereferencing pointer to incomplete type
s3c2410_nand.c:153: error: dereferencing pointer to incomplete type
s3c2410_nand.c:154: error: dereferencing pointer to incomplete type
make[1]: *** [s3c2410_nand.o] Error 1
make[1]: Leaving directory `/work/tools/u-boot-2012.04.01/drivers/mtd/nand'
make: *** [drivers/mtd/nand/libnand.o] Error 2

 s3c2410_nand.c找错误,发现是因为更改了#define CONFIG_S3C2440后,s3c2410_nand未定义

  暂且先让串口输出正常看看,去掉nand支持。

现取消CONFIG_NAND_S3C2410的定义,在smdk2440.h中发现
   #ifdef CONFIG_CMD_NAND
   #define CONFIG_NAND_S3C2410
   #define CONFIG_SYS_S3C2410_NAND_HWECC
   #define CONFIG_SYS_MAX_NAND_DEVICE	1
   #define CONFIG_SYS_NAND_BASE	0x4E000000
   #endif
   则注释掉//#define CONFIG_CMD_NAND
再次 make,有时会出现:
<pre name="code" class="cpp">fs/yaffs2/libyaffs2.o: In function `yaffs_StartUp':
   /home/profiles/u-boot-2012.04.01/fs/yaffs2/yaffscfg.c:210: undefined reference to `nand_info'
为什么有的时候 make 就会出现,有的时候没有,我也不是特别清楚!如果出现的话 在smdk2440.h 中   //#define CONFIG_YAFFS2,记得编译之前要make distclean下,不然修改没生效。
 
将生成的 u-boot.bin 烧写后,<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);">串口打印正常:</span>

【Linux 移植 】——3、移植 u-boot-2012.04.01 之 修改代码(时钟,SDRAM,UART)


5、修改设置 BWSCON 的SMRDATA (lowlevel_init.S)

<pre name="code" class="cpp">        .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