平台简介
开发板:tiny4412ADK + S700 + 4GB Flash
要移植的内核版本:Linux-4.4.0 (支持device tree)
u-boot版本:友善之臂自带的 U-Boot 2010.12 (为支持uImage启动,做了少许改动)
busybox版本:busybox 1.25
SD卡:Kingston SDHC 4GB
交叉编译工具链: arm-none-linux-gnueabi-gcc
(gcc version 4.8.3 20140320 (prerelease) (Sourcery CodeBench Lite 2014.05-29))
概述
移植SD卡比较简单,但是刚开始的时候也出现了不少问题,关键是对设备树的修改、对regulator的理解以及sdcard检测过程。
移植
下面是tiny4412关于sd卡部分的原理图:
底板:
核心板:
从原理图可以看出,tiny4412用的MMC控制器是SDMMC2。一共用到了7个引脚(CLK、CMD、CDn、DATA0-DATA3),其中CDn的意思是当插入SD卡时,这个引脚的电平会被拉低(可以轮询这个引脚的电平转态或者通过设置这个引脚产生中断来检测sdcard状态)。在之前的移植中我们将sdhc2给disabled了:
arch/arm/boot/dts/exynos4412-tiny4412.dts:
&sdhci_2 {
bus-width = <4>;
pinctrl-0 = ;
pinctrl-names = "default";
status = "disabled";
};
其中princtrl-0后的作用是设置用到的GPIO的复用功能(一旦复用为sdcard控制器的专用引脚后,就不能作为普通的gpio使用了),这几个标号是在arch/arm/boot/dts/exynos4x12-pinctrl.dtsi中定义的:
sd2_clk: sd2-clk {
samsung,pins = "gpk2-0";
samsung,pin-function = <2>;
samsung,pin-pud = <0>;
samsung,pin-drv = <3>;
};
sd2_cmd: sd2-cmd {
samsung,pins = "gpk2-1";
samsung,pin-function = <2>;
samsung,pin-pud = <0>;
samsung,pin-drv = <3>;
};
sd2_cd: sd2-cd {
samsung,pins = "gpk2-2";
samsung,pin-function = <2>;
samsung,pin-pud = <3>;
samsung,pin-drv = <3>;
};
sd2_bus4: sd2-bus-width4 {
samsung,pins = "gpk2-3", "gpk2-4", "gpk2-5", "gpk2-6";
samsung,pin-function = <2>;
samsung,pin-pud = <3>;
samsung,pin-drv = <3>;
};
这样只是设置了这几个GPIO的复用功能,并不用在驱动程序中申请这几个GPIO资源,因为这几个引脚已经不是作为普通的GPIO使用了。
如果直接将sdhc2使能的话:
--- a/arch/arm/boot/dts/exynos4412-tiny4412.dts
+++ b/arch/arm/boot/dts/exynos4412-tiny4412.dts
@@ -86,7 +86,7 @@
bus-width = <4>;
pinctrl-0 = ;
pinctrl-names = "default";
- status = "disabled";
+ status = "okay";
};
&serial_0 {
内核在启动时会崩溃,信息如下:
1: [ 2.228406] sdhci: Secure Digital Host Controller Interface driver
2: [ 2.233751] sdhci: Copyright(c) Pierre Ossman
3: [ 2.238350] s3c-sdhci 12530000.sdhci: clock source 2: mmc_busclk.2 (100000000 Hz)
4: [ 2.245838] s3c-sdhci 12530000.sdhci: No vmmc regulator found
5: [ 2.251358] s3c-sdhci 12530000.sdhci: No vqmmc regulator found
6: [ 2.257480] ------------[ cut here ]------------
7: [ 2.261686] kernel BUG at drivers/mmc/host/sdhci.c:1304!
8: [ 2.266981] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM
9: [ 2.272796] Modules linked in:
10: [ 2.275836] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.4.0-gbd7378b-dirty #33
11: [ 2.283038] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
12: [ 2.289115] task: ef078000 ti: ef080000 task.ti: ef080000
13: [ 2.294500] PC is at sdhci_do_set_ios+0x564/0x5e0
14: [ 2.299189] LR is at arm_heavy_mb+0x1c/0x38
15: [ 2.303351] pc : [ 16: [ 2.303351] sp : ef081cc8 ip : 00000200 fp : 00000001 17: [ 2.314807] r10: 00000003 r9 : ef30e800 r8 : 60000013 18: [ 2.320015] r7 : ef30e800 r6 : ef30ec98 r5 : ef30ea34 r4 : ef30eb80 19: [ 2.326525] r3 : 00000001 r2 : 75004180 r1 : 00000000 r0 : ef30eb80 20: [ 2.333036] Flags: Nzcv IRQs off FIQs on Mode SVC_32 ISA ARM Segment none 21: [ 2.340240] Control: 10c5387d Table: 4000404a DAC: 00000051 22: [ 2.345969] Process swapper/0 (pid: 1, stack limit = 0xef080210) 23: [ 2.351958] Stack: (0xef081cc8 to 0xef082000) 24: [ 2.356300] 1cc0: 00000000 ef30eb80 00000043 c02d30e8 c02d30e8 00000004 25: [ 2.364460] 1ce0: c0058b5c ef080000 ef1a6ebc c0407168 ef1a6e10 ef1a6e80 c02d30e8 c02d3114 26: [ 2.372619] 1d00: 00000004 c02d465c ef1a6e10 c0852100 c086ea10 c02d46b0 00000000 ef1a6e10 27: [ 2.380778] 1d20: c0852100 c02d54fc eeca0fa0 c00f2934 00000188 eeca0fa0 ef078000 60000013 28: [ 2.388937] 1d40: ef1a6e80 ef1a6e10 ef1a6e80 00000004 60000013 00000000 00000002 ef30ea80 29: [ 2.397096] 1d60: 00000000 c02d56c8 00000000 ef30e800 ef30ea24 60000013 ef080000 c03eff80 30: [ 2.405256] 1d80: eec0b7b8 00000000 ef078000 c0044ee8 00000100 00000200 eec0b6b4 ef30e800 31: [ 2.413415] 1da0: ef30ed2c ef30eb80 ef30e800 00000000 00000200 00000000 ef30ed18 c03f2fd8 32: [ 2.421574] 1dc0: ef30e800 c03f41ac 00000000 c0407ba4 ef264300 ef30eb80 00000808 ef30e800 33: [ 2.429733] 1de0: ef7d3488 00000000 00000000 c03f3dd4 00000000 ef30eb80 00000004 ef1a6e10 34: [ 2.437893] 1e00: ef1a6e00 ef30edec 00000001 ef264110 00000000 c0408be8 05f5e100 c087a810 35: [ 2.446052] 1e20: ef17df50 c087a8a4 5f636d6d 63737562 332e6b6c ee9d9600 00000001 ef1a6e10 36: [ 2.454211] 1e40: fffffffe fffffdfb c087a810 c087a810 00000000 c081683c c0816848 c02ce238 37: [ 2.462370] 1e60: c02ce1e8 ef1a6e10 c08d942c c088e410 00000000 c02cc634 c087a810 ef1a6e44 38: [ 2.470529] 1e80: c088e338 ef1a6e10 c087a810 ef1a6e44 c088e338 00000000 00000000 c02cc8d4 39: [ 2.478688] 1ea0: 00000000 c087a810 c02cc848 c02ca7d4 ef003274 ef17b7c0 c087a810 eebf6f00 40: [ 2.486848] 1ec0: c086ebc8 c02cbb48 c0755dc0 c087a810 c087a810 c0855520 ef267240 c089c000 41: [ 2.495007] 1ee0: c08023cc c02cd0cc c087a7fc c0855520 c0855520 c00097a0 ef15eb00 c0598680 42: [ 2.503166] 1f00: 00000025 0000c000 ef078000 60000013 efffca92 c05aba2c 000000c0 c003da88 43: [ 2.511325] 1f20: 00000001 00000003 c0746c3c c07b1804 00000000 c088c6b8 00000006 00000006 44: [ 2.519484] 1f40: c0858ec8 c0849e3c c084a108 00000006 c089c000 c089c000 c07e35b0 000000c0 45: [ 2.527643] 1f60: c081683c c07e3dec 00000006 00000006 00000000 c07e35b0 ef078000 c0042518 46: [ 2.535802] 1f80: 000000a2 00000000 c058e6c8 00000000 00000000 00000000 00000000 00000000 47: [ 2.543962] 1fa0: 00000000 c058e6d0 00000000 c0010338 00000000 00000000 00000000 00000000 48: [ 2.552121] 1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 49: [ 2.560280] 1fe0: 00000000 00000000 00000000 00000000 00000013 00000000 dffffefb f5fbff7f 50: [ 2.568447] [ 51: [ 2.577557] [ 52: [ 2.587366] [ 53: [ 2.596216] [ 54: [ 2.603942] [ 55: [ 2.611493] [ 56: [ 2.619482] [ 57: [ 2.628161] [ 58: [ 2.636232] [ 59: [ 2.643957] [ 60: [ 2.651855] [ 61: [ 2.660016] [ 62: [ 2.668348] [ 63: [ 2.677200] [ 64: [ 2.685626] [ 65: [ 2.693780] [ 66: [ 2.702025] [ 67: [ 2.710012] [ 68: [ 2.718176] [ 69: [ 2.726855] [