Using QEMU for Embedded Systems Development, Part 2 - LINUX For You.pdf

Using QEMU for Embedded Systems Development, Part 2 - LINUX For You.pdf

ID:33881982

大小:815.28 KB

页数:4页

时间:2019-03-01

上传者:不努力梦想只是梦
Using QEMU for Embedded Systems Development, Part 2 - LINUX For You.pdf_第1页
Using QEMU for Embedded Systems Development, Part 2 - LINUX For You.pdf_第2页
Using QEMU for Embedded Systems Development, Part 2 - LINUX For You.pdf_第3页
Using QEMU for Embedded Systems Development, Part 2 - LINUX For You.pdf_第4页
资源描述:

《Using QEMU for Embedded Systems Development, Part 2 - LINUX For You.pdf》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

WriteForUsSubmitTipsSubscribetoPrintEditionSearchHOMEREVIEWSHOW-TOSCODINGINTERVIEWSFEATURESOVERVIEWBLOGSSERIESITADMINUsingQEMUforEmbeddedSystemsSearchfor:SearchDevelopment,Part2ByManojKumaronJuly1,2011inCoding,Developers·3Commentsand0ReactionsGetConnectedInthepreviousarticles,weRSSFeedTwitterlearnthowtouseQEMUforagenericLinuxOSinstallation,fornetworkingusingOpenVPNandTAP/TUN,forcross-compilationoftheLinuxkernelforARM,tobootthekernelfromQEMU,andhowtobuildasmallfilesystemandthenmountitonthevanillakernel.Nowwewillstepoutfurther.Firstofall,Iwouldliketoexplaintheneedforabootloader.ThebootloaderiscodethatisusedtoloadthekernelintoRAM,andthenspecifywhichpartitionwillbemountedastherootfilesystem.ThebootloaderresidesintheMBR(MasterBootRecord).Ingeneral-purposecomputingmachines,animportantcomponentistheBIOS(BasicInputOutputSystem).TheBIOScontainsthelow-leveldriversfordeviceslikethekeyboard,mouse,display,etc.Itinitiatesthebootloader,whichthenloadsthekernel.Linuxusersareveryfamiliarwithboot-loaderslikeGRUB(GrandUnifiedBoot-Loader)andLILO(LinuxLoader).Micro-controllerprogrammersareveryfamiliarwiththeterm“Bare-MetalProgramming”.Itmeansthatthereisnothingbetweenyourprogramandtheprocessor—thecodeyouwriterunsdirectlyontheprocessor.Itbecomestheprogrammer’sresponsibilitytocheckeachandeverypossibleconditionthatcancorruptthesystem.Now,letusbuildasmallprogramfortheARMVersatilePlatformBaseboard,whichwillrunontheQEMUemulator,andthenprintamessageontheserialconsole.Downloadedthetool-chainforARMEABIfromhere.Asdescribedinthepreviousarticle,addthistool-chaininyourPATH.Bydefault,QEMUredirectstheserialconsoleoutputtotheterminal,whenitisinitialisedwiththenographicoption:$qemu-system-arm--help|grepnographic-nographicdisablegraphicaloutputandredirectserialI/Ostoconsole.Whenusing-nographic,press'ctrl-ah'togetsomehelp.Wecanmakegooduseofthisfeature;let’swritesomedatatotheserialport,anditcanbeagoodworkingexample.Beforegoingfurther,wemustmakesurewhichprocessortheGNUEABItool-chainsupports,andwhichprocessorQEMUcanemulate.Thereshouldbeasimilarprocessorsupportedbyboththetool-chainandtheemulator.Let’scheckfirstinQEMU.Intheearlierarticles,wecompiledtheQEMUsourcecode,sousethatsourcecodetogetthelistofthesupportedARMprocessors:LINUXForYouonFollow$cd(your-path)/qemu/qemu-0.14.0/hw$grep"arm"versatilepb.c#include"arm-misc.h"+2,296staticstructarm_boot_infoversatile_binfo;cpu_model="arm926";It’sveryclearthatthe“arm926″issupportedbyQEMU.Let’scheckitsavailabilityintheGNUARMtool-chain: $cd(your-path)/CodeSourcery/Sourcery_G++_Lite/share/doc/arm-arm-none-eabi/info$catgcc.info|greparm|head-n20无法显示此.网页.`strongarm1110',`arm8',`arm810',`arm9',`arm9e',`arm920',`arm920t',`arm922t',`arm946e-s',`arm966e-s',`arm968e-s',由于www.facebook.com响应时间过长,导致`arm926ej-s',`arm940t',`arm9tdmi',`arm10tdmi',`arm1020t',GoogleChrome无法加载网页。该网站可能已崩`arm1026ej-s',`arm10e',`arm1020e',`arm1022e',`arm1136j-s',溃,或者您的互联网连接出现了问题。Great!!TheARM926EJ-SprocessorissupportedbytheGNUARMtool-chain.Now,let’swrite以下是一些建议:somedatatotheserialportofthisprocessor.Aswearenotusinganyheaderfilethatdescribes请稍后重新加载此网页。theaddressofUART0,wemustfinditmanually,fromthefile(your-path)/qemu/qemu-请检查您的互联网连接状况,重新启动您可0.14.0/hw/versatilepb.c:能正在使用的任何路由器、调制解调器以及其他网络设备。/*0x101f0000Smartcard0.*//*0x101f1000UART0.*/将GoogleChrome作为允许的程序添加到/*0x101f2000UART1.*/您的防火墙或防病毒软件设置中。如果已经/*0x101f3000UART2.*/是允许的程序,则请尝试从允许的程序列表中将其删除,然后重新添加。Opensourcecodeissopowerful,itgivesyoueachandeverydetail.UART0ispresentataddress0x101f1000.Fortestingpurposes,wecanwritedatadirectlytothisaddress,andcheckoutputontheterminal.CompleteMagazineonOpenSource@LinuxForYouOurfirsttestprogramisabare-metalprogramrunningdirectlyontheprocessor,withoutthehelpofabootloader.Wehavetocreatethreeimportantfiles.Firstofall,letusdevelopasmallapplicationprogram(init.c):volatileunsignedchar*constUART0_PTR=(unsignedchar*)0x0101f1000;voiddisplay(constchar*string){while(*string!=''){*UART0_PTR=*string;string++;}}intmy_init(){display("HelloOpenWorld ");}Let’srunthroughthiscodesnippet.First,wedeclaredavolatilevariablepointer,andassignedtheaddressoftheserialport(UART0).Thefunctionmy_init(),isthemainroutine.Itmerelycallsthefunctiondisplay(),whichwritesastringtotheUART0.Engineersfamiliarwithbase-levelmicro-controllerprogrammingwillfindthisveryeasy.IfyouareJointheconversationnotexperiencedinembeddedsystemsprogramming,thenyoucansticktothebasicsofdigitalelectronics.Themicroprocessorisanintegratedchip,withinput/outputlines,differentports,etc.TheARM926EJ-Shasfourserialports(informationobtainedfromitsdata-sheet);andtheyhavetheirdatalines(theaddress).WhentheprocessorisprogrammedtowritedatatooneofthePopularCommentsTagcloudserialports,itwritesdatatotheselines.That’swhatthisprogramdoes.February27,2013·7Comments·COSSLinuxProfessionalsinHighDemandThenextstepistodevelopthestartupcodefortheprocessor.Whenaprocessorispoweredon,itjumpstoaspecifiedlocation,readscodefromthatlocation,andexecutesit.EveninthecaseMarch1,2013·4Comments·vinayak-pandeyofareset(likeonadesktopmachine),theprocessorjumpstoapredefinedlocation.Here’sthePlayingHideandSeekwithPasswordsstartupcode,startup.s:April4,2013·4Comments·Aditya-PareekCrunchbangLinuxMinimalistandMac-Friendly.global_Start_Start:LDRsp,=sp_topMarch1,2013·3Comments·BoudhayanGuptaBLmy_initIntroducingSamba4Now,EvenMoreAwesomenessB.April1,2013·2Comments·vinayak-pandeyInthefirstline,_Startisdeclaredasglobal.Thenextlineisthebeginningof_Start‘scode.WeLearntheArtofLinuxTroubleshootingsettheaddressofthestacktosp_top.(TheinstructionLDRwillmovethedatavalueofsp_topinthestackpointer(sp).TheinstructionBLwillinstructtheprocessortojumptomy_init(previouslydefinedininit.c).ThentheprocessorwillstepintoaninfiniteloopwiththeinstructionB.,whichislikeawhile(1)orfor(;;)loop.Ifwedon’tdothis,oursystemwillcrash.Thebasicsofembeddedsystemsprogrammingisthatourcodeshouldrunintoaninfiniteloop.Now,thefinaltaskistowritealinkerscriptforthesetwofiles(linker.ld):ENTRY(_Start)SECTIONS{.=0x10000;startup:{startup.o(.text)}.data:{*(.data)}.bss:{*(.bss)}.=.+0x500;sp_top=.;}Thefirstlinetellsthelinkerthattheentrypointis_Start(definedinstartup.s).Asthisisabasicprogram,wecanignoretheInterruptssection.TheQEMUemulator,whenexecutedwiththe- kerneloption,startsexecutionfromtheaddress0x10000,sowemustplaceourcodeatthisaddress.That’swhatwehavedoneinLine4.Thesection“SECTIONS”,definesthedifferentsectionsofaprogram.Inthis,startup.oformsthetext(code)part.Thencomesthesubsequentdataandthebsspart.Thefinalstepistodefinetheaddressofthestackpointer.Thestackusuallygrowsdownward,soit’sbettertogiveitasafeaddress.Wehaveaverysmallcodesnippet,andcanplacethestackat0x500aheadofthecurrentposition.Thevariablesp_topwillstoretheaddressforthestack.Wearenowdonewiththecodingpart.Let’scompileandlinkthesefiles.Assemblethestartup.sfilewith:$arm-none-eabi-as-mcpu=arm926ej-sstartup.s-ostartup.oCompileinit.c:$arm-none-eabi-gcc-c-mcpu=arm926ej-sinit.c-oinit.oLinktheobjectfilesintoanELFfile:$arm-none-eabi-ld-Tlinker.ldinit.ostartup.o-ooutput.elfFinally,createabinaryfilefromtheELFfile:$arm-none-eabi-objcopy-Obinaryoutput.elfoutput.binTheaboveinstructionsareeasytounderstand.AllthetoolsusedarepartoftheARMtool-chain.Checktheirhelp/manpagesfordetails.Afterallthesesteps,finallywewillrunourprogramontheQEMUemulator:$qemu-system-arm-Mversatilepb-nographic-kerneloutput.binTheabovecommandhasbeenexplainedinpreviousarticles(1,2),sowewon’tgointothedetails.ThebinaryfileisexecutedonQEMUandwillwritethemessage“HelloOpenWorld”toUART0oftheARM926EJ-S,whichQEMUredirectsasoutputintheterminal.AcknowledgementThisarticleisinspiredbythefollowingblogpost:“HelloworldforbaremetalARMusingQEMU“.RelatedPosts:UsingQEMUforEmbeddedSystemsDevelopment,Part3UsingQEMUforEmbeddedSystemsDevelopment,Part1TheQuickGuidetoQEMUSetupKernelDevelopment&DebuggingUsingtheEclipseIDEBuildingImageProcessingEmbeddedSystemsusingPython,Part3Tags:ARM926EJ-Sprocessor,bare-metalprogram,Bare-MetalProgramming,binaryfile,bootloader,digitalelectronics,ELF,embeddedsystems,embeddedsystemsprogramming,integratedchip,LFYJuly2011,Linuxkernel,MBR,openvpn,QEMU,rootfilesystem,serialportsArticlewrittenby:ManojKumarTheauthorisafreelancedeveloperandtrainer.HeleadsateaminLinuxkernelprogramming,Linuxadministration,clustercomputing,embeddedsystemsandQT/GTKprogrammingonLinux.ViewandparticipateinthelatestdiscussionsonhisYahooGroup.Connectwithhim:WebsitePreviousPostNextPostTheNagiosSetupExplainedWordPressMulti-siteServersonProductionMachines ALSOONLINUXFORYOUALSOONLINUXFORYOU3comments0Leaveamessage...NewestCommunitySharenmr•ayearagohi,ayearagowhilelinkingobjectfilestest.oandstartup.ousingthecommand:-”$arm-none-eabi-ld-Ttest.ldtest.ostartup.o-otest.elf”itshowsanERRORError:-“cannotfindstartup.o”.plzhelpme……thanks,nmrReplyShare›ReplyShare›DaredevilVivek•ayearagohaiiamnotabletocompiletheinit.cfile.igetthisaserrorayearagoinit.c:Assemblermessages:init.c:4:Error:badinstruction`volatileunsignedchar*constUART0_PTR=(unsignedchar*)0x0101f1000'init.c:5:Error:badinstruction`voiddisplay(constchar*string){'init.c:6:Error:badinstruction`while(*string!=48){'init.c:7:Error:junkatendofline,firstunrecognizedcharacteris`*'init.c:8:Error:badinstruction`string++'init.c:9:Error:junkatendofline,firstunrecognizedcharacteris`}'init.c:10:Error:junkatendofline,firstunrecognizedcharacteris`}'init.c:12:Error:badinstruction`intmy_init(){'init.c:13:Error:badinstruction`display("HelloOpenWorld ")'init.c:14:Error:junkatendofline,firstunrecognizedcharacteris`}'ReplyShare›ReplyShare›Balau•ayearagoThanksfortheacknowledge!ayearago1ReplyShare›ReplyShare›CommentfeedSubscribeviaemailCommentfeedSubscribeviaemailReviewsHow-TosCodingInterviewsFeaturesOverviewBlogsForYou&MeSearchDevelopersSysadminsPopulartagsOpenGurusCXOsLinux,ubuntu,Java,MySQL,Google,python,Fedora,Android,PHP,ColumnsC,html,webapplications,India,Microsoft,unix,Windows,RedHat,Oracle,Security,Apache,xml,LFYApril2012,FOSS,GNOME,http,JavaScript,LFYJune2011,opensource,RAM,operatingsystemsAllpublishedarticlesarereleasedunderCreativeCommonsAttribution-NonCommercial3.0UnportedLicense,unlessotherwisenoted.LINUXForYouispoweredbyWordPress,whichgladlysitsontopofaCentOS-basedLEMPstack..

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
关闭