├── Hikey970_download_images.xml ├── README.md ├── build_kernel.sh ├── config ├── hikey_idt ├── hisi-idt.py ├── lpm3.img ├── recovery-flash.sh ├── sec_usb_xloader.img ├── sec_usb_xloader2.img ├── sec_xloader.img └── update_Hikey970.bat /Hikey970_download_images.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/96boards-hikey/tools-images-hikey970/3186eef70ca79ff7226fe37682fda2fa64f6ddd8/Hikey970_download_images.xml -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tools-images-hikey970 2 | -------------------------------------------------------------------------------- /build_kernel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DTB=1 3 | LOCAL_DIR=$(pwd) 4 | KERNEL_DIR=${LOCAL_DIR}/kernel/hikey-linaro 5 | PRODUCT_OUT=${LOCAL_DIR}/out/target/product/hikey970 6 | HIKEY970_KERNEL=${LOCAL_DIR}/device/linaro/hikey-kernel 7 | MKBOOTTOOL_DIR=${LOCAL_DIR}/system/core/mkbootimg 8 | CURRENT_DIR=${LOCAL_DIR} 9 | NCPU=`grep -c ^processor /proc/cpuinfo` 10 | 11 | if [ ! -e ${PRODUCT_OUT} ] 12 | then 13 | mkdir -p ${PRODUCT_OUT} 14 | fi 15 | 16 | export ARCH=arm64 17 | export CROSS_COMPILE=${CURRENT_DIR}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android- 18 | 19 | function check_build_result() 20 | { 21 | if [ $? != 0 ]; then 22 | echo -e "\033[31m $1 build fail! \033[0m" 23 | exit -1 24 | else 25 | echo -e "\033[32m $1 build success! \033[0m" 26 | fi 27 | } 28 | 29 | cd ${KERNEL_DIR} 30 | 31 | make hikey970_defconfig && \ 32 | make -j$[NCPU*2] Image.gz modules 33 | 34 | check_build_result "Kernel Image" 35 | rm -f arch/arm64/configs/hikey970_temp_defconfig 36 | 37 | cp arch/arm64/boot/Image.gz ${HIKEY970_KERNEL} 38 | 39 | if [ $DTB -eq 1 ]; then 40 | make hisilicon/kirin970-hikey970.dtb 41 | check_build_result "Hikey970 dtb" 42 | cp arch/arm64/boot/dts/hisilicon/kirin970-hikey970.dtb ${HIKEY970_KERNEL} 43 | 44 | cp arch/arm64/boot/Image.gz ${HIKEY970_KERNEL}/Image.gz-hikey970-4.9 45 | cp arch/arm64/boot/dts/hisilicon/kirin970-hikey970.dtb ${HIKEY970_KERNEL}/kirin970-hikey970.dtb-4.9 46 | fi 47 | 48 | cd ${CURRENT_DIR} 49 | 50 | RAMDISK=${PRODUCT_OUT}/ramdisk.img 51 | 52 | if [ ! -e $RAMDISK ]; then 53 | . ./build/envsetup.sh && lunch hikey970-userdebug && make ramdisk 54 | check_build_result "Ramdisk Image" 55 | fi 56 | 57 | if [ ! -e $RAMDISK ]; then 58 | echo -e "\033[33m $RAMDISK is not exist! please build ramdisk first. \033[0m" 59 | echo -e "\033[33m . ./build/envsetup.sh && lunch hikey970-userdebug && make ramdisk \033[0m" 60 | exit -1 61 | fi 62 | 63 | #uefi boot.img = Image + dtb + ramdisk 64 | cat ${KERNEL_DIR}/arch/arm64/boot/Image ${KERNEL_DIR}/arch/arm64/boot/dts/hisilicon/kirin970-hikey970.dtb > ${HIKEY970_KERNEL}/Image-dtb 65 | check_build_result "Image-dtb" 66 | 67 | ${MKBOOTTOOL_DIR}/mkbootimg --kernel ${HIKEY970_KERNEL}/Image-dtb --ramdisk ${RAMDISK} --cmdline "androidboot.hardware=hikey970 firmware_class.path=/system/etc/firmware loglevel=15 buildvariant=userdebug androidboot.selinux=permissive clk_ignore_unused=true" --base 0x0 --tags_offset 0x07A00000 --kernel_offset 0x00080000 --ramdisk_offset 0x07c00000 --os_version 7.0 --os_patch_level 2016-08-05 --output ${PRODUCT_OUT}/boot.img 68 | check_build_result "Boot Image" 69 | 70 | echo -e "\033[36m build boot.img complete! \033[0m" 71 | -------------------------------------------------------------------------------- /config: -------------------------------------------------------------------------------- 1 | ./sec_usb_xloader.img 0x00022000 2 | ./sec_usb_xloader2.img 0x60049000 3 | ./l-loader.bin 0x16800000 4 | -------------------------------------------------------------------------------- /hikey_idt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/96boards-hikey/tools-images-hikey970/3186eef70ca79ff7226fe37682fda2fa64f6ddd8/hikey_idt -------------------------------------------------------------------------------- /hisi-idt.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | #-*- coding: utf-8 -*- 3 | 4 | import os 5 | import os.path 6 | import serial, time 7 | import array 8 | import sys, getopt 9 | 10 | class bootdownload(object): 11 | ''' 12 | Hisilicon boot downloader 13 | 14 | >>> downloader = bootdownload() 15 | >>> downloader.download(filename) 16 | 17 | ''' 18 | 19 | # crctab calculated by Mark G. Mendel, Network Systems Corporation 20 | crctable = [ 21 | 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 22 | 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 23 | 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 24 | 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 25 | 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 26 | 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 27 | 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 28 | 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 29 | 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 30 | 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, 31 | 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 32 | 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, 33 | 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 34 | 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 35 | 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 36 | 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 37 | 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 38 | 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, 39 | 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 40 | 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 41 | 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 42 | 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 43 | 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 44 | 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, 45 | 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 46 | 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 47 | 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 48 | 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 49 | 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 50 | 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 51 | 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 52 | 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, 53 | ] 54 | 55 | startframe = { 56 | 'hi3660':[0xFE,0x00,0xFF,0x01,0x00,0x00,0x00,0x04,0x00,0x00,0x02,0x01] 57 | } 58 | 59 | headframe = { 60 | 'hi3660':[0xFE,0x00,0xFF,0x01,0x00,0x00,0x00,0x04,0x00,0x00,0x02,0x01] 61 | } 62 | 63 | bootdownloadaddress0 = { 64 | #'hi3716cv200':0xF9800800 65 | 'hi3660':0x00022000 66 | } 67 | 68 | bootdownloadaddress1 = { 69 | #'hi3716cv200':0x07000000 70 | 'hi3660':0x60049000 71 | } 72 | 73 | bootdownloadaddress2 = { 74 | #'hi3716cv200':0x07000000 75 | 'hi3660':0x16800000 76 | } 77 | 78 | bootdownloadaddress3 = { 79 | 'hi3660':0x10000000 80 | } 81 | 82 | 83 | BOOT_HEAD_LEN = 0x4F00 84 | MAX_DATA_LEN = 0x400 85 | 86 | def __init__(self,chiptype,serialport): 87 | try: 88 | self.s = serial.Serial(dsrdtr=True, rtscts=True, port=serialport, baudrate=115200, timeout=1) 89 | except serial.serialutil.SerialException: 90 | #no serial connection 91 | self.s = None 92 | print("\nFailed to open serial!", serialport) 93 | sys.exit(2) 94 | 95 | self.chip = chiptype 96 | 97 | def __del__(self): 98 | if self.s != None: 99 | self.s.close() 100 | 101 | def calc_crc(self, data, crc=0): 102 | for char in data: 103 | crc = ((crc << 8) | char) ^ self.crctable[(crc >> 8) & 0xff] 104 | for i in range(0,2): 105 | crc = ((crc << 8) | 0) ^ self.crctable[(crc >> 8) & 0xff] 106 | return crc & 0xffff 107 | 108 | def getsize(self, filename): 109 | st = os.stat(filename) 110 | return st.st_size 111 | 112 | def sendframe(self, data, loop): 113 | for i in range(1, loop): 114 | self.s.flushOutput() 115 | self.s.write(data) 116 | self.s.flushInput() 117 | try: 118 | ack = self.s.read() 119 | if ack == b'\xaa': 120 | return None 121 | except: 122 | return None 123 | 124 | print('failed') 125 | 126 | def sendstartframe(self): 127 | self.s.timeout =0.01 128 | data = array.array('B', self.startframe[self.chip]).tostring() 129 | crc = self.calc_crc(data) 130 | data += chr((crc >> 8)&0xff) 131 | data += chr(crc&0xff) 132 | self.sendframe(data,10000) 133 | 134 | def sendheadframe(self,length,address): 135 | self.s.timeout = 0.03 136 | self.headframe[self.chip][4] = (length>>24)&0xff 137 | self.headframe[self.chip][5] = (length>>16)&0xff 138 | self.headframe[self.chip][6] = (length>>8)&0xff 139 | self.headframe[self.chip][7] = (length)&0xff 140 | self.headframe[self.chip][8] = (address>>24)&0xff 141 | self.headframe[self.chip][9] = (address>>16)&0xff 142 | self.headframe[self.chip][10] = (address>>8)&0xff 143 | self.headframe[self.chip][11] = (address)&0xff 144 | 145 | data = bytearray(self.headframe[self.chip]) 146 | crc = self.calc_crc(data) 147 | 148 | data.append((crc >> 8)&0xff) 149 | data.append(crc&0xff) 150 | 151 | self.sendframe(data,16) 152 | 153 | 154 | def senddataframe(self,seq,data): 155 | self.s.timeout = 0.15 156 | head = bytearray(b'\xDA') 157 | head.append(seq&0xFF) 158 | head.append((~seq)&0xFF) 159 | data = head + data 160 | 161 | crc = self.calc_crc(data) 162 | data.append((crc >> 8)&0xff) 163 | data.append(crc&0xff) 164 | 165 | self.sendframe(data,32) 166 | 167 | def sendtailframe(self,seq): 168 | data = bytearray(b'\xED') 169 | data.append(seq&0xFF) 170 | data.append((~seq)&0xFF) 171 | crc = self.calc_crc(data) 172 | data.append((crc >> 8)&0xff) 173 | data.append(crc&0xff) 174 | 175 | self.sendframe(data,16) 176 | 177 | def senddata(self, data, address): 178 | length=len(data) 179 | self.sendheadframe(length,address) 180 | seq=1 181 | while length > self.MAX_DATA_LEN: 182 | self.senddataframe(seq,data[(seq-1)*self.MAX_DATA_LEN:seq*self.MAX_DATA_LEN]) 183 | seq = seq+1 184 | length = length-self.MAX_DATA_LEN 185 | self.senddataframe(seq,data[(seq-1)*self.MAX_DATA_LEN:]) 186 | self.sendtailframe(seq+1) 187 | 188 | 189 | def download(self, filename1, filename2, filename3, filename4): 190 | 191 | f=open(filename1,"rb") 192 | data = f.read() 193 | f.close() 194 | 195 | print('Sending', filename1, '...') 196 | self.senddata(data,self.bootdownloadaddress0[self.chip]) 197 | print('Done\n') 198 | 199 | if filename2: 200 | f=open(filename2,"rb") 201 | data = f.read() 202 | f.close() 203 | 204 | print('Sending', filename2, '...') 205 | self.senddata(data,self.bootdownloadaddress1[self.chip]) 206 | print('Done\n') 207 | 208 | if filename3: 209 | f=open(filename3,"rb") 210 | data = f.read() 211 | f.close() 212 | 213 | print('Sending', filename3, '...') 214 | self.senddata(data,self.bootdownloadaddress2[self.chip]) 215 | print('Done\n') 216 | 217 | if filename4: 218 | f=open(filename4,"rb") 219 | data = f.read() 220 | f.close() 221 | 222 | print('Sending', filename4, '...') 223 | self.senddata(data,self.bootdownloadaddress3[self.chip]) 224 | print('Done\n') 225 | 226 | 227 | 228 | def burnboot(chiptype, serialport, filename1, filename2='', filename3='', filename4=''): 229 | downloader = bootdownload(chiptype, serialport) 230 | downloader.download(filename1, filename2, filename3, filename4) 231 | 232 | def startterm(serialport=0): 233 | try: 234 | miniterm = Miniterm( 235 | serialport, 236 | 115200, 237 | 'N', 238 | rtscts=False, 239 | xonxoff=False, 240 | echo=False, 241 | convert_outgoing=2, 242 | repr_mode=0, 243 | ) 244 | except serial.SerialException as e: 245 | sys.stderr.write("could not open port %r: %s\n" % (port, e)) 246 | sys.exit(1) 247 | miniterm.start() 248 | miniterm.join(True) 249 | miniterm.join() 250 | 251 | def main(argv): 252 | ''' 253 | img2 = 'fastboot2.img' 254 | ''' 255 | img1 = 'fastboot1.img' 256 | img2 = '' 257 | img3 = '' 258 | img4 = '' 259 | dev = ''; 260 | dev1 = '/dev/serial/by-id/usb-䕇䕎䥎_㄰㌲㔴㜶㤸-if00-port0' 261 | dev2 = '/dev/serial/by-id/pci-䕇䕎䥎_㄰㌲㔴㜶㤸-if00-port0' 262 | try: 263 | opts, args = getopt.getopt(argv,"hd:",["img1=","img2=","img3=","img4="]) 264 | except getopt.GetoptError: 265 | print('hisi-idt.py -d device --img1 --img2 ') 266 | sys.exit(2) 267 | for opt, arg in opts: 268 | if opt == '-h': 269 | print('hisi-idt.py -d device --img1 --img2 ') 270 | sys.exit() 271 | elif opt in ("-d"): 272 | dev = arg 273 | elif opt in ("--img1"): 274 | img1 = arg 275 | elif opt in ("--img2"): 276 | img2 = arg 277 | elif opt in ("--img3"): 278 | img3 = arg 279 | elif opt in ("--img4"): 280 | img4 = arg 281 | 282 | if dev == '': 283 | if os.path.exists(dev1): 284 | dev = dev1 285 | elif os.path.exists(dev2): 286 | dev = dev2 287 | else: 288 | print('Device not detected under /dev/serial/by-id/. Please use -d.') 289 | sys.exit(3) 290 | print('+----------------------+') 291 | print(' Serial: ', dev) 292 | print(' Image1: ', img1) 293 | print(' Image2: ', img2) 294 | print('+----------------------+\n') 295 | 296 | if not os.path.isfile(img1): 297 | print("Image don't exists:", img1) 298 | sys.exit(1) 299 | 300 | if (img2): 301 | if not os.path.isfile(img2): 302 | print("Image don't exists:", img2) 303 | sys.exit(1) 304 | 305 | if (img3): 306 | if not os.path.isfile(img3): 307 | print("Image don't exists:", img3) 308 | sys.exit(1) 309 | 310 | if (img4): 311 | if not os.path.isfile(img4): 312 | print("Image don't exists:", img4) 313 | sys.exit(1) 314 | 315 | burnboot('hi3660', dev, img1, img2, img3, img4) 316 | 317 | if __name__ == "__main__": 318 | main(sys.argv[1:]) 319 | -------------------------------------------------------------------------------- /lpm3.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/96boards-hikey/tools-images-hikey970/3186eef70ca79ff7226fe37682fda2fa64f6ddd8/lpm3.img -------------------------------------------------------------------------------- /recovery-flash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DEVICE=$1 3 | IMG_FOLDER=${PWD} 4 | 5 | # UEFI dir. Downloaded from 6 | # https://builds.96boards.org/snapshots/reference-platform/components/uefi-staging/ 7 | # Eg: 26/hikey970/release/ 8 | # Then, modify UEFI_BUILD_PATH accordingly. 9 | UEFI_BUILD_PATH=/home/qubo/tools-images-hikey970 10 | 11 | if [ "${DEVICE}" == "" ]; then 12 | DEVICE=/dev/ttyUSB0 13 | fi 14 | 15 | cd ${UEFI_BUILD_PATH} 16 | sudo ${UEFI_BUILD_PATH}/hikey_idt -c ${UEFI_BUILD_PATH}/config -p ${DEVICE} 17 | 18 | # partition table 19 | fastboot flash ptable ${UEFI_BUILD_PATH}/prm_ptable.img 20 | 21 | # bootloader 22 | fastboot flash xloader ${UEFI_BUILD_PATH}/sec_xloader.img 23 | fastboot flash fastboot ${UEFI_BUILD_PATH}/l-loader.bin 24 | fastboot flash fip ${UEFI_BUILD_PATH}/fip.bin 25 | 26 | # kernel ramdisk dt 27 | fastboot flash boot ${UEFI_BUILD_PATH}/boot.img 28 | 29 | fastboot flash cache ${UEFI_BUILD_PATH}/cache.img 30 | 31 | fastboot flash system ${UEFI_BUILD_PATH}/system.img 32 | 33 | fastboot flash userdata ${UEFI_BUILD_PATH}/userdata.img 34 | -------------------------------------------------------------------------------- /sec_usb_xloader.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/96boards-hikey/tools-images-hikey970/3186eef70ca79ff7226fe37682fda2fa64f6ddd8/sec_usb_xloader.img -------------------------------------------------------------------------------- /sec_usb_xloader2.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/96boards-hikey/tools-images-hikey970/3186eef70ca79ff7226fe37682fda2fa64f6ddd8/sec_usb_xloader2.img -------------------------------------------------------------------------------- /sec_xloader.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/96boards-hikey/tools-images-hikey970/3186eef70ca79ff7226fe37682fda2fa64f6ddd8/sec_xloader.img -------------------------------------------------------------------------------- /update_Hikey970.bat: -------------------------------------------------------------------------------- 1 | cls 2 | 3 | :start 4 | 5 | @echo ----------------------------- 6 | @echo %date%-%time% 7 | @echo "hikey970 Updating:" 8 | 9 | fastboot flash xloader sec_xloader.img 10 | @if errorlevel 1 goto error 11 | 12 | fastboot flash ptable prm_ptable.img 13 | @if errorlevel 1 goto error 14 | 15 | fastboot flash fastboot l-loader.bin 16 | @if errorlevel 1 goto error 17 | 18 | fastboot flash fip fip.bin 19 | @if errorlevel 1 goto error 20 | 21 | ::fastboot flash nvme nvme.img 22 | :: @if errorlevel 1 goto error 23 | 24 | ::fastboot flash trustfirmware bl31.bin 25 | :: @if errorlevel 1 goto error 26 | 27 | fastboot flash boot boot.img 28 | @if errorlevel 1 goto error 29 | 30 | fastboot flash cache cache.img 31 | @if errorlevel 1 goto error 32 | 33 | fastboot flash system system.img 34 | @if errorlevel 1 goto error 35 | 36 | fastboot flash userdata userdata.img 37 | @if errorlevel 1 goto error 38 | 39 | @goto sucess 40 | 41 | :error 42 | @echo "Update Failed!" 43 | @pause 44 | @goto end 45 | 46 | :sucess 47 | @echo "Update Sucess" 48 | @pause 49 | 50 | :end --------------------------------------------------------------------------------