主線linux已經提供對無MMU的處理器的支持,configs中已經存在stm32_defconfig,DTS中包含:stm32f746-disco;所以只須要編譯便可。
下載主線源碼:http://cdn.kernel.org/pub/linux/kernel/v4.x
安裝交叉編譯鏈,可使用以前編譯uboot的arm-none-eabi-gcc,可是這個是編譯鏈線程模式是single,而不是posix,也就是說雖然這個編譯鏈能夠編譯內核和根文件系統,可是不能編譯linux應用程序。若是須要支持編譯linux應用程序(通常要支持,否則移植linux幹嗎--!),則須要本身去構建交叉編譯鏈,網上講解的比較詳細,不過我推薦使用Buildroot來構建支持stm32的交叉編譯鏈,簡單快捷,固然也能夠用Buildroot來構建內核和根文件系統。node
根文件系統可使用busybox構建,也可使用buildroot構建。
elinux.org提供了一個使用busybox編譯好的Ramdisk最小系統,File:Stm32 mini rootfs.cpio.bz2, 但須要作以下改動:
使用initramfs,將下載的Stm32_mini_rootfs.cpio.bz2解壓,先解壓成cpio文件:
bzip2 -d Stm32_mini_rootfs.cpio.bz2
建立文件夾rootfs:
mkdir rootfs
將文件解壓到rootfs文件夾中:
cpio -idmv <../Stm32_mini_rootfs.cpio
看看dev中是否有null,tty0,console節點,沒有的話須要在dev文件夾中建立這三個節點。linux
sudo mknod console c 5 1 sudo mknod null c 1 3 sudo mknod tty0 c 204 64
再rootfs文件夾下新建init文件,內容以下dom
#!/bin/sh # devtmpfs does not get automounted for initramfs /bin/mount -t devtmpfs devtmpfs /dev exec 0/dev/console exec 2>/dev/console exec /sbin/init $
配置內核使用initramfs
make ARCH=arm CROSS_COMPILE=arm-none-eabi- menuconfig
electron
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support (/work/system/my-linux/rootfs) Initramfs source file(s)
上述步驟主要參考了這位老哥的實現,https://blog.csdn.net/u011371090/article/details/81587170
若是須要使用其餘類型的根文件系統,好比ext4等,須要修改bootcmd,具體再研究。oop
make ARCH=arm CROSS_COMPILE=arm-none-eabi- stm32_defconfig make mkimage -n 'linux' -A arm -O linux -T kernel -C none -a 0xc0300000 -e 0xc0300000 -d ./arch/arm/boot/zImage uImage
setenv ipaddr 192.168.66.69 setenv serverip 192.168.66.66 tftp c0300000 uImage tftp c0500000 stm32f746-disco.dtb setenv bootargs "root=/dev/ram console=ttySTM0,115200" bootm c0300000 - c0500000
sf probe sf erase 0 1000000 sf write c0300000 0 200000 sf write c0500000 200000 4000
能夠更改源碼將bootcmd寫入源碼中,否則每次都要手動改。ui
setenv bootcmd "setenv bootargs "root=/dev/ram console=ttySTM0,115200"; sf probe; sf read c0300000 0 200000;sf read c0500000 200000 4000;bootm c0300000 - c0500000;"
U-Boot > env set bootargs "root=/dev/ram console=ttySTM0,115200" U-Boot > bootm c0300000 - c0500000 ## Booting kernel from Legacy Image at c0300000 ... Image Name: linux Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 1519384 Bytes = 1.4 MiB Load Address: c0300000 Entry Point: c0300000 Verifying Checksum ... OK ## Flattened Device Tree blob at c0500000 Booting using the fdt blob at 0xc0500000 Loading Kernel Image ... OK Using Device Tree in place at c0500000, end c0506a09 Starting kernel ... [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 4.19.69 (yhang@localhost.localdomain) (gcc version 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907] (GNU Tools for Arm Embedded Processors 7-2018-q2-update)) #1 PREEMPT Thu Sep 5 09:03:24 CST 2019 [ 0.000000] CPU: ARMv7-M [410fc271] revision 1 (ARMv7M), cr=00000000 [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache [ 0.000000] OF: fdt: Machine model: STMicroelectronics STM32F746-DISCO board [ 0.000000] random: get_random_bytes called from start_kernel+0x55/0x2c8 with crng_init=0 [ 0.000000] Built 1 zonelists, mobility grouping off. Total pages: 2032 [ 0.000000] Kernel command line: root=/dev/ram console=ttySTM0,115200 [ 0.000000] Dentry cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.000000] Inode-cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.000000] Memory: 5508K/8192K available (1479K kernel code, 142K rwdata, 472K rodata, 216K init, 115K bss, 2684K reserved, 0K cma-reserved) [ 0.000000] Virtual kernel memory layout: [ 0.000000] vector : 0x00000000 - 0x00001000 ( 4 kB) [ 0.000000] fixmap : 0xffc00000 - 0xfff00000 (3072 kB) [ 0.000000] vmalloc : 0x00000000 - 0xffffffff (4095 MB) [ 0.000000] lowmem : 0xc0000000 - 0xc0800000 ( 8 MB) [ 0.000000] .text : 0x(ptrval) - 0x(ptrval) (1480 kB) [ 0.000000] .init : 0x(ptrval) - 0x(ptrval) ( 216 kB) [ 0.000000] .data : 0x(ptrval) - 0x(ptrval) ( 143 kB) [ 0.000000] .bss : 0x(ptrval) - 0x(ptrval) ( 116 kB) [ 0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1 [ 0.000000] rcu: Preemptible hierarchical RCU implementation. [ 0.000000] Tasks RCU enabled. [ 0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16 [ 0.000000] interrupt-controller@40013c00: bank0, External IRQs available:0xffffff [ 0.000000] clocksource: arm_system_timer: mask: 0xffffff max_cycles: 0xffffff, max_idle_ns: 298634427 ns [ 0.000000] ARM System timer initialized as clocksource [ 0.000067] sched_clock: 32 bits at 100MHz, resolution 10ns, wraps every 21474836475ns [ 0.000154] timer@40000c00: STM32 sched_clock registered [ 0.000250] Switching to timer-based delay loop, resolution 10ns [ 0.000322] timer@40000c00: STM32 delay timer registered [ 0.000434] clocksource: timer@40000c00: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604467 ns [ 0.000592] /soc/timer@40000c00: STM32 clockevent driver initialized (32 bits) [ 0.001473] Calibrating delay loop (skipped), value calculated using timer frequency.. 200.00 BogoMIPS (lpj=1000000) [ 0.001635] pid_max: default: 4096 minimum: 301 [ 0.002945] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.003100] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.012600] rcu: Hierarchical SRCU implementation. [ 0.017399] devtmpfs: initialized [ 0.069578] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns [ 0.069719] pinctrl core: initialized pinctrl subsystem [ 0.108491] stm32f746-pinctrl soc:pin-controller: GPIOA bank added [ 0.110059] stm32f746-pinctrl soc:pin-controller: GPIOB bank added [ 0.111741] stm32f746-pinctrl soc:pin-controller: GPIOC bank added [ 0.113419] stm32f746-pinctrl soc:pin-controller: GPIOD bank added [ 0.114960] stm32f746-pinctrl soc:pin-controller: GPIOE bank added [ 0.116526] stm32f746-pinctrl soc:pin-controller: GPIOF bank added [ 0.118141] stm32f746-pinctrl soc:pin-controller: GPIOG bank added [ 0.119682] stm32f746-pinctrl soc:pin-controller: GPIOH bank added [ 0.121218] stm32f746-pinctrl soc:pin-controller: GPIOI bank added [ 0.123182] stm32f746-pinctrl soc:pin-controller: GPIOJ bank added [ 0.124780] stm32f746-pinctrl soc:pin-controller: GPIOK bank added [ 0.124952] stm32f746-pinctrl soc:pin-controller: Pinctrl STM32 initialized [ 0.167396] clocksource: Switched to clocksource timer@40000c00 [ 0.286124] workingset: timestamp_bits=30 max_order=11 bucket_order=0 [ 0.355551] io scheduler noop registered (default) [ 0.355664] io scheduler mq-deadline registered [ 0.355753] io scheduler kyber registered [ 0.359175] STM32 USART driver initialized [ 0.360584] 40011000.serial: ttySTM0 at MMIO 0x40011000 (irq = 33, base_baud = 6250000) is a stm32-usart [ 0.757352] console [ttySTM0] enabled [ 0.763214] stm32-usart 40011000.serial: rx dma alloc failed [ 0.769230] stm32-usart 40011000.serial: interrupt mode used for rx (no dma) [ 0.776229] stm32-usart 40011000.serial: tx dma alloc failed [ 0.782067] stm32-usart 40011000.serial: interrupt mode used for tx (no dma) [ 0.792438] i2c /dev entries driver [ 0.843743] stm32f7-i2c 40005400.i2c: can't use DMA [ 0.851160] stm32f7-i2c 40005400.i2c: STM32F7 I2C-0 bus adapter [ 0.862408] mmci-pl18x 40012c00.sdio1: Got CD GPIO [ 0.868031] mmci-pl18x 40012c00.sdio1: Linked as a consumer to regulator.2 [ 0.875138] mmci-pl18x 40012c00.sdio1: mmc0: PL180 manf 80 rev8 at 0x40012c00 irq 34,0 (pio) [ 0.883767] mmci-pl18x 40012c00.sdio1: DMA channels RX none, TX none [ 0.928369] hctosys: unable to open rtc device (rtc0) [ 0.935401] mmc_vcard: disabling [ 0.941700] Freeing unused kernel memory: 216K [ 0.946045] This architecture does not have kernel memory protection. [ 0.952691] Run /init as init process