1 实现系统调试信息打印接口
??当系统出错时或者使用内核日志时会输出一些打印信息,这最终都是调用到bspLib.c中的bspDebugMsg 这个接口来实现的,所以我们在开发BSP时,第一个要做的工作就是实现这个接口。 ??我们去bspLib.c文件中看看系统对于我们的bspDebugMsg()函数的描述:
2 T3开发板连接我们的笔记本电脑
??一般的调试信息都是通过串口来输出的,所以我们需要实现T3开发板上串口发送的函数。因为我们的开发板使用的是P10串口连接,下图就是连接方式,即UART0,所以U-Boot在启动时使用串口0输出信息,所以我们这里只要实现串口0的发送函数即可。 我们去T3的电路图看一下这个P10。 我们注意在连接杜邦线的时候TTL转USB的时候RX连接TX,TX连接RX。我们通过开发板的P10串口连接转USB接口工具连接到我们的笔记本电脑,出现下面的页面,会出现很多uboot的信息:
3 实现调试串口
我们现在要实现串口驱动,在driver 目录下新建一个uart目录用来存放串口驱动文件uart.c和uart.h: 其中uart.h会被bspLib.c文件使用,我们需要在uart.c中实现串口的轮询发送接口,
#define __SYLIXOS_KERNEL
#include <SylixOS.h>
#include <linux/compat.h>
#define UART0_BASE (0x01c28000)
#define RBR 0x0
#define THR 0x0
#define USR 0x7C
VOID uartPutChar (CHAR cChar)
{
while (!(readl(UART0_BASE + USR) & BIT(1)));
writel(cChar, UART0_BASE + THR);
}
VOID uartPutMsg (CPCHAR cpcMsg)
{
CHAR cChar;
if (!cpcMsg) {
return;
}
while ((cChar = *cpcMsg) != '\0') {
uartPutChar(cChar);
cpcMsg++;
}
}
- 在手册中查看寄存器偏移量,分别是 0x00、0x00、0x7C:
- 继续看手册,USR寄存区的第二位
readl 我们追一下就知道这个表示就是地址,其实是为了判断USR寄存器的第二位是0是1,如果是1 & 1 为1 ,0&1为0 所以这个的逻辑就是,通过判断USR寄存器的第二位,为0表示发送FIFI不满,就填数据,为1表示发送FIFO已满了。
然后在bspLib.c中的bspDebugMsg 接口中调用我们刚刚实现的串口轮询发送函数:
VOID bspDebugMsg (CPCHAR pcMsg)
{
uartPutMsg(pcMsg);
}
4 验证调试串口
接下来我们需要验证我们的这个debug串口是否正确。我们先编译一下我们的BSP工程,生成我们的SylixOS内核镜像文件,然后看有没有串口打印信息。如果有说明我们代码没问题。 编译BSP工程(注意,我们的BSP工程是依赖BASE工程的,所以编译BSP过程之前要先把BASE工程编译好),在Debug目录下找到BSP_T3.bin 这个文件,如下图
这个就是我们编译出来的SylixOS内核镜像,将其拷贝到SD卡上,将SD卡插入开发板上,然后和上面一样连接开发板进入uboot ,查看我们的mmc信息,遇到了一点点问题,但是最后还是解决了,下面记录一下。
上电通过以下命令启动SylixOS内核:
=> fatload mmc 2:0 40100000 bsp_t3.bin
=> go 40100000
由于这里我的UBoot读不出我的bin文件,所以我没办法看到我的调试串口的打印信息,这里的第一条指令就没有通过,报出了下面的错误信息: 我尝试了一些办法但是都没有解决。我也只能先继续往下做了。如果有遇到过相同问题的朋友欢迎指导。
这个问题解决啦!万分感觉翼辉信息的老师,经过他的指导我解决了这个问题。由于我的uboot没有tftp网络传输功能,所以我只能用sd卡,但是它又读不出我的文件类型。最后的解决办法是这样子的:
-
把我们编译好的镜像文件放到我们的格式化好的sd卡里面,然后插入我们的开发板 -
把开发板原本的翼辉镜像跑起来,开发板串口连接笔记本电脑,然后不按回车,让他由uboot启动开发板内的固化好的SylixOS镜像文件。
- 然后进入根目录——>media目录——>一个一个的找我们的bsp_bin文件
- 给开发板重新上电。在启动的时候敲回车。进入我们的uboot 然后输入命令载入我们编译好的镜像。
fatload mmc 2:2 40000000 bsp_t3.bin
去这个地址去运行我们的镜像,输入命令:
go 40000000
我们就可以在串口上看到SylixOS启动过程中的日志打印,出现下面的页面:
sunxi#fatload mmc 2:2 40000000 bsp_t3.bin
reading bsp_t3.bin
5066312 bytes read in 65 ms (74.3 MiB/s)
sunxi#go 40000000
## Starting application at 0x40000000 ...
longwing(TM) kernel initialize...
kernel low level initialize...
kernel heap build...
semaphore "heap_lock" has been create.
kernel heap has been create 0x40f11458 (47115048 Bytes).
system heap build...
system heap has been create 0x0 (0 Bytes).
kernel interrupt vector initialize...
kernel high level initialize...
semaphore "sigfdsel_lock" has been create.
thread "t_idle0" has been initialized.
thread "t_idle0" has been start.
thread "t_itimer" has been initialized.
thread "t_itimer" has been start.
semaphore "job_sync" has been create.
thread "t_isrdefer" has been initialized.
thread "t_isrdefer" has been start.
semaphore "job_sync" has been create.
thread "t_except" has been create.
msgqueue "log_msg" has been create.
partition "printk_pool" has been create.
thread "t_log" has been initialized.
semaphore "ios_mutex" has been create.
semaphore "evtfdsel_lock" has been create.
semaphore "bmsgsel_lock" has been create.
semaphore "bmsgd_lock" has been create.
semaphore "semfdsel_lock" has been create.
semaphore "semfd_lock" has been create.
semaphore "tmrfdsel_lock" has been create.
semaphore "hstmrfdsel_lock" has been create.
semaphore "gpiofdsel_lock" has been create.
semaphore "blkio_lock" has been create.
semaphore "autom_lock" has been create.
semaphore "mount_lock" has been create.
semaphore "bus_listlock" has been create.
semaphore "blk_lock" has been create.
semaphore "power_lock" has been create.
semaphore "sel_wakeup" has been create.
thread "t_power" has been create.
semaphore "job_sync" has been create.
semaphore "hotplug_lock" has been create.
semaphore "sel_wakeup" has been create.
thread "t_hotplug" has been create.
semaphore "hpsel_lock" has been create.
semaphore "hotplug_lock" has been create.
system initialized.
semaphore "cpprt_lock" has been create.
semaphore "cond_signal" has been create.
c++ run time lib initialized.
kernel primary cpu usrStartup...
ARM(R) A7 vfpv4 FPU pri-core initialization.
FPU initilaized.
semaphore "vmm_lock" has been create.
semaphore "vmmap_lock" has been create.
ARM(R) A7 MMU initialization.
partition "pgd_pool" has been create.
partition "pte_pool" has been create.
mmu initialize. start memory pagination...
MMU initilaized.
ARM(R) 920 L1 cache controller initialization.
ARMv4 I-Cache line size = 64 bytes, Way size = 256 bytes.
ARMv4 D-Cache line size = 8 bytes, Way size = 256 bytes.
CACHE initilaized.
I-CACHE enable.
D-CACHE enable.
semaphore "sel_wakeup" has been create.
thread "t_boot" has been create.
msgqueue "res_reclaim" has been create.
semaphore "sel_wakeup" has been create.
thread "t_reclaim" has been create.
semaphore "resh_lock" has been create.
semaphore "resraw_lock" has been create.
kernel ticks initialize...
semaphore "ints_lock" has been create.
IRQ 0 : tick_timer connect : 0x40000ab0
primary cpu multi-task start...
我们现在只是实现了调试信息输出。后面继续加油!
|