{"id":483,"date":"2011-06-24T14:07:22","date_gmt":"2011-06-24T21:07:22","guid":{"rendered":"http:\/\/blog.mezeske.com\/?p=483"},"modified":"2011-06-24T16:04:16","modified_gmt":"2011-06-24T23:04:16","slug":"boot-a-kernel-over-serial-with-u-boot-and-kermit","status":"publish","type":"post","link":"http:\/\/blog.mezeske.com\/?p=483","title":{"rendered":"Boot a Kernel over Serial with U\u2011Boot and Kermit"},"content":{"rendered":"<p>I\u2019m doing a lit\u00adtle bit of work that involves fre\u00adquent\u00adly rebuild\u00ading the Linux ker\u00adnel and installing it on a head\u00adless <span class=\"caps\">ARM<\/span> board.  The par\u00adtic\u00adu\u00adlar <span class=\"caps\">ARM<\/span> board I\u2019m work\u00ading with has some ven\u00addor sup\u00adport for flash\u00ading ker\u00adnels, but it\u2019s slow and clunky, and I have to run it inside a Windows <span class=\"caps\">XP<\/span> <span class=\"caps\">VM<\/span>.  The <span class=\"caps\">ARM<\/span> board uses the U\u2011Boot boot\u00adloader, though, so it\u2019s pos\u00adsi\u00adble to boot the ker\u00adnel in a cou\u00adple of dif\u00adfer\u00adent ways.  One way would be to load the ker\u00adnel via <span class=\"caps\">TFTP<\/span>, but I haven\u2019t got\u00adten that work\u00ading yet on my board.  The oth\u00ader option is to load it via ser\u00adi\u00adal, which isn\u2019t very fast but requires very lit\u00adtle&nbsp;setup.<\/p>\n<p>U\u2011Boot\u2019s <em>loadm<\/em> com\u00admand allows a ker\u00adnel to be loaded, via ser\u00adi\u00adal, into a mem\u00ado\u00adry loca\u00adtion.  The <em>bootm<\/em> com\u00admand may then be used to boot the ker\u00adnel direct\u00adly, which saves time com\u00adpared to writ\u00ading the ker\u00adnel to the flash mem\u00ado\u00adry and load\u00ading it from there.  The trou\u00adble is that <em>loadm<\/em> expects the ker\u00adnel to be sent via the Kermit pro\u00adto\u00adcol.  I found a few exam\u00adples of how to deal with Kermit, but none of them direct\u00adly applied to load\u00ading a ker\u00adnel with U\u2011Boot.<\/p>\n<p>I came up with the fol\u00adlow\u00ading Kermit script to solve my prob\u00adlem.  This script auto\u00admat\u00adi\u00adcal\u00adly waits for the board to reset, sends the <em>loadm<\/em> com\u00admand, push\u00ades down the ker\u00adnel, and runs it via the <em>bootm<\/em> com\u00admand.  After it boots the ker\u00adnel, it turns into an inter\u00adac\u00adtive con\u00adsole.  This script relies on C\u2011Kermit, which I installed under Ubuntu as follows:<\/p>\n<div class=\"codecolorer-container bash twitlight\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"bash codecolorer\"><span class=\"co4\">bash$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">aptitude install<\/span> ckermit<\/div><\/div>\n<p>The script I\u2019m using is as fol\u00adlows.  There are a lot of set\u00adtings hard-cod\u00aded into the script, so read the com\u00adments care\u00adful\u00adly to deter\u00admine what parts you might need to change to suit your set\u00adup.  To use this script, sim\u00adply copy it into a file named, for exam\u00adple, <em>boot-ker\u00adnel<\/em>, give it exe\u00adcutable per\u00admis\u00adsions, and run&nbsp;it.<\/p>\n<div class=\"codecolorer-container bash twitlight\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"bash codecolorer\"><span class=\"co0\">#!\/usr\/bin\/kermit<\/span><br>\n<br>\n<span class=\"co0\"># Serial port setup. &nbsp;These settings will likely need to be<\/span><br>\n<span class=\"co0\"># changed to match the configuration of your workstation<\/span><br>\n<span class=\"co0\"># and the ARM board you're working with.<\/span><br>\n<span class=\"kw1\">set<\/span> line <span class=\"sy0\">\/<\/span>dev<span class=\"sy0\">\/<\/span>ttyUSB0<br>\n<span class=\"kw1\">set<\/span> speed <span class=\"nu0\">115200<\/span><br>\n<span class=\"kw1\">set<\/span> serial 8n1<br>\n<br>\n<span class=\"co0\"># General C-Kermit settings. &nbsp;These probably don't need to change.<\/span><br>\n<span class=\"kw1\">set<\/span> flow-control none<br>\n<span class=\"kw1\">set<\/span> <span class=\"kw2\">file<\/span> <span class=\"kw3\">type<\/span> bin<br>\n<span class=\"kw1\">set<\/span> carrier-watch off<br>\n<span class=\"kw1\">set<\/span> prefixing all<br>\n<span class=\"kw1\">set<\/span> modem none<br>\n<br>\n<span class=\"kw3\">echo<\/span> <span class=\"st0\">\"Prepared to boot new kernel. &nbsp;Reset the board now.\"<\/span><br>\n<br>\n<span class=\"co0\"># This is the string that my board outputs to allow the user to<\/span><br>\n<span class=\"co0\"># gain access to the U-Boot console. &nbsp;Change this to suit your<\/span><br>\n<span class=\"co0\"># setup.<\/span><br>\ninput <span class=\"nu0\">60<\/span> <span class=\"st0\">\"Hit SPACE to stop autoboot\"<\/span><br>\n<span class=\"co0\"># If your board wants you to press a different key to get to<\/span><br>\n<span class=\"co0\"># U-Boot, edit this line.<\/span><br>\noutput <span class=\"st0\">\" \"<\/span><br>\ninput <span class=\"nu0\">5<\/span> <span class=\"st0\">\"u-boot&gt;\"<\/span><br>\n<span class=\"co0\"># Here, 0x800000 is the memory address into which the kernel<\/span><br>\n<span class=\"co0\"># should be loaded.<\/span><br>\nlineout <span class=\"st0\">\"loadb 0x800000\"<\/span><br>\n<span class=\"co0\"># This should be the absolute path to your kernel uImage file.<\/span><br>\nsend <span class=\"sy0\">\/<\/span>path<span class=\"sy0\">\/<\/span>to<span class=\"sy0\">\/<\/span>uImage<br>\ninput <span class=\"nu0\">5<\/span> <span class=\"st0\">\"u-boot&gt;\"<\/span><br>\nlineout <span class=\"st0\">\"bootm 0x800000\"<\/span><br>\n<br>\n<span class=\"co0\"># This command drops you into a console where you can interact<\/span><br>\n<span class=\"co0\"># with the kernel.<\/span><br>\nconnect<\/div><\/div>\n<p>Once the script has giv\u00aden you con\u00adsole con\u00adtrol, you need to use the Kermit escape key to exit.  By default, this is set to <em>Ctrl+\\<\/em> (that\u2019s a back\u00adslash).  To see a list of com\u00admands, type <em>Ctrl+\\<\/em> and then <em>?<\/em>.  The com\u00admand to imme\u00addi\u00adate\u00adly exit the con\u00adsole is <em>q<\/em>.<\/p>\n<p>One last thing to note: this script does\u00adn\u2019t do any error check\u00ading.  Each of the <em>input<\/em> com\u00admands can fail, if it does not see the text it\u2019s look\u00ading for in the spec\u00adi\u00adfied time.  The script could be extend\u00aded to check for errors using Kermit\u2019s <em><span class=\"caps\">IF<\/span><\/em> command.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019m doing a lit\u00adtle bit of work that involves fre\u00adquent\u00adly rebuild\u00ading the Linux ker\u00adnel and installing it on a head\u00adless <span class=\"caps\">ARM<\/span> board. The par\u00adtic\u00adu\u00adlar <span class=\"caps\">ARM<\/span> board I\u2019m work\u00ading with has some ven\u00addor sup\u00adport for flash\u00ading ker\u00adnels, but it\u2019s slow and clunky, and I have to run it inside a Windows <span class=\"caps\">XP<\/span> <span class=\"caps\">VM<\/span>. The <span class=\"caps\">ARM<\/span>&nbsp;board&nbsp;[\u2026]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wp_typography_post_enhancements_disabled":false},"categories":[3],"tags":[5,33,32],"_links":{"self":[{"href":"http:\/\/blog.mezeske.com\/index.php?rest_route=\/wp\/v2\/posts\/483"}],"collection":[{"href":"http:\/\/blog.mezeske.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.mezeske.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.mezeske.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.mezeske.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=483"}],"version-history":[{"count":21,"href":"http:\/\/blog.mezeske.com\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions"}],"predecessor-version":[{"id":504,"href":"http:\/\/blog.mezeske.com\/index.php?rest_route=\/wp\/v2\/posts\/483\/revisions\/504"}],"wp:attachment":[{"href":"http:\/\/blog.mezeske.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.mezeske.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=483"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.mezeske.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}