浅谈telnet和gdbserver

2015-02-26发布0条评论

  下面要讲的是如何使用pc机telnet目标机,和如何使用gdbserver调试目标机的代码.

  1.拿到板子后,我所说的烧了boot,kerner,rootfs的板子,可以正常使用的,确保串口终端能正常使用。

  2.完成1之后在目标机rootfs加载完成之后,配置好目标机的ip,单网口可以使用,ifconfigeth0192.168

  .1.xxx,双网口需要多配置一路,ifconfigeth1192.168.1.xxx。配制完成之后可以ping一下同一网段的pc机,看看网络是否已通畅。

  3.Telnet在文件系统中的一些相关支持,如下:

  3.1内核(2.6)和busybox都需要支持udev,并且/usr/sbin/telnetd文件存在。

  3.2/etc/services,里面可以指定telnet的端口号,默认是23.

  3.3/etc/passwd指定登陆的用户账号和密码。

  3.4/etc/protocols指定telnet的使用协议,一般使用TCP即可。

  3.5在rootbox中添加

  mkdir/dev/pts

  mount-tdevptsdevpts/dev/pts

  udevd--daemon

  udevstart

  Telnetd

  重新启动之后,用ps察看一下,网络守护进程是否已经起来,然后PC上用telnet工具登陆即可.

  关于GDBserver的使用缘由,做过linux嵌入式开发的人都有这个感触,资源太少了,显然在目标板上要调试gdb那显然不可能,GDBserver由此诞生,即在交叉编译环境中,由目标机指定代码,端口号,IP(PC机),如gdbserver192.168.1.58:123456hello其中58为我自己的PC机的IP.不过在这之前你需要确定在你的rootfs中有gdbserver存在,一般都是在/bin或/sbin下面的。上述流程顺畅之后,就可以在PC上使用gdb调试了,gdb命令需要跟代码相对应,如使用arm-linux-gcc-g-c-ohellohello.c生成的,需要使用arm-linux-gdbhello调试。

  还有一点就上在挂载nfs网络文件系统的时候,为了不使用默认的udp协议,需要修改挂载参数,

  eg:mount-tnfs-ointr,tcp,nolock192.168.1.8:/home/mstar/nfsroot/root/home

  其中-o选向manmount->nfs如下:

  proto=transport

  ThetransporttheNFSclientusestotransmitrequeststotheNFSserverforthismountpoint.transportcanbeeitherudportcp.Eachtransportusesdifferentdefaultretransandtimeosettings;refertothedescriptionofthesetwomountoptionsfordetails.InadditiontocontrollinghowtheNFSclienttransmitsrequeststotheserver,thismountoptionalsocontrolshowthemount(8)command

  communicateswiththeserver鈙rpcbindandmountdservices.Specifyingproto=tcpforcesalltrafficfromthemount(8)commandandtheNFSclienttouseTCP.Specifyingproto=udpforcesalltraffictypestouseUDP.Iftheprotomountoptionisnotspecified,themount(8)commanddiscoverswhichprotocolstheserversupportsandchoosesanappropriatetransportforeachservice.RefertotheTRANSPORTMETHODSsectionformoredetails.

  udpTheudpoptionisanalternativetospecifyingproto=udp.Itisincludedforcompatibilitywithotheroperatingsystems.

  tcpThetcpoptionisanalternativetospecifyingproto=tcp.Itisincludedforcompatibilitywithotheroperatingsystems.

  port=nThenumericvalueoftheserver鈙NFSserviceport.Iftheserver鈙NFSserviceisnotavailableonthespecifiedport,themountrequestfails.

  Ifthisoptionisnotspecified,orifthespecifiedportvalueis0,thentheNFSclientusestheNFSserviceportnumberadvertisedbytheserver鈙rpcbindservice.Themountrequestfailsiftheserver鈙rpcbindserviceisnotavailable,theserver鈙NFSserviceisnotregisteredwithitsrpcbindservice,ortheserver鈙NFSserviceisnotavailableontheadvertisedport.

  mountport=nThenumericvalueoftheserver鈙mountdport.Iftheserver鈙mountdserviceisnotavailableonthespecifiedport,themountrequestfails.

  is0,thenthemount(8)commandusesthemountdserviceportnumberadver-

  tisedbytheserver鈙rpcbindservice.Themountrequestfailsiftheserver鈙rpcbindserviceisnotavailable,theserver鈙mountdser-viceisnotregisteredwithitsrpcbindservice,ortheserver鈙mountdserviceisnotavailableontheadvertisedport.ThisoptioncanbeusedwhenmountinganNFSserverthroughafirewallthatblockstherpcbindprotocol.

  mountproto=transport

  ThetransporttheNFSclientusestotransmitrequeststotheNFSserver鈙mountdservicewhenperformingthismountrequest,andwhenlaterunmountingthismountpoint.transportcanbeeitherudportcp.ThisoptioncanbeusedwhenmountinganNFSserverthroughafirewallthatblocksaparticulartransport.Whenusedincombinationwiththeprotooption,differenttransportsformountdrequestsandNFSrequestscanbespecified.Iftheserver鈙mountdserviceisnot

  availableviathespecifiedtransport,themountrequestfails.RefertotheTRANSPORTMETHODSsectionformoreonhowthemountprotomountoptioninteractswiththeprotomountoption.mounthost=nameThehostnameofthehostrunningmountd.Ifthisoptionisnotspecified,themount(8)commandassumesthatthemountdservicerunsonthesamehostastheNFSservice.

  mountvers=nTheRPCversionnumberusedtocontacttheserver鈙mountd.Ifthisoptionisnotspecified,theclientusesaversionnumberappropriatetotherequestedNFSversion.ThisoptionisusefulwhenmultipleNFSservicesarerunningonthesameremoteserverhost.

  namlen=nThemaximumlengthofapathnamecomponentonthismount.Ifthisoptionisnotspecified,themaximumlengthisnegotiatedwiththeserver.Inmostcases,thismaximumlengthis255characters.SomeearlyversionsofNFSdidnotsupportthisnegotiation.Usingthisoptionensuresthatpathconf(3)reportsthepropermaximumcompo-nentlengthtoapplicationsinsuchcases.

  nfsvers=nTheNFSprotocolversionnumberusedtocontacttheserver鈙NFSservice.TheLinuxclientsupportsversion2andversion3oftheNFSprotocolwhenusingthefilesystemtypenfs.Iftheserverdoesnotsupporttherequestedversion,themountrequestfails.Ifthisoptionisnotspecified,theclientattemptstouseversion3,butnegotiatestheNFSversionwiththeserverifversion3supportisnotavailable.

  vers=nThisoptionisanalternativetothenfsversoption.Itisincludedforcompatibilitywithotheroperatingsystems.

  lock/nolockSelectswhethertousetheNLMsidebandprotocoltolockfilesontheserver.Ifneitheroptionisspecified(oriflockisspecified),NLMlockingisusedforthismountpoint.Whenusingthenolockoption,applicationscanlockfiles,butsuchlocksprovideexclusiononlyagainstotherapplicationsrunningonthesameclient.Remoteapplicationsarenotaffectedbytheselocks.NLMlockingmustbedisabledwiththenolockoptionwhenusingNFStomount/varbecause/varcontainsfilesusedbytheNLMimplementa-tiononLinux.UsingthenolockoptionisalsorequiredwhenmountingexportsonNFSserversthatdonotsupporttheNLMprotocol.

  intr/nointrSelectswhethertoallowsignalstointerruptfileoperationsonthismountpoint.Ifneitheroptionisspecified(orifnointrisspeci-fied),signalsdonotinterruptNFSfileoperations.Ifintrisspecified,systemcallsreturnEINTRifanin-progressNFSoperationisinterruptedbyasignal.Usingtheintroptionispreferredtousingthesoftoptionbecauseitissignificantlylesslikelytoresultindatacorruption.

  cto/noctoSelectswhethertouseclose-to-opencachecoherencesemantics.Ifneitheroptionisspecified(orifctoisspecified),theclientusesclose-to-opencachecoherencesemantics.Ifthenoctooptionisspecified,theclientusesanon-standardheuristictodeterminewhenfilesontheserverhavechanged.Usingthenoctooptionmayimproveperformanceforread-onlymounts,butshouldbeusedonlyifthedataontheserverchangesonlyocca-sionally.TheDATAANDMETADATACOHERENCEsectiondiscussesthebehaviorofthisoptioninmoredetail.

  acl/noaclSelectswhethertousetheNFSACLsidebandprotocolonthismountpoint.TheNFSACLsidebandprotocolisaproprietaryprotocolimple-mentedinSolaristhatmanagesAccessControlLists.NFSACLwasnevermadeastandardpartoftheNFSprotocolspecification.Ifneitheraclnornoacloptionisspecified,theNFSclientnegotiateswiththeservertoseeiftheNFSACLprotocolissupported,and

  usesitiftheserversupportsit.DisablingtheNFSACLsidebandprotocolmaybenecessaryifthenegotiationcausesproblemsontheclientorserver.RefertotheSECURITYCONSIDERATIONSsectionformoredetails.

  rdirplus/nordirplusSelectswhethertouseNFSversion3READDIRPLUSrequests.Ifthisoptionisnotspecified,theNFSclientusesREADDIRPLUSrequestson

  NFSversion3mountstoreadsmalldirectories.SomeapplicationsperformbetteriftheclientusesonlyREADDIRrequestsforalldirec-tories.

  上述是我在搭建平台的时候遇到的一些经验总结,希望能对大家有用。