Changes between Version 2 and Version 3 of gsc/alternate_boot_device


Ignore:
Timestamp:
07/29/2020 04:52:55 PM (4 years ago)
Author:
Tim Harvey
Comment:

convert from html to wiki markup

Legend:

Unmodified
Added
Removed
Modified
  • gsc/alternate_boot_device

    v2 v3  
    1 {{{#!html
    2           <div id="wikipage" class="trac-content"><p>
    3 </p><div class="wiki-toc">
    4 <ol>
    5   <li>
    6     <a href="#AlternateBootDevice">Alternate Boot Device</a>
    7     <ol>
    8       <li>
    9         <ol>
    10           <li>
    11             <a href="#FlashMapping">Flash Mapping</a>
    12           </li>
    13         </ol>
    14       </li>
    15       <li>
    16         <a href="#AutoSwitchBootDevice">Auto Switch Boot Device</a>
    17         <ol>
    18           <li>
    19             <a href="#FromLinux">From Linux</a>
    20           </li>
    21           <li>
    22             <a href="#Fromu-boot">From u-boot</a>
    23           </li>
    24         </ol>
    25       </li>
    26       <li>
    27         <a href="#AlternateBootFlashfirmwareimages">Alternate Boot Flash firmware images</a>
    28         <ol>
    29           <li>
    30             <a href="#Step1.Bootloader">Step 1. Bootloader</a>
    31           </li>
    32           <li>
    33             <a href="#Step2.KernelRootFilesystem">Step 2. Kernel / Root Filesystem</a>
    34           </li>
    35           <li>
    36             <a href="#Usingu-boot-2014.10-cns3xxxbootloader">Using u-boot-2014.10-cns3xxx bootloader</a>
    37           </li>
    38         </ol>
    39       </li>
    40     </ol>
    41   </li>
    42 </ol>
    43 </div><p>
    44 </p>
    45 <h1 id="AlternateBootDevice">Alternate Boot Device</h1>
    46 <p>
     1[[PageOutline]]
     2
     3= Alternate Boot Device
    474Some Gateworks Laguna family products have an 'Alternate boot device' that can be used for alternate firmware images, such as a flash recovery image.
    48 </p>
    49 <p>
    50 Please note that if you have a board with a 4MB SPI flash device, such as the GW2388-4 you will need to use <a class="ext-link" href="https://github.com/Gateworks/u-boot-cns3xxx"><span class="icon">​</span>u-boot-2014.10 cns3xxx</a> bootloader.
    51 </p>
    52 <p>
    53 There are 2 ways that you can instruct the '<a class="wiki" href="/wiki/gsc">Gateworks System Controller</a>' to boot to the <strong>alternate boot device (an SPI FLASH device) vs the primary boot device (a NOR FLASH device)</strong>:
    54 </p>
    55 <ol><li>set GSC R0.3 and press the user pushbutton 5x times to perform a 1-time hard reboot to the alternate boot device
    56 <pre class="wiki">i2cset -f -y 0 0x20 0 0x08
    57 </pre></li><li>set GSC R1.6 (SWITCH_BOOT_ENABLE) to enable 'switch boot check'. If this is set when the board powers on, it will 'toggle' boot device selection and reboot after 30 seconds unless GSC R1.7 (SWITCH_BOOT_CLEAR) has been set before that time. Note that the countdown timer is only activated when the board powers on from a GSC sleep or unpowered state
    58 </li></ol><h3 id="FlashMapping">Flash Mapping</h3>
    59 <p>
     5
     6Please note that if you have a board with a 4MB SPI flash device, such as the GW2388-4 you will need to use ​[https://github.com/Gateworks/u-boot-cns3xxx u-boot-2014.10 cns3xxx] bootloader.
     7
     8There are 2 ways that you can instruct the [wiki:gsc Gateworks System Controller] to boot to the **alternate boot device (an SPI FLASH device) vs the primary boot device (a NOR FLASH device)**:
     91. set GSC R0.3 and press the user pushbutton 5x times to perform a 1-time hard reboot to the alternate boot device
     10{{{#!bash
     11i2cset -f -y 0 0x20 0 0x08
     12}}}
     132. set GSC R1.6 (SWITCH_BOOT_ENABLE) to enable 'switch boot check'. If this is set when the board powers on, it will 'toggle' boot device selection and reboot after 30 seconds unless GSC R1.7 (SWITCH_BOOT_CLEAR) has been set before that time. Note that the countdown timer is only activated when the board powers on from a GSC sleep or unpowered state
     14
     15== Flash Mapping
    6016This is an example from a Laguna 2388 with 16MB NOR and 4MB SPI. The mapping is set by us but can be changed.
    61 </p>
    62 <pre class="wiki">root@(none):/# cat /proc/mtd
     17
     18{{{#!bash
     19root@(none):/# cat /proc/mtd
    6320dev:    size   erasesize  name
    6421mtd0: 00040000 00020000 "uboot"
     
    7128mtd7: 00180000 00010000 "kernel"
    7229mtd8: 00200000 00010000 "rootfs"
     30}}}
    7331
    74 </pre><h2 id="AutoSwitchBootDevice">Auto Switch Boot Device</h2>
    75 <p>
    76 The <a class="wiki" href="/wiki/gsc">Gateworks System Controller</a> implements an 'Auto Switch Boot Device' feature that can be useful as a firmware recovery mechanism. GSC register R1.6 (SWITCH_BOOT_ENABLE) enables this mode. When this is set and the board powers on it will initiate a countdown timer that expires in 30 seconds. Writing a 1 to GSC R1.7 (SWITCH_BOOT_CLEAR) will cancel this timer. If the timer expires the boot device will be 'toggled' and the board will be hard reset.
    77 </p>
    78 <p>
     32== Auto Switch Boot Device
     33The [wiki:gsc Gateworks System Controller] implements an 'Auto Switch Boot Device' feature that can be useful as a firmware recovery mechanism. GSC register R1.6 (SWITCH_BOOT_ENABLE) enables this mode. When this is set and the board powers on it will initiate a countdown timer that expires in 30 seconds. Writing a 1 to GSC R1.7 (SWITCH_BOOT_CLEAR) will cancel this timer. If the timer expires the boot device will be 'toggled' and the board will be hard reset.
     34
    7935If you need to progamattically hard power cycle the board you can put it to sleep for a few seconds.
    80 </p>
    81 <h3 id="FromLinux">From Linux</h3>
    82 <p>
     36
     37=== From Linux
    8338Within the linux command-line shell, you can use i2cset from the i2c-tools package.
    84 </p>
    85 <p>
     39
    8640To enable 'switch boot check':
    87 </p>
    88 <pre class="wiki">i2cset -f -y 0 0x20 1 0x40      ;# enable R1.6 (SWITCH_BOOT_ENABLE)
    89 </pre><p>
     41{{{#!bash
     42i2cset -f -y 0 0x20 1 0x40      ;# enable R1.6 (SWITCH_BOOT_ENABLE)
     43}}}
     44
    9045To assert 'SWITCH_BOOT_CLEAR' and cancel the countdown timer (within 30 seconds of power up):
    91 </p>
    92 <pre class="wiki">i2cset -f -y 0 0x20 1 0xC0      ;# cancel countdown by asserting R1.7 (SWITCH_BOOT_CLEAR) but keep enabled R1.6 (SWITCH_BOOT_ENABLE)
     46{{{#!bash
     47i2cset -f -y 0 0x20 1 0xC0      ;# cancel countdown by asserting R1.7 (SWITCH_BOOT_CLEAR) but keep enabled R1.6 (SWITCH_BOOT_ENABLE)
    9348# or
    9449i2cset -f -y 0 0x20 1 0x80      ;# cancel countdown by asserting R1.7 (SWITCH_BOOT_CLEAR) and disable R1.6 (SWITCH_BOOT_ENABLE)
    95 </pre><p>
     50}}}
     51
    9652To programatically hard power-cycle the board by putting it to sleep for a few seconds while also enabling 'switch boot':
    97 </p>
    98 <pre class="wiki"># power cycle board: must be a hard power cycle, not a soft reboot (which can be done manually or via sleep/wake timer control)
     53{{{#!bash
     54# power cycle board: must be a hard power cycle, not a soft reboot (which can be done manually or via sleep/wake timer control)
    9955i2cset -f -y 0 0x20 6 5         ;# write add timer to 5sec
    10056i2cset -f -y 0 0x20 7 0
     
    10561# wait for board to reboot into linux and within 30 seconds of powerup cancel the boot timer
    10662i2cset -f -y 0 0x20 1 0xC0      ;# set R1.7 (SWITCH_BOOT_CLEAR) to cancel timer but leave R1.6 (SWITCH_BOOT_ENABLE) enabled
    107 </pre><h3 id="Fromu-boot">From u-boot</h3>
    108 <p>
     63}}}
     64
     65=== From u-boot
    10966Within the u-boot environment you can use the imw command to set i2c registers.
    110 </p>
    111 <p>
     67
    11268To enable 'switch boot check':
    113 </p>
    114 <pre class="wiki">Laguna &gt; imw 0x20 1 0x40 1     ;# enable R1.6 (SWITCH_BOOT_ENABLE)
    115 </pre><p>
     69{{{#!bash
     70Laguna > imw 0x20 1 0x40 1     ;# enable R1.6 (SWITCH_BOOT_ENABLE)
     71}}}
     72
    11673To assert R1.7 (SWITCH_BOOT_CLEAR) and cancel the countdown timer (within 30 seconds of power up):
    117 </p>
    118 <pre class="wiki">Laguna &gt; imw 0x20 1 0xc0 1  # set SWITCH_BOOT_CLEAR (R1.7)
    119 </pre><p>
     74{{{#!bash
     75Laguna > imw 0x20 1 0xc0 1  # set SWITCH_BOOT_CLEAR (R1.7)
     76}}}
     77
    12078To programatically hard power-cycle the board by putting it to sleep for a few seconds while also enabling 'switch boot':
    121 </p>
    122 <pre class="wiki">Laguna &gt; imw 0x20 6 0x05 1  # LSB (5 secs)
    123 Laguna &gt; imw 0x20 7 0x00 1
    124 Laguna &gt; imw 0x20 8 0x00 1
    125 Laguna &gt; imw 0x20 9 0x00 1  # MSB
    126 Laguna &gt; imw 0x20 1 0x04 1  # latch R6-R9 and add to RTC
    127 Laguna &gt; imw 0x20 1 0x43 1  # set SWITCH_BOOT_ENABLE (R1.6), sleep operation (R1.0) and activate sleep (R1.1)
    128 </pre><h2 id="AlternateBootFlashfirmwareimages">Alternate Boot Flash firmware images</h2>
    129 <h3 id="Step1.Bootloader">Step 1. Bootloader</h3>
    130 <p>
    131 The alternate boot device and the primary boot device require different bootloaders <strong>(SPI vs NOR FLASH)</strong>. Only the primary boot device is programmed with a bootable image by Gateworks. In order to program the alternate boot device you will need to do so from Linux (as u-boot-nor.bin on the primary boot device without modification can only access NOR flash).
    132 </p>
    133 <p>
    134 <strong>REQUIRED: You will also need to modify your Linux kernel to allow writing to the u-boot partition of SPI flash by commenting out the '.mask_flags = MTD_WRITEABLE' in the laguna_spi_partitions structure in:</strong>
    135 </p>
    136 <blockquote>
    137 <p>
     79{{{#!bash
     80Laguna > imw 0x20 6 0x05 1  # LSB (5 secs)
     81Laguna > imw 0x20 7 0x00 1
     82Laguna > imw 0x20 8 0x00 1
     83Laguna > imw 0x20 9 0x00 1  # MSB
     84Laguna > imw 0x20 1 0x04 1  # latch R6-R9 and add to RTC
     85Laguna > imw 0x20 1 0x43 1  # set SWITCH_BOOT_ENABLE (R1.6), sleep operation (R1.0) and activate sleep (R1.1)
     86}}}
     87
     88
     89== Alternate Boot Flash firmware images
     90
     91=== Step 1. Bootloader
     92The alternate boot device and the primary boot device require different bootloaders **(SPI vs NOR FLASH)**. Only the primary boot device is programmed with a bootable image by Gateworks. In order to program the alternate boot device you will need to do so from Linux (as u-boot-nor.bin on the primary boot device without modification can only access NOR flash).
     93
     94**REQUIRED: You will also need to modify your Linux kernel to allow writing to the u-boot partition of SPI flash by commenting out the '.mask_flags = MTD_WRITEABLE' in the laguna_spi_partitions structure in:**
     95{{{
    13896/gateworks-openwrt/trunk$ vi build_dir/target-arm_v6k_uClibc-0.9.33.2_eabi/linux-cns3xxx/linux-3.8.6/arch/arm/mach-cns3xxx/laguna.c
    139 </p>
    140 </blockquote>
    141 <p>
     97}}}
     98
    14299Once modified, recompile the BSP. Then flash this to the NOR flash on your board.
    143 </p>
    144 <p>
     100
    145101Once booted to NOR flash with this modified kernel you can write the laguna u-boot-spi.bin to /dev/mtd5 via mtd:
    146 </p>
    147 <pre class="wiki">root@OpenWrt:/# mtd write u-boot_spi.bin /dev/mtd5
     102{{{#!bash
     103root@OpenWrt:/# mtd write u-boot_spi.bin /dev/mtd5
    148104Unlocking /dev/mtd5 ...
    149105
    150106Writing from u-boot_spi.bin to /dev/mtd5 ...     
    151 root@OpenWrt:/#
    152 </pre><p>
    153 Now you can follow the instructions above to boot off the <strong>Alternate Boot Device</strong> (SPI Flash) and setup your kernel/rootfs using the instructions for an SPI FLASH device such as the GW2380 found here <a class="wiki" href="/wiki/laguna/openwrt">here</a>
    154 </p>
    155 <h3 id="Step2.KernelRootFilesystem">Step 2. Kernel / Root Filesystem</h3>
    156 <p>
    157 Depending on the size of the SPI FLASH you will likely <strong>need to prune features from your kernel/filesystem</strong>. A good starting point may be the Laguna <a class="ext-link" href="https://github.com/Gateworks/openwrt/blob/16.02/gateworks/configs/cns3xxx/.config_test"><span class="icon">​</span>test_config</a> file which uses a ramdisk and a minimal set of utilities used by Gateworks to test boards. As this <a class="wiki" href="/wiki/OpenWrt">OpenWrt</a> config file specifies an INTRAMFS ramdisk, you only need to flash the kernel which includes the root filesystem.
    158 </p>
    159 <ol><li>Use the instructions above to boot from the <strong>Alternate Boot Device</strong> (SPI FLASH) and break out into the bootloader. You can determine that you are booted to the <strong>Alternate Boot Device</strong> by seeing a smaller FLASH size in the boot header or by looking at the output of 'printenv bootcmd' and seeing that it boots a kernel from 0x60080000 (SPI FLASH) instead of 0x10080000 (NOR FLASH)
    160 <pre class="wiki">...
     107root@OpenWrt:/#
     108}}}
     109 
     110Now you can follow the instructions above to boot off the **Alternate Boot Device** (SPI Flash) and setup your kernel/rootfs using the instructions for an SPI FLASH device such as the GW2380 found here here
     111
     112=== Step 2. Kernel / Root Filesystem
     113Depending on the size of the SPI FLASH you will likely **need to prune features from your kernel/filesystem**. A good starting point may be the Laguna ​test_config file which uses a ramdisk and a minimal set of utilities used by Gateworks to test boards. As this OpenWrt config file specifies an INTRAMFS ramdisk, you only need to flash the kernel which includes the root filesystem.
     114
     1151. Use the instructions above to boot from the **Alternate Boot Device** (SPI FLASH) and break out into the bootloader. You can determine that you are booted to the **Alternate Boot Device** by seeing a smaller FLASH size in the boot header or by looking at the output of 'printenv bootcmd' and seeing that it boots a kernel from 0x60080000 (SPI FLASH) instead of 0x10080000 (NOR FLASH)
     116{{{#!bash
     117...
    161118Hit any key to stop autoboot:  0
    162 Laguna&gt; printenv bootcmd
     119Laguna> printenv bootcmd
    163120bootcmd=bootm 0x60080000
    164 </pre></li></ol><ol start="2"><li>set R1.7 (SWITCH_BOOT_CLEAR) so that you have plenty of time to write the kernel to the SPI Flash:
    165 <pre class="wiki">Laguna &gt; imw 0x20 1 0xc0 1  # set SWITCH_BOOT_CLEAR (R1.7)
    166 </pre></li></ol><ol start="3"><li>set ipaddr/serverip according to your network. For example if your server is at 192.168.1.14 and your target is to be 192.168.1.211:
    167 <pre class="wiki">Laguna&gt; sete ipaddr 192.168.1.211
    168 Laguna&gt; sete serverip 192.168.1.14
    169 </pre></li></ol><ol start="4"><li>Erase what is currently in the SPI FLASH: (This is a range, start and end for a specific flash size. Example 16MB SPI below)
    170 <pre class="wiki">Laguna&gt; erase 0x60080000 0x60ffffff
    171 </pre></li></ol><ol start="5"><li>Copy Kernel+Root-filesystem to the Board
    172 <pre class="wiki">Laguna&gt; tftpboot 0x00800000 laguna/openwrt-cns3xxx-uImage_ramdisk
    173 Laguna&gt; cp.b 0x00800000 0x60080000 $(filesize)
    174 </pre></li></ol><ol start="6"><li>Set kernel commandline for booting a ramdisk:
    175 <pre class="wiki">setenv bootargs 'console=ttyS0,115200 root=/dev/ram0 rootfstype=ramfs'
     121}}}
     1221. set R1.7 (SWITCH_BOOT_CLEAR) so that you have plenty of time to write the kernel to the SPI Flash:
     123{{{#!bash
     124Laguna > imw 0x20 1 0xc0 1  # set SWITCH_BOOT_CLEAR (R1.7)
     125}}}
     1261. set ipaddr/serverip according to your network. For example if your server is at 192.168.1.14 and your target is to be 192.168.1.211:
     127{{{#!bash
     128Laguna> sete ipaddr 192.168.1.211
     129Laguna> sete serverip 192.168.1.14
     130}}}
     1311. Erase what is currently in the SPI FLASH: (This is a range, start and end for a specific flash size. Example 16MB SPI below)
     132{{{#!bash
     133Laguna> erase 0x60080000 0x60ffffff
     134}}}
     1351. Copy Kernel+Root-filesystem to the Board
     136{{{#!bash
     137Laguna> tftpboot 0x00800000 laguna/openwrt-cns3xxx-uImage_ramdisk
     138Laguna> cp.b 0x00800000 0x60080000 $(filesize)
     139}}}
     1401. Set kernel commandline for booting a ramdisk:
     141{{{#!bash
     142setenv bootargs 'console=ttyS0,115200 root=/dev/ram0 rootfstype=ramfs'
    176143saveenv
    177 </pre></li></ol><ol start="7"><li>Boot into Linux<br />
    178 <pre class="wiki">Laguna&gt; bootm
    179 </pre></li></ol><p>
     144}}}
     1451. Boot into Linux
     146{{{#!bash
     147Laguna> bootm
     148}}}
     149
    180150Notes:
    181 </p>
    182 <ul><li>when using the SPI FLASH device you can erase the u-boot env flash section and restore factory defaults with:
    183 <pre class="wiki">Laguna&gt; protect off 0x60040000 +0x40000
    184 Laguna&gt; erase 0x60040000 +0x40000
    185 Laguna&gt; reset
    186 </pre></li></ul><h3 id="Usingu-boot-2014.10-cns3xxxbootloader">Using u-boot-2014.10-cns3xxx bootloader</h3>
    187 <p>
    188 If using the <a class="ext-link" href="https://github.com/Gateworks/u-boot-cns3xxx"><span class="icon">​</span>u-boot-2014.10-cns3xxx</a> which supports both the 16MB and 4MB SPI flash devices used on Laguna products, you will need to use the 'sf' commands within uboot to access flash.
    189 </p>
    190 <p>
     151 * when using the SPI FLASH device you can erase the u-boot env flash section and restore factory defaults with:
     152{{{#!bash
     153Laguna> protect off 0x60040000 +0x40000
     154Laguna> erase 0x60040000 +0x40000
     155Laguna> reset
     156}}}
     157
     158=== Using u-boot-2014.10-cns3xxx bootloader
     159If using the [https://github.com/Gateworks/u-boot-cns3xxx ​u-boot-2014.10-cns3xxx] which supports both the 16MB and 4MB SPI flash devices used on Laguna products, you will need to use the 'sf' commands within uboot to access flash.
     160
    191161Update kernel:
    192 </p>
    193 <pre class="wiki">setenv serverip 192.168.1.146
     162{{{#!bash
     163setenv serverip 192.168.1.146
    194164setenv ipaddr 192.168.1.1
    195165setenv spi_koffset 0x80000
     
    197167setenv spi_roffset 0x200000
    198168# update kernel
    199 tftp ${loadaddr} laguna/openwrt-cns3xxx-uImage &amp;&amp; sf probe &amp;&amp; sf update ${loadaddr} ${spi_koffset} ${filesize}
    200 </pre><p>
     169tftp ${loadaddr} laguna/openwrt-cns3xxx-uImage && sf probe && sf update ${loadaddr} ${spi_koffset} ${filesize}
     170}}}
     171
    201172Update SPI uboot:
    202 </p>
    203 <pre class="wiki"># update SPI uboot
     173{{{#!bash
     174# update SPI uboot
    204175setenv serverip 192.168.1.146
    205176setenv ipaddr 192.168.1.1
    206 tftp ${loadaddr} laguna/u-boot_spi.bin &amp;&amp; sf probe &amp;&amp; sf update ${loadaddr} 0 ${filesize}
    207 </pre><p>
     177tftp ${loadaddr} laguna/u-boot_spi.bin && sf probe && sf update ${loadaddr} 0 ${filesize}
     178}}}
     179
    208180Enable Alternate Boot timer:
    209 </p>
    210 <pre class="wiki">i2c mw 0x20 1 0x40 1 # set R1.6 SWITCH_BOOT_ENABLE
    211 </pre><p>
     181{{{#!bash
     182i2c mw 0x20 1 0x40 1 # set R1.6 SWITCH_BOOT_ENABLE
     183}}}
     184
    212185Clear Alternate Boot timer:
    213 </p>
    214 <pre class="wiki">i2c mw 0x20 1 0xc0 1 # set R1.7 SWITCH_BOOT_CLEAR
    215 </pre
     186{{{#!bash
     187i2c mw 0x20 1 0xc0 1 # set R1.7 SWITCH_BOOT_CLEAR
    216188}}}