{"id":14213,"date":"2016-11-10T07:28:17","date_gmt":"2016-11-10T14:28:17","guid":{"rendered":"http:\/\/ainslies.net\/?p=14213"},"modified":"2016-11-10T07:28:17","modified_gmt":"2016-11-10T14:28:17","slug":"booting-the-i-mx7-sabre-board-from-the-mikrobus-spi-flash","status":"publish","type":"post","link":"https:\/\/ainslies.net\/?p=14213","title":{"rendered":"Booting the i.MX7 Sabre board from the mikroBUS SPI flash"},"content":{"rendered":"<p><a href=\"http:\/\/ainslies.net\/wp-content\/uploads\/2016\/11\/DSC_0199.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/ainslies.net\/wp-content\/uploads\/2016\/11\/DSC_0199-300x269.jpg\" alt=\"dsc_0199\" width=\"300\" height=\"269\" class=\"alignleft size-medium wp-image-14222\" srcset=\"https:\/\/ainslies.net\/wp-content\/uploads\/2016\/11\/DSC_0199-300x269.jpg 300w, https:\/\/ainslies.net\/wp-content\/uploads\/2016\/11\/DSC_0199-768x688.jpg 768w, https:\/\/ainslies.net\/wp-content\/uploads\/2016\/11\/DSC_0199-335x300.jpg 335w, https:\/\/ainslies.net\/wp-content\/uploads\/2016\/11\/DSC_0199.jpg 916w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nI&#8217;ve been working with the Freescale i.MX7 Sabre board and I wanted to free up the SD card so I could do some SDIO testing. I decided to boot the board from SPI flash ( I needed to test that out anyway ) and then load a kernel and rootfs across the network.<\/p>\n<p>On the i.MX7 board there is a <a href=\"http:\/\/www.mikroe.com\/mikrobus\/\">mikroBUS<\/a> connector which basically just breaks out SPI\/I2C\/serial and a couple of GPIOs. There is a 8Mb SPI flash that you can get for this bus called the <a href=\"http:\/\/www.mikroe.com\/click\/flash\/\">flash click<\/a>. Just what I needed so I ordered one.<\/p>\n<p>The documentation the board comes with claims the flash chip is a M25P80, no problem u-boot supports that. I added the config below into &#8220;include\/configs\/mx7dsabresd.h&#8221; to enable the u-boot SPI flash tools.<\/p>\n<pre>\r\n#define CONFIG_CMD_SF\r\n#define CONFIG_MXC_SPI\r\n<\/pre>\n<p>Also enable SPI flash in the defconfig &#8220;configs\/mx7dsabresd_secure_defconfig&#8221;<\/p>\n<pre>\r\nCONFIG_SPI_FLASH=y\r\n<\/pre>\n<p>You also need to add some code to your machine initialisation &#8220;board\/freescale\/mx7dsabresd\/mx7dsabresd.c&#8221; so that the pads get configured properly.<\/p>\n<pre>\r\ndefine SPI_PAD_CTRL \\\r\n  (PAD_CTL_HYS | PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_SRE_FAST)\r\n\r\nstatic iomux_v3_cfg_t const ecspi3_pads[] = {\r\n  MX7D_PAD_SAI2_RX_DATA__ECSPI3_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL),\r\n  MX7D_PAD_SAI2_TX_SYNC__ECSPI3_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL),\r\n  MX7D_PAD_SAI2_TX_BCLK__ECSPI3_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL),\r\n  MX7D_PAD_SAI2_TX_DATA__GPIO6_IO22 | MUX_PAD_CTRL(NO_PAD_CTRL),\r\n};\r\n\r\nint board_spi_cs_gpio(unsigned bus, unsigned cs)\r\n{\r\n       return (bus == 2 && cs == 0) ? (IMX_GPIO_NR(6, 22)) : -1;\r\n}\r\n\r\nstatic void setup_spi(void)\r\n{\r\n       imx_iomux_v3_setup_multiple_pads(ecspi3_pads, ARRAY_SIZE(ecspi3_pads));\r\n}\r\n<\/pre>\n<p>One more edit to &#8220;board\/freescale\/mx7dsabresd\/mx7dsabresd.c&#8221; to get the code above called. Into the function board_init add this<\/p>\n<pre>\r\n#ifdef CONFIG_MXC_SPI\r\n       setup_spi();\r\n#endif\r\n<\/pre>\n<p>So then I built myself a new u-boot <\/p>\n<pre>\r\nmake mx7dsabresd_secure_defconfig         \r\nCROSS_COMPILE=arm-linux-gnueabihf- make\r\n<\/pre>\n<p>Now take your newly minted u-boot, burn it to an SD card.<\/p>\n<pre>\r\nsudo dd if=u-boot.imx of=\/dev\/mmcblk0 seek=1 bs=1024\r\n<\/pre>\n<p>and it boots the board<\/p>\n<pre>\r\nU-Boot 2016.11-rc3-00044-g38cacda-dirty (Nov 09 2016 - 15:59:35 -0700)\r\n\r\nCPU:   Freescale i.MX7D rev1.1 996 MHz (running at 792 MHz)\r\nCPU:   Commercial temperature grade (0C to 95C) at 35C\r\nReset cause: POR\r\nBoard: i.MX7D SABRESD in secure mode\r\nI2C:   ready\r\nDRAM:  1 GiB\r\nPMIC: PFUZE3000 DEV_ID=0x30 REV_ID=0x11\r\nMMC:   FSL_SDHC: 0, FSL_SDHC: 1\r\nVideo: 480x272x24\r\nIn:    serial\r\nOut:   serial\r\nErr:   serial\r\nswitch to partitions #0, OK\r\nmmc0 is current device\r\nNet:   FEC0\r\nHit any key to stop autoboot:  0 \r\n=>\r\n<\/pre>\n<p>Excellent now I want to scan for the flash chip so that I can burn my new u-boot to it.<\/p>\n<pre>\r\n=> sf probe 2:0\r\nSF: Unsupported flash IDs: manuf 1c, jedec 3014, ext_jedec 1c30\r\nFailed to initialize SPI flash at 2:0\r\n<\/pre>\n<p>WTF that&#8217;s not the jedec id for a N25P80. So if you go back to the link near the top of the page the mikroBUS flash click actually uses the EN25Q80B which is not in mainline u-boot. Back to the code we go.<\/p>\n<p>Edit &#8220;drivers\/mtd\/spi\/sf_params.c&#8221; and right after &#8220;#ifdef CONFIG_SPI_FLASH_EON   \/* EON *\/&#8221; add the line below.<\/p>\n<pre>\r\n  {\"EN25Q80B\",        0x1c3014, 0x0, 64 * 1024,  16, 0},\r\n<\/pre>\n<p>You&#8217;ll also nee to edit your config again &#8220;include\/configs\/mx7dsabresd.h&#8221; and add EON SPI to the configuration.<\/p>\n<pre>\r\n#define CONFIG_SPI_FLASH_EON\r\n<\/pre>\n<p>Rebuild it and burn it back to the SD card and try the probe again.<\/p>\n<pre>\r\n=> sf probe 2:0\r\nSF: Detected EN25Q80B with page size 256 Bytes, erase size 64 KiB, total 1 MiB\r\n<\/pre>\n<p>So now u-boot can understand the flash, lets erase enough space for u-boot it and flash it.<\/p>\n<pre>\r\n=> sf erase 0 80000 \r\nSF: 524288 bytes @ 0x0 Erased: OK\r\n=> mmc read 0x80000000 2 400\r\n\r\nMMC read: dev # 0, block # 2, count 1024 ... 1024 blocks read: OK\r\n=> sf write 0x80000000 400 80000\r\ndevice 0 offset 0x400, size 0x80000\r\nSF: 524288 bytes @ 0x400 Written: OK\r\n<\/pre>\n<p>Now set the jumpers to boot from the SPI flash, remove the SD card and reset the board.<a href=\"http:\/\/ainslies.net\/wp-content\/uploads\/2016\/11\/DSC_0201.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/ainslies.net\/wp-content\/uploads\/2016\/11\/DSC_0201.png\" alt=\"dsc_0201\" width=\"253\" height=\"119\" class=\"alignleft size-full wp-image-14223\" \/><\/a><\/p>\n<p>Here&#8217;s the <a href=\"http:\/\/ainslies.net\/wp-content\/uploads\/2016\/11\/mikrobus_flash_click.patch_.gz\">mikroBUS flash click patch<\/a> that should apply to mainline u-boot.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working with the Freescale i.MX7 Sabre board and I wanted to free up the SD card so I could do some SDIO testing. I decided to boot the board from SPI flash ( I needed to test that &hellip; <a href=\"https:\/\/ainslies.net\/?p=14213\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-14213","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/ainslies.net\/index.php?rest_route=\/wp\/v2\/posts\/14213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ainslies.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ainslies.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ainslies.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ainslies.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14213"}],"version-history":[{"count":9,"href":"https:\/\/ainslies.net\/index.php?rest_route=\/wp\/v2\/posts\/14213\/revisions"}],"predecessor-version":[{"id":14229,"href":"https:\/\/ainslies.net\/index.php?rest_route=\/wp\/v2\/posts\/14213\/revisions\/14229"}],"wp:attachment":[{"href":"https:\/\/ainslies.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ainslies.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ainslies.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}