Supporting A New ARM Platfrom: The Allwinner Example - ELinux

Transcription

Embedded Linux Conference 2014Supporting a new ARM platform: theAllwinner exampleMaxime RipardFree Electronsmaxime@free-electrons.comFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com1/36

Maxime RipardIEmbedded Linux engineer and trainer at Free ElectronsIIIIContributionsIIIEmbedded Linux development: kernel and driverdevelopment, system integration, boot time and powerconsumption optimization, consulting, etc.Embedded Linux training, Linux driver development trainingand Android system development training, with materialsfreely available under a Creative Commons license.http://free-electrons.comKernel support for the sunXi SoCs from AllwinnerContributor to few open-source projects, Buildroot, anopen-source, simple and fast embedded Linux build system,Barebox, a modern bootloader.Living in Toulouse, south west of FranceFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com2/36

IntroductionIntroductionFree ElectronsEmbedded LinuxDevelopersMaxime RipardFree Electronsc Copyright 2004-2014, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com3/36

AllwinnerIChinese fabless SoC vendorIFounded in 2007, in ZhuhaiIAlways did ARM SoC, starting with ARM9 CPUsIMostly doing multimedia SoCsI550 employeesFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com4/36

Tablet Market Share in 2013Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com5/36

SoC Line-upIF-SeriesIIIA10 / A10s / A12 / A13 (sun4i/sun5i), A20 (sun7i)IIIIIQuad Cortex-A7The GPU is Imagination’s PowerVRBrand new design, a lot of IPs changedA23/A33 (sun8iw3/sun8iw5)IIICortex-A8 based for the sun4i/sun5iDual Cortex-A7 for the A20A31 / A31s (sun6i)IIARM9-based SoCsMostly were running a custom OS called MeliOS, except forthe late SoCs in that familyDual/Quad Cortex-A7An hybrid between the A20 and the A31A80 (sun9i)Ibig.LITTLE with 4 Cortex A15 and 4 Cortex A7Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com6/36

Development / Hacker-friendly boardsIOlimex OlinuxinoIIIICubieboardsIIIOpen Source HardwareAccess to most of the SoC pins through 0.1” headersVery supportive towards the communityTiny, and cheapA very strong community has been built around itA lot of other boards: pcDuino, Marsboard, Banana Pi, etc.Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com7/36

BoardsFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com8/36

Where we wereWhere we wereFree ElectronsEmbedded LinuxDevelopersMaxime RipardFree Electronsc Copyright 2004-2014, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com9/36

Allwinner’s KernelIAllwinner Kernel are mostly based on two kernels:IILinux 3.0 for Cortex-A8 based SoCsLinux 3.3/3.4 for Cortex-A7 based SoCsIJust like most vendor code, their focus is primarily on makingthat particular kernel version working on one SoCIThere’s one different kernel tree for each SoC, even if they arereally closeIApart from that, given the version they’re based on, they’re inpretty decent shapeFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com10/36

Allwinner Kernel IssuesIHowever, it suffers some major issuesIBy today standards, the code is pretty outdatedIIIIIINo Common Clock FrameworkNo pinctrl / GPIOlibNo dmaengineThere’s no consolidation at all between the SoCs codeYou’re pretty much stuck with that kernel version. And there’s FEXFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com11/36

FEXIIt is a binary file, compiled from a human-readable text fileIPassed along the boot chain to the various components(bootloaders, kernel)IUsed to get the hardware configuration of the board they’rerunning on, in a generic wayIn the FEX script, you getIIIIIIIWhich device are enabledThe memory timingsThe clocks frequencyThe pin muxingThe regulators voltagePlus, various hardware and configuration informationFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com12/36

How it looks like[twi1 para]twi used 1twi scl port:PH16 2 default default default twi sda port:PH17 2 default default default [mmc0 para]sdc used 1sdc detmode 2sdc buswidth 4sdc clk port:PF02 2 1 2 default sdc cmd port:PF03 2 1 2 default sdc d0 port:PF01 2 1 2 default sdc d1 port:PF00 2 1 2 default sdc d2 port:PF05 2 1 2 default sdc d3 port:PF04 2 1 2 default sdc det port:PA08 6 1 2 default Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com13/36

How it is usedIIIt is then compiled by fexc to a binary fileThen, Linux will have hardcoded devices, and each matchingdevice willIIIIBe probedLookup the FEX to get if it is allowed to probeThen retrieve whatever parameter it is interested inEven though it is a lot like the device tree, the logic iscompletely backwardFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com14/36

Pros / ConsIProsIIIIIMost of the DT ProsAllows to have a completely generic kernel imageSeparates the hardware description from the codeAllows a very short time-to-boot, even if you’re not really akernel developerConsIIICompletely non-standardOnly works for a single platformNot generic enoughFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com15/36

FEX moment of gloryso.coming back to what you said earlier: I’m formulatingwhat to say to allwinner [and need to pre-send somethingby monday so that they can consider it before themeeting]. so far, it consists of:* device-tree is what the linux kernel community hascome up with, it is equivalent to FEX.* the linux kernel community would like to apologisefor not consulting with you (allwinner) on the decision toonly accept device tree(Luke Kenneth Casson Leighton, 6/7/2013)Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com16/36

FEX moment of gloryThanks to their script.fex system when i said theyonly need to develop one kernel and one u-boot i reallywasn’t kidding around: they really have got to the pointwhich everyone else dreams of with device-tree(Luke Kenneth Casson Leighton, 6/7/2013)Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com17/36

FEX moment of gloryI have a Cubieboard and I have a pca9532 on mydesk. Now I want to attach this pca9532 to theCubieboard so I wire them together on I2C. How is theAllwinner kernel going to load the driver for thepca9532? The mainline pca9532 driver does notunderstand fex so it can’t read the necessary initializationdata.(Jon Smirl, 6/6/2013)You’re immediately outside of the target market forwhich allwinner designed and deployed script.fex.(Luke Kenneth Casson Leighton, 6/6/2013)Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com18/36

Boot ProcessFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com19/36

CommunityCommunityFree ElectronsEmbedded LinuxDevelopersMaxime RipardFree Electronsc Copyright 2004-2014, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com20/36

linux-sunxiIA community started around rhombus-tech and theirEOMA-68 standard in 2010IIt forked off in 2011, and created http://linux-sunxi.orgIIt’s very active these days, with around 600 subscribers on theML, and around 150 persons on IRC (idlers included)IAround 10 very active developers, working on different areasof the SoC support: bootloader, kernel, VPU and GPU reverseengineering, distribution support, etc.ILibre Software ExtremistsFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com21/36

AchievementsIDocumentation of the hardwareIDocumentation of the BSPIImplementation of needed toolsIMaintainance of linux and u-bootIBring up of DistributionsIReverse engineering of the SoC (NAND, VPU, etc.)Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com22/36

linux-sunxi kernelIIMaintains a fork of Allwinner’s kernelDoes all the maintenance workIIIISupport most of the SoCs made by Allwinner in one singlekernel treeFactorizes and cleans up the codeFix bugsBased on a 3.4 (stable) kernelFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com23/36

Community Kernel: Pros and ConsIProsIIIIIMaintain the code that Allwinner doesn’tAllows to run your own Android/Fedora/Buildroot on yourcheap tabletSlightly better than the Allwinner codeWorks well for the hobbyist that just wants to play with hisnew toyConsIIIIIStuck in the pastDoesn’t think about the long-term viewOnly keeps hacking more without thinking about upstreamingchanges to lessen their burdenNot much better than Allwinner codeSupport for new “generation” SoCs?Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com24/36

MainliningMainliningFree ElectronsEmbedded LinuxDevelopersMaxime RipardFree Electronsc Copyright 2004-2014, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com25/36

How it startedIStarted in late 2011IFirst code merged in Linux 3.8, for the Allwinner A13IWas not doing much at the timeIWas only able to boot to an initramfsIOther SoCs and features quickly followedFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com26/36

ContributionsFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com27/36

ChallengesIRewrite most of the core drivers to use the new subsystems:CCF, pinctrl, dmaengineIMove away from FEX, to DTIClean up the code to make it fit for submissionIGet the code acceptedFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com28/36

BabelfishICouldn’t boot a generic kernel on every board out thereanymoreIWorked on sunxi-babelfish, a runtime FEX-to-DT translatorIBehaves like a regular u-boot kernel image, and embeds DTSIand the DT-based kernel imageIAt runtime, will lookup the data from the FEX file, andconstruct the DT from the skeletons it has, and pass it to theDT kernelIEnables to run a DT-based kernel on every cheap tablet outthere, without modifying the bootloader.INot very used, and support only a few devicesIOnly to be seen as a legacy solutionFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com29/36

BabelfishFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com30/36

Current StatusIAll the core stuff works, only DMA is missing on the olderSoCsIMost of the latest fancy stuff: PSCI, Virtualization, etc.INetwork worksIStorage starts to work too: SATA and MMC are merged,MMC is pendingIPretty much everything you need for a headless system worksnowadays.IThe only things missing are the user-friendly ones: Display,Audio, touchscreen, etc.Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com31/36

What’s nextWhat’s nextFree ElectronsEmbedded LinuxDevelopersMaxime RipardFree Electronsc Copyright 2004-2014, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com32/36

Allwinner’s usage of the codeILatest kernel still based on Linux 3.4IThey are using some of our code though (clock, pinctrl)IAre switching to standard APIs (dmaengine, ASoC)IBut are still using FEXIJoined LinaroFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com33/36

TODO-ListIPretty much all the hard work nowINAND is working, but is going (slowly) through themainlining processIAudio is working for some SoCs, and is in the cleanup phaseIVideo is still an issueIWork on newer SoCs (A33, A80, A83)IPlenty of things to do, you’re welcome to join!Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com34/36

Lessons LearnedITake your timeIKnow when to start from scratch and when to clean upIYou want documentationIHave as much hardware as you canIYou don’t want to be alone in thereFree Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com35/36

Questions?Maxime Ripardmaxime@free-electrons.comSlides under CC-BY-SA elc/ripard-mainliningof-out-of-tree-socs/Free Electrons. Kernel, drivers, embedded Linux and Android - Development, consulting, training and support. http://free-electrons.com36/36

Development / Hacker-friendly boards I Olimex Olinuxino I Open Source Hardware I Access to most of the SoC pins through 0.1" headers I Very supportive towards the community I Cubieboards I Tiny, and cheap I A very strong community has been built around it I A lot of other boards: pcDuino, Marsboard, Banana Pi, etc. Free Electrons. Kernel, drivers, embedded Linux and Android - Development .