{"id":1122,"date":"2016-10-08T10:10:12","date_gmt":"2016-10-08T18:10:12","guid":{"rendered":"http:\/\/www.beyond-circuits.com\/wordpress\/?page_id=1122"},"modified":"2016-10-14T08:27:45","modified_gmt":"2016-10-14T16:27:45","slug":"tutorial27","status":"publish","type":"page","link":"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial27\/","title":{"rendered":"Tutorial 27 : Booting PicoZed using eMMC FLASH"},"content":{"rendered":"<p>In my current project we are using a PicoZed module with a custom carrier board. But the carrier board does not have a SD card so we want to boot Linux from the eMMC module on the PicoZed board.<\/p>\n<p>There is a good <a href=\"https:\/\/www.google.com\/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwjIwc3H6cnPAhUS82MKHTbiDjEQFggeMAA&amp;url=http%3A%2F%2Fzedboard.org%2Freference-designs-categories%2Fapplication-note-booting-picozed-using-qspi-and-emmc&amp;usg=AFQjCNF7d-p5HKiSOBrKr6FXX-mpJdAhyA&amp;sig2=Du-XnOtCrCkKZx5vlycIpg\">document<\/a> from Avnet about it but there are a couple of things you need to know to get it working. I thought I would cover what I needed to do to get it working here.<\/p>\n<h1>Overview<\/h1>\n<p>First I want to go over a high level description of what we are going to do. It can be a little confusing. Normally on the FMC development board you boot the board using the SD card. You program a BOOT.BIN and an image.ub onto a FAT filesystem on the SD card, plug it in to the carrier board, and boot. You can program the SD card on your build machine or as I usually do once development is in progress I just scp the files from the build machine to the development board directly. That way you don&#8217;t need to move the SD card physically.<\/p>\n<p>Without an SD card in your carrier board things change a little. The goal is to not boot the board using the QSPI interface to a Micron FLASH chip. This only loads UBoot. UBoot then programs the FPGA and then uses the SD card interface to access the eMMC chip on the PicoZed. This eMMC chip behaves like an SD card but is not removable.<\/p>\n<p>So to get all this working you first need a Linux build and FPGA which can access both the SD card on the PicoZed FMC carrier board, and the eMMC on the PicoZed module. Next you need to build your target FPGA application which accesses the eMMC memory and the Linux build for your application.<\/p>\n<p>We will use this bootstrap Linux build and FPGA to write our actual application FPGA and Linux build to the QSPI FLASH and eMMC memory. Then when we place our PicoZed module in our application carrier board it will boot our target application. If you included Ethernet on your carrier board then you can use that to update your eMMC as your development progresses. If you didn&#8217;t include SD support or Ethernet (what were you thinking?) on your carrier, then you need to use JTAG to program your images or you need to keep moving PicoZed modules back and forth between your carrier board and the FMC carrier board.<\/p>\n<h1>Bootstrap FPGA Requirements<\/h1>\n<div id=\"attachment_1123\" style=\"width: 310px\" class=\"wp-caption alignright\"><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/10\/tutorial27_mio_config.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1123\" class=\"wp-image-1123 size-medium\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/10\/tutorial27_mio_config-300x111.png\" alt=\"tutorial27_mio_config\" width=\"300\" height=\"111\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/10\/tutorial27_mio_config-300x111.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/10\/tutorial27_mio_config.png 409w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1123\" class=\"wp-caption-text\">Enable the second SDHC controller<\/p><\/div>\n<div id=\"attachment_1124\" style=\"width: 267px\" class=\"wp-caption alignright\"><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/10\/tutorial27_CDN.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1124\" class=\"wp-image-1124 size-medium\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/10\/tutorial27_CDN-257x300.png\" alt=\"tutorial27_cdn\" width=\"257\" height=\"300\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/10\/tutorial27_CDN-257x300.png 257w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2016\/10\/tutorial27_CDN.png 411w\" sizes=\"auto, (max-width: 257px) 100vw, 257px\" \/><\/a><p id=\"caption-attachment-1124\" class=\"wp-caption-text\">Connect the chip detect to a logic zero<\/p><\/div>\n<p>First, on your bootstrap FPGA design you need to enable the SD 1 device in the MIO configuration for the ARM processor. Use MIO pins 10 through 15. Also, you need to enable the Chip Detect port (CD) and connect it to EMIO. You will need to connect this to a logic zero in your FPGA design.<\/p>\n<p>Once you have done this you can build your FPGA and export the hardware description to SDK. My FPGA has just the ZYNQ processor, the constant 0 feeding to the SDIO1_CDN pin and the FCLK_CLK0 feeding back to the M_AXI_GP0_ACLK input of the ZYNQ module.<\/p>\n<h1>Configure Linux<\/h1>\n<p>Use petalinux-config with the &#8211;get-hw-description to pull in the hardware for the FPGA to Linux. If you used an older\u00a0version of the PicoZed BSP you will need to modify the subsystems\/linux\/configs\/device-tree\/system-top.dts file and add the following lines. The default compatible value for the FLASH chip is not specific enough to enable the eMMC chip on the PicoZed. Check the file to see if you need to make the changes. You should see an entry like this.<\/p>\n<pre>&amp;qspi {\r\n  flash0: flash@0 {\r\n    compatible = \"micron,n25q128a13\";\r\n  };\r\n};\r\n<\/pre>\n<h1>Bootstrapping<\/h1>\n<p>You should now run petalinux-build and petalinux-package to build a Linux that will boot from the SD card on a carrier board. This build will be aware of the eMMC chip and be able to control it. The plan is to boot this Linux from an SD card with the PicoZed plugged into an FMC carrier board which does support SD cards. We will then copy the image we build in the next steps onto the QSPI FLASH and the eMMC chip using this build. We can then remove the module and change the boot switch settings and have a module which will boot from QSPI and eMMC.<\/p>\n<p>So copy the BOOT.BIN and image.ub files you build in the previous section to an SD card. Verify that this image boots in a FMC carrier. The critical component is that this image can read and write the QSPI\u00a0chip. To verify that log in to the console and type<\/p>\n<pre>root@linux:~# cat \/proc\/mtd\r\nev:    size   erasesize  name\r\nmtd0: 00500000 00010000 \"boot\"\r\nmtd1: 00020000 00010000 \"bootenv\"\r\nmtd2: 00a80000 00010000 \"kernel\"\r\nmtd3: 00060000 00010000 \"spare\"\r\n<\/pre>\n<p>You should see the four partitions on the QSPI FLASH\u00a0memory. You should also check that you can see the eMMC device file.<\/p>\n<pre>root@pz-7015-2016-2:~# ls \/dev\/mmcblk?\r\n\/dev\/mmcblk0       \/dev\/mmcblk1\r\n<\/pre>\n<p>We need to partition the eMMC memory and write a FAT 32 filesystem onto it. Run fdisk like this<\/p>\n<pre>root@pz-7015-2016-2:~# fdisk \/dev\/mmcblk1\r\nDevice contains neither a valid DOS partition table, nor Sun, SGI, OSF or GPT disklabel\r\nBuilding a new DOS disklabel. Changes will remain in memory only,\r\nuntil you decide to write them. After that the previous content\r\nwon't be recoverable.\r\n\r\n\r\nThe number of cylinders for this disk is set to 115456.\r\nThere is nothing wrong with that, but this is larger than 1024,\r\nand could in certain setups cause problems with:\r\n1) software that runs at boot time (e.g., old versions of LILO)\r\n2) booting and partitioning software from other OSs\r\n   (e.g., DOS FDISK, OS\/2 FDISK)\r\n\r\nCommand (m for help): \r\n<\/pre>\n<p>Type &#8220;p&#8221; to print the partition table.<\/p>\n<pre>Command (m for help): p\r\n\r\nDisk \/dev\/mmcblk1: 3783 MB, 3783262208 bytes\r\n4 heads, 16 sectors\/track, 115456 cylinders\r\nUnits = cylinders of 64 * 512 = 32768 bytes\r\n\r\n        Device Boot      Start         End      Blocks  Id System\r\n\r\nCommand (m for help): \r\n<\/pre>\n<p>If you do have partitions you should delete them by entering &#8220;d&#8221; unless you know they are the correct size.<\/p>\n<p>Next you should create a partition starting at 1 that is 128MB in size.<\/p>\n<pre>Command (m for help): p\r\n\r\nDisk \/dev\/mmcblk1: 3783 MB, 3783262208 bytes\r\n4 heads, 16 sectors\/track, 115456 cylinders\r\nUnits = cylinders of 64 * 512 = 32768 bytes\r\n\r\n        Device Boot      Start         End      Blocks  Id System\r\n\r\nCommand (m for help): n\r\nCommand action\r\n   e   extended\r\n   p   primary partition (1-4)\r\np\r\nPartition number (1-4): 1\r\nFirst cylinder (1-115456, default 1): 1\r\nLast cylinder or +size or +sizeM or +sizeK (1-115456, default 115456): +128M\r\n\r\nCommand (m for help): \r\n<\/pre>\n<p>If you now print the partition table you should see the following<\/p>\n<pre>Command (m for help): p\r\n\r\nDisk \/dev\/mmcblk1: 3783 MB, 3783262208 bytes\r\n4 heads, 16 sectors\/track, 115456 cylinders\r\nUnits = cylinders of 64 * 512 = 32768 bytes\r\n\r\n        Device Boot      Start         End      Blocks  Id System\r\n\/dev\/mmcblk1p1               1        3907      125016  83 Linux\r\n\r\nCommand (m for help): \r\n<\/pre>\n<p>Now write the partition table.<\/p>\n<pre>Command (m for help): w\r\nThe partition table has been altered.\r\nCalling ioctl() to re-read partition table\r\nroot@pz-7015-2016-2:~# \r\n<\/pre>\n<p>Next we need to put a FAT 32 filesystem onto the partition.<\/p>\n<pre>root@pz-7015-2016-2:~# mkdosfs -F 32 \/dev\/mmcblk1p1\r\n<\/pre>\n<p>Now we need to build our application FPGA and Linux build.<\/p>\n<h1>Application FPGA<\/h1>\n<p>Configure your FPGA such that the SD interface uses MIO pins 10 through 15. If you have two SD card interfaces then you will need to configure UBoot to use the correct interface. Since you don&#8217;t have an SD card you only need one SD interface to talk to the eMMC chip so I recommend only using the one. As before, make sure that you enable the chip detect (CD) pin and connect it to a logic 0.<\/p>\n<h1>Application Linux<\/h1>\n<p>Now you need to configure the\u00a0Linux build for your application. Create your project and run petalinux-config with the &#8211;get-hw-description option to read the FPGA settings. When the menuconfig screen comes up you need to set the boot image location to QSPI. Go to<\/p>\n<ul>\n<li>Subsystem AUTO Hardware Settings -&gt;<\/li>\n<li>Advanced bootable images storage Settings -&gt;<\/li>\n<li>boot image settings -&gt;<\/li>\n<li>image storage media -&gt;<\/li>\n<\/ul>\n<p>Change the device selection to <em>primary flash<\/em> and then exit to move up one level. Set the kernel image location to eMMC. Go to<\/p>\n<ul>\n<li>kernel image settings -&gt;<\/li>\n<\/ul>\n<p>and set the device selection to <em>primary sd<\/em>.\u00a0Then select exit twice to move up two levels. If you have two SD interfaces select<\/p>\n<ul>\n<li>SD\/SDIO Settings -&gt;<\/li>\n<\/ul>\n<p>and change the device selection to <em>ps7_sd_1<\/em>. Now exit out of the configuration and build and package your linux. If you only had one SD card interface then this will be your only option.<\/p>\n<h1>Copy the application Linux build<\/h1>\n<p>Now, back on the PicoZed carrier board which has booted the bootstrap Linux from the SD card, copy the application Linux build files BOOT.BIN and image.ub to the SD card using ssh. Don&#8217;t overwrite the files you booted from but put the files in a separate directory. Instead of using ssh, you could plug the SD card into your development machine and transferring the files that way.<\/p>\n<pre>root@pz-7015-2016-2:~# cd \/run\/media\/mmcblk0p1\/\r\nrroot@pz-7015-2016-2:\/run\/media\/mmcblk0p1# mkdir application\r\nroot@pz-7015-2016-2:\/run\/media\/mmcblk0p1# cd application\r\nroot@pz-7015-2016-2:\/run\/media\/mmcblk0p1\/application# scp user@build-server-ip:\/project-path\/images\/linux\/{BOOT.BIN,image.ub} .\r\n\r\nHost 'build-server-ip' is not in the trusted hosts file.\r\n(ecdsa-sha2-nistp256 fingerprint md5 ce:04:f3:db:96:67:d7:7a:6a:24:48:7e:a8:98:66:5f)\r\nDo you want to continue connecting? (y\/n) y\r\nuser@build-server-ip's password: \r\nBOOT.BIN                                                                                                                                 100% 3889KB   3.8MB\/s   00:00    \r\nuser@build-server-ip's password: \r\nimage.ub                                                                                                                                 100% 6185KB   6.0MB\/s   00:01    \r\nroot@pz-7015-2016-2:\/run\/media\/mmcblk0p1\/application# ls\r\nBOOT.BIN  image.ub\r\nroot@pz-7015-2016-2:\/run\/media\/mmcblk0p1\/application# \r\n<\/pre>\n<p>Verify that you can see the QSPI partitions.<\/p>\n<pre>root@pz-7015-2016-2:\/run\/media\/mmcblk0p1\/application# cat \/proc\/mtd\r\ndev:    size   erasesize  name\r\nmtd0: 00620000 00010000 \"boot\"\r\nmtd1: 00020000 00010000 \"bootenv\"\r\nmtd2: 00960000 00010000 \"kernel\"\r\nmtd3: 00060000 00010000 \"spare\"\r\n<\/pre>\n<p>Now copy the BOOT.BIN to the QSPI partition 0 using the flashcp command.<\/p>\n<pre>root@pz-7015-2016-2:\/run\/media\/mmcblk0p1\/application# flashcp BOOT.BIN \/dev\/mtd0\r\n<\/pre>\n<p>Next mount the eMMC partition and copy the linux filesystem to the eMMC.<\/p>\n<pre>root@pz-7015-2016-2:\/run\/media\/mmcblk0p1\/application# mount \/dev\/mmcblk1p1 \/mnt\r\nroot@pz-7015-2016-2:\/run\/media\/mmcblk0p1\/application# cp image.ub \/mnt\r\n<\/pre>\n<p>The system is now ready to boot from QSPI and eMMC. With the board oriented such that SW1 is at the bottom, set the switches such that the switch on the left is pushed towards the edge of the board and the one on the right is pushed towards the center. Now remove the SD card and reboot the board.<\/p>\n<h1>Conclusion<\/h1>\n<p>Your board should now boot without the SD card. If your board fails to boot, check the SW1 settings. If they are not correct, the boot loaded will fail to load and the FPGA will not be programmed. If you see the bootloader load and program the FPGA but fail to find a Linux image to boot then it is likely configured to look for the image on the SD card rather than the eMMC. Make sure you have configured the correct SD device for boot, or simple use only the eMMC SD interface on your FPGA.<\/p>\n\t\t<div class=\"social-sharing \">\r\n\t\t\t\t        <a onclick=\"return ss_plugin_loadpopup_js(this);\" rel=\"external nofollow\" class=\"button-facebook\" href=\"http:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwww.beyond-circuits.com%2Fwordpress%2Ftutorial%2Ftutorial27%2F\" target=\"_blank\" >Share on Facebook<\/a><a onclick=\"return ss_plugin_loadpopup_js(this);\" rel=\"external nofollow\" class=\"button-twitter\" href=\"http:\/\/twitter.com\/intent\/tweet\/?text=Tutorial+27+%3A+Booting+PicoZed+using+eMMC+FLASH&url=https%3A%2F%2Fwww.beyond-circuits.com%2Fwordpress%2Ftutorial%2Ftutorial27%2F&via=arjun077\" target=\"_blank\">Share on Twitter<\/a><a onclick=\"return ss_plugin_loadpopup_js(this);\" rel=\"external nofollow\" class=\"button-linkedin\" href=\"http:\/\/www.linkedin.com\/shareArticle?mini=true&url=https%3A%2F%2Fwww.beyond-circuits.com%2Fwordpress%2Ftutorial%2Ftutorial27%2F&title=Tutorial+27+%3A+Booting+PicoZed+using+eMMC+FLASH\" target=\"_blank\" >Share on Linkedin<\/a><a onclick=\"return ss_plugin_loadpopup_js(this);\" rel=\"external nofollow\" class=\"button-pinterest\" href=\"http:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.beyond-circuits.com%2Fwordpress%2Ftutorial%2Ftutorial27%2F&media=&description=Tutorial+27+%3A+Booting+PicoZed+using+eMMC+FLASH\" target=\"_blank\" >Share on Pinterest<\/a><a onclick=\"return ss_plugin_loadpopup_js(this);\" rel=\"external nofollow\" class=\"button-xing\" href=\"https:\/\/www.xing.com\/spi\/shares\/new?url=https%3A%2F%2Fwww.beyond-circuits.com%2Fwordpress%2Ftutorial%2Ftutorial27%2F\" target=\"_blank\" >Share on Xing<\/a>\t        \t    <\/div>\r\n\t    \n","protected":false},"excerpt":{"rendered":"<p>In my current project we are using a PicoZed module with a custom carrier board. But the carrier board does not have a SD card so we want to boot Linux from the eMMC module on the PicoZed board. There &hellip; <a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial27\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":226,"menu_order":27,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-1122","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/1122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1122"}],"version-history":[{"count":9,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/1122\/revisions"}],"predecessor-version":[{"id":1144,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/1122\/revisions\/1144"}],"up":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/226"}],"wp:attachment":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}