U-boot2016.05移植TQ2440之串口輸出實現

uboot下載:ftp://ftp.denx.de/pub/u-boot/

之前習慣性的使用串口燒錄u-boot,可是,在調試這個的時候輸出一直是

因此,改用TFTP燒錄。

之前玩過的u-boot是沒有帶menuconfig這個功能,感覺變了許多。從根目錄的README得知

$ CROSS_COMPILE=ppc_4xx-
$ export CROSS_COMPILE

make NAME_defconfig

If the system board that you have is not listed, then you will need
to port U-Boot to your hardware platform. To do this, follow these
steps:

1.  Create a new directory to hold your board specific code. Add any
    files you need. In your board directory, you will need at least
    the "Makefile" and a "<board>.c".
2.  Create a new configuration file "include/configs/<board>.h" for
    your board.
3.  If you're porting U-Boot to a new CPU, then also create a new
    directory to hold your CPU specific code. Add any files you need.
4.  Run "make <board>_defconfig" with your new name.
5.  Type "make", and you should get a working "u-boot.srec" file
    to be installed on your target system.
6.  Debug and solve any problems that might arise.
    [Of course, this last step is much harder than it sounds.]

由於sc32440是Samsung公司出產的arm920t系列,這個可以從s3c2440的數據手冊得知。搜索了一下這個目錄並沒有s3c2440的相關配置,使用2410代替。

1.  複製2410配置,並修改相關信息

[root@Double u-boot-2016.05]# \cp -rf board/samsung/smdk2410 board/samsung/smdk2440/
需要修改文件 Kconfig lowlevel_init.S MAINTAINERS Makefile smdk2440.c 使用vim打開文件後,全部修改變量。
:%s/2410/2440/g
從MAINTAINERS文件中看出相關聯文件,
  1 SMDK2440 BOARD                                                                                                                  
  2 M:  David Müller <[email protected]>
  3 S:  Maintained
  4 F:  board/samsung/smdk2440/
  5 F:  include/configs/smdk2440.h
  6 F:  configs/smdk2440_defconfig
方法就是在相對應的目錄下以2410爲模版備份一份,並修改文件內的2410爲2440。
文件的運行開始爲u-boot.lds中的_start
#include <config.h>

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
#ifndef CONFIG_CMDLINE
	/DISCARD/ : { *(.u_boot_list_2_cmd_*) }
#endif
...
}
而後跳轉到version.S,由“breset”
_start:

#ifdef CONFIG_SYS_DV_NOR_BOOT_CFG
	.word	CONFIG_SYS_DV_NOR_BOOT_CFG
#endif

	b	reset
	ldr	pc, _undefined_instruction
	ldr	pc, _software_interrupt
	ldr	pc, _prefetch_abort
	ldr	pc, _data_abort
	ldr	pc, _not_used
	ldr	pc, _irq
	ldr	pc, _fiq
在rebet中配置關門狗的寄存器,關閉看門狗。
reset:
.......
#if defined(CONFIG_S3C2440)
#define pWTCON	0x15300000
#define INTMSK	0x14400008	/* Interrupt-Controller base addresses */
#define INTSUBMSK	0x4A00001C
#define CLKDIVN	0x14800014	/* clock divisor register */
#else
#define pWTCON	0x53000000
#define INTMSK	0x4A000008	/* Interrupt-Controller base addresses */
#define CLKDIVN	0x4C000014	/* clock divisor register */
#endif

	ldr	r0, =pWTCON
	mov	r1, #0x0
	str	r1, [r0]
......
#ifndef CONFIG_SKIP_LOWLEVEL_INIT
	bl	cpu_init_crit
#endif

	bl	_main
由於等下使用TFTP將u-boot下載到內存中運行,如果還執行cpu_init_crit函數配置底層的初始化,會造成代碼的丟失,這個觀看衛東山的學習視頻有很清晰的講解。因爲在開頭就 #include <config.h> 因此,在config.h中定義,還有方便調試定義DEBUG變量。
#define CONFIG_SKIP_LOWLEVEL_INIT
#define DEBUG
使用TFTP燒錄。。。
U-Boot 2016.05 (Jul 20 2017 - 21:13:16 +0800)


initcall: 3200f110
U-Boot code: 32000000 -> 3207E780  BSS: -> 320CDD70
initcall: 3200038c
CPUID: 32440001
FCLK:  405.600 MHz
HCLK:  101.400 MHz
PCLK:   50.700 MHz
initcall: 3200f368
DRAM:  initcall: 3200116c
initcall: 3200f2b8
Monitor len: 000CDD70
Ram size: 04000000
Ram top: 34000000
initcall: 3200eeec
initcall: 3200f0b8
TLB table from 33ff0000 to 33ff4000
initcall: 3200ef04
initcall: 3200f06c
Reserving 823k for U-Boot at: 33f22000
initcall: 3200f040
Reserving 4160k for malloc() at: 33b12000
initcall: 3200f26c
memset_count:-1Reserving 80 Bytes for Board Info at: 33b11fb0
initcall: 3200ef0c
initcall: 3200f00c
Reserving 168 Bytes for Global Data at: 33b11f08
initcall: 3200ef94
initcall: 3200ef40
initcall: 3200ef14
initcall: 3200f358
initcall: 3200f1e4


RAM Configuration:
Bank #0: 30000000 64 MiB


DRAM:  64 MiB
initcall: 3200ef78
New Stack Pointer is: 33b11ee0
initcall: 3200f1a8
initcall: 3200f13c
Relocation Offset is: 01f22000
Relocating to 33f22000, new gd at 33b11f08, sp at 33b11ee0
initcall: 33f313e4
initcall: 33f313ec
initcall: 3200f5d0 (relocated to 33f315d0)
WARNING: Caches not enabled
initcall: 3200f404 (relocated to 33f31404)
initcall: 3200f42c (relocated to 33f3142c)
initcall: 3200f5b4 (relocated to 33f315b4)
using memory 0x33b12000-0x33f22000 for malloc()
搜索關鍵字“using memory”定位到dlmalloc.c文件,查看源碼
void mem_malloc_init(ulong start, ulong size)
{
	mem_malloc_start = start;
	mem_malloc_end = start + size;
	mem_malloc_brk = start;


	debug("using memory %#lx-%#lx for malloc()\n", mem_malloc_start,   //using memory 0x33b12000-0x33f22000 for malloc()
	      mem_malloc_end);
#ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT
	memset((void *)mem_malloc_start, 0x0, size);
#endif
	debug("malloc_bin_reloc()   before;\n");
	malloc_bin_reloc();
	debug("malloc_bin_reloc()   after;\n");
}
debug("malloc_bin_reloc() before;\n");和debug("malloc_bin_reloc() after;\n");是我添加上去定位BUG所在位置,結果控制檯的輸出結果依舊沒變。鎖定了錯誤在
memset((void *)mem_malloc_start, 0x0, size); 經計算的出(0x33f22000-0x33b12000=4M)在追到memset源碼
void * memset(void * s,int c,size_t count)
{
	unsigned long *sl = (unsigned long *) s;
	unsigned long cl = 0;
	char *s8;
	int i;
	printf("memset_begin",(int)count);
	/* do it one word at a time (32 bits or 64 bits) while possible */
	if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) {
		for (i = 0; i < sizeof(*sl); i++) {
			cl <<= 8;
			cl |= c & 0xff;
		}
		while (count >= sizeof(*sl)) {
			*sl++ = cl;
			count -= sizeof(*sl);
		}
	}
	/* fill 8 bits at a time */
	s8 = (char *)sl;
	while (count--)
		*s8++ = c;
	return s;
}
具體原因有待深究。
解決方法是:
mem_malloc_init中memset((void *)mem_malloc_start, 0x0, size/2);此處將size的範圍縮小一半可以解決這個BUG。
之後使用TFTP燒錄

EmbedSky> tftp 0x32000000 u-boot.bin;go 0x32000000
dm9000 i/o: 0x20000300, id: 0x90000a46 
MAC: 0a:1b:2c:3d:4e:5f
TFTP from server 192.168.1.135; our IP address is 192.168.1.3
Filename 'u-boot.bin'.
Load address: 0x32000000
Loading: #######################################
done
Bytes transferred = 561056 (88fa0 hex)
## Starting application at 0x32000000 ...
initcall: 3205d30c


U-Boot 2016.05 (Jul 20 2017 - 22:58:10 +0800)

initcall: 3200f110
U-Boot code: 32000000 -> 3207E760  BSS: -> 320CDD70
initcall: 3200038c
CPUID: 32440001
FCLK:  405.600 MHz
HCLK:  101.400 MHz
PCLK:   50.700 MHz
initcall: 3200f368
DRAM:  initcall: 3200116c
initcall: 3200f2b8
Monitor len: 000CDD70
Ram size: 04000000
Ram top: 34000000
initcall: 3200eeec
initcall: 3200f0b8
TLB table from 33ff0000 to 33ff4000
initcall: 3200ef04
initcall: 3200f06c
Reserving 823k for U-Boot at: 33f22000
initcall: 3200f040
Reserving 4160k for malloc() at: 33b12000
initcall: 3200f26c
Reserving 80 Bytes for Board Info at: 33b11fb0
initcall: 3200ef0c
initcall: 3200f00c
Reserving 168 Bytes for Global Data at: 33b11f08
initcall: 3200ef94
initcall: 3200ef40
initcall: 3200ef14
initcall: 3200f358
initcall: 3200f1e4

RAM Configuration:
Bank #0: 30000000 64 MiB

DRAM:  64 MiB
initcall: 3200ef78
New Stack Pointer is: 33b11ee0
initcall: 3200f1a8
initcall: 3200f13c
Relocation Offset is: 01f22000
Relocating to 33f22000, new gd at 33b11f08, sp at 33b11ee0
initcall: 33f313e4
initcall: 33f313ec
initcall: 3200f5d0 (relocated to 33f315d0)
WARNING: Caches not enabled
initcall: 3200f404 (relocated to 33f31404)
initcall: 3200f42c (relocated to 33f3142c)
initcall: 3200f5b4 (relocated to 33f315b4)
using memory 0x33b12000-0x33f22000 for malloc()
malloc_bin_reloc()   before;
malloc_bin_reloc()   after;
initcall: 3200f434 (relocated to 33f31434)
initcall: 3200f3c0 (relocated to 33f313c0)
initcall: 3200f5a0 (relocated to 33f315a0)
initcall: 320011a4 (relocated to 33f231a4)
initcall: 32018164 (relocated to 33f3a164)
initcall: 3200f590 (relocated to 33f31590)
initcall: 3200f4f8 (relocated to 33f314f8)
Now running in RAM - U-Boot at: 33f22000
initcall: 3200f43c (relocated to 33f3143c)
initcall: 3200f514 (relocated to 33f31514)
Flash: fwc addr 00000000 cmd f0 00f0 16bit x 16 bit
fwc addr 0000aaaa cmd aa 00aa 16bit x 16 bit
fwc addr 00005554 cmd 55 0055 16bit x 16 bit
fwc addr 0000aaaa cmd 90 0090 16bit x 16 bit
fwc addr 00000000 cmd f0 00f0 16bit x 16 bit
JEDEC PROBE: ID 1c 2249 0
fwc addr 00000000 cmd ff 00ff 16bit x 16 bit
fwc addr 00000000 cmd 90 0090 16bit x 16 bit
fwc addr 00000000 cmd ff 00ff 16bit x 16 bit
JEDEC PROBE: ID 16 ea00 0
0 Bytes
initcall: 3200f4dc (relocated to 33f314dc)
NAND:  board_nand_init()
end of nand_init
hwcontrol(): 0xff 0x83
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0x90 0x83
hwcontrol(): 0x00 0x85
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0x90 0x83
hwcontrol(): 0x00 0x85
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0x90 0x83
hwcontrol(): 0x40 0x85
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0xffffffff 0x80
0 MiB
initcall: 3200f4ac (relocated to 33f314ac)
*** Warning - bad CRC, using default environment

Destroy Hash Table: 33f9af74 table = 00000000
Create Hash Table: N=75
INSERT: table 33f9af74, filled 1/79 rv 33b12238 ==> name="bootdelay" value="5"
INSERT: table 33f9af74, filled 2/79 rv 33b120f8 ==> name="baudrate" value="115200"
INSERT: table 33f9af74, filled 3/79 rv 33b120a8 ==> name="ipaddr" value="10.0.0.110"
INSERT: table 33f9af74, filled 4/79 rv 33b12260 ==> name="serverip" value="10.0.0.1"
INSERT: table 33f9af74, filled 5/79 rv 33b124f4 ==> name="netmask" value="255.255.255.0"
INSERT: free(data = 33b12008)
INSERT: done
initcall: 3200f3d4 (relocated to 33f313d4)
initcall: 32018224 (relocated to 33f3a224)
initcall: 3200f49c (relocated to 33f3149c)
initcall: 32015d00 (relocated to 33f37d00)
Initial value for argc=3
Final value for argc=3
Initial value for argc=3
Final value for argc=3
Initial value for argc=3
Final value for argc=3
initcall: 32000bb0 (relocated to 33f22bb0)
initcall: 3200f48c (relocated to 33f3148c)
initcall: 3200f46c (relocated to 33f3146c)
initcall: 3200f450 (relocated to 33f31450)
Net:   Initial value for argc=3
Final value for argc=3
CS8900-0
Error: CS8900-0 address not set.

initcall: 3200f444 (relocated to 33f31444)
### main_loop entered: bootdelay=5

### main_loop: bootcmd="<UNDEFINED>"
SMDK2440 # 






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