├── .gitignore └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # vagrant work directory 2 | /.vagrant 3 | /bin 4 | /tmp 5 | /run 6 | 7 | # files 8 | **/*iso 9 | **/*img 10 | 11 | # no build 12 | build/ 13 | 14 | # no archive 15 | **/*tgz 16 | **/*gz 17 | **/*xz 18 | **/*gzip 19 | 20 | 21 | # custom 22 | **/currentContainerIpAddr.txt 23 | 24 | # for security reason 25 | .vscode/** 26 | **/*key 27 | **/*pem 28 | **/*crt 29 | **/*id 30 | **/*der 31 | data/**/* 32 | *id 33 | 34 | # log not to repo 35 | log/* 36 | 37 | # wireshark 38 | **/*pcap 39 | 40 | # Logs 41 | logs 42 | *.log 43 | npm-debug.log* 44 | yarn-debug.log* 45 | yarn-error.log* 46 | 47 | # Runtime data 48 | pids 49 | *.pid 50 | *.seed 51 | *.pid.lock 52 | 53 | # Directory for instrumented libs generated by jscoverage/JSCover 54 | lib-cov 55 | 56 | # Coverage directory used by tools like istanbul 57 | coverage 58 | 59 | # nyc test coverage 60 | .nyc_output 61 | 62 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 63 | .grunt 64 | 65 | # Bower dependency directory (https://bower.io/) 66 | bower_components 67 | 68 | # node-waf configuration 69 | .lock-wscript 70 | 71 | # Compiled binary addons (https://nodejs.org/api/addons.html) 72 | build/Release 73 | 74 | # Dependency directories 75 | node_modules/ 76 | jspm_packages/ 77 | 78 | # TypeScript v1 declaration files 79 | typings/ 80 | 81 | # Optional npm cache directory 82 | .npm 83 | 84 | # Optional eslint cache 85 | .eslintcache 86 | 87 | # Optional REPL history 88 | .node_repl_history 89 | 90 | # Output of 'npm pack' 91 | *.tgz 92 | 93 | # Yarn Integrity file 94 | .yarn-integrity 95 | 96 | # dotenv environment variables file 97 | .env 98 | 99 | # next.js build output 100 | .next 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # orange-pi-zero-boot-from-spi 2 | 3 | ## sources 4 | 5 | ```txt 6 | https://forum.armbian.com/topic/3252-opi-zero-boot-with-spi/ 7 | ``` 8 | 9 | ## hardware 10 | 11 | - [orange pi zero](http://www.orangepi.org/orangepizero/) 12 | - 512 MByte version 13 | - ** with SPI memory ** 14 | - usb pen drive or disk with usb adapter 15 | 16 | ## os 17 | 18 | - [ARMBIAN strech](https://www.armbian.com/orange-pi-zero/) 19 | 20 | ```bash 21 | > uname -a 22 | Linux radio 4.14.12-sunxi #1 SMP Tue Jan 9 13:53:33 UTC 2018 armv7l GNU/Linux 23 | ``` 24 | 25 | ## prepare and boot from sd card 26 | 27 | ```bash 28 | # prepare sd card for boot on your linux computer 29 | cd /tmp 30 | curl -k -L https://dl.armbian.com/orangepizero/Debian_stretch_next.7z 31 | 7z e Debian_stretch_next.7z 32 | # the archive Dabian_strech_next.7z contains Armbian_5.75_Orangepizero_Debian_stretch_next_4.19.20.img 33 | sudo dd if=Armbian_5.75_Orangepizero_Debian_stretch_next_4.19.20.img of=/dev/mmcblk0 bs=1M status=progress | sync 34 | sync 35 | # boot with this sd card your orange pi zero 36 | ``` 37 | 38 | ## connect serial console at start minicom 39 | 40 | - pin layout look on the board near the pins 41 | 42 | ```bash 43 | # serial modem on /dev/ttyUSB0 44 | sudo minicom -s -D /dev/ttyUSB0 -b 115200 --color=on 45 | ``` 46 | 47 | 48 | ## install software 49 | 50 | **first** freeze the kernel packages 51 | the package not anytime updated 52 | 53 | -via armbian-config 54 | 55 | -or via cli 56 | 57 | ```bash 58 | sudo apt-mark hold linux-dtb-next-sunxi 59 | sudo apt-mark hold linux-image-next-sunxi 60 | sudo apt-mark hold linux-stretch-root-next-orangepizero 61 | sudo apt-mark hold linux-u-boot-orangepizero-next 62 | ``` 63 | 64 | - un hold 65 | 66 | ```bash 67 | sudo apt-mark unhold linux-dtb-next-sunxi 68 | sudo apt-mark unhold linux-image-next-sunxi 69 | sudo apt-mark unhold linux-stretch-root-next-orangepizero 70 | sudo apt-mark unhold linux-u-boot-orangepizero-next 71 | ``` 72 | 73 | - display packages on hold 74 | 75 | ```bash 76 | dpkg --get-selections |awk '$2 == "hold" { print $1 }' 77 | ``` 78 | 79 | ## activate overlay for spi bus (rom) 80 | 81 | **Important** this follow step must you do onces per board or for update uboot, this is not necessary you want update your usb device 82 | 83 | **PLEASE BE SURE** you have a OPI zero with a spi ic :-) Some version came w/o spi 84 | 85 | ```bash 86 | sudo apt update && sudo apt upgrade && sudo apt autoremove 87 | sudo apt-get install flashrom 88 | ``` 89 | 90 | - edit in file /boot/armbianEnv.txt and add spi-spidev AND param_spidev_spi_bus=0 91 | 92 | ```bash 93 | # edit by hand 94 | overlays=analog-codec usbhost2 usbhost3 spi-spidev 95 | param_spidev_spi_bus=0 96 | ``` 97 | 98 | - with bash script 99 | 100 | ```bash 101 | ARMBIAN_ENV_FILE="/boot/armbianEnv.txt" 102 | if sudo grep spi-spidev $ARMBIAN_ENV_FILE; then 103 | echo "[ok] found spi-spidev" 104 | else 105 | echo "[missing] NOT found spi-spidev" 106 | echo "[todo] add spi-spidev" 107 | sudo sed -i '/overlays=/s/$/ spi-spidev/' $ARMBIAN_ENV_FILE 108 | echo "param_spidev_spi_bus=0"|sudo tee -a $ARMBIAN_ENV_FILE 109 | fi 110 | ``` 111 | 112 | - sample /boot/armbianEnv.txt file from working device 113 | 114 | ```bash 115 | verbosity=1 116 | logo=disabled 117 | console=both 118 | disp_mode=1920x1080p60 119 | overlay_prefix=sun8i-h3 120 | overlays=usbhost2 usbhost3 121 | rootdev=UUID=84168f41-20b8-4905-9021-54488d09dc33 122 | rootfstype=ext4 123 | overlays=analog-codec usbhost2 usbhost3 spi-spidev 124 | param_spidev_spi_bus=0 125 | usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u 126 | ``` 127 | 128 | ## cold reboot the OPI zero 129 | 130 | ```bash 131 | sudo shutdown -Fh now 132 | # unplug/plug the power adapter and start again 133 | ``` 134 | 135 | **AFTER THE COLD REBOOT** should you see the spi device under /dev 136 | 137 | ```bash 138 | >ls -l /dev/spidev0.0 139 | crw------- 1 root root 153, 0 Nov 10 21:17 /dev/spidev0.0 140 | ``` 141 | 142 | ## write uboot to spi rom for boot from it 143 | 144 | ```bash 145 | # create empty image 146 | sudo dd if=/dev/zero count=2048 bs=1K | tr '\000' '\377' > spi.img 147 | # ATTENTION in some tutorial used the size 4096k BUT in the some OPI zero board are only a 2048K 148 | # We need only 537k space for the u-boot image in this case 149 | 150 | # write/copy u-boot in spi image 151 | # this file is already of the images/sd card 152 | # only the version number is depend from the armbian version 153 | # e.g. sudo dd if=/usr/lib/linux-u-boot-next-orangepizero_5.65_armhf/u-boot-sunxi-with-spl.bin of=spi.img bs=1k conv=notrunc 154 | 155 | ARMBIAN_VERSION=$(grep VERSION /etc/armbian-release|sed 's/.*=//g') 156 | echo $ARMBIAN_VERSION 157 | sudo dd if=/usr/lib/linux-u-boot-next-orangepizero_${ARMBIAN_VERSION}_armhf/u-boot-sunxi-with-spl.bin of=spi.img bs=1k conv=notrunc 158 | 159 | # flash the image to spi rom 160 | sudo flashrom -p linux_spi:dev=/dev/spidev0.0 -w spi.img -c MX25L1605A/MX25L1606E/MX25L1608E 161 | ``` 162 | 163 | 164 | ## prepare usb or disk 165 | 166 | 167 | 168 | ```bash 169 | # install Armbian on usb stick, pendisk or disk 170 | # follow instruction inside the menu default value is a good choice 171 | # DON'T REBOOT the device last step in the dialog 172 | sudo nand-sata-install 173 | 174 | # mount the pendrive/stick 175 | sudo mount /dev/sda1 /mnt 176 | 177 | # copy (overwrite) the /boot directory 178 | sudo cp -a /boot /mnt 179 | 180 | # edit /mnt/boot/boot.cmd and set the rootdev from usb device 181 | setenv rootdev "/dev/sda1" 182 | 183 | # create a new boot.scr on the boot device 184 | sudo mkimage -C none -A arm -T script -d /mnt/boot/boot.cmd /mnt/boot/boot.scr 185 | 186 | # save /mnt/etc/fstab 187 | sudo cp /mnt/etc/fstab /mnt/etc/fstab_save 188 | 189 | # edit /mnt/etc/fstab and uncomment all line with /media/mmcboot 190 | sudo sed -i '/mmcboot/s/^/#/' /mnt/etc/fstab 191 | 192 | 193 | # and ADD the the boot partition to /mnt/etc/fstab 194 | printf "UUID=%s\t/\t%s\tdefaults,noatime,nodiratime,commit=600,errors=remount-ro,x-gvfs-hide\t0\t1" $(sudo blkid /dev/sda1 -o value -s UUID) $(sudo blkid /dev/sda1 -o value -s TYPE)|sudo tee -a /mnt/etc/fstab 195 | 196 | ``` 197 | 198 | 199 | 200 | ## troubleshooting flashrom 201 | 202 | - the first 100 byte of the spi.img must the same as the u-boot-sunxi-with-spl.bin 203 | 204 | ```bash 205 | >hexdump -C -n100 spi.img 206 | 00000000 16 00 00 ea 65 47 4f 4e 2e 42 54 30 d5 5b 4c 75 |....eGON.BT0.[Lu| 207 | 00000010 00 60 00 00 53 50 4c 02 00 00 00 00 00 00 00 00 |.`..SPL.........| 208 | 00000020 2c 00 00 00 00 00 00 00 00 00 00 00 73 75 6e 38 |,...........sun8| 209 | 00000030 69 2d 68 32 2d 70 6c 75 73 2d 6f 72 61 6e 67 65 |i-h2-plus-orange| 210 | 00000040 70 69 2d 7a 65 72 6f 00 00 00 00 00 00 00 00 00 |pi-zero.........| 211 | 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 212 | 00000060 0f 00 00 ea |....| 213 | 214 | > hexdump -C -n100 /usr/lib/linux-u-boot-next-orangepizero_5.65_armhf/u-boot-sunxi-with-spl.bin 215 | 00000000 16 00 00 ea 65 47 4f 4e 2e 42 54 30 d5 5b 4c 75 |....eGON.BT0.[Lu| 216 | 00000010 00 60 00 00 53 50 4c 02 00 00 00 00 00 00 00 00 |.`..SPL.........| 217 | 00000020 2c 00 00 00 00 00 00 00 00 00 00 00 73 75 6e 38 |,...........sun8| 218 | 00000030 69 2d 68 32 2d 70 6c 75 73 2d 6f 72 61 6e 67 65 |i-h2-plus-orange| 219 | 00000040 70 69 2d 7a 65 72 6f 00 00 00 00 00 00 00 00 00 |pi-zero.........| 220 | 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 221 | 00000060 0f 00 00 ea |....| 222 | ``` 223 | 224 | - after flashrom write can you reread the image back and compare 225 | 226 | ```bash 227 | # read spi rom to img file 228 | >sudo flashrom -p linux_spi:dev=/dev/spidev0.0 -r spi_read.img -c MX25L1605A/MX25L1606E/MX25L1608E 229 | ``` 230 | 231 | - the hexdump of the spi_read.img must the same as the spi.img 232 | - check e,g, with md5sum and other checksum methods 233 | 234 | ```bash 235 | >md5sum spi.img 236 | c61f5c3823f1752d59505148ce90ae89 spi.img 237 | >md5sum spi_read.img 238 | c61f5c3823f1752d59505148ce90ae89 spi_read.img 239 | ``` 240 | 241 | - if the reread images is only collection of null repeat all step in prepare spi for boot 242 | - WRONG WRITING OR WRITING WITHOUT COPY THE UBOOT.BIN 243 | 244 | ```bash 245 | >hexdump -C -n100 spi_read.img 246 | 00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| 247 | ``` 248 | 249 | - Warning: Chip content is identical to the requested image. give you a hint of any error 250 | 251 | ## cold reboot the device 252 | 253 | ```bash 254 | shutdown -Fh now 255 | # unplug the power adapter 256 | # remove the sd card 257 | # start the device hopeful boot from spi/usb pendrive 258 | ``` 259 | 260 | ## delete spi device / enable boot from sdcard 261 | 262 | - delete the u-boot image in the spi memory 263 | 264 | ```bash 265 | # erase 266 | sudo flashrom -p linux_spi:dev=/dev/spidev0.0 -E -c MX25L1605A/MX25L1606E/MX25L1608E 267 | # check it empty 268 | sudo flashrom -p linux_spi:dev=/dev/spidev0.0 -r spi_read.img -c MX25L1605A/MX25L1606E/MX25L1608E 269 | hexdump -C -n100 spi_read.img 270 | 00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| 271 | # you should see a collection of null 272 | ``` 273 | 274 | - now should we boot from sd card again 275 | --------------------------------------------------------------------------------