# bsp内核的SPI flash启动 ## Flash分区规划 这里 使用MX25L25645G, 32M SPI flash作为启动介质,规划分区如下: |分区序号|分区大小|分区作用|地址空间及分区名| |--|--|--|--| |mtd0|1MB|spl+uboot|0x0000000-0x0100000 : "uboot"| |mtd1|64KB|script.bin文件|0x0100000-0x0110000 : "script"| |mtd2|4MB|linux内核|0x0110000-0x0510000 : "kernel"| |mtd3|剩余|根文件系统|0x0510000-0x2000000 : "rootfs"| ### 配置uboot默认环境变量 在文件`include/configs/sun8i.h`中添加默认bootcmd和bootargs的环境变量设置,注意添加的位置在“#include <configs/sunxi-common.h>”的前边。 ~~~ vi include/configs/sun8i.h #define CONFIG_MACH_TYPE 0x1029 #define CONFIG_BOOTCOMMAND "sf probe 0; " \ "sf read 0x41d00000 0x100000 0x10000; " \ "sf read 0x41000000 0x110000 0x400000; " \ "bootz 0x41000000" #define CONFIG_BOOTARGS "console=ttyS0,115200 earlyprintk panic=5 rootwait " \ "mtdparts=spi32766.0:1M(uboot)ro,64k(script)ro,4M(kernel)ro,16M(rootfs),-(data) root=31:03 rw rootfstype=squashfs" ~~~ ~~~ #ifdef CONFIG_ARCH_SUN8IW8 static int partitions_register(struct mtd_info *mtd, struct mtd_part_parser_data *ppdata) { ret = m25p80_read(mtd, MBR_OFFSET, MBR_SIZE, &retlen, (u_char *)sunxi_mbr); ~~~ 所以需要在240K(0x3C000)偏移处, 写入16KB大小的MBR信息 ~~~ #define MBR_OFFSET ((256-16)*1024) #define MBR_SIZE (16 * 1024) #define DL_SIZE (16 * 1024) #define MBR_MAGIC "softw411" #define MBR_MAX_PART_COUNT 120 #define MBR_RESERVED (MBR_SIZE - 32 - (MBR_MAX_PART_COUNT * sizeof(PARTITION))) //mbr����Ŀռ� #define NOR_BLK_SIZE 512 /* partition information */ typedef struct sunxi_partition_t { ַ unsigned int addrhi; //��ʼ��ַ, ������Ϊ��λ unsigned int addrlo; // unsigned int lenhi; //���� unsigned int lenlo; // unsigned char classname[16]; //���豸�� unsigned char name[16]; // 豸�� unsigned int user_type; //�ؼ�û��ݣ�Ҫ����������ʧ unsigned int keydata; //��дؼ��� ݣ�Ҫ����������ʧ unsigned int ro; //��д //�������ݣ�ƥ��ֽ unsigned char reserved[68]; //�������ݣ�ƥ�������Ϣ128�ֽ� }__attribute__ ((packed))PARTITION; /* mbr information */ typedef struct { unsigned int crc32; // crc 1k - 4 unsigned int version; // �汾��Ϣ�� 0x00000100 unsigned char magic[8]; //softw311" unsigned int copy; //���� unsigned int index; //�ڼ���MBR���� unsigned int PartCount; //�������� unsigned int stamp[1]; //���� PARTITION array[MBR_MAX_PART_COUNT]; // unsigned char res[MBR_RESERVED]; }__attribute__ ((packed)) MBR; ~~~ 由于增加MBR信息不太方便,这里我们直接修改linux-3.4/drivers/mtd/devices/m25p80.c partitions_register函数,手工加入分区信息 ~~~ partitions = kzalloc(4, GFP_KERNEL); if (partitions == NULL) { M25_ERR("Failed to kzalloc(%d patition)\n", sunxi_mbr->PartCount); kfree(sunxi_mbr); return -ENOMEM; } partitions[0].name = "uboot"; partitions[0].offset = 0; partitions[0].size = 1024 * 1024; partitions[1].name = "script"; partitions[1].offset = 1024*1024; partitions[1].size = 64 * 1024; partitions[2].name = "kernel"; partitions[2].offset = 1024*1024 + 64*1024; partitions[2].size = 4 * 1024 * 1024; partitions[3].name = "rootfs"; partitions[3].offset = 1024*1024 + 64*1024 + 4*1024*1024; partitions[3].size = 11200 * 1024; //ret = mtd_device_parse_register(mtd, NULL, ppdata, partitions, sunxi_mbr->PartCount-1); ret = mtd_device_parse_register(mtd, NULL, ppdata, partitions, 4); ~~~ 修改后成功启动: 但是会有一些jffs2的警告,这里就需要在制作jffs2时,加上 ~~~ U-Boot SPL 2017.01-rc2-00073-gdd6e874-dirty (Nov 27 2017 - 06:51:50) DRAM: 64 MiB Trying to boot from sunxi SPICPU: Allwinner V3s (SUN8I 1681) Model: Lichee Pi Zero DRAM: 64 MiB MMC: SUNXI SD/MMC: 0 SF: Detected w25q128bv with page size 256 Bytes, erase size 64 KiB, total 16 MiB *** Warning - bad CRC, using default environment Setting up a 800x480 lcd console (overscan 0x0) dotclock: 27000kHz = 27000kHz: (1 * 3MHz * 54) / 6 In: serial@01c28000 Out: serial@01c28000 Err: serial@01c28000 CPU: Allwinner V3s (SUN8I 1681) Model: Lichee Pi Zero DRAM: 64 MiB MMC: SUNXI SD/MMC: 0 SF: Detected w25q128bv with page size 256 Bytes, erase size 64 KiB, total 16 MiB *** Warning - bad CRC, using default environment Setting up a 800x480 lcd console (overscan 0x0) dotclock: 27000kHz = 27000kHz: (1 * 3MHz * 54) / 6 In: serial@01c28000 Out: serial@01c28000 Err: serial@01c28000 Net: No ethernet found. starting USB... No controllers found Hit any key to stop autoboot: 0 SF: Detected w25q128bv with page size 256 Bytes, erase size 64 KiB, total 16 MiB device 0 offset 0x100000, size 0x10000 SF: 65536 bytes @ 0x100000 Read: OK device 0 offset 0x110000, size 0x400000 SF: 4194304 bytes @ 0x110000 Read: OK Starting kernel ... [sun8i_fixup]: From boot, get meminfo: Start: 0x40000000 Size: 64MB ion_carveout reserve: 28m@0 28m@0 ion_reserve_common: ion reserve: [0x42400000, 0x44000000]! [ 0.000000] Booting Linux on physical CPU 0 [ 0.000000] Linux version 3.4.39 (root@bf756b445919) (gcc version 4.6.3 20120201 (prerelease) (crosstool-NG linaro-1.13.1-2012.02-20120222 - Linaro GCC 2012.02) ) #23 Mon Nov 27 06:38:53 UTC 2017 [ 0.000000] bootconsole [earlycon0] enabled [ 0.000000] Initialized persistent memory from 41d20800-41d307ff [ 0.000000] Kernel command line: console=ttyS0,115200 earlyprintk panic=5 rootwait mtdparts=spi32766.0:1M(uboot)ro,64k(script)ro,4M(kernel)ro,-(rootfs) root=/dev/mtdblock3 rw rootfstype=jffs2 [ 0.000000] PID hash table entries: 256 (order: -2, 1024 bytes) [ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes) [ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes) [ 0.000000] Memory: 64MB = 64MB total [ 0.000000] Memory: 30672k/30672k available, 34864k reserved, 0K highmem [ 0.000000] Virtual kernel memory layout: [ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB) [ 0.000000] fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB) [ 0.000000] vmalloc : 0xc4800000 - 0xff000000 ( 936 MB) [ 0.000000] lowmem : 0xc0000000 - 0xc4000000 ( 64 MB) [ 0.000000] modules : 0xbf000000 - 0xc0000000 ( 16 MB) [ 0.000000] .text : 0xc0008000 - 0xc043a000 (4296 kB) [ 0.000000] .init : 0xc043a000 - 0xc045c000 ( 136 kB) [ 0.000000] .data : 0xc045c000 - 0xc049f680 ( 270 kB) [ 0.000000] .bss : 0xc049f6a4 - 0xc0538a4c ( 613 kB) [ 0.000000] NR_IRQS:544 [ 0.000000] Architected local timer running at 24.00MHz. [ 0.000000] Switching to timer-based delay loop [ 0.000000] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 178956ms [ 0.000000] Console: colour dummy device 80x30 [ 0.014542] Calibrating delay loop (skipped), value calculated using timer frequency.. 4800.00 BogoMIPS (lpj=24000000) [ 0.022937] pid_max: default: 32768 minimum: 301 [ 0.027770] Mount-cache hash table entries: 512 [ 0.030594] CPU: Testing write buffer coherency: ok [ 0.035148] Setting up static identity map for 0x40320948 - 0x403209a0 [ 0.040773] devtmpfs: initialized [ 0.045468] pinctrl core: initialized pinctrl subsystem [ 0.049177] NET: Registered protocol family 16 [ 0.050397] DMA: preallocated 128 KiB pool for atomic coherent allocations [ 0.056950] script_sysfs_init success [ 0.060958] gpiochip_add: registered GPIOs 0 to 223 on device: sunxi-pinctrl [ 0.068176] sunxi-pinctrl sunxi-pinctrl: initialized sunXi PIO driver [ 0.070433] gpiochip_add: registered GPIOs 1024 to 1031 on device: axp-pinctrl [ 0.078176] persistent_ram: found existing buffer, size 24824, start 24824 [ 0.200017] console [ram-1] enabled [ 0.200591] Not Found clk pll_isp in script [ 0.202410] Not Found clk pll_video in script [ 0.207018] Not Found clk pll_ve in script [ 0.210016] Not Found clk pll_periph0 in script [ 0.214773] Not Found clk pll_de in script [ 0.223234] bio: create slab <bio-0> at 0 [ 0.223685] pwm module init! [ 0.228492] SCSI subsystem initialized [ 0.229903] usbcore: registered new interface driver usbfs [ 0.230106] usbcore: registered new interface driver hub [ 0.235596] usbcore: registered new device driver usb [ 0.240159] twi_chan_cfg()340 - [twi0] has no twi_regulator. [ 0.245813] twi_chan_cfg()340 - [twi1] has no twi_regulator. [ 0.250526] Linux video capture interface: v2.00 [ 0.254901] gpiochip_add: gpios 1024..1028 (axp_pin) failed to register [ 0.260397] Advanced Linux Sound Architecture Driver Version 1.0.25. [ 0.267305] Switching to clocksource arch_sys_counter [ 0.281153] NET: Registered protocol family 2 [ 0.281715] IP route cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.287446] TCP established hash table entries: 2048 (order: 2, 16384 bytes) [ 0.294349] TCP bind hash table entries: 2048 (order: 1, 8192 bytes) [ 0.300690] TCP: Hash tables configured (established 2048 bind 2048) [ 0.306955] TCP: reno registered [ 0.310263] UDP hash table entries: 256 (order: 0, 4096 bytes) [ 0.316258] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes) [ 0.322804] NET: Registered protocol family 1 [ 0.327425] standby_mode = 1. [ 0.330049] wakeup src cnt is : 3. [ 0.333582] pmu1_enable = 0x0. [ 0.336881] config_pmux_para: script_parser_fetch err. [ 0.342070] pmu2_enable = 0x0. [ 0.345264] add_sys_pwr_dm: get ldo name failed [ 0.349957] add_sys_pwr_dm: get ldo name failed [ 0.354453] add_sys_pwr_dm: get ldo name failed [ 0.359142] add_sys_pwr_dm: get ldo name failed [ 0.363642] add_sys_pwr_dm: get ldo name failed [ 0.368227] add_sys_pwr_dm: get ldo name failed [ 0.372934] add_sys_pwr_dm: get ldo name failed [ 0.377413] add_sys_pwr_dm: get ldo name failed [ 0.382120] add_sys_pwr_dm: get ldo name failed [ 0.386599] add_sys_pwr_dm: get ldo name failed [ 0.391198] after inited: sys_mask config = 0x0. [ 0.396066] dynamic_standby enalbe = 0x0. [ 0.400181] sunxi_reg_init enter [ 0.405385] squashfs: version 4.0 (2009/01/31) Phillip Lougher [ 0.409463] jffs2: version 2.2. (NAND) (SUMMARY) © 2001-2006 Red Hat, Inc. [ 0.416837] msgmni has been set to 59 [ 0.421265] io scheduler noop registered [ 0.424136] io scheduler deadline registered [ 0.428640] io scheduler cfq registered (default) [ 0.433742] [DISP]disp_module_init [ 0.437149] cmdline,disp= [ 0.440186] [DISP] disp_get_rotation_sw,line:68:disp 0 out of range? g_rot_sw=0 [ 0.446745] [DISP] disp_init_connections,line:289:NULL pointer: 0, 0 [ 0.454794] [DISP] Fb_map_kernel_logo,line:924:Fb_map_kernel_logo failed! [ 0.462548] [DISP] disp_sys_power_enable,line:387:some error happen, fail to get regulator [ 0.468416] [DISP] disp_sys_gpio_set_value,line:374:OSAL_GPIO_DevWRITE_ONEPIN_DATA, hdl is NULL [ 0.477353] [DISP]disp_module_init finish [ 0.481596] sw_uart_get_devinfo()1503 - uart0 has no uart_regulator. [ 0.488157] uart0: ttyS0 at MMIO 0x1c28000 (irq = 32) is a SUNXI [ 0.493777] sw_uart_pm()890 - uart0 clk is already enable [ 0.499297] sw_console_setu[ 0.508034] console [ttyS0] enabled, bootconsole disabled [ 0.508034] console [ttyS0] enabled, bootconsole disabled [ 0.515942] sunxi_spi_chan_cfg()1376 - [spi-0] has no spi_regulator. [ 0.527590] spi spi0: master is unqueued, this is deprecated [ 0.534254] m25p_probe()988 - Use the Dual Mode Read. [ 0.540124] m25p80 spi0.0: found W25q128, expected at25df641 [ 0.546639] m25p80 spi0.0: W25q128 (16384 Kbytes) [ 0.552353] Creating 4 MTD partitions on "spi0.0": [ 0.557911] 0x000000000000-0x000000100000 : "uboot" [ 0.564635] 0x000000100000-0x000000110000 : "script" [ 0.571423] 0x000000110000-0x000000510000 : "kernel" [ 0.578020] 0x000000510000-0x000001000000 : "rootfs" [ 0.584964] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver [ 0.612598] sunxi-ehci sunxi-ehci.1: SW USB2.0 'Enhanced' Host Controller (EHCI) Driver [ 0.621840] sunxi-ehci sunxi-ehci.1: new USB bus registered, assigned bus number 1 [ 0.630635] sunxi-ehci sunxi-ehci.1: irq 104, io mem 0xf1c1a000 [ 0.650041] sunxi-ehci sunxi-ehci.1: USB 0.0 started, EHCI 1.00 [ 0.657659] hub 1-0:1.0: USB hub found [ 0.662040] hub 1-0:1.0: 1 port detected [ 0.667035] sunxi-ehci sunxi-ehci.1: remove, state 1 [ 0.672829] usb usb1: USB disconnect, device number 1 [ 0.679403] sunxi-ehci sunxi-ehci.1: USB bus 1 deregistered [ 0.685886] [DISP] disp_lcd_pwm_enable,line:1021:pwm device hdl is NULL [ 0.703736] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver [ 0.730959] sunxi-ohci sunxi-ohci.1: SW USB2.0 'Open' Host Controller (OHCI) Driver [ 0.739642] sunxi-ohci sunxi-ohci.1: new USB bus registered, assigned bus number 1 [ 0.748337] sunxi-ohci sunxi-ohci.1: irq 105, io mem 0xf1c1a400 [ 0.814780] hub 1-0:1.0: USB hub found [ 0.819088] hub 1-0:1.0: 1 port detected [ 0.824069] sunxi-ohci sunxi-ohci.1: remove, state 1 [ 0.829848] usb usb1: USB disconnect, device number 1 [ 0.836289] sunxi-ohci sunxi-ohci.1: USB bus 1 deregistered [ 0.852869] Initializing USB Mass Storage driver... [ 0.858501] usbcore: registered new interface driver usb-storage [ 0.865431] USB Mass Storage support registered. [ 0.871076] file system registered [ 0.876824] android_usb gadget: Mass Storage Function, version: 2009/09/11 [ 0.884754] android_usb gadget: Number of LUNs=1 [ 0.890108] lun0: LUN: removable file: (no medium) [ 0.896346] android_usb gadget: android_usb ready [ 0.901868] sunxikbd_script_init: key para not found, used default para. [ 0.910909] sunxi-rtc sunxi-rtc: rtc core: registered sunxi-rtc as rtc0 [ 0.919467] platform reg-20-cs-dcdc2: Driver reg-20-cs-dcdc2 requests probe deferral [ 0.928535] platform reg-20-cs-dcdc3: Driver reg-20-cs-dcdc3 requests probe deferral [ 0.937552] platform reg-20-cs-ldo1: Driver reg-20-cs-ldo1 requests probe deferral [ 0.946223] platform reg-20-cs-ldo2: Driver reg-20-cs-ldo2 requests probe deferral [ 0.955007] platform reg-20-cs-ldo3: Driver reg-20-cs-ldo3 requests probe deferral [ 0.963773] platform reg-20-cs-ldo4: Driver reg-20-cs-ldo4 requests probe deferral [ 0.972461] platform reg-20-cs-ldoio0: Driver reg-20-cs-ldoio0 requests probe deferral [ 0.981595] sunxi_wdt_init_module: sunxi WatchDog Timer Driver v1.0 [ 0.989005] sunxi_wdt_probe: devm_ioremap return wdt_reg 0xf1c20ca0, res->start 0x01c20ca0, res->end 0x01c20cbf [ 1.000508] sunxi_wdt_probe: initialized (g_timeout=16s, g_nowayout=0) [ 1.008202] wdt_enable, write reg 0xf1c20cb8 val 0x00000000 [ 1.014657] wdt_set_tmout, write 0x000000b0 to mode reg 0xf1c20cb8, actual timeout 16 sec [ 1.030558] sunxi_leds_fetch_sysconfig_para leds is not used in config [ 1.037999] =========script_get_err============ [ 1.043379] usbcore: registered new interface driver usbhid [ 1.049747] usbhid: USB HID core driver [ 1.054926] ashmem: initialized [ 1.058688] logger: created 256K log 'log_main' [ 1.064074] logger: created 32K log 'log_events' [ 1.069414] logger: created 32K log 'log_radio' [ 1.074813] logger: created 32K log 'log_system' [ 1.085076] script_get_item return type err, consider it no ldo [ 1.091944] *******************Try sdio******************* [ 1.099154] asoc: sndcodec <-> sunxi-codec mapping ok [ 1.107244] TCP: cubic registered [ 1.111119] *******************Try sd ******************* [ 1.117222] NET: Registered protocol family 17 [ 1.122563] VFP support v0.3: [mmc]: *** sunxi_mci_dump_errinfo(L826): smc 0 err, cmd 55, RTO !! [ 1.132757] ThumbEE CPU extension supported. [ 1.137719] Registering SWP/SWPB emulation handler [ 1.144032] *******************Try mmc******************* [ 1.150487] platform reg-20-cs-ldoio0: Driver reg-20-cs-ldoio0 requests probe deferral [ 1.159427] platform reg-20-cs-ldo4: Driver reg-20-cs-ldo4 requests probe deferral [ 1.168304] platform reg-20-cs-ldo3: Driver reg-20-cs-ldo3 requests probe deferral [ 1.177192] platform reg-20-cs-ldo2: Driver reg-20-cs-ldo2 requests probe deferral [ 1.186878] platform reg-20-cs-ldo1: Driver reg-20-cs-ldo1 requests probe deferral [ 1.196829] platform reg-20-cs-dcdc3: Driver reg-20-cs-dcdc3 requests probe deferral [ 1.205670] platform reg-20-cs-dcdc2: Driver reg-20-cs-dcdc2 requests probe deferral [ 1.214732] sunxi-rtc sunxi-rtc: setting system clock to 1970-01-01 04:04:40 UTC (14680) [ 1.225163] ALSA device list: [ 1.228696] #0: audiocodec [ 1.232455] fs_names=/dev/root [ 1.235999] fs_name=jffs2 [ 1.245400] *******************Try sdio******************* [ 1.256367] *******************Try sd ******************* [ 1.267056] *******************Try mmc******************* [ 1.329128] *******************Try sdio******************* [ 1.342075] *******************Try sd ******************* [ 1.354874] *******************Try mmc******************* [ 1.407233] *******************Try sdio******************* [ 1.418090] *******************Try sd ******************* [ 1.428749] *******************Try mmc******************* [ 1.485235] *******************Try sdio******************* [ 1.505780] mmc1: new high speed SDIO card at address 0001 [ 1.512714] *******************sdio init ok******************* [ 3.628556] VFS: Mounted root (jffs2 filesystem) on device 31:3. [ 3.635449] err=0 [ 3.638311] devtmpfs: mounted [ 3.641908] Freeing init memory: 136K Starting logging: OK Starting mdev... modprobe: can't change directory to '/lib/modules': No such file or directory Initializing random number generator... done. Starting network: OK Welcome to Lichee Pi Lichee login: ~~~