{"id":403,"date":"2010-03-16T14:18:13","date_gmt":"2010-03-16T19:18:13","guid":{"rendered":"http:\/\/www.multitech.net\/developer\/?page_id=403"},"modified":"2014-02-13T13:02:30","modified_gmt":"2014-02-13T19:02:30","slug":"nand-flash-programming","status":"publish","type":"page","link":"https:\/\/www.multitech.net\/developer\/software\/corecdp\/development\/nand-flash-programming\/","title":{"rendered":"NAND Flash Programming"},"content":{"rendered":"<h3>NAND Flash Layout<\/h3>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr>\n<th><strong>MTD<\/strong><\/th>\n<th><strong>Name<\/strong><\/th>\n<th><strong>Offset<\/strong><\/th>\n<th><strong>Size<\/strong><\/th>\n<th><strong>Usage<\/strong><\/th>\n<\/tr>\n<tr>\n<td>mtd0<\/td>\n<td>MTNCG-NANDFlash<\/td>\n<td>0x00000000<\/td>\n<td>0x10000000<\/td>\n<td>Whole NAND<\/td>\n<\/tr>\n<tr>\n<td>mtd1<\/td>\n<td>AT91Bootstrap<\/td>\n<td>0x00000000<\/td>\n<td>0x00020000<\/td>\n<td>Bootstrap [bootstrap.bin]<\/td>\n<\/tr>\n<tr>\n<td>mtd2<\/td>\n<td>UBoot<\/td>\n<td>0x00020000<\/td>\n<td>0x00040000<\/td>\n<td>U-Boot [u-boot.bin]<\/td>\n<\/tr>\n<tr>\n<td>mtd3<\/td>\n<td>UBoot Config<\/td>\n<td>0x00060000<\/td>\n<td>0x00020000<\/td>\n<td>U-Boot environment<\/td>\n<\/tr>\n<tr>\n<td>mtd4<\/td>\n<td>UBoot Redundant Config<\/td>\n<td>0x00080000<\/td>\n<td>0x00020000<\/td>\n<td>U-Boot redundant environment<\/td>\n<\/tr>\n<tr>\n<td>mtd5<\/td>\n<td>uImage<\/td>\n<td>0x000A0000<\/td>\n<td>0x00760000<\/td>\n<td>Linux Kernel [uImage.bin]<\/td>\n<\/tr>\n<tr>\n<td>mtd6<\/td>\n<td>Config<\/td>\n<td>0x00800000<\/td>\n<td>0x00800000<\/td>\n<td>Configuration [\/var\/config]<\/td>\n<\/tr>\n<tr>\n<td>mtd7<\/td>\n<td>Oem Config<\/td>\n<td>0x01000000<\/td>\n<td>0x00800000<\/td>\n<td>OEM Specific configuration [not used by default]<\/td>\n<\/tr>\n<tr>\n<td>mtd8<\/td>\n<td>Rootfs<\/td>\n<td>0x01800000<\/td>\n<td>0x0E800000<\/td>\n<td>root filesystem [rootfs.jffs]<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Total Size: 256 MB<br \/>\nBlock\/Sector Size: 128 KB<\/p>\n<h3>Flashing from U-Boot<\/h3>\n<p>U-Boot can be accessed at boot time from the DEBUG serial port.<\/p>\n<ul>\n<li>If you have an MTCDP and are using the <a href='https:\/\/www.multitech.net\/developer\/products\/multiconnect-ocg\/multiconnect-ocg-break-out-board\/' title='MultiConnect OCG Break-Out Board'>MultiConnect OCG Break-Out Board<\/a>, you may connect the Break-Out Board to the MTCDP using the 36-pin cable provided, and then connect a standard 9-pin serial cable to the DEBUG port on the Break-out Board.<\/li>\n<li>If you have an MTCDP without a <a href='https:\/\/www.multitech.net\/developer\/products\/multiconnect-ocg\/multiconnect-ocg-break-out-board\/' title='MultiConnect OCG Break-Out Board'>MultiConnect OCG Break-Out Board<\/a>, you will have to remove the case and plug in the provided DEBUG serial cable to the 3-pin connector located on the board.  See <a href='https:\/\/www.multitech.net\/developer\/products\/multiconnect-ocg\/hardware\/how-to-setup-serial-console-cable\/' title='How to Setup Serial Console Cable'>How to Setup Serial Console Cable<\/a>.<\/li>\n<li>If using the MT100EOCG embedded gateway, connect the serial cable to the 3-pin connector on the developer board.<\/li>\n<\/ul>\n<h4>Setting up the U-Boot Environment<\/h4>\n<p>Install and configure a TFTP server on your development workstation. For example using in.tftpd and xinetd the following configuration will listen on port 69 and set \/tftboot as the tftp root dir.<\/p>\n<p>\/etc\/xinetd.d\/tftp:<\/p>\n<pre class=\"brush:text\">service tftp\r\n{\r\nprotocol\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = udp\r\nport\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 69\r\nsocket_type\u00a0\u00a0\u00a0\u00a0 = dgram\r\nwait\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = yes\r\nuser\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = nobody\r\nserver\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \/usr\/sbin\/in.tftpd\r\nserver_args\u00a0\u00a0\u00a0\u00a0 = -s \/tftpboot\r\ndisable\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = no\r\n}<\/pre>\n<p>Run minicom and configure the serial port attached to the device to [115200 8N1] with hardware flow control OFF.<\/p>\n<p>Power on the device after connecting the debug cable.  You will need to press a key to interrupt U-Boot from booting the system &#8212; look for the <em>Hit any key to stop autoboot<\/em> message.<\/p>\n<pre class=\"brush:text\">\r\nU-Boot 1.3.4 (Mar 26 2010 - 10:35:18)\r\n\r\nDRAM:  64 MB\r\nNAND:  256 MiB\r\nIn:    serial\r\nOut:   serial\r\nErr:   serial\r\nNet:   macb0\r\nmacb0: link up, 100Mbps half-duplex (lpa: 0x40a1)\r\nHit any key to stop autoboot:  0 \r\nU-Boot> \r\n<\/pre>\n<p>Some units come already configured with a U-Boot environment that makes flashing the device simple.  To check the contents of the U-Boot environment, run <code>printenv<\/code> and check for variables named <code>tftp_kernel<\/code> and <code>tftp_rootfs<\/code>, etc.<\/p>\n<pre class=\"brush:text\">\r\nU-Boot> printenv\r\nbaudrate=115200\r\nethaddr=00:08:00:87:00:02\r\nbootargs=mem=64M console=ttyS0,115200 root=\/dev\/mtdblock8 ro rootfstype=jffs2\r\nbootcmd=nboot.jffs2 ${loadaddr} 0 ${kernel_addr}; bootm ${loadaddr}\r\nbootdelay=3\r\n...\r\ntftp_kernel=tftp ${loadaddr} ${kernel_file}; run erase_kernel; nand write.jffs2 ${fileaddr} ${kernel_addr} ${filesize}\r\ntftp_config=tftp ${loadaddr} ${config_file}; run erase_config; nand write.jffs2 ${fileaddr} ${config_addr} ${filesize}\r\ntftp_oem=tftp ${loadaddr} ${oem_file}; run erase_oem; nand write.jffs2 ${fileaddr} ${oem_addr} ${filesize}\r\ntftp_rootfs=tftp ${loadaddr} ${rootfs_file}; run erase_rootfs; nand write.jffs2 ${fileaddr} ${rootfs_addr} ${filesize}\r\nkrb=run tftp_kernel; run tftp_rootfs; boot\r\nrb=run tftp_rootfs; boot\r\nstdin=serial\r\nstdout=serial\r\nstderr=serial\r\n\r\nEnvironment size: 2445\/131067 bytes\r\nU-Boot>\r\n<\/pre>\n<p>If these variables do exist, then modify the <code>serverip<\/code>, <code>ipaddr<\/code>, and <code>netmask<\/code> variables to match your network and device and save the settings to make the changes permanent.  Then continue to the &#8220;Flash the Kernel from U-Boot&#8221; section below.<\/p>\n<pre class=\"brush:text\">\r\nU-Boot> set ipaddr 192.168.2.1\r\nU-Boot> set serverip 192.168.2.2\r\nU-Boot> set netmask 255.255.255.0\r\nU-Boot> save\r\nSaving Environment to NAND...\r\nErasing redundant Nand...\r\nErasing at 0x80000 -- 100% complete.\r\nWriting to redundant Nand... done\r\nU-Boot> save\r\nSaving Environment to NAND...\r\nErasing Nand...\r\nErasing at 0x60000 -- 100% complete.\r\nWriting to Nand... done\r\nU-Boot>\r\n<\/pre>\n<p>If the <code>tftp_kernel<\/code> and <code>tftp_rootfs<\/code> variables do not exist in the U-Boot environment, follow the instructions below to update the U-Boot environment for flashing.<\/p>\n<p>Copy the U-Boot environment setup script to a location with a shorter path. The full path needs to be short enough to fit in the Minicom run script menu.<\/p>\n<pre class=\"brush:text\">cp $OETREE\/multitech\/contrib\/uboot-setenv $HOME\/uboot-setenv<\/pre>\n<p>Edit ${HOME}\/uboot-setenv to match your network and device.<\/p>\n<pre class=\"brush:text\">\r\nsend setenv serverip              192.168.2.2\r\nsend setenv ipaddr                192.168.2.1\r\nsend setenv netmask               255.255.255.0\r\n<\/pre>\n<p>Run the U-Boot environment setup script. At minicom type CTRL-A G and enter ${HOME}\/uboot-setenv as the name of the script to run. When the script finishes it should save and print out the environment.  Make sure you expand ${HOME} to your actual home dir when entering the script name.<\/p>\n<div class=\"note\">Version 2.4 of Minicom (the version in Ubuntu 10.04) has a bug where scripts never ever exit.  In this case, the variables actually get set properly so after the script has run for a while, exit Minicom, restart it, and run &#8216;printenv&#8217; to see if the changes took effect.<\/div>\n<h4>Flash the Kernel from U-Boot<\/h4>\n<p>Make sure oe_uImage.bin is in your tftpboot dir then run the tftp kernel command.<br \/>\nIf you have TFTPBOOT_DIR set in your env-oe.sh script then this should happen automatically after building.<\/p>\n<pre class=\"brush:text\">U-Boot&gt; run tftp_kernel\r\nmacb0: link up, 100Mbps full-duplex (lpa: 0x45e1)\r\nUsing macb0 device\r\nTFTP from server 192.168.2.2; our IP address is 192.168.2.1\r\nFilename 'oe_uImage.bin'.\r\nLoad address: 0x21400000\r\nLoading: #################################################################\r\n#################################################################\r\n#################################################################\r\n#################################################################\r\n#################################################################\r\n########\r\ndone\r\nBytes transferred = 1703556 (19fe84 hex)\r\n\r\nNAND erase: device 0 offset 0xa0000, size 0x760000\r\nErasing at 0x7e0000 -- 100% complete.\r\nOK\r\n\r\nNAND write: device 0 offset 0xa0000, size 0x19fe84\r\n\r\nWriting data at 0x23f800 -- 100% complete.\r\n1703556 bytes written: OK\r\nU-Boot&gt;<\/pre>\n<h4>Flash the Rootfs from U-Boot<\/h4>\n<p>Make sure oe_rootfs.jffs2 is in your tftpboot dir then run the tftp rootfs command.<br \/>\nIf you have TFTPBOOT_DIR set in your env-oe.sh script then this should happen automatically after building.<\/p>\n<pre class=\"brush:text\">U-Boot&gt; run tftp_rootfs\r\nmacb0: link up, 100Mbps full-duplex (lpa: 0x45e1)\r\nUsing macb0 device\r\nTFTP from server 192.168.2.2; our IP address is 192.168.2.1\r\nFilename 'oe_rootfs.jffs2'.\r\nLoad address: 0x21400000\r\nLoading: #################################################################\r\n#################################################################\r\n#################################################################\r\n...\r\n#################################################################\r\n######\r\ndone\r\nBytes transferred = 11010048 (a80000 hex)\r\n\r\nNAND erase: device 0 offset 0x1800000, size 0xe800000\r\nErasing at 0xffe0000 -- 100% complete.\r\nOK\r\n\r\nNAND write: device 0 offset 0x1800000, size 0xa80000\r\n\r\nWriting data at 0x227f800 -- 100% complete.\r\n11010048 bytes written: OK\r\nU-Boot&gt;<\/pre>\n<p>U-Boot may not complete a response to a delayed ARP request. If your tftp transfers are timing out, you may need to add an entry to the ARP cache manually. You do not need to do anything unless you are having a problem.<\/p>\n<pre class=\"brush:text\">$ # Add an entry for the device 00:D0:A0:02:0D:E1 with IP address 192.168.2.1 reachable via interface eth2\r\n$ sudo arp -i eth2 -s 192.168.2.1 00:D0:A0:02:0D:E1\r\n$ # View the ARP cache entries on interface eth2\r\n$ arp -n -i eth2\r\nAddress                  HWtype  HWaddress           Flags Mask            Iface\r\n192.168.2.1              ether   00:D0:A0:02:0D:E1   CM                    eth2<\/pre>\n<h3>Flashing from Linux<\/h3>\n<p>The kernel and root filesystem can also be flashed from Linux as part of the reboot process.  The device will check for the existence of a file named <code>\/var\/volatile\/do_flash_upgrade<\/code> to indicate that it should attempt to flash itself on reboot.  If <code>\/var\/volatile\/do_flash_upgrade<\/code> exists, it will look for the upgrade files in two locations: <code>\/var\/volatile\/flash-upgrade<\/code> and <code>\/media\/card\/flash-upgrade<\/code> and flash itself.<\/p>\n<div class=\"note\">Prior to CoreCDP 2, creating \/var\/volatile\/do_flash_upgrade was not necessary.  The addition of this step makes the intention to upgrade more explicit and prevents unintended repeated flashing from the SD card.<\/div>\n<h4>Summary<\/h4>\n<p>Copy kernel and rootfs to:<br \/>\n<code>\/var\/volatile\/flash-upgrade\/uImage.bin<\/code><br \/>\n<code>\/var\/volatile\/flash-upgrade\/rootfs.jffs2<\/code><br \/>\nOR<br \/>\n<code>\/media\/card\/flash-upgrade\/uImage.bin<\/code><br \/>\n<code>\/media\/card\/flash-upgrade\/rootfs.jffs2<\/code><\/p>\n<p>Run <code>touch \/var\/volatile\/do_flash_upgrade<\/code><br \/>\nRun <code>reboot<\/code><\/p>\n<p>The file names must match above exactly and are case-sensitive.<\/p>\n<h4>Step-by-step<\/h4>\n<p>On the device, first create the destination directory:<\/p>\n<pre class=\"brush:shell\">\r\nmkdir \/var\/volatile\/flash-upgrade\r\n<\/pre>\n<p>On your development machine, use SCP to transfer the files to the device.  The following example shows flashing corecdp-base-image on an MTCDP device (MACHINE=&#8221;mtcdp&#8221;).<\/p>\n<pre class=\"brush:shell\">\r\ncd ${OETREE}\/build\/tmp\/deploy\/eglibc\/images\/mtcdp\r\nscp uImage-mtcdp.bin root@192.168.2.1:\/var\/volatile\/flash-upgrade\/uImage.bin\r\nscp corecdp-base-image-mtcdp.jffs2 root@192.168.2.1:\/var\/volatile\/flash-upgrade\/rootfs.jffs2\r\n<\/pre>\n<p>If you have <code>TFTPBOOT_DIR<\/code> set in your env-oe.sh script, you may also use the linked files in <code>\/tftpboot<\/code> instead.<\/p>\n<p>If you choose to copy uImage.bin and rootfs.jffs2 into the tmpfs mounted at \/var\/volatile, you will have to make sure there is enough space to fit the images in memory before hand.  If you need to flash a larger image and have an SD card inserted, you can copy the images into \/media\/card instead.<\/p>\n<p>After transferring the files to the proper location, create <code>\/var\/volatile\/do_flash_upgrade<\/code> and reboot to initiate the upgrade.<\/p>\n<pre class=\"brush:text\">\r\n# touch \/var\/volatile\/do_flash_upgrade\r\n# reboot\r\n\r\nBroadcast message from root (ttyS0) (Tue Nov 15 05:35:42 2011):\r\n\r\nThe system is going down for reboot NOW!\r\nINIT: Sending processes the TERM signal\r\nStopping Dropbear SSH server: stopped \/usr\/sbin\/dropbear (pid 303)\r\ndropbear.\r\nStopping Vixie-cron.\r\nDeconfiguring network interfaces... done.\r\nStopping Lighttpd Web Server: stopped \/usr\/sbin\/lighttpd (pid 342)\r\nlighttpd.\r\nStopping syslogd\/klogd: stopped syslogd (pid 309)\r\nstopped klogd (pid 311)\r\ndone\r\nSending all processes the TERM signal...\r\neth0: link down\r\nSending all processes the KILL signal...\r\nUnmounting remote filesystems...\r\n\/var\/volatile\/flash-upgrade not present, skipping\r\n\r\nStarting flash upgrade from \/media\/card\/flash-upgrade...\r\nFlashing \/dev\/mtd5 (uImage) with \/media\/card\/flash-upgrade\/uImage.bin...\r\nflash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it\r\nErasing 128 Kibyte @ 740000 -- 100 % complete \r\nWriting data to block 0 at offset 0x0\r\nWriting data to block 1 at offset 0x20000\r\nWriting data to block 2 at offset 0x40000\r\nWriting data to block 3 at offset 0x60000\r\nWriting data to block 4 at offset 0x80000\r\nWriting data to block 5 at offset 0xa0000\r\nWriting data to block 6 at offset 0xc0000\r\nWriting data to block 7 at offset 0xe0000\r\nWriting data to block 8 at offset 0x100000\r\nWriting data to block 9 at offset 0x120000\r\nWriting data to block 10 at offset 0x140000\r\nWriting data to block 11 at offset 0x160000\r\nWriting data to block 12 at offset 0x180000\r\nWriting data to block 13 at offset 0x1a0000\r\nWriting data to block 14 at offset 0x1c0000\r\nFlashing \/dev\/mtd8 (rootfs) with \/media\/card\/flash-upgrade\/rootfs.jffs2...\r\nDeactivating swap...\r\nUnmounting local filesystems...\r\numount2: Device or resource busy\r\numount: none busy - remounted read-only\r\numount2: Device or resource busy\r\numount: devtmpfs busy - remounted read-only\r\nflash_eraseall has been replaced by `flash_erase <mtddev> 0 0`; please use it\r\nErasing 128 Kibyte @ 0 --  0 % complete flash_erase:  Cleanmarker written at 0\r\nErasing 128 Kibyte @ 20000 --  0 % complete flash_erase:  Cleanmarker written at 20000\r\n...\r\nWriting data to block 593 at offset 0x4a20000\r\nWriting data to block 594 at offset 0x4a40000\r\nWriting data to block 595 at offset 0x4a60000\r\nRebooting...\r\nRestarting system.\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>NAND Flash Layout MTD Name Offset Size Usage mtd0 MTNCG-NANDFlash 0x00000000 0x10000000 Whole NAND mtd1 AT91Bootstrap 0x00000000 0x00020000 Bootstrap [bootstrap.bin] mtd2 UBoot 0x00020000 0x00040000 U-Boot [u-boot.bin] mtd3 UBoot Config 0x00060000 0x00020000 U-Boot environment mtd4 UBoot Redundant Config 0x00080000 0x00020000 U-Boot redundant environment mtd5 uImage 0x000A0000 0x00760000 Linux Kernel [uImage.bin] mtd6 Config 0x00800000 0x00800000 Configuration [\/var\/config] [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":314,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"class_list":["post-403","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/comments?post=403"}],"version-history":[{"count":73,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/403\/revisions"}],"predecessor-version":[{"id":8306,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/403\/revisions\/8306"}],"up":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/314"}],"wp:attachment":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/media?parent=403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}