本文主要是如何让开机启动的时候的日志中显示时间戳的相关笔记。若笔记中有错误或者不合适的地方,欢迎批评指正😃。
点击查看使用工具及版本
Windows版本 | windows11 |
Ubuntu版本 | Ubuntu16.04的64位版本 |
VMware® Workstation 16 Pro | 16.2.3 build-19376536 |
终端软件 | MobaXterm(Professional Edition v23.0 Build 5042 (license)) |
Linux开发板 | 正点原子 i.MX6ULL Linux 阿尔法开发板 |
uboot | NXP官方提供的uboot,NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03) |
linux内核 | linux-4.15(NXP官方提供) |
Win32DiskImager | Win32DiskImager v1.0 |
点击查看本文参考资料
点击查看相关文件下载
一、为什么这么做?
我们移植好linux后,启动之后,使用dmesg打印日志的时候是这样的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| root@imx: /$ dmesg Booting Linux on physical CPU 0x0 Linux version 4.1.15 (hk@vm) (gcc version 4.9.4 (Linaro GCC 4.9-2017.01) ) #1 SMP PREEMPT Sun Oct 23 22:17:07 CST 2022 CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache Machine model: Freescale i.MX6 ULL 14x14 EVK Board Reserved memory: created CMA memory pool at 0x8c000000, size 320 MiB Reserved memory: initialized node linux,cma, compatible id shared-dma-pool Memory policy: Data cache writealloc On node 0 totalpages: 131072 free_area_init_node: node 0, pgdat 809e9bc0, node_mem_map 8bb57000 Normal zone: 1024 pages used for memmap Normal zone: 0 pages reserved Normal zone: 131072 pages, LIFO batch:31 // ... ...
|
然后开发板出厂的时候打印的日志格式:
1 2 3 4 5 6 7 8 9
| root@ATK-IMX6U:~# dmesg [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 4.1.15-g06f53e4 (alientek@ubuntu) (gcc version 5.3.0 (GCC) ) #1 SMP PREEMPT Sat Nov 27 18:39:27 CST 2021 [ 0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c53c7d [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache [ 0.000000] Machine model: Freescale i.MX6 ULL 14x14 EVK Board [ 0.000000] Reserved memory: created CMA memory pool at 0x98000000, size 128 MiB [ 0.000000] Reserved memory: initialized node linux,cma, compatible id shared-dma-pool // ... ...
|
看起来好像整齐一些,后来查了查,前边的是时间戳,其实linux内核可以打开,只是默认是关闭的罢了。其实这样做是有好处的,我们可以看到开机在什么时间段做了什么事情。
二、打开日志时间戳
我们进入linux内核源码目录,执行:
1
| make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
|
然后找到如下配置项,配置为 * 。然后重新编译内核,从新编译的内核启动即可。
1 2 3
| Kernel hacking ---> printk and dmesg options ---> [*] Show timing information on printks
|
修改完毕后保存,重新编译内核即可。
三、最终效果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| root@imx: /$ dmesg [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 4.1.15 (hk@vm) (gcc version 4.9.4 (Linaro GCC 4.9-2017.01) ) #2 SMP PREEMPT Sun Nov 20 14:14:16 CST 2022 [ 0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache [ 0.000000] Machine model: Freescale i.MX6 ULL 14x14 EVK Board [ 0.000000] Reserved memory: created CMA memory pool at 0x8c000000, size 320 MiB [ 0.000000] Reserved memory: initialized node linux,cma, compatible id shared-dma-pool [ 0.000000] Memory policy: Data cache writealloc [ 0.000000] On node 0 totalpages: 131072 [ 0.000000] free_area_init_node: node 0, pgdat 809e9bc0, node_mem_map 8bb57000 [ 0.000000] Normal zone: 1024 pages used for memmap [ 0.000000] Normal zone: 0 pages reserved [ 0.000000] Normal zone: 131072 pages, LIFO batch:31 [ 0.000000] PERCPU: Embedded 12 pages/cpu @8bb31000 s16768 r8192 d24192 u49152 [ 0.000000] pcpu-alloc: s1676
|