Flash from command line

From www.chip-community.org
Jump to: navigation, search

This page describes two distinct options for flashing from the command line. The first is interactive and similar to the web flasher but without the web interface. The second is non-interactive and works offline, that is, it does not communicate with any server and can thus be used after Nextthing's demise as long as you have a saved copy of the image files.

Flashing your C.H.I.P. without the web flasher

related forum post

If you need more diagnostic information, or the web flasher simply doesn't work for you / you don't use Google products because of privacy concerns, there is a method you can use for the Ubuntu[1] shell.

Step 1: fire up your Ubuntu machine. Can be 14.04 - mine was 14.10, and it worked.

Step 2: be sure you have git installed

sudo apt install git

(apt-get if you prefer over apt. No, that's not a mistake, there's an apt program now. I know, shocked me too when I first saw it.)

Step 3: Make a work directory (or use one you already have) and clone the NextThingCo Chip-SDK.

 mkdir ~/workdir
 cd ~/workdir
 git clone https://github.com/NextThingCo/CHIP-SDK

Step 4: Since Dec 13, 2016 this step should be obsolete (as the 4.4multi branch got merged into master)

change to the CHIP-SDK directory, and switch to the "4.4multi" branch. This is the branch that has the November 2016 fixes, including Toshiba NAND chip support.

 cd CHIP-SDK
 git checkout -b 4.4multi origin/by/4.4multi

Step 5: change to the CHIP-SDK directory, and inspect the script

 cd ~/workdir/CHIP-SDK
 less setup_ubuntu1404.sh

READ the script. Understand what it will do. It will _probably_ install software to your machine. It will also be asking you for administrative access to make changes. If you don't understand what something does, ask on the forum or on irc for an explanation of what the part you are confused about does.

 bash setup_ubuntu1404.sh

Step 6: This step should be obsolete (the setup script setup_ubuntu1404.sh links sunix-fel to /usr/local/bin/)

Link the fel program from the newly created/updated sunxi-tools directory to somewhere in your path. (If you are using your own work directory, change the path below to match your work directory)

 sudo ln -s ~/workdir/CHIP-SDK/sunxi-tools/fel /usr/local/bin/fel 

Step 7: This step should be obsolete (the setup script setup_ubuntu1404.sh links sunix-fel to /usr/local/bin/)

Edit the CHIP-tools/common.sh script so that the fel program is 'fel' and not sunxi-fel - use whatever editor you like. nano/mg/emacs/jed/sublime/zile/textadept/vi/ex/vim/leafpad - whichever you prefer, doens't matter.

 Line #4 contains the following:  FEL=sunxi-fel  ; replace this with  FEL=fel  ; then save the file.

Step 8: enter the CHIP-tools directory, be sure we're on the 4.4multi version [Since Dec 13, 2016 the striked out part of this step should be obsolete (as the 4.4multi branch got merged into chip/stable)], and run the chip-update-firmware program with -h to get help.

 cd CHIP-tools
 git checkout -b 4.4multi origin/by/4.4multi
 bash chip-update-firmware.sh -h

``RESULT:``

   == Help ==
   
     -s  --  Server             [Debian + Headless]
     -g  --  GUI                [Debian + XFCE]
     -p  --  PocketCHIP
     -b  --  Buildroot
     -f  --  Force clean
     -B  --  Branch(optional)   [eg. -B testing]
     -N  --  Build#(optional)   [eg. -N 150]
     -F  --  Format(optional)   [eg. -F Toshiba_4G_MLC]


Step 9: Choose which version you want to install.

-p is for pocketchip.
-s is for the headless server version.
-g is for the GUI version.  It is unknown if this is the limited or unlimited version from the web flasher.  It is ```likely``` unlimited.
-b is for buildroot, which is a good test to see if this works as it won't download much.  It is VERY bare bones.

You won't need to pick which NAND type you need, the script should detect that, and the build numbers are undocumented at this time, so unless you really want to expiriment, don't worry about -N, -B, or -F options.

Step 10: put the FEL jumper wire into the CHIP, just like it shows on the docs.getchip.com/chip.html documentation page - and here: uboot_fel_jumper.jpg


OPTIONAL: run tmux to capture the output / screen to capture the output / capture the output your favorite way. If you don't know any other way to do it, you can use the "tee" program to make a copy. This is shown below.

Step 11: run the chip-update-firmware program with the option you want. (I used -b and then, after it was successful, I used -g . The gui image took much longer to download as it had more data to pull from the net.)

 bash chip-update-firmware.sh -b | tee /var/tmp/flash_buildroot.log

the pipe (the | character ) and the tee command will save what you see to a log file (/var/tmp/flash_buildroot.log) - feel free to name it something else or put it in another folder.

Step 12: Watch the diagnostic info, and wait for it to say 'entering Fastboot mode' and WATCH IT ENTER FASTBOOT MODE AND NOT FAIL. This part is where most failures happened BEFORE the new flash versions came out. I.e. trying to flash the HYANIX on a Toshiba.

      • if this doesn't work, we have an issue - take the debug log, put it on paste.ie or somewhere like that, and ask for help on the forum (including the link to the log.)

Step 13: Look at the ascii graphic, the "FLASH VERIFICATION COMPLETE." and "CHIP is ready to roll!" messages, and power off the CHIP.

Step 14: Remove the jumper wire! (Unless you are going to immediately flash again. )

Step 15: Connect your display and fire it up - or use the usb serial if you prefer. Enjoy using your newly flashed C.H.I.P!

FAQs

Question 1 can I use some other Linux? - answer: Debian SHOULD work; someone did report success with it. That means Mint also should work, and other Debian and Ubuntu and Mint based Linux Distros. - The install script uses apt-get (or apt) so... you might be in for some converting if you're using Fedora/Centos/Gentoo/Arch/Void/Slackware/TinyCore. And you are definately in for converting if using Free/Net/OpenBSD or TrueOS, or Opensolaris. You did read the script, and were just wondering if you really _needed_ the install script if you just installed the software in it and compiled sunxi-tools? Then yes, yes this _should_ work. Your mileage will vary; please report success using this on non-Ubuntu in the forum / discussion!

Question 2: how about osX? - POTENTIALLY, after some conversion, but you may run into some low-level issues with writing to the usb port directly. - Using a Ubuntu live cd/dvd/usb stick is likely to be less time consuming.

Question 3: Powershell on Windows? - That would be something I would not want to spend time on, but a Windows engineer might enjoy converting this for Windows. - Also you are likely to run into usb driver issues and other difficulties. - Using the Ubuntu Livecd/dvd/usb stick is definately less time consuming.

Question 4: There's a vagrant file in there, would that work? - Sadly, no. Even on Linux, this seems to run into issues with the fastboot program and the C.H.I.P being seen. Other programs (Fel) can see it, read and write, but Fastboot ... just times out. As that's integral to getting this to work, until fastboot can be made to work from Vagrant / Virtualbox, it's going to be trouble. - alternate backings for Vagrant: VMware? Untested. KVM? Untested. QEMU? Untested. Report success/failure if you try!
Note: from this forum post by GTP The vagrant method works, but you have to manually change a value in the vagrant file. It’s explained in this GitHub issue.

Question 5: Where are the images saved? All the data is within the .dl folder. - For example, my buildroot cached files are in ~/workdir/CHIP-SDK-CHIP-tools/.dl/stable-buildroot-b128/

Question 6: How do these files relate to the .chp format? We don't know, and we'd love to know! Please contribute info if you know/find anything out.

Notes

  1. This script is tested/developed? on Ubuntu, and the install script assumes a .deb style (apt, apt-get) package management system. It uses the bash shell. It is currently untested on other distributions of Linux and other forms of Un*x like the BSD's. It has also not been tested with osX directly.

Flashing CHIP offline

Note: this section is largely copied from forum user yoursunny

The offline flashing requires having a number of images files downloaded and uses the `chip-update-firmware.sh` script provided by NextThing in their CHIP-tools github repository.

The files that need to be downloaded depend on the flavor of chip, e.g. server, gui, pocketchip, and buildroot. For the stable version of the server flavor the following files are needed:

SPL, sunxi, U-Boot

http://opensource.nextthing.co/chip/images/stable/server/149/spl-40000-1000-100.bin http://opensource.nextthing.co/chip/images/stable/server/149/spl-400000-4000-500.bin http://opensource.nextthing.co/chip/images/stable/server/149/spl-400000-4000-680.bin http://opensource.nextthing.co/chip/images/stable/server/149/sunxi-spl.bin http://opensource.nextthing.co/chip/images/stable/server/149/u-boot-dtb.bin http://opensource.nextthing.co/chip/images/stable/server/149/uboot-40000.bin http://opensource.nextthing.co/chip/images/stable/server/149/uboot-400000.bin

CHIP operating system for Hynix NAND

http://opensource.nextthing.co/chip/images/stable/server/149/chip-400000-4000-680.ubi.sparse

CHIP operating system for Toshiba NAND

http://opensource.nextthing.co/chip/images/stable/server/149/chip-400000-4000-500.ubi.sparse

The instructions below assume that these files are downloaded into a server-b149 directory. If the Nextthing server is no longer available, these can also be downloaded from yoursunny's bintray repo https://dl.bintray.com/yoursunny/CHIP/.

Instructions

  • Download all needed files into a stable-server-b149 directory (or otherwise appropriately named).
  • git clone https://github.com/NextThingCo/CHIP-tools into another directory.
  • Install some standard tools: on ubuntu sudo apt install android-tools-fastboot sunxi-tools u-boot-tools and on Arch install aur/android-sdk-platform-tools, aur/sunxi-tools and aur/uboot-tools.
  • Put CHIP into FEL mode and connect to your computer via USB.
  • Run sudo whoami so the next command doesn't prompt you for the sudo password.
  • In the CHIP-tools directory run FEL='sudo sunxi-fel' FASTBOOT='sudo fastboot' SNIB=false ./chip-update-firmware.sh -L ../stable-server-b149.
  • When FLASH VERIFICATION COMPLETE message appears, flashing is successful.

Notes

  • You may need to install a LiPo battery on the CHIP if you're using a Raspberry Pi 3's USB port because it cannot supply enough current for CHIP to operate smoothly.

Sample transcript

> env FEL='sudo sunxi-fel' FASTBOOT='sudo fastboot' SNIB=false ./chip-
update-firmware.sh -L ../Images
== Local directory '../Images' selected ==
== preparing images ==
== Local/cached probe files located ==
== Staging for NAND probe ==
Image Name:   detect NAND
Created:      Wed Apr  4 09:12:36 2018
Image Type:   ARM Linux Script (uncompressed)
Data Size:    97 Bytes = 0.09 KiB = 0.00 MiB
Load Address: 00000000
Entry Point:  00000000
Contents:
   Image 0: 89 Bytes = 0.09 KiB = 0.00 MiB
waiting for fel...OK
waiting for fel......OK
NAND detected:
nand_erasesize=400000
nand_oobsize=680
nand_writesize=4000
== Cached UBI located ==
Image Name:   flash server
Created:      Wed Apr  4 09:12:44 2018
Image Type:   ARM Linux Script (uncompressed)
Data Size:    1784 Bytes = 1.74 KiB = 0.00 MiB
Load Address: 00000000
Entry Point:  00000000
Contents:
   Image 0: 1776 Bytes = 1.73 KiB = 0.00 MiB
waiting for fel...OK
waiting for fastboot...........OK
target reported max download size of 33554432 bytes
sending sparse 'UBI' 1/11 (28672 KB)...
OKAY [  2.559s]
writing 'UBI' 1/11...
OKAY [  2.093s]
sending sparse 'UBI' 2/11 (28672 KB)...
OKAY [  2.489s]

...

sending sparse 'UBI' 11/11 (16384 KB)...
OKAY [  1.353s]
writing 'UBI' 11/11...
OKAY [  2.719s]
finished. total time: 135.135s
resuming boot...
OKAY [  0.000s]
finished. total time: 0.000s


FLASH VERIFICATION COMPLETE.


   #  #  #
  #########
###       ###
  # {#}   #
###  '%######
  #       #
###       ###
  ########
   #  #  #


CHIP is ready to roll!

CHIP Flasher Pi

Instructions for use:

  1. Download one of the versions of the card image. chip_flasher.img.xz 2.5GB or chip_flasher.zip 3.3GB
  2. Put the image on a µSD card at least 8G in size. I find Etcher easiest because it recognizes the compressed archive and automatically decompresses it and also validates that the writing was correct
  3. Connect a powered hub with a charging port of at least 1.5A capability to a Raspberry Pi (tested with the 3B, 3B+, and ZeroW). Alternatively use a LiPo battery connected to the CHIP as described in the previous section.
  4. Connect a monitor and keyboard to the Pi
  5. Insert the µSD card in the Pi
  6. Power up the Pi. It will boot most of the way up, set up to resize the partitions to fill the card then reboot (like the stock Raspbian images do)
  7. Log in as user pi, password raspberry
  8. Run this command in the home directory: sudo ./flash_chip.sh and follow the on screen instructions (be sure to use the charging port for CHIP)

After you're done, power off the Pi and pack away the card for the next time you need to flash a CHIP.

Notes:

  • The card image only contains the stable server, GUI and Pocket files but you can add others and modify the flashing script if you need one of the other variations.
  • To use this on a headless Raspberry Pi you need to vary the instructions above a little