您尚未登录。

楼主 # 2021-07-08 12:25:51

shawn.d
会员
注册时间: 2020-09-12
已发帖子: 147
积分: 137.5

f1c100s 裸机IAP调试不能正常工作,请大佬帮忙看看呗

boot使用的是这个例子, https://whycan.com/t_3645.html

于是想在这个boot上改个IAP,我修改了start.S,如下

 

/*
 * Exception vector table
 */
.text

	.arm

	.global	_start
_start:
	/* Boot head information for BROM */
	//.long 0xea000016
	//.byte 'e', 'G', 'O', 'N', '.', 'B', 'T', '0'
	//.long 0, __bootloader_size
	//.byte 'S', 'P', 'L', 2
	//.long 0, 0
	//.long 0, 0, 0, 0, 0, 0, 0, 0
	//.long 0, 0, 0, 0, 0, 0, 0, 0	/* 0x40 - boot params, 0x58 - fel boot type, 0x5c - dram size */

_vector:
	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

_undefined_instruction:
	.word undefined_instruction
_software_interrupt:
	.word software_interrupt
_prefetch_abort:
	.word prefetch_abort
_data_abort:
	.word data_abort
_not_used:
	.word not_used
_irq:
	.word irq
_fiq:
	.word fiq

/*
 * The actual reset code
 */
reset:



	/* Save boot params to 0x00000040 */
	//ldr r0, =0x00000040
	//str sp, [r0, #0]
	//str lr, [r0, #4]
	//mrs lr, cpsr
	//str lr, [r0, #8]
	//mrc p15, 0, lr, c1, c0, 0
	//str lr, [r0, #12]
	//mrc p15, 0, lr, c1, c0, 0
	//str lr, [r0, #16]

	/* Check boot type just for fel */
//	mov r0, #0x0
//	ldr r1, [r0, #8]
//	ldr r2, =0x4c45462e
//	cmp r1, r2
//	bne 1f
//	ldr r1, =0x1
//	str r1, [r0, #0x58]
//1:	nop

	/* Enter svc mode and mask interrupts */
//	mrs r0, cpsr
//	bic r0, r0, #0x1f
//	orr r0, r0, #0xd3
//	msr cpsr, r0

	/* Set vector to the low address */
	mrc p15, 0, r0, c1, c0, 0
	bic r0, #(1<<13)
	mcr p15, 0, r0, c1, c0, 0

	/* Copy vector to the correct address */
	adr r0, _vector
	mrc p15, 0, r2, c1, c0, 0
	ands r2, r2, #(1 << 13)
	ldreq r1, =0x00000000
	ldrne r1, =0xffff0000
	ldmia r0!, {r2-r8, r10}
	stmia r1!, {r2-r8, r10}
	ldmia r0!, {r2-r8, r10}
	stmia r1!, {r2-r8, r10}

	/* Initial system clock, ddr add uart */
//	bl sys_clock_init
//	bl sys_dram_init
//	bl sys_uart_init

	/* Boot speed up, leave slower sram */
//	adr r0, _start
//	ldr r1, =_start
//	cmp r0, r1
//	beq _speedup
//	ldr r0, =0x81f80000
//	adr r1, _start
//	mov r2, #0x4000
//	bl memcpy
//	ldr r0, =_speedup
//	ldr r1, =_start
//	sub r0, r0, r1
//	ldr r1, =0x81f80000
//	add r0, r0, r1
//	mov pc, r0
//_speedup:
//	nop

	/* Copyself to link address */
//	adr r0, _start
//	ldr r1, =_start
//	cmp r0, r1
//	beq 1f
//	bl sys_copyself
//1:	nop

	/* Initialize stacks */
	mrs r0, cpsr
	bic r0, r0, #0x1f
	orr r1, r0, #0x1b
	msr cpsr_cxsf, r1
	ldr sp, _stack_und_end

	bic r0, r0, #0x1f
	orr r1, r0, #0x17
	msr cpsr_cxsf, r1
	ldr sp, _stack_abt_end

	bic r0, r0, #0x1f
	orr r1, r0, #0x12
	msr cpsr_cxsf, r1
	ldr sp, _stack_irq_end

	bic r0, r0, #0x1f
	orr r1, r0, #0x11
	msr cpsr_cxsf, r1
	ldr sp, _stack_fiq_end

	bic r0, r0, #0x1f
	orr r1, r0, #0x1f
	msr cpsr_cxsf, r1
	ldr sp, _stack_usr_end

	bic r0, r0, #0x1f
	orr r1, r0, #0x13
	msr cpsr_cxsf, r1
	ldr sp, _stack_srv_end
	
	

	/* Copy data section */
	ldr r0, _data_start
	ldr r1, _data_shadow_start
	ldr r2, _data_shadow_end
	sub r2, r2, r1
	bl memcpy

	/* Clear bss section */
	ldr r0, _bss_start
	ldr r2, _bss_end
	sub r2, r2, r0
	mov r1, #0
	bl memset

	/* Call _main */
	ldr r1, =_main
	mov pc, r1
_main:
	mov r0, #1;
	mov r1, #0;
	bl boot_main
	b _main

//	.global return_to_fel
//return_to_fel:
//	mov r0, #0x4
//	mov r1, #'e'
//	strb r1, [r0, #0]
//	mov r1, #'G'
//	strb r1, [r0, #1]
//	mov r1, #'O'
//	strb r1, [r0, #2]
//	mov r1, #'N'
//	strb r1, [r0, #3]
//	mov r1, #'.'
//	strb r1, [r0, #4]
//	mov r1, #'F'
//	strb r1, [r0, #5]
//	mov r1, #'E'
//	strb r1, [r0, #6]
//	mov r1, #'L'
//	strb r1, [r0, #7]
//	ldr r0, =0x00000040
//	ldr sp, [r0, #0]
//	ldr lr, [r0, #4]
//	ldr r1, [r0, #16]
//	mcr p15, 0, r1, c1, c0, 0
//	ldr r1, [r0, #12]
//	mcr p15, 0, r1, c1, c0, 0
//	ldr r1, [r0, #8]
//	msr cpsr, r1
//	bx lr

/*
 * Exception handlers
 */
	.align 5
undefined_instruction:
	b .

	.align 5
software_interrupt:
	b .

	.align 5
prefetch_abort:
	b .

	.align 5
data_abort:
	b .

	.align 5
not_used:
	b .

	.align 5
irq:
	ldr sp, _stack_irq_end
	sub sp, sp, #72
	stmia sp, {r0 - r12}
	add r8, sp, #60
	stmdb r8, {sp, lr}^
	str lr, [r8, #0]
	mrs r6, spsr
	str r6, [r8, #4]
	str r0, [r8, #8]
	mov r0, sp
	bl arm32_do_irq
	ldmia sp, {r0 - lr}^
	mov r0, r0
	ldr lr, [sp, #60]
	add sp, sp, #72
	subs pc, lr, #4

	.align 5
fiq:
	ldr sp, _stack_irq_end
	sub sp, sp, #72
	stmia sp, {r0 - r12}
	add r8, sp, #60
	stmdb r8, {sp, lr}^
	str lr, [r8, #0]
	mrs r6, spsr
	str r6, [r8, #4]
	str r0, [r8, #8]
	mov r0, sp
	bl arm32_do_fiq
	ldmia sp, {r0 - lr}^
	mov r0, r0
	ldr lr, [sp, #60]
	add sp, sp, #72
	subs pc, lr, #4

/*
 * The location of section
 */
 	.align 4
//_image_start:
//	.long __image_start
//_image_end:
//	.long __image_end
_data_shadow_start:
	.long __data_shadow_start
_data_shadow_end:
	.long __data_shadow_end
_data_start:
	.long __data_start
_data_end:
	.long __data_end
_bss_start:
	.long __bss_start
_bss_end:
	.long __bss_end
_stack_usr_end:
	.long __stack_usr_end
_stack_und_end:
	.long __stack_und_end
_stack_abt_end:
	.long __stack_abt_end
_stack_irq_end:
	.long __stack_irq_end
_stack_fiq_end:
	.long __stack_fiq_end
_stack_srv_end:
	.long __stack_srv_end


可以跳到main()函数执行,但是下面的代码只能输出abc, 却没人办法输出test2134就死掉了

int main(int argc, char **argv) {

	

	
		sys_uart_init();

	  sys_uart_putc('a');
		sys_uart_putc('b');
		sys_uart_putc('c');
	
//	sys_mmu_init();
	
		printf("test2134");
		while(1);

return 0;
}

所用LD文件如下

OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)

STACK_USR_SIZE = 0x10000; /* 40k */
STACK_UND_SIZE = 0x10000;
STACK_ABT_SIZE = 0x10000;
STACK_IRQ_SIZE = 0x10000;
STACK_FIQ_SIZE = 0x10000;
STACK_SRV_SIZE = 0x10000; /* 160k */

MEMORY
{
	/*
	ram  : org = 0x80000000, len = 8M
	dma  : org = 0x80800000, len = 8M
	heap : org = 0x81000000, len = 16M 
	*/

	ram  : org = 0x80000100, len = 800K
	dma  : org = 0x80800000, len = 2M
	heap : org = 0x80c00000, len = 2M
   stack : org = 0x81000000, len = 1M
	
}

SECTIONS
{
/*
	.bootloader :
	{
		PROVIDE(__bootloader_start = .);
		PROVIDE(__image_start = .);
		PROVIDE(__text_start = .);
		Objects\start.o (.text)
		Objects\memcpy.o (.text)
		Objects\memset.o (.text)
		Objects\sys-uart.o (.text)
		Objects\sys-clock.o (.text)
		Objects\sys-dram.o (.text)
		Objects\sys-mmu.o (.text)
		
		Objects\sys-spi-flash.o (.text)
		Objects\sys-copyself.o (.text)
		
		PROVIDE(__bootloader_end = .);
	} > ram
	
	__bootloader_size = SIZEOF(.bootloader);
*/

	.text :
	{
		/*Objects\main.o (.text)*/
		*(.text)
		*(.text*)
		*(.init.text)
		*(.exit.text)
		*(.glue*)
		*(.note.gnu.build-id)
		PROVIDE(__text_end = .);
	} > ram

	.initcall ALIGN(8) :
	{
		PROVIDE(__initcall_start = .);
		KEEP(*(.initcall_0.text))
		KEEP(*(.initcall_1.text))
		KEEP(*(.initcall_2.text))
		KEEP(*(.initcall_3.text))
		KEEP(*(.initcall_4.text))
		KEEP(*(.initcall_5.text))
		KEEP(*(.initcall_6.text))
		KEEP(*(.initcall_7.text))
		KEEP(*(.initcall_8.text))
		KEEP(*(.initcall_9.text))
		PROVIDE(__initcall_end = .);
	} > ram

	.exitcall ALIGN(8) :
	{
		PROVIDE(__exitcall_start = .);
		KEEP(*(.exitcall_9.text))
		KEEP(*(.exitcall_8.text))
		KEEP(*(.exitcall_7.text))
		KEEP(*(.exitcall_6.text))
		KEEP(*(.exitcall_5.text))
		KEEP(*(.exitcall_4.text))
		KEEP(*(.exitcall_3.text))
		KEEP(*(.exitcall_2.text))
		KEEP(*(.exitcall_1.text))
		KEEP(*(.exitcall_0.text))
		PROVIDE(__exitcall_end = .);
	} > ram

	.ksymtab ALIGN(8) :
	{
		PROVIDE(__ksymtab_start = .);
		KEEP(*(.ksymtab.text))
		PROVIDE(__ksymtab_end = .);
	} > ram

	.romdisk ALIGN(8) :
	{
		PROVIDE(__romdisk_start = .);
		KEEP(*(.romdisk))
		PROVIDE(__romdisk_end = .);
	} > ram

	.rodata ALIGN(8) :
	{
		PROVIDE(__rodata_start = .);
		*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*)))
		PROVIDE(__rodata_end = .);
	} > ram

	.data_shadow ALIGN(8) :
	{
		PROVIDE(__data_shadow_start = .);
		PROVIDE(__data_shadow_end = (. + SIZEOF(.data)));
		PROVIDE(__image_end = __data_shadow_end);
	} > ram

	.data : AT(ADDR(.data_shadow))
	{
		PROVIDE(__data_start = .);	
		*(.data*)
		. = ALIGN(8);
  		PROVIDE(__data_end = .);
	} > ram

	.ARM.exidx ALIGN(8) :
	{
		PROVIDE (__exidx_start = .);
		*(.ARM.exidx*)
		PROVIDE (__exidx_end = .);
	} > ram

	.ARM.extab ALIGN(8) :
	{
		PROVIDE (__extab_start = .);
		*(.ARM.extab*)
		PROVIDE (__extab_end = .);
	} > ram

	.bss ALIGN(8) (NOLOAD) :
	{
		PROVIDE(__bss_start = .);
		*(.bss*)
		*(.sbss*)
		*(COMMON)
		. = ALIGN(8);
		PROVIDE(__bss_end = .);
	} > ram

	
	.stack ALIGN(8) (NOLOAD) :
	{
		PROVIDE(__stack_start = ORIGIN(stack));
		PROVIDE(__stack_usr_start = __stack_start);
		PROVIDE(__stack_usr_end = __stack_start + STACK_USR_SIZE);
		PROVIDE(__stack_und_start = __stack_usr_end);
		PROVIDE(__stack_und_end = __stack_usr_end + STACK_UND_SIZE);
		. = ALIGN(8);
		PROVIDE(__stack_abt_start = __stack_und_end);
		PROVIDE(__stack_abt_end = __stack_und_end + STACK_ABT_SIZE);
		. = ALIGN(8);
		PROVIDE(__stack_irq_start = __stack_abt_end);
		PROVIDE(__stack_irq_end = __stack_abt_end + STACK_IRQ_SIZE);
		. = ALIGN(8);
		PROVIDE(__stack_fiq_start = __stack_irq_end);
		PROVIDE(__stack_fiq_end = __stack_irq_end + STACK_FIQ_SIZE);
		. = ALIGN(8);
		PROVIDE(__stack_srv_start = __stack_fiq_end);
		PROVIDE(__stack_srv_end = __stack_fiq_end + STACK_SRV_SIZE);
		. = ALIGN(8);
		PROVIDE(__stack_end = __stack_srv_end);
	} > stack

	.dma ALIGN(8) (NOLOAD) :
	{
		PROVIDE(__dma_start = ORIGIN(dma));
		PROVIDE(__dma_end = ORIGIN(dma) + LENGTH(dma));
	} > dma

	.heap ALIGN(8) (NOLOAD) :
	{
		PROVIDE(__heap_start = ORIGIN(heap));
		PROVIDE(__heap_end = ORIGIN(heap) + LENGTH(heap));
	} > heap

	.stab 0 : { *(.stab) }
	.stabstr 0 : { *(.stabstr) }
	.stab.excl 0 : { *(.stab.excl) }
	.stab.exclstr 0 : { *(.stab.exclstr) }
	.stab.index 0 : { *(.stab.index) }
	.stab.indexstr 0 : { *(.stab.indexstr) }
	.comment 0 : { *(.comment) }
	.debug_abbrev 0 : { *(.debug_abbrev) }
	.debug_info 0 : { *(.debug_info) }
	.debug_line 0 : { *(.debug_line) }
	.debug_pubnames 0 : { *(.debug_pubnames) }
	.debug_aranges 0 : { *(.debug_aranges) }
}

最近编辑记录 shawn.d (2021-07-08 12:30:22)

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn