{"id":154,"date":"2010-08-26T22:42:55","date_gmt":"2010-08-27T02:42:55","guid":{"rendered":"http:\/\/hackspot.net\/iSpotBlog\/?p=154"},"modified":"2010-08-26T22:42:55","modified_gmt":"2010-08-27T02:42:55","slug":"a-closer-look-at-flash-memory-partitions-with-some-insight-on-the-firmware-update-process","status":"publish","type":"post","link":"http:\/\/hackspot.net\/iSpotBlog\/?p=154","title":{"rendered":"A closer look at flash memory partitions (with some insight on the firmware update process)"},"content":{"rendered":"<p>As I pointed out in my earlier article &#8220;<a href=\"http:\/\/hackspot.net\/iSpotBlog\/?p=115\">Backing up the flash memory on your iSpot to your PC<\/a>&#8220;, there are 10 &#8216;partitions&#8217; on the flash memory chip in the iSpot (at least on my device). You can get a list of the partitions by dumping the contents of the file &#8220;\/proc\/mtd&#8221;:<\/p>\n<pre># cat \/proc\/mtd\r\ndev:    size   erasesize  name\r\nmtd0: 00040000 00020000 \"RedBoot\"\r\nmtd1: 00020000 00020000 \"param\"\r\nmtd2: 00120000 00020000 \"linux\"\r\nmtd3: 00600000 00020000 \"rootfs\"\r\nmtd4: 00100000 00020000 \"system\"\r\nmtd5: 00120000 00020000 \"linux_2\"\r\nmtd6: 00600000 00020000 \"rootfs_2\"\r\nmtd7: 00020000 00020000 \"ver_1\"\r\nmtd8: 00020000 00020000 \"ver_2\"\r\nmtd9: 0001f000 00020000 \"FIS directory\"\r\nmtd10: 00001000 00020000 \"RedBoot config\"<\/pre>\n<p>\u00a0Here is a brief description of the partitions:<\/p>\n<ul>\n<li><strong>RedBoot<\/strong> : The RedBoot &#8216;boot loader&#8217;.\u00a0 This contains the code that runs when you first power-ON your device.\u00a0 It loads the Linux kernel and starts it (which in turn starts the main code for the iSpot)<\/li>\n<li><strong>param<\/strong> : Persistent parameters loaded into the iSpot at manufacturing time.\u00a0 Information such as the WiMax MAC address, as well as radio &#8216;calibration&#8217; data is stored here.\u00a0 This information is very important!<\/li>\n<li><strong>linux<\/strong> : The Linux kernel portion of <em>Firmware Image 1<\/em> (see <em><span style=\"color: #000080;\">Dual Firmware Images<\/span><\/em>, below)<\/li>\n<li><strong>rootfs<\/strong> : The JFFS2 root filesystem portion of <em>Firmware Image 1<\/em> (see <em><span style=\"color: #000080;\">Dual Firmware Images<\/span><\/em>, below)<\/li>\n<li><strong>system<\/strong> : Persistent storage for &#8216;settings&#8217; and other info that will remain even after a firmware upgrade<\/li>\n<li><strong>linux_2<\/strong> : The Linux kernel portion of <em>Firmware Image 2<\/em>\u00a0(see <em><span style=\"color: #000080;\">Dual Firmware Images<\/span><\/em>, below)<\/li>\n<li><strong>rootfs_2<\/strong> : The JFFS2 root filesystem portion of <em>Firmware Image 2<\/em>\u00a0(see <em><span style=\"color: #000080;\">Dual Firmware Images<\/span><\/em>, below)<\/li>\n<li><strong>ver_1<\/strong> : The &#8216;version counter&#8217; for <em>Firmware Image 1\u00a0(see <em><span style=\"color: #000080;\">Dual Firmware Images<\/span><\/em>, below)<\/em><\/li>\n<li><strong>ver_2<\/strong> : The &#8216;version counter&#8217;\u00a0for <em>Firmware Image 2\u00a0(see <em><span style=\"color: #000080;\">Dual Firmware Images<\/span><\/em>, below)<\/em><\/li>\n<li><strong>FIS directory<\/strong> : RedBoot&#8217;s table of flash memory partitions (corresponds to \/proc\/mtd in Linux)<\/li>\n<li><strong>RedBoot config<\/strong> : Configuration for RedBoot (includes the &#8216;boot script&#8217; that gets executed at startup)<\/li>\n<\/ul>\n<h2>Dual Firmware Images<\/h2>\n<p>The iSpot maintains two separate copies of Linux firmware in flash memory.\u00a0 A single\u00a0<em>Firmware Image<\/em> consists of two flash partitions :\u00a0a Linux kernel, plus a JFFS2 root filesystem.<\/p>\n<p>Only one copy of firmware is running at a time.\u00a0 This is known as the &#8216;active&#8217; Firmware Image (and the two flash partitions associated with it are the &#8216;active&#8217; firmware partitions).<\/p>\n<p>The <em>other<\/em> copy of the firmware is known as the &#8216;idle&#8217; Firmware Image.<\/p>\n<p>The iSpot uses the &#8220;ver_1&#8221; and &#8220;ver_2&#8221; partitions to decide which Firmware Image is &#8216;active&#8217;, and which is &#8216;idle&#8217;.\u00a0 These partitions each hold a &#8216;counter&#8217; value.\u00a0 Whichever partition&#8217;s counter is higher is the one that is &#8216;active&#8217; (and the lower counter value is &#8216;idle&#8217;).<\/p>\n<p>For example, if the &#8220;ver_1&#8221; partition contains the value &#8220;26&#8221;, and the &#8220;ver_2&#8221; partition contains the value &#8220;27&#8221;, then the system knows that Firmware Image 2 is the &#8216;active&#8217; one.\u00a0 So, it chooses the &#8220;linux_2&#8221; partition to load the kernel, and &#8220;rootfs_2&#8221; for the JFFS2 root filesystem.\u00a0 Firmware Image 1 (and its associated &#8220;linux&#8221; and &#8220;rootfs&#8221; partitions) are &#8216;idle&#8217;.<\/p>\n<p>\u00a0Whenever a &#8220;firmware update&#8221; process takes place, the &#8220;\/bin\/flash_program&#8221; application find the &#8216;idle&#8217; pair of partitions, and writes the new firmware there.\u00a0 This avoids any possible problems with writing to the &#8216;active&#8217; partition (for example, trying to modifiy files that are &#8216;in use&#8217;, or a power loss).\u00a0 <em>After<\/em> the new firmware partitions are completely written\/verified, the new firmware partitions are marked as &#8216;active&#8217; (and the current one becomes &#8216;idle&#8217;).\u00a0 This is done by taking the current &#8216;active&#8217; partition&#8217;s &#8216;counter&#8217; value (from the &#8216;active&#8217; Firmware&#8217;s\u00a0&#8220;ver&#8221; partition), adding one to it, then writing that to the &#8216;idle&#8217; Firmware&#8217;s &#8220;ver&#8221; partition.<\/p>\n<p>Going back to the above example, if &#8220;ver_1&#8221; contained &#8220;26&#8221; and &#8220;ver_2&#8221; contained &#8220;27&#8221; before the &#8220;firmware update&#8221; process (<em>Firmware Image 2<\/em> is &#8216;active&#8217;), the new firmware would be written to the <em>Firmware Image 1<\/em> partitions (&#8220;linux&#8221; and &#8220;rootfs&#8221;), as they are the &#8216;idle&#8217; partitions.\u00a0 When finished, &#8220;ver_1&#8221; would be updated with the value &#8220;28&#8221; (one higher than the &#8216;active&#8217; partition&#8217;s &#8220;27&#8221;).<\/p>\n<p>After the &#8216;active\/idle&#8217; switch, the iSpot reboots.\u00a0 RedBoot will see that &#8220;ver_1&#8221; has the higher value (&#8220;28&#8221;), so will choose <em>Firmware Image 1<\/em> as the &#8216;active&#8217; firmware, and will boot with &#8220;linux&#8221; and &#8220;rootfs&#8221; (instead of &#8220;linux_2&#8221; and &#8220;rootfs_2&#8221;).<\/p>\n<p><em>\u00a0<\/em><\/p>\n<p><em>Disclaimer: information on this site is for educational purposes only, and intended to help iSpot owners experiment with their own devices. I do not condone any hacking for illegal purposes, such as stealing service, etc.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I pointed out in my earlier article &#8220;Backing up the flash memory on your iSpot to your PC&#8220;, there are 10 &#8216;partitions&#8217; on the flash memory chip in the iSpot (at least on my device). You can get a &hellip; <a href=\"http:\/\/hackspot.net\/iSpotBlog\/?p=154\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/hackspot.net\/iSpotBlog\/index.php?rest_route=\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hackspot.net\/iSpotBlog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hackspot.net\/iSpotBlog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hackspot.net\/iSpotBlog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/hackspot.net\/iSpotBlog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=154"}],"version-history":[{"count":13,"href":"http:\/\/hackspot.net\/iSpotBlog\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":168,"href":"http:\/\/hackspot.net\/iSpotBlog\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions\/168"}],"wp:attachment":[{"href":"http:\/\/hackspot.net\/iSpotBlog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hackspot.net\/iSpotBlog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hackspot.net\/iSpotBlog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}