标签:需要 meta OLE uboot console 函数 自己的 波特率 display
make menuconfig
Kernel hacking --->
[*] Kernel low-level debugging functions (read help!)
Kernel low-level debugging port (Use Samsung S3C UART 0 for low-level debug)
[*] Early printk
2、设置环境变量
Add earlyprintk to your kernel parameters to enable this console
在 bootargs 中添加 earlyprintk
首先来看 bootargs earlyprintk的解析:
arch/arm/kernel/early_printk.c
extern void printascii(const char *);
static void early_write(const char *s, unsigned n)
{
char buf[128];
while (n) {
unsigned l = min(n, sizeof(buf)-1);
memcpy(buf, s, l);
buf[l] = 0;
s += l;
n -= l;
printascii(buf);
}
}
static void early_console_write(struct console *con, const char *s, unsigned n)
{
early_write(s, n);
}
static struct console early_console_dev = {
.name = "earlycon",
.write = early_console_write,
.flags = CON_PRINTBUFFER | CON_BOOT,
.index = -1,
};
static int __init setup_early_printk(char *buf)
{
early_console = &early_console_dev;
register_console(&early_console_dev);
return 0;
}
early_param("earlyprintk", setup_early_printk);
extern void printascii(const char *);
static void early_write(const char *s, unsigned n)
{
char buf[128];
while (n) {
unsigned l = min(n, sizeof(buf)-1);
memcpy(buf, s, l);
buf[l] = 0;
s += l;
n -= l;
printascii(buf);
}
}
static void early_console_write(struct console *con, const char *s, unsigned n)
{
early_write(s, n);
}
static struct console early_console_dev = {
.name = "earlycon",
.write = early_console_write,
.flags = CON_PRINTBUFFER | CON_BOOT,
.index = -1,
};
static int __init setup_early_printk(char *buf)
{
early_console = &early_console_dev;
register_console(&early_console_dev);
return 0;
}
early_param("earlyprintk", setup_early_printk);
在内核启动进入C语言阶段,start_kernel->parse_early_param 就会第一时间解析early_param("earlyprintk", setup_early_printk);
然后调用 register_console(&early_console_dev);
可以看到 early_console 的 write 函数最终靠 printascii 来实现,同样,直接调用 earlyprintk 也会调用 printascii
void __init early_print(const char *str, ...)
{
extern void printascii(const char *);
char buf[256];
va_list ap;
va_start(ap, str);
vsnprintf(buf, sizeof(buf), str, ap);
va_end(ap);
#ifdef CONFIG_DEBUG_LL
printascii(buf);
#endif
printk("%s", buf);
}
void __init early_print(const char *str, ...)
{
extern void printascii(const char *);
char buf[256];
va_list ap;
va_start(ap, str);
vsnprintf(buf, sizeof(buf), str, ap);
va_end(ap);
printascii(buf);
printk("%s", buf);
}
ENTRY(printascii)
addruart_current r3, r1, r2
1: teq r0, #0
ldrneb r1, [r0], #1
teqne r1, #0
reteq lr
2: teq r1, #‘\n‘
bne 3f
mov r1, #‘\r‘
waituart r2, r3
senduart r1, r3
busyuart r2, r3
mov r1, #‘\n‘
3: waituart r2, r3
senduart r1, r3
busyuart r2, r3
b 1b
ENDPROC(printascii)
ENTRY(printascii)
addruart_current r3, r1, r2
1: teq r0, #0
ldrneb r1, [r0], #1
teqne r1, #0
reteq lr
2: teq r1, #‘\n‘
bne 3f
mov r1, #‘\r‘
waituart r2, r3
senduart r1, r3
busyuart r2, r3
mov r1, #‘\n‘
3: waituart r2, r3
senduart r1, r3
busyuart r2, r3
b 1b
ENDPROC(printascii)
.macro addruart_current, rx, tmp1, tmp2
addruart \tmp1, \tmp2, \rx
mrc p15, 0, \rx, c1, c0
tst \rx, #1
moveq \rx, \tmp1
movne \rx, \tmp2
.endm
.macro addruart_current, rx, tmp1, tmp2
addruart \tmp1, \tmp2, \rx
mrc p15, 0, \rx, c1, c0
tst \rx, #1
moveq \rx, \tmp1
movne \rx, \tmp2
.endm
23 .macro addruart, rp, rv, tmp
24 mrc p15, 0, \tmp, c0, c0, 0
25 and \tmp, \tmp, #0xf0
26 teq \tmp, #0xf0 @@ A15
27 beq 100f
28 mrc p15, 0, \tmp, c0, c0, 5
29 and \tmp, \tmp, #0xf00
30 teq \tmp, #0x100 @@ A15 + A7 but boot to A7
31 100: ldreq \rp, =EXYNOS5_PA_UART
32 movne \rp, #EXYNOS4_PA_UART @@ EXYNOS4
33 ldr \rv, =S3C_VA_UART
34 #if CONFIG_DEBUG_S3C_UART != 0
35 add \rp, \rp, #(0x10000 * CONFIG_DEBUG_S3C_UART)
36 add \rv, \rv, #(0x10000 * CONFIG_DEBUG_S3C_UART)
37 #endif
38 .endm
23 .macro addruart, rp, rv, tmp
24 mrc p15, 0, \tmp, c0, c0, 0
25 and \tmp, \tmp, #0xf0
26 teq \tmp, #0xf0 @@ A15
27 beq 100f
28 mrc p15, 0, \tmp, c0, c0, 5
29 and \tmp, \tmp, #0xf00
30 teq \tmp, #0x100 @@ A15 + A7 but boot to A7
31 100: ldreq \rp, =EXYNOS5_PA_UART
32 movne \rp, #EXYNOS4_PA_UART @@ EXYNOS4
33 ldr \rv, =S3C_VA_UART
34 #if CONFIG_DEBUG_S3C_UART != 0
35 add \rp, \rp, #(0x10000 * CONFIG_DEBUG_S3C_UART)
36 add \rv, \rv, #(0x10000 * CONFIG_DEBUG_S3C_UART)
37 #endif
38 .endm
51 .macro senduart,rd,rx
52 strb \rd, [\rx, # S3C2410_UTXH]
53 .endm
51 .macro senduart,rd,rx
52 strb \rd, [\rx, # S3C2410_UTXH]
53 .endm
__error_p:
#ifdef CONFIG_DEBUG_LL
adr r0, str_p1
bl printascii
mov r0, r9
bl printhex8
adr r0, str_p2
bl printascii
b __error
str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x"
str_p2: .asciz ").\n"
.align
#endif
ENDPROC(__error_p)
__error_p:
adr r0, str_p1
bl printascii
mov r0, r9
bl printhex8
adr r0, str_p2
bl printascii
b __error
str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x"
str_p2: .asciz ").\n"
.align
ENDPROC(__error_p)
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -24,6 +24,7 @@
* 100% relocatable. Any attempt to do so will result in a crash.
* Please select one of the following when turning on debugging.
*/
+#define DEBUG
#ifdef DEBUG
#if defined(CONFIG_DEBUG_ICEDCC)
@@ -67,7 +68,7 @@
.endm
#else
.macro loadsp, rb, tmp
- addruart \rb, \tmp
+ addruart \rb, \tmp, \tmp
.endm
#endif
#endif
@@ -554,6 +555,12 @@ not_relocated: mov r0, #0
* r7 = architecture ID
* r8 = atags pointer
*/
+ stmfd sp!, {r0-r3, r10-r12, lr}
+ mov r0, r8
+ bl memdump
+ kputc #‘\n‘
+ ldmfd sp!, {r0-r3, r10-r12, lr}
+
mov r0, r4
mov r1, sp @ malloc space above stack
add r2, sp, #0x10000 @ 64k max
@@ -563,6 +570,12 @@ not_relocated: mov r0, #0
bl cache_off
mov r1, r7 @ restore architecture number
mov r2, r8 @ restore atags pointer
+
+ stmfd sp!, {r0-r3, r10-r12, lr}
+ mov r0, r8
+ bl memdump
+ kputc #‘\n‘
+ ldmfd sp!, {r0-r3, r10-r12, lr}
#ifdef CONFIG_ARM_VIRT_EXT
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -24,6 +24,7 @@
* 100% relocatable. Any attempt to do so will result in a crash.
* Please select one of the following when turning on debugging.
*/
+#define DEBUG
@@ -67,7 +68,7 @@
.endm
.macro loadsp, rb, tmp
- addruart \rb, \tmp
+ addruart \rb, \tmp, \tmp
.endm
@@ -554,6 +555,12 @@ not_relocated: mov r0, #0
* r7 = architecture ID
* r8 = atags pointer
*/
+ stmfd sp!, {r0-r3, r10-r12, lr}
+ mov r0, r8
+ bl memdump
+ kputc #‘\n‘
+ ldmfd sp!, {r0-r3, r10-r12, lr}
+
mov r0, r4
mov r1, sp @ malloc space above stack
add r2, sp, #0x10000 @ 64k max
@@ -563,6 +570,12 @@ not_relocated: mov r0, #0
bl cache_off
mov r1, r7 @ restore architecture number
mov r2, r8 @ restore atags pointer
+
+ stmfd sp!, {r0-r3, r10-r12, lr}
+ mov r0, r8
+ bl memdump
+ kputc #‘\n‘
+ ldmfd sp!, {r0-r3, r10-r12, lr}
标签:需要 meta OLE uboot console 函数 自己的 波特率 display
原文地址:https://www.cnblogs.com/bringup/p/9316103.html