您尚未登录。

楼主 # 2025-05-31 21:21:22

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,381
积分: 9202

九鼎创展 A733 开发板使用记录

九鼎创展 A733 开发板使用记录



开发板购买地址:九鼎全志A733开发板NPU算力3TOPS安卓Linux系统八核处理器


台电P50Ai平板电脑购买地址:Teclast/台电 P50Ai平板电脑A733八核CPU11英寸屏幕6G+128G安卓15





在线

楼主 #1 2025-05-31 21:21:43

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,381
积分: 9202

Re: 九鼎创展 A733 开发板使用记录

出厂固件的开机日志:

[11677]Training result is = 7
[11680]DRAM Pstate 0 training, frequency is 1800 Mhz
[11688]Actual DRAM SIZE =6144 M
[11691]DRAM SIZE =6144 MBytes, para1 = a10a, para2 = 18001001, dram_tpr13 = 10061
[11701]DRAM simple test OK.
[11704]rtc[3] value = 0xb00f
[11707]rtc[7] value = 0x2
[11709]init dram ok


U-Boot 2018.07 (Mar 31 2025 - 06:54:43 +0000) Allwinner Technology

[13.838]CPU:   Allwinner Family
[13.841]Model: sun60iw2
I2C:   ready
[13.901]DRAM:  512 MiB
[13.906]Relocation Offset is: 15dac000
[13.956]sunxi_drm_dsi_post_bind:706
[13.960]secure enable bit: 0
[13.963]PMU: AXP8191
[13.965]PMU: AXP8191 VER_A
[13.967]PMU: pmu_axp8191 found
FDT ERROR:fdt_get_regulator_name:get property handle twi-supply error:FDT_ERR_INTERNAL
[13.979]gpio_bias, pc_bias:   -1, pc_supply: not set
[13.984]gpio_bias, pl_bias:   -1, pl_supply: not set
[13.989]BMU: no found
[13.991][AXP8191] onoff status: 0x50 = 0x0, 0x51 = 0x0
[13.996][AXP8191] charge status: 0x4 = 0x0
[14.000]CPU=1014 MHz,PLL6=1200 Mhz,AHB=200 Mhz, APB1=24Mhz  MBus=600Mhz
[14.006]gic: normal mode
[14.008]sunxi flash type@0 not support fast burn key
[14.013]sunxi flash map init
[14.018]init_clocks:finish
[14.020]flash init start
[14.022]workmode = 16,storage type = 0
try card 2
set card number 2
get card number 2
[14.030][mmc]: mmc driver ver uboot2018:2024-10-18 9:01:00
[14.039][mmc]: Is not Boot mode!
[14.041][mmc]: SUNXI SDMMC Controller Version:0x50610
[14.049][mmc]: 200 MHz...
[14.051][mmc]: sample: 23 - 108(ps)
[14.054][mmc]: ds: 23 - 108(ps)
[14.061][mmc]: ************Try SD card 2************
[14.066][mmc]: mmc 2 cmd timeout 100 status 100
[14.070][mmc]: smc 2 err, cmd 8,  RTO
[14.074][mmc]: mmc 2 close bus gating and reset
[14.079][mmc]: mmc 2 cmd timeout 100 status 100
[14.083][mmc]: smc 2 err, cmd 55,  RTO
[14.086][mmc]: mmc 2 close bus gating and reset
[14.090][mmc]: ************Try MMC card 2************
[14.199][mmc]: mmc 2 cmd timeout 100 status 100
[14.203][mmc]: smc 2 err, cmd 8,  RTO
[14.206][mmc]: mmc 2 close bus gating and reset
[14.211][mmc]: mmc 2 cmd timeout 100 status 100
[14.215][mmc]: smc 2 err, cmd 55,  RTO
[14.219][mmc]: mmc 2 close bus gating and reset
[14.234][mmc]: gen_tuning_blk_bus8: total blk 10
[14.239][mmc]: gen_tuning_blk_bus4: total blk 6
[14.243][mmc]: Using 8 bit tuning now
[14.278][mmc]: write_tuning_try_freq: write ok
[14.283][mmc]: Pattern compare ok
[14.286][mmc]: Write tuning pattern ok
[14.289][mmc]: ================== HSSDR52_SDR25...
[14.294][mmc]: skip freq 400000
[14.297][mmc]: skip freq 25000000
[14.300][mmc]: freq: 2-50000000-64-4
[15.069][mmc]: [0-63|64]
[15.071][mmc]: ================== HS200_SDR104...
[15.076][mmc]: skip freq 400000
[15.078][mmc]: skip freq 25000000
[15.081][mmc]: freq: 2-50000000-64-4
[15.840][mmc]: freq: 3-100000000-64-4
[16.539][mmc]: freq: 4-150000000-64-4
[17.157][mmc]: freq: 5-200000000-64-4
[17.756][mmc]: [0-62|63]
[17.759][mmc]: [0-62|63]
[17.761][mmc]: [0-0|1] [7-62|56]
[17.764][mmc]: [0-15|16] [23-61|39]
[17.767][mmc]: ================== HSDDR52_DDR50...
[17.772][mmc]: skip freq 400000
[17.775][mmc]: freq: 1-25000000-64-4
[18.503][mmc]: freq: 2-50000000-64-4
[19.149][mmc]: [0-59|60]
[19.151][mmc]: [0-44|45] [47-59|13]
[19.154][mmc]: ================== HS400...
[19.158][mmc]: skip freq 400000
[19.161][mmc]: skip freq 25000000
[19.164][mmc]: freq: 2-50000000
[19.189][mmc]: freq: 3-100000000
[19.213][mmc]: freq: 4-150000000
[19.235][mmc]: freq: 5-200000000
[19.257][mmc]: speed mode: HS400
[19.260][mmc]: [0-63|64]
[19.262][mmc]: [0-63|64]
[19.265][mmc]: [0-3|4] [7-63|57]
[19.268][mmc]: [0-20|21] [23-63|41]
[19.271][mmc]: skip freq 400000
[19.274][mmc]: skip freq 25000000
[19.277][mmc]: freq: 2-50000000-64-4
[19.963][mmc]: freq: 3-100000000-64-4
[20.400][mmc]: freq: 4-150000000-64-4
[20.679][mmc]: freq: 5-200000000-64-4
[20.888][mmc]: [2-63|62]
[20.890][mmc]: [2-41|40]
[20.892][mmc]: [2-26|25]
[20.895][mmc]: *** hs400 200m: data win=10, delay cell = 108 ***
[20.900][mmc]: [2-19|18]
[20.903][mmc]: DS26/SDR12: 0xffffffff 0xffffffff
[20.907][mmc]: HSSDR52/SDR25: 0xff20ffff 0xffffffff
[20.912][mmc]: HSDDR52/DDR50: 0xff161eff 0xffffffff
[20.916][mmc]: HS200/SDR104: 0x1f1fffff 0xffff2a23
[20.921][mmc]: HS400: 0x1621ffff 0xffff0b0e
[20.925][mmc]: HS400: 0x2020ffff 0xffff2b23
[20.929][mmc]: Best spd md: 4-HS400, freq: 5-200000000, Bus width: 8
[20.935]Loading Environment from SUNXI_FLASH... OK
[20.940]try to burn key
[20.942]out of usb burn from boot: not boot mode
Hit any key to stop autoboot:  0
sunxi work mode=0x10
run usb efex
buf queue page size = 65536
delay time 2500
usb init ok
set address 0xe
set address 0xe ok
set address 0xf
set address 0xf ok
SUNXI_EFEX_ERASE_TAG
erase_flag = 0x12
origin_erase_flag = 0x1
FEX_CMD_fes_verify_status
FEX_CMD_fes_verify last err=0
the 0 mbr table is ok
the 1 mbr table is ok
the 2 mbr table is ok
the 3 mbr table is ok
*************MBR DUMP***************
total mbr part 29

part[0] name      :bootloader_a
part[0] classname :DISK
part[0] addrlo    :0x8000
part[0] lenlo     :0x10000
part[0] user_type :32768
part[0] keydata   :0
part[0] ro        :0

part[1] name      :bootloader_b
part[1] classname :DISK
part[1] addrlo    :0x18000
part[1] lenlo     :0x10000
part[1] user_type :32768
part[1] keydata   :0
part[1] ro        :0

part[2] name      :env_a
part[2] classname :DISK
part[2] addrlo    :0x28000
part[2] lenlo     :0x200
part[2] user_type :32768
part[2] keydata   :0
part[2] ro        :0

part[3] name      :env_b
part[3] classname :DISK
part[3] addrlo    :0x28200
part[3] lenlo     :0x200
part[3] user_type :32768
part[3] keydata   :0
part[3] ro        :0

part[4] name      :boot_a
part[4] classname :DISK
part[4] addrlo    :0x28400
part[4] lenlo     :0x20000
part[4] user_type :32768
part[4] keydata   :0
part[4] ro        :0

part[5] name      :boot_b
part[5] classname :DISK
part[5] addrlo    :0x48400
part[5] lenlo     :0x20000
part[5] user_type :32768
part[5] keydata   :0
part[5] ro        :0

part[6] name      :vendor_boot_a
part[6] classname :DISK
part[6] addrlo    :0x68400
part[6] lenlo     :0x10000
part[6] user_type :32768
part[6] keydata   :0
part[6] ro        :0

part[7] name      :vendor_boot_b
part[7] classname :DISK
part[7] addrlo    :0x78400
part[7] lenlo     :0x10000
part[7] user_type :32768
part[7] keydata   :0
part[7] ro        :0

part[8] name      :init_boot_a
part[8] classname :DISK
part[8] addrlo    :0x88400
part[8] lenlo     :0x4000
part[8] user_type :32768
part[8] keydata   :0
part[8] ro        :0

part[9] name      :init_boot_b
part[9] classname :DISK
part[9] addrlo    :0x8c400
part[9] lenlo     :0x4000
part[9] user_type :32768
part[9] keydata   :0
part[9] ro        :0

part[10] name      :super
part[10] classname :DISK
part[10] addrlo    :0x90400
part[10] lenlo     :0x700000
part[10] user_type :32768
part[10] keydata   :0
part[10] ro        :0

part[11] name      :misc
part[11] classname :DISK
part[11] addrlo    :0x790400
part[11] lenlo     :0x8000
part[11] user_type :32768
part[11] keydata   :0
part[11] ro        :0

part[12] name      :vbmeta_a
part[12] classname :DISK
part[12] addrlo    :0x798400
part[12] lenlo     :0x100
part[12] user_type :32768
part[12] keydata   :0
part[12] ro        :0

part[13] name      :vbmeta_b
part[13] classname :DISK
part[13] addrlo    :0x798500
part[13] lenlo     :0x100
part[13] user_type :32768
part[13] keydata   :0
part[13] ro        :0

part[14] name      :vbmeta_system_a
part[14] classname :DISK
part[14] addrlo    :0x798600
part[14] lenlo     :0x80
part[14] user_type :32768
part[14] keydata   :0
part[14] ro        :0

part[15] name      :vbmeta_system_b
part[15] classname :DISK
part[15] addrlo    :0x798680
part[15] lenlo     :0x80
part[15] user_type :32768
part[15] keydata   :0
part[15] ro        :0

part[16] name      :vbmeta_vendor_a
part[16] classname :DISK
part[16] addrlo    :0x798700
part[16] lenlo     :0x80
part[16] user_type :32768
part[16] keydata   :0
part[16] ro        :0

part[17] name      :vbmeta_vendor_b
part[17] classname :DISK
part[17] addrlo    :0x798780
part[17] lenlo     :0x80
part[17] user_type :32768
part[17] keydata   :0
part[17] ro        :0

part[18] name      :frp
part[18] classname :DISK
part[18] addrlo    :0x798800
part[18] lenlo     :0x400
part[18] user_type :32768
part[18] keydata   :32768
part[18] ro        :0

part[19] name      :empty
part[19] classname :DISK
part[19] addrlo    :0x798c00
part[19] lenlo     :0x7800
part[19] user_type :32768
part[19] keydata   :0
part[19] ro        :0

part[20] name      :metadata
part[20] classname :DISK
part[20] addrlo    :0x7a0400
part[20] lenlo     :0x8000
part[20] user_type :32768
part[20] keydata   :0
part[20] ro        :0

part[21] name      :treadahead
part[21] classname :DISK
part[21] addrlo    :0x7a8400
part[21] lenlo     :0x30000
part[21] user_type :32768
part[21] keydata   :0
part[21] ro        :0

part[22] name      :private
part[22] classname :DISK
part[22] addrlo    :0x7d8400
part[22] lenlo     :0x8000
part[22] user_type :32768
part[22] keydata   :0
part[22] ro        :0

part[23] name      :dtbo_a
part[23] classname :DISK
part[23] addrlo    :0x7e0400
part[23] lenlo     :0x1000
part[23] user_type :32768
part[23] keydata   :0
part[23] ro        :0

part[24] name      :dtbo_b
part[24] classname :DISK
part[24] addrlo    :0x7e1400
part[24] lenlo     :0x1000
part[24] user_type :32768
part[24] keydata   :0
part[24] ro        :0

part[25] name      :media_data
part[25] classname :DISK
part[25] addrlo    :0x7e2400
part[25] lenlo     :0x8000
part[25] user_type :32768
part[25] keydata   :0
part[25] ro        :0

part[26] name      :Reserve0
part[26] classname :DISK
part[26] addrlo    :0x7ea400
part[26] lenlo     :0x20000
part[26] user_type :32768
part[26] keydata   :0
part[26] ro        :0

part[27] name      :pstore
part[27] classname :DISK
part[27] addrlo    :0x80a400
part[27] lenlo     :0x10000
part[27] user_type :32768
part[27] keydata   :0
part[27] ro        :0

part[28] name      :UDISK
part[28] classname :DISK
part[28] addrlo    :0x81a400
part[28] lenlo     :0x0
part[28] user_type :33024
part[28] keydata   :0
part[28] ro        :0

[24.598]erase all part start
need erase flash: 18
[24.603][mmc]: erase from: 0, to: 61194239, cnt: 61194240, erase_group: 1024
[25.101][mmc]: sunxi_mmc_do_send_cmd_common: cmd 38 wait rsp busy 0x1e9 ms
[25.107]read item0 copy0
[25.117]Item0 (Map) magic is bad
[25.119]the secure storage item0 copy0 magic is bad
[25.131]Item0 (Map) magic is bad
[25.134]the secure storage item0 copy1 magic is bad
[25.138]Item0 (Map) magic is bad
[25.141]the secure storage map is empty
[25.159]erase secure storage: 0 ok
SUNXI_EFEX_MBR_TAG
mbr size = 0x10000
write primary GPT success
write Backup GPT success
[25.173]update partition map
FEX_CMD_fes_verify_status
FEX_CMD_fes_verify last err=0
******Has init
FEX_CMD_fes_verify_value, start 0x8000, size high 0x0:low 0x111d400
FEX_CMD_fes_verify_value 0xa14dbd74
FEX_CMD_fes_verify_value, start 0x28000, size high 0x0:low 0x20000
FEX_CMD_fes_verify_value 0xf00b1936
FEX_CMD_fes_verify_value, start 0x28400, size high 0x0:low 0x4000000
FEX_CMD_fes_verify_value 0x2d9ccd73
FEX_CMD_fes_verify_value, start 0x68400, size high 0x0:low 0x2000000
FEX_CMD_fes_verify_value 0x7435dd4a
FEX_CMD_fes_verify_value, start 0x88400, size high 0x0:low 0x800000
FEX_CMD_fes_verify_value 0xbad6702e
FEX_CMD_fes_verify_value, start 0x790400, size high 0x0:low 0x1000000
FEX_CMD_fes_verify_value 0xb961f417
FEX_CMD_fes_verify_value, start 0x798400, size high 0x0:low 0x2000
FEX_CMD_fes_verify_value 0x81ff878d
FEX_CMD_fes_verify_value, start 0x798600, size high 0x0:low 0x1000
FEX_CMD_fes_verify_value 0xd3178e38
FEX_CMD_fes_verify_value, start 0x798700, size high 0x0:low 0x1000
FEX_CMD_fes_verify_value 0xccfd9b0c
FEX_CMD_fes_verify_value, start 0x7e0400, size high 0x0:low 0x200000
FEX_CMD_fes_verify_value 0x9d9c6d85
FEX_CMD_fes_verify_value, start 0x7ea400, size high 0x0:low 0x1000000
FEX_CMD_fes_verify_value 0x0
bootfile_mode=4
SUNXI_EFEX_BOOT1_TAG
boot1 size = 0x13c000, max size = 0x400000
uboot size = 0x13c000
storage type = 2
FEX_CMD_fes_verify_status
FEX_CMD_fes_verify last err=0
bootfile_mode=4
SUNXI_EFEX_BOOT0_TAG
boot0 size = 0x3c000
[68.943][mmc]: write mmc 2 info ok
storage type = 2
FEX_CMD_fes_verify_status
FEX_CMD_fes_verify last err=0
sunxi_efex_next_action=2
exit usb
next work 2
SUNXI_UPDATE_NEXT_ACTION_REBOOT▒......


[176]HELLO! BOOT0 is starting!
[179]BOOT0 commit : {cfda5fbe}
[188]volume key pressed!
[190][mmc]: mmc driver ver 2024-03-20 10:36
[200][mmc]: Wrong media type 0x0, but host sdc2, try mmc first
[206][mmc]: ***Try MMC card 2***
[228][mmc]: RMCA OK!
[235][mmc]: MMC 5.1
[237][mmc]: HSSDR52/SDR25 8 bit
[240][mmc]: 50000000 Hz
[242][mmc]: 29880 MB
[244][mmc]: ***SD/MMC 2 init OK!!!***
[249]DRAM BOOT DRIVE INFO: V0.599
[254]DRAM_VCC set to 560 mv
[257]DRAM CLK =1800 MHZ
[259]DRAM Type =9 (8:LPDDR4,9:LPDDR5)
[386]Training result is = 7
[388]DRAM Pstate 0 training, frequency is 1800 Mhz
[397]Actual DRAM SIZE =6144 M
[400]DRAM SIZE =6144 MBytes, para1 = a10a, para2 = 18001001, dram_tpr13 = 10061
[414]DRAM simple test OK.
[456]error: dtb not found for scp
[461]tunning data addr:0x4a0003e8
[464]Jump to ATF: monitor_base = 0x48000000, uboot_base = 0x4a000000, optee_base = 0x0
NOTICE:  BL31: OP-TEE 32bit detected
NOTICE:  BL31: U-BOOT 32bit detected
NOTICE:  BL31: v2.5(debug):eec78cd3c
NOTICE:  BL31: Built : 14:02:13, Oct 29 2024
NOTICE:  BL31: No DTB found.
ERROR:   Error initializing runtime service opteed_fast


U-Boot 2018.07 (Mar 31 2025 - 06:54:43 +0000) Allwinner Technology

[00.511]CPU:   Allwinner Family
[00.514]Model: sun60iw2
I2C:   ready
[00.574]DRAM:  6 GiB
[00.578]Relocation Offset is: 75dac000
[00.634]secure enable bit: 0
[00.637]PMU: AXP8191
[00.639]PMU: AXP8191 VER_A
FDT ERROR:fdt_get_regulator_name:get property handle twi-supply error:FDT_ERR_INTERNAL
[00.651][AXP8191] onoff status: 0x50 = 0x0, 0x51 = 0x0
[00.656][AXP8191] charge status: 0x4 = 0x0
[00.660]CPU=1014 MHz,PLL6=1200 Mhz,AHB=200 Mhz, APB1=24Mhz  MBus=600Mhz
[00.666]gic: sec monitor mode
[00.671]flash init start
[00.673]workmode = 0,storage type = 2
[00.677][mmc]: mmc driver ver uboot2018:2024-10-18 9:01:00
[00.685][mmc]: SUNXI SDMMC Controller Version:0x50610
[00.695][mmc]: 200 MHz...
[00.697][mmc]: sample: 23 - 108(ps)
[00.700][mmc]: ds: 23 - 108(ps)
[00.718][mmc]: Best spd md: 4-HS400, freq: 5-200000000, Bus width: 8
[00.724]sunxi flash init ok
[00.740]Loading Environment from SUNXI_FLASH... [00.751]the secure storage item0 copy0 magic is bad
[00.763]the secure storage item0 copy1 magic is bad
erase secure storage failed
OK
[00.827]NOT support bridge yet
[00.829]Warn: no find panel or bridge
[00.837]failed to request regulator(avdd-supply): -22
[00.842]failed to request regulator_vol(avdd-output-voltage): -22
[00.848]failed to request regulator(avee-supply): -22
[00.852]failed to request regulator_vol(avee-output-voltage): -22
** Unrecognized filesystem type **
[00.868]get file(disp_rsl.fex) size from Reserve0 error
dsi0@5506000:  detailed mode clock 50000 kHz, flags[0]
    H: 1024 1174 1194 1344
    V: 0600 0608 0611 0635
bus_format: 0
[00.884]hdmi@5520000 disconnected
[00.887]bad framebuffer width 0
[00.904]m:6, m0:1, m1:6, m2:3, m3:12
[01.816]failed to display uboot logo for disp 64
[01.827]the secure storage item0 copy0 magic is bad
[01.838]the secure storage item0 copy1 magic is bad
[01.843]usb burn from boot
delay time 0
[01.849]usb prepare ok
[02.057]usb sof ok
[02.059]usb probe ok
[02.061]usb setup ok
set address 0x10
set address 0x10 ok
set address 0x11
set address 0x11 ok
[02.467]do_burn_from_boot usb : have no handshake
skip update boot_param
List file under ULI/factory
** Unrecognized filesystem type **
[02.481]update part info
[02.485]battery temp is -1
[02.502]update bootcmd
[02.570]change working_fdt 0xbbd5be30 to 0xbbd2be30
ret 0
[02.690]no battery, disabled battery functons
[02.696]update dts
Hit any key to stop autoboot:  0
Android's image name: arm64
kernel  addr 0x40080000 0x4289a000 exceed boot_a scope
boot_a  addr 0x4007f000 0x4289a000
ERROR: reserving fdt memory region failed (addr=bbe31000 size=258000)
[03.033]Starting kernel ...

[03.036]total: 3036 ms

[03.038][mmc]: mmc exit start
[03.055][mmc]: mmc 2 exit ok
NOTICE:  [SCP] :wait arisc ready....
NOTICE:  [SCP] :arisc version: [c82a3c8d0b638500aa1ffe037d00fa24cf20a903-dirty]
NOTICE:  [SCP] :arisc startup ready
NOTICE:  [SCP] :arisc startup notify message feedback
NOTICE:  [SCP] :sunxi-arisc driver is starting
NOTICE:  BL3-1: Next image address = 0x40080000
NOTICE:  BL3-1: Next image spsr = 0x3c5
[    0.000000][    T0] Booting Linux on physical CPU 0x0000000000 [0x412fd050]
[    0.000000][    T0] Linux version 5.15.119-gc82a3c8d0b63-dirty (xtx@ubuntu-201) (Android (8490178, based on r450784d) clang version 14.0.6 (https://android.googlesource.com/toolchain/llvm-project 4c603efb0cca074e9238af8b4106c30add4418f6), LLD 14.0.6) #13 SMP PREEMPT Mon Mar 31 06:56:51 UTC 2025
[    0.000000][    T0] Machine model: sun60iw2
[    0.000000][    T0] Stack Depot is disabled
[    0.000000][    T0] KVM is not available. Ignoring kvm-arm.mode
[    0.000000][    T0] earlycon: uart8250 at MMIO32 0x0000000002500000 (options '')
[    0.000000][    T0] printk: bootconsole [uart8250] enabled
[    0.000000][    T0] efi: UEFI not found.
[    0.000000][    T0] [Firmware Bug]: Kernel image misaligned at boot, please fix your bootloader!
[    0.000000][    T0] OF: reserved mem: 0x0000000048000000..0x0000000048ffffff (16384 KiB) map non-reusable bl31
[    0.000000][    T0] Zone ranges:
[    0.000000][    T0]   DMA32    [mem 0x0000000040000000-0x00000000ffffffff]
[    0.000000][    T0]   Normal   [mem 0x0000000100000000-0x00000001bfffffff]
[    0.000000][    T0] Movable zone start for each node
[    0.000000][    T0] Early memory node ranges
[    0.000000][    T0]   node   0: [mem 0x0000000040000000-0x00000001bfffffff]
[    0.000000][    T0] Initmem setup node 0 [mem 0x0000000040000000-0x00000001bfffffff]
[    0.000000][    T0] cma: Reserved 8 MiB at 0x00000000ff800000
[    0.000000][    T0] psci: probing for conduit method from DT.
[    0.000000][    T0] psci: PSCIv1.1 detected in firmware.
[    0.000000][    T0] psci: Using standard PSCI v0.2 function IDs
[    0.000000][    T0] psci: MIGRATE_INFO_TYPE not supported.
[    0.000000][    T0] psci: SMC Calling Convention v1.2
[    0.000000][    T0] Load bootconfig: 810 bytes 50 nodes
[    0.000000][    T0] percpu: Embedded 29 pages/cpu s81752 r8192 d28840 u118784
[    0.000000][    T0] pcpu-alloc: s81752 r8192 d28840 u118784 alloc=29*4096
[    0.000000][    T0] pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3 [0] 4 [0] 5 [0] 6 [0] 7
[    0.000000][    T0] Detected VIPT I-cache on CPU0
[    0.000000][    T0] CPU features: SYS_ID_AA64MMFR1_EL1[11:8]: forced to 0
[    0.000000][    T0] CPU features: detected: GIC system register CPU interface
[    0.000000][    T0] CPU features: kernel page table isolation forced ON by KASLR
[    0.000000][    T0] CPU features: detected: Kernel page table isolation (KPTI)
[    0.000000][    T0] CPU features: detected: Qualcomm erratum 1009, or ARM erratum 1286807, 2441009
[    0.000000][    T0] CPU features: detected: ARM errata 1165522, 1319367, or 1530923
[    0.000000][    T0] Built 1 zonelists, mobility grouping on.  Total pages: 1548288
[    0.000000][    T0] Kernel command line: stack_depot_disable=on kasan.stacktrace=off kvm-arm.mode=protected cgroup_disable=pressure rcutree.rcu_idle_gp_delay=1 cpufreq.default_governor=performance earlycon=uart8250,mmio32,0x02500000 clk_ignore_unused= initcall_debug=0 console=ttyAS0,115200 loglevel=8 root=/dev/mmcblk0p4 init=/init init_rc= cma=8M slub_min_objects=8 snum=7c00161172014741e8d mac_addr= wifi_mac= bt_mac= specialstr= gpt=1 sn2= deferred_probe_timeout=10 boot_type=2 gpt=1 uboot_message=2018.07(03/31/2025-06:54:43) bootreason=button uboot_backup=ubootA  loop.max_part=4 mmcblk.perdev_minors=16 firmware_class.path=/vendor/etc/firmware bootconfig buildvariant=userdebug
[    0.000000][    T0] cgroup: Disabling pressure control group feature
[    0.000000][    T0] Unknown kernel command line parameters "init_rc= snum=7c00161172014741e8d mac_addr= wifi_mac= bt_mac= specialstr= sn2= boot_type=2 uboot_message=2018.07(03/31/2025-06:54:43) bootreason=button uboot_backup=ubootA buildvariant=userdebug", will be passed to user space.
[    0.000000][    T0] Dentry cache hash table entries: 1048576 (order: 11, 8388608 bytes, linear)
[    0.000000][    T0] Inode-cache hash table entries: 524288 (order: 10, 4194304 bytes, linear)
[    0.000000][    T0] mem auto-init: stack:all(zero), heap alloc:on, heap free:off
[    0.000000][    T0] software IO TLB: mapped [mem 0x00000000fb800000-0x00000000ff800000] (64MB)
[    0.000000][    T0] Memory: 6008524K/6291456K available (18432K kernel code, 2214K rwdata, 18820K rodata, 1472K init, 614K bss, 274740K reserved, 8192K cma-reserved)
[    0.000000][    T0] SLUB: HWalign=64, Order=0-3, MinObjects=8, CPUs=8, Nodes=1
[    0.000000][    T0] trace event string verifier disabled
[    0.000000][    T0] rcu: Preemptible hierarchical RCU implementation.
[    0.000000][    T0] rcu:     RCU event tracing is enabled.
[    0.000000][    T0] rcu:     RCU dyntick-idle grace-period acceleration is enabled.
[    0.000000][    T0] rcu:     RCU restricting CPUs from NR_CPUS=32 to nr_cpu_ids=8.
[    0.000000][    T0] rcu:     RCU priority boosting: priority 1 delay 500 ms.
[    0.000000][    T0]  Trampoline variant of Tasks RCU enabled.
[    0.000000][    T0]  Tracing variant of Tasks RCU enabled.
[    0.000000][    T0] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[    0.000000][    T0] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=8
[    0.000000][    T0] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000][    T0] GICv3: 256 SPIs implemented
[    0.000000][    T0] GICv3: 0 Extended SPIs implemented
[    0.000000][    T0] GICv3: Distributor has no Range Selector support
[    0.000000][    T0] Root IRQ handler: gic_handle_irq.10d7cf410c142aff6d31b6303c3f9f87.cfi_jt
[    0.000000][    T0] GICv3: 16 PPIs implemented
[    0.000000][    T0] GICv3: CPU0: found redistributor 0 region 0:0x0000000003460000
[    0.000000][    T0] ITS: No ITS available, not enabling LPIs
[    0.000000][    T0] rcu:     Offload RCU callbacks from CPUs: (none).
[    0.000000][    T0] kfence: initialized - using 524288 bytes for 63 objects at 0x(____ptrval____)-0x(____ptrval____)
[    0.000000][    T0] arch_timer: cp15 timer(s) running at 24.00MHz (virt).
[    0.000000][    T0] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns
[    0.000001][    T0] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 4398046511097ns
[    0.011206][    T0] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=96000)
[    0.023251][    T0] pid_max: default: 32768 minimum: 301
[    0.029401][    T0] LSM: Security Framework initializing
[    0.035321][    T0] SELinux:  Initializing.
[    0.040291][    T0] Mount-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
[    0.049394][    T0] Mountpoint-cache hash table entries: 16384 (order: 5, 131072 bytes, linear)
[    0.062026][    T1] rcu: Hierarchical SRCU implementation.
[    0.069177][    T1] dyndbg: Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build
[    0.079182][    T1] EFI services will not be available.
[    0.085811][    T1] smp: Bringing up secondary CPUs ...
[    0.092555][    T0] Detected VIPT I-cache on CPU1
[    0.092593][    T0] GICv3: CPU1: found redistributor 100 region 0:0x0000000003480000
[    0.092646][    T0] CPU1: Booted secondary processor 0x0000000100 [0x412fd050]
[    0.093765][    T0] Detected VIPT I-cache on CPU2
[    0.093797][    T0] GICv3: CPU2: found redistributor 200 region 0:0x00000000034a0000
[    0.093835][    T0] CPU2: Booted secondary processor 0x0000000200 [0x412fd050]
[    0.094846][    T0] Detected VIPT I-cache on CPU3
[    0.094873][    T0] GICv3: CPU3: found redistributor 300 region 0:0x00000000034c0000
[    0.094904][    T0] CPU3: Booted secondary processor 0x0000000300 [0x412fd050]
[    0.095934][    T0] Detected VIPT I-cache on CPU4
[    0.095962][    T0] GICv3: CPU4: found redistributor 400 region 0:0x00000000034e0000
[    0.095991][    T0] CPU4: Booted secondary processor 0x0000000400 [0x412fd050]
[    0.097035][    T0] Detected VIPT I-cache on CPU5
[    0.097063][    T0] GICv3: CPU5: found redistributor 500 region 0:0x0000000003500000
[    0.097091][    T0] CPU5: Booted secondary processor 0x0000000500 [0x412fd050]
[    0.098117][    T0] CPU features: detected: Spectre-v4
[    0.098122][    T0] CPU features: detected: Spectre-BHB
[    0.098126][    T0] Detected PIPT I-cache on CPU6
[    0.098142][    T0] GICv3: CPU6: found redistributor 600 region 0:0x0000000003520000
[    0.098160][    T0] CPU6: Booted secondary processor 0x0000000600 [0x414fd0b1]
[    0.099144][    T0] Detected PIPT I-cache on CPU7
[    0.099164][    T0] GICv3: CPU7: found redistributor 700 region 0:0x0000000003540000
[    0.099183][    T0] CPU7: Booted secondary processor 0x0000000700 [0x414fd0b1]
[    0.099267][    T1] smp: Brought up 1 node, 8 CPUs
[    0.266949][    T1] SMP: Total of 8 processors activated.
[    0.272877][    T1] CPU features: detected: 32-bit EL0 Support
[    0.279280][    T1] CPU features: detected: Data cache clean to the PoU not required for I/D coherence
[    0.289499][    T1] CPU features: detected: Common not Private translations
[    0.297149][    T1] CPU features: detected: CRC32 instructions
[    0.303563][    T1] CPU features: detected: RCpc load-acquire (LDAPR)
[    0.310640][    T1] CPU features: detected: LSE atomic instructions
[    0.317523][    T1] CPU features: detected: Privileged Access Never
[    0.324403][    T1] CPU features: detected: RAS Extension Support
[    0.331093][    T1] CPU features: detected: Speculative Store Bypassing Safe (SSBS)
[    0.375725][    T1] CPU: All CPU(s) started at EL1
[    0.381083][   T19] alternatives: patching kernel code
[    0.425590][    T1] Registered cp15_barrier emulation handler
[    0.431914][    T1] Registered setend emulation handler
[    0.437644][    T1] KASLR disabled due to lack of seed
[    0.443388][    T1] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.454558][    T1] futex hash table entries: 2048 (order: 5, 131072 bytes, linear)
[    0.463257][    T1] pinctrl core: initialized pinctrl subsystem
[    0.470425][    T1] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.480071][    T1] DMA: preallocated 1024 KiB GFP_KERNEL pool for atomic allocations
[    0.489149][    T1] DMA: preallocated 1024 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations
[    0.498686][    T1] audit: initializing netlink subsys (disabled)
[    0.505553][   T80] audit: type=2000 audit(0.328:1): state=initialized audit_enabled=0 res=1
[    0.505817][    T1] thermal_sys: Registered thermal governor 'step_wise'
[    0.514825][    T1] thermal_sys: Registered thermal governor 'user_space'
[    0.522174][    T1] thermal_sys: Registered thermal governor 'power_allocator'
[    0.530251][    T1] cpuidle: using governor menu
[    0.543389][    T1] hw-breakpoint: found 6 breakpoint and 4 watchpoint registers.
[    0.551779][    T1] ASID allocator initialised with 32768 entries
[    0.558547][    T1] Serial: AMBA PL011 UART driver
[    0.578553][    T1] platform 5501000.tcon0: Fixing up cyclic dependency with 5000000.de
[    0.587564][    T1] platform 5506000.dsi0: Fixing up cyclic dependency with 5501000.tcon0
[    0.596791][    T1] platform 5730000.tcon3: Fixing up cyclic dependency with 5000000.de
[    0.605712][    T1] platform 5731000.tcon4: Fixing up cyclic dependency with 5000000.de
[    0.614648][    T1] platform 5520000.hdmi: Fixing up cyclic dependency with 5730000.tcon3
[    0.631804][    T1] iommu: Default domain type: Translated
[    0.637948][    T1] iommu: DMA domain TLB invalidation policy: strict mode
[    0.645969][    T1] SCSI subsystem initialized
[    0.650927][    T1] usbcore: registered new interface driver usbfs
[    0.657722][    T1] usbcore: registered new interface driver hub
[    0.664321][    T1] usbcore: registered new device driver usb
[    0.670697][    T1] mc: Linux media interface: v0.10
[    0.676093][    T1] videodev: Linux video capture interface: v2.00
[    0.682916][    T1] EDAC MC: Ver: 3.0.0
[    0.687831][    T1] Advanced Linux Sound Architecture Driver Initialized.
[    0.695569][    T1] Bluetooth: Core ver 2.22
[    0.700127][    T1] NET: Registered PF_BLUETOOTH protocol family
[    0.706131][    T1] Bluetooth: HCI device and connection manager initialized
[    0.713862][    T1] Bluetooth: HCI socket layer initialized
[    0.719988][    T1] Bluetooth: L2CAP socket layer initialized
[    0.726239][    T1] Bluetooth: SCO socket layer initialized
[    0.732435][    T1] nfc: nfc_init: NFC Core ver 0.1
[    0.737798][    T1] NET: Registered PF_NFC protocol family
[    0.744146][    T1] clocksource: Switched to clocksource arch_sys_counter
[    0.773471][    T1] VFS: Disk quotas dquot_6.6.0
[    0.778592][    T1] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.787374][    T1] NET: Registered PF_INET protocol family
[    0.793795][    T1] IP idents hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.805406][    T1] tcp_listen_portaddr_hash hash table entries: 4096 (order: 4, 65536 bytes, linear)
[    0.815696][    T1] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.824962][    T1] TCP established hash table entries: 65536 (order: 7, 524288 bytes, linear)
[    0.834814][    T1] TCP bind hash table entries: 65536 (order: 8, 1048576 bytes, linear)
[    0.844505][    T1] TCP: Hash tables configured (established 65536 bind 65536)
[    0.852583][    T1] UDP hash table entries: 4096 (order: 5, 131072 bytes, linear)
[    0.860990][    T1] UDP-Lite hash table entries: 4096 (order: 5, 131072 bytes, linear)
[    0.869178][    T1] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.876174][    T1] NET: Registered PF_XDP protocol family
[    0.882197][    T1] PCI: CLS 0 bytes, default 64
[    0.887640][    T8] Trying to unpack rootfs image as initramfs...
[    0.894583][    T1] hw perfevents: enabled with armv8_pmuv3 PMU driver, 7 counters available
[    0.904250][    T1] kvm [1]: HYP mode not available
[    0.910328][    T1] Initialise system trusted keyrings
[    0.916089][    T1] workingset: timestamp_bits=46 max_order=21 bucket_order=0
[    0.928051][    T1] fuse: init (API version 7.36)
[    0.960477][    T1] Key type asymmetric registered
[    0.965693][    T1] Asymmetric key parser 'x509' registered
[    0.971889][    T1] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 241)
[    0.980720][    T1] io scheduler mq-deadline registered
[    0.986368][    T1] io scheduler kyber registered
[    0.991598][    T1] io scheduler bfq registered
[    0.999925][   T22] cacheinfo: Unable to detect cache hierarchy for CPU 0
[    1.010986][    T1] brd: module loaded
[    1.022092][    T1] loop: module loaded
[    1.028304][    T1] wireguard: WireGuard 1.0.0 loaded. See www.wireguard.com for information.
[    1.037626][    T1] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
[    1.040110][    T8] Freeing initrd memory: 22396K
[    1.049267][    T1] MACsec IEEE 802.1AE
[    1.058637][    T1] tun: Universal TUN/TAP device driver, 1.6
[    1.064988][    T1] CAN device driver interface
[    1.069955][    T1] PPP generic driver version 2.4.2
[    1.075436][    T1] PPP BSD Compression module registered
[    1.081356][    T1] PPP Deflate Compression module registered
[    1.087669][    T1] PPP MPPE Compression module registered
[    1.093684][    T1] NET: Registered PF_PPPOX protocol family
[    1.099732][    T1] PPTP driver version 0.8.5
[    1.104757][    T1] usbcore: registered new interface driver rtl8150
[    1.111749][    T1] usbcore: registered new interface driver r8152
[    1.118544][    T1] usbcore: registered new interface driver asix
[    1.124655][    T1] usbcore: registered new interface driver ax88179_178a
[    1.132110][    T1] usbcore: registered new interface driver cdc_ether
[    1.139278][    T1] usbcore: registered new interface driver cdc_eem
[    1.146267][    T1] usbcore: registered new interface driver cdc_ncm
[    1.152958][    T1] usbcore: registered new interface driver aqc111
[    1.159839][    T1] usbcore: registered new interface driver r8153_ecm
[    1.167381][    T1] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    1.174594][    T1] ehci-pci: EHCI PCI platform driver
[    1.180240][    T1] ehci-platform: EHCI generic platform driver
[    1.187024][    T1] usbcore: registered new interface driver cdc_acm
[    1.193967][    T1] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[    1.203530][    T1] usbcore: registered new interface driver uas
[    1.210138][    T1] usbcore: registered new interface driver usb-storage
[    1.217634][    T1] usbcore: registered new interface driver xpad
[    1.224279][    T1] usbcore: registered new interface driver uvcvideo
[    1.231343][    T1] gspca_main: v2.14.0 registered
[    1.236769][    T1] device-mapper: uevent: version 1.0.3
[    1.242710][    T1] device-mapper: ioctl: 4.45.0-ioctl (2021-03-22) initialised: dm-devel@redhat.com
[    1.252697][    T1] Bluetooth: HCI UART driver ver 2.3
[    1.258198][    T1] Bluetooth: HCI UART protocol H4 registered
[    1.264602][    T1] Bluetooth: HCI UART protocol LL registered
[    1.271034][    T1] Bluetooth: HCI UART protocol Broadcom registered
[    1.278008][    T1] Bluetooth: HCI UART protocol QCA registered
[    1.285541][    T1] mmcblk: using 16 minors per device
[    1.291191][    T1] sdhci: Secure Digital Host Controller Interface driver
[    1.298729][    T1] sdhci: Copyright(c) Pierre Ossman
[    1.304265][    T1] sdhci-pltfm: SDHCI platform and OF driver helper
[    1.311390][    T1] SMCCC: SOC_ID: ARCH_SOC_ID not implemented, skipping ....
[    1.319243][    T1] hid: raw HID events driver (C) Jiri Kosina
[    1.326126][    T1] usbcore: registered new interface driver usbhid
[    1.333001][    T1] usbhid: USB HID core driver
[    1.338099][    T1] ashmem: initialized
[    1.342479][    T1] gnss: GNSS driver registered with major 509
[    1.349344][    T1] usbcore: registered new interface driver snd-usb-audio
[    1.357177][    T1] GACT probability NOT on
[    1.361548][    T1] Mirror/redirect action on
[    1.366332][    T1] netem: version 1.3
[    1.370334][    T1] u32 classifier
[    1.374060][    T1]     input device check on
[    1.378836][    T1]     Actions configured
[    1.385137][    T1] xt_time: kernel timezone is -0000
[    1.390815][    T1] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    1.397847][    T1] gre: GRE over IPv4 demultiplexor driver
[    1.403961][    T1] ip_gre: GRE over IPv4 tunneling driver
[    1.410455][    T1] IPv4 over IPsec tunneling driver
[    1.415866][    T1] Initializing XFRM netlink socket
[    1.421344][    T1] IPsec XFRM device driver
[    1.426317][    T1] NET: Registered PF_INET6 protocol family
[    1.433706][    T1] Segment Routing with IPv6
[    1.438519][    T1] In-situ OAM (IOAM) with IPv6
[    1.443665][    T1] mip6: Mobile IPv6
[    1.448024][    T1] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[    1.455708][    T1] ip6_gre: GRE over IPv6 tunneling driver
[    1.462024][    T1] NET: Registered PF_PACKET protocol family
[    1.468352][    T1] NET: Registered PF_KEY protocol family
[    1.474434][    T1] can: controller area network core
[    1.480042][    T1] NET: Registered PF_CAN protocol family
[    1.486074][    T1] can: raw protocol
[    1.490097][    T1] can: broadcast manager protocol
[    1.495448][    T1] can: netlink gateway - max_hops=1
[    1.501195][    T1] Bluetooth: RFCOMM TTY layer initialized
[    1.507323][    T1] Bluetooth: RFCOMM socket layer initialized
[    1.513734][    T1] Bluetooth: RFCOMM ver 1.11
[    1.518610][    T1] Bluetooth: HIDP (Human Interface Emulation) ver 1.2
[    1.525214][    T1] Bluetooth: HIDP socket layer initialized
[    1.531430][    T1] l2tp_core: L2TP core driver, V2.0
[    1.536974][    T1] l2tp_ppp: PPPoL2TP kernel driver, V2.0
[    1.542987][    T1] 8021q: 802.1Q VLAN Support v1.8
[    1.548348][    T1] tipc: Activated (version 2.0.0)
[    1.553793][    T1] NET: Registered PF_TIPC protocol family
[    1.559972][    T1] tipc: Started in single node mode
[    1.565627][    T1] NET: Registered PF_IEEE802154 protocol family
[    1.572443][    T1] NET: Registered PF_VSOCK protocol family
[    1.579433][    T1] registered taskstats version 1
[    1.584703][    T1] Loading compiled-in X.509 certificates
[    1.591081][  T108] cryptomgr_probe (108) used greatest stack depth: 14016 bytes left
[    1.592666][    T1] Loaded X.509 cert 'Build time autogenerated kernel key: ce4e882886e7b069224779dcae2c567271036ca1'
[    1.612155][    T1] page_owner is disabled
[    1.616371][    T1] Key type .fscrypt registered
[    1.621437][    T1] Key type fscrypt-provisioning registered
[    1.629066][    T1] clk: Not disabling unused clocks
[    1.634535][    T1] ALSA device list:
[    1.638551][    T1]   No soundcards found.
[    1.643107][    T1] Warning: unable to open an initial console.
[    1.650156][    T1] Freeing unused kernel memory: 1472K
[    1.660374][    T1] Run /init as init process
[    1.665171][    T1]   with arguments:
[    1.668931][    T1]     /init
[    1.672182][    T1]   with environment:
[    1.676383][    T1]     HOME=/
[    1.679645][    T1]     TERM=linux
[    1.683370][    T1]     init_rc=
[    1.686600][    T1]     snum=7c00161172014741e8d
[    1.691633][    T1]     mac_addr=
[    1.695262][    T1]     wifi_mac=
[    1.698890][    T1]     bt_mac=
[    1.702327][    T1]     specialstr=
[    1.706146][    T1]     sn2=
[    1.709280][    T1]     boot_type=2
[    1.713104][    T1]     uboot_message=2018.07(03/31/2025-06:54:43)
[    1.719879][    T1]     bootreason=button
[    1.724271][    T1]     uboot_backup=ubootA
[    1.728618][    T1]     buildvariant=userdebug
[    1.735151][    T1] init: init first stage started!
[    1.743053][  T109] init: Loading module /lib/modules/zsmalloc.ko with args ''
[    1.743112][  T112] init: Loading module /lib/modules/twi-sunxi.ko with args ''
[    1.743312][  T111] init: Loading module /lib/modules/timer-sun50i.ko with args ''
[    1.743347][  T113] init: Loading module /lib/modules/tee.ko with args ''
[    1.743400][  T110] init: Loading module /lib/modules/sunxi-uart-ng.ko with args ''
[    1.743545][  T114] init: Loading module /lib/modules/sunxi-smc.ko with args ''
[    1.743578][  T111] timer_sun50i: module verification failed: signature and/or required key missing - tainting kernel
[    1.743664][  T115] init: Loading module /lib/modules/sunxi-power-notifier.ko with args ''
[    1.744255][  T116] init: Loading module /lib/modules/sunxi_pd_test.ko with args ''
[    1.816859][  T114] init: Loaded kernel module /lib/modules/sunxi-smc.ko
[    1.831229][  T116] [drm] [DSI-PANEL] panel_dsi_init start
[    1.837444][  T116] [drm] [DSI-PANEL] dsi driver regsiter finsh
[    1.845139][  T113] i2c_dev: i2c /dev entries driver
[    1.845757][  T112] BOOTEVENT:      1845.756325: ON
[    1.846424][  T116] init (116) used greatest stack depth: 12480 bytes left
[    1.852407][  T115] init (115) used greatest stack depth: 12368 bytes left
[    1.864155][  T125] sunxi:ccu-ng:[INFO]: sunxi rtc-ccu version: 0.5.3
[    1.865025][  T124] optee: probing for conduit method.
[    1.865039][  T124] optee: api uid mismatch
[    1.865042][  T124] optee: probe of firmware:optee failed with error -22
[    1.865713][  T118] zram: Added device: zram0
[    1.879489][  T119] AW BSP version: UNKNOWN, 2025-04-28 11:18:30
[    1.883900][  T125] AW BSP version: UNKNOWN, 2025-04-28 11:18:30
[    1.890517][  T119] sunxi:ccu-ng:[INFO]: r_ccu: sunxi ccu init OK
[    1.896699][  T125] sunxi:ccu-ng:[INFO]: rtc_ccu: sunxi ccu init OK
[    1.900534][  T119] sunxi:ccu-ng:[INFO]: sunxi ccu common driver version: 1.2.4
[    1.907682][  T125] init (125) used greatest stack depth: 11920 bytes left
[    1.911549][  T117] sunxi:ccu-ng:[INFO]: cpupll_ccu: sunxi ccu init OK
[    1.911556][  T117] sunxi:ccu-ng:[INFO]: sunxi pll_cpu driver version: 0.0.3
[    1.912364][  T117] sunxi:ccu-ng:[INFO]: ccu will stop clk in init process
[    1.913991][  T119] sunxi:ccu-ng:[INFO]: sunxi ccu driver version: 0.5.4
[    1.954266][  T117] sunxi:ccu-ng:[INFO]: ccu: sunxi ccu init OK
[    1.973165][  T129] [ADDR_MGT] addr_mgt_probe: module version: v1.0.12
[    1.973567][  T133] init (133) used greatest stack depth: 11376 bytes left
[    1.978579][  T117] sunxi:ccu-ng:[INFO]: sunxi ccu driver version: 1.0.13
[    1.986218][  T129] sunxi:sunxi_sidget_soc_ver_regs() +293: Failed to find "soc_bin" in dts.
[    1.993341][  T126] [drm] [TCON] sunxi_tcon_probe start
[    1.993476][  T117] sunxi:ccu_ddr:[ERR]: dram_clk:1800
[    1.993482][  T117] sunxi:ccu_ddr:[ERR]: dram_div:0x11080503
[    1.994428][  T117] sun55iw3-timer 3009000.timer: sun50i timer init:0xffffff0000000a
[    1.994434][  T117] clocksource: timer: mask: 0xffffffffffffff max_cycles: 0x1623fa770, max_idle_ns: 440795202238 ns
[    1.995080][  T117] sunxi:pwm-2527000.pwm:[INFO]: pwmchip probe success
[    1.995431][  T117] sunxi:pwm-2528000.pwm:[INFO]: pwmchip probe success
[    1.995800][  T117] sunxi:pwm-7023000.pwm:[INFO]: pwmchip probe success
[    1.996083][  T117] sunxi iommu: irq = 19
[    1.996115][  T117] sunxi iommu: irq = 20
[    1.997464][  T117] sun6i-dma 4601000.dma-controller: sunxi dma probed, driver version: 1.2.6
[    1.997853][  T117] pwm-backlight backlight1: supply power not found, using dummy regulator
[    1.998144][  T117] sunxi:pin:[INFO]: sunxi r-pinctrl version: 0.0.2
[    1.998458][    T8] sunxi:rtc:[INFO]:  Saving SoC boot-reason: OTHERS
[    1.999302][    T8] sunxi-rtc 7090000.rtc: registered as rtc0
[    1.999311][  T117] sunxi:pin-7025000.pinctrl:[INFO]: pinctrl withstand voltage config mode=auto_hard
[    1.999314][  T117] sunxi:pin:[INFO]: sunxi pinctrl core driver version: 1.4.8
[    1.999360][    T8] sunxi-rtc 7090000.rtc: setting system clock to 2025-05-29T13:49:17 UTC (1748526557)
[    1.999389][    T8] sunxi:rtc-7090000.rtc:[INFO]: sunxi rtc probed
[    1.999439][  T117] sunxi:pin:[INFO]: sunxi pinctrl version: 0.6.7
[    2.004331][  T129] [ADDR_MGT] addr_mgt_probe: success.
[    2.009919][  T126] [drm] [SUNXI-TCON] sunxi_tcon_of_get_id 0
[    2.016490][  T117] sunxi:pin-2000000.pinctrl:[INFO]: pinctrl withstand voltage config mode=auto_hard
[    2.021296][  T126] [drm] [TCON] sunxi_tcon_probe ret = 0
[    2.028203][  T117] sunxi:pin-2000000.pinctrl:[INFO]: Auto power withstand voltage configuration detected, automatically exit!
[    2.035827][  T126] [drm] [TCON] sunxi_tcon_probe start
[    2.046908][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: SD/MMC/SDIO Host Controller Driver(v5.58 2024-11-11 09:32)
[    2.054231][  T126] [drm] [SUNXI-TCON] sunxi_tcon_of_get_id 4
[    2.061554][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: ctl-spec-caps 428
[    2.068655][  T126] [drm] [TCON] sunxi_tcon_probe ret = 0
[    2.072742][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: No vmmc regulator found
[    2.077255][  T126] [drm] [TCON] sunxi_tcon_probe start
[    2.086349][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: No vqmmc regulator found
[    2.095132][  T126] [drm] [SUNXI-TCON] sunxi_tcon_of_get_id 5
[    2.102020][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: No vdmmc regulator found
[    2.109197][  T126] [drm] [TCON] sunxi_tcon_probe ret = 0
[    2.115354][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: No vd33sw regulator found
[    2.115357][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: No vd18sw regulator found
[    2.115358][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: No vq33sw regulator found
[    2.115360][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: No vq18sw regulator found
[    2.125724][  T126] [drm] sunxi_drm_platform_probe start
[    2.133387][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: manual set ocr
[    2.133400][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[WARN]: Cann't get uart0 pinstate,check if needed
[    2.143697][  T126] [drm] sunxi_drm_match_add start
[    2.150470][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[WARN]: Cann't get pin bias hs pinstate,check if needed
[    2.158003][  T126] [drm] sunxi_drm_match_add finish
[    2.163578][  T117] sunxi-mmc 4021000.sdmmc: sunxi:sunxi_mmc_hostexecute tuning in kernel, retune_period=3600
[    2.371929][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm UP vdd 21 width 1 timing LEGACY(SDR12) dt B
[    2.396156][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    2.420270][  T117] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: detmode:manually by software
[    2.421096][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 52, RTO !!
[    2.430877][  T117] NSI_PMU 2020000.nsi-controller: Get support-ecc failed
[    2.446364][  T117] [drm] [TCON_TOP]sunxi_tcon_top_probe start
[    2.446829][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 52, RTO !!
[    2.452951][  T117] [drm] [TCON_TOP]sunxi_tcon_top_probe start
[    2.467861][   T70] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    2.482102][  T117] sunxi-display-engine 5000000.de: Adding to iommu group 0
[    2.484817][   T70] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    2.490037][  T117] [drm] de use no display sys
[    2.505297][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 5, RTO !!
[    2.508511][  T117] sunxi-display-engine 5000000.de: register iommu fault callback for sunxi-drm, master=8
[    2.517719][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 5, RTO !!
[    2.526965][  T117] [drm] [PHY] sunxi_dsi_combophy_probe start
[    2.536423][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 5, RTO !!
[    2.542302][  T117] [drm] [PHY]sunxi_dsi_combophy_probe finish
[    2.551798][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 5, RTO !!
[    2.557752][  T117] [drm] [DSI] sunxi_drm_dsi_probe start
[    2.566328][   T70] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm OFF vdd 0 width 1 timing LEGACY(SDR12) dt B
[    2.572439][  T117] mipi-dsi 5506000.dsi0.0: Fixing up cyclic dependency with dsi_panel@1
[    2.585102][   T70] sunxi:pin-2000000.pinctrl:[INFO]: Auto power withstand voltage configuration detected, automatically exit!
[    2.594114][  T117] [drm] [DSI]sunxi_drm_dsi_probe ok
[    2.611971][  T117] pwm-backlight backlight0: supply power not found, using dummy regulator
[    2.621384][  T117] sunxi:pin-2000000.pinctrl:[ERR]: unknown pin
[    2.621390][  T117] sunxi:pin-2000000.pinctrl:[ERR]: unknown pin
[    2.628076][  T117] uart-ng 2500000.uart: there is not valid maps for state default
[    2.643169][  T117] sunxi:pin-2000000.pinctrl:[ERR]: unknown pin
[    2.643173][  T117] sunxi:pin-2000000.pinctrl:[ERR]: unknown pin
[    2.649776][  T117] uart-ng 2500000.uart: there is not valid maps for state sleep
[    2.664893][  T117] uart-ng uart-ng0: supply uart not found, using dummy regulator
[    2.673298][  T117] sunxi:uart-ng-uart-ng0:[INFO]: cannot get the TX DMA channel!
[    2.681507][  T117] sunxi:uart-ng-uart-ng0:[INFO]: cannot get the RX DMA channel!
[    2.689761][  T117] sunxi:uart-ng:[INFO]: sunxi uart-ng driver version: 1.1.7
[    2.697391][  T117] uart-ng0: ttyAS0 at MMIO 0x2500000 (irq = 426, base_baud = 1500000) is a SUNXI
[    2.707228][  T117] sunxi:uart-ng-uart-ng0:[INFO]: console setup baud 115200 parity n bits 8, flow n
[    2.717275][  T117] printk: console [ttyAS0] enabled
[    2.717275][  T117] printk: console [ttyAS0] enabled
[    2.728254][  T117] printk: bootconsole [uart8250] disabled
[    2.728254][  T117] printk: bootconsole [uart8250] disabled
[    2.741160][  T117] uart-ng uart-ng1: supply uart not found, using dummy regulator
[    2.749734][  T117] sunxi:uart-ng-uart-ng1:[INFO]: cannot get the TX DMA channel!
[    2.758119][  T117] sunxi:uart-ng-uart-ng1:[INFO]: cannot get the RX DMA channel!
[    2.766560][  T117] uart-ng1: ttyAS1 at MMIO 0x2501000 (irq = 427, base_baud = 1500000) is a SUNXI
[    2.777071][  T117] uart-ng uart-ng4: supply uart not found, using dummy regulator
[    2.785622][  T117] sunxi:uart-ng-uart-ng4:[INFO]: cannot get the TX DMA channel!
[    2.793984][  T117] sunxi:uart-ng-uart-ng4:[INFO]: cannot get the RX DMA channel!
[    2.802402][  T117] uart-ng4: ttyAS4 at MMIO 0x2504000 (irq = 428, base_baud = 1500000) is a SUNXI
[    2.812897][  T117] sunxi-twi 7083000.twi: supply twi not found, using dummy regulator
[    2.823032][  T117] sunxi:axp2101-13-0036:[INFO]: AXP20x variant AXP8191 found
[    2.836296][  T117] axp8191-dcdc1: supplied by regulator-dummy
[    2.845230][  T117] axp8191-dcdc2: supplied by regulator-dummy
[    2.854161][  T117] axp8191-dcdc3: supplied by regulator-dummy
[    2.863079][  T117] axp8191-dcdc4: supplied by regulator-dummy
[    2.872522][  T117] axp8191-dcdc5: supplied by regulator-dummy
[    2.881923][  T117] axp8191-dcdc6: supplied by regulator-dummy
[    2.891339][  T117] axp8191-dcdc7: supplied by regulator-dummy
[    2.900781][  T117] axp8191-dcdc8: supplied by regulator-dummy
[    2.909448][  T117] axp8191-dcdc9: supplied by regulator-dummy
[    2.918401][  T117] axp8191-dc1sw1: supplied by axp8191-dcdc1
[    2.925130][  T117] axp8191-dc1sw2: supplied by axp8191-dcdc1
[    2.932227][  T117] axp8191-aldo1: supplied by regulator-dummy
[    2.942011][  T117] axp8191-aldo2: supplied by regulator-dummy
[    2.949641][  T117] axp8191-aldo3: supplied by regulator-dummy
[    2.957288][  T117] axp8191-aldo4: supplied by regulator-dummy
[    2.964899][  T117] axp8191-aldo5: supplied by regulator-dummy
[    2.972562][  T117] axp8191-aldo6: supplied by regulator-dummy
[    2.979684][  T117] axp8191-bldo1: supplied by regulator-dummy
[    2.986737][  T117] axp8191-bldo2: supplied by regulator-dummy
[    2.993767][  T117] axp8191-bldo3: supplied by regulator-dummy
[    3.000807][  T117] axp8191-bldo4: supplied by regulator-dummy
[    3.007611][  T117] axp8191-bldo5: supplied by regulator-dummy
[    3.016108][  T117] axp8191-cldo1: supplied by regulator-dummy
[    3.024910][  T117] axp8191-cldo2: supplied by regulator-dummy
[    3.031699][  T117] axp8191-cldo3: supplied by regulator-dummy
[    3.040823][  T117] axp8191-cldo4: supplied by regulator-dummy
[    3.047656][  T117] axp8191-cldo5: supplied by regulator-dummy
[    3.056289][  T117] axp8191-dldo1: supplied by regulator-dummy
[    3.065861][  T117] axp8191-dldo2: supplied by regulator-dummy
[    3.072934][  T117] axp8191-dldo3: supplied by regulator-dummy
[    3.079998][  T117] axp8191-dldo4: supplied by regulator-dummy
[    3.086762][  T117] axp8191-dldo5: Bringing 2800000uV into 3300000-3300000uV
[    3.095601][  T117] axp8191-dldo5: supplied by regulator-dummy
[    3.104259][  T117] axp8191-dldo6: supplied by regulator-dummy
[    3.113229][  T117] axp8191-eldo1: supplied by regulator-dummy
[    3.122650][  T117] axp8191-eldo2: supplied by regulator-dummy
[    3.131865][  T117] axp8191-eldo3: supplied by regulator-dummy
[    3.138958][  T117] axp8191-eldo4: supplied by regulator-dummy
[    3.146031][  T117] axp8191-eldo5: supplied by regulator-dummy
[    3.152819][  T117] axp8191-eldo6: supplied by regulator-dummy
[    3.161158][  T117] axp8191-rtcldo: supplied by regulator-dummy
[    3.168054][  T117] axp2101-pek axp2101-pek.0: DMA mask not set
[    3.179544][  T117] input: axp8191-pek as /devices/platform/soc@3000000/7083000.twi/i2c-13/13-0036/axp2101-pek.0/input/input0
[    3.192257][  T117] axp8191-temp-ctrl: Failed to locate of_node [id: 0]
[    3.199739][  T117] sunxi:axp8191_temp_ctrl:[ERR]: axp8191-temp-ctrl device is not configed
[    3.211329][  T117] reg-virt-consumer: Failed to locate of_node [id: -2]
[    3.218886][  T117] reg-virt-consumer: Failed to locate of_node [id: -2]
[    3.226423][  T117] reg-virt-consumer: Failed to locate of_node [id: -2]
[    3.233965][  T117] reg-virt-consumer: Failed to locate of_node [id: -2]
[    3.241504][  T117] reg-virt-consumer: Failed to locate of_node [id: -2]
[    3.249038][  T117] reg-virt-consumer: Failed to locate of_node [id: -2]
[    3.256568][  T117] reg-virt-consumer: Failed to locate of_node [id: -2]
[    3.264095][  T117] reg-virt-consumer: Failed to locate of_node [id: -2]
[    3.271631][  T117] reg-virt-consumer: Failed to locate of_node [id: -2]
[    3.279189][  T117] reg-virt-consumer: Failed to locate of_node [id: -2]
[    3.288979][  T117] sunxi:axp2101-13-0036:[INFO]: AXP20X driver loaded
[    3.296421][  T117] i2c 13-004e: Fixing up cyclic dependency with 10.usbc0
[    3.304232][  T117] sunxi:twi-7083000.twi:[INFO]: v2.7.4 probe success
[    3.312030][  T117] sunxi-twi 7084000.twi: supply twi not found, using dummy regulator
[    3.321798][  T117] sunxi:twi-7084000.twi:[INFO]: v2.7.4 probe success
[    3.332693][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: SD/MMC/SDIO Host Controller Driver(v5.58 2024-11-11 09:32)
[    3.345168][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: ctl-spec-caps 328
[    3.354815][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: No vdmmc regulator found
[    3.363796][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: No vd33sw regulator found
[    3.372833][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: No vd18sw regulator found
[    3.381871][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: No vq33sw regulator found
[    3.390907][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: No vq18sw regulator found
[    3.399962][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[WARN]: Cann't get uart0 pinstate,check if needed
[    3.410558][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[WARN]: Cann't get pin bias hs pinstate,check if needed
[    3.421860][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[ERR]: Could not get store clock
[    3.431499][  T117] sunxi-mmc 4023000.sdmmc: sunxi:sunxi_mmc_host***ctl-cmdq-md*** 20
[    3.440518][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: cq_host:ffffff80c81d7c80, mmc:ffffff80c775d000, host:ffffff80c775d7c0
[    3.453859][  T117] mmc0: CQHCI version 0.00
[    3.458740][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm UP vdd 21 width 1 timing LEGACY(SDR12) dt B
[    3.485223][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    3.512205][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    3.526330][  T117] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: detmode:alway in(non removable)
[    3.536955][  T117] sunxi:sunxi_mmc_host-4020000.sdmmc:[INFO]: SD/MMC/SDIO Host Controller Driver(v5.58 2024-11-11 09:32)
[    3.549577][  T117] sunxi:sunxi_mmc_host-4020000.sdmmc:[INFO]: ctl-spec-caps 428
[    3.552323][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    3.560037][  T117] sunxi:sunxi_mmc_host-4020000.sdmmc:[INFO]: No vqmmc regulator found
[    3.573280][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm OD pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    3.580893][  T117] sunxi:sunxi_mmc_host-4020000.sdmmc:[INFO]: No vdmmc regulator found
[    3.604593][  T117] sunxi-mmc 4020000.sdmmc: Got CD GPIO
[    3.608583][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm OD pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    3.610575][  T117] sunxi-mmc 4020000.sdmmc: sunxi:sunxi_mmc_hostcd-set-debounce is 0x1
[    3.624695][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm OD pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    3.647963][  T117] sunxi:sunxi_mmc_host-4020000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm UP vdd 21 width 1 timing LEGACY(SDR12) dt B
[    3.650703][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm OD pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    3.692120][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    3.720595][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[ERR]: avoid to switch power_off_notification to POWERED_ON(0x01)
[    3.732777][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[ERR]: avoid to switch power_off_notification to POWERED_ON(0x01)
[    3.744924][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[ERR]: avoid to switch power_off_notification to POWERED_ON(0x01)
[    3.757066][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[ERR]: avoid to switch power_off_notification to POWERED_ON(0x01)
[    3.770313][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 8 timing LEGACY(SDR12) dt B
[    3.787946][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 8 timing MMC-HS200 dt B
[    3.801794][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 52000000Hz bm PP pm ON vdd 21 width 8 timing MMC-HS200 dt B
[    3.815969][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 200000000Hz bm PP pm ON vdd 21 width 8 timing MMC-HS200 dt B
[    3.830148][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[ERR]: sdc3 :the host don't support tuning in kernel
[    3.841091][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 200000000Hz bm PP pm ON vdd 21 width 8 timing MMC-HS(SDR20) dt B
[    3.855629][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 52000000Hz bm PP pm ON vdd 21 width 8 timing MMC-HS(SDR20) dt B
[    3.870252][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 50000000Hz bm PP pm ON vdd 21 width 8 timing MMC-HS400 dt B
[    3.880351][  T117] sunxi:sunxi_mmc_host-4020000.sdmmc:[INFO]: no vqmmc,Check if there is regulator
[    3.884337][   T70] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: sdc set ios:clk 200000000Hz bm PP pm ON vdd 21 width 8 timing MMC-HS400 dt B
[    3.906905][  T117] sunxi:sunxi_mmc_host-4020000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[    3.922452][   T70] mmc0: Command Queue Engine enabled
[    3.928202][   T70] mmc0: new HS400 MMC card at address 0001
[    3.935404][   T70] blk_queue_max_segment_size: set to minimum 4096
[    3.935497][   T95] sunxi:sunxi_mmc_host-4020000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm OFF vdd 0 width 1 timing LEGACY(SDR12) dt B
[    3.942434][   T70] mmcblk0: mmc0:0001 MMC32G 29.2 GiB
[    3.956040][  T117] sunxi:sunxi_mmc_host-4020000.sdmmc:[INFO]: detmode:gpio irq
[    3.966283][   T70]  mmcblk0: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29
[    3.970902][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    3.984917][   T70] mmcblk0rpmb: mmc0:0001 MMC32G 4.00 MiB, chardev (235:0)
[    3.992948][  T168] random: fsck_msdos: uninitialized urandom read (40 bytes read)
[    3.994465][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (408000000)
[    3.994665][    T1] fsck_msdos: linker: Warning: failed to find generated linker configuration from "/linkerconfig/ld.config.txt"
[    3.994680][    T1] fsck_msdos: WARNING: linker: Warning: failed to find generated linker configuration from "/linkerconfig/ld.config.txt"
[    3.998470][  T168] random: fsck_msdos: uninitialized urandom read (40 bytes read)
[    4.001284][    T1] fsck_msdos: Invalid signature in boot block: 0000
[    4.001297][    T1] fsck_msdos: /dev/block/by-name/media_data: UNEXPECTED INCONSISTENCY; RUN fsck_msdos MANUALLY.
[    4.002171][    T1] fsck_msdos: fsck_msdos terminated by exit(8)
[    4.002171][    T1]
[    4.005333][    T1] random: init: uninitialized urandom read (16 bytes read)
[    4.010791][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.028719][    T1] erofs: (device dm-0): mounted with root inode @ nid 65.
[    4.032349][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (720000000)
[    4.032431][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.052039][    T1] EXT4-fs (dm-4): mounted filesystem without journal. Opts: . Quota mode: none.
[    4.054787][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (792000000)
[    4.054866][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.063844][    T1] erofs: (device dm-1): mounted with root inode @ nid 42.
[    4.073498][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1008000000)
[    4.073591][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.084207][    T1] erofs: (device dm-3): mounted with root inode @ nid 39.
[    4.090603][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1104000000)
[    4.102037][    T1] erofs: (device dm-2): mounted with root inode @ nid 39.
[    4.109142][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.122387][    T1] newfs_msdos: executing /system/bin/newfs_msdos failed: No such file or directory
[    4.128327][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1200000000)
[    4.138262][    T1] newfs_msdos: newfs_msdos terminated by exit(255)
[    4.138262][    T1]
[    4.146866][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.157856][    T1] FAT-fs (mmcblk0p26): bogus number of reserved sectors
[    4.165261][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1296000000)
[    4.165345][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.173919][    T1] FAT-fs (mmcblk0p26): Can't find a valid FAT filesystem
[    4.175180][    T1] newfs_msdos: executing /system/bin/newfs_msdos failed: No such file or directory
[    4.184621][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1392000000)
[    4.184707][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.192425][    T1] newfs_msdos: newfs_msdos terminated by exit(255)
[    4.192425][    T1]
[    4.201126][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1416000000)
[    4.209321][    T1] FAT-fs (mmcblk0p27): bogus number of reserved sectors
[    4.219627][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.229791][    T1] FAT-fs (mmcblk0p27): Can't find a valid FAT filesystem
[    4.238414][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1512000000)
[    4.274912][    T1] printk: init: 146 output lines suppressed due to ratelimiting
[    4.285616][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.394547][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1608000000)
[    4.403420][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.410423][    T1] init: DM_DEV_STATUS failed for system_ext_a: No such device or address
[    4.414137][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1704000000)
[    4.423429][    T1] init: Could not update logical partition
[    4.433038][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.438435][    T1] init: Opening SELinux policy
[    4.449246][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1800000000)
[    4.454978][    T1] init: Falling back to standard signature check. TODO implementent support for fsverity SEPolicy.
[    4.463070][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.474709][    T1] init: Error: Apex SEPolicy failed signature check
[    4.485336][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (728000000)
[    4.492569][    T1] init: Loading APEX Sepolicy from /system/etc/selinux/apex/SEPolicy.zip
[    4.501239][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.510367][    T1] init: Failed to open package /system/etc/selinux/apex/SEPolicy.zip: No such file or directory
[    4.521007][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1092000000)
[    4.521264][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.541118][    T1] init: Loading SELinux policy
[    4.556918][    T1] SELinux:  Permission bpf in class capability2 not defined in policy.
[    4.556964][  T117] cpu cpu0: _opp_add: OPP not supported by regulators (1586000000)
[    4.566030][    T1] SELinux:  Permission checkpoint_restore in class capability2 not defined in policy.
[    4.575509][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.585169][    T1] SELinux:  Permission bpf in class cap2_userns not defined in policy.
[    4.595849][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (408000000)
[    4.595927][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.604905][    T1] SELinux:  Permission checkpoint_restore in class cap2_userns not defined in policy.
[    4.613450][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (720000000)
[    4.613511][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.624210][    T1] SELinux:  Class mctp_socket not defined in policy.
[    4.634634][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (792000000)
[    4.634702][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.643203][    T1] SELinux: the above unknown classes and permissions will be denied
[    4.653885][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1008000000)
[    4.653956][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.665791][    T1] SELinux:  policy capability network_peer_controls=1
[    4.669722][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1200000000)
[    4.669796][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.680461][    T1] SELinux:  policy capability open_perms=1
[    4.689183][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1296000000)
[    4.689247][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.697838][    T1] SELinux:  policy capability extended_socket_class=1
[    4.708520][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1392000000)
[    4.708593][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.715921][    T1] SELinux:  policy capability always_check_network=0
[    4.724559][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1512000000)
[    4.724636][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.735275][    T1] SELinux:  policy capability cgroup_seclabel=0
[    4.741577][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1608000000)
[    4.741634][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.750234][    T1] SELinux:  policy capability nnp_nosuid_transition=1
[    4.760918][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1704000000)
[    4.760991][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.768311][    T1] SELinux:  policy capability genfs_seclabel_symlinks=0
[    4.776956][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1800000000)
[    4.777030][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.787654][    T1] SELinux:  policy capability ioctl_skip_cloexec=0
[    4.794937][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1896000000)
[    4.795009][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.920482][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1920000000)
[    4.929331][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.940028][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1992000000)
[    4.948900][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.959595][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (728000000)
[    4.968562][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.979262][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1300000000)
[    4.988221][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    4.998915][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1586000000)
[    5.007763][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.018456][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1690000000)
[    5.027527][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.038223][  T117] cpu cpu6: _opp_add: OPP not supported by regulators (1976000000)
[    5.047369][  T117] cpu cpu0: EM: created perf domain
[    5.058868][  T117] cpu cpu6: EM: created perf domain
[    5.064587][   T80] audit: type=1403 audit(1748526560.564:2): auid=4294967295 ses=4294967295 lsm=selinux res=1
[    5.067994][  T117] sunxi:sunxi_dsufreq:[WARN]: dsu dvfs: 26m-vf0200
[    5.070180][    T1] selinux: SELinux: Loaded file_contexts
[    5.070185][    T1] selinux:
[    5.075564][    T1] random: init: uninitialized urandom read (40 bytes read)
[    5.082221][    T1] random: init: uninitialized urandom read (40 bytes read)
[    5.082999][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.091100][    T1] init: init second stage started!
[    5.092311][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (288000000)
[    5.092468][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.145524][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (528000000)
[    5.147758][    T1] FAT-fs (mmcblk0p26): bogus number of reserved sectors
[    5.156188][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.163701][    T1] FAT-fs (mmcblk0p26): Can't find a valid FAT filesystem
[    5.174545][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (600000000)
[    5.182159][    T1] init: mount media_data fail*****Invalid argument
[    5.192705][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.210415][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (744000000)
[    5.219149][    T1] init: Using Android DT directory /proc/device-tree/firmware/android/
[    5.221086][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.233982][    T1] init: Couldn't load property file '/vendor/default.prop': open() failed: No such file or directory: No such file or directory
[    5.240734][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (792000000)
[    5.240807][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.257627][    T1] init: Couldn't load property file '/odm_dlkm/etc/build.prop': open() failed: No such file or directory: No such file or directory
[    5.265886][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (840000000)
[    5.265955][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.277404][    T1] init: Couldn't load property file '/oem/build.prop': open() failed: No such file or directory: No such file or directory
[    5.291526][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (888000000)
[    5.291596][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.302488][    T1] init: Could not set 'ro.boot.dynamic_partitions' to 'true' while loading .prop filesRead-only property was already set
[    5.312793][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (912000000)
[    5.312858][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.326898][    T1] init: Could not set 'ro.boot.dynamic_partitions_retrofit' to 'true' while loading .prop filesRead-only property was already set
[    5.337453][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (984000000)
[    5.337522][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.348750][    T1] init: Setting product property ro.product.brand to 'Allwinner' (from ro.product.product.brand)
[    5.362023][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (1032000000)
[    5.362089][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.372630][    T1] init: Setting product property ro.product.device to 'a733-demo-aiot' (from ro.product.product.device)
[    5.383287][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (1056000000)
[    5.383352][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.485850][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (1152000000)
[    5.496624][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.507329][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (1200000000)
[    5.511106][  T184] random: init: uninitialized urandom read (40 bytes read)
[    5.518096][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.536625][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (1224000000)
[    5.547448][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.558134][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (1296000000)
[    5.568887][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.579571][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (546000000)
[    5.590325][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.601006][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (832000000)
[    5.611878][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.622568][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (1196000000)
[    5.633432][  T117] core: _opp_supported_by_regulators: OPP minuV: 0 maxuV: 0, not supported by regulator
[    5.644114][  T117] sunxi-dsufreq 8860000.dsufreq: _opp_add: OPP not supported by regulators (1352000000)
[    5.654927][  T117] [drm] [DSI-PANEL] panel_dsi_probe start
[    5.661354][  T117] [drm] reset-on-sequence property not found
[    5.668136][  T117] [drm] [DSI]sunxi_drm_dsi_host_attach start
[    5.674668][  T117] [drm] [DSI]sunxi_drm_dsi_host_attach finish
[    5.681272][  T117] [drm] [DSI-PANEL] panel_dsi_probe finish
[    5.687866][  T117] [drm] sunxi_drm_bind start
[    5.692983][  T117] [drm] [TCON_TOP]sunxi_tcon_top_bind start
[    5.699517][  T117] sunxi-drm soc@3000000:sunxi-drm: bound 5500000.vo0 (ops sunxi_tcon_top_component_ops [sunxidrm])
[    5.711367][  T117] [drm] [TCON_TOP]sunxi_tcon_top_bind start
[    5.717820][  T117] sunxi-drm soc@3000000:sunxi-drm: bound 5510000.vo1 (ops sunxi_tcon_top_component_ops [sunxidrm])
[    5.729663][  T117] [drm] [SUNXI-DE] sunxi_de_bind start
[    5.735620][  T117] sunxi-drm soc@3000000:sunxi-drm: Adding to iommu group 0
[    5.743626][  T117] [drm] sunxi_de_bind crtc init for de 0 ok
[    5.750086][  T117] [drm] sunxi_de_bind crtc init for de 1 ok
[    5.757000][  T117] sunxi-drm soc@3000000:sunxi-drm: bound 5000000.de (ops sunxi_de_component_ops [sunxidrm])
[    5.768182][  T117] sunxi-drm soc@3000000:sunxi-drm: bound 5507000.phy (ops sunxi_cphy_component_ops [sunxi_drm_phy])
[    5.780041][  T117] [drm] [DSI]sunxi_drm_dsi_bind start
[    5.786045][  T117] [drm] [SUNXI-TCON] sunxi_tcon_of_get_id 0
[    5.787979][  T188] linkerconfig: Unable to access VNDK APEX at path: /apex/com.android.vndk.v33: No such file or directory
[    5.792489][  T117] sunxi-drm soc@3000000:sunxi-drm: bound 5506000.dsi0 (ops sunxi_drm_dsi_component_ops [sunxidrm])
[    5.805116][  T188] linkerconfig: Unable to access VNDK APEX at path: /apex/com.android.vndk.v33: No such file or directory
[    5.816785][  T117] [drm] [SUNXI-TCON] sunxi_tcon_of_get_id 4
[    5.831259][  T188] linkerconfig (188) used greatest stack depth: 11104 bytes left
[    5.835909][  T117] [drm] sunxi-hdmi: hdmi drv init dts done
[    5.851357][  T117] [drm] sunxi-hdmi: hdmi drv enable resource done
[    5.858364][  T117] [drm] sunxi-hdmi: hdmi drv init resource done
[    5.865265][  T117] [drm] sunxi-hdmi: hdmi drv init i2c adapter finish
[    5.865619][  T189] ueventd: ueventd started!
[    5.878252][  T117] [drm] sunxi-hdmi: drm hdmi connector create finish
[    5.879202][  T189] selinux: SELinux: Loaded file_contexts
[    5.885578][  T117] [drm] sunxi-hdmi: hdmi devices bind done <<<<<<<<<<
[    5.885578][  T117]
[    5.885591][  T117] sunxi-drm soc@3000000:sunxi-drm: bound 5520000.hdmi (ops sunxi_hdmi_compoent_ops [sunxidrm])
[    5.891794][  T189] selinux:
[    5.898693][  T190] apexd: Bootstrap subcommand detected
[    5.898765][  T190] apexd: ActivateFlattenedApex
[    5.898801][  T190] apexd: Scanning /system/apex
[    5.899419][  T190] apexd: Bind mounting /system/apex/com.android.adbd onto /apex/com.android.adbd
[    5.900047][  T190] apexd: Bind mounting /system/apex/com.android.adservices onto /apex/com.android.adservices
[    5.900637][  T190] apexd: Bind mounting /system/apex/com.android.appsearch onto /apex/com.android.appsearch
[    5.901214][  T190] apexd: Bind mounting /system/apex/com.android.art onto /apex/com.android.art
[    5.901543][  T117] sunxi-drm soc@3000000:sunxi-drm: bound 5501000.tcon0 (ops sunxi_tcon_component_ops [sunxidrm])
[    5.901818][  T190] apexd: Bind mounting /system/apex/com.android.btservices onto /apex/com.android.btservices
[    5.902431][  T190] apexd: Bind mounting /system/apex/com.android.conscrypt onto /apex/com.android.conscrypt
[    5.902952][  T190] apexd: Bind mounting /system/apex/com.android.extservices onto /apex/com.android.extservices
[    5.913451][  T189] ueventd: Parsing file /system/etc/ueventd.rc...
[    5.916216][  T117] sunxi-drm soc@3000000:sunxi-drm: bound 5730000.tcon3 (ops sunxi_tcon_component_ops [sunxidrm])
[    5.922254][  T189] ueventd: Added '/vendor/etc/ueventd.rc' to import list
[    5.923944][  T190] printk: apexd: 24 output lines suppressed due to ratelimiting
[    5.924165][  T190] apexd (190) used greatest stack depth: 10464 bytes left
[    5.927303][  T117] sunxi-drm soc@3000000:sunxi-drm: bound 5731000.tcon4 (ops sunxi_tcon_component_ops [sunxidrm])
[    5.932561][  T189] ueventd: Added '/odm/etc/ueventd.rc' to import list
[    5.942755][   T80] audit: type=1400 audit(1748526561.440:3): avc:  denied  { sys_admin } for  pid=117 comm="kworker/u16:2" capability=21  scontext=u:r:kernel:s0 tcontext=u:r:kernel:s0 tclass=capability permissive=1
[    5.945132][  T117] [drm] [SUNXI-CRTC]sunxi_crtc_atomic_enable
[    5.945137][  T117] [drm] sunxi_de_enable index 0
[    5.949771][  T117] [drm] sunxi_de_enable finish sw en=1
[    5.949787][  T117] [drm] [DSI] sunxi_drm_dsi_encoder_atomic_enable vrr_setp:0 start
[    5.949789][  T117] [drm] [DSI] sunxi_tcon_dsi_mode_init start
[    5.949909][  T117] [drm] [DSI] sunxi_lcd_pin_set_state start
[    5.954570][  T189] ueventd: Parsing file /vendor/etc/ueventd.rc...
[    6.095342][  T197] random: boringssl_self_: uninitialized urandom read (40 bytes read)
[    6.102506][  T189] ueventd: Parsing file /odm/etc/ueventd.rc...
[    6.131448][  T198] random: prng_seeder: uninitialized urandom read (40 bytes read)
[    6.135110][  T189] ueventd: Unable to read config file '/odm/etc/ueventd.rc': open() failed: No such file or directory
[    6.136105][  T199] random: boringssl_self_: uninitialized urandom read (40 bytes read)
[    6.172749][  T117] [drm] [DSI] sunxi_drm_dsi_encoder_atomic_enable finish
[    6.188569][  T198] prng_seeder: Hanging forever because setup failed: Unable to open hwrng /dev/hw_random
[    6.188569][  T198]
[    6.208178][  T117] [drm] Initialized sunxi-drm 3.0.0 20230901 for soc@3000000:sunxi-drm on minor 0
[    6.214976][  T198] Caused by:
[    6.216997][   T80] audit: type=1400 audit(1748526561.712:4): avc:  denied  { search } for  pid=184 comm="init" name="/" dev="dm-4" ino=2 scontext=u:r:vendor_init:s0 tcontext=u:object_r:system_dlkm_file:s0 tclass=dir permissive=1
[    6.224886][  T117] [drm] sunxi_drm_bind ok
[    6.226074][  T184] sunxi-rfkill soc@3000000:rfkill: module version: v1.1.4
[    6.226269][  T117] i2c i2c-2: of_i2c: modalias failure on /soc@3000000/twi@2512000/focaltech@38
[    6.226273][  T117] i2c i2c-2: Failed to create I2C device for /soc@3000000/twi@2512000/focaltech@38
[    6.226319][  T117] sunxi:twi-2512000.twi:[INFO]: v2.7.4 probe success
[    6.227254][  T117] sunxi:twi-2513000.twi:[INFO]: v2.7.4 probe success
[    6.228366][  T117] sunxi-cadence-combophy 6c00000.serdes: Sub System Version v2.0.0
[    6.228651][  T198]     No such file or directory (os error 2)
[    6.283755][  T184] sunxi-rfkill soc@3000000:rfkill: pinctrl_lookup_state(default) failed! return ffffffffffffffed
[    6.312737][  T189] ueventd: Coldboot took 0.127 seconds
[    6.320158][  T184] sunxi-rfkill soc@3000000:rfkill: get gpio chip_en failed
[    6.339567][  T184] sunxi-rfkill soc@3000000:rfkill: get gpio power_en failed
[    6.347617][  T184] sunxi-rfkill soc@3000000:rfkill: wlan_busnum (1)
[    6.355182][  T184] sunxi-rfkill soc@3000000:rfkill: wlan power[0] (axp8191-dcdc1) voltage: 3300mV
[    6.365441][  T184] sunxi-rfkill soc@3000000:rfkill: wlan power[1] (axp8191-bldo5) voltage: 1800mV
[    6.375694][  T184] sunxi-rfkill soc@3000000:rfkill: wlan power[2] (axp8191-cldo1) voltage: 1800mV
[    6.385726][  T184] sunxi-rfkill soc@3000000:rfkill: wlan_regon gpio=385 assert=1
[    6.394097][  T184] sunxi-rfkill soc@3000000:rfkill: wlan_hostwake gpio=384 assert=1
[    6.402743][  T184] sunxi-rfkill soc@3000000:rfkill: wakeup source is enabled
[    6.410703][  T184] sunxi-rfkill soc@3000000:rfkill: wlan power boot-on: 0, always-on: 0
[    6.419999][  T184] sunxi-rfkill soc@3000000:rfkill: bt power[0] (axp8191-dcdc1) voltage: 3300mV
[    6.430136][  T184] sunxi-rfkill soc@3000000:rfkill: bt power[1] (axp8191-bldo5) voltage: 1800mV
[    6.440266][  T184] sunxi-rfkill soc@3000000:rfkill: bt power[2] (axp8191-cldo1) voltage: 1800mV
[    6.450122][  T184] sunxi-rfkill soc@3000000:rfkill: bt_rst gpio=386 assert=0
[    6.458111][  T184] sunxi-rfkill soc@3000000:rfkill: bluetooth power boot-on: 0, always-on: 0
[    6.527208][    T1] Registered swp emulation handler
[    6.583577][  T184] g2d 5440000.g2d: Adding to iommu group 0
[    6.584547][  T212] logd.auditd: start
[    6.591007][  T184] sunxi:g2d_sunxi:[INFO]: [G2D]: rcq version initialized.major:505
[    6.594231][  T212] logd.klogd: 6418075835
[    6.602808][  T184] sunxi:g2d_sunxi:[INFO]: [G2D]: g2d_module_init
console:/ $ [    6.618121][  T212] logd: Loaded bug_map file: /system_ext/etc/selinux/bug_map
[    6.626659][  T212] logd: Loaded bug_map file: /vendor/etc/selinux/selinux_denial_metadata
[    6.636575][  T212] logd: Loaded bug_map file: /system/etc/selinux/bug_map
[    6.643045][  T219] treadahead: /treadahead/readahead_file_offset not exist;
[    6.652380][  T219] treadahead: go to open trace
[    6.686710][    T1] mke2fs: mke2fs 1.46.2 (28-Feb-2021)
[    6.692604][    T1] mke2fs: Discarding device blocks: done
[    6.703208][    T1] mke2fs: Creating filesystem with 4096 4k blocks and 4096 inodes
[    6.711758][    T1] mke2fs:
[    6.714970][    T1] mke2fs: Allocating group tables: done
[    6.724875][    T1] mke2fs: Writing inode tables: done
[    6.734495][    T1] mke2fs: Creating journal (1024 blocks): done
[    6.741203][    T1] mke2fs: Writing superblocks and filesystem accounting information: done
[    6.751691][    T1] mke2fs:
[    6.781266][    T1] e2fsdroid: Created filesystem with 11/4096 inodes and 1545/4096 blocks
[    6.792430][    T1] EXT4-fs (mmcblk0p21): Ignoring removed nomblk_io_submit option
[    6.803250][    T1] EXT4-fs (mmcblk0p21): mounted filesystem with ordered data mode. Opts: errors=remount-ro,nomblk_io_submit. Quota mode: none.
[    6.876619][    T1] EXT4-fs (mmcblk0p21): mounted filesystem with ordered data mode. Opts: errors=panic. Quota mode: none.
[    6.999862][    T1] EXT4-fs (mmcblk0p22): Ignoring removed nomblk_io_submit option
[    7.010725][    T1] EXT4-fs (mmcblk0p22): mounted filesystem with ordered data mode. Opts: errors=remount-ro,nomblk_io_submit. Quota mode: none.
[    7.052736][    T1] EXT4-fs (mmcblk0p22): mounted filesystem with ordered data mode. Opts: errors=panic. Quota mode: none.
[    7.098465][  T251] random: newfs_msdos: uninitialized urandom read (40 bytes read)
[    7.194125][  T229] type=1400 audit(1748526562.692:5): avc: denied { getattr } for comm="init" path="/sys/kernel/debug/devices_deferred" dev="debugfs" ino=11811 scontext=u:r:init:s0 tcontext=u:object_r:debugfs:s0 tclass=file permissive=1
[    7.218829][  T229] type=1400 audit(1748526562.692:6): avc: denied { getattr } for comm="init" path="/sys/kernel/debug/wakeup_sources" dev="debugfs" ino=1048 scontext=u:r:init:s0 tcontext=u:object_r:debugfs_wakeup_sources:s0 tclass=file permissive=1
[    7.289947][  T257] AW_keymint_2 : starting aw keymint service
[    7.290616][  T257] AW_keymint_2 : no optee, use software keymint
[    7.332656][  T257] AW_keymint_2 : adding keymint service instance: android.hardware.security.keymint.IKeyMintDevice/default
[    7.340360][  T257] AW_keymint_2 : adding keymint service instance: android.hardware.security.secureclock.ISecureClock/default
[    7.353464][  T257] AW_keymint_2 : adding keymint service instance: android.hardware.security.sharedsecret.ISharedSecret/default
[    7.366575][  T257] AW_keymint_2 : adding keymint service instance: android.hardware.security.keymint.IRemotelyProvisionedComponent/default
[    7.380207][  T257] AW_keymint_2 : start aw keymint service ok
[    9.361924][    T1] EXT4-fs (mmcblk0p29): Ignoring removed nomblk_io_submit option
[    9.381124][    T1] EXT4-fs (mmcblk0p29): mounted filesystem with ordered data mode. Opts: errors=remount-ro,nomblk_io_submit. Quota mode: journalled.
[    9.480150][    C6] random: crng init done
[    9.484731][    C6] random: 84 urandom warning(s) missed due to ratelimiting
[    9.604721][    T1] EXT4-fs (mmcblk0p29): Ignoring removed nomblk_io_submit option
[    9.613270][    T1] EXT4-fs (mmcblk0p29): Using encoding defined by superblock: utf8-12.1.0 with flags 0x0
[    9.631024][    T1] EXT4-fs (mmcblk0p29): mounted filesystem with ordered data mode. Opts: barrier=1,data=ordered,nomblk_io_submit,noauto_da_alloc,errors=panic,resuid=0,resgid=1065. Quota mode: journalled.
[    9.704261][  T184] pvrsrvkm: loading out-of-tree module taints kernel.
[    9.735350][  T184] [sunxi bxm]SysDevInit start!
[    9.740526][  T184] pvrsrvkm 1800000.gpu: sunxi_platform_init start
[    9.747581][  T184] pvrsrvkm 1800000.gpu: warning: default clk_rate is NOT set in DTS, set it to default:600000000
[    9.759138][  T184] pvrsrvkm 1800000.gpu: sunxi_parse_dts clk_rate:600000000
[    9.768272][  T184] pvrsrvkm 1800000.gpu: succeed to get gpu regulator, default volt value:800000
[    9.778315][  T184] pvrsrvkm 1800000.gpu: get opp:(400000000 hz, 800000 uv)
[    9.786097][  T184] pvrsrvkm 1800000.gpu: get opp:(600000000 hz, 800000 uv)
[    9.793865][  T184] pvrsrvkm 1800000.gpu: get opp:(800000000 hz, 840000 uv)
[    9.801636][  T184] pvrsrvkm 1800000.gpu: get opp:(1008000000 hz, 960000 uv)
[    9.809500][  T184] pvrsrvkm 1800000.gpu: opp count:4
[    9.815135][  T184] pvrsrvkm 1800000.gpu: set default clk_rate to max opp freq:1008000000
[    9.824260][  T184] pvrsrvkm 1800000.gpu: sunxi_parse_dts finished
[    9.831273][  T184] pvrsrvkm 1800000.gpu: sunxi_set_device_clk_rate:1008000000
[    9.839353][  T184] pvrsrvkm 1800000.gpu: sunxi_platform_init end
[    9.846159][  T184] [sunxi bxm]SysDevInit end!
[    9.851140][  T184] pvrsrvkm 1800000.gpu: sunxiPrePowerState ePwrFlags:1 current power status:1 1
[    9.861047][  T184] pvrsrvkm 1800000.gpu: sunxiPostPowerState ePwrFlags:1 current power status:1 1
[    9.871049][  T184] PVR_K:  184: Read BVNC 36.56.104.183 from HW device registers
[    9.879399][  T184] pvrsrvkm 1800000.gpu: sunxiPrePowerState ePwrFlags:1 current power status:1 1
[    9.889309][  T184] pvrsrvkm 1800000.gpu: sunxiPostPowerState ePwrFlags:1 current power status:1 1
[    9.899350][  T184] PVR_K:  184: RGX Device registered BVNC 36.56.104.183 with 1 core in the system
[    9.909820][  T184] pvrsrvkm 1800000.gpu: Found 4 OPP points.
[    9.916239][  T184] pvrsrvkm 1800000.gpu: opp[1/4]: (400000000 Hz, 800000 uV)
[    9.924206][  T184] pvrsrvkm 1800000.gpu: opp[2/4]: (600000000 Hz, 800000 uV)
[    9.932170][  T184] pvrsrvkm 1800000.gpu: opp[3/4]: (800000000 Hz, 840000 uV)
[    9.940133][  T184] pvrsrvkm 1800000.gpu: opp[4/4]: (1008000000 Hz, 960000 uV)
[    9.949382][  T184] [drm] Initialized pvr 24.2.6643903 20170530 for 1800000.gpu on minor 1
[   10.073537][  T226] vold: keystore2 Keystore earlyBootEnded returned service specific error: -68
[   10.096527][    T1] init: Not setting encryption policy on: /data/apex
[   10.108086][    T1] init: Inferred action different from explicit one, expected 0 but got 2
[   10.120795][    T1] init: Inferred action different from explicit one, expected 0 but got 3
[   10.121294][  T225] logd: logd reinit
[   10.131331][    T1] init: Inferred action different from explicit one, expected 0 but got 2
[   10.134684][  T225] logd: Cannot read /data/misc/logd/event-log-tags
[   10.145083][    T1] init: starting service 'apexd'...
[   10.151673][  T225] logd: FrameworkListener: read() failed (Connection reset by peer)
[   10.158952][    T1] init: Service 'logd-reinit' (pid 289) exited with status 0 oneshot service took 0.065000 seconds in background
[   10.178530][    T1] init: Sending signal 9 to service 'logd-reinit' (pid 289) process group...
[   10.186057][  T290] apexd: This device does not support updatable APEX. Exiting
[   10.188691][    T1] libprocessgroup: Successfully killed process cgroup uid 1036 pid 289 in 0ms
[   10.196399][  T290] apexd: Marking APEXd as activated
[   10.207566][    T1] init: Command 'copy /data/misc/recovery/ro.build.fingerprint /data/misc/recovery/ro.build.fingerprint.1' action=post-fs-data (/system/etc/init/hw/init.rc:754) took 0ms and failed: Could not read input file '/data/misc/recovery/ro.build.fingerprint': open() failed: No such file or directory
[   10.242371][    T1] init: Service 'apexd' (pid 290) exited with status 0 oneshot service took 0.084000 seconds in background
[   10.446885][  T295] vdc: Waited 0ms for vold
[   10.498427][  T226] vold: Failed to chmod /data/system_ce/0: No such file or directory
[   10.507563][  T226] vold: Failed to chmod /data/misc_ce/0: No such file or directory
[   10.516427][  T226] vold: Failed to chmod /data/media/0: No such file or directory
[   10.727306][  T301] apexd: This device does not support updatable APEX. Exiting
[   10.735722][  T301] apexd: Marking APEXd as ready
[   10.793386][  T184] init: Top-level directory needs encryption action, eg mkdir /data/audio_d <mode> <uid> <gid> encryption=Require
[   10.828546][  T184] init: Inferred action different from explicit one, expected 0 but got 2
[   10.841725][    T1] WARNING: Unprivileged eBPF is enabled, data leaks possible via Spectre v2 BHB attacks!
[   10.879971][  T305] bpfloader: Override /apex/com.android.tethering/etc/bpf/offload.o with /system/etc/bpf-override/offload.o
[   10.893957][  T305] LibBpfLoader: Loading critical for tethering ELF object /system/etc/bpf-override/offload.o with license Apache 2.0
[   10.907540][  T305] LibBpfLoader: Section bpfloader_min_ver value is 2 [0x2]
[   10.915478][  T305] LibBpfLoader: Section bpfloader_max_ver value is 65536 [0x10000]
[   10.924190][  T305] LibBpfLoader: Section size_of_bpf_map_def value is 116 [0x74]
[   10.932613][  T305] LibBpfLoader: Section size_of_bpf_prog_def value is 92 [0x5c]
[   10.940970][  T305] LibBpfLoader: BpfLoader version 0x00013 processing ELF object /system/etc/bpf-override/offload.o with ver [0x00002,0x10000)
[   10.958101][  T305] LibBpfLoader: Loaded code section 3 (schedcls_tether_downstream6_ether)
[   10.967725][  T305] LibBpfLoader: Loaded relo section 3 (.relschedcls/tether_downstream6_ether)
[   10.977447][  T305] LibBpfLoader: Adding section 3 to cs list
[   11.183655][  T305] printk: bpfloader: 1670 output lines suppressed due to ratelimiting
[   11.222764][  T308] update_verifier: Started with arg 1: nonencrypted
[   11.233363][  T308] update_verifier: Booting slot 0: isSlotMarkedSuccessful=1
[   11.241388][  T308] update_verifier: Leaving update_verifier.
[   11.343807][  T315] sunxi-rfkill soc@3000000:rfkill: wlan power on success
[   11.344486][  T184] [Awinic] aw87xxx_pa_init:driver version: v2.14.0
[   11.359212][  T184] [Awinic] [14-0058]aw87xxx_dtsi_parse: get det_battery_supply failed
[   11.359212][  T184]
[   11.371639][  T184] [Awinic] [14-0059]aw87xxx_dtsi_parse: get det_battery_supply failed
[   11.371639][  T184]
[   11.401134][  T184] sunxi:sound-i2s:[WARN]: 2206 snd_sunxi_dts_params_init(): clk-en-post-delay missing
[   11.411709][  T184] sunxi:sound-i2s:[WARN]: 2214 snd_sunxi_dts_params_init(): clk-keep missing
[   11.421777][  T184] sunxi:sound-i2s:[WARN]: 2206 snd_sunxi_dts_params_init(): clk-en-post-delay missing
[   11.432302][  T184] sunxi:sound-i2s:[WARN]: 2214 snd_sunxi_dts_params_init(): clk-keep missing
[   11.446002][  T184] sunxi:sound-ac101:[INFO]: 2626 ac101_i2c_probe():
[   11.451768][  T315] misc sunxi-wlan: start scan device on bus_index: 1
[   11.453414][  T184] sunxi:sound-ac101:[ERR]: 2592 ac101_set_params_from_of(): det_gpio        -> 34
[   11.460668][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm UP vdd 21 width 1 timing LEGACY(SDR12) dt B
[   11.470750][  T184] sunxi:sound-ac101:[ERR]: 2593 ac101_set_params_from_of(): plug_gpio        -> 313
[   11.495768][  T184] sunxi:sound-common:[INFO]: 36 snd_sunxi_pa_user_trig_init(): pa user mode -> init
[   11.496150][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   11.506090][  T184] sunxi:sound-common:[INFO]: 36 snd_sunxi_pa_user_trig_init(): pa user mode -> init
[   11.533005][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 52, RTO !!
[   11.543098][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 52, RTO !!
[   11.552374][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   11.569459][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   11.585843][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 11, RE !!
[   11.595029][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm OFF vdd 0 width 1 timing LEGACY(SDR12) dt B
[   11.610981][  T184] sunxi:sound-codec-hdmi:[ERR]: 442 sunxi_codec_dev_probe(): register codec-hdmi success
[   11.611256][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm UP vdd 21 width 1 timing LEGACY(SDR12) dt B
[   11.637540][  T184] sunxi:sound-mach:[WARN]: 372 asoc_simple_parse_ucfmt(): set data late to default
[   11.648055][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   11.662907][   T94] platform boost5v-en: deferred probe pending
[   11.689441][   T95] mmc1: queuing unknown CIS tuple 0x10 [07 00 11 00 8e] (5 bytes)
[   11.703261][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 50000000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   11.704497][  T184] sunxi:sound-ac101:[INFO]: 1529 ac101_probe(): wait ac101 reset successfully, need 0x101/257
[   11.717684][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 50000000Hz bm PP pm ON vdd 21 width 4 timing LEGACY(SDR12) dt B
[   11.741916][  T184] debugfs: Directory '2532000.i2s0_plat' with parent 'sndi2s0' already present!
[   11.743293][   T95] mmc1: queuing unknown CIS tuple 0x10 [07 00 31 00 32] (5 bytes)
[   11.753048][  T160] sunxi:sound-ac101:[INFO]: 531 sunxi_jack_adv_det_scan_work():
[   11.770114][  T160] [sound] jack report -> OUT
[   11.775378][   T95] mmc1: new SDIO card at address ac4d
[   11.776478][  T184] input: sndi2s0 Headphones as /devices/platform/soc@3000000/soc@3000000:i2s0_mach/sound/card0/input1
[   11.784648][  T315] sunxi-rfkill soc@3000000:rfkill: wlan power off success
[   11.793712][  T184] sunxi:sound-mach:[WARN]: 372 asoc_simple_parse_ucfmt(): set data late to default
[   11.801118][  T315] misc sunxi-wlan: start scan device on bus_index: 1
[   11.811664][  T184] debugfs: Directory '2535000.i2s3_plat' with parent 'sndhdmi' already present!
[   11.818680][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 7, RTO !!
[   11.837682][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 7, RTO !!
[   11.846907][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 7, RTO !!
[   11.856110][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 7, RTO !!
[   11.856901][  T184] npu[b8][b8] vipcore, platform driver init
[   11.871918][   T95] mmc1: card ac4d removed
[   11.872407][  T184] npu[b8][b8] vipcore, insmod param cpu_physical=0x0
[   11.876690][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm OFF vdd 0 width 1 timing LEGACY(SDR12) dt B
[   11.884000][  T184] npu[b8][b8] vipcore, insmod param cpu_physical=0x0
[   11.898907][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm UP vdd 21 width 1 timing LEGACY(SDR12) dt B
[   11.905459][  T184] npu[b8][b8] vipcore, insmod param cpu_physical=0x0
[   11.919205][  T315] aicbsp_init
[   11.926452][  T184] npu[b8][b8] vipcore, insmod param cpu_physical=0x0
[   11.929400][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   11.929504][  T315] aicbsp_init, Driver Release Tag: aic-bsp-compatible(sdio)-20240730-002
[   11.936851][  T184] npu[b8][b8] vipcore, platform device compatible=allwinner,npu
[   11.951401][  T315] -->aicbt_rfkill_init
[   11.951716][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 52, RTO !!
[   11.960349][  T184] npu[b8][b8] vipcore, platform driver device=0xffffff80c0b7e410
[   11.968565][  T315] <--aicbt_rfkill_init
[   11.969279][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 52, RTO !!
[   11.972957][  T184] npu[b8][b8] clock_rate: 26000000
[   11.982153][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   11.990777][  T184] npu[b8][b8] vipcore irq number is 463.
[   11.997953][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   12.004224][  T184] npu[b8][b8] npu power domains status: 0
[   12.004941][  T315] [BT_LPM] bluesleep_init: BlueSleep Mode Driver Ver 1.3.3
[   12.004949][  T315] [BT_LPM] bluesleep_init: Driver Release Tag: aic-btlpm-20220429-008
[   12.005329][  T315] [BT_LPM] bluesleep_probe: bt_hostwake gpio=388 assert=1
[   12.005329][  T315]
[   12.005333][  T315] [BT_LPM] bluesleep_probe: override host_wake assert to 1
[   12.005367][  T315] [BT_LPM] bluesleep_probe: wakeup source is disabled!
[   12.005367][  T315]
[   12.005380][  T315] [BT_LPM] bluesleep_probe: bt_wake gpio=387 assert=1
[   12.005380][  T315]
[   12.005384][  T315] [BT_LPM] bluesleep_probe: override ext_wake assert to 1
[   12.005400][  T315] [BT_LPM] bluesleep_probe: uart_index (1)
[   12.005400][  T315]
[   12.012191][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 5, RTO !!
[   12.023847][  T184] NPU AXI CLK NULL
[   12.030788][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 5, RTO !!
[   12.044049][  T184] NPU AHB CLK NULL
[   12.051092][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 5, RTO !!
[   12.058151][  T184] NPU TZMA CLK NULL
[   12.067894][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 5, RTO !!
[   12.077302][  T184] npu[b8][b8] EXTRA: 0x00005100, SID: 0x0, max_freq: 1100000000, default_freq: 1100000000
[   12.085225][   T95] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm OFF vdd 0 width 1 timing LEGACY(SDR12) dt B
[   12.095058][  T184] npu[b8][b8] current dvfs: 0, vf index: 0
[   12.095174][  T184] vipcore 3600000.npu: dev_pm_opp_set_regulators: no regulator (npu) found: -19
[   12.210697][  T184] npu[b8][b8] failed to set opp regulator
[   12.216944][  T184] npu[b8][b8] enable aw vip devfreq
[   12.222590][  T184] npu[b8][b8] no available freq info
[   12.228375][  T184] vipcore 3600000.npu: supply npu not found, using dummy regulator
[   12.237305][  T184] npu[b8][b8] vipcore, device_cnt=1, core_cnt=1
[   12.244308][  T184] npu[b8][b8] core_0, request irqline=463, name=vipcore_0
[   12.252171][  T184] npu[b8][b8] vipcore, allocate page for video memory, size: 0x400000 bytes
[   12.263004][  T184] npu[b8][b8] vipcore, heap_cnt=0, reserved video memory cpu_phy=0x11ac00000, vip_phy=0x11ac00000, size=0x400000
[   12.276294][  T184] npu[b8][b8] VIPLite driver version 2.0.3.0-AW-2024-05-29
[   12.308072][  T229] type=1400 audit(1748526567.804:10): avc: denied { write } for comm="init" name="discard_max_bytes" dev="sysfs" ino=39324 scontext=u:r:init:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1
[   12.330221][  T229] type=1400 audit(1748526567.804:11): avc: denied { open } for comm="init" path="/sys/devices/platform/soc@3000000/4023000.sdmmc/mmc_host/mmc0/mmc0:0001/block/mmcblk0/queue/discard_max_bytes" dev="sysfs" ino=39324 scontext=u:r:init:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1
[   12.425767][  T344] healthd: No battery devices found
[   12.433879][  T344] healthd: battery none chg=
[   12.438935][  T344] healthd: battery none chg=
[   12.444250][  T344] healthd: battery none chg=
[   12.479970][  T343] PVR_K:  343: RGX Firmware image 'rgx.fw.36.56.104.183' loaded
[   12.499008][  T343] PVR_K:  343: Shader binary image 'rgx.sh.36.56.104.183' loaded
[   12.512245][  T343] pvrsrvkm 1800000.gpu: sunxiPrePowerState ePwrFlags:1 current power status:0 1
[   12.513689][  T229] type=1400 audit(1748526568.012:12): avc: denied { read } for comm="display.output-" name="u:object_r:boot_status_prop:s0" dev="tmpfs" ino=80 scontext=u:r:hal_awdisplayoutput_default:s0 tcontext=u:object_r:boot_status_prop:s0 tclass=file permissive=1
[   12.522326][  T343] pvrsrvkm 1800000.gpu: sunxiPostPowerState ePwrFlags:1 current power status:1 1
[   12.549389][  T229] type=1400 audit(1748526568.012:13): avc: denied { open } for comm="display.output-" path="/dev/__properties__/u:object_r:boot_status_prop:s0" dev="tmpfs" ino=80 scontext=u:r:hal_awdisplayoutput_default:s0 tcontext=u:object_r:boot_status_prop:s0 tclass=file permissive=1
[   12.575490][  T343] pvrsrvkm 1800000.gpu: sunxiPrePowerState ePwrFlags:1 current power status:1 1
[   12.588254][  T229] type=1400 audit(1748526568.012:14): avc: denied { getattr } for comm="display.output-" path="/dev/__properties__/u:object_r:boot_status_prop:s0" dev="tmpfs" ino=80 scontext=u:r:hal_awdisplayoutput_default:s0 tcontext=u:object_r:boot_status_prop:s0 tclass=file permissive=1
[   12.598117][  T343] pvrsrvkm 1800000.gpu: sunxiPostPowerState ePwrFlags:1 current power status:1 1
[   12.601525][  T344] healthd: battery none chg=
[   12.625376][  T344] healthd: battery none chg=
[   12.626833][  T229] type=1400 audit(1748526568.012:15): avc: denied { map } for comm="display.output-" path="/dev/__properties__/u:object_r:boot_status_prop:s0" dev="tmpfs" ino=80 scontext=u:r:hal_awdisplayoutput_default:s0 tcontext=u:object_r:boot_status_prop:s0 tclass=file permissive=1
[   12.637247][  T362] function = msa_startup =  =  =  =  =  =  =  =  = LINE = 1043.
[   12.637765][  T343] pvrsrvkm 1800000.gpu: sunxiPrePowerState ePwrFlags:1 current power status:0 1
[   12.637837][  T343] pvrsrvkm 1800000.gpu: sunxiPostPowerState ePwrFlags:1 current power status:1 1
[   12.637843][  T343] pvrsrvkm 1800000.gpu: sunxiPrePowerState ePwrFlags:1 current power status:1 1
[   12.637845][  T343] pvrsrvkm 1800000.gpu: sunxiPostPowerState ePwrFlags:1 current power status:1 1
[   12.637882][  T344] healthd: battery none chg=
[   12.640102][  T344] healthd: battery none chg=
[   12.641800][  T229] type=1400 audit(1748526568.056:16): avc: denied { read } for comm="android.hardwar" name="thermal" dev="sysfs" ino=9141 scontext=u:r:hal_power_default:s0 tcontext=u:object_r:sysfs_thermal:s0 tclass=dir permissive=1
[   12.643025][  T344] healthd: battery none chg=
[   12.645330][  T184] file system registered
[   12.647025][  T362] msa use sepical device node name  =  msa
[   12.652935][  T184] using random self ethernet address
[   12.652944][  T184] using random host ethernet address
[   12.656841][  T343] PVR_K:  343: FTrace event from "gpu_work_period" enabled
[   12.675510][  T229] type=1400 audit(1748526568.056:17): avc: denied { open } for comm="android.hardwar" path="/sys/class/thermal" dev="sysfs" ino=9141 scontext=u:r:hal_power_default:s0 tcontext=u:object_r:sysfs_thermal:s0 tclass=dir permissive=1
[   12.685146][  T362] ERROR! get gsensor_para failed, func:sunxi_gsensor_startup, line:304
[   12.693964][  T229] type=1400 audit(1748526568.072:18): avc: denied { setattr } for comm="init" name="ext_csd" dev="debugfs" ino=11031 scontext=u:r:init:s0 tcontext=u:object_r:debugfs_mmc:s0 tclass=file permissive=1
[   12.703702][  T362] =========gsensor script_get_err============
[   12.703710][  T362] msa_startup: err.
[   12.710831][  T184] sunxi-rfkill soc@3000000:rfkill: block state already is 1
[   12.714169][  T229] type=1400 audit(1748526568.088:19): avc: denied { integrity } for comm="init" lockdown_reason="debugfs access" scontext=u:r:init:s0 tcontext=u:r:init:s0 tclass=lockdown permissive=1
[   12.735457][  T344] healthd: battery none chg=
[   12.763702][  T184] pps_core: LinuxPPS API ver. 1 registered
[   12.900186][  T184] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[   12.914661][  T362] qst-qmi8658_i2c_init(line:1046)  qmi8658 A+G driver: init
[   12.922816][  T362] function=startup=========LINE=1025.
[   12.923403][  T184] PTP clock support registered
[   12.929763][  T362] ERROR! get gsensor_para failed, func:sunxi_gsensor_startup, line:304
[   12.943343][  T362] =========gsensor script_get_err============
[   12.950007][  T362] startup: err.
[   12.955627][  T184] dwmac-sunxi 4500000.ethernet: IRQ eth_wake_irq not found
[   12.963890][  T184] sunxi:stmmac-4500000.ethernet:[INFO]: Phy use soc fanout
[   12.972399][  T184] sunxi:stmmac-4500000.ethernet:[INFO]: Not found delay-maps in dts
[   12.981662][  T184] sunxi:stmmac-4500000.ethernet:[INFO]: RGMII use external transmit clock
[   12.991313][  T184] dwmac-sunxi 4500000.ethernet: User ID: 0x20, Synopsys ID: 0x53
[   12.999835][  T184] dwmac-sunxi 4500000.ethernet:    DWMAC4/5
[   13.006089][  T184] dwmac-sunxi 4500000.ethernet: DMA HW capability register supported
[   13.008638][  T389] [drm] sunxi-hdmi: [warn] hdmi drv check old dynamic range 1 unsupport!
[   13.014951][  T184] dwmac-sunxi 4500000.ethernet: RX Checksum Offload Engine supported
[   13.014954][  T184] dwmac-sunxi 4500000.ethernet: TX Checksum insertion supported
[   13.014955][  T184] dwmac-sunxi 4500000.ethernet: Wake-Up On Lan supported
[   13.015092][  T184] dwmac-sunxi 4500000.ethernet: Enable RX Mitigation via HW Watchdog Timer
[   13.015098][  T184] dwmac-sunxi 4500000.ethernet: Enabled RFS Flow TC (entries=8)
[   13.015103][  T184] dwmac-sunxi 4500000.ethernet: Using 32 bits DMA width
[   13.025269][  T362] ERROR! get ls_para failed, func:sunxi_ls_startup, line:563
[   13.033997][  T389] [drm] sunxi-hdmi: drm hdmi detect: disconnect
[   13.041985][  T362] startup: ls_fetch_sysconfig_para err.
[   13.049853][  T389] [drm] sunxi-hdmi: [warn] hdmi drv check old dynamic range 1 unsupport!
[   13.193111][  T184] sunxi:stmmac-4500000.ethernet:[INFO]: probe success (Version 0.3.2)
[   13.196839][  T418] [drm] sunxi-hdmi: drm hdmi detect: disconnect
[   13.218417][  T418] [drm] sunxi-hdmi: [warn] hdmi drv check old dynamic range 1 unsupport!
[   13.218839][  T184] IR NEC protocol handler initialized
[   13.240427][  T184] sun60iw2-r-pinctrl 7025000.pinctrl: pin PL4 already requested by 7025000.pinctrl:356; cannot claim for 7040000.irrx
[   13.254084][  T184] sun60iw2-r-pinctrl 7025000.pinctrl: pin-356 (7040000.irrx) status -22
[   13.263233][  T184] sun60iw2-r-pinctrl 7025000.pinctrl: could not request pin 356 (PL4) from group PL4  on device 7025000.pinctrl
[   13.276254][  T184] sunxi-rc-recv 7040000.irrx: Error applying setting, reverse things back
[   13.313983][  T184] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[   13.318667][  T418] [drm] sunxi-hdmi: drm hdmi detect: disconnect
[   13.323851][  T184] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[   13.330621][  T418] [drm] sunxi-hdmi: [warn] hdmi drv check old dynamic range 1 unsupport!
[   13.338692][   T95] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[   13.358365][   T95] cfg80211: failed to load regulatory.db
[   13.385258][  T184] deinterlace 5400000.deinterlace: Adding to iommu group 0
[   13.393262][  T184] sunxi:deinterlace:[INFO]: DI probe
[   13.403432][  T184] sunxi:ehci_sunxi:[INFO]: sunxi-ehci: EHCI SUNXI driver
[   13.417438][  T184] sunxi:sunxi_hci:[INFO]: sunxi ehci0-controller don't init wakeup source
[   13.426852][  T184] sunxi:ehci_sunxi:[INFO]: [sunxi-ehci0]: probe, pdev->name: 4101000.ehci0-controller, sunxi_ehci: 0xffffffc001df0030, 0x:ffffffc00ca4d000, irq_no:1d5
[   13.443656][  T184] sunxi:ehci_sunxi:[INFO]: [sunxi-ehci0]: Not init ehci0
[   13.451870][  T184] sunxi:sunxi_hci:[INFO]: sunxi ehci1-controller don't init wakeup source
[   13.461224][  T184] sunxi:ehci_sunxi:[INFO]: [sunxi-ehci1]: probe, pdev->name: 4200000.ehci1-controller, sunxi_ehci: 0xffffffc001df0930, 0x:ffffffc00ca65000, irq_no:1d6
[   13.478132][  T184] sunxi-ehci 4200000.ehci1-controller: supply drvvbus not found, using dummy regulator
[   13.488964][  T184] sunxi-ehci 4200000.ehci1-controller: supply hci not found, using dummy regulator
[   13.499325][  T184] sunxi-ehci 4200000.ehci1-controller: EHCI Host Controller
[   13.507340][  T184] sunxi-ehci 4200000.ehci1-controller: new USB bus registered, assigned bus number 1
[   13.517819][  T184] sunxi-ehci 4200000.ehci1-controller: irq 470, io mem 0x04200000
[   13.540163][  T184] sunxi-ehci 4200000.ehci1-controller: USB 2.0 started, EHCI 1.00
[   13.548795][  T184] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.15
[   13.558810][  T184] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   13.567653][  T184] usb usb1: Product: EHCI Host Controller
[   13.573870][  T184] usb usb1: Manufacturer: Linux 5.15.119-gc82a3c8d0b63-dirty ehci_hcd
[   13.582807][  T184] usb usb1: SerialNumber: sunxi-ehci
[   13.588827][  T184] hub 1-0:1.0: USB hub found
[   13.593830][  T184] hub 1-0:1.0: 1 port detected
[   13.608353][  T184] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[   13.618398][  T184] ohci-pci: OHCI PCI platform driver
[   13.627014][  T184] sunxi:ohci_sunxi:[INFO]: sunxi-ohci: OHCI SUNXI driver
[   13.635291][  T184] sunxi:sunxi_hci:[INFO]: sunxi ohci0-controller don't init wakeup source
[   13.644689][  T184] sunxi:ohci_sunxi:[INFO]: [sunxi-ohci0]: probe, pdev->name: 4101400.ohci0-controller, sunxi_ohci: 0xffffffc001df04b0
[   13.658331][  T184] sunxi:ohci_sunxi:[INFO]: [sunxi-ohci0]: Not init ohci0
[   13.666544][  T184] sunxi:sunxi_hci:[INFO]: sunxi ohci1-controller don't init wakeup source
[   13.675926][  T184] sunxi:ohci_sunxi:[INFO]: [sunxi-ohci1]: probe, pdev->name: 4200400.ohci1-controller, sunxi_ohci: 0xffffffc001df0db0
[   13.689639][  T184] sunxi-ohci 4200400.ohci1-controller: supply drvvbus not found, using dummy regulator
[   13.700480][  T184] sunxi-ohci 4200400.ohci1-controller: supply hci not found, using dummy regulator
[   13.710834][  T184] sunxi-ohci 4200400.ohci1-controller: OHCI Host Controller
[   13.718846][  T184] sunxi-ohci 4200400.ohci1-controller: new USB bus registered, assigned bus number 2
[   13.729379][  T184] sunxi-ohci 4200400.ohci1-controller: irq 472, io mem 0x04200400
[   13.800390][  T184] usb usb2: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 5.15
[   13.810415][  T184] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   13.819257][  T184] usb usb2: Product: OHCI Host Controller
[   13.825477][  T184] usb usb2: Manufacturer: Linux 5.15.119-gc82a3c8d0b63-dirty ohci_hcd
[   13.834416][  T184] usb usb2: SerialNumber: sunxi-ohci
[   13.840451][  T184] hub 2-0:1.0: USB hub found
[   13.845456][  T184] hub 2-0:1.0: 1 port detected
[   13.852562][   T95] usb 1-1: new high-speed USB device number 2 using sunxi-ehci
[   13.861921][  T184] sunxi:phy_sunxi_plat-6b00000.phy:[INFO]: resistance calibration supported - enabled, mode - V2
[   13.873943][  T184] sunxi:phy_sunxi_plat-6b00000.phy:[INFO]: phy provider register success
[   13.887686][  T184] sunxi:dwc3_sunxi_plat-12.usbc2:[ERR]: couldn't get drvvbus supply
[   13.897741][  T184] sunxi-cadence-combophy 6c00000.serdes: combophy1 set power ON
[   13.919545][  T441] sunxi:sound-ac101:[INFO]: 653 ac101_startup(): wait ac101 reset successfully, need 0x101/257
[   13.933017][  T184] xhci-hcd xhci-hcd.41.auto: xHCI Host Controller
[   13.935958][  T441] sunxi-ac101 14-001a: sunxi:sound-ac101ac101 sysclk source don't pll, don't need config pll
[   13.940064][  T184] xhci-hcd xhci-hcd.41.auto: new USB bus registered, assigned bus number 3
[   13.940166][  T184] xhci-hcd xhci-hcd.41.auto: hcc params 0x0118ffc5 hci version 0x120 quirks 0x0000000000010010
[   13.966260][  T441] dma dma0chan0: The timeout func is not suportted or chan->private is NULL, timeout mode not used
[   13.972188][  T184] xhci-hcd xhci-hcd.41.auto: irq 473, io mem 0x06a00000
[   13.991639][  T184] xhci-hcd xhci-hcd.41.auto: xHCI Host Controller
[   13.998683][  T184] xhci-hcd xhci-hcd.41.auto: new USB bus registered, assigned bus number 4
[   14.008116][  T184] xhci-hcd xhci-hcd.41.auto: Host supports USB 3.1 Enhanced SuperSpeed
[   14.017244][  T184] usb usb3: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.15
[   14.027289][  T184] usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   14.036167][  T184] usb usb3: Product: xHCI Host Controller
[   14.042403][  T184] usb usb3: Manufacturer: Linux 5.15.119-gc82a3c8d0b63-dirty xhci-hcd
[   14.051351][  T184] usb usb3: SerialNumber: xhci-hcd.41.auto
[   14.057671][   T95] usb 1-1: New USB device found, idVendor=1a40, idProduct=0101, bcdDevice= 1.11
[   14.060470][  T184] hub 3-0:1.0: USB hub found
[   14.067579][   T95] usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[   14.067581][   T95] usb 1-1: Product: USB 2.0 Hub
[   14.068916][   T95] hub 1-1:1.0: USB hub found
[   14.072601][  T184] hub 3-0:1.0: 1 port detected
[   14.085454][   T95] hub 1-1:1.0: 4 ports detected
[   14.086840][  T184] usb usb4: We don't know the algorithms for LPM for this host, disabling LPM.
[   14.111935][  T184] usb usb4: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.15
[   14.121962][  T184] usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[   14.130811][  T184] usb usb4: Product: xHCI Host Controller
[   14.137040][  T184] usb usb4: Manufacturer: Linux 5.15.119-gc82a3c8d0b63-dirty xhci-hcd
[   14.145986][  T184] usb usb4: SerialNumber: xhci-hcd.41.auto
[   14.152602][  T184] hub 4-0:1.0: USB hub found
[   14.157604][  T184] hub 4-0:1.0: 1 port detected
[   14.163161][  T184] sunxi:dwc3_sunxi_plat-12.usbc2:[INFO]: DesignWare USB3 Allwinner Glue Layer Driver(v1.0.22 2024-10-08 16:30)
[   14.184539][  T184] sunxi_usb_udc 4100000.udc-controller: sunxi:sunxi_usb_udc UDC Inner DMA Feature - wordaddr: 1, extend: enabled
[   14.201634][  T184] sunxi:sunxi_usbc:[INFO]: OTG can't find bcten-gpio, use default mode.
[   14.211003][  T184] sunxi:sunxi_usbc:[INFO]: get det_vbus is fail, -84
[   14.218364][  T184] sunxi:sunxi_usbc:[INFO]: get id is fail, -84
[   14.233759][  T184] usbcore: registered new interface driver option
[   14.246127][  T184] usbserial: USB Serial support registered for GSM modem (1-port)
[   14.257084][  T184] I2C functionality : OK...
[   14.262411][  T184] husb311 failed to find usb power
[   14.270733][  T184] husb311 13-004e: vbus is already Off
[   14.277974][  T184] sunxi:sunxi_usbc:[INFO]: usb role switch set null -> null
[   14.287433][  T448] husb311 13-004e: vbus is already Off
[   14.287730][  T184] husb311 13-004e: Vendor ID:0x2e99, Product ID:0x0311, probe success
[   14.294758][  T448] sunxi:sunxi_usbc:[INFO]: usb role switch set null -> null
[   14.331714][  T184] sunxi:lradc-2524000.lradc:[WARN]: get key_debounce failed, please check whether to enable key debounce
[   14.344215][  T184] sunxi:lradc-2524000.lradc:[WARN]: warn: filter_cnt not set, default value is 3
[   14.355347][  T184] input: sunxi-keyboard as /devices/platform/soc@3000000/2524000.lradc/input/input2
[   14.367079][  T184] sunxi:lradc-2524000.lradc:[INFO]: sunxi lradc init success
[   14.377856][  T184] sunxi:sunxi_smcdrm config service not available: FFFFFFFF
[   14.428922][  T184] sunxi:VE:[INFO]: 2373 sunxi_cedar_init(): sunxi cedar version 1.1
[   14.445886][  T184] sunxi-cedar 1c0e000.ve: Adding to iommu group 0
[   14.452968][  T184] sunxi:VE:[INFO]: 2295 sunxi_cedar_probe(): probe ve
[   14.460508][  T184] sunxi-cedar 1c0e000.ve: supply ve not found, using dummy regulator
[   14.469664][  T184] sunxi-cedar 1c0e000.ve: sunxi:VE no or not support operating-points-v2 node
[   14.479573][  T184] sunxi-cedar soc@3000000:ve1@1c0e000: Adding to iommu group 0
[   14.487906][  T184] sunxi:VE:[INFO]: 2298 sunxi_cedar_probe(): probe ve1
[   14.495464][  T184] sunxi-cedar 1c10000.ve2: Adding to iommu group 0
[   14.502611][  T184] sunxi:VE:[INFO]: 2301 sunxi_cedar_probe(): probe ve2
[   14.510241][  T184] sunxi-cedar 1c10000.ve2: supply ve not found, using dummy regulator
[   14.519484][  T184] sunxi-cedar 1c10000.ve2: sunxi:VE no or not support operating-points-v2 node
[   14.533175][  T184] reg-virt-consumer reg-virt-consumer.1.auto: DMA mask not set
[   14.541952][  T184] reg-virt-consumer reg-virt-consumer.2.auto: DMA mask not set
[   14.550587][  T184] reg-virt-consumer reg-virt-consumer.3.auto: DMA mask not set
[   14.559241][  T184] reg-virt-consumer reg-virt-consumer.4.auto: DMA mask not set
[   14.567912][  T184] reg-virt-consumer reg-virt-consumer.5.auto: DMA mask not set
[   14.576654][  T184] reg-virt-consumer reg-virt-consumer.6.auto: DMA mask not set
[   14.585462][  T184] reg-virt-consumer reg-virt-consumer.7.auto: DMA mask not set
[   14.594237][  T184] reg-virt-consumer reg-virt-consumer.8.auto: DMA mask not set
[   14.603129][  T184] reg-virt-consumer reg-virt-consumer.9.auto: DMA mask not set
[   14.611998][  T184] reg-virt-consumer reg-virt-consumer.10.auto: DMA mask not set
[   14.620799][  T184] reg-virt-consumer reg-virt-consumer.11.auto: DMA mask not set
[   14.629414][  T184] reg-virt-consumer reg-virt-consumer.12.auto: DMA mask not set
[   14.638020][  T184] reg-virt-consumer reg-virt-consumer.13.auto: DMA mask not set
[   14.646611][  T184] reg-virt-consumer reg-virt-consumer.14.auto: DMA mask not set
[   14.655215][  T184] reg-virt-consumer reg-virt-consumer.15.auto: DMA mask not set
[   14.663866][  T184] reg-virt-consumer reg-virt-consumer.16.auto: supply bldo1 not found, using dummy regulator
[   14.675256][  T184] reg-virt-consumer reg-virt-consumer.17.auto: supply bldo2 not found, using dummy regulator
[   14.686640][  T184] reg-virt-consumer reg-virt-consumer.18.auto: supply bldo3 not found, using dummy regulator
[   14.697990][  T184] reg-virt-consumer reg-virt-consumer.19.auto: supply bldo4 not found, using dummy regulator
[   14.709334][  T184] reg-virt-consumer reg-virt-consumer.20.auto: supply bldo5 not found, using dummy regulator
[   14.720692][  T184] reg-virt-consumer reg-virt-consumer.21.auto: supply cldo1 not found, using dummy regulator
[   14.732041][  T184] reg-virt-consumer reg-virt-consumer.22.auto: supply cldo2 not found, using dummy regulator
[   14.743409][  T184] reg-virt-consumer reg-virt-consumer.23.auto: supply cldo3 not found, using dummy regulator
[   14.754753][  T184] reg-virt-consumer reg-virt-consumer.24.auto: supply cldo4 not found, using dummy regulator
[   14.766146][  T184] reg-virt-consumer reg-virt-consumer.25.auto: supply cldo5 not found, using dummy regulator
[   14.777496][  T184] reg-virt-consumer reg-virt-consumer.26.auto: DMA mask not set
[   14.786234][  T184] reg-virt-consumer reg-virt-consumer.27.auto: DMA mask not set
[   14.794792][  T184] reg-virt-consumer reg-virt-consumer.28.auto: DMA mask not set
[   14.796543][  T317] husb311 13-004e: CC1: 0 - Open, CC2: 0 - Open
[   14.803345][  T184] reg-virt-consumer reg-virt-consumer.29.auto: DMA mask not set
[   14.810001][  T317] sunxi:sunxi_usbc:[INFO]: usb role switch set null -> null
[   14.818488][  T184] reg-virt-consumer reg-virt-consumer.30.auto: DMA mask not set
[   14.834989][  T184] reg-virt-consumer reg-virt-consumer.31.auto: DMA mask not set
[   14.843734][  T184] reg-virt-consumer reg-virt-consumer.32.auto: DMA mask not set
[   14.852624][  T184] reg-virt-consumer reg-virt-consumer.33.auto: DMA mask not set
[   14.861411][  T184] reg-virt-consumer reg-virt-consumer.34.auto: DMA mask not set
[   14.870127][  T184] reg-virt-consumer reg-virt-consumer.35.auto: DMA mask not set
[   14.878712][  T184] reg-virt-consumer reg-virt-consumer.36.auto: DMA mask not set
[   14.887398][  T184] reg-virt-consumer reg-virt-consumer.37.auto: DMA mask not set
[   14.896274][  T184] reg-virt-consumer reg-virt-consumer.38.auto: DMA mask not set
[   14.904995][  T184] reg-virt-consumer reg-virt-consumer.39.auto: DMA mask not set
[   14.913412][  T184] reg-virt-consumer reg-virt-consumer.39.auto: supply dc1sw1 not found, using dummy regulator
[   14.924909][  T184] reg-virt-consumer reg-virt-consumer.40.auto: DMA mask not set
[   14.933333][  T184] reg-virt-consumer reg-virt-consumer.40.auto: supply dc1sw2 not found, using dummy regulator
[   15.102309][    T1] init: Command 'mkdir /sys/kernel/tracing/instances/bootreceiver 0700 system system' action=bootreceiver.enable=1 && ro.product.cpu.abilist64=* (/system/etc/init/hw/init.rc:656) took 67ms and succeeded
[   15.126380][    T1] init: processing action (net.tcp_def_init_rwnd=*) from (/system/etc/init/hw/init.rc:1211)
[   15.137848][    T1] init: processing action (sys.init.perf_lsm_hooks=1) from (/system/etc/init/hw/init.rc:1222)
[   15.149422][    T1] init: processing action (security.perf_harden=1) from (/system/etc/init/hw/init.rc:1236)
[   15.160789][    T1] init: processing action (ro.debuggable=1) from (/system/etc/init/hw/init.rc:1271)
[   15.171367][    T1] init: processing action (init.svc.audioserver=running) from (/system/etc/init/audioserver.rc:38)
[   15.183165][    T1] init: service 'vendor.audio-hal' requested start, but it is already running (flags: 4)
[   15.193983][    T1] init: Command 'start vendor.audio-hal-4-0-msd' action=init.svc.audioserver=running (/system/etc/init/audioserver.rc:40) took 0ms and failed: service vendor.audio-hal-4-0-msd not found
[   15.214279][    T1] init: Command 'start audio_proxy_service' action=init.svc.audioserver=running (/system/etc/init/audioserver.rc:41) took 0ms and failed: service audio_proxy_service not found
[   15.233625][    T1] init: Command 'start vendor.audio-hal-2-0' action=init.svc.audioserver=running (/system/etc/init/audioserver.rc:43) took 0ms and failed: service vendor.audio-hal-2-0 not found
[   15.390477][  T104] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: have to disable cqe when send cmd with data!!!, CQHCI_CFG:2001020
[   15.404602][    C0] sunxi:sunxi_mmc_host-4023000.sdmmc:[INFO]: cmd with data done, restore cqe enable and halt:2001021,1,6,6
[   15.716746][  T337] [Awinic] [14-0059]aw_monitor_get_battery_status: get power supply failed
[   15.720789][  T536] read descriptors
[   15.726930][  T337] [Awinic] [14-0058]aw_monitor_get_battery_status: get power supply failed
[   15.736197][  T536] read strings
[   15.739980][  T337] [Awinic] aw87xxx_hal_monitor_time_get:get monitor time 3000
[   15.756692][  T317] husb311 13-004e: CC1: 3 - Rp-def, CC2: 3 - Rp-def
[   15.764332][  T317] sunxi:sunxi_usbc:[INFO]: usb role switch set null -> device
[   15.772840][  T317] sunxi:sunxi_usbc:[INFO]: auto set usb role [device]
[   15.780576][  T317] sunxi:sunxi_usbc:[INFO]: insmod_device_driver
[   15.780576][  T317]
[   15.790671][  T317] sunxi_usb_udc 4100000.udc-controller: supply udc not found, using dummy regulator
[   16.435316][  T317] sunxi:sunxi_usb_udc:[WARN]: sunxi_set_cur_vol_work()537 WARN: get power supply failed
[   16.522187][  T317] android_work: sent uevent USB_STATE=CONNECTED
[   16.687823][   T21] sunxi:sunxi_usb_udc:[WARN]: sunxi_set_cur_vol_work()537 WARN: get power supply failed
[   16.780216][  T317] sunxi:sunxi_usb_udc:[WARN]: sunxi_vbus_det_work()3728 WARN: get power supply failed
[   16.791713][  T317] android_work: sent uevent USB_STATE=DISCONNECTED
[   16.802842][  T317] android_work: sent uevent USB_STATE=CONNECTED
[   16.831884][  T317] android_work: sent uevent USB_STATE=CONFIGURED
[   18.341302][  T229] type=1400 audit(1748526573.840:54): avc: denied { open } for comm="getprop" path="/dev/__properties__/u:object_r:aac_drc_prop:s0" dev="tmpfs" ino=59 scontext=u:r:shell:s0 tcontext=u:object_r:aac_drc_prop:s0 tclass=file permissive=1
[   18.345749][  T608] audit: audit_backlog=65 > audit_backlog_limit=64
[   18.364522][  T362] audit: audit_backlog=65 > audit_backlog_limit=64
[   18.364531][  T362] audit: audit_lost=1 audit_rate_limit=0 audit_backlog_limit=64
[   18.364535][  T362] audit: backlog limit exceeded
[   18.366819][  T229] type=1400 audit(1748526573.840:55): avc: denied { getattr } for comm="getprop" path="/dev/__properties__/u:object_r:aac_drc_prop:s0" dev="tmpfs" ino=59 scontext=u:r:shell:s0 tcontext=u:object_r:aac_drc_prop:s0 tclass=file permissive=1
[   18.370523][  T344] healthd: battery none chg=
[   18.372078][  T344] healthd: battery none chg=
[   18.372476][  T344] healthd: battery none chg=
[   18.373547][  T608] audit: audit_lost=2 audit_rate_limit=0 audit_backlog_limit=64
[   18.381050][  T229] type=1400 audit(1748526573.840:56): avc: denied { map } for comm="getprop" path="/dev/__properties__/u:object_r:aac_drc_prop:s0" dev="tmpfs" ino=59 scontext=u:r:shell:s0 tcontext=u:object_r:aac_drc_prop:s0 tclass=file permissive=1
[   18.382334][  T344] healthd: battery none chg=
[   18.382911][  T344] healthd: battery none chg=
[   18.385306][  T344] healthd: battery none chg=
[   18.389152][  T608] audit: backlog limit exceeded
[   18.394629][  T229] type=1400 audit(1748526573.840:57): avc: denied { open } for comm="getprop" path="/dev/__properties__/u:object_r:ab_update_gki_prop:s0" dev="tmpfs" ino=61 scontext=u:r:shell:s0 tcontext=u:object_r:ab_update_gki_prop:s0 tclass=file permissive=1
[   18.419640][  T608] audit: audit_backlog=65 > audit_backlog_limit=64
[   18.424660][  T229] type=1400 audit(1748526573.840:58): avc: denied { getattr } for comm="getprop" path="/dev/__properties__/u:object_r:ab_update_gki_prop:s0" dev="tmpfs" ino=61 scontext=u:r:shell:s0 tcontext=u:object_r:ab_update_gki_prop:s0 tclass=file permissive=1
[   18.429511][  T608] audit: audit_lost=3 audit_rate_limit=0 audit_backlog_limit=64
[   18.434564][  T229] type=1400 audit(1748526573.840:59): avc: denied { map } for comm="getprop" path="/dev/__properties__/u:object_r:ab_update_gki_prop:s0" dev="tmpfs" ino=61 scontext=u:r:shell:s0 tcontext=u:object_r:ab_update_gki_prop:s0 tclass=file permissive=1
[   18.442787][  T608] audit: backlog limit exceeded
[   18.442899][  T608] audit: audit_backlog=65 > audit_backlog_limit=64
[   18.469395][  T229] type=1400 audit(1748526573.840:60): avc: denied { open } for comm="getprop" path="/dev/__properties__/u:object_r:adaptive_haptics_prop:s0" dev="tmpfs" ino=62 scontext=u:r:shell:s0 tcontext=u:object_r:adaptive_haptics_prop:s0 tclass=file permissive=1
[   18.620830][  T229] type=1400 audit(1748526573.840:61): avc: denied { getattr } for comm="getprop" path="/dev/__properties__/u:object_r:adaptive_haptics_prop:s0" dev="tmpfs" ino=62 scontext=u:r:shell:s0 tcontext=u:object_r:adaptive_haptics_prop:s0 tclass=file permissive=1
[   18.647877][  T229] type=1400 audit(1748526573.840:62): avc: denied { map } for comm="getprop" path="/dev/__properties__/u:object_r:adaptive_haptics_prop:s0" dev="tmpfs" ino=62 scontext=u:r:shell:s0 tcontext=u:object_r:adaptive_haptics_prop:s0 tclass=file permissive=1
[   18.674481][  T229] type=1400 audit(1748526573.840:63): avc: denied { open } for comm="getprop" path="/dev/__properties__/u:object_r:adbd_prop:s0" dev="tmpfs" ino=64 scontext=u:r:shell:s0 tcontext=u:object_r:adbd_prop:s0 tclass=file permissive=1
[   18.810467][  T344] healthd: battery none chg=
[   18.816778][  T344] healthd: battery none chg=
[   18.822488][  T344] healthd: battery none chg=
[   18.828438][  T344] healthd: battery none chg=
[   24.999219][  T441] sunxi:sound-ac101:[INFO]: 653 ac101_startup(): wait ac101 reset successfully, need 0x101/257
[   25.016396][  T441] sunxi-ac101 14-001a: sunxi:sound-ac101ac101 sysclk source don't pll, don't need config pll
[   25.172235][   T95] sunxi:sunxi_pd_test-soc@3000000:pd_pcie_test@0:[WARN]: runtime_suspend disable clock
[   25.182858][   T95] sunxi:sunxi_pd_test-soc@3000000:pd_usb2_test@0:[WARN]: runtime_suspend disable clock
[   25.193652][   T95] sunxi:sunxi_pd_test-soc@3000000:pd_de_sys_test@0:[WARN]: runtime_suspend disable clock
[   25.204584][   T95] sunxi:sunxi_pd_test-soc@3000000:pd_vo_test@0:[WARN]: runtime_suspend disable clock
[   25.215000][   T95] sunxi:sunxi_pd_test-soc@3000000:pd_vo1_test@0:[WARN]: runtime_suspend disable clock
[   28.553250][    T1] init: Sending signal 9 to service 'idmap2d' (pid 483) process group...
[   28.568012][    T1] libprocessgroup: Successfully killed process cgroup uid 1000 pid 483 in 5ms
[   28.578387][    T1] init: Control message: Processed ctl.stop for 'idmap2d' from pid: 450 (system_server)
[   28.589418][    T1] init: Service 'idmap2d' (pid 483) received signal 9
[   29.077868][  T615] read descriptors
[   29.081889][  T615] read strings
[   29.085581][  T615] read descriptors
[   29.089583][  T615] read strings
[   29.757067][  T344] healthd: battery none chg=
[   29.866566][    T1] init: starting service 'vendor.wifi_hal_legacy'...
[   29.877917][    T1] init: Control message: Processed ctl.interface_start for 'android.hardware.wifi@1.0::IWifi/default' from pid: 215 (/system/bin/hwservicemanager)
[   29.895306][    T1] init: service 'vendor.wifi_hal_legacy' requested start, but it is already running (flags: 134)
[   29.907141][    T1] init: Control message: Processed ctl.interface_start for 'android.hardware.wifi@1.0::IWifi/default' from pid: 215 (/system/bin/hwservicemanager)
[   29.997174][  T344] healthd: battery none chg=
[   30.014342][ T1002] >>> rwnx_mod_init()
[   30.018712][ T1002] rwnx 20240730-005-6.4.3.0 - - 241c091M (master)
[   30.025735][ T1002] Driver Release Tag: aic-rwnx-compatible(sdio)-20240730-005
[   30.033872][ T1002] aicbsp: aicbsp_set_subsys, subsys: AIC_WIFI, state to: 1
[   30.041778][ T1002] aicbsp: aicbsp_set_subsys, power state change to 1 dure to AIC_WIFI
[   30.050806][ T1002] aicbsp: aicbsp_platform_power_on
[   30.060502][ T1002] sunxi-rfkill soc@3000000:rfkill: bus_index: 1
[   30.067930][ T1002] aicbsp: aicbsp_platform_power_on disable MMC_CAP_UHS_DDR50 for host 00000000b1358c3e
[   30.078886][  T344] healthd: battery none chg=
[   30.089841][ T1002] sunxi-rfkill soc@3000000:rfkill: wlan power on success
[   30.147563][  T160] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm UP vdd 21 width 1 timing LEGACY(SDR12) dt B
[   30.164459][  T310] dwmac-sunxi 4500000.ethernet eth0: PHY [stmmac-0:01] driver [Generic PHY] (irq=POLL)
[   30.175596][  T160] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   30.176352][  T310] dwmac-sunxi 4500000.ethernet eth0: Register MEM_TYPE_PAGE_POOL RxQ-0
[   30.201056][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 52, RTO !!
[   30.208168][  T310] dwmac4: Master AXI performs fixed burst length
[   30.211245][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 52, RTO !!
[   30.217317][  T310] dwmac-sunxi 4500000.ethernet eth0: No Safety Features support found
[   30.226572][  T160] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   30.245548][  T310] dwmac-sunxi 4500000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported
[   30.252559][  T160] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   30.260130][  T344] healthd: battery none chg=
[   30.275047][  T310] dwmac-sunxi 4500000.ethernet eth0: registered PTP clock
[   30.286773][  T344] healthd: battery none chg=
[   30.287964][    C0] sunxi:sunxi_mmc_host-4021000.sdmmc:[ERR]: smc 1 p1 err, cmd 11, RE !!
[   30.291883][  T310] dwmac-sunxi 4500000.ethernet eth0: configuring for phy/rgmii link mode
[   30.292309][  T344] healthd: battery none chg=
[   30.292438][  T344] healthd: battery none chg=
[   30.292564][  T344] healthd: battery none chg=
[   30.292676][  T344] healthd: battery none chg=
[   30.292784][  T344] healthd: battery none chg=
[   30.300905][  T160] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm OFF vdd 0 width 1 timing LEGACY(SDR12) dt B
[   30.303531][  T160] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 0Hz bm PP pm UP vdd 21 width 1 timing LEGACY(SDR12) dt B
[   30.310683][  T310] 8021q: adding VLAN 0 to HW filter on device eth0
[   30.327762][  T160] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 400000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   30.413655][  T160] mmc1: queuing unknown CIS tuple 0x10 [07 00 11 00 8e] (5 bytes)
[   30.427681][  T160] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 50000000Hz bm PP pm ON vdd 21 width 1 timing LEGACY(SDR12) dt B
[   30.442190][  T160] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 50000000Hz bm PP pm ON vdd 21 width 4 timing LEGACY(SDR12) dt B
[   30.456687][  T160] mmc1: queuing unknown CIS tuple 0x10 [07 00 31 00 32] (5 bytes)
[   30.466396][  T160] mmc1: new SDIO card at address 96ec
[   30.489266][ T1002] aicbsp: aicbsp_sdio_probe:2
[   30.494361][ T1002] aicbsp: aicbsp_sdio_probe:2, matched chip: aic8800d
[   30.501775][ T1002] aicbsp: aicbsp_sdio_probe after replace:1
[   30.508193][ T1002] aicbsp: aicbsp_sdio_probe host max clock frequecy: 208000000
[   30.516459][ T1002] aicbsp: aicwf_sdio_reg_init
[   30.521609][ T1002] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 70000000Hz bm PP pm ON vdd 21 width 4 timing LEGACY(SDR12) dt B
[   30.535990][ T1002] aicbsp: Set SDIO Clock 66 MHz
[   30.543179][ T1002] aicbsp: aicbsp_8800d_fw_init, rev id: 0x7, subrev id: 0x20
[   30.554646][ T1002] rwnx_request_firmware, name: fw_patch_table_u03.bin
[   30.562083][ T1002] aicbt_patch_info_unpack bt patch version: - Jun 24 2024 21:01:47 - git 0bcba10
[   30.572099][ T1002] aicbt_init no patch info found in bt fw
[   30.578885][ T1002] rwnx_request_firmware, name: fw_adid_u03.bin
[   30.587722][ T1002] rwnx_request_firmware, name: fw_patch_u03.bin
[   30.610188][ T1002] aicbt_patch_table_load bt uart baud: 1500000, flowctrl: 1, lpm_enable: 1, tx_pwr: 24608, bt mode:255.
[   30.655276][ T1002] rwnx_request_firmware, name: fmacfw.bin
[   30.731715][ T1002] rwnx_request_firmware, name: fmacfw_patch.bin
[   30.748002][ T1002] aicbsp: crypto data BBAD831C477E445AC3A462102C50D125
[   30.755693][ T1002] aicbsp: verify data 52C1C402DC4E526F51C01D59442A8008
[   30.764406][ T1002] aicsdio: aicwf_sdio_probe:1
[   30.769617][ T1002] aicsdio: aicwf_sdio_reg_init
[   30.775410][ T1002] sunxi:sunxi_mmc_host-4021000.sdmmc:[INFO]: sdc set ios:clk 70000000Hz bm PP pm ON vdd 21 width 4 timing LEGACY(SDR12) dt B
[   30.790214][ T1002] aicsdio: Set SDIO Clock 66 MHz
[   30.796167][    C7] aicbsp: err:<aicwf_sdio_bus_pwrctl,1257>: bus down
[   30.806825][ T1002] aicbsp: aicbsp_resv_mem_alloc_skb, alloc resv_mem_txdata succuss, id: 0, size: 98304
[   30.818886][ T1002] >>> rwnx_platform_init()
[   30.824712][ T1002] >>> rwnx_cfg80211_init()
[   30.829988][ T1002] rwnx_cfg80211_init sizeof(struct rwnx_hw):47616
[   30.839359][ T1002] >>> rwnx_init_aic()
[   30.843701][ T1002] >>> rwnx_cmd_mgr_init()
[   30.852307][ T1002] tcp_ack_init
[   30.856650][ T1002] >>> rwnx_send_set_stack_start_req()
[   30.865250][ T1002] is 5g support = 1, vendor_info = 0x21
[   30.871750][ T1002] Firmware Version: di Nov 14 2024 17:34:41 - g9aed4718
[   30.871769][ T1002] >>> rwnx_platform_on()
[   30.884313][ T1002] >>> rwnx_plat_fmac_load()
[   30.889578][ T1002] userconfig file path:aic_userconfig.txt
[   30.897883][ T1002] rwnx_plat_userconfig_parsing, enable = 1
[   30.908928][ T1002] rwnx_plat_userconfig_parsing, dsss = 10
[   30.915284][ T1002] rwnx_plat_userconfig_parsing, ofdmlowrate_2g4 = 11
[   30.922595][ T1002] rwnx_plat_userconfig_parsing, ofdm64qam_2g4 = 10
[   30.930072][ T1002] rwnx_plat_userconfig_parsing, ofdm256qam_2g4 = 10
[   30.937650][ T1002] rwnx_plat_userconfig_parsing, ofdm1024qam_2g4 = 9
[   30.945329][ T1002] rwnx_plat_userconfig_parsing, ofdmlowrate_5g = 11
[   30.953537][ T1002] rwnx_plat_userconfig_parsing, ofdm64qam_5g = 10
[   30.961230][ T1002] rwnx_plat_userconfig_parsing, ofdm256qam_5g = 10
[   30.968681][ T1002] rwnx_plat_userconfig_parsing, ofdm1024qam_5g = 9
[   30.977630][ T1002] rwnx_plat_userconfig_parsing, ofst_enable = 1
[   30.984742][ T1002] rwnx_plat_userconfig_parsing, ofst_chan_1_4 = -5
[   30.992222][ T1002] rwnx_plat_userconfig_parsing, ofst_chan_5_9 = -2
[   31.002539][ T1002] rwnx_plat_userconfig_parsing, ofst_chan_10_13 = -2
[   31.010779][ T1002] rwnx_plat_userconfig_parsing, ofst_chan_36_64 = -5
[   31.018437][ T1002] rwnx_plat_userconfig_parsing, ofst_chan_100_120 = -6
[   31.026217][ T1002] rwnx_plat_userconfig_parsing, ofst_chan_122_140 = -6
[   31.033983][ T1002] rwnx_plat_userconfig_parsing, ofst_chan_142_165 = 4
[   31.041585][ T1002] >>> rwnx_send_txpwr_idx_req()
[   31.048236][ T1002] >>> rwnx_send_txpwr_ofst_req()
[   31.054049][ T1002] >>> rwnx_send_rf_calib_req()
[   31.390545][ T1002] get macaddr: 94:ff:6e:cd:1f:cc
[   31.396015][ T1002] >>> rwnx_send_reset()
[   31.401929][ T1002] >>> rwnx_send_version_req()
[   31.407285][ T1002] >>> rwnx_set_vers()
[   31.411583][ T1002] >>> rwnx_send_me_config_req()
[   31.416835][ T1002] ieee80211 phy0: HT supp 1, VHT supp 1, HE supp 1
[   31.424666][ T1002] >>> rwnx_send_me_chan_config_req()
[   31.431003][ T1002] >>> rwnx_send_me_chan_config_req()
[   31.437213][ T1002] >>> rwnx_dbgfs_register()
[   31.442192][ T1002] rwnx_interface_add: wlan%d, 2, 10
[   31.442226][ T1002] interface add:94 ff 6e cd 1f cc
[   31.460241][ T1002] ieee80211 phy0: New interface create wlan0
[   31.500677][ T1002] >>> rwnx_open()
[   31.504653][ T1002] >>> rwnx_send_me_set_lp_level()
[   31.510152][ T1002] rwnx_send_me_set_lp_level 1 1
[   31.518129][ T1002] >>> rwnx_send_start()
[   31.524513][ T1002] >>> rwnx_send_coex_req()
[   31.529878][ T1002] rwnx_open rwnx_vif->drv_flags:4
[   31.535501][ T1002] >>> rwnx_send_add_if()
[   31.548562][  T229] type=1107 audit(1748526587.044:313): uid=0 auid=4294967295 ses=4294967295 subj=u:r:init:s0 msg='avc: denied { set } for property=vendor.wlan.firmware.version pid=1002 uid=1010 gid=1010 scontext=u:r:hal_wifi_default:s0 tcontext=u:object_r:vendor_default_prop:s0 tclass=property_service permissive=1'
[   31.653165][    T1] init: starting service 'wpa_supplicant'...
[   31.660385][    T1] init: Created socket '/dev/socket/wpa_wlan0', mode 660, user 1010, group 1010
[   31.749168][ T1190] capability: warning: `wpa_supplicant' uses 32-bit capabilities (legacy support in use)
[   31.920048][ T1190] rwnx_virtual_interface_add: 10, p2p-dev-wlan0
[   31.926970][ T1190] rwnx_virtual_interface_add, ifname=p2p-dev-wlan0, wdev=00000000670e1c4a, vif_idx=1
[   31.937393][ T1190] p2p dev addr=94 ff 6e cd 1f cd
[   31.945929][ T1190] P2P interface started
[   32.009541][ T1190] IOCTL PRIVATE
[   32.013322][ T1190] android_priv_cmd: Android private cmd "COUNTRY CN" on wlan0
[   32.021779][ T1190] wrong cmd:(null) in handle_private_cmd
[   32.045484][ T1190] IOCTL PRIVATE
[   32.049702][ T1190] android_priv_cmd: Android private cmd "SETSUSPENDMODE 1" on wlan0
[   32.058898][ T1190] >>> rwnx_send_me_set_lp_level()
[   32.064553][ T1190] rwnx_send_me_set_lp_level 1 0
[   32.067369][  T229] type=1400 audit(1748526587.564:314): avc: granted { read } for comm="rkstack.process" name="psched" dev="proc" ino=4026531986 scontext=u:r:network_stack:s0 tcontext=u:object_r:proc_net:s0 tclass=file
[   32.072791][ T1190] set suspend mode 1
[   32.093242][  T229] type=1400 audit(1748526587.564:315): avc: granted { read open } for comm="rkstack.process" path="/proc/1204/net/psched" dev="proc" ino=4026531986 scontext=u:r:network_stack:s0 tcontext=u:object_r:proc_net:s0 tclass=file
[   32.120002][  T229] type=1400 audit(1748526587.564:316): avc: granted { getattr } for comm="rkstack.process" path="/proc/1204/net/psched" dev="proc" ino=4026531986 scontext=u:r:network_stack:s0 tcontext=u:object_r:proc_net:s0 tclass=file
[   33.059997][  T338] aicbt_set_power: start_block=1
[   33.065431][  T338] aicbsp: aicbsp_set_subsys, subsys: AIC_BLUETOOTH, state to: 0
[   33.074320][  T338] aicbsp: aicbsp_set_subsys, power state no need to change, current: 1
[   33.083431][  T338] aicbt_set_power: end_block=1
[   33.088950][  T338] aicbt_set_power: start_block=0
[   33.094393][  T338] aicbsp: aicbsp_set_subsys, subsys: AIC_BLUETOOTH, state to: 1
[   33.102957][  T338] aicbsp: aicbsp_set_subsys, power state no need to change, current: 1
[   33.112201][  T338] aicbt_set_power: end_block=0
[   33.127845][ T1002] >>> rwnx_close()
[   33.131914][ T1002] aicwf_sdio mmc1:96ec:1 wlan0: CLOSE
[   33.137906][    T8] >>> rwnx_cfg80211_del_key()
[   33.138859][ T1002] >>> rwnx_send_remove_if()
[   33.142993][    T8] >>> rwnx_send_key_del()
[   33.145537][    T8] >>> rwnx_cfg80211_del_key()
[   33.148618][ T1002] >>> rwnx_send_msg1()
[   33.152573][    T8] >>> rwnx_send_key_del()
[   33.153485][    T8] >>> rwnx_cfg80211_del_key()
[   33.158626][ T1002] >>> rwnx_send_coex_req()
[   33.163220][    T8] >>> rwnx_send_key_del()
[   33.167525][ T1002] >>> rwnx_send_reset()
[   33.172234][    T8] >>> rwnx_cfg80211_del_key()
[   33.178309][ T1002] >>> rwnx_send_me_config_req()
[   33.181730][    T8] >>> rwnx_send_key_del()
[   33.185845][ T1002] ieee80211 phy0: HT supp 1, VHT supp 1, HE supp 1
[   33.186282][ T1002] >>> rwnx_send_me_chan_config_req()
[   33.191582][    T8] >>> rwnx_cfg80211_del_key()
[   33.196765][ T1002] rwnx_close rwnx_vif->drv_flags:0
[   33.201120][    T8] >>> rwnx_send_key_del()
[   33.229682][    T8] >>> rwnx_cfg80211_del_key()
[   33.234761][    T8] >>> rwnx_send_key_del()
[   33.240302][ T1002] >>> rwnx_open()
[   33.244215][ T1002] >>> rwnx_send_me_set_lp_level()
[   33.249663][ T1002] rwnx_send_me_set_lp_level 1 1
[   33.255483][ T1002] >>> rwnx_send_start()
[   33.260675][ T1002] >>> rwnx_send_coex_req()
[   33.265850][ T1002] rwnx_open rwnx_vif->drv_flags:4
[   33.271416][ T1002] >>> rwnx_send_add_if()
[   33.276561][  T160] >>> rwnx_send_me_chan_config_req()
[   33.282716][  T160] >>> rwnx_send_me_chan_config_req()
[   33.320559][  T338] [BT_LPM] bluesleep_get_uart_port: bluesleep_get_uart_port get uart_port from blusleep_uart_dev: 2501000.uart, port irq: 427
[   33.368684][ T1190] IOCTL PRIVATE
[   33.372412][ T1190] android_priv_cmd: Android private cmd "BTCOEXSCAN-STOP" on wlan0
[   33.381074][ T1190] wrong cmd:(null) in handle_private_cmd
[   33.387730][ T1190] IOCTL PRIVATE
[   33.391588][ T1190] android_priv_cmd: Android private cmd "RXFILTER-STOP" on wlan0
[   33.400173][ T1190] wrong cmd:(null) in handle_private_cmd
[   33.406901][ T1190] IOCTL PRIVATE
[   33.410622][ T1190] android_priv_cmd: Android private cmd "RXFILTER-ADD 2" on wlan0
[   33.419192][ T1190] wrong cmd:(null) in handle_private_cmd
[   33.425748][ T1190] IOCTL PRIVATE
[   33.429483][ T1190] android_priv_cmd: Android private cmd "RXFILTER-START" on wlan0
[   33.438041][ T1190] wrong cmd:(null) in handle_private_cmd
[   33.444459][ T1190] IOCTL PRIVATE
[   33.448179][ T1190] android_priv_cmd: Android private cmd "RXFILTER-STOP" on wlan0
[   33.456642][ T1190] wrong cmd:(null) in handle_private_cmd
[   33.463066][ T1190] IOCTL PRIVATE
[   33.466800][ T1190] android_priv_cmd: Android private cmd "RXFILTER-ADD 3" on wlan0
[   33.475373][ T1190] wrong cmd:(null) in handle_private_cmd
[   33.481777][ T1190] IOCTL PRIVATE
[   33.485498][ T1190] android_priv_cmd: Android private cmd "RXFILTER-START" on wlan0
[   33.494062][ T1190] wrong cmd:(null) in handle_private_cmd
[   33.500593][ T1190] IOCTL PRIVATE
[   33.504314][ T1190] android_priv_cmd: Android private cmd "SETSUSPENDMODE 1" on wlan0
[   33.513079][ T1190] >>> rwnx_send_me_set_lp_level()
[   33.518526][ T1190] rwnx_send_me_set_lp_level 1 0
[   33.524545][ T1190] set suspend mode 1
[   33.579613][ T1190] IOCTL PRIVATE
[   33.583365][ T1190] android_priv_cmd: Android private cmd "SETSUSPENDMODE 0" on wlan0
[   33.592132][ T1190] >>> rwnx_send_me_set_lp_level()
[   33.597578][ T1190] rwnx_send_me_set_lp_level 1 1
[   33.603637][ T1190] set suspend mode 0
[   34.132751][    T1] init: starting service 'idmap2d'...
[   34.142467][    T1] init: Control message: Processed ctl.start for 'idmap2d' from pid: 450 (system_server)
[   34.348171][    C7] [BT_LPM] bluesleep_rx_timer_expire: bluesleep_rx_timer_expire
[   35.326899][    T1] init: processing action (sys.boot_completed=1) from (/system/etc/init/hw/init.rc:1193)
[   35.339953][    T1] init: starting service 'exec 19 (/bin/rm -rf /data/per_boot)'...
[   35.354540][    T1] init: SVC_EXEC service 'exec 19 (/bin/rm -rf /data/per_boot)' pid 1584 (uid 1000 gid 1000+0 context default) started; waiting...
[   35.370880][    T1] init: Service 'exec 19 (/bin/rm -rf /data/per_boot)' (pid 1584) exited with status 0 waiting took 0.018000 seconds
[   35.374592][  T500] >>> rwnx_cfg80211_scan()
[   35.384489][    C7] [BT_LPM] bluesleep_rx_timer_expire: bluesleep_rx_timer_expire
[   35.384773][    T1] init: Sending signal 9 to service 'exec 19 (/bin/rm -rf /data/per_boot)' (pid 1584) process group...
[   35.389347][  T500] >>> rwnx_send_scanu_req()
[   35.398294][    T1] libprocessgroup: Successfully killed process cgroup uid 1000 pid 1584 in 0ms
[   35.426295][    T1] init: processing action (sys.boot_completed=1) from (/vendor/etc/init/hw/init.sun60iw2p1.rc:138)
[   35.438798][    T1] init: Command 'insmod /vendor/lib/modules/kheaders.ko' action=sys.boot_completed=1 (/vendor/etc/init/hw/init.sun60iw2p1.rc:139) took 0ms and failed: open("/vendor/lib/modules/kheaders.ko") failed: No such file or directory
[   35.754224][  T184] init (184): drop_caches: 3
[   35.754822][  T344] healthd: battery none chg=
[   35.788907][    T1] zram0: detected capacity change from 0 to 9060872
[   35.846457][    T1] mkswap: Swapspace size: 4530432k, UUID=aa727031-8a5d-4aba-ae20-95608634a812
[   35.858906][    T1] Adding 4530432k swap on /dev/block/zram0.  Priority:-2 extents:1 across:4530432k SS
[   35.893905][  T229] type=1400 audit(1748526591.392:317): avc: denied { entrypoint } for comm="init" path="/system/bin/fix_traceing" dev="dm-0" ino=8778258 scontext=u:r:shell:s0 tcontext=u:object_r:system_file:s0 tclass=file permissive=1
[   35.955090][  T229] type=1400 audit(1748526591.452:318): avc: denied { dac_read_search } for comm="runin.sh" capability=2 scontext=u:r:shell:s0 tcontext=u:r:shell:s0 tclass=capability permissive=1
[   35.989174][  T229] type=1400 audit(1748526591.484:319): avc: denied { search } for comm="treadahead" name="/" dev="mmcblk0p22" ino=2 scontext=u:r:vendor_init:s0 tcontext=u:object_r:unlabeled:s0 tclass=dir permissive=1
[   35.989614][ T1658] treadahead: /treadahead/readahead_file_offset not exist;
[   36.021142][ T1658] treadahead: go to read trace
[   36.226833][  T344] healthd: battery none chg=
[   36.233557][  T344] healthd: battery none chg=
[   36.242210][  T184] get ctp_power is fail, -22
[   36.247556][  T184] get ctp_power_ldo_vol is fail, -22
[   36.255059][  T184] sunxi_ctp_startup: ctp_power_io is invalid.
[   36.261894][  T184] get ctp_gesture_wakeup fail, no gesture wakeup
[   36.270165][  T184] i2c 2-0040: supply ctp not found, using dummy regulator
[   36.287139][  T344] healthd: battery none chg=
[   36.318690][  T184] can not get fw from file gsl_firmware/gsl1680_7inch.bin
[   36.328547][  T184] input: gslX680 as /devices/platform/soc@3000000/2512000.twi/i2c-2/2-0040/input/input3
[   36.328604][  T344] healthd: battery none chg=
[   36.344913][  T344] healthd: battery none chg=
[   36.346238][  T184] ERROR! get hall_para failed, func:switch_init, line:236
[   36.350540][  T344] healthd: battery none chg=
[   36.363209][  T344] healthd: battery none chg=
[   36.363377][  T229] type=1400 audit(1748526591.860:320): avc: denied { read } for comm="InputReader" name="u:object_r:vendor_awdisplayoutput_prop:s0" dev="tmpfs" ino=301 scontext=u:r:system_server:s0 tcontext=u:object_r:vendor_awdisplayoutput_prop:s0 tclass=file permissive=1
[   36.371924][  T344] healthd: battery none chg=
[   36.397127][  T229] type=1400 audit(1748526591.860:321): avc: denied { open } for comm="InputReader" path="/dev/__properties__/u:object_r:vendor_awdisplayoutput_prop:s0" dev="tmpfs" ino=301 scontext=u:r:system_server:s0 tcontext=u:object_r:vendor_awdisplayoutput_prop:s0 tclass=file permissive=1
[   36.400495][    C7] [BT_LPM] bluesleep_rx_timer_expire: bluesleep_rx_timer_expire
[   36.404502][  T344] healthd: battery none chg=
[   36.431874][  T229] type=1400 audit(1748526591.860:322): avc: denied { getattr } for comm="InputReader" path="/dev/__properties__/u:object_r:vendor_awdisplayoutput_prop:s0" dev="tmpfs" ino=301 scontext=u:r:system_server:s0 tcontext=u:object_r:vendor_awdisplayoutput_prop:s0 tclass=file permissive=1
[   36.553997][ T1104] >>> rwnx_rx_scanu_start_cfm()
[   36.575575][  T229] type=1400 audit(1748526592.072:324): avc: denied { write } for comm="HwBinder:346_2" name="property_service" dev="tmpfs" ino=335 scontext=u:r:mediacodec:s0 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=1
[   36.600890][  T229] type=1400 audit(1748526592.072:325): avc: denied { connectto } for comm="HwBinder:346_2" path="/dev/socket/property_service" scontext=u:r:mediacodec:s0 tcontext=u:r:init:s0 tclass=unix_stream_socket permissive=1
[   36.624583][  T229] type=1107 audit(1748526592.072:326): uid=0 auid=4294967295 ses=4294967295 subj=u:r:init:s0 msg='avc: denied { set } for property=vendor.display.codec2_aisr_process pid=346 uid=1046 gid=1006 scontext=u:r:mediacodec:s0 tcontext=u:object_r:vendor_default_prop:s0 tclass=property_service permissive=1'
[   36.849265][ T1450] [BT_LPM] bluesleep_tx_allow_sleep: Tx has been idle
[   36.849265][ T1450]
[   36.964510][ T1919] audit_log_lost: 503 callbacks suppressed
[   36.964516][ T1919] audit: audit_lost=172 audit_rate_limit=5 audit_backlog_limit=64
[   36.967844][  T229] type=1400 audit(1748526592.460:327): avc: denied { setattr } for comm="chmod" name="/" dev="tracefs" ino=1 scontext=u:r:shell:s0 tcontext=u:object_r:debugfs_tracing_debug:s0 tclass=dir permissive=1
[   36.971757][ T1919] audit: rate limit exceeded
[   37.158118][ T1309] BOOTEVENT:     37158.117399: OFF
[   37.369794][  T338] [BT_LPM] bluesleep_outgoing_data: tx was sleeping, wakeup it
[   37.417090][  T229] type=1400 audit(1748526592.916:330): avc: denied { read } for comm="binder:254_2" name="event_count" dev="sysfs" ino=46443 scontext=u:r:system_suspend:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1
[   37.447404][  T229] type=1400 audit(1748526592.916:331): avc: denied { open } for comm="binder:254_2" path="/sys/devices/platform/soc@3000000/7083000.twi/i2c-13/13-004e/wakeup/wakeup12/event_count" dev="sysfs" ino=46443 scontext=u:r:system_suspend:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1
[   37.477822][  T229] type=1400 audit(1748526592.916:332): avc: denied { getattr } for comm="binder:254_2" path="/sys/devices/platform/soc@3000000/7083000.twi/i2c-13/13-004e/wakeup/wakeup12/event_count" dev="sysfs" ino=46443 scontext=u:r:system_suspend:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=1
[   37.636006][  T229] type=1400 audit(1748526593.132:333): avc: denied { search } for comm="android.hardwar" name="1" dev="proc" ino=30 scontext=u:r:hal_power_default:s0 tcontext=u:r:init:s0 tclass=dir permissive=1
[   37.657750][  T229] type=1400 audit(1748526593.132:334): avc: denied { read } for comm="android.hardwar" name="cmdline" dev="proc" ino=23769 scontext=u:r:hal_power_default:s0 tcontext=u:r:init:s0 tclass=file permissive=1
[   37.868174][    C1] [BT_LPM] bluesleep_rx_timer_expire: bluesleep_rx_timer_expire
[   38.027515][ T1658] treadahead: getpartitiondev /system= 254:0
[   38.036843][ T1658] treadahead: getpartitiondev /product= 254:2
[   38.045477][ T1658] treadahead: getpartitiondev /vendor= 254:1
[   38.053325][ T1658] treadahead: getpartitiondev /vendor_dlkm= 254:3
[   38.092516][ T1658] audit: audit_lost=277 audit_rate_limit=5 audit_backlog_limit=64
[   38.101804][ T1658] audit: rate limit exceeded
[   38.108677][ T1658] treadahead:  begain fgets_alloc ======== 254:0   254:2
[   38.892175][    C1] [BT_LPM] bluesleep_rx_timer_expire: bluesleep_rx_timer_expire
[   39.916177][    C1] [BT_LPM] bluesleep_rx_timer_expire: bluesleep_rx_timer_expire
[   40.401219][ T1450] [BT_LPM] bluesleep_tx_allow_sleep: Tx has been idle
[   40.401219][ T1450]
[   41.420174][    C5] [BT_LPM] bluesleep_rx_timer_expire: bluesleep_rx_timer_expire
[   41.435573][   T79] [BT_LPM] bluesleep_sleep_work: going to sleep...
[   42.390131][ T1658] treadahead: treadahead read-trace over 327701  345525
[   42.505827][    T1] init: starting service 'vendor.drm-clearkey-service'...
[   42.518906][    T1] init: Control message: Processed ctl.interface_start for 'aidl/android.hardware.drm.IDrmFactory/clearkey' from pid: 214 (/system/bin/servicemanager)
[   42.565481][    T1] init: starting service 'vendor.drm-widevine-hal'...
[   42.579417][    T1] init: Control message: Processed ctl.interface_start for 'aidl/android.hardware.drm.IDrmFactory/widevine' from pid: 214 (/system/bin/servicemanager)
[   42.733367][ T1658] treadahead: treadahead write trace end
[   42.990365][    T1] init: processing action (persist.service.dragon.start=1) from (/system/etc/init/dragonservice.rc:1)
[   43.004493][    T1] init: starting service 'dragonservice'...
[   43.104392][    T1] init: processing action (persist.service.dragon.start=0) from (/system/etc/init/dragonservice.rc:4)
[   43.116584][    T1] init: Sending signal 9 to service 'dragonservice' (pid 2469) process group...
[   43.132631][    T1] libprocessgroup: Successfully killed process cgroup uid 0 pid 2469 in 5ms
[   43.143970][    T1] init: Service 'dragonservice' (pid 2469) received signal 9
[   51.168801][ T1658] treadahead: read trace end
[   51.476065][ T1658] treadahead: begin match traceinfo
[   51.483300][  T229] type=1400 audit(1748526606.980:443): avc: denied { search } for comm="treadahead" name="/" dev="mmcblk0p22" ino=2 scontext=u:r:vendor_init:s0 tcontext=u:object_r:unlabeled:s0 tclass=dir permissive=1
[   51.505850][  T229] type=1400 audit(1748526606.980:444): avc: denied { write } for comm="treadahead" name="/" dev="mmcblk0p22" ino=2 scontext=u:r:vendor_init:s0 tcontext=u:object_r:unlabeled:s0 tclass=dir permissive=1
[   51.529592][  T229] type=1400 audit(1748526606.980:445): avc: denied { add_name } for comm="treadahead" name="readahead_file_offset" scontext=u:r:vendor_init:s0 tcontext=u:object_r:unlabeled:s0 tclass=dir permissive=1
[   51.551336][  T229] type=1400 audit(1748526606.980:446): avc: denied { create } for comm="treadahead" name="readahead_file_offset" scontext=u:r:vendor_init:s0 tcontext=u:object_r:unlabeled:s0 tclass=file permissive=1
[   51.573015][  T229] type=1400 audit(1748526606.980:447): avc: denied { read write open } for comm="treadahead" path="/treadahead/readahead_file_offset" dev="mmcblk0p22" ino=15 scontext=u:r:vendor_init:s0 tcontext=u:object_r:unlabeled:s0 tclass=file permissive=1
[   51.602351][    T1] init: Service 'vendor.drm-clearkey-service' (pid 2434) exited with status 0 oneshot service took 9.086000 seconds in background
[   51.617399][    T1] init: Sending signal 9 to service 'vendor.drm-clearkey-service' (pid 2434) process group...
[   51.629259][    T1] libprocessgroup: Successfully killed process cgroup uid 1013 pid 2434 in 0ms
[   51.652328][    T1] init: Service 'vendor.drm-widevine-hal' (pid 2437) exited with status 0 oneshot service took 9.077000 seconds in background
[   51.667180][    T1] init: Sending signal 9 to service 'vendor.drm-widevine-hal' (pid 2437) process group...
[   51.678647][    T1] libprocessgroup: Successfully killed process cgroup uid 1013 pid 2437 in 0ms
[   51.948662][ T1658] audit: audit_lost=282 audit_rate_limit=5 audit_backlog_limit=64
[   51.957280][ T1658] audit: rate limit exceeded
[   52.019280][ T1658] treadahead: trace readahead complete
[   52.019840][    T1] init: processing action (persist.device_config.runtime_native_boot.iorap_perfetto_enable=true && persist.sys.without.treadahead=1 && ro.iorapd.enable=true) from (/system/etc/init/iorapd.rc:34)
[   52.047472][    T1] init: starting service 'iorapd'...
[   52.060493][    T1] init: Service 'treadahead_trace' (pid 1658) exited with status 0 oneshot service took 16.128000 seconds in background
[   52.074782][    T1] init: Sending signal 9 to service 'treadahead_trace' (pid 1658) process group...
[   55.383165][  T500] >>> rwnx_cfg80211_scan()
[   55.388008][  T500] >>> rwnx_send_scanu_req()
[   56.542667][ T1104] >>> rwnx_rx_scanu_start_cfm()

console:/ $
console:/ $
console:/ $




在线

楼主 #2 2025-05-31 21:21:46

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,381
积分: 9202

Re: 九鼎创展 A733 开发板使用记录

.





在线

楼主 #3 2025-05-31 21:21:48

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,381
积分: 9202

Re: 九鼎创展 A733 开发板使用记录

.





在线

楼主 #4 2025-05-31 21:24:40

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,381
积分: 9202

Re: 九鼎创展 A733 开发板使用记录

烧录自己编译的固件,出现:

......


[225]HELLO! BOOT0 is starting!
[228]BOOT0 commit : {cfda5fbe}
[237]volume key pressed!
[240][mmc]: mmc driver ver 2024-03-20 10:36
[250][mmc]: Wrong media type 0x0, but host sdc2, try mmc first
[256][mmc]: ***Try MMC card 2***
[278][mmc]: RMCA OK!
[284][mmc]: MMC 5.1
[286][mmc]: HSSDR52/SDR25 8 bit
[289][mmc]: 50000000 Hz
[292][mmc]: 29880 MB
[294][mmc]: ***SD/MMC 2 init OK!!!***
[299]DRAM BOOT DRIVE INFO: V0.599
[304]DRAM_VCC set to 560 mv
[307]DRAM CLK =1800 MHZ
[309]DRAM Type =9 (8:LPDDR4,9:LPDDR5)
[435]Training result is = 7
[438]DRAM Pstate 0 training, frequency is 1800 Mhz
[447]Actual DRAM SIZE =6144 M
[449]DRAM SIZE =6144 MBytes, para1 = a10a, para2 = 18001001, dram_tpr13 = 10061
[464]DRAM simple test OK.
[505]error: dtb not found for scp
[510]tunning data addr:0x4a0003e8
[513]Jump to ATF: monitor_base = 0x48000000, uboot_base = 0x4a000000, optee_base = 0x0
NOTICE:  BL31: OP-TEE 32bit detected
NOTICE:  BL31: U-BOOT 32bit detected
NOTICE:  BL31: v2.5(debug):eec78cd3c
NOTICE:  BL31: Built : 14:02:13, Oct 29 2024
NOTICE:  hardware check error1
BACKTRACE: START: bl31_platform_setup
0: EL3: 0x48003c9c
1: EL3: 0x4800407c
2: EL3: 0x48003f78
3: EL3: 0x480001f0
BACKTRACE: END: bl31_platform_setup
PANIC in EL3.
x30            = 0x0000000048004088
x0             = 0x0000000002500000
x1             = 0x0000000000000060
x2             = 0x0000000000000060
x3             = 0x00000000ffffffc8
x4             = 0x0000000000000034
x5             = 0x0000000000000034
x6             = 0x0000000000000004
x7             = 0x0000000000000000
x8             = 0x000000023fffffff
x9             = 0x0000000048013000
x10            = 0x0000000000000000
x11            = 0x0000000000000000
x12            = 0x0000000000000010
x13            = 0x0000000000000000
x14            = 0x0000000000000000
x15            = 0x0000000000000000
x16            = 0x0000000000000000
x17            = 0x0000000000048c00
x18            = 0x0000000000000020
x19            = 0x000000004800f4b4
x20            = 0x0000000000000000
x21            = 0x0000000000001903
x22            = 0x0000000000000000
x23            = 0x0000000000000000
x24            = 0x0000000000000000
x25            = 0x0000000000000000
x26            = 0x0000000000000000
x27            = 0x0000000000000000
x28            = 0x0000000000000000
x29            = 0x0000000048014280
scr_el3        = 0x0000000000000238
sctlr_el3      = 0x0000000030cd183f
cptr_el3       = 0x0000000000000000
tcr_el3        = 0x000000008081351e
daif           = 0x00000000000002c0
mair_el3       = 0x00000000004404ff
spsr_el3       = 0x00000000000001cd
elr_el3        = 0x0000000000000000
ttbr0_el3      = 0x0000000048041001
esr_el3        = 0x0000000000000000
far_el3        = 0x0000000000000000
spsr_el1       = 0x00000000000001cd
elr_el1        = 0x0000000000000000
spsr_abt       = 0x00000000400bfc0e
spsr_und       = 0x00000000f08378cd
spsr_irq       = 0x0000000034037e06
spsr_fiq       = 0x0000000030077c14
sctlr_el1      = 0x0000000000c50838
actlr_el1      = 0x0000000000000000
cpacr_el1      = 0x0000000000000000
csselr_el1     = 0x0000000000000000
sp_el1         = 0x0000000000000000
esr_el1        = 0x00000000000c0000
ttbr0_el1      = 0x000000003a3f7f7c
ttbr1_el1      = 0x000000080c7f7f7c
mair_el1       = 0x44e048e000098aa4
amair_el1      = 0x0000000000000000
tcr_el1        = 0x0000000000000000
tpidr_el1      = 0x7f3fff00fdff7f00
tpidr_el0      = 0x7f007f8000ff0800
tpidrro_el0    = 0x00000000ff0c0080
par_el1        = 0xff00000048000980
mpidr_el1      = 0x0000000081000000
afsr0_el1      = 0x0000000000000000
afsr1_el1      = 0x0000000000000000
contextidr_el1 = 0x0000000000000000
vbar_el1       = 0x0000000000000000
cntp_ctl_el0   = 0x0000000000000000
cntp_cval_el0  = 0xf6de00005fffeeee
cntv_ctl_el0   = 0x0000000000000000
cntv_cval_el0  = 0xffde00005fffffef
cntkctl_el1    = 0x0000000000000000
sp_el0         = 0x0000000048014280
isr_el1        = 0x0000000000000000
cpuectlr_el1   = 0x000000002808bc00
icc_hppir0_el1 = 0x00000000000003ff
icc_hppir1_el1 = 0x00000000000003ff
icc_ctlr_el3   = 0x0000000000028400
gicd_ispendr regs (Offsets 0x200-0x278)
Offset                  Value
0x200:           0x0000000000000000
0x208:           0x0000000000000000
0x210:           0x0000000000000000
0x218:           0x0000000000000000
0x220:           0x0000000000000000
0x228:           0x0000000000000000
0x230:           0x0000000000000000
0x238:           0x0000000000000000
0x240:           0x0000000000000000
0x248:           0x0000000000000000
0x250:           0x0000000000000000
0x258:           0x0000000000000000
0x260:           0x0000000000000000
0x268:           0x0000000000000000
0x270:           0x0000000000000000
0x278:           0x0000000000000000

_20250531212328.jpg

不勾选任何选项刷出厂固件,可以正常启动。





在线

楼主 #5 2025-05-31 21:32:07

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,381
积分: 9202

Re: 九鼎创展 A733 开发板使用记录

找到一个相关的问题,但是我的这个和命令长度没有关系:


【FAQ3027】 SDK所在目录路径过长引发固件异常无法启动.pdf

1.主题
SDK所在目录路径过长引发固件异常无法启动

2.问题背景
有客户反馈,sdk按如下目录放置,编译出的固件烧写后无法启动,错误如下:

/ibm/ExdroidData/workspace/mynewroot/jenkins/code/dailybuild/androidv/platform/android14

[2024-07-07 01:11:06.834698] [387]phy_dfs_clk3 = 150M
[2024-07-07 01:11:06.837708] [390]phy_dfs_clk0 = 1200M
[2024-07-07 01:11:06.841707] [392]DRAM MDFS VERSION INFO: V0.660
[2024-07-07 01:11:06.844748] [396]DRAM MDFS time =38136 ns
[2024-07-07 01:11:06.851745] [399]DRAM SIZE =4096 MBytes, para1 = 310a, para2 = 10001000, tpr13 = 6065
[2024-07-07 01:11:06.855749] [407]DRAM simple test OK.
[2024-07-07 01:11:06.857749] [410]dram size =4096
[2024-07-07 01:11:06.859749] [412]nsi init 2023-2-23
[2024-07-07 01:11:06.911773] [462]read toc1 from emmc 32800 sector
[2024-07-07 01:11:06.915730] [467]don't have rotpk, skip check
[2024-07-07 01:11:06.917719] [470]OLD version: 0.0
[2024-07-07 01:11:06.919729] [472]NEW version: 0.0
[2024-07-07 01:11:07.031703] [583]monitor entry=0x48000000
[2024-07-07 01:11:07.033702] [585]uboot entry=0x4a000000
[2024-07-07 01:11:07.036642] [588]optee entry=0x48600000
[2024-07-07 01:11:07.038641] [591]opensbi entry=0x0
[2024-07-07 01:11:07.040638] [593]no need rotpk flag
[2024-07-07 01:11:07.044622] [595]tunning data addr:0x4a0003e8
[2024-07-07 01:11:07.049625] [599]sec_mem_map[0]: addr = 0x48000000, size = 0x100000
[2024-07-07 01:11:07.055622] [604]sec_mem_map[1]: addr = 0x48600000, size = 0x100000
[2024-07-07 01:11:07.057653] [610]run out of boot0
[2024-07-07 01:11:07.067667] NOTICE:  BL31: v2.5(debug):55b180a27
[2024-07-07 01:11:07.071665] NOTICE:  BL31: Built : 11:09:52, Sep 18 2023
[2024-07-07 01:11:07.074610] NOTICE:  hardware check error1
[2024-07-07 01:11:07.077657] BACKTRACE: START: bl31_platform_setup
[2024-07-07 01:11:07.079655] 0: EL3: 0x480038a4
[2024-07-07 01:11:07.081653] 1: EL3: 0x48003b40
[2024-07-07 01:11:07.083616] 2: EL3: 0x48003a94
[2024-07-07 01:11:07.085619] 3: EL3: 0x480001e0
[2024-07-07 01:11:07.088622] BACKTRACE: END: bl31_platform_setup
[2024-07-07 01:11:07.089654] PANIC in EL3.
[2024-07-07 01:11:07.093608] x30            = 0x0000000048003b4c
[2024-07-07 01:11:07.096654] x0             = 0x0000000002500000
[2024-07-07 01:11:07.100609] x1             = 0x0000000000000060
[2024-07-07 01:11:07.103654] x2             = 0x0000000000000060
[2024-07-07 01:11:07.106609] x3             = 0x00000000ffffffc8
[2024-07-07 01:11:07.110608] x4             = 0x0000000000000034
[2024-07-07 01:11:07.113667] x5             = 0x0000000000000034
[2024-07-07 01:11:07.116619] x6             = 0x0000000000000004
[2024-07-07 01:11:07.120606] x7             = 0x0000000000000000
[2024-07-07 01:11:07.123654] x8             = 0x000000023fffffff
[2024-07-07 01:11:07.126603] x9             = 0x0000000048600000
[2024-07-07 01:11:07.130611] x10            = 0x0000000000000000
[2024-07-07 01:11:07.133654] x11            = 0x0000000000100000
[2024-07-07 01:11:07.137665] x12            = 0x0000000000000018
[2024-07-07 01:11:07.140618] x13            = 0x0000000000000000
[2024-07-07 01:11:07.143658] x14            = 0x0000000000000000
[2024-07-07 01:11:07.147657] x15            = 0x0000000000000000
[2024-07-07 01:11:07.150611] x16            = 0x0000000000000000
[2024-07-07 01:11:07.153651] x17            = 0x0000000000045400
[2024-07-07 01:11:07.157653] x18            = 0x0000000000000020
[2024-07-07 01:11:07.168273] x19            = 0x000000004800e3f6
[2024-07-07 01:11:07.168345] x20            = 0x0000000000000000
[2024-07-07 01:11:07.168360] x21            = 0x0000000000001890
[2024-07-07 01:11:07.170569] x22            = 0x0000000000000000
[2024-07-07 01:11:07.173624] x23            = 0x0000000000000000
[2024-07-07 01:11:07.177663] x24            = 0x0000000000000000
[2024-07-07 01:11:07.180668] x25            = 0x0000000000000000
[2024-07-07 01:11:07.184671] x26            = 0x0000000000000000
[2024-07-07 01:11:07.187621] x27            = 0x0000000000000000
[2024-07-07 01:11:07.190672] x28            = 0x0000000000000000
[2024-07-07 01:11:07.194658] x29            = 0x00000000480112c0
[2024-07-07 01:11:07.197625] scr_el3        = 0x0000000000000238
[2024-07-07 01:11:07.200677] sctlr_el3      = 0x0000000030cd183f
[2024-07-07 01:11:07.204676] cptr_el3       = 0x0000000000000000
[2024-07-07 01:11:07.207626] tcr_el3        = 0x000000008081351e
[2024-07-07 01:11:07.211638] daif           = 0x00000000000002c0
[2024-07-07 01:11:07.214678] mair_el3       = 0x00000000004404ff
[2024-07-07 01:11:07.217635] spsr_el3       = 0x00000000000001cd
[2024-07-07 01:11:07.221632] elr_el3        = 0x0000000000012ea4
[2024-07-07 01:11:07.224661] ttbr0_el3      = 0x000000004803e381
[2024-07-07 01:11:07.227617] esr_el3        = 0x00000000b2050b37
[2024-07-07 01:11:07.231620] far_el3        = 0x5ad7c3dbfffe3ff9
[2024-07-07 01:11:07.234664] spsr_el1       = 0x00000000000001cd
[2024-07-07 01:11:07.238658] elr_el1        = 0x0000000000000000
[2024-07-07 01:11:07.241683] spsr_abt       = 0x00000000f01f28b9
[2024-07-07 01:11:07.244659] spsr_und       = 0x00000000f0478217
[2024-07-07 01:11:07.248612] spsr_irq       = 0x00000000f00b8ebd
[2024-07-07 01:11:07.251658] spsr_fiq       = 0x00000000f40f6460
[2024-07-07 01:11:07.254613] sctlr_el1      = 0x0000000000c50838
[2024-07-07 01:11:07.258618] actlr_el1      = 0x0000000000000000
[2024-07-07 01:11:07.261660] cpacr_el1      = 0x0000000000000000
[2024-07-07 01:11:07.265661] csselr_el1     = 0x0000000000000000
[2024-07-07 01:11:07.268613] sp_el1         = 0x0000000000000000
[2024-07-07 01:11:07.271659] esr_el1        = 0x00000000b4897f9c
[2024-07-07 01:11:07.274616] ttbr0_el1      = 0x0000f63708ac0ce2
[2024-07-07 01:11:07.278663] ttbr1_el1      = 0x00000bfc5c0958d0
[2024-07-07 01:11:07.281624] mair_el1       = 0x44e048e000098aa4
[2024-07-07 01:11:07.285628] amair_el1      = 0x0000000000000000
[2024-07-07 01:11:07.288657] tcr_el1        = 0x0000000000000000
[2024-07-07 01:11:07.291610] tpidr_el1      = 0x3a0c50eb9150e67b
[2024-07-07 01:11:07.295614] tpidr_el0      = 0xdc178f81ebf9d7ff
[2024-07-07 01:11:07.298664] tpidrro_el0    = 0xfb10d70cdeff6571
[2024-07-07 01:11:07.301621] par_el1        = 0xff00000048000980
[2024-07-07 01:11:07.305628] mpidr_el1      = 0x0000000081000000
[2024-07-07 01:11:07.308625] afsr0_el1      = 0x0000000000000000
[2024-07-07 01:11:07.312624] afsr1_el1      = 0x0000000000000000
[2024-07-07 01:11:07.315625] contextidr_el1 = 0x0000000000000000
[2024-07-07 01:11:07.318667] vbar_el1       = 0x0000000000000000
[2024-07-07 01:11:07.322622] cntp_ctl_el0   = 0x0000000000000000
[2024-07-07 01:11:07.325666] cntp_cval_el0  = 0xff5f39fefd2bd7ce
[2024-07-07 01:11:07.328614] cntv_ctl_el0   = 0x0000000000000000
[2024-07-07 01:11:07.332623] cntv_cval_el0  = 0xd7f5971ac72c673d
[2024-07-07 01:11:07.335660] cntkctl_el1    = 0x0000000000000000
[2024-07-07 01:11:07.338663] sp_el0         = 0x00000000480112c0
[2024-07-07 01:11:07.342662] isr_el1        = 0x0000000000000000
[2024-07-07 01:11:07.345612] dacr32_el2     = 0x0000000000000000
[2024-07-07 01:11:07.348657] ifsr32_el2     = 0x0000000000000217
[2024-07-07 01:11:07.352666] cpuectlr_el1   = 0x000000002808bc00
[2024-07-07 01:11:07.355622] icc_hppir0_el1 = 0x00000000000003ff
[2024-07-07 01:11:07.359625] icc_hppir1_el1 = 0x00000000000003ff
[2024-07-07 01:11:07.362686] icc_ctlr_el3   = 0x0000000000028400
[2024-07-07 01:11:07.366678] gicd_ispendr regs (Offsets 0x200-0x278)
[2024-07-07 01:11:07.367626] Offset			Value
[2024-07-07 01:11:07.370673] 0x200:		 0x0000000000000000
[2024-07-07 01:11:07.373673] 0x208:		 0x0000000000000000
[2024-07-07 01:11:07.375675] 0x210:		 0x0000000000000000
[2024-07-07 01:11:07.378592] 0x218:		 0x0000000000000000
[2024-07-07 01:11:07.380634] 0x220:		 0x0000000000000000
[2024-07-07 01:11:07.383664] 0x228:		 0x0000000000000000
[2024-07-07 01:11:07.386613] 0x230:		 0x0000000000000000
[2024-07-07 01:11:07.388617] 0x238:		 0x0000000000000000
[2024-07-07 01:11:07.391612] 0x240:		 0x0000000000000000
[2024-07-07 01:11:07.394648] 0x248:		 0x0000000000000000
[2024-07-07 01:11:07.396647] 0x250:		 0x0000000000000000
[2024-07-07 01:11:07.399601] 0x258:		 0x0000000000000000
[2024-07-07 01:11:07.401601] 0x260:		 0x0000000000000000
[2024-07-07 01:11:07.404653] 0x268:		 0x0000000000000000
[2024-07-07 01:11:07.407609] 0x270:		 0x0000000000000000
[2024-07-07 01:11:07.409613] 0x278:		 0x0000000000000000

3.原因分析
当前编译工具对路径长度有要求。如果longan所在的路径过长,会引起编译时image异常。当前所支持的bsp的绝对路径长度为83个字符,如android sdk,则为包含longan目录时的长度,如:

/ibm/ExdroidData/workspace/mynewroot/jenkins/code/dailybuild/androidv/platform/android14/longan
长度以及超过83字符限制。

4.解决措施
缩短sdk所在目录长度。





在线

楼主 #7 2025-06-01 09:36:47

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,381
积分: 9202

Re: 九鼎创展 A733 开发板使用记录

删除 longan/out/ 目录,重新编译 longan,然而,还是一样的问题





在线

楼主 #8 2025-06-01 10:03:10

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,381
积分: 9202

Re: 九鼎创展 A733 开发板使用记录

使用这个 img工具 解包之后,用beyondcompare比较,发现boot0*.fex 有差异

_20250601093603.jpg





在线

楼主 #9 2025-06-01 10:08:02

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,381
积分: 9202

Re: 九鼎创展 A733 开发板使用记录

现在基本确定了,就是打包工具导致 boot0_*.fex 几个文件并没有更新成功


折腾半小时,修改 longan/build/pack 脚本,从正常的img提取出来的boot0_*.fex 复制到 longan/out/a733/demo_aiot/pack_out/ 目录,

然后强制 boot0_*.fex 不更新

longan/build/pack 修改前:

#!/bin/bash
#
# pack/pack
# (c) Copyright 2013
# Allwinner Technology Co., Ltd. <www.allwinnertech.com>
# James Deng <csjamesdeng@allwinnertech.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

############################ Notice #####################################
# a. Some config files priority is as follows:
#    - xxx_${platform}.{cfg|fex} > xxx.{cfg|fex}
#    - ${chip}/${board}/*.{cfg|fex} > ${chip}/default/*.{cfg|fex}
#    - ${chip}/default/*.cfg > ${LICHEE_COMMON_CONFIG_DIR}/imagecfg/*.cfg
#    - ${chip}/default/*.fex > ${LICHEE_COMMON_CONFIG_DIR}/partition/*.fex
#  e.g. sun8iw7p1/configs/perf/image_linux.cfg > sun8iw7p1/configs/default/image_linux.cfg
#       > ${LICHEE_COMMON_CONFIG_DIR}/imagecfg/image_linux.cfg > sun8iw7p1/configs/perf/image.cfg
#       > sun8iw7p1/configs/default/image.cfg > ${LICHEE_COMMON_CONFIG_DIR}/imagecfg/image.cfg
#
# b. Support Nor storages rule:
#    - Need to create sys_partition_nor.fex or sys_partition_nor_${platform}.fex
#    - Add "{filename = "full_img.fex",     maintype = "12345678", \
#      subtype = "FULLIMG_00000000",}" to image[_${platform}].cfg
#
# c. Switch uart port
#    - Need to add your chip configs into ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin
#    - Call pack with 'debug' parameters

#if you want to debug pack, set vlaue to 1. use pause func in the place where you want to stop
enable_pause=0

function get_char()
{
	SAVEDSTTY=`stty -g`
	stty -echo
	stty cbreak
	dd if=/dev/tty bs=1 count=1 2> /dev/null
	stty -raw
	stty echo
	stty $SAVEDSTTY
}

function pause()
{
	if [ "x$1" != "x" ] ;then
		echo "$1"
	fi
	if [ $enable_pause -eq 1 ] ; then
		echo "Press any key to continue!"
		char=`get_char`
	fi
}

function pack_error()
{
	echo -e "\033[47;31mERROR: $*\033[0m"
}

function pack_warn()
{
	echo -e "\033[47;34mWARN: $*\033[0m"
}

function pack_info()
{
	echo -e "\033[47;30mINFO: $*\033[0m"
}

localpath=$(cd $(dirname $0) && pwd)
. $localpath/shflags

# define option, format:
#   'long option' 'default value' 'help message' 'short option'
DEFINE_string 'chip' '' 'chip to build, e.g. sun7i' 'c'
DEFINE_string 'ic' '' 'ic to build, e.g. a50' 'i'
DEFINE_string 'addition' '' 'additional config files, e.g. xx.fex' 'a'
DEFINE_string 'platform' '' 'platform to build, e.g. linux, android' 'p'
DEFINE_string 'platform_version' '' 'platform version to build' 'V'
DEFINE_string 'board' '' 'board to build, e.g. evb' 'b'
DEFINE_string 'kernel' '' 'kernel to build, e.g. linux-3.4, linux-3.10' 'k'
DEFINE_string 'debug_mode' 'uart0' 'config debug mode, e.g. uart0, card0' 'd'
DEFINE_string 'signture' 'none' 'pack boot signture to do secure boot' 's'
DEFINE_string 'secure' 'none' 'pack secure boot with -v arg' 'v'
DEFINE_string 'mode' 'normal' 'pack dump firmware' 'm'
DEFINE_string 'function' 'android' 'pack private firmware' 'f'
DEFINE_string 'vsp' '' 'pack firmware for vsp' 't'
DEFINE_string 'programmer' '' 'creat programmer img or not' 'w'
DEFINE_string 'key_path' '' 'the path of keys' 'P'
DEFINE_string 'nor' 'none' 'pack nor image' 'n'
DEFINE_boolean 'verity' false 'if enable dm-verity' ''
DEFINE_boolean 'signfel' false 'if enable fel signing' ''
DEFINE_string 'boot_path' '' 'the path of gki boot.img' 'B'
DEFINE_string 'output_resources' '' 'only output resources to pack-out' ''
DEFINE_string 'from_resources' '' 'pack from resources path' ''

# parse the command-line
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"

PACK_CHIP=${FLAGS_chip}
PACK_IC=${FLAGS_ic}
PACK_PLATFORM=${FLAGS_platform}
PACK_PLATFORM_VERSION=${FLAGS_platform_version}
PACK_BOARD=${FLAGS_board}
PACK_KERN=${FLAGS_kernel}
PACK_DEBUG=${FLAGS_debug_mode}
PACK_SIG=${FLAGS_signture}
PACK_SECURE=${FLAGS_secure}
PACK_MODE=${FLAGS_mode}
PACK_FUNC=${FLAGS_function}
PACK_VSP=${FLAGS_vsp}
PACK_PROGRAMMER=${FLAGS_programmer}
PACK_NOR=${FLAGS_nor}
PACK_PRODUCT=${FLAGS_product}
PACK_VERITY=${FLAGS_verity}
PACK_SIGNFEL=${FLAGS_signfel}
PACK_ADD_FILES=(${FLAGS_addition})
PACK_KEY_PATH=${FLAGS_key_path}
PACK_BOOT_PATH=${FLAGS_boot_path}

CFG_TOP_DIR=$(cd $localpath/../ && pwd)
CFG_PLAT_OUT=$CFG_TOP_DIR/out/$PACK_IC/$PACK_BOARD/$PACK_PLATFORM
CFG_KEY_DIR=$CFG_TOP_DIR/out/$PACK_IC/common/keys

if [ ! -z "${PACK_KEY_PATH}" ]; then
    CFG_KEY_DIR=${PACK_KEY_PATH}
fi
pack_info "${CFG_KEY_DIR}"

if [ ! -d ${CFG_PLAT_OUT} ] || \
   [ ! -f $CFG_PLAT_OUT/.buildconfig ]; then
	pack_error "config & build lichee before you pack"
	exit 1
fi

source $CFG_PLAT_OUT/.buildconfig

if [ -z "${PACK_KERN}" ]; then
	pack_info "No kernel param, parse it from .buildconfig"
	PACK_KERN=$LICHEE_KERN_VER
	if [ -z "${PACK_KERN}" ]; then
		pack_error "Failed to parse kernel param from .buildconfig"
		exit 1
	fi
fi

PACK_TYPE=""
case "x${PACK_PLATFORM}" in
	"xandroid")
		PACK_TYPE="android"
		;;
	"xdragonboard")
		PACK_TYPE="dragonboard"
		;;
	"xdragonabts")
		PACK_TYPE="dragonabts"
		;;
	"xbsp"|"xsata"|"xbuildroot"|"xopenwrt"|"xdebian")
		PACK_TYPE="linux"
		;;
	*)
		pack_error "Unsupport PACK_PLATFORM: ${PACK_PLATFORM}"
		exit 1
		;;
esac

export PATH=${LICHEE_TOOLS_DIR}/pack/pctools/linux/mod_update:${LICHEE_TOOLS_DIR}/pack/pctools/linux/openssl:${LICHEE_TOOLS_DIR}/pack/pctools/linux/eDragonEx:${LICHEE_TOOLS_DIR}/pack/pctools/linux/fsbuild200:${LICHEE_TOOLS_DIR}/pack/pctools/linux/android:$PATH
export LD_LIBRARY_PATH=${LICHEE_TOOLS_DIR}/pack/pctools/linux/softhsm/lib/:$LD_LIBRARY_PATH

tools_file_list=(
${LICHEE_COMMON_CONFIG_DIR}/tools/split_xxxx.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/split_xxxx.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/usbtool_test.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/usbtool_crash.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/usbtool_test.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/cardscript.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/cardscript_secure.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/cardscript.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/cardscript_secure.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/cardtool.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/cardtool.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/usbtool.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/usbtool.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/usbtool_crash.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/usbtool_crash.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/aultls32.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/aultls32.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/aultools.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/aultools.fex
)

configs_file_list=(
${LICHEE_COMMON_CONFIG_DIR}/toc/toc1.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/toc0.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/toc0_sdcard.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/toc0_nand.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/toc0_ufs.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/toc0_ft.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/boot_package.fex
${LICHEE_COMMON_CONFIG_DIR}/hdcp/esm.fex
${LICHEE_COMMON_CONFIG_DIR}/dtb/sunxi.fex
${LICHEE_COMMON_CONFIG_DIR}/imagecfg/*.cfg
${LICHEE_COMMON_CONFIG_DIR}/partition/sys_partition_dump.fex
${LICHEE_COMMON_CONFIG_DIR}/partition/sys_partition_private.fex
${LICHEE_COMMON_CONFIG_DIR}/version/version_base.mk
${LICHEE_CHIP_CONFIG_DIR}/configs/default/*
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/*.fex
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/boot_package*.cfg
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/${LICHEE_KERN_VER}/*.cfg
${LICHEE_CHIP_CONFIG_DIR}/configs/default/version_base.mk
${LICHEE_CHIP_CONFIG_DIR}/dtbo/*
${LICHEE_BOARD_CONFIG_DIR}/dtbo/*
${LICHEE_CHIP_CONFIG_DIR}/${BIN_PATH}/ft_${PACK_CHIP}.bin
${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_ft.cfg
${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc_ft.cfg
${LICHEE_COMMON_CONFIG_DIR}/sign_config/cnf_base.cnf
${LICHEE_PLAT_OUT}/.buildconfig
)

product_configs_file_list=(
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/${PACK_PLATFORM}/*.fex
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/${PACK_PLATFORM}/*.cfg
)

boot_resource_list=(
${LICHEE_CHIP_CONFIG_DIR}/boot-resource/boot-resource:${LICHEE_PACK_OUT_DIR}
${LICHEE_CHIP_CONFIG_DIR}/boot-resource/boot-resource.ini:${LICHEE_PACK_OUT_DIR}
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/*.bmp:${LICHEE_PACK_OUT_DIR}/boot-resource/
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/bootlogo.bmp:${LICHEE_PACK_OUT_DIR}/bootlogo.bmp
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/wavefile/*:${LICHEE_PACK_OUT_DIR}/boot-resource/wavefile/
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/${PACK_TYPE}/*.bmp:${LICHEE_PACK_OUT_DIR}/boot-resource/
${LICHEE_CHIP_CONFIG_DIR}/boot-resource/boot-resource/bat/bempty.bmp:${LICHEE_PACK_OUT_DIR}/bempty.bmp
${LICHEE_CHIP_CONFIG_DIR}/boot-resource/boot-resource/bat/battery_charge.bmp:${LICHEE_PACK_OUT_DIR}/battery_charge.bmp
)

boot_file_list=(
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_nand_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_nand.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_sdcard_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_sdcard.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_ufs_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_ufs.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_${LICHEE_BOOT0_BIN_NAME}_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_nandfastboot_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_nandfastboot_${PACK_CHIP}.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_spinor_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_spinor.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/fes1_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/fes1.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/fes1_uart_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/fes1_uart.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-${LICHEE_EFEX_BIN_NAME}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-${LICHEE_EFEX_BIN_NAME}.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-crashdump-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-crash.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-crashdump-spinor-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor-crash.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/bl31.bin:${LICHEE_PACK_OUT_DIR}/monitor.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/bl31_${PACK_BOARD}.bin:${LICHEE_PACK_OUT_DIR}/monitor.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/scp.bin:${LICHEE_PACK_OUT_DIR}/scp.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/amp_dsp0.bin:${LICHEE_PACK_OUT_DIR}/amp_dsp0.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/amp_dsp1.bin:${LICHEE_PACK_OUT_DIR}/amp_dsp1.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/amp_arm64.bin:${LICHEE_PACK_OUT_DIR}/amp_arm64.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/amp_rv0.bin:${LICHEE_PACK_OUT_DIR}/amp_rv0.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/video.bin:${LICHEE_PACK_OUT_DIR}/video.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/optee_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/optee.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/optee_${PACK_CHIP}-monitor.bin:${LICHEE_PACK_OUT_DIR}/optee-monitor.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/opensbi_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/opensbi.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-spinor-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-spinor-secure-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor-secure.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/*.fex:${LICHEE_PACK_OUT_DIR}/
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/*.dtb:${LICHEE_PACK_OUT_DIR}/
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/*.bin:${LICHEE_PACK_OUT_DIR}/
)

boot_file_list_2=(
${LICHEE_PLAT_OUT}/arisc:${LICHEE_PACK_OUT_DIR}/arisc.fex
${LICHEE_PLAT_OUT}/sunxi.dtb:${LICHEE_PACK_OUT_DIR}/sunxi.fex
${LICHEE_PLAT_OUT}/boot0_nand_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_nand.fex
${LICHEE_PLAT_OUT}/boot0_sdcard_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_sdcard.fex
${LICHEE_PLAT_OUT}/boot0_${LICHEE_BOOT0_BIN_NAME}_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex
${LICHEE_PLAT_OUT}/boot0_spinor_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_spinor.fex
${LICHEE_PLAT_OUT}/fes1_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/fes1.fex
${LICHEE_PLAT_OUT}/fes1_uart_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/fes1_uart.fex
${LICHEE_PLAT_OUT}/sboot_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot.bin
${LICHEE_PLAT_OUT}/sboot_nor_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nor.bin
${LICHEE_PLAT_OUT}/sboot_sdcard_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_sdcard.bin
${LICHEE_PLAT_OUT}/sboot_nand_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nand.bin
${LICHEE_PLAT_OUT}/sboot_ufs_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_ufs.bin
${LICHEE_PLAT_OUT}/u-boot-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot.fex
${LICHEE_PLAT_OUT}/u-boot-${LICHEE_EFEX_BIN_NAME}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-${LICHEE_EFEX_BIN_NAME}.fex
${LICHEE_PLAT_OUT}/u-boot-crashdump-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-crash.fex
${LICHEE_PLAT_OUT}/u-boot-crashdump-spinor-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor-crash.fex
${LICHEE_PLAT_OUT}/scp.bin:${LICHEE_PACK_OUT_DIR}/scp.fex
${LICHEE_PLAT_OUT}/u-boot-spinor-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor.fex
${LICHEE_PLAT_OUT}/u-boot-spinor-secure-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor-secure.fex
${LICHEE_PLAT_OUT}/vmlinux.tar.bz2:${LICHEE_PACK_OUT_DIR}/vmlinux.fex
)

arm_boot_file_secure=(
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/semelis_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/semelis.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/optee_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/optee.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_nor_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nor.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_sdcard_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_sdcard.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_nand_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nand.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_ufs_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_ufs.bin
${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_android.cfg:${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc_android.cfg:${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
)

arm64_boot_file_secure=(
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/optee_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/optee.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_nor_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nor.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_sdcard_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_sdcard.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_nand_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nand.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_ufs_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_ufs.bin
${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_a64_android.cfg:${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc_android.cfg:${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/amp_rv0.bin:${LICHEE_PACK_OUT_DIR}/amp_rv0.fex
)

#
# This function can get the realpath between $SRC and $DST
#
function get_realpath()
{
	local src=$(cd $1; pwd);
	local dst=$(cd $2; pwd);
	local res="./";
	local tmp="$dst"

	while [ "${src##*$tmp}" == "${src}" ]; do
		tmp=${tmp%/*};
		res=$res"../"
	done
	res="$res${src#*$tmp/}"

	printf "%s" $res
}

function show_boards()
{
	printf "\nAll avaiable chips, platforms and boards:\n\n"
	printf "Chip            Board\n"
	for chipdir in $(find chips/ -mindepth 1 -maxdepth 1 -type d) ; do
		chip=`basename ${chipdir}`
		printf "${chip}\n"
		for boarddir in $(find chips/${chip}/configs/${platform} \
			-mindepth 1 -maxdepth 1 -type d) ; do
			board=`basename ${boarddir}`
			printf "                ${board}\n"
		done
	done
	printf "\nFor Usage:\n"
	printf "     $(basename $0) -h\n\n"
}

function uart_switch()
{
	rm -rf ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	touch ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	TX=`awk  '$0~"'$PACK_CHIP'"{print $2}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	RX=`awk  '$0~"'$PACK_CHIP'"{print $3}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	PORT=`awk  '$0~"'$PACK_CHIP'"{print $4}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	MS=`awk  '$0~"'$PACK_CHIP'"{print $5}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	CK=`awk  '$0~"'$PACK_CHIP'"{print $6}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	DO=`awk  '$0~"'$PACK_CHIP'"{print $7}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	DI=`awk  '$0~"'$PACK_CHIP'"{print $8}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`

	BOOT_UART_ST=`awk  '$0~"'$PACK_CHIP'"{print $2}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	BOOT_PORT_ST=`awk  '$0~"'$PACK_CHIP'"{print $3}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	BOOT_TX_ST=`awk  '$0~"'$PACK_CHIP'"{print $4}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	BOOT_RX_ST=`awk  '$0~"'$PACK_CHIP'"{print $5}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART0_ST=`awk  '$0~"'$PACK_CHIP'"{print $6}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART0_USED_ST=`awk  '$0~"'$PACK_CHIP'"{print $7}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART0_PORT_ST=`awk  '$0~"'$PACK_CHIP'"{print $8}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART0_TX_ST=`awk  '$0~"'$PACK_CHIP'"{print $9}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART0_RX_ST=`awk  '$0~"'$PACK_CHIP'"{print $10}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART1_ST=`awk  '$0~"'$PACK_CHIP'"{print $11}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	JTAG_ST=`awk  '$0~"'$PACK_CHIP'"{print $12}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	MS_ST=`awk  '$0~"'$PACK_CHIP'"{print $13}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	CK_ST=`awk  '$0~"'$PACK_CHIP'"{print $14}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	DO_ST=`awk  '$0~"'$PACK_CHIP'"{print $15}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	DI_ST=`awk  '$0~"'$PACK_CHIP'"{print $16}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	MMC0_ST=`awk  '$0~"'$PACK_CHIP'"{print $17}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	MMC0_USED_ST=`awk  '$0~"'$PACK_CHIP'"{print $18}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`

	if [ -z "$TX" ] || [ -z "$BOOT_UART_ST" ]; then
		pack_error "$FUNCNAME: $PACK_CHIP not configured in card_debug_pin/card_debug_string!"
		exit 1
	fi

	echo '$0!~";" && $0~"'$BOOT_TX_ST'"{if(C)$0="'$BOOT_TX_ST' = '$TX'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$BOOT_RX_ST'"{if(C)$0="'$BOOT_RX_ST' = '$RX'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$BOOT_PORT_ST'"{if(C)$0="'$BOOT_PORT_ST' = '$PORT'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	if [ "`grep "auto_print_used" "${LICHEE_PACK_OUT_DIR}/sys_config.fex" | grep "1"`" ]; then
		echo '$0!~";" && $0~"'$MMC0_USED_ST'"{if(A)$0="'$MMC0_USED_ST' = 1";A=0} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	else
	echo '$0!~";" && $0~"'$MMC0_USED_ST'"{if(A)$0="'$MMC0_USED_ST' = 0";A=0} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	fi
	echo '$0!~";" && $0~"\\['$MMC0_ST'\\]"{A=1}  \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$UART0_TX_ST'"{if(B)$0="'$UART0_TX_ST' = '$TX'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$UART0_RX_ST'"{if(B)$0="'$UART0_RX_ST' = '$RX'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"\\['$UART0_ST'\\]"{B=1} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$UART0_USED_ST'"{if(B)$0="'$UART0_USED_ST' = 1"}  \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '/^'$UART0_PORT_ST'/{next} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"\\['$UART1_ST'\\]"{B=0} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"\\['$BOOT_UART_ST'\\]"{C=1} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"\\['$JTAG_ST'\\]"{C=0} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$MS_ST'"{$0="'$MS_ST' = '$MS'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$CK_ST'"{$0="'$CK_ST' = '$CK'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$DO_ST'"{$0="'$DO_ST' = '$DO'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$DI_ST'"{$0="'$DI_ST' = '$DI'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '1' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0

	if [ "`grep "auto_print_used" "${LICHEE_PACK_OUT_DIR}/sys_config.fex" | grep "1"`" ]; then
		sed -i -e '/^uart0_rx/a\pinctrl-1=' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		sed -i -e '/^uart0_rx/a\pinctrl-0=' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	fi

	awk -f ${LICHEE_PACK_OUT_DIR}/awk_debug_card0 ${LICHEE_PACK_OUT_DIR}/sys_config.fex > ${LICHEE_PACK_OUT_DIR}/sys_config_debug.fex
	rm -f ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	mv ${LICHEE_PACK_OUT_DIR}/sys_config_debug.fex ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	echo "uart -> card0"
}

function add_lzma_header()
{
	lzma_file=$1
	original_file=$2
	file_size=$(printf "%.8x\n" `stat -c%s ${lzma_file}`)
	original_file_size=$(printf "%.8x\n" `stat -c%s ${original_file}`)

	bin_str=""

	file_size_len=${#file_size}

	#"LZMA"+size+origin_size
	bin_str="\x4c\x5a\x4d\x41\x${file_size:6:2}\x${file_size:4:2}\x${file_size:2:2}\x${file_size:0:2}"
	bin_str+="\x${original_file_size:6:2}\x${original_file_size:4:2}\x${original_file_size:2:2}\x${original_file_size:0:2}"


	printf "%b" ${bin_str} > tempbin

	cat ${lzma_file} >> tempbin

	mv tempbin "${lzma_file}.head"
}

function partition_size_handle()
{
	echo "handle partition_size"
	local filename=${LICHEE_PACK_OUT_DIR}/sys_partition.fex
	local size
	local number
	local dimension
	local blocks
	local line
	local m
	local index=0
	while read line; do
		let "index++"
		size=$(echo $line | awk -F= '/^[[:space:]]*size[[:space:]]*=/{print $2}' | sed 's|\s\+||g')
		if [ -n "$size" ]; then
			dimension=$(echo $size | sed 's|^[0-9,.]\+||g')
			[ -z "$dimension" ] && continue
			case $dimension in
				B|b)
					m=1
					;;
				K|k)
					m=1024
					;;
				M|m)
					m=1048576
					;;
				G|g)
					m=1073741824
					;;
				*)
					pack_error "ERROR Dimension($dimension)!"
					return 1
					;;
			esac
			number=$(echo $size | sed 's|[a-z,A-Z]*$||g')
			blocks=$(echo "$number * $m / 512" | bc | awk -F. '{print $1}')
			printf "sys_partition.fex: size %6s => %7d Blocks\n" "${number}${dimension}" "${blocks}"
			size="$(echo "$line" | sed "s|=.*$|= $blocks|g")"
			sed -i "${index}s|$line|$size|g" $filename
		fi
	done < $filename
	return 0
}

function do_prepare()
{
	local runinfo=($(lsof 2>/dev/null | awk '$9~"'$LICHEE_TOP_DIR/tools/build/buildserver'"{print $2}'))
	local possible_bin_path="${LICHEE_POSSIBLE_BIN_PATH}"

	if [ ${#runinfo[@]} -lt 2 ]; then
		pack_error "something is incorrect:please <./build.sh config>."
	fi

	if [ -z "${PACK_CHIP}" -o -z "${PACK_TYPE}" -o -z "${PACK_BOARD}" ] ; then
		pack_error "Invalid parameters Chip: ${PACK_CHIP}, \
			Platform: ${PACK_TYPE}, Board: ${PACK_BOARD}"
		show_boards
		exit 1
	fi

	if [ ! -d ${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD} ] ; then
		pack_error "Board's directory \
			\"${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}\" is not exist."
		show_boards
		exit 1
	fi

	# Cleanup
	if [ "x" != "x${LICHEE_PACK_OUT_DIR}" ]; then
		rm -rf ${LICHEE_PACK_OUT_DIR}
	fi
	mkdir -p ${LICHEE_PACK_OUT_DIR}

	(
		cd $LICHEE_OUT_DIR
		if [ "${LICHEE_PACK_OUT_DIR}" != "$LICHEE_OUT_DIR/pack_out" ]; then
			rm -rf pack_out
			ln -sf ${LICHEE_IC}/${LICHEE_BOARD}/pack_out pack_out
		fi
	)

	printf "copying tools file\n"
	for file in ${tools_file_list[@]} ; do
		cp -f $file ${LICHEE_PACK_OUT_DIR} 2> /dev/null
	done

	if [ "x${PACK_KERN}" = "xlinux-3.4" ]; then
		cp -f ${LICHEE_COMMON_CONFIG_DIR}/tools/cardscript.fex ${LICHEE_PACK_OUT_DIR} 2> /dev/null
	fi

	printf "copying configs file\n"
	for file in ${configs_file_list[@]} ; do
		cp -f $file ${LICHEE_PACK_OUT_DIR} 2> /dev/null
	done

	printf "copying product configs file\n"
	for file in ${product_configs_file_list[@]}; do
		cp -f $file ${LICHEE_PACK_OUT_DIR} 2>/dev/null
	done

	if [ x"${PACK_PLATFORM}" != x"android" ]; then
		printf "linux copying boardt&linux_kernel_version configs file\n"
		local possible_env_path=(
			configs/default
			configs/${LICHEE_BOARD}
			configs/${LICHEE_BOARD}/${LICHEE_KERN_VER}
			configs/${LICHEE_BOARD}/${PACK_PLATFORM}
		)
		local possible_env_list=(
			env.cfg
			env-$(echo ${LICHEE_KERN_VER} | awk -F '-' '{print $2}').cfg
		)
		local copy_env_file=''

		for d in ${possible_env_path[@]}; do
			[ ! -d ${LICHEE_CHIP_CONFIG_DIR}/$d ] && continue
			for file in ${possible_env_list[@]} ; do
				if [ -e "${LICHEE_CHIP_CONFIG_DIR}/$d/$file" ]; then
					copy_env_file=${LICHEE_CHIP_CONFIG_DIR}/$d/$file
				fi
			done
		done
		echo "Use u-boot env file: ${copy_env_file}"
		if [[ ! -f ${copy_env_file} ]]
		then
			echo -e "\e[33mWarning: u-boot env file '${copy_env_file}' not exist! use file in default directory other than '${PACK_BOARD}' directory\e[0m"
		fi

		cp -f ${copy_env_file} ${LICHEE_PACK_OUT_DIR}/env.cfg 2>/dev/null

		cp -f ${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/${LICHEE_KERN_VER}/sys_* ${LICHEE_PACK_OUT_DIR} 2>/dev/null
	fi

	# If platform config files exist, we will cover the default files
	# For example, mv pack_out/image_linux.cfg pack_out/image.cfg
	if [ ${PACK_PLATFORM} != "android" ]; then
		cp -f ${LICHEE_BOARD_CONFIG_DIR}/${PACK_PLATFORM}/* ${LICHEE_PACK_OUT_DIR} 2> /dev/null
		if [ ${PACK_PLATFORM} = "bsp" -o "x${PACK_PLATFORM}" = "xsata" ] ; then
			find ${LICHEE_PACK_OUT_DIR}/* -type f -a \( -name "*.fex" -o -name "*.cfg" \) -print | \
			sed "s#\(.*\)_linux\(\..*\)#mv -fv & \1\2#e"
		else
			find ${LICHEE_PACK_OUT_DIR}/* -type f -a \( -name "*.fex" -o -name "*.cfg" \) -print | \
			sed "s#\(.*\)_${PACK_PLATFORM}\(\..*\)#mv -fv & \1\2#e"
		fi
	else
		find ${LICHEE_PACK_OUT_DIR}/* -type f -a \( -name "*.fex" -o -name "*.cfg" \) -print | \
			sed "s#\(.*\)_${PACK_TYPE}\(\..*\)#mv -fv & \1\2#e"
	fi

	if [ "x${PACK_MODE}" = "xdump" ] ; then
		cp -vf ${LICHEE_PACK_OUT_DIR}/sys_partition_dump.fex ${LICHEE_PACK_OUT_DIR}/sys_partition.fex
		cp -vf ${LICHEE_PACK_OUT_DIR}/usbtool_test.fex ${LICHEE_PACK_OUT_DIR}/usbtool.fex
	elif [ "x${PACK_FUNC}" = "xprvt" ] ; then
		cp -vf ${LICHEE_PACK_OUT_DIR}/sys_partition_private.fex ${LICHEE_PACK_OUT_DIR}/sys_partition.fex
	fi

	printf "copying boot resource\n"
	for file in ${boot_resource_list[@]} ; do
		cp -rf $(echo $file | sed -e 's/:/ /g') 2>/dev/null
	done

	# openwrt use these logo files
	if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
		rm -rf ${LICHEE_PACK_OUT_DIR}/boot-resource
		cp -rf $CFG_TOP_DIR/${PACK_PLATFORM}/target/$PACK_IC/$PACK_IC-common/boot-resource/boot-resource ${LICHEE_PACK_OUT_DIR}
		cp -rf $CFG_TOP_DIR/${PACK_PLATFORM}/target/$PACK_IC/$PACK_IC-common/boot-resource/boot-resource.ini ${LICHEE_PACK_OUT_DIR}/boot-resource.ini
	fi

	if [ ! -f ${LICHEE_PACK_OUT_DIR}/bootlogo.bmp ]; then
		cp ${LICHEE_PACK_OUT_DIR}/boot-resource/bootlogo.bmp ${LICHEE_PACK_OUT_DIR}/bootlogo.bmp
	fi

	lzma -k ${LICHEE_PACK_OUT_DIR}/bootlogo.bmp
	lzma -k ${LICHEE_PACK_OUT_DIR}/bempty.bmp
	lzma -k ${LICHEE_PACK_OUT_DIR}/battery_charge.bmp

	if [ -f ${LICHEE_PACK_OUT_DIR}/bootlogo.bmp.lzma ]; then
		add_lzma_header "${LICHEE_PACK_OUT_DIR}/bootlogo.bmp.lzma" "${LICHEE_PACK_OUT_DIR}/bootlogo.bmp"
		(cd ${LICHEE_PACK_OUT_DIR}; ln -sf bootlogo.bmp.lzma.head  bootlogo.fex)
	fi

	printf "copying boot file\n"
	for d in ${possible_bin_path[@]}; do
		[ ! -d ${LICHEE_CHIP_CONFIG_DIR}/$d ] && continue
		BIN_PATH=$d
		for file in ${boot_file_list[@]} ; do
			eval cp -v -f $(echo $file | sed -e 's/:/ /g') 2>/dev/null
		done
	done
	printf "copying boot file 2.0\n"
	for file in ${boot_file_list_2[@]} ; do
		eval cp -v -f $(echo $file | sed -e 's/:/ /g') 2>/dev/null
	done
	if [[ ${LICHEE_BOARD} == *fastboot*spinand* ]] ; then
		mv -v ${LICHEE_PACK_OUT_DIR}/boot0_nandfastboot_${PACK_CHIP}.fex ${LICHEE_PACK_OUT_DIR}/boot0_nand.fex
	fi

	if ! [ -z ${LICHEE_BOOT0_BIN_NAME} ]; then
                # nand fastboot
                cp -v -f ${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex ${LICHEE_PACK_OUT_DIR}/boot0_nand.fex

		if [[ ${LICHEE_FLASH} == default ]] ; then
			mv -v ${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex ${LICHEE_PACK_OUT_DIR}/boot0_sdcard.fex
		elif [[ ${LICHEE_FLASH} == nor ]] ; then
			mv -v ${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex ${LICHEE_PACK_OUT_DIR}/boot0_spinor.fex
		else
			echo "invalid LICHEE_FLASH, default choose sdcard!"
			mv -v ${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex ${LICHEE_PACK_OUT_DIR}/boot0_sdcard.fex
		fi
	fi

	[ -z "${BIN_PATH}" ] &&
	pack_error "No BIN_PATH found!" && exit 1

	printf "copying $LICHEE_ARCH secure boot file\n"
	for d in ${possible_bin_path[@]}; do
		[ ! -d ${LICHEE_CHIP_CONFIG_DIR}/$d ] && continue
		BIN_PATH=$d
		for file in $(eval echo '$'"{${LICHEE_ARCH}_boot_file_secure[@]}"); do
			eval cp -f $(echo $file | sed -e 's/:/ /g') 2>/dev/null
		done
	done

	# If platform config use
	if [ -f ${LICHEE_CHIP_CONFIG_DIR}/tools/plat_config.sh ] ; then
		${LICHEE_CHIP_CONFIG_DIR}/tools/plat_config.sh
	fi

	if [ "x${PACK_NOR}" = "xnor" ] ; then
		cp -vf ${LICHEE_PACK_OUT_DIR}/image_nor.cfg ${LICHEE_PACK_OUT_DIR}/image.cfg
		cp -vf ${LICHEE_PACK_OUT_DIR}/sboot_nor.bin ${LICHEE_PACK_OUT_DIR}/sboot.bin
		cp -vf ${LICHEE_PACK_OUT_DIR}/dragon_toc_nor.cfg ${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
	fi

	if [ "x${PACK_VSP}" = "xvsp" ] ; then
		printf "change usb_port_type to device...\n"
		printf "disable usb_serial_unique...\n"
		printf "change usb_serial_number to ${PACK_TYPE}_android...\n"
		sed -i 's/^usb_port_type.*/usb_port_type = 0/g' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		sed -i 's/^usb_serial_unique.*/usb_serial_unique = 0/g' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		sed -i 's/^usb_serial_number.*/usb_serial_number = "'"${PACK_CHIP}"'_android"/g' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	fi

	printf "copying additional files\n"
	for file in ${PACK_ADD_FILES[@]}; do
		cp -vf $(echo $file | sed -e 's/:/ /g') 2>/dev/null
	done

	if [ "x${PACK_PLATFORM}" == "xandroid" ] && [ "x$TARGET_BUILD_VARIANT" == "xuser" ]; then
		pack_info "change kernel loglevel to 3 for android user build"
		sed -i 's|^\s*loglevel=[0-9]\s*$|loglevel=3|g' ${LICHEE_PACK_OUT_DIR}/env.cfg
		if [ "${ENABLE_VENDOR_ADB}" == "true" ]; then
			pack_info "enable vendor adb for android user build"
			sed -i 's|^init_rc=.*$|init_rc=/vendor/etc/init/hw/init.aw.rc|g' ${LICHEE_PACK_OUT_DIR}/env.cfg
		fi
	fi

	if [ "x${PACK_PROGRAMMER}" = "xprogrammer" ]; then
		printf "add programmer img info target in sys config\n"
		sed -i -e '/^\[target\]/a\programmer=1' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	fi

	sed -i 's/\\boot-resource/\/boot-resource/g' ${LICHEE_PACK_OUT_DIR}/boot-resource.ini
	sed -i 's/\\\\/\//g' ${LICHEE_PACK_OUT_DIR}/image.cfg
	sed -i 's/^imagename/;imagename/g' ${LICHEE_PACK_OUT_DIR}/image.cfg

	prepare_mixed_androiddragonboard
	[ $? -ne 0 ] && exit 1

	partition_size_handle
	[ $? -ne 0 ] && exit 1

	if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
		cd ${LICHEE_PACK_OUT_DIR}/
		echo "vmlinux" > ${LICHEE_PACK_OUT_DIR}/vmlinux.fex
		if [ "x${PACK_NOR}" = "xnor" ] ; then
			make_user_res sys_partition_nor.fex
			make_app_res sys_partition_nor.fex
			make_data_res sys_partition_nor.fex
		else
			make_user_res sys_partition.fex
			make_app_res sys_partition.fex
			make_data_res sys_partition.fex
		fi
		cd - > /dev/null
	fi
}

function img_to_programmer()
{
	local out_img=$1
	local in_img=$2

	cd ${LICHEE_PACK_OUT_DIR}/

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		if [ -f toc0_sdcard.fex ] ; then
			programmer_img toc0_sdcard.fex toc1.fex ${out_img} > /dev/null
		elif [ -f toc0_nand.fex ] ; then
			programmer_img toc0_nand.fex toc1.fex ${out_img} > /dev/null
		else
			programmer_img toc0.fex toc1.fex ${out_img} > /dev/null
		fi
	else
		programmer_img boot0_sdcard.fex boot_package.fex ${out_img} > /dev/null
	fi

	if [ -f sunxi_gpt.fex ] ; then
		#create_img for sunxi_gpt.fex
		programmer_img sys_partition.bin sunxi_mbr.fex ${out_img} ${in_img} sunxi_gpt.fex > /dev/null
	else
		#create_img for sunxi_mbr.fex
		programmer_img sys_partition.bin sunxi_mbr.fex ${out_img} ${in_img} > /dev/null
	fi

}

function uboot_ini_to_dts()
{
	local TARGET_UBOOT
	local PLATFORM_ADDR
	local SOC_ADDR
	local DTC_FLAGS=""

	if [ x${LICHEE_BRANDY_UBOOT_VER} == x2023 ]; then
		pack_info "skip split fdt"
		return
	fi

	if [ "x${PACK_NOR}" == "xnor" ]; then
		TARGET_UBOOT=${LICHEE_PACK_OUT_DIR}/u-boot-spinor.fex
	else
		TARGET_UBOOT=${LICHEE_PACK_OUT_DIR}/u-boot.fex
	fi
	sunxi_ubootools split ${TARGET_UBOOT} > /dev/null
	if [ $? -ne 0 ]
	then
		pack_warn "split uboot and fdt failed!!"
		return
	fi

	[ "$(readlink -f .)" != "$(readlink -f ${LICHEE_PACK_OUT_DIR})" ] && {
		mv temp_fdt.dtb  ${LICHEE_PACK_OUT_DIR}
		mv temp_ubootnodtb.bin  ${LICHEE_PACK_OUT_DIR}
	}

	# to dts
	$DTC_COMPILER ${DTC_FLAGS} -I dtb -O dts -o ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp ${LICHEE_PACK_OUT_DIR}/temp_fdt.dtb  2>/dev/null

	PLATFORM_ADDR=`grep -Po "(?<=platform@)(\w+)(?=\s*{)" ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp | head -1`
	SOC_ADDR=`grep -Po "(?<=soc@)(\w+)(?=\s*{)" ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp | head -1`

	if [ "x${PACK_TYPE}" = "xdragonboard" -o "x${PACK_TYPE}" = "xdragonabts" ] ; then
		cat <<- EOF >> ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp
		/{
			soc@${SOC_ADDR} {
				platform@${PLATFORM_ADDR} {
				dragonboard_test = <1>;
				};
			};
		};
		EOF
	fi

	# to dtb
	$DTC_COMPILER ${DTC_FLAGS} -I dts -O dtb -o ${LICHEE_PACK_OUT_DIR}/temp_fdt.dtb ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp  2>/dev/null

	# get update_to_ubootfdt value from sysconfig
	sunxi_ubootools subkey_value sys_config.bin sunxi_ubootools update_to_ubootfdt > /dev/null
	if [ $? -eq 1 ]; then
		echo "uboot ini to dts"
		$DTC_COMPILER -p 2048 ${DTC_FLAGS} -@ -O dtb -o ${LICHEE_PACK_OUT_DIR}/new_fdt.dtb	\
			-b 0			\
			-i ${LICHEE_PACK_OUT_DIR}	\
			-F $DTC_INI_FILE \
			-d ${LICHEE_PACK_OUT_DIR}/temp_fdt.dtb ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp 2>/dev/null
	else
		mv ${LICHEE_PACK_OUT_DIR}/temp_fdt.dtb  ${LICHEE_PACK_OUT_DIR}/new_fdt.dtb
	fi

	sunxi_ubootools merge ${LICHEE_PACK_OUT_DIR}/temp_ubootnodtb.bin ${LICHEE_PACK_OUT_DIR}/new_fdt.dtb > /dev/null
	cp -vf ${LICHEE_PACK_OUT_DIR}/temp_ubootnodtb.bin ${TARGET_UBOOT}
	# .uboot.dts is the last dts of uboot
	$DTC_COMPILER ${DTC_FLAGS} -I dtb -O dts -o ${LICHEE_PACK_OUT_DIR}/.uboot.dts ${LICHEE_PACK_OUT_DIR}/new_fdt.dtb 2>/dev/null
}

function do_ini_to_dts()
{
	cd ${LICHEE_PACK_OUT_DIR}/

	maybe_busybox unix2dos sys_config.fex
	script  sys_config.fex > /dev/null

	local DTC_SRC_PATH=${LICHEE_PLAT_OUT}
	local DTC_COMPILER=${LICHEE_PLAT_OUT}/dtc
	local DTC_FLAGS=""

	uboot_ini_to_dts

	if [ "x${PACK_KERN}" == "xlinux-3.4" \
			-o "x${PACK_KERN}" == "xlinux-3.10" \
			-o "x${PACK_KERN}" == "xlinux-4.4" \
			-o "x${PACK_KERN}" == "xlinux-5.4" \
			-o "x${PACK_KERN}" == "xlinux-5.4-ansc" \
			-o "x${PACK_KERN}" == "xlinux-5.10" \
			-o "x${PACK_KERN}" == "xlinux-5.10-origin" \
			-o "x${PACK_KERN}" == "xlinux-5.15" \
			-o "x${PACK_KERN}" == "xlinux-5.15-origin" ] || [[  ${PACK_KERN/linux-} > 5.15 ]]; then
		# For debug: sunxi.dtb -> .sunxi.dts
		$DTC_COMPILER ${DTC_FLAGS} -I dtb -O dts -o ${LICHEE_PLAT_OUT}/.sunxi.dts ${LICHEE_PLAT_OUT}/sunxi.dtb 2>/dev/null
		return
	fi

	local dtc_file_list=(
		.board.dtb.d.dtc.tmp:.board.dtb.dts.tmp
		.${PACK_CHIP}-${PACK_BOARD}.dtb.d.dtc.tmp:.${PACK_CHIP}-${PACK_BOARD}.dtb.dts.tmp
		.${PACK_CHIP}-${LICHEE_BUSSINESS}.dtb.d.dtc.tmp:.${PACK_CHIP}-${LICHEE_BUSSINESS}.dtb.dts.tmp
		.${PACK_CHIP}-soc.dtb.d.dtc.tmp:.${PACK_CHIP}-soc.dtb.dts.tmp)

	local DTC_INI_FILE_BASE=${LICHEE_PACK_OUT_DIR}/sys_config.fex
	local DTC_INI_FILE=${LICHEE_PACK_OUT_DIR}/sys_config_fix.fex

	cp $DTC_INI_FILE_BASE $DTC_INI_FILE
	sed -i "s/\(\[dram\)_para\(\]\)/\1\2/g" $DTC_INI_FILE
	sed -i "s/\(\[nand[0-9]\)_para\(\]\)/\1\2/g" $DTC_INI_FILE

	if [ ! -f $DTC_COMPILER ]; then
		pack_error "Script_to_dts: Can not find dtc compiler.\n"
		exit 1
	fi

	local DTC_DEP_FILE DTC_SRC_FILE
	for e in ${dtc_file_list[@]}; do
		DTC_DEP_FILE=$DTC_SRC_PATH/${e/:*}
		if [ -f $DTC_DEP_FILE ]; then
			DTC_SRC_FILE=$DTC_SRC_PATH/${e#*:}
			break
		fi
	done

	echo "sunxi_dtb create"
	$DTC_COMPILER -p 2048 ${DTC_FLAGS} -@ -O dtb -o ${LICHEE_PLAT_OUT}/sunxi.dtb	\
		-b 0			\
		-i $DTC_SRC_PATH	\
		-F $DTC_INI_FILE	\
		-d $DTC_DEP_FILE $DTC_SRC_FILE 2>/dev/null

	if [ $? -ne 0 ]; then
		pack_error "Conver script to dts failed"
		exit 1
	fi

	#restore the orignal dtsi
	if [ "x${PACK_TYPE}" = "xdragonboard" \
		-o "x${PACK_TYPE}" = "xdragonmat" ]; then
		local DTS_PATH=${LICHEE_KERN_DIR}/arch/${LICHEE_ARCH}/boot/dts
		[ "x${LICHEE_ARCH}" = "xarm64" ] && DTS_PATH=${LICHEE_KERN_DIR}/arch/${LICHEE_ARCH}/boot/dts/sunxi
		if [ -f ${DTS_PATH}/${PACK_CHIP}_bak.dtsi ];then
			rm -f ${DTS_PATH}/${PACK_CHIP}.dtsi
			mv  ${DTS_PATH}/${PACK_CHIP}_bak.dtsi  ${DTS_PATH}/${PACK_CHIP}.dtsi
		fi
	fi

	printf "Conver script to dts ok.\n"

	# It'is used for debug dtb
	$DTC_COMPILER ${DTC_FLAGS} -I dtb -O dts -o ${LICHEE_PLAT_OUT}/.sunxi.dts ${LICHEE_PLAT_OUT}/sunxi.dtb 2>/dev/null

	return
}

function maybe_busybox()
{
	if [ "x$(which busybox)" == "x" ]; then
		pack_error "Tool busybox does not exist!"
		exit 1
	fi

	busybox $@ || $@
}

function generate_env_for_uboot()
{
	printf "$1 Conver to $2.\n"
	printf "LICHEE_BRANDY_UBOOT_VER : ${LICHEE_BRANDY_UBOOT_VER}\n"
	if [ -n "${LICHEE_BRANDY_UBOOT_VER}" ] && [ ${LICHEE_BRANDY_UBOOT_VER} -ge 2023 ]; then
		printf "create env.fex for uboot2023 or later, size 128K\n"
		# mkenvimage -p 0x00 -s 0x20000 -o env.fex env.cfg
		mkenvimage -p 0x00 -s 0x20000 -o $2 $1
	else
		# u_boot_env_gen env_nor.cfg env_nor.fex >/dev/null
		u_boot_env_gen $1 $2 >/dev/null
	fi
}

function do_common()
{
	cd ${LICHEE_PACK_OUT_DIR}/

	echo $(date -d "$ts" +"%Y-%m-%d %H:%M:%S") > ${LICHEE_PACK_OUT_DIR}/sunxi_version.fex

	# Here, we can switch uart to card or normal
	if [ "x${PACK_DEBUG}" = "xcard0" -a "x${PACK_MODE}" != "xdump" \
		-a "x${PACK_FUNC}" != "xprvt" ] ; then \
		uart_switch
	else
		sed -i -e '/^auto_print_used/s\1\0\' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	fi

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		printf "add burn_secure_mode in target in sys config\n"
		sed -i -e '/^\[target\]/a\burn_secure_mode=1' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		sed -i -e '/^\[platform\]/a\secure_without_OS=0' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		if [ -f ${LICHEE_PACK_OUT_DIR}/optee-monitor.fex ]; then
			rm -f ${LICHEE_PACK_OUT_DIR}/optee-monitor.fex
		fi
	else
		sed -i '/^burn_secure_mod/d' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		sed -i '/^secure_without_OS/d' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		if [ -f ${LICHEE_PACK_OUT_DIR}/optee-monitor.fex ]; then
			mv -v ${LICHEE_PACK_OUT_DIR}/optee-monitor.fex ${LICHEE_PACK_OUT_DIR}/optee.fex
		fi
	fi

	if [ ! -f board_config.fex ]; then
		echo "[empty]" > board_config.fex
	fi

	maybe_busybox unix2dos sys_config.fex
	maybe_busybox unix2dos board_config.fex
	script  sys_config.fex > /dev/null
	cp -f   sys_config.bin config.fex
	script  board_config.fex > /dev/null
	cp -f board_config.bin board.fex

	maybe_busybox unix2dos sys_partition.fex
	script  sys_partition.fex > /dev/null


	if [ "x${PACK_TYPE}" = "xdragonboard" ] ; then
		maybe_busybox dos2unix test_config.fex
		cp test_config.fex boot-resource/
		maybe_busybox unix2dos test_config.fex
		script test_config.fex > /dev/null
		cp test_config.bin boot-resource/
	fi

	if [ "x${PACK_TYPE}" = "xdragonabts" ] ; then
		maybe_busybox dos2unix test_config.fex
		cp test_config.fex boot-resource/
		maybe_busybox unix2dos test_config.fex
		script test_config.fex > /dev/null
		cp test_config.bin boot-resource/
	fi
	# Those files for SpiNor. We will try to find sys_partition_nor.fex
	if [ "x${PACK_NOR}" = "xnor" ] ; then

		if [ ! -f sys_partition_nor.fex ];  then
			echo "sys partition for nor not exist"
			exit 1
		fi

		if [ ! -f ${LICHEE_CHIP_CONFIG_DIR}/tools/arisc_config_parse.sh ]; then
			if [ -f "scp.fex" ]; then
				echo "update scp"
				update_scp scp.fex sunxi.fex >/dev/null
			fi
		fi

		# Here, will create sys_partition_nor.bin
		maybe_busybox unix2dos sys_partition_nor.fex
		script  sys_partition_nor.fex > /dev/null
		update_boot0 boot0_spinor.fex   sys_config.bin SPINOR_FLASH > /dev/null
		update_chip boot0_spinor.fex   > /dev/null
		update_fes1  fes1.fex           sys_config.bin > /dev/null

		if [ "x${PACK_KERN}" = "xlinux-3.4" ] ; then
			update_uboot -merge u-boot-spinor.fex  sys_config.bin > /dev/null
		else
			update_uboot -no_merge u-boot-spinor.fex  sys_config.bin > /dev/null
			update_uboot -no_merge u-boot-spinor-secure.fex  sys_config.bin > /dev/null
			[ -f u-boot-efex.fex ] && {
				update_uboot -no_merge u-boot-efex.fex  sys_config.bin > /dev/null
			}
		fi

		while read line
		do
			compress_name=(`echo $line | awk '($1 !~ ";" && ($2 ~ "lzma" || $2 ~ "lz4" || $2 ~ "gz")) {print $2}'`)
			source_name=(`echo $compress_name | cut -d \.  -f 1,2 | cut -d \  -f 2`)
			compress_type=(`echo $compress_name | cut -d \.  -f 3 | cut -d \  -f 2`)
			[ -z "$compress_name" ] && continue
			case $compress_type in
			"gz")
				[ -f $source_name ] && gzip -c $source_name > $compress_name || echo "no exist $source_name"
				echo "compress name: $compress_name"
				;;
			"lzma")
				[ -f $source_name ] && lzma -k $source_name || echo "no exist $source_name"
				mv $source_name.lzma $compress_name >/dev/null 2<&1
				echo "compress name: $compress_name"
				;;
			"lz4")
				[ -f $source_name ] && lz4 -f $source_name $compress_name || echo "no exist $source_name"
				echo "compress name: $compress_name"
				;;
			*)
				echo "no match compress type"
				;;
			esac
			echo "compress type: $compress_type"
		done < boot_package_nor.cfg

		if [ -f boot_package_nor.cfg ]; then
			mv u-boot-spinor-crash.fex u-boot-crash.fex
			echo "pack boot package"
			maybe_busybox unix2dos boot_package.cfg
			dragonsecboot -pack boot_package_nor.cfg
			cp boot_package.fex boot_package_nor.fex
		fi
		# Ugly, but I don't have a better way to change it.
		# We just set env's downloadfile name to env_nor.cfg in sys_partition_nor.fex
		# And if env_nor.cfg is not exist, we should copy one.
		if [ ! -f env_nor.cfg ]; then
			cp -f env.cfg env_nor.cfg >/dev/null 2<&1
		fi

		#card sprite
		if [ -f "boot0_sdcard.fex" ]; then
			update_boot0 boot0_sdcard.fex   sys_config.bin SDMMC_CARD > /dev/null
			update_chip boot0_sdcard.fex > /dev/null
		fi

		# Fixup boot mode for SPINor, just can bootm
		sed -i '/^boot_normal/s#\<boota\>#bootm#g' env_nor.cfg

		echo 1:LICHEE_REDUNDANT_ENV_SIZE:$LICHEE_REDUNDANT_ENV_SIZE
		if [ "x${LICHEE_REDUNDANT_ENV_SIZE}" != "x" ]; then
			echo "--mkenvimage create redundant env data!--"
			echo "--redundant nor env data size ${LICHEE_REDUNDANT_ENV_SIZE}---"
			mkenvimage -r -p 0x00 -s ${LICHEE_REDUNDANT_ENV_SIZE} -o env_nor.fex env_nor.cfg
		else
			generate_env_for_uboot env_nor.cfg env_nor.fex
		fi
	else
		update_boot0 boot0_nand.fex     sys_config.bin NAND > /dev/null
		update_boot0 boot0_sdcard.fex   sys_config.bin SDMMC_CARD > /dev/null
		update_boot0 boot0_ufs.fex   sys_config.bin UFS > /dev/null
		update_chip boot0_nand.fex >/dev/null
		update_chip boot0_sdcard.fex >/dev/null
		update_chip boot0_ufs.fex >/dev/null
	fi

	if [ ! -f "u-boot-crash.fex" ]; then
		touch "u-boot-crash.fex"
		echo "ensure u-boot-crash.fex is not empty" > u-boot-crash.fex
	fi

	if [ -f "sunxi.fex" ]; then
		update_dtb sunxi.fex 4096
	fi

	if [ ! -f ${LICHEE_CHIP_CONFIG_DIR}/tools/arisc_config_parse.sh ]; then
		if [ -f "scp.fex" ]; then
			echo "update scp"
			update_scp scp.fex sunxi.fex >/dev/null
		fi
	fi

	if [ -f "optee.fex" ]; then
		echo "update optee"
		update_optee optee.fex sunxi.fex >/dev/null
	fi

	# Those files for Nand or Card
	if [ "x${PACK_KERN}" = "xlinux-3.4" ] ; then
		update_uboot -merge u-boot.fex sys_config.bin > /dev/null
	else
		update_uboot -no_merge u-boot.fex sys_config.bin > /dev/null
		[ -f u-boot-nodtb.fex ] && {
			update_uboot -no_merge u-boot-nodtb.fex sys_config.bin > /dev/null
		}
		[ -f u-boot-efex.fex ] && {
			update_uboot -no_merge u-boot-efex.fex  sys_config.bin > /dev/null
		}
	fi

	if [ -f "fes1_uart.fex" ]; then
		update_fes1  fes1_uart.fex           sys_config.bin > /dev/null
	fi

	update_fes1  fes1.fex           sys_config.bin > /dev/null
	if [ -f ${LICHEE_TOOLS_DIR}/pack/pctools/linux/mod_update/update_sboot ];then
		update_sboot sboot.bin  sys_config.bin  > /dev/null
		if [ $? -ne 0 ]
		then
			pack_error "update sboot run error"
			exit 1
		fi
	fi
	fsbuild      boot-resource.ini  split_xxxx.fex > /dev/null

	if [ -f boot_package_uartburn.cfg ]; then
		dragonsecboot -pack boot_package_uartburn.cfg
		if [ $? -ne 0 ]
		then
			pack_error "dragon pack boot_package_uartburn run error"
			exit 1
		fi
		mv boot_package.fex boot_package_uartburn.fex
	fi

	if [ -f boot_package.cfg ]; then
		if [ "x$LINUX_DTBO_FILE" = "x" ]; then
			echo "do not set LINUX_DTBO_FILE"
			line_num=`sed -n -e "/default.dtbo/=" boot_package.cfg`
			if [ "x$line_num" != "x" ]; then
				sed -i "$line_num s/^/;/g" boot_package.cfg
			fi
		else
			if [ -f $LINUX_DTBO_FILE ]
			then
				sed -i "s/default.dtbo/$LINUX_DTBO_FILE/g" boot_package.cfg
			else
				line_num=`sed -n -e "/default.dtbo/=" boot_package.cfg`
				if [ "x$line_num" != "x" ]; then
					sed -i "$line_num s/^/;/g" boot_package.cfg
				fi
			fi
		fi

			echo "pack boot package"
			maybe_busybox unix2dos boot_package.cfg
			dragonsecboot -pack boot_package.cfg

		if [ $? -ne 0 ]
		then
			pack_error "dragon pack run error"
			exit 1
		fi
	fi

	echo 2:LICHEE_REDUNDANT_ENV_SIZE:$LICHEE_REDUNDANT_ENV_SIZE
	if [ "x${PACK_FUNC}" = "xprvt" ] ; then
		if [ "x${LICHEE_REDUNDANT_ENV_SIZE}" != "x" ]; then
			echo "--mkenvimage create redundant env data!--"
			echo "--redundant env data size ${LICHEE_REDUNDANT_ENV_SIZE}---"
			mkenvimage -r -p 0x00 -s ${LICHEE_REDUNDANT_ENV_SIZE} -o env.fex env_burn.cfg
		else
			generate_env_for_uboot env_burn.cfg env.fex
		fi
	else
		if [ "x${LICHEE_REDUNDANT_ENV_SIZE}" != "x" ]; then
			echo "--mkenvimage create redundant env data!--"
			echo "--redundant env data size ${LICHEE_REDUNDANT_ENV_SIZE}---"
			mkenvimage -r -p 0x00 -s ${LICHEE_REDUNDANT_ENV_SIZE} -o env.fex env.cfg
		else
			generate_env_for_uboot env.cfg env.fex
		fi
	fi

	dmverity_deal clean

}

function do_finish()
{
	# Yeah, it should contain all files into full_img.fex for spinor
	# Because, as usually, spinor image size is very small.
	# If fail to create full_img.fex, we should fake it empty.

	# WTF, it is so ugly!!! It must be sunxi_mbr.fex & sys_partition.bin,
	# not sunxi_mbr_xxx.fex & sys_partition_xxx.bin. In order to advoid this
	# loathsome thing, we need to backup & copy files. Check whether
	# sys_partition_nor.bin is exist, and create sunxi_mbr.fex for Nor.
	local max_toc_size=2097152

	local IMG_NAME="${PACK_IC}_${PACK_TYPE}${PACK_PLATFORM_VERSION}_${PACK_BOARD}_${PACK_DEBUG}"
	if [ "x${PACK_MODE}" = "xdump" ] ; then
		IMG_NAME="${IMG_NAME}_${PACK_MODE}"
	fi

	if [ "x${PACK_FUNC}" = "xprvt" ]; then
		IMG_NAME="${IMG_NAME}_${PACK_FUNC}"
	fi

	if [ "x${PACK_SECURE}" = "xsecure" ] ; then
		IMG_NAME="${IMG_NAME}_${PACK_SECURE}"
	fi

	if [ "x${PACK_FUNC}" = "xprev_refurbish" ] ; then
		IMG_NAME="${IMG_NAME}_${PACK_FUNC}"
	fi

	if [ "x${PACK_NOR}" = "xnor" ] ; then
		IMG_NAME="${IMG_NAME}_${PACK_NOR}"
	fi

	if [ "x${PACK_SECURE}" != "xnone" ]; then
		local MAIN_VERION=$(readcfg dragon_toc.cfg rollback_ver ver)
		if [ ! -n "${MAIN_VERION}" ]; then
			local MAIN_VERION="$(echo '__unique:;@echo ${MAIN_VERSION}' | make -f - -f ${LICHEE_PACK_OUT_DIR}/version_base.mk --no-print-directory __unique)"
		fi
		IMG_NAME="${IMG_NAME}_v${MAIN_VERION}.img"
	else
		IMG_NAME="${IMG_NAME}.img"
	fi

	local IMG_PROGRAMMER_NAME="${IMG_NAME%.*}_programmer.img"

	echo "imagename = $IMG_NAME" >> ${LICHEE_PACK_OUT_DIR}/image.cfg
	echo "" >> ${LICHEE_PACK_OUT_DIR}/image.cfg

	local imagesize
	local toc_size
	local max_toc_size=3883264

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		toc_size=`stat toc1.fex --format="%s"`
	else
		toc_size=`stat boot_package.fex --format="%s"`
	fi

	if [ "$LICHEE_CHIP" == "sun55iw3p1" ]; then
		max_toc_size=3883264
	fi

	if [ ${toc_size} -gt ${max_toc_size} ];then
		pack_error "boot_package.fex/toc1.fex More than ${max_toc_size} bytes limit too large!!!"
		exit 1
	fi

	if [ "x${PACK_NOR}" = "xnor" ] ; then
		NOR_LOGIC_START=2016
		NOR_UBOOT_START=128
		NOR_FLASH_SIZE=65536 #32M
		NOR_LOGIC_START_KB=`expr ${NOR_LOGIC_START} / 2`
		NOR_UBOOT_START_KB=`expr ${NOR_UBOOT_START} / 2`

		local uboot_dts=""
		if [ -n "${LICHEE_BRANDY_UBOOT_VER}" ] && [ ${LICHEE_BRANDY_UBOOT_VER} -ge 2023 ]; then
			uboot_dts="${LICHEE_BOARD_CONFIG_DIR}/uboot-${LICHEE_BRANDY_UBOOT_VER}/uboot-board.dts"
		else
			uboot_dts="${LICHEE_BOARD_CONFIG_DIR}/uboot-board.dts"
		fi

		if [ -f ${uboot_dts} ] && [ x"$(grep "nor_map" ${uboot_dts})" != x"" ]; then
			echo "get flashmap from ${uboot_dts}"
			NOR_FLASH_SIZE=$(awk '/nor_map {/,/}/ {print NR ": " $0}' ${uboot_dts} \
				| grep  "\bflash_size\b" | grep -oP "(?<=\<)\d+(?=\>)")

			NOR_LOGIC_START=$(awk '/nor_map {/,/}/ {print NR ": " $0}' ${uboot_dts} \
				| grep  "\blogic_offset\b" | grep -oP "(?<=\<)\d+(?=\>)")

			NOR_UBOOT_START=$(awk '/nor_map {/,/}/ {print NR ": " $0}' ${uboot_dts} \
				| grep  "\buboot_start\b" | grep -oP "(?<=\<)\d+(?=\>)")

			[ x"${NOR_FLASH_SIZE}" = x"" -o x"${NOR_LOGIC_START}" = x"" -o x"${NOR_UBOOT_START}" = x"" ] && {
				pack_warn "flash_size,logic_offset,uboot_start maybe not set in uboot-board.dts"
				NOR_LOGIC_START=2016
				NOR_UBOOT_START=128
				NOR_FLASH_SIZE=65536 #32M
			}

			NOR_LOGIC_START_KB=`expr ${NOR_LOGIC_START} / 2`
			NOR_UBOOT_START_KB=`expr ${NOR_UBOOT_START} / 2`
			echo "flash size:${NOR_FLASH_SIZE}, logic start:${NOR_LOGIC_START}, uboot start:${NOR_UBOOT_START}"
		fi

		update_mbr sys_partition_nor.bin 1 sunxi_mbr_nor.fex dlinfo.fex \
				${NOR_FLASH_SIZE} ${NOR_LOGIC_START} 1

		if [ $? -ne 0 ]; then
			pack_error "update_mbr failed"
			exit 1
		fi
		echo '----------programmer nor image is full_img.fex ----------'
		if [ "x${PACK_KERN}" = "xlinux-3.4" ] ; then
		#when use devicetree, the size of uboot+dtb is larger then 256K
			#BOOT1_FILE=u-boot-spinor.fex
			#LOGIC_START=240 #240+16=256K
			#merge_package full_img.fex boot0_spinor.fex \
			#        u-boot-spinor.fex sunxi_mbr_nor.fex sys_partition_nor.bin
			merge_full_img --out full_img.fex --boot0 boot0_spinor.fex --boot1 u-boot-spinor.fex \
							--mbr sunxi_mbr_nor.fex  --partition sys_partition_nor.bin \
							--logic_start 240 > /dev/null
		else
			merge_full_img --out full_img.fex --boot0 boot0_spinor.fex --boot1 boot_package_nor.fex \
				--mbr sunxi_gpt.fex --partition sys_partition_nor.bin \
				--logic_start ${NOR_LOGIC_START_KB} --uboot_start ${NOR_UBOOT_START_KB} > /dev/null
		fi

		if [ $? -ne 0 ]; then
			pack_error "merge_full_img failed"
			exit 1
		fi
		mv sys_partition_nor.fex sys_partition.fex
	fi

	if [ ! -f sys_partition_nor.bin ]; then
		update_mbr          sys_partition.bin 4
		if [ $? -ne 0 ]; then
			pack_error "update_mbr failed"
			exit 1
		fi

		#15269888 is from emmc datasheet, sec_count in Extended CSD is 0xe90000 = 15269888.
		#40960 is the mbr location for emmc
		#0  is emmc/nand ; 1 is spinor
		update_mbr sys_partition.bin 4 sunxi_mbr.fex dlinfo.fex 15269888 40960 0
		if [ $? -ne 0 ]; then
			pack_error "update_mbr_gpt failed"
			exit 1
		fi
	fi

	if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
		echo "===================================="
		echo "show sys_partition.fex message"
		show_partition_message sys_partition.fex
	fi

	local e cfgadd cfgget lastcfgline localfile filename
	local imgcfg_add_list=(
		# localfile             filename-in-cfg        maintype  subtype
		'vmlinux.fex            vmlinux.fex            12345678  123456789VMLINUX'
		'vendor_boot-debug.fex  vendor_boot-debug.fex  RFSFAT16  VENDOR_BOOTDEBUG'
		'dragon_toc.cfg         dragon_toc.fex         12345678  12345678DGTOCCFG'
		)

	for e in "${imgcfg_add_list[@]}"; do
		localfile="$(awk '{print $1}' <<< $e)"
		filename="$(awk '{print $2}' <<< $e)"
		maintype="$(awk '{print $3}' <<< $e)"
		subtype="$(awk '{print $4}' <<< $e)"
		cfgget="$(sed -n '/^\s*{\s*filename\s*=\s*"'$filename'"\s*,/p' image.cfg)"
		lastcfgline="$(sed -n '/^\s*{\s*filename\s*=/=' image.cfg | tail -1)"

		[ ! -f "$localfile" -o -n "$cfgget" -o -z "$lastcfgline" ] && continue
		[ "$localfile" != "$filename" ] && ln -sf $localfile $filename
		cfgadd='    {filename = "'$filename'",'
		cfgadd+='     maintype = "'$maintype'",'
		cfgadd+='     subtype  = "'$subtype'",},'
		sed -i -e  ''"${lastcfgline}"'a\' -e "$cfgadd" image.cfg
	done

	dragon image.cfg    sys_partition.fex
	if [ $? -eq 0 ]; then
		if [ -e ${IMG_NAME} ]; then
			mv ${IMG_NAME} $LICHEE_OUT_DIR/$LICHEE_IC/$LICHEE_BOARD/$LICHEE_LINUX_DEV/${IMG_NAME}
			rm -f $LICHEE_OUT_DIR/${IMG_NAME}
			ln -f $LICHEE_OUT_DIR/$LICHEE_IC/$LICHEE_BOARD/$LICHEE_LINUX_DEV/${IMG_NAME}  $LICHEE_OUT_DIR/${IMG_NAME}
			imagesize=$(du --apparent-size -sh $LICHEE_OUT_DIR/$LICHEE_IC/$LICHEE_BOARD/$LICHEE_LINUX_DEV/${IMG_NAME} | awk '{print $1}')
			echo '----------image is at----------'
			echo -e '\033[0;31;1m'
			echo -e "$imagesize\t${LICHEE_OUT_DIR}/${IMG_NAME}"
			echo -e '\033[0m'
		fi
	fi
	cd ..

	if [ "x${PACK_PROGRAMMER}" = "xprogrammer" ]; then
		if [ -f  $LICHEE_PACK_OUT_DIR/super.fex ]; then
			mv $LICHEE_PACK_OUT_DIR/super.fex $LICHEE_PACK_OUT_DIR/super.bak.fex
			simg2img  $LICHEE_PACK_OUT_DIR/super.bak.fex $LICHEE_PACK_OUT_DIR/super.fex
		fi
		echo "waiting to ceate programmer img..."
		img_to_programmer ${IMG_PROGRAMMER_NAME} $LICHEE_OUT_DIR/${LICHEE_IC}/${LICHEE_BOARD}/${LICHEE_LINUX_DEV}/${IMG_NAME}
		if [ $? -eq 0 ]; then
			if [ -e ${IMG_PROGRAMMER_NAME} ]; then
				mv $LICHEE_PACK_OUT_DIR/${IMG_PROGRAMMER_NAME} $LICHEE_OUT_DIR/${LICHEE_IC}/${LICHEE_BOARD}/${LICHEE_LINUX_DEV}/${IMG_PROGRAMMER_NAME}
				imagesize=$(du --apparent-size -sh $LICHEE_OUT_DIR/${LICHEE_IC}/${LICHEE_BOARD}/${LICHEE_LINUX_DEV}/${IMG_PROGRAMMER_NAME} | awk '{print $1}')
				echo '----------programmer image is at----------'
				echo -e '\033[0;31;1m'
				echo -e "$imagesize\t${LICHEE_OUT_DIR}/${IMG_PROGRAMMER_NAME}"
				echo -e '\033[0m'
			fi
		fi
	fi
	cd ..
	do_finish_SATA
	printf "pack finish\n"
	[ -e ${LICHEE_TOP_DIR}/build/.hooks/post-dragon ] &&
		source ${LICHEE_TOP_DIR}/build/.hooks/post-dragon
	return 0
}

function do_finish_SATA()
{
	if [ "x$BUILD_SATA" = "xtrue" ];then
		SATA_TAR=$LICHEE_TOP_DIR/SATA/linux/${LICHEE_CHIP}.tar
		if [ -f $SATA_TAR ];then
			echo '----------SATA is at----------'
			echo -e '\033[0;31;1m'
			echo $SATA_TAR
			echo -e '\033[0m'
		else
			echo PACK SATA failed!
		fi
	fi
}

function dmverity_deal()
{
	local script_name=scripts/build.sh
	local script_path=$LICHEE_KERN_DIR

	if [ ! -x $script_path/$script_name ]; then
		script_path=$LICHEE_BUILD_DIR
		script_name=mkkernel.sh
	fi

	[ ! -x $script_path/$script_name ] && return 255
	[ -z "$(grep "^\s*deal_verity)\s*$" $script_path/$script_name)" ] && return 1

	(cd $script_path && ./$script_name "deal_verity" $@)
}

function dmverity_get_blk_count()
{
	local size=`du --apparent-size -b $1 | awk '{print $1}'`
	local BLK_SIZE=$2

	if [ `expr ${size} % ${BLK_SIZE}` = "0" ]; then
			local blks=`(expr ${size} / ${BLK_SIZE})`
	else
			local blks=`(expr ${size} / ${BLK_SIZE} + 1 )`
	fi

	echo $blks
}

function dmverity_determ_blk_size()
{
	local type_info=`file -L $1`

	#check rootfs file system type to determ block size
	if [ "x""`echo ${type_info}| grep "ext4 filesystem"`" != "x" ];then
		block_size=`tune2fs -l $1|grep "Block size"|awk {'print $3'}`
		echo ${block_size}
	else
		echo "not support file system type"
		return -1
	fi

}
function dmverity_genHashTable()
{
	local fs_name=$1
	local tree_name=$2
	local table_name=$3
	local block_size=`dmverity_determ_blk_size ${fs_name}`
	if [ ${block_size} -lt 0 ];then
		return -1
	fi
	veritysetup format --data-block-size=${block_size} --hash-block-size=${block_size} ${fs_name} ${tree_name} > ${table_name}
	return $?
}

function dmverity_genDownloadFile()
{
	local fs_name=$1
	local sign_name=$2
	local table_name=$3
	local tree_name=$4
	local download_file_name=$5

	local BLK_SIZE=`dmverity_determ_blk_size ${fs_name}`
	if [ ${BLK_SIZE} -lt 0 ];then
		return -1
	fi
	local SIGN_BLK=`dmverity_get_blk_count ${sign_name} ${BLK_SIZE}`
	local TABLE_BLK=`dmverity_get_blk_count ${table_name} ${BLK_SIZE}`
	local TREE_BLK=`dmverity_get_blk_count ${tree_name} ${BLK_SIZE}`

	# 3.1 copy sign
	dd if=${sign_name} of=${download_file_name}"tmp" bs=${BLK_SIZE} count=${SIGN_BLK} >/dev/null 2>&1

	# 3.2 copy table size
	local TABLE_SIZE=`du --apparent-size -b ${table_name} | awk '{print $1}'`
	local HIGH_BYTES=`expr $TABLE_SIZE / 256 `
	local LOW_BYTES=`expr $TABLE_SIZE % 256 `
	if [ $HIGH_BYTES -gt 256 ]; then
		echo "ERROR rootfs_hash_table size should < 64KB"
		return -1
	fi
	local HIGH_BYTES_H=`echo "obase=16;ibase=10;$HIGH_BYTES" | bc`
	local LOW_BYTES_H=`echo "obase=16;ibase=10;$LOW_BYTES" | bc`
	echo -e -n "\x$LOW_BYTES_H\x$HIGH_BYTES_H" >> ${download_file_name}"tmp"

	# 3.3 copy rootfs_hash_table
	dd if=${table_name} of=${download_file_name}"tmp"  bs=${BLK_SIZE} seek=${SIGN_BLK} count=${TABLE_BLK} > /dev/null 2>&1

	# 3.4 copy rootfs_hash_tree.bin
	dd if=${tree_name} of=${download_file_name}"tmp"  bs=${BLK_SIZE} seek=`expr ${SIGN_BLK} + ${TABLE_BLK}` count=${TREE_BLK} > /dev/null 2>&1

	dd of=${download_file_name} if=${download_file_name}"tmp" bs=${BLK_SIZE} count=`expr ${SIGN_BLK} + ${TABLE_BLK} + ${TREE_BLK}`>/dev/null 2>&1
	rm ${download_file_name}"tmp"
}

function do_signature_dsp()
{
	local DSP0_BIN=${LICHEE_PACK_OUT_DIR}/amp_dsp0.fex;
	local DSP1_BIN=${LICHEE_PACK_OUT_DIR}/amp_dsp1.fex;
	local CFG_FILE=${LICHEE_CHIP_CONFIG_DIR}/configs/default/image_header_secure.cfg;

	if [ -f ${CFG_FILE} ] ; then
		cp -v ${CFG_FILE} image_header_secure.cfg
	else
		printf "can not found image_header_secure cfg\n"
		return 1
	fi

	if [ -f ${DSP0_BIN} ] ; then
		mkimage_header -C 5 -c image_header_secure.cfg -s rsa -k $CFG_KEY_DIR
		if [ $? -ne 0 ]
		then
			pack_error "mkimage_header signature dsp error\n"
			exit 1
		fi
		mv amp_dsp0.fex.pack amp_dsp0.fex
	else
		printf "can not found amp_dsp0 bin\n"
		return 3
	fi

	if [ -f ${DSP1_BIN} ] ; then
		mv amp_dsp0.fex.pack amp_dsp0.fex
	fi

}

function do_signature_riscv()
{
	local RV0_BIN=${LICHEE_PACK_OUT_DIR}/amp_rv0.fex;
	local RV1_BIN=${LICHEE_PACK_OUT_DIR}/amp_rv1.fex;
	local CFG_FILE=${LICHEE_CHIP_CONFIG_DIR}/configs/default/image_header_secure.cfg;
	local key_type=$(readcfg dragon_toc.cfg key_para key_toc1 | cut -c 1-3)
	if [ x${key_type} == "xecc" ]; then
		sign_alg=ecc
	else
		sign_alg=rsa
	fi

	if [ -f ${CFG_FILE} ] ; then
		cp -v ${CFG_FILE} image_header_secure.cfg
	else
		printf "can not found image_header_secure cfg\n"
		return 1
	fi

	if [ -f ${RV0_BIN} ] ; then
		mkimage_header -C 5 -c image_header_secure.cfg -s $sign_alg -k $CFG_KEY_DIR
		if [ $? -ne 0 ]
		then
			pack_error "mkimage_header signature rv error\n"
			exit 1
		fi
		mv amp_rv0.fex.pack amp_rv0.fex
	else
		printf "can not found amp_rv0 bin\n"
		return 3
	fi

	if [ -f ${RV1_BIN} ] ; then
		mv amp_rv1.fex.pack amp_rv1.fex
	fi

}

function do_signature_ft()
{
	if [ ! -e ${LICHEE_PACK_OUT_DIR}/ft_${PACK_CHIP}.bin ]; then
		printf "can not found ft bin\n"
		return 1
	fi

	if [ -e ${LICHEE_PACK_OUT_DIR}/dragon_toc_ft.cfg ]; then
		printf "can not found dragon_toc_ft cfg\n"
	fi

	printf "prepare for signature for ft bin\n"
	mv ${LICHEE_PACK_OUT_DIR}/ft_${PACK_CHIP}.bin ${LICHEE_PACK_OUT_DIR}/ft.bin
	dragonsecboot -toc0 dragon_toc_ft.cfg $CFG_KEY_DIR ${LICHEE_PACK_OUT_DIR}/version_base.mk > /dev/null
	if [ $? -ne 0 ]; then
		pack_error "dragon toc0_ft run error\n"
		exit 1
	fi

	mv toc0.fex toc0_ft.fex
}

function do_signature_fel()
{
	printf "prepare for signature for fex tools\n"
	local ROOT_KEY_NAME="";
	local UBOOT_NAME="u-boot";
	local sign_tools=$(readcfg dragon_toc.cfg sign_fel_tools sign_tools)

	if [ -f u-boot-efex.fex ]; then
		UBOOT_NAME="u-boot-efex"
	fi
	echo UBOOT_NAME ${UBOOT_NAME}

	if [ x${sign_tools} == "xdragonsboot" ]; then
		printf "using dragonsboot to sign fel\n"

		if [ -f ${CFG_KEY_DIR}/RootKey_Level_0.pem ]; then
			ROOT_KEY_NAME=${CFG_KEY_DIR}/RootKey_Level_0.pem
		elif [ -f ${CFG_KEY_DIR}/Trustkey.pem ]; then
			ROOT_KEY_NAME=${CFG_KEY_DIR}/Trustkey.pem
		else
			pack_error "can not found root key to sign fex tool"
			exit 1
		fi
		echo rootkeyname ${ROOT_KEY_NAME}

		dragonsecboot -sign fes1.fex ${ROOT_KEY_NAME} ${LICHEE_PACK_OUT_DIR}/version_base.mk > /dev/null
		if [ $? -eq 0 ]; then
			dragonsecboot -sign ${UBOOT_NAME}.fex ${ROOT_KEY_NAME} ${LICHEE_PACK_OUT_DIR}/version_base.mk > /dev/null
			if [ $? -ne 0 ]
			then
				pack_error "dragonsecboot uboot fail"
			fi
		fi
	else
		printf "using sig_fel_image to sign fel\n"
		if [ -f ${CFG_KEY_DIR}/RootKey_Level_0.bin ]; then
			ROOT_KEY_NAME=${CFG_KEY_DIR}/RootKey_Level_0.bin
		elif [ -f ${CFG_KEY_DIR}/Trustkey.bin ]; then
			ROOT_KEY_NAME=${CFG_KEY_DIR}/Trustkey.bin
		else
			pack_error "can not found root key to sign fex tool"
			exit 1
		fi
		echo rootkeyname ${ROOT_KEY_NAME}

		sig_fel_image --input fes1.fex --rsakey ${ROOT_KEY_NAME} --output fes1_sign.fex --version_base ${LICHEE_PACK_OUT_DIR}/version_base.mk
		if [ $? -ne 0 ]
		then
			pack_error "sig_fel_image fes fail"
			exit 1
		fi
		sig_fel_image --input ${UBOOT_NAME}.fex --rsakey ${ROOT_KEY_NAME} --output ${UBOOT_NAME}_sign.fex --version_base ${LICHEE_PACK_OUT_DIR}/version_base.mk
		if [ $? -ne 0 ]
		then
			pack_error "sig_fel_image uboot fail"
		fi
	fi

	if [ -f fes1_sign.fex ]; then
		cp fes1_sign.fex fes1.fex
	fi

	if [ -f  ${UBOOT_NAME}_sign.fex ]; then
		cp ${UBOOT_NAME}_sign.fex ${UBOOT_NAME}.fex
	fi
}

function readcfg()
{
	local fid=$1
	local section=$2
	local option=$3

	test ! -f $fid && echo "file not exits:$fid" && exit 1
	if [ $# -eq 3 ] ; then
		local src=$(cat $fid | awk '/\['$section'\]/{f=1;next} /\[*\]/{f=0} f' |
		grep ^$option |
		grep '='     |
		cut -d'=' -f2|
		cut -d'#' -f1|
		cut -d';' -f1|
		awk '{gsub(/^\s+|\s+$/, "");print}')
		echo -n $src
		test ${#src} -eq 0 && return 1 || return 0
	else
		echo "the input parameters should be 3"
		exit 1
	fi
}

function get_item_from_cfg()
{
	name=()
	bin=()
	cert=()
	counts=0

	local toc_cfg=$1
	local field=$2
	local key=$3

	toc1_item_content=$(readcfg ${toc_cfg} ${field} ${key})
	i=0
	IFS=', ' read -r -a parts <<< $toc1_item_content
	for part in "${parts[@]}"; do
		if [ $(($i % 3)) -eq 0 ]; then
			name[counts]=$part
		elif [ $(($i % 3)) -eq 1 ]; then
			bin[counts]=$part
		else
			cert[counts]=$part
			counts=$((counts + 1))
		fi
		i=$((i + 1))
	done
}

function create_toc0()
{
	local toc_cfg=$1
	local key=""
	local cert_type=""
	local key_type=""
	local psck_mode=""

	rm -rf toc0

	if [ ! -d "toc0" ]; then
		mkdir -p toc0
	fi

	if [ ! -d "temp" ]; then
		mkdir -p temp
	fi

	get_item_from_cfg ${toc_cfg} toc0 item

	key=$(readcfg ${toc_cfg} key_toc0 ${name[0]})
	cert_type=$(readcfg ${toc_cfg} cert_type cert_type_toc0)
	key_type=$(readcfg ${toc_cfg} key_para key_toc0 | cut -c 1-3)
	if [ x${key_type} == "xrsa" ]; then
		psck_mode=RSA-PKCS
	elif [ x${key_type} == "xecc" ]; then
		psck_mode=ECDSA
	else
		pack_error "key_toc0 type error"
		exit 1
	fi

	#gen sboot hash
	dragon_securetool hash --mode 256 --in ${bin[0]} --out ./temp/${bin[0]}.hash.out
	if [ $? -ne 0 ]
	then
		pack_error "gen sboot hash error"
		exit 1
	fi

	#req no sign cert, ext is sboot_hash; use pubkey
	dragon_securetool req_cert --type ${cert_type} --cfg ${toc_cfg} --pubkey ${CFG_KEY_DIR}/${key}.pem.pub --ext ./temp/${bin[0]}.hash.out --out ./temp/${name[0]}.req
	if [ $? -ne 0 ]
	then
		pack_error "req no sign cert for toc0 error"
		exit 1
	fi

	#gen no sign cert hash, witch is to be signed
	dragon_securetool hash --mode 256 --type ${cert_type} --in ./temp/${name[0]}.req --out ./temp/${name[0]}.req.hash
	if [ $? -ne 0 ]
	then
		pack_error "gen no sign cert hash for toc0 error"
		exit 1
	fi

	#sign cert(to be signed) hash
	if [ "x$SOFTHSM_FLAG" == "x1" ]; then
		local id=$(echo "$key" | md5sum | awk '{print $1}')
		pkcs11-tool --label ${key} --id ${id} -s -p ${PIN} -m ${psck_mode} --module ${MODULES} --input-file ./temp/${name[0]}.req.hash --output-file ./temp/${name[0]}.req.sign
		if [ $? -ne 0 ]
		then
			pack_error "softhsm sign cert(to be signed) hash for toc0 error"
			exit 1
		fi
	else
		dragon_securetool sign --cfg ${toc_cfg} --privatekey ${CFG_KEY_DIR}/${key}.pem --in ./temp/${name[0]}.req.hash --out ./temp/${name[0]}.req.sign
		if [ $? -ne 0 ]
		then
			pack_error "sign cert(to be signed) hash for toc0 error"
			exit 1
		fi
	fi

	#create cert with sign
	dragon_securetool create_cert --type ${cert_type} --cfg ${toc_cfg} --pubkey ${CFG_KEY_DIR}/${key}.pem.pub --reqfile ./temp/${name[0]}.req --signfile ./temp/${name[0]}.req.sign --out ./toc0/${cert[0]}
	if [ $? -ne 0 ]
	then
		pack_error "create cert with sign for toc0 error"
		exit 1
	fi

	#create toc0.fex(toc0_head + sboot.crtpt + sboot)
	dragon_securetool create_toc0 --cfg ${toc_cfg} --out ./toc0.fex
	if [ $? -ne 0 ]
	then
		pack_error "dragon toc0 run error"
		exit 1
	fi
}

function do_signature_sboot()
{
	local sboot_file=$1;
	local flash_type=$2;

	#dram_param
	if [ -f ${LICHEE_TOOLS_DIR}/pack/pctools/linux/mod_update/update_sboot ]; then
		update_sboot $sboot_file  sys_config.bin  > /dev/null
		if [ $? -ne 0 ]
		then
			pack_error "update sboot run error"
			exit 1
		fi
	fi

	update_chip $sboot_file > /dev/null

	#dragon_toc only load sboot.bin
	[ "$(readlink -f $sboot_file)" != "$(readlink -f sboot.bin)" ] && \
	mv $sboot_file sboot.bin

	#readcfg determines whether the cfg file is legacy or new
	readcfg dragon_toc.cfg key_para key > /dev/null
	if [ $? -ne 0 ]; then
		dragonsecboot -toc0 dragon_toc.cfg $CFG_KEY_DIR ${LICHEE_PACK_OUT_DIR}/version_base.mk > /dev/null
		if [ $? -ne 0 ]
		then
			pack_error "dragon toc0 run error"
			exit 1
		fi
	else
		create_toc0 dragon_toc.cfg

	fi

	update_toc0  toc0.fex           sys_config.bin
	if [ $? -ne 0 ]
	then
		pack_error "update toc0 run error"
		exit 1
	fi

	[ "$(readlink -f $sboot_file)" != "$(readlink -f sboot.bin)" ] && \
	mv sboot.bin $sboot_file
	if [ -f toc0_$flash_type.fex ]; then
		rm -rf toc0_$flash_type.fex
	fi
	mv toc0.fex toc0_$flash_type.fex
	mv toc0 toc0_$flash_type
}

function do_signature_toc0()
{
	if [ -f sboot.bin ]; then
		do_signature_sboot sboot.bin bak
		mv sboot.bin sboot_bak.bin
	fi

	if [ -f sboot_sdcard.bin ]; then
		if [ -f cardscript.fex ]; then
			sed -i "s/TOC0_00000000000/TOC0_SDCARD00000/g" cardscript.fex
		fi
		do_signature_sboot sboot_sdcard.bin sdcard
	fi

	if [ -f sboot_nand.bin ]; then
		do_signature_sboot sboot_nand.bin nand

	fi

	if [ -f sboot_ufs.bin ]; then
		do_signature_sboot sboot_ufs.bin ufs
	fi

	if [ -f sboot_nor.bin ]; then
		do_signature_sboot sboot_nor.bin nor
	fi

	mv sboot_bak.bin sboot.bin
	mv toc0_bak.fex toc0.fex
	mv toc0_bak toc0
}

function toc1_create_cert_for_per_bin()
{
	local toc_cfg=$1
	local key=""
	local cert_type=""
	local key_type=""
	local psck_mode=""

	cert_type=$(readcfg ${toc_cfg} cert_type cert_type_toc1)
	key_type=$(readcfg ${toc_cfg} key_para key_toc1 | cut -c 1-3)
	if [ x${key_type} == "xrsa" ]; then
		psck_mode=RSA-PKCS
	elif [ x${key_type} == "xecc" ]; then
		psck_mode=ECDSA
	else
		pack_error "key_toc1 type error"
		exit 1
	fi

	for ((count=0; count < counts; count++)); do
		key=$(readcfg ${toc_cfg} key_toc1 ${name[count]})
		#gen ${bin[count]} hash
		dragon_securetool hash --mode 256 --in ${bin[count]} --out temp/${name[count]}_hash.out
		if [ $? -ne 0 ]
		then
			pack_error "gen hash ${name[count]} error"
			exit 1
		fi

		#req no sign cert, ext is sboot_hash; use pubkey
		dragon_securetool req_cert --type ${cert_type} --cfg ${toc_cfg} --pubkey ${CFG_KEY_DIR}/$key.pem.pub --ext temp/${name[count]}_hash.out --out temp/${cert[count]}.req
		if [ $? -ne 0 ]
		then
			pack_error "req no sign cert ${name[count]} error"
			exit 1
		fi

		#gen no sign cert hash, witch is to be signed
		dragon_securetool hash --mode 256 --type ${cert_type} --in temp/${cert[count]}.req --out temp/to_be_signed_${name[count]}_hash.out
		if [ $? -ne 0 ]
		then
			pack_error "gen no sign cert hash ${name[count]} error"
			exit 1
		fi

		#sign cert(to be signed) hash
		if [ "x$SOFTHSM_FLAG" == "x1" ]; then
			local id=$(echo "$key" | md5sum | awk '{print $1}')
			pkcs11-tool --label ${key} --id ${id} -s -p ${PIN} -m ${psck_mode} --module ${MODULES} --input-file temp/to_be_signed_${name[count]}_hash.out --output-file temp/${name[count]}_sign.out
			if [ $? -ne 0 ]
			then
				pack_error "softhsm sign cert(to be signed) hash ${name[count]} error"
				exit 1
			fi
		else
			dragon_securetool sign --cfg ${toc_cfg} --privatekey ${CFG_KEY_DIR}/$key.pem --in temp/to_be_signed_${name[count]}_hash.out --out temp/${name[count]}_sign.out
			if [ $? -ne 0 ]
			then
				pack_error "sign cert(to be signed) hash ${name[count]} error"
				exit 1
			fi
		fi

		#create cert with sign
		dragon_securetool create_cert --type ${cert_type} --cfg ${toc_cfg} --pubkey ${CFG_KEY_DIR}/${key}.pem.pub --reqfile temp/${cert[count]}.req --signfile temp/${name[count]}_sign.out --out toc1/cert/${cert[count]}
		if [ $? -ne 0 ]
		then
			pack_error "create cert with sign ${name[count]} error"
			exit 1
		fi
	done
}

function toc1_create_cert_for_rootkey()
{
	local toc_cfg=$1
	local key=""
	local cert_type=""
	local key_type=""
	local psck_mode=""

	cert_type=$(readcfg ${toc_cfg} cert_type cert_type_toc1)
	get_item_from_cfg ${toc_cfg} toc1 rootkey
	key=$(readcfg ${toc_cfg} key_toc0 rootkey)
	key_type=$(readcfg ${toc_cfg} key_para key_toc0 | cut -c 1-3)
	if [ x${key_type} == "xrsa" ]; then
		psck_mode=RSA-PKCS
	elif [ x${key_type} == "xecc" ]; then
		psck_mode=ECDSA
	else
		pack_error "key_toc0 type error"
		exit 1
	fi

	#rootkey no sign cert
	#req no sign rootkey cert, insert extensions in the dragon_toc.cfg; use pubkey
	dragon_securetool req_rootkey_cert --type ${cert_type} --cfg ${toc_cfg} --keypath ${CFG_KEY_DIR} --pubkey ${CFG_KEY_DIR}/${key}.pem.pub
	if [ $? -ne 0 ]
	then
		pack_error "req rootkey cert error"
		exit 1
	fi

	mv toc1/cert/${cert[0]} temp/${cert[0]}.req
	#gen no sign rootkey cert hash, witch is to be signed; Non-x509 certificates do not need to skip 4 bytes
	dragon_securetool hash --mode 256 --type ${cert_type} --in temp/${cert[0]}.req --out temp/to_be_signed_${name[0]}_hash.out
	if [ $? -ne 0 ]
	then
		pack_error "gen no sign rootkey cert hash error"
		exit 1
	fi

	#sign rootkey cert(to be signed) hash
	if [ "x$SOFTHSM_FLAG" == "x1" ]; then
		local id=$(echo "$key" | md5sum | awk '{print $1}')
		pkcs11-tool --label ${key} --id ${id} -s -p ${PIN} -m ${psck_mode} --module ${MODULES} --input-file temp/to_be_signed_${name[0]}_hash.out --output-file temp/${name[0]}_sign.out
		if [ $? -ne 0 ]
		then
			pack_error "softhsm sign rootkey cert(to be signed) hash error"
			exit 1
		fi
	else
		dragon_securetool sign --cfg ${toc_cfg} --privatekey ${CFG_KEY_DIR}/${key}.pem --in temp/to_be_signed_${name[0]}_hash.out --out temp/${name[0]}_sign.out
		if [ $? -ne 0 ]
		then
			pack_error "sign rootkey cert(to be signed) hash error"
			exit 1
		fi
	fi

	#create rootkey cert with sign
	dragon_securetool create_cert --type ${cert_type} --cfg ${toc_cfg} --pubkey ${CFG_KEY_DIR}/${key}.pem.pub --reqfile temp/${cert[0]}.req --signfile temp/${name[0]}_sign.out --out toc1/cert/${cert[0]}
	if [ $? -ne 0 ]
	then
		pack_error "create rootkey cert with sign error"
		exit 1
	fi
}

function do_signature_toc1()
{
	rm -rf toc1

	if [ ! -d "toc1/cert" ]; then
		mkdir -p toc1/cert
	fi

	if [ ! -d "temp" ]; then
		mkdir -p temp
	fi

	#create cert for toc1 item
	get_item_from_cfg dragon_toc.cfg toc1 item
	toc1_create_cert_for_per_bin dragon_toc.cfg

	#create cert for toc1 onlykey
	get_item_from_cfg dragon_toc.cfg toc1 onlykey
	toc1_create_cert_for_per_bin dragon_toc.cfg

	toc1_create_cert_for_rootkey dragon_toc.cfg

	#create toc1.fex(toc1_head + rootkey.crtpt + ..)
	dragon_securetool create_toc1 --cfg dragon_toc.cfg --out toc1.fex
	if [ $? -ne 0 ]
	then
		pack_error "dragon toc1 run error"
		exit 1
	fi
}

function do_signature()
{
	printf "prepare for signature by openssl\n"
	if [ ! -d $CFG_KEY_DIR ] ; then
		pack_error "No key exist, please run './build/createkeys' to generate keys first."
		exit 1
	fi
	if [ "x${PACK_SIG}" = "xprev_refurbish" ] ; then
		if [ "x${LICHEE_ARCH}" = "xarm64" ] ; then
			cp -v ${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_a64_no_secureos.cfg dragon_toc.cfg
		else
			cp -v ${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_no_secureos.cfg dragon_toc.cfg
		fi
	else
		if [ "x${LICHEE_ARCH}" = "xarm64" ] ; then
			if [ -f ${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc.cfg ] ; then
				cp -v ${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc.cfg dragon_toc.cfg
			else
				cp -v ${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_a64.cfg dragon_toc.cfg
			fi
		else
			if [ -f ${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc.cfg ] ; then
				cp -v ${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc.cfg dragon_toc.cfg
			else
				cp -v ${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc.cfg dragon_toc.cfg
			fi
		fi
	fi
	if [ "x${PACK_NOR}" = "xnor" ] ; then
		cp -vf ${LICHEE_PACK_OUT_DIR}/dragon_toc_nor.cfg ${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
	fi

	if [ -f ${CFG_KEY_DIR}/softhsm2.cfg ]; then
		# fix tokendir
		tokendir=$(grep tokendir ${CFG_KEY_DIR}/softhsm2.cfg | awk '{print $3}')
		if [ "x$tokendir" != "x${CFG_KEY_DIR}/.token" ]; then
			sed -i "s#${tokendir}#${CFG_KEY_DIR}/.token#g" ${CFG_KEY_DIR}/softhsm2.cfg
		fi

		PIN=1234
		SOPIN=12345678
		SOFTHSM_TOOLS_DIR=${LICHEE_TOOLS_DIR}/pack/pctools/linux/softhsm
		MODULES=${SOFTHSM_TOOLS_DIR}/lib/softhsm/libsofthsm2.so
		export LD_LIBRARY_PATH=${SOFTHSM_TOOLS_DIR}/lib:${SOFTHSM_TOOLS_DIR}/lib/softhsm:${LIB_LIBRARY_PATH}
		export PATH=${SOFTHSM_TOOLS_DIR}/bin:$PATH
		export SOFTHSM2_CONF=${CFG_KEY_DIR}/softhsm2.cfg

		SOFTHSM_FLAG=1
	fi

	if [ $? -ne 0 ]
	then
		pack_error "dragon toc config file is not exist"
		exit 1
	fi

	rm -f cardscript.fex
	mv cardscript_secure.fex cardscript.fex
	if [ $? -ne 0 ]
	then
		pack_error "dragon cardscript_secure.fex file is not exist"
		exit 1
	fi

	if [ ! -f ${LICHEE_PLAT_OUT}/recovery.img ]; then
		printf "recovery img is not exist, remove recovery cert from dragon_toc.cfg\n"
		sed -i '/recovery/d' dragon_toc.cfg > /dev/null
	else
		local recovery_buf=$(grep "recovery" -nr dragon_toc.cfg)
		if [ x"${recovery_buf}" = x"" ]; then
			readcfg dragon_toc.cfg key_para key > /dev/null
				if [ $? -ne 0 ]; then
					sed -i '/^onlykey=boot/a\onlykey=recovery,      recovery.fex,        SCPFirmwareContentCertPK' dragon_toc.cfg
				else
					sed -i '/^boot=/a recovery=NonTrustedFirmwareContentCertPK' dragon_toc.cfg
					sed -i '/^onlykey=boot/a\onlykey=recovery,     recovery.fex,        recovery.crtpt' dragon_toc.cfg
				fi
		fi
	fi

	if [ "x${PACK_VERITY}" = "x${FLAGS_TRUE}" ]; then
		# verity setup for squashfs type filesystem
		if [ x"${PACK_PLATFORM}" = x"openwrt" ] || [ x"${PACK_PLATFORM}" = x"bsp" ] || [ x"${PACK_PLATFORM}" = x"buildroot" ]; then
			rm -rf rootfs.fex
			local link_real_new=$(get_realpath ${LICHEE_PLAT_OUT} ./)

			if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
				cp ${link_real_new}/rootfs.img		rootfs.fex
			else
				cp ${link_real_new}/rootfs.squashfs	rootfs.fex
			fi

			if [ "x${PACK_KERN}" == "xlinux-5.4" \
					-o "x${PACK_KERN}" == "xlinux-5.4-ansc" \
					-o "x${PACK_KERN}" == "xlinux-5.10" \
					-o "x${PACK_KERN}" == "xlinux-5.10-origin" \
					-o "x${PACK_KERN}" == "xlinux-5.15" \
					-o "x${PACK_KERN}" == "xlinux-5.15-origin" ]; then

				squashfs_real_size=`hexdump -s 0x28 -n 4 -e '/4 "%d"' rootfs.fex`
				squashfs_data_blocks=`expr \( ${squashfs_real_size} + 4095 \) / 4096`

				local TEMP=${LC_ALL}
				export LC_ALL=C

				veritysetup --data-blocks=${squashfs_data_blocks} format rootfs.fex hash_tree > raw_table

				export LC_ALL=${TEMP}

				readcfg dragon_toc.cfg key_para key > /dev/null
				if [ $? -ne 0 ]; then
					sed -i '/^onlykey=boot/a\onlykey=rootfs,          hash_tree,        SCPFirmwareContentCertPK' dragon_toc.cfg
				else
					sed -i '/^boot=/a rootfs=NonTrustedFirmwareContentCertPK' dragon_toc.cfg
					sed -i '/^onlykey=boot/a\onlykey=rootfs,          hash_tree,        rootfs.crtpt' dragon_toc.cfg
				fi
			else
				# get sample from squashfs rootfs
				local rootfs_per_MB=`grep "^rootfs_per_MB=" env.cfg | awk -F = '{printf $2}'`
				if [ -z $rootfs_per_MB ]; then
					echo "rootfs_per_MB is not defined in env.cfg, use default value 4096"
					rootfs_per_MB=4096
				fi

				extract_squashfs $rootfs_per_MB rootfs.fex rootfs-extract.fex
				if [ $? -ne 0 ]; then
					echo "extract squashfs error"
					exit 1;
				fi

				readcfg dragon_toc.cfg key_para key > /dev/null
				if [ $? -ne 0 ]; then
					sed -i '/^onlykey=boot/a\onlykey=rootfs,          rootfs-extract.fex,        SCPFirmwareContentCertPK' dragon_toc.cfg
				else
					sed -i '/^boot=/a rootfs=NonTrustedFirmwareContentCertPK' dragon_toc.cfg
					sed -i '/^onlykey=boot/a\onlykey=rootfs,          rootfs-extract.fex,        rootfs.crtpt' dragon_toc.cfg
				fi
			fi
		else
			# generate verity data, suport more different filesystem in the future
			(dmverity_genHashTable rootfs.fex rootfsHashTree.fex rootfsHashTable.fex &&
			openssl dgst -sha256 -binary -sign $CFG_KEY_DIR/SCPFirmwareContentCertPK.pem rootfsHashTable.fex > rootfsHashSign.fex &&
			openssl rsa -in $CFG_KEY_DIR/SCPFirmwareContentCertPK.pem -pubout -out rootfsPubKey.pk &&
			dmverity_genDownloadFile rootfs.fex rootfsHashSign.fex rootfsHashTable.fex rootfsHashTree.fex VerityInfo.fex) ||
			{ pack_error "generate verity data failed"; exit 1; }

			# add partition for verity data
			(add_partition -2 rootfsverityInfo 4096 "VerityInfo.fex" &&
			maybe_busybox unix2dos sys_partition.fex &&
			script  sys_partition.fex > /dev/null) ||
			{ pack_error "add verity info part failed"; exit 1; }

			# add verity tools into ramdisk
			local rootfsPath=`readlink -f rootfs.fex`
			local keyPath=`readlink -f rootfsPubKey.pk`
			local blockSize=`dmverity_determ_blk_size ${rootfsPath}`
			dmverity_deal $blockSize rootfsverityInfo ext4 $keyPath ||
			{ pack_error "deal verity utils failed"; exit 1; }
		fi
	fi

	if [ "x${PACK_SIGNFEL}" = "x${FLAGS_TRUE}" ]; then
		do_signature_fel
	fi

	do_signature_ft

	do_signature_toc0

	#readcfg determines whether the cfg file is legacy or new
	readcfg dragon_toc.cfg key_para key > /dev/null
	if [ $? -ne 0 ]; then
		dragonsecboot -toc1 dragon_toc.cfg $CFG_KEY_DIR ${LICHEE_PACK_OUT_DIR}/cnf_base.cnf ${LICHEE_PACK_OUT_DIR}/version_base.mk
		if [ $? -ne 0 ]
		then
			pack_error "dragon toc1 run error"
			exit 1
		fi
		cert=".der"
	else
		do_signature_toc1
		cert=".crtpt"
	fi

	sigbootimg --image boot.fex --cert toc1/cert/boot${cert} --output boot_sig.fex
	if [ $? -ne 0 ] ; then
		pack_error "Pack cert to image error"
		exit 1
	else
		mv -f boot_sig.fex boot.fex
	fi

	do_signature_dsp

	do_signature_riscv

	if [ "x${PACK_VERITY}" = "x${FLAGS_TRUE}" ]; then
		if [ x"${PACK_PLATFORM}" = x"openwrt" ] || [ x"${PACK_PLATFORM}" = x"bsp" ] || [ x"${PACK_PLATFORM}" = x"buildroot" ]; then
			if [ "x${PACK_KERN}" == "xlinux-5.4" \
					-o "x${PACK_KERN}" == "xlinux-5.4-ansc" \
					-o "x${PACK_KERN}" == "xlinux-5.10" \
					-o "x${PACK_KERN}" == "xlinux-5.10-origin" \
					-o "x${PACK_KERN}" == "xlinux-5.15" \
					-o "x${PACK_KERN}" == "xlinux-5.15-origin" ]; then
				verity_root_hash_str=`grep "Root hash:" raw_table | awk '{print $3}'`
				verity_salt_str=`grep "Salt:" raw_table | awk '{print $2}'`

				update_squashfs_verity -f rootfs.fex -c toc1/cert/rootfs${cert} -t hash_tree -r ${verity_root_hash_str} -s ${verity_salt_str}
				if [ $? -ne 0 ]; then
					pack_error "add verity block error."
					exit 1
				fi
			else
				update_squashfs rootfs.fex toc1/cert/rootfs${cert}
				if [ $? -ne 0 ]
				then
					pack_error "signature squashfs rootfs error."
					exit 1
				fi
			fi
		fi
	fi

	local link_real=$(get_realpath ${LICHEE_PLAT_OUT} ./)
	local recovery_path=${link_real}/recovery.img

	if [ -f "$recovery_path" ]; then
		sigbootimg --image recovery.fex --cert toc1/cert/recovery${cert} --output recovery_sig.fex
		if [ $? -ne 0 ] ; then
			pack_error "Pack cert to image error"
			exit 1
		else
			mv -f recovery_sig.fex recovery.fex
		fi
	fi

	echo "secure signature ok!"
}

function do_android_signature()
{
	if [ "x$LINUX_DTBO_FILE" = "x" ]; then
		echo "do not set LINUX_DTBO_FILE"
		line_num=`sed -n -e "/default.dtbo/=" dragon_toc.cfg`
		if [ "x$line_num" != "x" ]; then
			sed -i "$line_num s/^/;/g" dragon_toc.cfg
		fi
	else
		if [ -f $LINUX_DTBO_FILE ]
		then
			sed -i "s/default.dtbo/$LINUX_DTBO_FILE/g" dragon_toc.cfg
		else
			line_num=`sed -n -e "/default.dtbo/=" dragon_toc.cfg`
			if [ "x$line_num" != "x" ]; then
				sed -i "$line_num s/^/;/g" dragon_toc.cfg
			fi
		fi
	fi

	if [ $? -ne 0 ]
	then
		pack_error "dragon toc config file is not exist"
		exit 1
	fi

	rm -f cardscript.fex
	mv cardscript_secure.fex cardscript.fex
	if [ $? -ne 0 ]
	then
		pack_error "dragon cardscript_secure.fex file is not exist"
		exit 1
	fi

	do_signature_ft

	do_signature_toc0

	#readcfg determines whether the cfg file is legacy or new
	readcfg dragon_toc.cfg key_para key > /dev/null
	if [ $? -ne 0 ]; then
		dragonsecboot -toc1 dragon_toc.cfg $CFG_KEY_DIR ${LICHEE_PACK_OUT_DIR}/cnf_base.cnf ${LICHEE_PACK_OUT_DIR}/version_base.mk
		if [ $? -ne 0 ]
		then
			pack_error "dragon toc1 run error"
			exit 1
		fi
		cert=".der"
	else
		do_signature_toc1
		cert=".crtpt"
	fi

	if [ -e dboot.fex ]; then
		local keyname=$(awk -F, '/^[[:space:]]*onlykey=boot\S*,[[:space:]]*dboot.fex,/{print $1}' dragon_toc.cfg  | awk -F= '{print $2}')
		sigbootimg --image dboot.fex --cert toc1/cert/${keyname}${cert} --output dboot_sig.fex
		[ $? -ne 0 ] && pack_error "Pack cert to image error" && exit 1
		mv -f dboot_sig.fex dboot.fex
	fi

	echo "secure android signature ok!"
}

################################ Tina func ################################
function get_partition_downfile_size()
{
    local downloadfile_name=`echo $1 | awk -F '=' '{print $2}'`
    if [ x${downloadfile_name: 0-4} != x".fex" ]; then
        pack_error "downloadfile format is wrong, it should be end with .fex"
        exit -1
    fi
    if [ ! -f ${downloadfile_name} ]; then
        echo "  file ${downloadfile_name} not find"
    else
        if [ -L ${downloadfile_name} ]; then
            local downloadfile_name_link=`readlink -f ${downloadfile_name}`
            local linkfile_name=${downloadfile_name_link##*/}
            echo "  ${downloadfile_name} -> ${downloadfile_name_link}"
            if [ ! -f ${downloadfile_name_link} ]; then
                echo "  link file ${linkfile_name} not find"
            else
                local linkfile_size=`ls -lh ${downloadfile_name_link} | awk '{print $5}'`
                echo "  ${linkfile_name} size : ${linkfile_size} byte"
            fi
        else
            local downloadfile_size=`ls -lh ${downloadfile_name} | awk '{print $5}'`
            echo "  ${downloadfile_name} size : ${downloadfile_size} byte"
        fi
    fi
}

function get_partition_mbr_size()
{
    local partition_size_name=`echo $1 | awk -F '=' '{print $1}' | sed 's/partition/mbr/g'`
    local partition_size=`echo $1 | awk -F '=' '{print $2}'`
    echo "  ${partition_size_name}  : ${partition_size} Kbyte"
}

function show_partition_message()
{
    grep -c '[mbr]' $1 > /dev/null
    if [ $? -eq 0 ]; then
        cp $1 ./show_sys_partition.tmp;
        sed -i '/^[\r;]/d' ./show_sys_partition.tmp;
        sed -i '/partition_start/d' ./show_sys_partition.tmp;
        sed -i '/user_type/d' ./show_sys_partition.tmp;
        sed -i 's/\[partition\]/------------------------------------/g' ./show_sys_partition.tmp;
        sed -i 's/[ "\r]//g' ./show_sys_partition.tmp;
        sed -i '/^[;]/d' ./show_sys_partition.tmp;
        sed -i 's/name/partition_name/g' ./show_sys_partition.tmp;
        sed -i 's/size/partition_size/g' ./show_sys_partition.tmp;
        echo "------------------------------------"
        while read line
        do
            if [ "$line" == "------------------------------------" ];then
                echo "$line"
            else
                echo "  $line" | sed 's/=/  : /g'
                echo "  $line" | grep "mbr" >> /dev/null
                if [ $? -eq 0 ]; then
                    read line
                    get_partition_mbr_size $line
                fi
                echo "$line" | grep "downloadfile" >> /dev/null
                if [ $? -eq 0 ]; then
                    get_partition_downfile_size $line
                fi
            fi
        done < ./show_sys_partition.tmp
        echo "------------------------------------"
        rm ./show_sys_partition.tmp
    else
        echo "==========input is not a partition file=========="
    fi
}

function sparse_ext4()
{
    local img=$1
    local sparse_img=$2

    if file $img | grep -q ext4 ;then
        echo "now make sparse ext4 img: $img"
    else
        echo "$img is not ext4 img"
        file $img
        return
    fi

    img2simg $img $sparse_img
}

# pack user resources to a vfat filesystem
# To use this, please add a folder "user-resource" in configs to save files, and add a partition to sys_partition.fex/sys_partition_nor.fex like this:
# [partition]
#   name         = user-res
#   size         = 1024	//size should be 32 aligned
#   downloadfile = "user-resource.fex"
#   user_type    = 0x8000
function make_user_res()
{
    printf "make user resource for : $1\n"
    local USER_RES_SYS_PARTITION=$1
    local USER_RES_PART_NAME=user-res
    local USER_RES_FILE=user-resource

    printf "handle partition ${USER_RES_PART_NAME}\n"
    local USER_RES_PART_DOWNLOAD_FILE=user-resource.fex
    local USER_RES_PART_SIZE=`sed -n "/${USER_RES_PART_NAME}/{N;p}" ${USER_RES_SYS_PARTITION} | awk '$0~"size"{print $3/2}'`
    local USER_RES_FILE_PATH=$CFG_TOP_DIR/${PACK_PLATFORM}/target/$PACK_IC/$PACK_IC-${PACK_BOARD}/configs/${USER_RES_FILE}

    if [ x"${USER_RES_PART_DOWNLOAD_FILE}" != x"" -a  x"${USER_RES_PART_SIZE}" != x"" ]; then
        rm -f ${LICHEE_PACK_OUT_DIR}/user-resource.fex
        mkfs.vfat ${LICHEE_PACK_OUT_DIR}/user-resource.fex -C ${USER_RES_PART_SIZE}
        if [ -d ${USER_RES_FILE_PATH} ]; then
            USER_RES_FILE_SIZE=`du --apparent-size --summarize "${USER_RES_FILE_PATH}" | awk '{print $1}'`
            printf "file size: ${USER_RES_FILE_SIZE}\n"
            printf "partition size: ${USER_RES_PART_SIZE}\n"
            if [ ${USER_RES_PART_SIZE} -le ${USER_RES_FILE_SIZE} ]; then
                printf "file size is larger than partition size, please check your configuration\n"
                printf "please enlarge size of ${USER_RES_PART_NAME} in sys_partition or remove some files in $USER_RES_FILE_PATH\n"
                exit -1
            fi
            mcopy -s -v -i ${LICHEE_PACK_OUT_DIR}/${USER_RES_PART_DOWNLOAD_FILE} ${USER_RES_FILE_PATH}/* ::
            if [ $? -ne 0 ]; then
                printf "mcopy file fail, exit\n"
                exit -1
            fi
        else
            printf "can not find ${USER_RES_FILE_PATH}, ignore it\n"
        fi
    else
        printf "no user resource partitions\n"
    fi
}

#[partition]
#    name         = app
#    size         = 10080
#    downloadfile = "app.fex"
#    user_type    = 0x8000
function make_app_res()
{
    local APP_PART_NAME=app
    cp $1 sys_partition_tmp_app.fex

    sed -i '/^[ \t]*downloadfile/d' sys_partition_tmp_app.fex
    maybe_busybox unix2dos sys_partition_tmp_app.fex
    script  sys_partition_tmp_app.fex > /dev/null
    update_mbr sys_partition_tmp_app.bin 1 sunxi_mbr_tmp_app.fex > /dev/null

    local APP_PART_DOWNLOAD_FILE=app.fex
    local APP_PART_FILE_PATH=$CFG_TOP_DIR/out/$PACK_IC/$PACK_BOARD/$PACK_PLATFORM/build_dir/target/app
    local APP_PART_SIZE_IN_SECTOR=`parser_mbr sunxi_mbr_tmp_app.fex get_size_by_name ${APP_PART_NAME}`
	local TINA_TOOLS_PATH=$CFG_TOP_DIR/out/$PACK_IC/$PACK_BOARD/$PACK_PLATFORM/staging_dir/host/bin

    if [ x${APP_PART_DOWNLOAD_FILE} != x'' -a  x${APP_PART_SIZE_IN_SECTOR} != x'' ]; then
        let APP_PART_SIZE_IN_K=$APP_PART_SIZE_IN_SECTOR/2
        echo "APP_PART_DOWNLOAD_FILE = ${LICHEE_PACK_OUT_DIR}/${APP_PART_DOWNLOAD_FILE}"
        rm -f ${LICHEE_PACK_OUT_DIR}/${APP_PART_DOWNLOAD_FILE}
        ${TINA_TOOLS_PATH}/make_ext4fs -l ${APP_PART_SIZE_IN_K}k -b 1024 -m 0 -j 1024 ${LICHEE_PACK_OUT_DIR}/${APP_PART_DOWNLOAD_FILE}  ${APP_PART_FILE_PATH}
    else
        printf "no app resource partitions\n"
    fi
}

#[partition]
#    name         = data
#    size         = 10080
#    downloadfile = "data.fex"
#    user_type    = 0x8000
function make_data_res()
{
    local DATA_PART_NAME=data
    cp $1 sys_partition_tmp_data.fex

    sed -i '/^[ \t]*downloadfile/d' sys_partition_tmp_data.fex
    maybe_busybox unix2dos sys_partition_tmp_data.fex
    script  sys_partition_tmp_data.fex > /dev/null
    update_mbr sys_partition_tmp_data.bin 1 sunxi_mbr_tmp_data.fex > /dev/null

    local DATA_PART_DOWNLOAD_FILE=data.fex
    local DATA_PART_DOWNLOAD_FILE_SPARSE=data_s.fex
    local DATA_PART_FILE_PATH=$CFG_TOP_DIR/out/$PACK_IC/$PACK_BOARD/$PACK_PLATFORM/build_dir/target/data
    local DATA_PART_SIZE_IN_SECTOR=`parser_mbr sunxi_mbr_tmp_data.fex get_size_by_name ${DATA_PART_NAME}`
	local TINA_TOOLS_PATH=$CFG_TOP_DIR/out/$PACK_IC/$PACK_BOARD/$PACK_PLATFORM/staging_dir/host/bin

    if [ x${DATA_PART_DOWNLOAD_FILE} != x'' -a  x${DATA_PART_SIZE_IN_SECTOR} != x'0' ]; then
        let DATA_PART_SIZE_IN_K=$DATA_PART_SIZE_IN_SECTOR/2
        echo "DATA_PART_DOWNLOAD_FILE = ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE}"
        rm -f ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE}
        rm -f ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE_SPARSE}
        ${TINA_TOOLS_PATH}/make_ext4fs -l ${DATA_PART_SIZE_IN_K}k -b 1024 -m 0 -j 1024 ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE}  ${DATA_PART_FILE_PATH}
        sparse_ext4 ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE} ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE_SPARSE}
    else
        printf "no data resource partitions\n"
    fi
}

################################ Platform func ################################
function do_pack_android()
{
	local localpath=$(readlink -f $(pwd))
	local androidout=$(readlink -f ${ANDROID_IMAGE_OUT})
	local link_real=$(get_realpath $androidout $localpath)

	printf "packing for android\n"

	if [ -z "${ANDROID_IMAGE_OUT}" ] ; then
		pack_error "please specify ANDROID_IMAGE_OUT env"
		exit 1
	fi

	local fex_list=($(\gawk '$0~"^[[:space:]]*downloadfile[[:space:]]*="{print $NF}' sys_partition.fex | sed 's/[",\r,\n]//g'))
	fex_list+=(vendor_boot-debug.fex)

	local img_name=""
	for fex_name in ${fex_list[@]}; do
		img_name=${fex_name%\.fex}.img
		if [ -f ${ANDROID_IMAGE_OUT}/${img_name} ]; then
			ln -sf ${link_real}/${img_name} ${fex_name}
			echo "link ${img_name} -> ${fex_name}"
		fi
	done

	if [ -e $androidout/vmlinux ]; then
		export PATH=$PATH:${LICHEE_TOP_DIR}/build/bin
		local vmlinuxpath=$(dirname $(readlink -f $androidout/vmlinux))
		local vmlinuxname=$(basename $(readlink -f $androidout/vmlinux))
		(cd $vmlinuxpath && tar cf $localpath/vmlinux.tar.bz2 --use-compress-prog=lbzip2 $vmlinuxname)
		rm -rf vmlinux.fex
		ln -sf vmlinux.tar.bz2 vmlinux.fex
	fi

	if [ -n "${PACK_BOOT_PATH}" ] && [ "x${PACK_BOOT_PATH}" != "xnone" ]; then
		ln -sf $PACK_BOOT_PATH boot.fex
	fi

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		echo "secure"
		do_android_signature
	else
		echo "normal"
	fi
}

function prepare_mixed_androiddragonboard()
{
	local mixed_fw_type

	if [ "${PACK_TYPE}" != "android" ] || [ -z "$PACK_MIXED_FIRMWARE" ]; then
		return 0
	fi

	case "$PACK_MIXED_FIRMWARE" in
		dragonboard|dragonabts)
			mixed_fw_type="$PACK_MIXED_FIRMWARE"
			pack_info "${FUNCNAME[0]}: mixed firmware type: $mixed_fw_type"
			;;
		*)
			echo "Unsupport mixed firmware type: $PACK_MIXED_FIRMWARE"
			return 1
	esac

	(
		cd ${LICHEE_PACK_OUT_DIR}

		local localpath=$(readlink -f $(pwd))
		local mixedboardout=$(readlink -f ${CFG_PLAT_OUT}/../$mixed_fw_type)
		if [ ! -d $mixedboardout ]; then
			pack_error "${FUNCNAME[0]}: cannot find out path for $mixed_fw_type"
			exit 1
		fi

		local envpath=($LICHEE_BOARD_CONFIG_DIR/$mixed_fw_type $LICHEE_CHIP_CONFIG_DIR/configs/default)
		local partition=(bootloader_b:boot-resource.fex env_b:denv.fex
					boot_b:dboot.fex vendor_boot_b:vendor_boot.fex media_data)

		local item name linenum nstart nend nmax file

		for item in ${partition[@]}; do
			name=${item/:*}
			linenum=$(sed -n "/^\s*name\s*=\s*$name/=" sys_partition.fex)
			if [ -z "$linenum" ]; then
				pack_error "${FUNCNAME[@]}: leak neccery partition $name in sys_partition.fex"
				exit 1
			fi
		done

		for item in ${envpath[@]}; do
			if [ -e $item/env.cfg ]; then
				cp $item/env.cfg denv.cfg
				sed -i '/^\s*boot_normal=/s/\<boot\>/boot_b/g' denv.cfg
				generate_env_for_uboot denv.cfg $mixedboardout/env.img
				rm -rf denv.cfg
				break
			fi
		done

		if  [ ! -e $mixedboardout/env.img  ] || \
			[ ! -e $mixedboardout/boot.img ] || \
			[ ! -e $mixedboardout/rootfs.ext4 ] || \
			[ ! -e $LICHEE_BOARD_CONFIG_DIR/$mixed_fw_type/test_config.fex ]; then
			pack_error "${FUNCNAME[@]}: leak neccery img/fex for $mixed_fw_type"
			exit 1
		fi

		printf "prepare for mixed android/$mixed_fw_type packing...\n"
		for item in ${partition[@]}; do
			name=${item/:*}
			linenum=$(sed -n "/^\s*name\s*=\s*$name/=" sys_partition.fex)
			nstart=$linenum
			nend=$linenum
			nmax=$(wc -l sys_partition.fex | awk '{print $1}')
			while [ $nstart -gt 1 ]; do
				nstart=$((nstart-1))
				if [ -n "$(sed -n "$nstart p" sys_partition.fex | grep "^\s*\[\S\+\]")" ]; then
					break;
				fi
			done

			while [ $nend -lt $nmax ]; do
				nend=$((nend+1))
				if [ -n "$(sed -n "$nend p" sys_partition.fex | grep "^\s*\[\S\+\]")" ]; then
					break;
				fi
			done
			[ $nend -ne $nmax ] && nend=$((nend-1))

			file="$(sed -n "${nstart},${nend}p" sys_partition.fex | \
					awk -F= '/^[[:space:]]*downloadfile[[:space:]]*=/{print $2}')"
			dlfile=${e#*:}
			case $name in
				bootloader_b|env_b|boot_b|vendor_boot_b)
					if [ -z "$file" ]; then
						sed -i "$linenum a\ \ \ \ downloadfile = \"${item#*:}\"" sys_partition.fex
					fi
					;;
				media_data)
					local cmd="$nstart i"
					local size=$(stat $mixedboardout/rootfs.ext4 --format="%s")

					size=$(((size+32*1024*1024-1)/(16*1024*1024)*16))  # at least size + 16M, and 16M align

					if [ -z "$(grep "^\s*name\s*=\s*rootfs" sys_partition.fex)" ]; then
						cmd+="[partition]\n"
						cmd+="    name         = rootfs\n"
						cmd+="    size         = ${size}M\n"
						cmd+="    downloadfile = \"drootfs.fex\"\n"
						cmd+="    user_type    = 0x8000\n"
						cmd+="\n"
					fi
					[ "$cmd" != "$nstart i" ] && sed -i "$cmd" sys_partition.fex
					;;
			esac
		done

		# Delete "^M" under Windows
		sed -i 's|
||g' sys_partition.fex

		readcfg dragon_toc.cfg key_para key > /dev/null
		if [ $? -ne 0 ]; then
			[ -z "$(grep "^\s*onlykey=boot_b,\s*dboot.fex," dragon_toc.cfg)" ] && \
			sed -i 's|^\(\s*onlykey=boot_b,\s*\)\S*,|\1dboot.fex,|g'    dragon_toc.cfg

			[ -z "$(grep "^\s*onlykey=boot_b,\s*dboot.fex," dragon_toc.cfg)" ] && \
			echo "onlykey=boot_b,dboot.fex,SCPFirmwareContentCertPK" >> dragon_toc.cfg
		else
			if [ -z "$(grep "^\s*onlykey=boot_b,\s*dboot.fex," dragon_toc.cfg)" ]; then
				sed -i '/^optee=/a boot_b=SCPFirmwareContentCertPK' dragon_toc.cfg
				sed -i '/^item=optee/a\onlykey=boot_b,dboot.fex,boot_b.crtpt' dragon_toc.cfg
			fi
		fi

		cp $LICHEE_BOARD_CONFIG_DIR/$mixed_fw_type/test_config.fex .
		maybe_busybox dos2unix test_config.fex
		cp test_config.fex boot-resource/
		script test_config.fex > /dev/null
		cp test_config.bin boot-resource/

		cp $mixedboardout/env.img denv.fex
		cp $mixedboardout/boot.img dboot.fex
		cp $mixedboardout/rootfs.ext4 drootfs.fex
		echo "android:$PACK_MIXED_FIRMWARE" > mixed-image-type.txt
	)
	if [ $? -ne 0 ]; then
		pack_error "${FUNCNAME[0]} fail"
		return 1
	fi
	return 0
}

function do_pack_dragonboard()
{
	local link_real=$(get_realpath ${LICHEE_PLAT_OUT} ./)
	printf "packing for dragonboard\n"

	ln -sf ${link_real}/boot.img boot.fex
	ln -sf ${link_real}/rootfs.ext4 rootfs.fex
	ln -sf ${link_real}/rootfs.ubifs rootfs-ubifs.fex

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		do_signature
	else
		echo "normal"
	fi
}

function do_pack_dragonabts()
{
	local link_real=$(get_realpath ${LICHEE_PLAT_OUT} ./)
	printf "packing for dragonabts\n"

	ln -sf ${link_real}/boot.img boot.fex
	ln -sf ${link_real}/rootfs.ext4 rootfs.fex
	ln -sf ${link_real}/rootfs.ubifs rootfs-ubifs.fex

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		do_signature
	else
		echo "normal"
	fi
}

function do_pack_linux()
{
	local link_real=$(get_realpath ${LICHEE_PLAT_OUT} ./)
	local recovery_path=${link_real}/recovery.img

	printf "packing for linux\n"

	do_fit_image
	if [ $? -eq 0 ]; then
		[ -f kernel.itb ] && mv kernel.itb   kernel.fex
		[ -f kernel-dtb.itb ] && mv kernel-dtb.itb   kernel-dtb.fex
	else
		[ -f ${link_real}/bootB.img ] && ln -sf ${link_real}/bootB.img bootB.fex
		ln -sf ${link_real}/boot.img        boot.fex

		# Those files is ready for SPINor.
		ln -sf ${link_real}/uImage          kernel.fex
		if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
			ln -sf ${link_real}/rootfs.img rootfs_nor.fex
		else
			ln -sf ${link_real}/rootfs.squashfs rootfs_nor.fex
		fi
	fi

	if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
		ln -sf ${link_real}/rootfs.img     rootfs.fex
	else
		ln -sf ${link_real}/rootfs.ext4     rootfs.fex
	fi

	ln -sf ${link_real}/rootfs.ubifs     rootfs-ubifs.fex

	if [ -f "$recovery_path" ]; then
		ln -sf ${recovery_path}     recovery.fex
	fi

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		echo "secure"
		do_signature
	else
		echo "normal"
	fi
}

function create_kernel_fit_image()
{
	local its_name=$1

	printf "create_kernel_fit_image\n"

	if [ ! -f ${LICHEE_PACK_OUT_DIR}/${its_name}.its ]; then
		printf "can not found ${its_name}.its\n"
		return 1
	fi

	mkimage -f ${its_name}.its ${its_name}.itb
	if [ $? -ne 0 ]; then
		pack_error "mkimage ${its_name}.itb error\n"
		exit 1
	fi
}

function do_fit_image()
{
	printf "do_fit_image\n"

	create_kernel_fit_image kernel
	if [ $? -ne 0 ]; then
		return 1
	fi

	create_kernel_fit_image kernel-dtb
	if [ $? -ne 0 ]; then
		return 1
	fi
}

function main()
{
	local output_resources=${FLAGS_output_resources:-false}
	local from_resources=${FLAGS_from_resources}

	local support_secure_type
	case x$LICHEE_PACK_SECURE_TYPE in
		xnone|xsecure|xany)
			support_secure_type=$LICHEE_PACK_SECURE_TYPE
			;;
		x)
			support_secure_type=any
			;;
		*)
			pack_error "Unsupport pack secure type: $LICHEE_PACK_SECURE_TYPE"
			return 1
			;;
	esac

	if [ "$support_secure_type" != "any" ] && [ "$support_secure_type" != "$PACK_SECURE" ]; then
		pack_error "This platform only support secure type [$support_secure_type], but current using [$PACK_SECURE], please check!!!"
		pack_error "Now, we try using secure type [$support_secure_type]!!!"
		PACK_SECURE=$support_secure_type
	fi

	if [ "$output_resources" == "false" ] && [ -z "$from_resources" ]; then
		do_prepare
		do_ini_to_dts
		do_common
		do_pack_${PACK_TYPE}
		do_finish
		return $?
	fi

	if [ "$output_resources" == "true" ]; then
		do_prepare
		do_ini_to_dts
	elif [ -n "$from_resources" ]; then
		if [ ! -d $from_resources ]; then
			pack_error "Cannot find resources path: $from_resources"
			return 1
		fi

		local count=0
		while [ -e ${LICHEE_PACK_OUT_DIR} -a  $count -lt 20 ]; do
			rm -rf ${LICHEE_PACK_OUT_DIR}
			count=$((count+1))
		done
		cp -rax $from_resources ${LICHEE_PACK_OUT_DIR}
		(
			cd $LICHEE_OUT_DIR
			if [ "${LICHEE_PACK_OUT_DIR}" != "$LICHEE_OUT_DIR/pack_out" ]; then
				rm -rf pack_out
				ln -sf ${LICHEE_IC}/${LICHEE_BOARD}/pack_out pack_out
			fi
		)

		if [ "${PACK_PLATFORM}" == "android" ] && [ -n "$PACK_MIXED_FIRMWARE" ]; then
			local resource_type="$(cat ${LICHEE_PACK_OUT_DIR}/mixed-image-type.txt)"
			local mixed_fw_type="android:$PACK_MIXED_FIRMWARE"
			if [ "$resource_type" != "android:$PACK_MIXED_FIRMWARE" ]; then
				pack_error "mixed firmware type [$mixed_fw_type] but resource type [$resource_type]"
				exit 1
			fi
			pack_info "mixed firmware type [$mixed_fw_type]"
		fi

		cd ${LICHEE_PACK_OUT_DIR}
		do_common
		do_pack_${PACK_TYPE}
		do_finish
	fi
	return $?
}

main "$@"

longan/build/pack 修改后:

#!/bin/bash
#
# pack/pack
# (c) Copyright 2013
# Allwinner Technology Co., Ltd. <www.allwinnertech.com>
# James Deng <csjamesdeng@allwinnertech.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

############################ Notice #####################################
# a. Some config files priority is as follows:
#    - xxx_${platform}.{cfg|fex} > xxx.{cfg|fex}
#    - ${chip}/${board}/*.{cfg|fex} > ${chip}/default/*.{cfg|fex}
#    - ${chip}/default/*.cfg > ${LICHEE_COMMON_CONFIG_DIR}/imagecfg/*.cfg
#    - ${chip}/default/*.fex > ${LICHEE_COMMON_CONFIG_DIR}/partition/*.fex
#  e.g. sun8iw7p1/configs/perf/image_linux.cfg > sun8iw7p1/configs/default/image_linux.cfg
#       > ${LICHEE_COMMON_CONFIG_DIR}/imagecfg/image_linux.cfg > sun8iw7p1/configs/perf/image.cfg
#       > sun8iw7p1/configs/default/image.cfg > ${LICHEE_COMMON_CONFIG_DIR}/imagecfg/image.cfg
#
# b. Support Nor storages rule:
#    - Need to create sys_partition_nor.fex or sys_partition_nor_${platform}.fex
#    - Add "{filename = "full_img.fex",     maintype = "12345678", \
#      subtype = "FULLIMG_00000000",}" to image[_${platform}].cfg
#
# c. Switch uart port
#    - Need to add your chip configs into ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin
#    - Call pack with 'debug' parameters

#if you want to debug pack, set vlaue to 1. use pause func in the place where you want to stop
enable_pause=0

function get_char()
{
	SAVEDSTTY=`stty -g`
	stty -echo
	stty cbreak
	dd if=/dev/tty bs=1 count=1 2> /dev/null
	stty -raw
	stty echo
	stty $SAVEDSTTY
}

function pause()
{
	if [ "x$1" != "x" ] ;then
		echo "$1"
	fi
	if [ $enable_pause -eq 1 ] ; then
		echo "Press any key to continue!"
		char=`get_char`
	fi
}

function pack_error()
{
	echo -e "\033[47;31mERROR: $*\033[0m"
}

function pack_warn()
{
	echo -e "\033[47;34mWARN: $*\033[0m"
}

function pack_info()
{
	echo -e "\033[47;30mINFO: $*\033[0m"
}

localpath=$(cd $(dirname $0) && pwd)
. $localpath/shflags

# define option, format:
#   'long option' 'default value' 'help message' 'short option'
DEFINE_string 'chip' '' 'chip to build, e.g. sun7i' 'c'
DEFINE_string 'ic' '' 'ic to build, e.g. a50' 'i'
DEFINE_string 'addition' '' 'additional config files, e.g. xx.fex' 'a'
DEFINE_string 'platform' '' 'platform to build, e.g. linux, android' 'p'
DEFINE_string 'platform_version' '' 'platform version to build' 'V'
DEFINE_string 'board' '' 'board to build, e.g. evb' 'b'
DEFINE_string 'kernel' '' 'kernel to build, e.g. linux-3.4, linux-3.10' 'k'
DEFINE_string 'debug_mode' 'uart0' 'config debug mode, e.g. uart0, card0' 'd'
DEFINE_string 'signture' 'none' 'pack boot signture to do secure boot' 's'
DEFINE_string 'secure' 'none' 'pack secure boot with -v arg' 'v'
DEFINE_string 'mode' 'normal' 'pack dump firmware' 'm'
DEFINE_string 'function' 'android' 'pack private firmware' 'f'
DEFINE_string 'vsp' '' 'pack firmware for vsp' 't'
DEFINE_string 'programmer' '' 'creat programmer img or not' 'w'
DEFINE_string 'key_path' '' 'the path of keys' 'P'
DEFINE_string 'nor' 'none' 'pack nor image' 'n'
DEFINE_boolean 'verity' false 'if enable dm-verity' ''
DEFINE_boolean 'signfel' false 'if enable fel signing' ''
DEFINE_string 'boot_path' '' 'the path of gki boot.img' 'B'
DEFINE_string 'output_resources' '' 'only output resources to pack-out' ''
DEFINE_string 'from_resources' '' 'pack from resources path' ''

# parse the command-line
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"

PACK_CHIP=${FLAGS_chip}
PACK_IC=${FLAGS_ic}
PACK_PLATFORM=${FLAGS_platform}
PACK_PLATFORM_VERSION=${FLAGS_platform_version}
PACK_BOARD=${FLAGS_board}
PACK_KERN=${FLAGS_kernel}
PACK_DEBUG=${FLAGS_debug_mode}
PACK_SIG=${FLAGS_signture}
PACK_SECURE=${FLAGS_secure}
PACK_MODE=${FLAGS_mode}
PACK_FUNC=${FLAGS_function}
PACK_VSP=${FLAGS_vsp}
PACK_PROGRAMMER=${FLAGS_programmer}
PACK_NOR=${FLAGS_nor}
PACK_PRODUCT=${FLAGS_product}
PACK_VERITY=${FLAGS_verity}
PACK_SIGNFEL=${FLAGS_signfel}
PACK_ADD_FILES=(${FLAGS_addition})
PACK_KEY_PATH=${FLAGS_key_path}
PACK_BOOT_PATH=${FLAGS_boot_path}

CFG_TOP_DIR=$(cd $localpath/../ && pwd)
CFG_PLAT_OUT=$CFG_TOP_DIR/out/$PACK_IC/$PACK_BOARD/$PACK_PLATFORM
CFG_KEY_DIR=$CFG_TOP_DIR/out/$PACK_IC/common/keys

if [ ! -z "${PACK_KEY_PATH}" ]; then
    CFG_KEY_DIR=${PACK_KEY_PATH}
fi
pack_info "${CFG_KEY_DIR}"

if [ ! -d ${CFG_PLAT_OUT} ] || \
   [ ! -f $CFG_PLAT_OUT/.buildconfig ]; then
	pack_error "config & build lichee before you pack"
	exit 1
fi

source $CFG_PLAT_OUT/.buildconfig

if [ -z "${PACK_KERN}" ]; then
	pack_info "No kernel param, parse it from .buildconfig"
	PACK_KERN=$LICHEE_KERN_VER
	if [ -z "${PACK_KERN}" ]; then
		pack_error "Failed to parse kernel param from .buildconfig"
		exit 1
	fi
fi

PACK_TYPE=""
case "x${PACK_PLATFORM}" in
	"xandroid")
		PACK_TYPE="android"
		;;
	"xdragonboard")
		PACK_TYPE="dragonboard"
		;;
	"xdragonabts")
		PACK_TYPE="dragonabts"
		;;
	"xbsp"|"xsata"|"xbuildroot"|"xopenwrt"|"xdebian")
		PACK_TYPE="linux"
		;;
	*)
		pack_error "Unsupport PACK_PLATFORM: ${PACK_PLATFORM}"
		exit 1
		;;
esac

export PATH=${LICHEE_TOOLS_DIR}/pack/pctools/linux/mod_update:${LICHEE_TOOLS_DIR}/pack/pctools/linux/openssl:${LICHEE_TOOLS_DIR}/pack/pctools/linux/eDragonEx:${LICHEE_TOOLS_DIR}/pack/pctools/linux/fsbuild200:${LICHEE_TOOLS_DIR}/pack/pctools/linux/android:$PATH
export LD_LIBRARY_PATH=${LICHEE_TOOLS_DIR}/pack/pctools/linux/softhsm/lib/:$LD_LIBRARY_PATH

tools_file_list=(
${LICHEE_COMMON_CONFIG_DIR}/tools/split_xxxx.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/split_xxxx.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/usbtool_test.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/usbtool_crash.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/usbtool_test.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/cardscript.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/cardscript_secure.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/cardscript.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/cardscript_secure.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/cardtool.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/cardtool.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/usbtool.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/usbtool.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/usbtool_crash.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/usbtool_crash.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/aultls32.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/aultls32.fex
${LICHEE_COMMON_CONFIG_DIR}/tools/aultools.fex
${LICHEE_CHIP_CONFIG_DIR}/tools/aultools.fex
)

configs_file_list=(
${LICHEE_COMMON_CONFIG_DIR}/toc/toc1.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/toc0.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/toc0_sdcard.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/toc0_nand.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/toc0_ufs.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/toc0_ft.fex
${LICHEE_COMMON_CONFIG_DIR}/toc/boot_package.fex
${LICHEE_COMMON_CONFIG_DIR}/hdcp/esm.fex
${LICHEE_COMMON_CONFIG_DIR}/dtb/sunxi.fex
${LICHEE_COMMON_CONFIG_DIR}/imagecfg/*.cfg
${LICHEE_COMMON_CONFIG_DIR}/partition/sys_partition_dump.fex
${LICHEE_COMMON_CONFIG_DIR}/partition/sys_partition_private.fex
${LICHEE_COMMON_CONFIG_DIR}/version/version_base.mk
${LICHEE_CHIP_CONFIG_DIR}/configs/default/*
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/*.fex
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/boot_package*.cfg
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/${LICHEE_KERN_VER}/*.cfg
${LICHEE_CHIP_CONFIG_DIR}/configs/default/version_base.mk
${LICHEE_CHIP_CONFIG_DIR}/dtbo/*
${LICHEE_BOARD_CONFIG_DIR}/dtbo/*
${LICHEE_CHIP_CONFIG_DIR}/${BIN_PATH}/ft_${PACK_CHIP}.bin
${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_ft.cfg
${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc_ft.cfg
${LICHEE_COMMON_CONFIG_DIR}/sign_config/cnf_base.cnf
${LICHEE_PLAT_OUT}/.buildconfig
)

product_configs_file_list=(
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/${PACK_PLATFORM}/*.fex
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/${PACK_PLATFORM}/*.cfg
)

boot_resource_list=(
${LICHEE_CHIP_CONFIG_DIR}/boot-resource/boot-resource:${LICHEE_PACK_OUT_DIR}
${LICHEE_CHIP_CONFIG_DIR}/boot-resource/boot-resource.ini:${LICHEE_PACK_OUT_DIR}
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/*.bmp:${LICHEE_PACK_OUT_DIR}/boot-resource/
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/bootlogo.bmp:${LICHEE_PACK_OUT_DIR}/bootlogo.bmp
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/wavefile/*:${LICHEE_PACK_OUT_DIR}/boot-resource/wavefile/
${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/${PACK_TYPE}/*.bmp:${LICHEE_PACK_OUT_DIR}/boot-resource/
${LICHEE_CHIP_CONFIG_DIR}/boot-resource/boot-resource/bat/bempty.bmp:${LICHEE_PACK_OUT_DIR}/bempty.bmp
${LICHEE_CHIP_CONFIG_DIR}/boot-resource/boot-resource/bat/battery_charge.bmp:${LICHEE_PACK_OUT_DIR}/battery_charge.bmp
)
#${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_nand_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_nand.fex
#${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_sdcard_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_sdcard.fex
#${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_ufs_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_ufs.fex
#${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_${LICHEE_BOOT0_BIN_NAME}_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex
#${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_nandfastboot_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_nandfastboot_${PACK_CHIP}.fex
#${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/boot0_spinor_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_spinor.fex
boot_file_list=(
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/fes1_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/fes1.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/fes1_uart_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/fes1_uart.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-${LICHEE_EFEX_BIN_NAME}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-${LICHEE_EFEX_BIN_NAME}.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-crashdump-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-crash.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-crashdump-spinor-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor-crash.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/bl31.bin:${LICHEE_PACK_OUT_DIR}/monitor.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/bl31_${PACK_BOARD}.bin:${LICHEE_PACK_OUT_DIR}/monitor.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/scp.bin:${LICHEE_PACK_OUT_DIR}/scp.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/amp_dsp0.bin:${LICHEE_PACK_OUT_DIR}/amp_dsp0.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/amp_dsp1.bin:${LICHEE_PACK_OUT_DIR}/amp_dsp1.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/amp_arm64.bin:${LICHEE_PACK_OUT_DIR}/amp_arm64.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/amp_rv0.bin:${LICHEE_PACK_OUT_DIR}/amp_rv0.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/video.bin:${LICHEE_PACK_OUT_DIR}/video.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/optee_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/optee.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/optee_${PACK_CHIP}-monitor.bin:${LICHEE_PACK_OUT_DIR}/optee-monitor.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/opensbi_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/opensbi.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-spinor-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/u-boot-spinor-secure-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor-secure.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/*.fex:${LICHEE_PACK_OUT_DIR}/
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/*.dtb:${LICHEE_PACK_OUT_DIR}/
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/*.bin:${LICHEE_PACK_OUT_DIR}/
)

#${LICHEE_PLAT_OUT}/boot0_nand_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_nand.fex
#${LICHEE_PLAT_OUT}/boot0_sdcard_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_sdcard.fex
#${LICHEE_PLAT_OUT}/boot0_${LICHEE_BOOT0_BIN_NAME}_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex
#${LICHEE_PLAT_OUT}/boot0_spinor_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/boot0_spinor.fex
boot_file_list_2=(
${LICHEE_PLAT_OUT}/arisc:${LICHEE_PACK_OUT_DIR}/arisc.fex
${LICHEE_PLAT_OUT}/sunxi.dtb:${LICHEE_PACK_OUT_DIR}/sunxi.fex
${LICHEE_PLAT_OUT}/fes1_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/fes1.fex
${LICHEE_PLAT_OUT}/fes1_uart_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/fes1_uart.fex
${LICHEE_PLAT_OUT}/sboot_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot.bin
${LICHEE_PLAT_OUT}/sboot_nor_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nor.bin
${LICHEE_PLAT_OUT}/sboot_sdcard_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_sdcard.bin
${LICHEE_PLAT_OUT}/sboot_nand_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nand.bin
${LICHEE_PLAT_OUT}/sboot_ufs_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_ufs.bin
${LICHEE_PLAT_OUT}/u-boot-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot.fex
${LICHEE_PLAT_OUT}/u-boot-${LICHEE_EFEX_BIN_NAME}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-${LICHEE_EFEX_BIN_NAME}.fex
${LICHEE_PLAT_OUT}/u-boot-crashdump-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-crash.fex
${LICHEE_PLAT_OUT}/u-boot-crashdump-spinor-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor-crash.fex
${LICHEE_PLAT_OUT}/scp.bin:${LICHEE_PACK_OUT_DIR}/scp.fex
${LICHEE_PLAT_OUT}/u-boot-spinor-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor.fex
${LICHEE_PLAT_OUT}/u-boot-spinor-secure-${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/u-boot-spinor-secure.fex
${LICHEE_PLAT_OUT}/vmlinux.tar.bz2:${LICHEE_PACK_OUT_DIR}/vmlinux.fex
)

arm_boot_file_secure=(
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/semelis_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/semelis.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/optee_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/optee.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_nor_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nor.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_sdcard_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_sdcard.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_nand_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nand.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_ufs_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_ufs.bin
${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_android.cfg:${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc_android.cfg:${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
)

arm64_boot_file_secure=(
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/optee_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/optee.fex
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_nor_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nor.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_sdcard_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_sdcard.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_nand_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_nand.bin
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/sboot_ufs_${PACK_CHIP}.bin:${LICHEE_PACK_OUT_DIR}/sboot_ufs.bin
${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_a64_android.cfg:${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc_android.cfg:${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
${LICHEE_CHIP_CONFIG_DIR}/\${BIN_PATH}/amp_rv0.bin:${LICHEE_PACK_OUT_DIR}/amp_rv0.fex
)

#
# This function can get the realpath between $SRC and $DST
#
function get_realpath()
{
	local src=$(cd $1; pwd);
	local dst=$(cd $2; pwd);
	local res="./";
	local tmp="$dst"

	while [ "${src##*$tmp}" == "${src}" ]; do
		tmp=${tmp%/*};
		res=$res"../"
	done
	res="$res${src#*$tmp/}"

	printf "%s" $res
}

function show_boards()
{
	printf "\nAll avaiable chips, platforms and boards:\n\n"
	printf "Chip            Board\n"
	for chipdir in $(find chips/ -mindepth 1 -maxdepth 1 -type d) ; do
		chip=`basename ${chipdir}`
		printf "${chip}\n"
		for boarddir in $(find chips/${chip}/configs/${platform} \
			-mindepth 1 -maxdepth 1 -type d) ; do
			board=`basename ${boarddir}`
			printf "                ${board}\n"
		done
	done
	printf "\nFor Usage:\n"
	printf "     $(basename $0) -h\n\n"
}

function uart_switch()
{
	rm -rf ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	touch ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	TX=`awk  '$0~"'$PACK_CHIP'"{print $2}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	RX=`awk  '$0~"'$PACK_CHIP'"{print $3}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	PORT=`awk  '$0~"'$PACK_CHIP'"{print $4}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	MS=`awk  '$0~"'$PACK_CHIP'"{print $5}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	CK=`awk  '$0~"'$PACK_CHIP'"{print $6}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	DO=`awk  '$0~"'$PACK_CHIP'"{print $7}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`
	DI=`awk  '$0~"'$PACK_CHIP'"{print $8}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_pin`

	BOOT_UART_ST=`awk  '$0~"'$PACK_CHIP'"{print $2}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	BOOT_PORT_ST=`awk  '$0~"'$PACK_CHIP'"{print $3}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	BOOT_TX_ST=`awk  '$0~"'$PACK_CHIP'"{print $4}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	BOOT_RX_ST=`awk  '$0~"'$PACK_CHIP'"{print $5}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART0_ST=`awk  '$0~"'$PACK_CHIP'"{print $6}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART0_USED_ST=`awk  '$0~"'$PACK_CHIP'"{print $7}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART0_PORT_ST=`awk  '$0~"'$PACK_CHIP'"{print $8}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART0_TX_ST=`awk  '$0~"'$PACK_CHIP'"{print $9}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART0_RX_ST=`awk  '$0~"'$PACK_CHIP'"{print $10}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	UART1_ST=`awk  '$0~"'$PACK_CHIP'"{print $11}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	JTAG_ST=`awk  '$0~"'$PACK_CHIP'"{print $12}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	MS_ST=`awk  '$0~"'$PACK_CHIP'"{print $13}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	CK_ST=`awk  '$0~"'$PACK_CHIP'"{print $14}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	DO_ST=`awk  '$0~"'$PACK_CHIP'"{print $15}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	DI_ST=`awk  '$0~"'$PACK_CHIP'"{print $16}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	MMC0_ST=`awk  '$0~"'$PACK_CHIP'"{print $17}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`
	MMC0_USED_ST=`awk  '$0~"'$PACK_CHIP'"{print $18}' ${LICHEE_COMMON_CONFIG_DIR}/debug/card_debug_string`

	if [ -z "$TX" ] || [ -z "$BOOT_UART_ST" ]; then
		pack_error "$FUNCNAME: $PACK_CHIP not configured in card_debug_pin/card_debug_string!"
		exit 1
	fi

	echo '$0!~";" && $0~"'$BOOT_TX_ST'"{if(C)$0="'$BOOT_TX_ST' = '$TX'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$BOOT_RX_ST'"{if(C)$0="'$BOOT_RX_ST' = '$RX'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$BOOT_PORT_ST'"{if(C)$0="'$BOOT_PORT_ST' = '$PORT'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	if [ "`grep "auto_print_used" "${LICHEE_PACK_OUT_DIR}/sys_config.fex" | grep "1"`" ]; then
		echo '$0!~";" && $0~"'$MMC0_USED_ST'"{if(A)$0="'$MMC0_USED_ST' = 1";A=0} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	else
	echo '$0!~";" && $0~"'$MMC0_USED_ST'"{if(A)$0="'$MMC0_USED_ST' = 0";A=0} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	fi
	echo '$0!~";" && $0~"\\['$MMC0_ST'\\]"{A=1}  \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$UART0_TX_ST'"{if(B)$0="'$UART0_TX_ST' = '$TX'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$UART0_RX_ST'"{if(B)$0="'$UART0_RX_ST' = '$RX'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"\\['$UART0_ST'\\]"{B=1} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$UART0_USED_ST'"{if(B)$0="'$UART0_USED_ST' = 1"}  \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '/^'$UART0_PORT_ST'/{next} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"\\['$UART1_ST'\\]"{B=0} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"\\['$BOOT_UART_ST'\\]"{C=1} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"\\['$JTAG_ST'\\]"{C=0} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$MS_ST'"{$0="'$MS_ST' = '$MS'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$CK_ST'"{$0="'$CK_ST' = '$CK'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$DO_ST'"{$0="'$DO_ST' = '$DO'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '$0!~";" && $0~"'$DI_ST'"{$0="'$DI_ST' = '$DI'"} \' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0
	echo '1' >> ${LICHEE_PACK_OUT_DIR}/awk_debug_card0

	if [ "`grep "auto_print_used" "${LICHEE_PACK_OUT_DIR}/sys_config.fex" | grep "1"`" ]; then
		sed -i -e '/^uart0_rx/a\pinctrl-1=' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		sed -i -e '/^uart0_rx/a\pinctrl-0=' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	fi

	awk -f ${LICHEE_PACK_OUT_DIR}/awk_debug_card0 ${LICHEE_PACK_OUT_DIR}/sys_config.fex > ${LICHEE_PACK_OUT_DIR}/sys_config_debug.fex
	rm -f ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	mv ${LICHEE_PACK_OUT_DIR}/sys_config_debug.fex ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	echo "uart -> card0"
}

function add_lzma_header()
{
	lzma_file=$1
	original_file=$2
	file_size=$(printf "%.8x\n" `stat -c%s ${lzma_file}`)
	original_file_size=$(printf "%.8x\n" `stat -c%s ${original_file}`)

	bin_str=""

	file_size_len=${#file_size}

	#"LZMA"+size+origin_size
	bin_str="\x4c\x5a\x4d\x41\x${file_size:6:2}\x${file_size:4:2}\x${file_size:2:2}\x${file_size:0:2}"
	bin_str+="\x${original_file_size:6:2}\x${original_file_size:4:2}\x${original_file_size:2:2}\x${original_file_size:0:2}"


	printf "%b" ${bin_str} > tempbin

	cat ${lzma_file} >> tempbin

	mv tempbin "${lzma_file}.head"
}

function partition_size_handle()
{
	echo "handle partition_size"
	local filename=${LICHEE_PACK_OUT_DIR}/sys_partition.fex
	local size
	local number
	local dimension
	local blocks
	local line
	local m
	local index=0
	while read line; do
		let "index++"
		size=$(echo $line | awk -F= '/^[[:space:]]*size[[:space:]]*=/{print $2}' | sed 's|\s\+||g')
		if [ -n "$size" ]; then
			dimension=$(echo $size | sed 's|^[0-9,.]\+||g')
			[ -z "$dimension" ] && continue
			case $dimension in
				B|b)
					m=1
					;;
				K|k)
					m=1024
					;;
				M|m)
					m=1048576
					;;
				G|g)
					m=1073741824
					;;
				*)
					pack_error "ERROR Dimension($dimension)!"
					return 1
					;;
			esac
			number=$(echo $size | sed 's|[a-z,A-Z]*$||g')
			blocks=$(echo "$number * $m / 512" | bc | awk -F. '{print $1}')
			printf "sys_partition.fex: size %6s => %7d Blocks\n" "${number}${dimension}" "${blocks}"
			size="$(echo "$line" | sed "s|=.*$|= $blocks|g")"
			sed -i "${index}s|$line|$size|g" $filename
		fi
	done < $filename
	return 0
}

function do_prepare()
{
	local runinfo=($(lsof 2>/dev/null | awk '$9~"'$LICHEE_TOP_DIR/tools/build/buildserver'"{print $2}'))
	local possible_bin_path="${LICHEE_POSSIBLE_BIN_PATH}"

	if [ ${#runinfo[@]} -lt 2 ]; then
		pack_error "something is incorrect:please <./build.sh config>."
	fi

	if [ -z "${PACK_CHIP}" -o -z "${PACK_TYPE}" -o -z "${PACK_BOARD}" ] ; then
		pack_error "Invalid parameters Chip: ${PACK_CHIP}, \
			Platform: ${PACK_TYPE}, Board: ${PACK_BOARD}"
		show_boards
		exit 1
	fi

	if [ ! -d ${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD} ] ; then
		pack_error "Board's directory \
			\"${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}\" is not exist."
		show_boards
		exit 1
	fi

	# Cleanup
#	if [ "x" != "x${LICHEE_PACK_OUT_DIR}" ]; then
#		rm -rf ${LICHEE_PACK_OUT_DIR}
#	fi
	mkdir -p ${LICHEE_PACK_OUT_DIR}

	(
		cd $LICHEE_OUT_DIR
		if [ "${LICHEE_PACK_OUT_DIR}" != "$LICHEE_OUT_DIR/pack_out" ]; then
#			rm -rf pack_out
			ln -sf ${LICHEE_IC}/${LICHEE_BOARD}/pack_out pack_out
		fi
	)

	printf "copying tools file\n"
	for file in ${tools_file_list[@]} ; do
		cp -f $file ${LICHEE_PACK_OUT_DIR} 2> /dev/null
	done

	if [ "x${PACK_KERN}" = "xlinux-3.4" ]; then
		cp -f ${LICHEE_COMMON_CONFIG_DIR}/tools/cardscript.fex ${LICHEE_PACK_OUT_DIR} 2> /dev/null
	fi

	printf "copying configs file\n"
	for file in ${configs_file_list[@]} ; do
		cp -f $file ${LICHEE_PACK_OUT_DIR} 2> /dev/null
	done

	printf "copying product configs file\n"
	for file in ${product_configs_file_list[@]}; do
		cp -f $file ${LICHEE_PACK_OUT_DIR} 2>/dev/null
	done

	if [ x"${PACK_PLATFORM}" != x"android" ]; then
		printf "linux copying boardt&linux_kernel_version configs file\n"
		local possible_env_path=(
			configs/default
			configs/${LICHEE_BOARD}
			configs/${LICHEE_BOARD}/${LICHEE_KERN_VER}
			configs/${LICHEE_BOARD}/${PACK_PLATFORM}
		)
		local possible_env_list=(
			env.cfg
			env-$(echo ${LICHEE_KERN_VER} | awk -F '-' '{print $2}').cfg
		)
		local copy_env_file=''

		for d in ${possible_env_path[@]}; do
			[ ! -d ${LICHEE_CHIP_CONFIG_DIR}/$d ] && continue
			for file in ${possible_env_list[@]} ; do
				if [ -e "${LICHEE_CHIP_CONFIG_DIR}/$d/$file" ]; then
					copy_env_file=${LICHEE_CHIP_CONFIG_DIR}/$d/$file
				fi
			done
		done
		echo "Use u-boot env file: ${copy_env_file}"
		if [[ ! -f ${copy_env_file} ]]
		then
			echo -e "\e[33mWarning: u-boot env file '${copy_env_file}' not exist! use file in default directory other than '${PACK_BOARD}' directory\e[0m"
		fi

		cp -f ${copy_env_file} ${LICHEE_PACK_OUT_DIR}/env.cfg 2>/dev/null

		cp -f ${LICHEE_CHIP_CONFIG_DIR}/configs/${PACK_BOARD}/${LICHEE_KERN_VER}/sys_* ${LICHEE_PACK_OUT_DIR} 2>/dev/null
	fi

	# If platform config files exist, we will cover the default files
	# For example, mv pack_out/image_linux.cfg pack_out/image.cfg
	if [ ${PACK_PLATFORM} != "android" ]; then
		cp -f ${LICHEE_BOARD_CONFIG_DIR}/${PACK_PLATFORM}/* ${LICHEE_PACK_OUT_DIR} 2> /dev/null
		if [ ${PACK_PLATFORM} = "bsp" -o "x${PACK_PLATFORM}" = "xsata" ] ; then
			find ${LICHEE_PACK_OUT_DIR}/* -type f -a \( -name "*.fex" -o -name "*.cfg" \) -print | \
			sed "s#\(.*\)_linux\(\..*\)#mv -fv & \1\2#e"
		else
			find ${LICHEE_PACK_OUT_DIR}/* -type f -a \( -name "*.fex" -o -name "*.cfg" \) -print | \
			sed "s#\(.*\)_${PACK_PLATFORM}\(\..*\)#mv -fv & \1\2#e"
		fi
	else
		find ${LICHEE_PACK_OUT_DIR}/* -type f -a \( -name "*.fex" -o -name "*.cfg" \) -print | \
			sed "s#\(.*\)_${PACK_TYPE}\(\..*\)#mv -fv & \1\2#e"
	fi

	if [ "x${PACK_MODE}" = "xdump" ] ; then
		cp -vf ${LICHEE_PACK_OUT_DIR}/sys_partition_dump.fex ${LICHEE_PACK_OUT_DIR}/sys_partition.fex
		cp -vf ${LICHEE_PACK_OUT_DIR}/usbtool_test.fex ${LICHEE_PACK_OUT_DIR}/usbtool.fex
	elif [ "x${PACK_FUNC}" = "xprvt" ] ; then
		cp -vf ${LICHEE_PACK_OUT_DIR}/sys_partition_private.fex ${LICHEE_PACK_OUT_DIR}/sys_partition.fex
	fi

	printf "copying boot resource\n"
	for file in ${boot_resource_list[@]} ; do
		cp -rf $(echo $file | sed -e 's/:/ /g') 2>/dev/null
	done

	# openwrt use these logo files
	if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
		rm -rf ${LICHEE_PACK_OUT_DIR}/boot-resource
		cp -rf $CFG_TOP_DIR/${PACK_PLATFORM}/target/$PACK_IC/$PACK_IC-common/boot-resource/boot-resource ${LICHEE_PACK_OUT_DIR}
		cp -rf $CFG_TOP_DIR/${PACK_PLATFORM}/target/$PACK_IC/$PACK_IC-common/boot-resource/boot-resource.ini ${LICHEE_PACK_OUT_DIR}/boot-resource.ini
	fi

	if [ ! -f ${LICHEE_PACK_OUT_DIR}/bootlogo.bmp ]; then
		cp ${LICHEE_PACK_OUT_DIR}/boot-resource/bootlogo.bmp ${LICHEE_PACK_OUT_DIR}/bootlogo.bmp
	fi

	lzma -k ${LICHEE_PACK_OUT_DIR}/bootlogo.bmp
	lzma -k ${LICHEE_PACK_OUT_DIR}/bempty.bmp
	lzma -k ${LICHEE_PACK_OUT_DIR}/battery_charge.bmp

	if [ -f ${LICHEE_PACK_OUT_DIR}/bootlogo.bmp.lzma ]; then
		add_lzma_header "${LICHEE_PACK_OUT_DIR}/bootlogo.bmp.lzma" "${LICHEE_PACK_OUT_DIR}/bootlogo.bmp"
		(cd ${LICHEE_PACK_OUT_DIR}; ln -sf bootlogo.bmp.lzma.head  bootlogo.fex)
	fi

	printf "copying boot file\n"
	for d in ${possible_bin_path[@]}; do
		[ ! -d ${LICHEE_CHIP_CONFIG_DIR}/$d ] && continue
		BIN_PATH=$d
		for file in ${boot_file_list[@]} ; do
			eval cp -v -f $(echo $file | sed -e 's/:/ /g') 2>/dev/null
		done
	done
	printf "copying boot file 2.0\n"
	for file in ${boot_file_list_2[@]} ; do
		eval cp -v -f $(echo $file | sed -e 's/:/ /g') 2>/dev/null
	done
	if [[ ${LICHEE_BOARD} == *fastboot*spinand* ]] ; then
		mv -v ${LICHEE_PACK_OUT_DIR}/boot0_nandfastboot_${PACK_CHIP}.fex ${LICHEE_PACK_OUT_DIR}/boot0_nand.fex
	fi

	if ! [ -z ${LICHEE_BOOT0_BIN_NAME} ]; then
	    echo 1111111111111111111111111111111111111
                # nand fastboot
#                cp -v -f ${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex ${LICHEE_PACK_OUT_DIR}/boot0_nand.fex

#		if [[ ${LICHEE_FLASH} == default ]] ; then
#			mv -v ${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex ${LICHEE_PACK_OUT_DIR}/boot0_sdcard.fex
#		elif [[ ${LICHEE_FLASH} == nor ]] ; then
#			mv -v ${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex ${LICHEE_PACK_OUT_DIR}/boot0_spinor.fex
#		else
#			echo "invalid LICHEE_FLASH, default choose sdcard!"
#			mv -v ${LICHEE_PACK_OUT_DIR}/boot0_${LICHEE_BOOT0_BIN_NAME}.fex ${LICHEE_PACK_OUT_DIR}/boot0_sdcard.fex
#		fi
	fi

	[ -z "${BIN_PATH}" ] &&
	pack_error "No BIN_PATH found!" && exit 1

	printf "copying $LICHEE_ARCH secure boot file\n"
	for d in ${possible_bin_path[@]}; do
		[ ! -d ${LICHEE_CHIP_CONFIG_DIR}/$d ] && continue
		BIN_PATH=$d
		for file in $(eval echo '$'"{${LICHEE_ARCH}_boot_file_secure[@]}"); do
			eval cp -f $(echo $file | sed -e 's/:/ /g') 2>/dev/null
		done
	done

	# If platform config use
	if [ -f ${LICHEE_CHIP_CONFIG_DIR}/tools/plat_config.sh ] ; then
		${LICHEE_CHIP_CONFIG_DIR}/tools/plat_config.sh
	fi

	if [ "x${PACK_NOR}" = "xnor" ] ; then
		cp -vf ${LICHEE_PACK_OUT_DIR}/image_nor.cfg ${LICHEE_PACK_OUT_DIR}/image.cfg
		cp -vf ${LICHEE_PACK_OUT_DIR}/sboot_nor.bin ${LICHEE_PACK_OUT_DIR}/sboot.bin
		cp -vf ${LICHEE_PACK_OUT_DIR}/dragon_toc_nor.cfg ${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
	fi

	if [ "x${PACK_VSP}" = "xvsp" ] ; then
		printf "change usb_port_type to device...\n"
		printf "disable usb_serial_unique...\n"
		printf "change usb_serial_number to ${PACK_TYPE}_android...\n"
		sed -i 's/^usb_port_type.*/usb_port_type = 0/g' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		sed -i 's/^usb_serial_unique.*/usb_serial_unique = 0/g' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		sed -i 's/^usb_serial_number.*/usb_serial_number = "'"${PACK_CHIP}"'_android"/g' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	fi

	printf "copying additional files\n"
	for file in ${PACK_ADD_FILES[@]}; do
		cp -vf $(echo $file | sed -e 's/:/ /g') 2>/dev/null
	done

	if [ "x${PACK_PLATFORM}" == "xandroid" ] && [ "x$TARGET_BUILD_VARIANT" == "xuser" ]; then
		pack_info "change kernel loglevel to 3 for android user build"
		sed -i 's|^\s*loglevel=[0-9]\s*$|loglevel=3|g' ${LICHEE_PACK_OUT_DIR}/env.cfg
		if [ "${ENABLE_VENDOR_ADB}" == "true" ]; then
			pack_info "enable vendor adb for android user build"
			sed -i 's|^init_rc=.*$|init_rc=/vendor/etc/init/hw/init.aw.rc|g' ${LICHEE_PACK_OUT_DIR}/env.cfg
		fi
	fi

	if [ "x${PACK_PROGRAMMER}" = "xprogrammer" ]; then
		printf "add programmer img info target in sys config\n"
		sed -i -e '/^\[target\]/a\programmer=1' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	fi

	sed -i 's/\\boot-resource/\/boot-resource/g' ${LICHEE_PACK_OUT_DIR}/boot-resource.ini
	sed -i 's/\\\\/\//g' ${LICHEE_PACK_OUT_DIR}/image.cfg
	sed -i 's/^imagename/;imagename/g' ${LICHEE_PACK_OUT_DIR}/image.cfg

	prepare_mixed_androiddragonboard
	[ $? -ne 0 ] && exit 1

	partition_size_handle
	[ $? -ne 0 ] && exit 1

	if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
		cd ${LICHEE_PACK_OUT_DIR}/
		echo "vmlinux" > ${LICHEE_PACK_OUT_DIR}/vmlinux.fex
		if [ "x${PACK_NOR}" = "xnor" ] ; then
			make_user_res sys_partition_nor.fex
			make_app_res sys_partition_nor.fex
			make_data_res sys_partition_nor.fex
		else
			make_user_res sys_partition.fex
			make_app_res sys_partition.fex
			make_data_res sys_partition.fex
		fi
		cd - > /dev/null
	fi
}

function img_to_programmer()
{
	local out_img=$1
	local in_img=$2

	cd ${LICHEE_PACK_OUT_DIR}/

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		if [ -f toc0_sdcard.fex ] ; then
			programmer_img toc0_sdcard.fex toc1.fex ${out_img} > /dev/null
		elif [ -f toc0_nand.fex ] ; then
			programmer_img toc0_nand.fex toc1.fex ${out_img} > /dev/null
		else
			programmer_img toc0.fex toc1.fex ${out_img} > /dev/null
		fi
	else
		programmer_img boot0_sdcard.fex boot_package.fex ${out_img} > /dev/null
	fi

	if [ -f sunxi_gpt.fex ] ; then
		#create_img for sunxi_gpt.fex
		programmer_img sys_partition.bin sunxi_mbr.fex ${out_img} ${in_img} sunxi_gpt.fex > /dev/null
	else
		#create_img for sunxi_mbr.fex
		programmer_img sys_partition.bin sunxi_mbr.fex ${out_img} ${in_img} > /dev/null
	fi

}

function uboot_ini_to_dts()
{
	local TARGET_UBOOT
	local PLATFORM_ADDR
	local SOC_ADDR
	local DTC_FLAGS=""

	if [ x${LICHEE_BRANDY_UBOOT_VER} == x2023 ]; then
		pack_info "skip split fdt"
		return
	fi

	if [ "x${PACK_NOR}" == "xnor" ]; then
		TARGET_UBOOT=${LICHEE_PACK_OUT_DIR}/u-boot-spinor.fex
	else
		TARGET_UBOOT=${LICHEE_PACK_OUT_DIR}/u-boot.fex
	fi
	sunxi_ubootools split ${TARGET_UBOOT} > /dev/null
	if [ $? -ne 0 ]
	then
		pack_warn "split uboot and fdt failed!!"
		return
	fi

	[ "$(readlink -f .)" != "$(readlink -f ${LICHEE_PACK_OUT_DIR})" ] && {
		mv temp_fdt.dtb  ${LICHEE_PACK_OUT_DIR}
		mv temp_ubootnodtb.bin  ${LICHEE_PACK_OUT_DIR}
	}

	# to dts
	$DTC_COMPILER ${DTC_FLAGS} -I dtb -O dts -o ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp ${LICHEE_PACK_OUT_DIR}/temp_fdt.dtb  2>/dev/null

	PLATFORM_ADDR=`grep -Po "(?<=platform@)(\w+)(?=\s*{)" ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp | head -1`
	SOC_ADDR=`grep -Po "(?<=soc@)(\w+)(?=\s*{)" ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp | head -1`

	if [ "x${PACK_TYPE}" = "xdragonboard" -o "x${PACK_TYPE}" = "xdragonabts" ] ; then
		cat <<- EOF >> ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp
		/{
			soc@${SOC_ADDR} {
				platform@${PLATFORM_ADDR} {
				dragonboard_test = <1>;
				};
			};
		};
		EOF
	fi

	# to dtb
	$DTC_COMPILER ${DTC_FLAGS} -I dts -O dtb -o ${LICHEE_PACK_OUT_DIR}/temp_fdt.dtb ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp  2>/dev/null

	# get update_to_ubootfdt value from sysconfig
	sunxi_ubootools subkey_value sys_config.bin sunxi_ubootools update_to_ubootfdt > /dev/null
	if [ $? -eq 1 ]; then
		echo "uboot ini to dts"
		$DTC_COMPILER -p 2048 ${DTC_FLAGS} -@ -O dtb -o ${LICHEE_PACK_OUT_DIR}/new_fdt.dtb	\
			-b 0			\
			-i ${LICHEE_PACK_OUT_DIR}	\
			-F $DTC_INI_FILE \
			-d ${LICHEE_PACK_OUT_DIR}/temp_fdt.dtb ${LICHEE_PACK_OUT_DIR}/.uboot.dtb.dts.tmp 2>/dev/null
	else
		mv ${LICHEE_PACK_OUT_DIR}/temp_fdt.dtb  ${LICHEE_PACK_OUT_DIR}/new_fdt.dtb
	fi

	sunxi_ubootools merge ${LICHEE_PACK_OUT_DIR}/temp_ubootnodtb.bin ${LICHEE_PACK_OUT_DIR}/new_fdt.dtb > /dev/null
	cp -vf ${LICHEE_PACK_OUT_DIR}/temp_ubootnodtb.bin ${TARGET_UBOOT}
	# .uboot.dts is the last dts of uboot
	$DTC_COMPILER ${DTC_FLAGS} -I dtb -O dts -o ${LICHEE_PACK_OUT_DIR}/.uboot.dts ${LICHEE_PACK_OUT_DIR}/new_fdt.dtb 2>/dev/null
}

function do_ini_to_dts()
{
	cd ${LICHEE_PACK_OUT_DIR}/

	maybe_busybox unix2dos sys_config.fex
	script  sys_config.fex > /dev/null

	local DTC_SRC_PATH=${LICHEE_PLAT_OUT}
	local DTC_COMPILER=${LICHEE_PLAT_OUT}/dtc
	local DTC_FLAGS=""

	uboot_ini_to_dts

	if [ "x${PACK_KERN}" == "xlinux-3.4" \
			-o "x${PACK_KERN}" == "xlinux-3.10" \
			-o "x${PACK_KERN}" == "xlinux-4.4" \
			-o "x${PACK_KERN}" == "xlinux-5.4" \
			-o "x${PACK_KERN}" == "xlinux-5.4-ansc" \
			-o "x${PACK_KERN}" == "xlinux-5.10" \
			-o "x${PACK_KERN}" == "xlinux-5.10-origin" \
			-o "x${PACK_KERN}" == "xlinux-5.15" \
			-o "x${PACK_KERN}" == "xlinux-5.15-origin" ] || [[  ${PACK_KERN/linux-} > 5.15 ]]; then
		# For debug: sunxi.dtb -> .sunxi.dts
		$DTC_COMPILER ${DTC_FLAGS} -I dtb -O dts -o ${LICHEE_PLAT_OUT}/.sunxi.dts ${LICHEE_PLAT_OUT}/sunxi.dtb 2>/dev/null
		return
	fi

	local dtc_file_list=(
		.board.dtb.d.dtc.tmp:.board.dtb.dts.tmp
		.${PACK_CHIP}-${PACK_BOARD}.dtb.d.dtc.tmp:.${PACK_CHIP}-${PACK_BOARD}.dtb.dts.tmp
		.${PACK_CHIP}-${LICHEE_BUSSINESS}.dtb.d.dtc.tmp:.${PACK_CHIP}-${LICHEE_BUSSINESS}.dtb.dts.tmp
		.${PACK_CHIP}-soc.dtb.d.dtc.tmp:.${PACK_CHIP}-soc.dtb.dts.tmp)

	local DTC_INI_FILE_BASE=${LICHEE_PACK_OUT_DIR}/sys_config.fex
	local DTC_INI_FILE=${LICHEE_PACK_OUT_DIR}/sys_config_fix.fex

	cp $DTC_INI_FILE_BASE $DTC_INI_FILE
	sed -i "s/\(\[dram\)_para\(\]\)/\1\2/g" $DTC_INI_FILE
	sed -i "s/\(\[nand[0-9]\)_para\(\]\)/\1\2/g" $DTC_INI_FILE

	if [ ! -f $DTC_COMPILER ]; then
		pack_error "Script_to_dts: Can not find dtc compiler.\n"
		exit 1
	fi

	local DTC_DEP_FILE DTC_SRC_FILE
	for e in ${dtc_file_list[@]}; do
		DTC_DEP_FILE=$DTC_SRC_PATH/${e/:*}
		if [ -f $DTC_DEP_FILE ]; then
			DTC_SRC_FILE=$DTC_SRC_PATH/${e#*:}
			break
		fi
	done

	echo "sunxi_dtb create"
	$DTC_COMPILER -p 2048 ${DTC_FLAGS} -@ -O dtb -o ${LICHEE_PLAT_OUT}/sunxi.dtb	\
		-b 0			\
		-i $DTC_SRC_PATH	\
		-F $DTC_INI_FILE	\
		-d $DTC_DEP_FILE $DTC_SRC_FILE 2>/dev/null

	if [ $? -ne 0 ]; then
		pack_error "Conver script to dts failed"
		exit 1
	fi

	#restore the orignal dtsi
	if [ "x${PACK_TYPE}" = "xdragonboard" \
		-o "x${PACK_TYPE}" = "xdragonmat" ]; then
		local DTS_PATH=${LICHEE_KERN_DIR}/arch/${LICHEE_ARCH}/boot/dts
		[ "x${LICHEE_ARCH}" = "xarm64" ] && DTS_PATH=${LICHEE_KERN_DIR}/arch/${LICHEE_ARCH}/boot/dts/sunxi
		if [ -f ${DTS_PATH}/${PACK_CHIP}_bak.dtsi ];then
			rm -f ${DTS_PATH}/${PACK_CHIP}.dtsi
			mv  ${DTS_PATH}/${PACK_CHIP}_bak.dtsi  ${DTS_PATH}/${PACK_CHIP}.dtsi
		fi
	fi

	printf "Conver script to dts ok.\n"

	# It'is used for debug dtb
	$DTC_COMPILER ${DTC_FLAGS} -I dtb -O dts -o ${LICHEE_PLAT_OUT}/.sunxi.dts ${LICHEE_PLAT_OUT}/sunxi.dtb 2>/dev/null

	return
}

function maybe_busybox()
{
	if [ "x$(which busybox)" == "x" ]; then
		pack_error "Tool busybox does not exist!"
		exit 1
	fi

	busybox $@ || $@
}

function generate_env_for_uboot()
{
	printf "$1 Conver to $2.\n"
	printf "LICHEE_BRANDY_UBOOT_VER : ${LICHEE_BRANDY_UBOOT_VER}\n"
	if [ -n "${LICHEE_BRANDY_UBOOT_VER}" ] && [ ${LICHEE_BRANDY_UBOOT_VER} -ge 2023 ]; then
		printf "create env.fex for uboot2023 or later, size 128K\n"
		# mkenvimage -p 0x00 -s 0x20000 -o env.fex env.cfg
		mkenvimage -p 0x00 -s 0x20000 -o $2 $1
	else
		# u_boot_env_gen env_nor.cfg env_nor.fex >/dev/null
		u_boot_env_gen $1 $2 >/dev/null
	fi
}

function do_common()
{
	cd ${LICHEE_PACK_OUT_DIR}/

	echo $(date -d "$ts" +"%Y-%m-%d %H:%M:%S") > ${LICHEE_PACK_OUT_DIR}/sunxi_version.fex

	# Here, we can switch uart to card or normal
	if [ "x${PACK_DEBUG}" = "xcard0" -a "x${PACK_MODE}" != "xdump" \
		-a "x${PACK_FUNC}" != "xprvt" ] ; then \
		uart_switch
	else
		sed -i -e '/^auto_print_used/s\1\0\' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
	fi

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		printf "add burn_secure_mode in target in sys config\n"
		sed -i -e '/^\[target\]/a\burn_secure_mode=1' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		sed -i -e '/^\[platform\]/a\secure_without_OS=0' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		if [ -f ${LICHEE_PACK_OUT_DIR}/optee-monitor.fex ]; then
			rm -f ${LICHEE_PACK_OUT_DIR}/optee-monitor.fex
		fi
	else
		sed -i '/^burn_secure_mod/d' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		sed -i '/^secure_without_OS/d' ${LICHEE_PACK_OUT_DIR}/sys_config.fex
		if [ -f ${LICHEE_PACK_OUT_DIR}/optee-monitor.fex ]; then
			mv -v ${LICHEE_PACK_OUT_DIR}/optee-monitor.fex ${LICHEE_PACK_OUT_DIR}/optee.fex
		fi
	fi

	if [ ! -f board_config.fex ]; then
		echo "[empty]" > board_config.fex
	fi

	maybe_busybox unix2dos sys_config.fex
	maybe_busybox unix2dos board_config.fex
	script  sys_config.fex > /dev/null
	cp -f   sys_config.bin config.fex
	script  board_config.fex > /dev/null
	cp -f board_config.bin board.fex

	maybe_busybox unix2dos sys_partition.fex
	script  sys_partition.fex > /dev/null


	if [ "x${PACK_TYPE}" = "xdragonboard" ] ; then
		maybe_busybox dos2unix test_config.fex
		cp test_config.fex boot-resource/
		maybe_busybox unix2dos test_config.fex
		script test_config.fex > /dev/null
		cp test_config.bin boot-resource/
	fi

	if [ "x${PACK_TYPE}" = "xdragonabts" ] ; then
		maybe_busybox dos2unix test_config.fex
		cp test_config.fex boot-resource/
		maybe_busybox unix2dos test_config.fex
		script test_config.fex > /dev/null
		cp test_config.bin boot-resource/
	fi
	# Those files for SpiNor. We will try to find sys_partition_nor.fex
	if [ "x${PACK_NOR}" = "xnor" ] ; then

		if [ ! -f sys_partition_nor.fex ];  then
			echo "sys partition for nor not exist"
			exit 1
		fi

		if [ ! -f ${LICHEE_CHIP_CONFIG_DIR}/tools/arisc_config_parse.sh ]; then
			if [ -f "scp.fex" ]; then
				echo "update scp"
				update_scp scp.fex sunxi.fex >/dev/null
			fi
		fi

		# Here, will create sys_partition_nor.bin
		maybe_busybox unix2dos sys_partition_nor.fex
		script  sys_partition_nor.fex > /dev/null
		update_boot0 boot0_spinor.fex   sys_config.bin SPINOR_FLASH > /dev/null
		update_chip boot0_spinor.fex   > /dev/null
		update_fes1  fes1.fex           sys_config.bin > /dev/null

		if [ "x${PACK_KERN}" = "xlinux-3.4" ] ; then
			update_uboot -merge u-boot-spinor.fex  sys_config.bin > /dev/null
		else
			update_uboot -no_merge u-boot-spinor.fex  sys_config.bin > /dev/null
			update_uboot -no_merge u-boot-spinor-secure.fex  sys_config.bin > /dev/null
			[ -f u-boot-efex.fex ] && {
				update_uboot -no_merge u-boot-efex.fex  sys_config.bin > /dev/null
			}
		fi

		while read line
		do
			compress_name=(`echo $line | awk '($1 !~ ";" && ($2 ~ "lzma" || $2 ~ "lz4" || $2 ~ "gz")) {print $2}'`)
			source_name=(`echo $compress_name | cut -d \.  -f 1,2 | cut -d \  -f 2`)
			compress_type=(`echo $compress_name | cut -d \.  -f 3 | cut -d \  -f 2`)
			[ -z "$compress_name" ] && continue
			case $compress_type in
			"gz")
				[ -f $source_name ] && gzip -c $source_name > $compress_name || echo "no exist $source_name"
				echo "compress name: $compress_name"
				;;
			"lzma")
				[ -f $source_name ] && lzma -k $source_name || echo "no exist $source_name"
				mv $source_name.lzma $compress_name >/dev/null 2<&1
				echo "compress name: $compress_name"
				;;
			"lz4")
				[ -f $source_name ] && lz4 -f $source_name $compress_name || echo "no exist $source_name"
				echo "compress name: $compress_name"
				;;
			*)
				echo "no match compress type"
				;;
			esac
			echo "compress type: $compress_type"
		done < boot_package_nor.cfg

		if [ -f boot_package_nor.cfg ]; then
			mv u-boot-spinor-crash.fex u-boot-crash.fex
			echo "pack boot package"
			maybe_busybox unix2dos boot_package.cfg
			dragonsecboot -pack boot_package_nor.cfg
			cp boot_package.fex boot_package_nor.fex
		fi
		# Ugly, but I don't have a better way to change it.
		# We just set env's downloadfile name to env_nor.cfg in sys_partition_nor.fex
		# And if env_nor.cfg is not exist, we should copy one.
		if [ ! -f env_nor.cfg ]; then
			cp -f env.cfg env_nor.cfg >/dev/null 2<&1
		fi

		#card sprite
		if [ -f "boot0_sdcard.fex" ]; then
		    echo 22222222222222222222222222222222222222
			#update_boot0 boot0_sdcard.fex   sys_config.bin SDMMC_CARD > /dev/null
			#update_chip boot0_sdcard.fex > /dev/null
		fi

		# Fixup boot mode for SPINor, just can bootm
		sed -i '/^boot_normal/s#\<boota\>#bootm#g' env_nor.cfg

		echo 1:LICHEE_REDUNDANT_ENV_SIZE:$LICHEE_REDUNDANT_ENV_SIZE
		if [ "x${LICHEE_REDUNDANT_ENV_SIZE}" != "x" ]; then
			echo "--mkenvimage create redundant env data!--"
			echo "--redundant nor env data size ${LICHEE_REDUNDANT_ENV_SIZE}---"
			mkenvimage -r -p 0x00 -s ${LICHEE_REDUNDANT_ENV_SIZE} -o env_nor.fex env_nor.cfg
		else
			generate_env_for_uboot env_nor.cfg env_nor.fex
		fi
	else
	echo 333333333333333333333333333333333333333333
		#update_boot0 boot0_nand.fex     sys_config.bin NAND > /dev/null
		#update_boot0 boot0_sdcard.fex   sys_config.bin SDMMC_CARD > /dev/null
		#update_boot0 boot0_ufs.fex   sys_config.bin UFS > /dev/null
		#update_chip boot0_nand.fex >/dev/null
		#update_chip boot0_sdcard.fex >/dev/null
		#update_chip boot0_ufs.fex >/dev/null
	fi

	if [ ! -f "u-boot-crash.fex" ]; then
		touch "u-boot-crash.fex"
		echo "ensure u-boot-crash.fex is not empty" > u-boot-crash.fex
	fi

	if [ -f "sunxi.fex" ]; then
		update_dtb sunxi.fex 4096
	fi

	if [ ! -f ${LICHEE_CHIP_CONFIG_DIR}/tools/arisc_config_parse.sh ]; then
		if [ -f "scp.fex" ]; then
			echo "update scp"
			update_scp scp.fex sunxi.fex >/dev/null
		fi
	fi

	if [ -f "optee.fex" ]; then
		echo "update optee"
		update_optee optee.fex sunxi.fex >/dev/null
	fi

	# Those files for Nand or Card
	if [ "x${PACK_KERN}" = "xlinux-3.4" ] ; then
		update_uboot -merge u-boot.fex sys_config.bin > /dev/null
	else
		update_uboot -no_merge u-boot.fex sys_config.bin > /dev/null
		[ -f u-boot-nodtb.fex ] && {
			update_uboot -no_merge u-boot-nodtb.fex sys_config.bin > /dev/null
		}
		[ -f u-boot-efex.fex ] && {
			update_uboot -no_merge u-boot-efex.fex  sys_config.bin > /dev/null
		}
	fi

	if [ -f "fes1_uart.fex" ]; then
		update_fes1  fes1_uart.fex           sys_config.bin > /dev/null
	fi

	update_fes1  fes1.fex           sys_config.bin > /dev/null
	if [ -f ${LICHEE_TOOLS_DIR}/pack/pctools/linux/mod_update/update_sboot ];then
		update_sboot sboot.bin  sys_config.bin  > /dev/null
		if [ $? -ne 0 ]
		then
			pack_error "update sboot run error"
			exit 1
		fi
	fi
	fsbuild      boot-resource.ini  split_xxxx.fex > /dev/null

	if [ -f boot_package_uartburn.cfg ]; then
		dragonsecboot -pack boot_package_uartburn.cfg
		if [ $? -ne 0 ]
		then
			pack_error "dragon pack boot_package_uartburn run error"
			exit 1
		fi
		mv boot_package.fex boot_package_uartburn.fex
	fi

	if [ -f boot_package.cfg ]; then
		if [ "x$LINUX_DTBO_FILE" = "x" ]; then
			echo "do not set LINUX_DTBO_FILE"
			line_num=`sed -n -e "/default.dtbo/=" boot_package.cfg`
			if [ "x$line_num" != "x" ]; then
				sed -i "$line_num s/^/;/g" boot_package.cfg
			fi
		else
			if [ -f $LINUX_DTBO_FILE ]
			then
				sed -i "s/default.dtbo/$LINUX_DTBO_FILE/g" boot_package.cfg
			else
				line_num=`sed -n -e "/default.dtbo/=" boot_package.cfg`
				if [ "x$line_num" != "x" ]; then
					sed -i "$line_num s/^/;/g" boot_package.cfg
				fi
			fi
		fi

			echo "pack boot package"
			maybe_busybox unix2dos boot_package.cfg
			dragonsecboot -pack boot_package.cfg

		if [ $? -ne 0 ]
		then
			pack_error "dragon pack run error"
			exit 1
		fi
	fi

	echo 2:LICHEE_REDUNDANT_ENV_SIZE:$LICHEE_REDUNDANT_ENV_SIZE
	if [ "x${PACK_FUNC}" = "xprvt" ] ; then
		if [ "x${LICHEE_REDUNDANT_ENV_SIZE}" != "x" ]; then
			echo "--mkenvimage create redundant env data!--"
			echo "--redundant env data size ${LICHEE_REDUNDANT_ENV_SIZE}---"
			mkenvimage -r -p 0x00 -s ${LICHEE_REDUNDANT_ENV_SIZE} -o env.fex env_burn.cfg
		else
			generate_env_for_uboot env_burn.cfg env.fex
		fi
	else
		if [ "x${LICHEE_REDUNDANT_ENV_SIZE}" != "x" ]; then
			echo "--mkenvimage create redundant env data!--"
			echo "--redundant env data size ${LICHEE_REDUNDANT_ENV_SIZE}---"
			mkenvimage -r -p 0x00 -s ${LICHEE_REDUNDANT_ENV_SIZE} -o env.fex env.cfg
		else
			generate_env_for_uboot env.cfg env.fex
		fi
	fi

	dmverity_deal clean

}

function do_finish()
{
	# Yeah, it should contain all files into full_img.fex for spinor
	# Because, as usually, spinor image size is very small.
	# If fail to create full_img.fex, we should fake it empty.

	# WTF, it is so ugly!!! It must be sunxi_mbr.fex & sys_partition.bin,
	# not sunxi_mbr_xxx.fex & sys_partition_xxx.bin. In order to advoid this
	# loathsome thing, we need to backup & copy files. Check whether
	# sys_partition_nor.bin is exist, and create sunxi_mbr.fex for Nor.
	local max_toc_size=2097152

	local IMG_NAME="${PACK_IC}_${PACK_TYPE}${PACK_PLATFORM_VERSION}_${PACK_BOARD}_${PACK_DEBUG}"
	if [ "x${PACK_MODE}" = "xdump" ] ; then
		IMG_NAME="${IMG_NAME}_${PACK_MODE}"
	fi

	if [ "x${PACK_FUNC}" = "xprvt" ]; then
		IMG_NAME="${IMG_NAME}_${PACK_FUNC}"
	fi

	if [ "x${PACK_SECURE}" = "xsecure" ] ; then
		IMG_NAME="${IMG_NAME}_${PACK_SECURE}"
	fi

	if [ "x${PACK_FUNC}" = "xprev_refurbish" ] ; then
		IMG_NAME="${IMG_NAME}_${PACK_FUNC}"
	fi

	if [ "x${PACK_NOR}" = "xnor" ] ; then
		IMG_NAME="${IMG_NAME}_${PACK_NOR}"
	fi

	if [ "x${PACK_SECURE}" != "xnone" ]; then
		local MAIN_VERION=$(readcfg dragon_toc.cfg rollback_ver ver)
		if [ ! -n "${MAIN_VERION}" ]; then
			local MAIN_VERION="$(echo '__unique:;@echo ${MAIN_VERSION}' | make -f - -f ${LICHEE_PACK_OUT_DIR}/version_base.mk --no-print-directory __unique)"
		fi
		IMG_NAME="${IMG_NAME}_v${MAIN_VERION}.img"
	else
		IMG_NAME="${IMG_NAME}.img"
	fi

	local IMG_PROGRAMMER_NAME="${IMG_NAME%.*}_programmer.img"

	echo "imagename = $IMG_NAME" >> ${LICHEE_PACK_OUT_DIR}/image.cfg
	echo "" >> ${LICHEE_PACK_OUT_DIR}/image.cfg

	local imagesize
	local toc_size
	local max_toc_size=3883264

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		toc_size=`stat toc1.fex --format="%s"`
	else
		toc_size=`stat boot_package.fex --format="%s"`
	fi

	if [ "$LICHEE_CHIP" == "sun55iw3p1" ]; then
		max_toc_size=3883264
	fi

	if [ ${toc_size} -gt ${max_toc_size} ];then
		pack_error "boot_package.fex/toc1.fex More than ${max_toc_size} bytes limit too large!!!"
		exit 1
	fi

	if [ "x${PACK_NOR}" = "xnor" ] ; then
		NOR_LOGIC_START=2016
		NOR_UBOOT_START=128
		NOR_FLASH_SIZE=65536 #32M
		NOR_LOGIC_START_KB=`expr ${NOR_LOGIC_START} / 2`
		NOR_UBOOT_START_KB=`expr ${NOR_UBOOT_START} / 2`

		local uboot_dts=""
		if [ -n "${LICHEE_BRANDY_UBOOT_VER}" ] && [ ${LICHEE_BRANDY_UBOOT_VER} -ge 2023 ]; then
			uboot_dts="${LICHEE_BOARD_CONFIG_DIR}/uboot-${LICHEE_BRANDY_UBOOT_VER}/uboot-board.dts"
		else
			uboot_dts="${LICHEE_BOARD_CONFIG_DIR}/uboot-board.dts"
		fi

		if [ -f ${uboot_dts} ] && [ x"$(grep "nor_map" ${uboot_dts})" != x"" ]; then
			echo "get flashmap from ${uboot_dts}"
			NOR_FLASH_SIZE=$(awk '/nor_map {/,/}/ {print NR ": " $0}' ${uboot_dts} \
				| grep  "\bflash_size\b" | grep -oP "(?<=\<)\d+(?=\>)")

			NOR_LOGIC_START=$(awk '/nor_map {/,/}/ {print NR ": " $0}' ${uboot_dts} \
				| grep  "\blogic_offset\b" | grep -oP "(?<=\<)\d+(?=\>)")

			NOR_UBOOT_START=$(awk '/nor_map {/,/}/ {print NR ": " $0}' ${uboot_dts} \
				| grep  "\buboot_start\b" | grep -oP "(?<=\<)\d+(?=\>)")

			[ x"${NOR_FLASH_SIZE}" = x"" -o x"${NOR_LOGIC_START}" = x"" -o x"${NOR_UBOOT_START}" = x"" ] && {
				pack_warn "flash_size,logic_offset,uboot_start maybe not set in uboot-board.dts"
				NOR_LOGIC_START=2016
				NOR_UBOOT_START=128
				NOR_FLASH_SIZE=65536 #32M
			}

			NOR_LOGIC_START_KB=`expr ${NOR_LOGIC_START} / 2`
			NOR_UBOOT_START_KB=`expr ${NOR_UBOOT_START} / 2`
			echo "flash size:${NOR_FLASH_SIZE}, logic start:${NOR_LOGIC_START}, uboot start:${NOR_UBOOT_START}"
		fi

		update_mbr sys_partition_nor.bin 1 sunxi_mbr_nor.fex dlinfo.fex \
				${NOR_FLASH_SIZE} ${NOR_LOGIC_START} 1

		if [ $? -ne 0 ]; then
			pack_error "update_mbr failed"
			exit 1
		fi
		echo '----------programmer nor image is full_img.fex ----------'
		if [ "x${PACK_KERN}" = "xlinux-3.4" ] ; then
		#when use devicetree, the size of uboot+dtb is larger then 256K
			#BOOT1_FILE=u-boot-spinor.fex
			#LOGIC_START=240 #240+16=256K
			#merge_package full_img.fex boot0_spinor.fex \
			#        u-boot-spinor.fex sunxi_mbr_nor.fex sys_partition_nor.bin
			merge_full_img --out full_img.fex --boot0 boot0_spinor.fex --boot1 u-boot-spinor.fex \
							--mbr sunxi_mbr_nor.fex  --partition sys_partition_nor.bin \
							--logic_start 240 > /dev/null
		else
			merge_full_img --out full_img.fex --boot0 boot0_spinor.fex --boot1 boot_package_nor.fex \
				--mbr sunxi_gpt.fex --partition sys_partition_nor.bin \
				--logic_start ${NOR_LOGIC_START_KB} --uboot_start ${NOR_UBOOT_START_KB} > /dev/null
		fi

		if [ $? -ne 0 ]; then
			pack_error "merge_full_img failed"
			exit 1
		fi
		mv sys_partition_nor.fex sys_partition.fex
	fi

	if [ ! -f sys_partition_nor.bin ]; then
		update_mbr          sys_partition.bin 4
		if [ $? -ne 0 ]; then
			pack_error "update_mbr failed"
			exit 1
		fi

		#15269888 is from emmc datasheet, sec_count in Extended CSD is 0xe90000 = 15269888.
		#40960 is the mbr location for emmc
		#0  is emmc/nand ; 1 is spinor
		update_mbr sys_partition.bin 4 sunxi_mbr.fex dlinfo.fex 15269888 40960 0
		if [ $? -ne 0 ]; then
			pack_error "update_mbr_gpt failed"
			exit 1
		fi
	fi

	if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
		echo "===================================="
		echo "show sys_partition.fex message"
		show_partition_message sys_partition.fex
	fi

	local e cfgadd cfgget lastcfgline localfile filename
	local imgcfg_add_list=(
		# localfile             filename-in-cfg        maintype  subtype
		'vmlinux.fex            vmlinux.fex            12345678  123456789VMLINUX'
		'vendor_boot-debug.fex  vendor_boot-debug.fex  RFSFAT16  VENDOR_BOOTDEBUG'
		'dragon_toc.cfg         dragon_toc.fex         12345678  12345678DGTOCCFG'
		)

	for e in "${imgcfg_add_list[@]}"; do
		localfile="$(awk '{print $1}' <<< $e)"
		filename="$(awk '{print $2}' <<< $e)"
		maintype="$(awk '{print $3}' <<< $e)"
		subtype="$(awk '{print $4}' <<< $e)"
		cfgget="$(sed -n '/^\s*{\s*filename\s*=\s*"'$filename'"\s*,/p' image.cfg)"
		lastcfgline="$(sed -n '/^\s*{\s*filename\s*=/=' image.cfg | tail -1)"

		[ ! -f "$localfile" -o -n "$cfgget" -o -z "$lastcfgline" ] && continue
		[ "$localfile" != "$filename" ] && ln -sf $localfile $filename
		cfgadd='    {filename = "'$filename'",'
		cfgadd+='     maintype = "'$maintype'",'
		cfgadd+='     subtype  = "'$subtype'",},'
		sed -i -e  ''"${lastcfgline}"'a\' -e "$cfgadd" image.cfg
	done

	dragon image.cfg    sys_partition.fex
	if [ $? -eq 0 ]; then
		if [ -e ${IMG_NAME} ]; then
			mv ${IMG_NAME} $LICHEE_OUT_DIR/$LICHEE_IC/$LICHEE_BOARD/$LICHEE_LINUX_DEV/${IMG_NAME}
			rm -f $LICHEE_OUT_DIR/${IMG_NAME}
			ln -f $LICHEE_OUT_DIR/$LICHEE_IC/$LICHEE_BOARD/$LICHEE_LINUX_DEV/${IMG_NAME}  $LICHEE_OUT_DIR/${IMG_NAME}
			imagesize=$(du --apparent-size -sh $LICHEE_OUT_DIR/$LICHEE_IC/$LICHEE_BOARD/$LICHEE_LINUX_DEV/${IMG_NAME} | awk '{print $1}')
			echo '----------image is at----------'
			echo -e '\033[0;31;1m'
			echo -e "$imagesize\t${LICHEE_OUT_DIR}/${IMG_NAME}"
			echo -e '\033[0m'
		fi
	fi
	cd ..

	if [ "x${PACK_PROGRAMMER}" = "xprogrammer" ]; then
		if [ -f  $LICHEE_PACK_OUT_DIR/super.fex ]; then
			mv $LICHEE_PACK_OUT_DIR/super.fex $LICHEE_PACK_OUT_DIR/super.bak.fex
			simg2img  $LICHEE_PACK_OUT_DIR/super.bak.fex $LICHEE_PACK_OUT_DIR/super.fex
		fi
		echo "waiting to ceate programmer img..."
		img_to_programmer ${IMG_PROGRAMMER_NAME} $LICHEE_OUT_DIR/${LICHEE_IC}/${LICHEE_BOARD}/${LICHEE_LINUX_DEV}/${IMG_NAME}
		if [ $? -eq 0 ]; then
			if [ -e ${IMG_PROGRAMMER_NAME} ]; then
				mv $LICHEE_PACK_OUT_DIR/${IMG_PROGRAMMER_NAME} $LICHEE_OUT_DIR/${LICHEE_IC}/${LICHEE_BOARD}/${LICHEE_LINUX_DEV}/${IMG_PROGRAMMER_NAME}
				imagesize=$(du --apparent-size -sh $LICHEE_OUT_DIR/${LICHEE_IC}/${LICHEE_BOARD}/${LICHEE_LINUX_DEV}/${IMG_PROGRAMMER_NAME} | awk '{print $1}')
				echo '----------programmer image is at----------'
				echo -e '\033[0;31;1m'
				echo -e "$imagesize\t${LICHEE_OUT_DIR}/${IMG_PROGRAMMER_NAME}"
				echo -e '\033[0m'
			fi
		fi
	fi
	cd ..
	do_finish_SATA
	printf "pack finish\n"
	[ -e ${LICHEE_TOP_DIR}/build/.hooks/post-dragon ] &&
		source ${LICHEE_TOP_DIR}/build/.hooks/post-dragon
	return 0
}

function do_finish_SATA()
{
	if [ "x$BUILD_SATA" = "xtrue" ];then
		SATA_TAR=$LICHEE_TOP_DIR/SATA/linux/${LICHEE_CHIP}.tar
		if [ -f $SATA_TAR ];then
			echo '----------SATA is at----------'
			echo -e '\033[0;31;1m'
			echo $SATA_TAR
			echo -e '\033[0m'
		else
			echo PACK SATA failed!
		fi
	fi
}

function dmverity_deal()
{
	local script_name=scripts/build.sh
	local script_path=$LICHEE_KERN_DIR

	if [ ! -x $script_path/$script_name ]; then
		script_path=$LICHEE_BUILD_DIR
		script_name=mkkernel.sh
	fi

	[ ! -x $script_path/$script_name ] && return 255
	[ -z "$(grep "^\s*deal_verity)\s*$" $script_path/$script_name)" ] && return 1

	(cd $script_path && ./$script_name "deal_verity" $@)
}

function dmverity_get_blk_count()
{
	local size=`du --apparent-size -b $1 | awk '{print $1}'`
	local BLK_SIZE=$2

	if [ `expr ${size} % ${BLK_SIZE}` = "0" ]; then
			local blks=`(expr ${size} / ${BLK_SIZE})`
	else
			local blks=`(expr ${size} / ${BLK_SIZE} + 1 )`
	fi

	echo $blks
}

function dmverity_determ_blk_size()
{
	local type_info=`file -L $1`

	#check rootfs file system type to determ block size
	if [ "x""`echo ${type_info}| grep "ext4 filesystem"`" != "x" ];then
		block_size=`tune2fs -l $1|grep "Block size"|awk {'print $3'}`
		echo ${block_size}
	else
		echo "not support file system type"
		return -1
	fi

}
function dmverity_genHashTable()
{
	local fs_name=$1
	local tree_name=$2
	local table_name=$3
	local block_size=`dmverity_determ_blk_size ${fs_name}`
	if [ ${block_size} -lt 0 ];then
		return -1
	fi
	veritysetup format --data-block-size=${block_size} --hash-block-size=${block_size} ${fs_name} ${tree_name} > ${table_name}
	return $?
}

function dmverity_genDownloadFile()
{
	local fs_name=$1
	local sign_name=$2
	local table_name=$3
	local tree_name=$4
	local download_file_name=$5

	local BLK_SIZE=`dmverity_determ_blk_size ${fs_name}`
	if [ ${BLK_SIZE} -lt 0 ];then
		return -1
	fi
	local SIGN_BLK=`dmverity_get_blk_count ${sign_name} ${BLK_SIZE}`
	local TABLE_BLK=`dmverity_get_blk_count ${table_name} ${BLK_SIZE}`
	local TREE_BLK=`dmverity_get_blk_count ${tree_name} ${BLK_SIZE}`

	# 3.1 copy sign
	dd if=${sign_name} of=${download_file_name}"tmp" bs=${BLK_SIZE} count=${SIGN_BLK} >/dev/null 2>&1

	# 3.2 copy table size
	local TABLE_SIZE=`du --apparent-size -b ${table_name} | awk '{print $1}'`
	local HIGH_BYTES=`expr $TABLE_SIZE / 256 `
	local LOW_BYTES=`expr $TABLE_SIZE % 256 `
	if [ $HIGH_BYTES -gt 256 ]; then
		echo "ERROR rootfs_hash_table size should < 64KB"
		return -1
	fi
	local HIGH_BYTES_H=`echo "obase=16;ibase=10;$HIGH_BYTES" | bc`
	local LOW_BYTES_H=`echo "obase=16;ibase=10;$LOW_BYTES" | bc`
	echo -e -n "\x$LOW_BYTES_H\x$HIGH_BYTES_H" >> ${download_file_name}"tmp"

	# 3.3 copy rootfs_hash_table
	dd if=${table_name} of=${download_file_name}"tmp"  bs=${BLK_SIZE} seek=${SIGN_BLK} count=${TABLE_BLK} > /dev/null 2>&1

	# 3.4 copy rootfs_hash_tree.bin
	dd if=${tree_name} of=${download_file_name}"tmp"  bs=${BLK_SIZE} seek=`expr ${SIGN_BLK} + ${TABLE_BLK}` count=${TREE_BLK} > /dev/null 2>&1

	dd of=${download_file_name} if=${download_file_name}"tmp" bs=${BLK_SIZE} count=`expr ${SIGN_BLK} + ${TABLE_BLK} + ${TREE_BLK}`>/dev/null 2>&1
	rm ${download_file_name}"tmp"
}

function do_signature_dsp()
{
	local DSP0_BIN=${LICHEE_PACK_OUT_DIR}/amp_dsp0.fex;
	local DSP1_BIN=${LICHEE_PACK_OUT_DIR}/amp_dsp1.fex;
	local CFG_FILE=${LICHEE_CHIP_CONFIG_DIR}/configs/default/image_header_secure.cfg;

	if [ -f ${CFG_FILE} ] ; then
		cp -v ${CFG_FILE} image_header_secure.cfg
	else
		printf "can not found image_header_secure cfg\n"
		return 1
	fi

	if [ -f ${DSP0_BIN} ] ; then
		mkimage_header -C 5 -c image_header_secure.cfg -s rsa -k $CFG_KEY_DIR
		if [ $? -ne 0 ]
		then
			pack_error "mkimage_header signature dsp error\n"
			exit 1
		fi
		mv amp_dsp0.fex.pack amp_dsp0.fex
	else
		printf "can not found amp_dsp0 bin\n"
		return 3
	fi

	if [ -f ${DSP1_BIN} ] ; then
		mv amp_dsp0.fex.pack amp_dsp0.fex
	fi

}

function do_signature_riscv()
{
	local RV0_BIN=${LICHEE_PACK_OUT_DIR}/amp_rv0.fex;
	local RV1_BIN=${LICHEE_PACK_OUT_DIR}/amp_rv1.fex;
	local CFG_FILE=${LICHEE_CHIP_CONFIG_DIR}/configs/default/image_header_secure.cfg;
	local key_type=$(readcfg dragon_toc.cfg key_para key_toc1 | cut -c 1-3)
	if [ x${key_type} == "xecc" ]; then
		sign_alg=ecc
	else
		sign_alg=rsa
	fi

	if [ -f ${CFG_FILE} ] ; then
		cp -v ${CFG_FILE} image_header_secure.cfg
	else
		printf "can not found image_header_secure cfg\n"
		return 1
	fi

	if [ -f ${RV0_BIN} ] ; then
		mkimage_header -C 5 -c image_header_secure.cfg -s $sign_alg -k $CFG_KEY_DIR
		if [ $? -ne 0 ]
		then
			pack_error "mkimage_header signature rv error\n"
			exit 1
		fi
		mv amp_rv0.fex.pack amp_rv0.fex
	else
		printf "can not found amp_rv0 bin\n"
		return 3
	fi

	if [ -f ${RV1_BIN} ] ; then
		mv amp_rv1.fex.pack amp_rv1.fex
	fi

}

function do_signature_ft()
{
	if [ ! -e ${LICHEE_PACK_OUT_DIR}/ft_${PACK_CHIP}.bin ]; then
		printf "can not found ft bin\n"
		return 1
	fi

	if [ -e ${LICHEE_PACK_OUT_DIR}/dragon_toc_ft.cfg ]; then
		printf "can not found dragon_toc_ft cfg\n"
	fi

	printf "prepare for signature for ft bin\n"
	mv ${LICHEE_PACK_OUT_DIR}/ft_${PACK_CHIP}.bin ${LICHEE_PACK_OUT_DIR}/ft.bin
	dragonsecboot -toc0 dragon_toc_ft.cfg $CFG_KEY_DIR ${LICHEE_PACK_OUT_DIR}/version_base.mk > /dev/null
	if [ $? -ne 0 ]; then
		pack_error "dragon toc0_ft run error\n"
		exit 1
	fi

	mv toc0.fex toc0_ft.fex
}

function do_signature_fel()
{
	printf "prepare for signature for fex tools\n"
	local ROOT_KEY_NAME="";
	local UBOOT_NAME="u-boot";
	local sign_tools=$(readcfg dragon_toc.cfg sign_fel_tools sign_tools)

	if [ -f u-boot-efex.fex ]; then
		UBOOT_NAME="u-boot-efex"
	fi
	echo UBOOT_NAME ${UBOOT_NAME}

	if [ x${sign_tools} == "xdragonsboot" ]; then
		printf "using dragonsboot to sign fel\n"

		if [ -f ${CFG_KEY_DIR}/RootKey_Level_0.pem ]; then
			ROOT_KEY_NAME=${CFG_KEY_DIR}/RootKey_Level_0.pem
		elif [ -f ${CFG_KEY_DIR}/Trustkey.pem ]; then
			ROOT_KEY_NAME=${CFG_KEY_DIR}/Trustkey.pem
		else
			pack_error "can not found root key to sign fex tool"
			exit 1
		fi
		echo rootkeyname ${ROOT_KEY_NAME}

		dragonsecboot -sign fes1.fex ${ROOT_KEY_NAME} ${LICHEE_PACK_OUT_DIR}/version_base.mk > /dev/null
		if [ $? -eq 0 ]; then
			dragonsecboot -sign ${UBOOT_NAME}.fex ${ROOT_KEY_NAME} ${LICHEE_PACK_OUT_DIR}/version_base.mk > /dev/null
			if [ $? -ne 0 ]
			then
				pack_error "dragonsecboot uboot fail"
			fi
		fi
	else
		printf "using sig_fel_image to sign fel\n"
		if [ -f ${CFG_KEY_DIR}/RootKey_Level_0.bin ]; then
			ROOT_KEY_NAME=${CFG_KEY_DIR}/RootKey_Level_0.bin
		elif [ -f ${CFG_KEY_DIR}/Trustkey.bin ]; then
			ROOT_KEY_NAME=${CFG_KEY_DIR}/Trustkey.bin
		else
			pack_error "can not found root key to sign fex tool"
			exit 1
		fi
		echo rootkeyname ${ROOT_KEY_NAME}

		sig_fel_image --input fes1.fex --rsakey ${ROOT_KEY_NAME} --output fes1_sign.fex --version_base ${LICHEE_PACK_OUT_DIR}/version_base.mk
		if [ $? -ne 0 ]
		then
			pack_error "sig_fel_image fes fail"
			exit 1
		fi
		sig_fel_image --input ${UBOOT_NAME}.fex --rsakey ${ROOT_KEY_NAME} --output ${UBOOT_NAME}_sign.fex --version_base ${LICHEE_PACK_OUT_DIR}/version_base.mk
		if [ $? -ne 0 ]
		then
			pack_error "sig_fel_image uboot fail"
		fi
	fi

	if [ -f fes1_sign.fex ]; then
		cp fes1_sign.fex fes1.fex
	fi

	if [ -f  ${UBOOT_NAME}_sign.fex ]; then
		cp ${UBOOT_NAME}_sign.fex ${UBOOT_NAME}.fex
	fi
}

function readcfg()
{
	local fid=$1
	local section=$2
	local option=$3

	test ! -f $fid && echo "file not exits:$fid" && exit 1
	if [ $# -eq 3 ] ; then
		local src=$(cat $fid | awk '/\['$section'\]/{f=1;next} /\[*\]/{f=0} f' |
		grep ^$option |
		grep '='     |
		cut -d'=' -f2|
		cut -d'#' -f1|
		cut -d';' -f1|
		awk '{gsub(/^\s+|\s+$/, "");print}')
		echo -n $src
		test ${#src} -eq 0 && return 1 || return 0
	else
		echo "the input parameters should be 3"
		exit 1
	fi
}

function get_item_from_cfg()
{
	name=()
	bin=()
	cert=()
	counts=0

	local toc_cfg=$1
	local field=$2
	local key=$3

	toc1_item_content=$(readcfg ${toc_cfg} ${field} ${key})
	i=0
	IFS=', ' read -r -a parts <<< $toc1_item_content
	for part in "${parts[@]}"; do
		if [ $(($i % 3)) -eq 0 ]; then
			name[counts]=$part
		elif [ $(($i % 3)) -eq 1 ]; then
			bin[counts]=$part
		else
			cert[counts]=$part
			counts=$((counts + 1))
		fi
		i=$((i + 1))
	done
}

function create_toc0()
{
	local toc_cfg=$1
	local key=""
	local cert_type=""
	local key_type=""
	local psck_mode=""

	rm -rf toc0

	if [ ! -d "toc0" ]; then
		mkdir -p toc0
	fi

	if [ ! -d "temp" ]; then
		mkdir -p temp
	fi

	get_item_from_cfg ${toc_cfg} toc0 item

	key=$(readcfg ${toc_cfg} key_toc0 ${name[0]})
	cert_type=$(readcfg ${toc_cfg} cert_type cert_type_toc0)
	key_type=$(readcfg ${toc_cfg} key_para key_toc0 | cut -c 1-3)
	if [ x${key_type} == "xrsa" ]; then
		psck_mode=RSA-PKCS
	elif [ x${key_type} == "xecc" ]; then
		psck_mode=ECDSA
	else
		pack_error "key_toc0 type error"
		exit 1
	fi

	#gen sboot hash
	dragon_securetool hash --mode 256 --in ${bin[0]} --out ./temp/${bin[0]}.hash.out
	if [ $? -ne 0 ]
	then
		pack_error "gen sboot hash error"
		exit 1
	fi

	#req no sign cert, ext is sboot_hash; use pubkey
	dragon_securetool req_cert --type ${cert_type} --cfg ${toc_cfg} --pubkey ${CFG_KEY_DIR}/${key}.pem.pub --ext ./temp/${bin[0]}.hash.out --out ./temp/${name[0]}.req
	if [ $? -ne 0 ]
	then
		pack_error "req no sign cert for toc0 error"
		exit 1
	fi

	#gen no sign cert hash, witch is to be signed
	dragon_securetool hash --mode 256 --type ${cert_type} --in ./temp/${name[0]}.req --out ./temp/${name[0]}.req.hash
	if [ $? -ne 0 ]
	then
		pack_error "gen no sign cert hash for toc0 error"
		exit 1
	fi

	#sign cert(to be signed) hash
	if [ "x$SOFTHSM_FLAG" == "x1" ]; then
		local id=$(echo "$key" | md5sum | awk '{print $1}')
		pkcs11-tool --label ${key} --id ${id} -s -p ${PIN} -m ${psck_mode} --module ${MODULES} --input-file ./temp/${name[0]}.req.hash --output-file ./temp/${name[0]}.req.sign
		if [ $? -ne 0 ]
		then
			pack_error "softhsm sign cert(to be signed) hash for toc0 error"
			exit 1
		fi
	else
		dragon_securetool sign --cfg ${toc_cfg} --privatekey ${CFG_KEY_DIR}/${key}.pem --in ./temp/${name[0]}.req.hash --out ./temp/${name[0]}.req.sign
		if [ $? -ne 0 ]
		then
			pack_error "sign cert(to be signed) hash for toc0 error"
			exit 1
		fi
	fi

	#create cert with sign
	dragon_securetool create_cert --type ${cert_type} --cfg ${toc_cfg} --pubkey ${CFG_KEY_DIR}/${key}.pem.pub --reqfile ./temp/${name[0]}.req --signfile ./temp/${name[0]}.req.sign --out ./toc0/${cert[0]}
	if [ $? -ne 0 ]
	then
		pack_error "create cert with sign for toc0 error"
		exit 1
	fi

	#create toc0.fex(toc0_head + sboot.crtpt + sboot)
	dragon_securetool create_toc0 --cfg ${toc_cfg} --out ./toc0.fex
	if [ $? -ne 0 ]
	then
		pack_error "dragon toc0 run error"
		exit 1
	fi
}

function do_signature_sboot()
{
	local sboot_file=$1;
	local flash_type=$2;

	#dram_param
	if [ -f ${LICHEE_TOOLS_DIR}/pack/pctools/linux/mod_update/update_sboot ]; then
		update_sboot $sboot_file  sys_config.bin  > /dev/null
		if [ $? -ne 0 ]
		then
			pack_error "update sboot run error"
			exit 1
		fi
	fi

	update_chip $sboot_file > /dev/null

	#dragon_toc only load sboot.bin
	[ "$(readlink -f $sboot_file)" != "$(readlink -f sboot.bin)" ] && \
	mv $sboot_file sboot.bin

	#readcfg determines whether the cfg file is legacy or new
	readcfg dragon_toc.cfg key_para key > /dev/null
	if [ $? -ne 0 ]; then
		dragonsecboot -toc0 dragon_toc.cfg $CFG_KEY_DIR ${LICHEE_PACK_OUT_DIR}/version_base.mk > /dev/null
		if [ $? -ne 0 ]
		then
			pack_error "dragon toc0 run error"
			exit 1
		fi
	else
		create_toc0 dragon_toc.cfg

	fi

	update_toc0  toc0.fex           sys_config.bin
	if [ $? -ne 0 ]
	then
		pack_error "update toc0 run error"
		exit 1
	fi

	[ "$(readlink -f $sboot_file)" != "$(readlink -f sboot.bin)" ] && \
	mv sboot.bin $sboot_file
	if [ -f toc0_$flash_type.fex ]; then
		rm -rf toc0_$flash_type.fex
	fi
	mv toc0.fex toc0_$flash_type.fex
	mv toc0 toc0_$flash_type
}

function do_signature_toc0()
{
	if [ -f sboot.bin ]; then
		do_signature_sboot sboot.bin bak
		mv sboot.bin sboot_bak.bin
	fi

	if [ -f sboot_sdcard.bin ]; then
		if [ -f cardscript.fex ]; then
			sed -i "s/TOC0_00000000000/TOC0_SDCARD00000/g" cardscript.fex
		fi
		do_signature_sboot sboot_sdcard.bin sdcard
	fi

	if [ -f sboot_nand.bin ]; then
		do_signature_sboot sboot_nand.bin nand

	fi

	if [ -f sboot_ufs.bin ]; then
		do_signature_sboot sboot_ufs.bin ufs
	fi

	if [ -f sboot_nor.bin ]; then
		do_signature_sboot sboot_nor.bin nor
	fi

	mv sboot_bak.bin sboot.bin
	mv toc0_bak.fex toc0.fex
	mv toc0_bak toc0
}

function toc1_create_cert_for_per_bin()
{
	local toc_cfg=$1
	local key=""
	local cert_type=""
	local key_type=""
	local psck_mode=""

	cert_type=$(readcfg ${toc_cfg} cert_type cert_type_toc1)
	key_type=$(readcfg ${toc_cfg} key_para key_toc1 | cut -c 1-3)
	if [ x${key_type} == "xrsa" ]; then
		psck_mode=RSA-PKCS
	elif [ x${key_type} == "xecc" ]; then
		psck_mode=ECDSA
	else
		pack_error "key_toc1 type error"
		exit 1
	fi

	for ((count=0; count < counts; count++)); do
		key=$(readcfg ${toc_cfg} key_toc1 ${name[count]})
		#gen ${bin[count]} hash
		dragon_securetool hash --mode 256 --in ${bin[count]} --out temp/${name[count]}_hash.out
		if [ $? -ne 0 ]
		then
			pack_error "gen hash ${name[count]} error"
			exit 1
		fi

		#req no sign cert, ext is sboot_hash; use pubkey
		dragon_securetool req_cert --type ${cert_type} --cfg ${toc_cfg} --pubkey ${CFG_KEY_DIR}/$key.pem.pub --ext temp/${name[count]}_hash.out --out temp/${cert[count]}.req
		if [ $? -ne 0 ]
		then
			pack_error "req no sign cert ${name[count]} error"
			exit 1
		fi

		#gen no sign cert hash, witch is to be signed
		dragon_securetool hash --mode 256 --type ${cert_type} --in temp/${cert[count]}.req --out temp/to_be_signed_${name[count]}_hash.out
		if [ $? -ne 0 ]
		then
			pack_error "gen no sign cert hash ${name[count]} error"
			exit 1
		fi

		#sign cert(to be signed) hash
		if [ "x$SOFTHSM_FLAG" == "x1" ]; then
			local id=$(echo "$key" | md5sum | awk '{print $1}')
			pkcs11-tool --label ${key} --id ${id} -s -p ${PIN} -m ${psck_mode} --module ${MODULES} --input-file temp/to_be_signed_${name[count]}_hash.out --output-file temp/${name[count]}_sign.out
			if [ $? -ne 0 ]
			then
				pack_error "softhsm sign cert(to be signed) hash ${name[count]} error"
				exit 1
			fi
		else
			dragon_securetool sign --cfg ${toc_cfg} --privatekey ${CFG_KEY_DIR}/$key.pem --in temp/to_be_signed_${name[count]}_hash.out --out temp/${name[count]}_sign.out
			if [ $? -ne 0 ]
			then
				pack_error "sign cert(to be signed) hash ${name[count]} error"
				exit 1
			fi
		fi

		#create cert with sign
		dragon_securetool create_cert --type ${cert_type} --cfg ${toc_cfg} --pubkey ${CFG_KEY_DIR}/${key}.pem.pub --reqfile temp/${cert[count]}.req --signfile temp/${name[count]}_sign.out --out toc1/cert/${cert[count]}
		if [ $? -ne 0 ]
		then
			pack_error "create cert with sign ${name[count]} error"
			exit 1
		fi
	done
}

function toc1_create_cert_for_rootkey()
{
	local toc_cfg=$1
	local key=""
	local cert_type=""
	local key_type=""
	local psck_mode=""

	cert_type=$(readcfg ${toc_cfg} cert_type cert_type_toc1)
	get_item_from_cfg ${toc_cfg} toc1 rootkey
	key=$(readcfg ${toc_cfg} key_toc0 rootkey)
	key_type=$(readcfg ${toc_cfg} key_para key_toc0 | cut -c 1-3)
	if [ x${key_type} == "xrsa" ]; then
		psck_mode=RSA-PKCS
	elif [ x${key_type} == "xecc" ]; then
		psck_mode=ECDSA
	else
		pack_error "key_toc0 type error"
		exit 1
	fi

	#rootkey no sign cert
	#req no sign rootkey cert, insert extensions in the dragon_toc.cfg; use pubkey
	dragon_securetool req_rootkey_cert --type ${cert_type} --cfg ${toc_cfg} --keypath ${CFG_KEY_DIR} --pubkey ${CFG_KEY_DIR}/${key}.pem.pub
	if [ $? -ne 0 ]
	then
		pack_error "req rootkey cert error"
		exit 1
	fi

	mv toc1/cert/${cert[0]} temp/${cert[0]}.req
	#gen no sign rootkey cert hash, witch is to be signed; Non-x509 certificates do not need to skip 4 bytes
	dragon_securetool hash --mode 256 --type ${cert_type} --in temp/${cert[0]}.req --out temp/to_be_signed_${name[0]}_hash.out
	if [ $? -ne 0 ]
	then
		pack_error "gen no sign rootkey cert hash error"
		exit 1
	fi

	#sign rootkey cert(to be signed) hash
	if [ "x$SOFTHSM_FLAG" == "x1" ]; then
		local id=$(echo "$key" | md5sum | awk '{print $1}')
		pkcs11-tool --label ${key} --id ${id} -s -p ${PIN} -m ${psck_mode} --module ${MODULES} --input-file temp/to_be_signed_${name[0]}_hash.out --output-file temp/${name[0]}_sign.out
		if [ $? -ne 0 ]
		then
			pack_error "softhsm sign rootkey cert(to be signed) hash error"
			exit 1
		fi
	else
		dragon_securetool sign --cfg ${toc_cfg} --privatekey ${CFG_KEY_DIR}/${key}.pem --in temp/to_be_signed_${name[0]}_hash.out --out temp/${name[0]}_sign.out
		if [ $? -ne 0 ]
		then
			pack_error "sign rootkey cert(to be signed) hash error"
			exit 1
		fi
	fi

	#create rootkey cert with sign
	dragon_securetool create_cert --type ${cert_type} --cfg ${toc_cfg} --pubkey ${CFG_KEY_DIR}/${key}.pem.pub --reqfile temp/${cert[0]}.req --signfile temp/${name[0]}_sign.out --out toc1/cert/${cert[0]}
	if [ $? -ne 0 ]
	then
		pack_error "create rootkey cert with sign error"
		exit 1
	fi
}

function do_signature_toc1()
{
	rm -rf toc1

	if [ ! -d "toc1/cert" ]; then
		mkdir -p toc1/cert
	fi

	if [ ! -d "temp" ]; then
		mkdir -p temp
	fi

	#create cert for toc1 item
	get_item_from_cfg dragon_toc.cfg toc1 item
	toc1_create_cert_for_per_bin dragon_toc.cfg

	#create cert for toc1 onlykey
	get_item_from_cfg dragon_toc.cfg toc1 onlykey
	toc1_create_cert_for_per_bin dragon_toc.cfg

	toc1_create_cert_for_rootkey dragon_toc.cfg

	#create toc1.fex(toc1_head + rootkey.crtpt + ..)
	dragon_securetool create_toc1 --cfg dragon_toc.cfg --out toc1.fex
	if [ $? -ne 0 ]
	then
		pack_error "dragon toc1 run error"
		exit 1
	fi
}

function do_signature()
{
	printf "prepare for signature by openssl\n"
	if [ ! -d $CFG_KEY_DIR ] ; then
		pack_error "No key exist, please run './build/createkeys' to generate keys first."
		exit 1
	fi
	if [ "x${PACK_SIG}" = "xprev_refurbish" ] ; then
		if [ "x${LICHEE_ARCH}" = "xarm64" ] ; then
			cp -v ${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_a64_no_secureos.cfg dragon_toc.cfg
		else
			cp -v ${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_no_secureos.cfg dragon_toc.cfg
		fi
	else
		if [ "x${LICHEE_ARCH}" = "xarm64" ] ; then
			if [ -f ${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc.cfg ] ; then
				cp -v ${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc.cfg dragon_toc.cfg
			else
				cp -v ${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc_a64.cfg dragon_toc.cfg
			fi
		else
			if [ -f ${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc.cfg ] ; then
				cp -v ${LICHEE_CHIP_CONFIG_DIR}/configs/default/dragon_toc.cfg dragon_toc.cfg
			else
				cp -v ${LICHEE_COMMON_CONFIG_DIR}/sign_config/dragon_toc.cfg dragon_toc.cfg
			fi
		fi
	fi
	if [ "x${PACK_NOR}" = "xnor" ] ; then
		cp -vf ${LICHEE_PACK_OUT_DIR}/dragon_toc_nor.cfg ${LICHEE_PACK_OUT_DIR}/dragon_toc.cfg
	fi

	if [ -f ${CFG_KEY_DIR}/softhsm2.cfg ]; then
		# fix tokendir
		tokendir=$(grep tokendir ${CFG_KEY_DIR}/softhsm2.cfg | awk '{print $3}')
		if [ "x$tokendir" != "x${CFG_KEY_DIR}/.token" ]; then
			sed -i "s#${tokendir}#${CFG_KEY_DIR}/.token#g" ${CFG_KEY_DIR}/softhsm2.cfg
		fi

		PIN=1234
		SOPIN=12345678
		SOFTHSM_TOOLS_DIR=${LICHEE_TOOLS_DIR}/pack/pctools/linux/softhsm
		MODULES=${SOFTHSM_TOOLS_DIR}/lib/softhsm/libsofthsm2.so
		export LD_LIBRARY_PATH=${SOFTHSM_TOOLS_DIR}/lib:${SOFTHSM_TOOLS_DIR}/lib/softhsm:${LIB_LIBRARY_PATH}
		export PATH=${SOFTHSM_TOOLS_DIR}/bin:$PATH
		export SOFTHSM2_CONF=${CFG_KEY_DIR}/softhsm2.cfg

		SOFTHSM_FLAG=1
	fi

	if [ $? -ne 0 ]
	then
		pack_error "dragon toc config file is not exist"
		exit 1
	fi

	rm -f cardscript.fex
	mv cardscript_secure.fex cardscript.fex
	if [ $? -ne 0 ]
	then
		pack_error "dragon cardscript_secure.fex file is not exist"
		exit 1
	fi

	if [ ! -f ${LICHEE_PLAT_OUT}/recovery.img ]; then
		printf "recovery img is not exist, remove recovery cert from dragon_toc.cfg\n"
		sed -i '/recovery/d' dragon_toc.cfg > /dev/null
	else
		local recovery_buf=$(grep "recovery" -nr dragon_toc.cfg)
		if [ x"${recovery_buf}" = x"" ]; then
			readcfg dragon_toc.cfg key_para key > /dev/null
				if [ $? -ne 0 ]; then
					sed -i '/^onlykey=boot/a\onlykey=recovery,      recovery.fex,        SCPFirmwareContentCertPK' dragon_toc.cfg
				else
					sed -i '/^boot=/a recovery=NonTrustedFirmwareContentCertPK' dragon_toc.cfg
					sed -i '/^onlykey=boot/a\onlykey=recovery,     recovery.fex,        recovery.crtpt' dragon_toc.cfg
				fi
		fi
	fi

	if [ "x${PACK_VERITY}" = "x${FLAGS_TRUE}" ]; then
		# verity setup for squashfs type filesystem
		if [ x"${PACK_PLATFORM}" = x"openwrt" ] || [ x"${PACK_PLATFORM}" = x"bsp" ] || [ x"${PACK_PLATFORM}" = x"buildroot" ]; then
			rm -rf rootfs.fex
			local link_real_new=$(get_realpath ${LICHEE_PLAT_OUT} ./)

			if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
				cp ${link_real_new}/rootfs.img		rootfs.fex
			else
				cp ${link_real_new}/rootfs.squashfs	rootfs.fex
			fi

			if [ "x${PACK_KERN}" == "xlinux-5.4" \
					-o "x${PACK_KERN}" == "xlinux-5.4-ansc" \
					-o "x${PACK_KERN}" == "xlinux-5.10" \
					-o "x${PACK_KERN}" == "xlinux-5.10-origin" \
					-o "x${PACK_KERN}" == "xlinux-5.15" \
					-o "x${PACK_KERN}" == "xlinux-5.15-origin" ]; then

				squashfs_real_size=`hexdump -s 0x28 -n 4 -e '/4 "%d"' rootfs.fex`
				squashfs_data_blocks=`expr \( ${squashfs_real_size} + 4095 \) / 4096`

				local TEMP=${LC_ALL}
				export LC_ALL=C

				veritysetup --data-blocks=${squashfs_data_blocks} format rootfs.fex hash_tree > raw_table

				export LC_ALL=${TEMP}

				readcfg dragon_toc.cfg key_para key > /dev/null
				if [ $? -ne 0 ]; then
					sed -i '/^onlykey=boot/a\onlykey=rootfs,          hash_tree,        SCPFirmwareContentCertPK' dragon_toc.cfg
				else
					sed -i '/^boot=/a rootfs=NonTrustedFirmwareContentCertPK' dragon_toc.cfg
					sed -i '/^onlykey=boot/a\onlykey=rootfs,          hash_tree,        rootfs.crtpt' dragon_toc.cfg
				fi
			else
				# get sample from squashfs rootfs
				local rootfs_per_MB=`grep "^rootfs_per_MB=" env.cfg | awk -F = '{printf $2}'`
				if [ -z $rootfs_per_MB ]; then
					echo "rootfs_per_MB is not defined in env.cfg, use default value 4096"
					rootfs_per_MB=4096
				fi

				extract_squashfs $rootfs_per_MB rootfs.fex rootfs-extract.fex
				if [ $? -ne 0 ]; then
					echo "extract squashfs error"
					exit 1;
				fi

				readcfg dragon_toc.cfg key_para key > /dev/null
				if [ $? -ne 0 ]; then
					sed -i '/^onlykey=boot/a\onlykey=rootfs,          rootfs-extract.fex,        SCPFirmwareContentCertPK' dragon_toc.cfg
				else
					sed -i '/^boot=/a rootfs=NonTrustedFirmwareContentCertPK' dragon_toc.cfg
					sed -i '/^onlykey=boot/a\onlykey=rootfs,          rootfs-extract.fex,        rootfs.crtpt' dragon_toc.cfg
				fi
			fi
		else
			# generate verity data, suport more different filesystem in the future
			(dmverity_genHashTable rootfs.fex rootfsHashTree.fex rootfsHashTable.fex &&
			openssl dgst -sha256 -binary -sign $CFG_KEY_DIR/SCPFirmwareContentCertPK.pem rootfsHashTable.fex > rootfsHashSign.fex &&
			openssl rsa -in $CFG_KEY_DIR/SCPFirmwareContentCertPK.pem -pubout -out rootfsPubKey.pk &&
			dmverity_genDownloadFile rootfs.fex rootfsHashSign.fex rootfsHashTable.fex rootfsHashTree.fex VerityInfo.fex) ||
			{ pack_error "generate verity data failed"; exit 1; }

			# add partition for verity data
			(add_partition -2 rootfsverityInfo 4096 "VerityInfo.fex" &&
			maybe_busybox unix2dos sys_partition.fex &&
			script  sys_partition.fex > /dev/null) ||
			{ pack_error "add verity info part failed"; exit 1; }

			# add verity tools into ramdisk
			local rootfsPath=`readlink -f rootfs.fex`
			local keyPath=`readlink -f rootfsPubKey.pk`
			local blockSize=`dmverity_determ_blk_size ${rootfsPath}`
			dmverity_deal $blockSize rootfsverityInfo ext4 $keyPath ||
			{ pack_error "deal verity utils failed"; exit 1; }
		fi
	fi

	if [ "x${PACK_SIGNFEL}" = "x${FLAGS_TRUE}" ]; then
		do_signature_fel
	fi

	do_signature_ft

	do_signature_toc0

	#readcfg determines whether the cfg file is legacy or new
	readcfg dragon_toc.cfg key_para key > /dev/null
	if [ $? -ne 0 ]; then
		dragonsecboot -toc1 dragon_toc.cfg $CFG_KEY_DIR ${LICHEE_PACK_OUT_DIR}/cnf_base.cnf ${LICHEE_PACK_OUT_DIR}/version_base.mk
		if [ $? -ne 0 ]
		then
			pack_error "dragon toc1 run error"
			exit 1
		fi
		cert=".der"
	else
		do_signature_toc1
		cert=".crtpt"
	fi

	sigbootimg --image boot.fex --cert toc1/cert/boot${cert} --output boot_sig.fex
	if [ $? -ne 0 ] ; then
		pack_error "Pack cert to image error"
		exit 1
	else
		mv -f boot_sig.fex boot.fex
	fi

	do_signature_dsp

	do_signature_riscv

	if [ "x${PACK_VERITY}" = "x${FLAGS_TRUE}" ]; then
		if [ x"${PACK_PLATFORM}" = x"openwrt" ] || [ x"${PACK_PLATFORM}" = x"bsp" ] || [ x"${PACK_PLATFORM}" = x"buildroot" ]; then
			if [ "x${PACK_KERN}" == "xlinux-5.4" \
					-o "x${PACK_KERN}" == "xlinux-5.4-ansc" \
					-o "x${PACK_KERN}" == "xlinux-5.10" \
					-o "x${PACK_KERN}" == "xlinux-5.10-origin" \
					-o "x${PACK_KERN}" == "xlinux-5.15" \
					-o "x${PACK_KERN}" == "xlinux-5.15-origin" ]; then
				verity_root_hash_str=`grep "Root hash:" raw_table | awk '{print $3}'`
				verity_salt_str=`grep "Salt:" raw_table | awk '{print $2}'`

				update_squashfs_verity -f rootfs.fex -c toc1/cert/rootfs${cert} -t hash_tree -r ${verity_root_hash_str} -s ${verity_salt_str}
				if [ $? -ne 0 ]; then
					pack_error "add verity block error."
					exit 1
				fi
			else
				update_squashfs rootfs.fex toc1/cert/rootfs${cert}
				if [ $? -ne 0 ]
				then
					pack_error "signature squashfs rootfs error."
					exit 1
				fi
			fi
		fi
	fi

	local link_real=$(get_realpath ${LICHEE_PLAT_OUT} ./)
	local recovery_path=${link_real}/recovery.img

	if [ -f "$recovery_path" ]; then
		sigbootimg --image recovery.fex --cert toc1/cert/recovery${cert} --output recovery_sig.fex
		if [ $? -ne 0 ] ; then
			pack_error "Pack cert to image error"
			exit 1
		else
			mv -f recovery_sig.fex recovery.fex
		fi
	fi

	echo "secure signature ok!"
}

function do_android_signature()
{
	if [ "x$LINUX_DTBO_FILE" = "x" ]; then
		echo "do not set LINUX_DTBO_FILE"
		line_num=`sed -n -e "/default.dtbo/=" dragon_toc.cfg`
		if [ "x$line_num" != "x" ]; then
			sed -i "$line_num s/^/;/g" dragon_toc.cfg
		fi
	else
		if [ -f $LINUX_DTBO_FILE ]
		then
			sed -i "s/default.dtbo/$LINUX_DTBO_FILE/g" dragon_toc.cfg
		else
			line_num=`sed -n -e "/default.dtbo/=" dragon_toc.cfg`
			if [ "x$line_num" != "x" ]; then
				sed -i "$line_num s/^/;/g" dragon_toc.cfg
			fi
		fi
	fi

	if [ $? -ne 0 ]
	then
		pack_error "dragon toc config file is not exist"
		exit 1
	fi

	rm -f cardscript.fex
	mv cardscript_secure.fex cardscript.fex
	if [ $? -ne 0 ]
	then
		pack_error "dragon cardscript_secure.fex file is not exist"
		exit 1
	fi

	do_signature_ft

	do_signature_toc0

	#readcfg determines whether the cfg file is legacy or new
	readcfg dragon_toc.cfg key_para key > /dev/null
	if [ $? -ne 0 ]; then
		dragonsecboot -toc1 dragon_toc.cfg $CFG_KEY_DIR ${LICHEE_PACK_OUT_DIR}/cnf_base.cnf ${LICHEE_PACK_OUT_DIR}/version_base.mk
		if [ $? -ne 0 ]
		then
			pack_error "dragon toc1 run error"
			exit 1
		fi
		cert=".der"
	else
		do_signature_toc1
		cert=".crtpt"
	fi

	if [ -e dboot.fex ]; then
		local keyname=$(awk -F, '/^[[:space:]]*onlykey=boot\S*,[[:space:]]*dboot.fex,/{print $1}' dragon_toc.cfg  | awk -F= '{print $2}')
		sigbootimg --image dboot.fex --cert toc1/cert/${keyname}${cert} --output dboot_sig.fex
		[ $? -ne 0 ] && pack_error "Pack cert to image error" && exit 1
		mv -f dboot_sig.fex dboot.fex
	fi

	echo "secure android signature ok!"
}

################################ Tina func ################################
function get_partition_downfile_size()
{
    local downloadfile_name=`echo $1 | awk -F '=' '{print $2}'`
    if [ x${downloadfile_name: 0-4} != x".fex" ]; then
        pack_error "downloadfile format is wrong, it should be end with .fex"
        exit -1
    fi
    if [ ! -f ${downloadfile_name} ]; then
        echo "  file ${downloadfile_name} not find"
    else
        if [ -L ${downloadfile_name} ]; then
            local downloadfile_name_link=`readlink -f ${downloadfile_name}`
            local linkfile_name=${downloadfile_name_link##*/}
            echo "  ${downloadfile_name} -> ${downloadfile_name_link}"
            if [ ! -f ${downloadfile_name_link} ]; then
                echo "  link file ${linkfile_name} not find"
            else
                local linkfile_size=`ls -lh ${downloadfile_name_link} | awk '{print $5}'`
                echo "  ${linkfile_name} size : ${linkfile_size} byte"
            fi
        else
            local downloadfile_size=`ls -lh ${downloadfile_name} | awk '{print $5}'`
            echo "  ${downloadfile_name} size : ${downloadfile_size} byte"
        fi
    fi
}

function get_partition_mbr_size()
{
    local partition_size_name=`echo $1 | awk -F '=' '{print $1}' | sed 's/partition/mbr/g'`
    local partition_size=`echo $1 | awk -F '=' '{print $2}'`
    echo "  ${partition_size_name}  : ${partition_size} Kbyte"
}

function show_partition_message()
{
    grep -c '[mbr]' $1 > /dev/null
    if [ $? -eq 0 ]; then
        cp $1 ./show_sys_partition.tmp;
        sed -i '/^[\r;]/d' ./show_sys_partition.tmp;
        sed -i '/partition_start/d' ./show_sys_partition.tmp;
        sed -i '/user_type/d' ./show_sys_partition.tmp;
        sed -i 's/\[partition\]/------------------------------------/g' ./show_sys_partition.tmp;
        sed -i 's/[ "\r]//g' ./show_sys_partition.tmp;
        sed -i '/^[;]/d' ./show_sys_partition.tmp;
        sed -i 's/name/partition_name/g' ./show_sys_partition.tmp;
        sed -i 's/size/partition_size/g' ./show_sys_partition.tmp;
        echo "------------------------------------"
        while read line
        do
            if [ "$line" == "------------------------------------" ];then
                echo "$line"
            else
                echo "  $line" | sed 's/=/  : /g'
                echo "  $line" | grep "mbr" >> /dev/null
                if [ $? -eq 0 ]; then
                    read line
                    get_partition_mbr_size $line
                fi
                echo "$line" | grep "downloadfile" >> /dev/null
                if [ $? -eq 0 ]; then
                    get_partition_downfile_size $line
                fi
            fi
        done < ./show_sys_partition.tmp
        echo "------------------------------------"
        rm ./show_sys_partition.tmp
    else
        echo "==========input is not a partition file=========="
    fi
}

function sparse_ext4()
{
    local img=$1
    local sparse_img=$2

    if file $img | grep -q ext4 ;then
        echo "now make sparse ext4 img: $img"
    else
        echo "$img is not ext4 img"
        file $img
        return
    fi

    img2simg $img $sparse_img
}

# pack user resources to a vfat filesystem
# To use this, please add a folder "user-resource" in configs to save files, and add a partition to sys_partition.fex/sys_partition_nor.fex like this:
# [partition]
#   name         = user-res
#   size         = 1024	//size should be 32 aligned
#   downloadfile = "user-resource.fex"
#   user_type    = 0x8000
function make_user_res()
{
    printf "make user resource for : $1\n"
    local USER_RES_SYS_PARTITION=$1
    local USER_RES_PART_NAME=user-res
    local USER_RES_FILE=user-resource

    printf "handle partition ${USER_RES_PART_NAME}\n"
    local USER_RES_PART_DOWNLOAD_FILE=user-resource.fex
    local USER_RES_PART_SIZE=`sed -n "/${USER_RES_PART_NAME}/{N;p}" ${USER_RES_SYS_PARTITION} | awk '$0~"size"{print $3/2}'`
    local USER_RES_FILE_PATH=$CFG_TOP_DIR/${PACK_PLATFORM}/target/$PACK_IC/$PACK_IC-${PACK_BOARD}/configs/${USER_RES_FILE}

    if [ x"${USER_RES_PART_DOWNLOAD_FILE}" != x"" -a  x"${USER_RES_PART_SIZE}" != x"" ]; then
        rm -f ${LICHEE_PACK_OUT_DIR}/user-resource.fex
        mkfs.vfat ${LICHEE_PACK_OUT_DIR}/user-resource.fex -C ${USER_RES_PART_SIZE}
        if [ -d ${USER_RES_FILE_PATH} ]; then
            USER_RES_FILE_SIZE=`du --apparent-size --summarize "${USER_RES_FILE_PATH}" | awk '{print $1}'`
            printf "file size: ${USER_RES_FILE_SIZE}\n"
            printf "partition size: ${USER_RES_PART_SIZE}\n"
            if [ ${USER_RES_PART_SIZE} -le ${USER_RES_FILE_SIZE} ]; then
                printf "file size is larger than partition size, please check your configuration\n"
                printf "please enlarge size of ${USER_RES_PART_NAME} in sys_partition or remove some files in $USER_RES_FILE_PATH\n"
                exit -1
            fi
            mcopy -s -v -i ${LICHEE_PACK_OUT_DIR}/${USER_RES_PART_DOWNLOAD_FILE} ${USER_RES_FILE_PATH}/* ::
            if [ $? -ne 0 ]; then
                printf "mcopy file fail, exit\n"
                exit -1
            fi
        else
            printf "can not find ${USER_RES_FILE_PATH}, ignore it\n"
        fi
    else
        printf "no user resource partitions\n"
    fi
}

#[partition]
#    name         = app
#    size         = 10080
#    downloadfile = "app.fex"
#    user_type    = 0x8000
function make_app_res()
{
    local APP_PART_NAME=app
    cp $1 sys_partition_tmp_app.fex

    sed -i '/^[ \t]*downloadfile/d' sys_partition_tmp_app.fex
    maybe_busybox unix2dos sys_partition_tmp_app.fex
    script  sys_partition_tmp_app.fex > /dev/null
    update_mbr sys_partition_tmp_app.bin 1 sunxi_mbr_tmp_app.fex > /dev/null

    local APP_PART_DOWNLOAD_FILE=app.fex
    local APP_PART_FILE_PATH=$CFG_TOP_DIR/out/$PACK_IC/$PACK_BOARD/$PACK_PLATFORM/build_dir/target/app
    local APP_PART_SIZE_IN_SECTOR=`parser_mbr sunxi_mbr_tmp_app.fex get_size_by_name ${APP_PART_NAME}`
	local TINA_TOOLS_PATH=$CFG_TOP_DIR/out/$PACK_IC/$PACK_BOARD/$PACK_PLATFORM/staging_dir/host/bin

    if [ x${APP_PART_DOWNLOAD_FILE} != x'' -a  x${APP_PART_SIZE_IN_SECTOR} != x'' ]; then
        let APP_PART_SIZE_IN_K=$APP_PART_SIZE_IN_SECTOR/2
        echo "APP_PART_DOWNLOAD_FILE = ${LICHEE_PACK_OUT_DIR}/${APP_PART_DOWNLOAD_FILE}"
        rm -f ${LICHEE_PACK_OUT_DIR}/${APP_PART_DOWNLOAD_FILE}
        ${TINA_TOOLS_PATH}/make_ext4fs -l ${APP_PART_SIZE_IN_K}k -b 1024 -m 0 -j 1024 ${LICHEE_PACK_OUT_DIR}/${APP_PART_DOWNLOAD_FILE}  ${APP_PART_FILE_PATH}
    else
        printf "no app resource partitions\n"
    fi
}

#[partition]
#    name         = data
#    size         = 10080
#    downloadfile = "data.fex"
#    user_type    = 0x8000
function make_data_res()
{
    local DATA_PART_NAME=data
    cp $1 sys_partition_tmp_data.fex

    sed -i '/^[ \t]*downloadfile/d' sys_partition_tmp_data.fex
    maybe_busybox unix2dos sys_partition_tmp_data.fex
    script  sys_partition_tmp_data.fex > /dev/null
    update_mbr sys_partition_tmp_data.bin 1 sunxi_mbr_tmp_data.fex > /dev/null

    local DATA_PART_DOWNLOAD_FILE=data.fex
    local DATA_PART_DOWNLOAD_FILE_SPARSE=data_s.fex
    local DATA_PART_FILE_PATH=$CFG_TOP_DIR/out/$PACK_IC/$PACK_BOARD/$PACK_PLATFORM/build_dir/target/data
    local DATA_PART_SIZE_IN_SECTOR=`parser_mbr sunxi_mbr_tmp_data.fex get_size_by_name ${DATA_PART_NAME}`
	local TINA_TOOLS_PATH=$CFG_TOP_DIR/out/$PACK_IC/$PACK_BOARD/$PACK_PLATFORM/staging_dir/host/bin

    if [ x${DATA_PART_DOWNLOAD_FILE} != x'' -a  x${DATA_PART_SIZE_IN_SECTOR} != x'0' ]; then
        let DATA_PART_SIZE_IN_K=$DATA_PART_SIZE_IN_SECTOR/2
        echo "DATA_PART_DOWNLOAD_FILE = ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE}"
        rm -f ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE}
        rm -f ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE_SPARSE}
        ${TINA_TOOLS_PATH}/make_ext4fs -l ${DATA_PART_SIZE_IN_K}k -b 1024 -m 0 -j 1024 ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE}  ${DATA_PART_FILE_PATH}
        sparse_ext4 ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE} ${LICHEE_PACK_OUT_DIR}/${DATA_PART_DOWNLOAD_FILE_SPARSE}
    else
        printf "no data resource partitions\n"
    fi
}

################################ Platform func ################################
function do_pack_android()
{
	local localpath=$(readlink -f $(pwd))
	local androidout=$(readlink -f ${ANDROID_IMAGE_OUT})
	local link_real=$(get_realpath $androidout $localpath)

	printf "packing for android\n"

	if [ -z "${ANDROID_IMAGE_OUT}" ] ; then
		pack_error "please specify ANDROID_IMAGE_OUT env"
		exit 1
	fi

	local fex_list=($(\gawk '$0~"^[[:space:]]*downloadfile[[:space:]]*="{print $NF}' sys_partition.fex | sed 's/[",\r,\n]//g'))
	fex_list+=(vendor_boot-debug.fex)

	local img_name=""
	for fex_name in ${fex_list[@]}; do
		img_name=${fex_name%\.fex}.img
		if [ -f ${ANDROID_IMAGE_OUT}/${img_name} ]; then
			ln -sf ${link_real}/${img_name} ${fex_name}
			echo "link ${img_name} -> ${fex_name}"
		fi
	done

	if [ -e $androidout/vmlinux ]; then
		export PATH=$PATH:${LICHEE_TOP_DIR}/build/bin
		local vmlinuxpath=$(dirname $(readlink -f $androidout/vmlinux))
		local vmlinuxname=$(basename $(readlink -f $androidout/vmlinux))
		(cd $vmlinuxpath && tar cf $localpath/vmlinux.tar.bz2 --use-compress-prog=lbzip2 $vmlinuxname)
		rm -rf vmlinux.fex
		ln -sf vmlinux.tar.bz2 vmlinux.fex
	fi

	if [ -n "${PACK_BOOT_PATH}" ] && [ "x${PACK_BOOT_PATH}" != "xnone" ]; then
		ln -sf $PACK_BOOT_PATH boot.fex
	fi

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		echo "secure"
		do_android_signature
	else
		echo "normal"
	fi
}

function prepare_mixed_androiddragonboard()
{
	local mixed_fw_type

	if [ "${PACK_TYPE}" != "android" ] || [ -z "$PACK_MIXED_FIRMWARE" ]; then
		return 0
	fi

	case "$PACK_MIXED_FIRMWARE" in
		dragonboard|dragonabts)
			mixed_fw_type="$PACK_MIXED_FIRMWARE"
			pack_info "${FUNCNAME[0]}: mixed firmware type: $mixed_fw_type"
			;;
		*)
			echo "Unsupport mixed firmware type: $PACK_MIXED_FIRMWARE"
			return 1
	esac

	(
		cd ${LICHEE_PACK_OUT_DIR}

		local localpath=$(readlink -f $(pwd))
		local mixedboardout=$(readlink -f ${CFG_PLAT_OUT}/../$mixed_fw_type)
		if [ ! -d $mixedboardout ]; then
			pack_error "${FUNCNAME[0]}: cannot find out path for $mixed_fw_type"
			exit 1
		fi

		local envpath=($LICHEE_BOARD_CONFIG_DIR/$mixed_fw_type $LICHEE_CHIP_CONFIG_DIR/configs/default)
		local partition=(bootloader_b:boot-resource.fex env_b:denv.fex
					boot_b:dboot.fex vendor_boot_b:vendor_boot.fex media_data)

		local item name linenum nstart nend nmax file

		for item in ${partition[@]}; do
			name=${item/:*}
			linenum=$(sed -n "/^\s*name\s*=\s*$name/=" sys_partition.fex)
			if [ -z "$linenum" ]; then
				pack_error "${FUNCNAME[@]}: leak neccery partition $name in sys_partition.fex"
				exit 1
			fi
		done

		for item in ${envpath[@]}; do
			if [ -e $item/env.cfg ]; then
				cp $item/env.cfg denv.cfg
				sed -i '/^\s*boot_normal=/s/\<boot\>/boot_b/g' denv.cfg
				generate_env_for_uboot denv.cfg $mixedboardout/env.img
				rm -rf denv.cfg
				break
			fi
		done

		if  [ ! -e $mixedboardout/env.img  ] || \
			[ ! -e $mixedboardout/boot.img ] || \
			[ ! -e $mixedboardout/rootfs.ext4 ] || \
			[ ! -e $LICHEE_BOARD_CONFIG_DIR/$mixed_fw_type/test_config.fex ]; then
			pack_error "${FUNCNAME[@]}: leak neccery img/fex for $mixed_fw_type"
			exit 1
		fi

		printf "prepare for mixed android/$mixed_fw_type packing...\n"
		for item in ${partition[@]}; do
			name=${item/:*}
			linenum=$(sed -n "/^\s*name\s*=\s*$name/=" sys_partition.fex)
			nstart=$linenum
			nend=$linenum
			nmax=$(wc -l sys_partition.fex | awk '{print $1}')
			while [ $nstart -gt 1 ]; do
				nstart=$((nstart-1))
				if [ -n "$(sed -n "$nstart p" sys_partition.fex | grep "^\s*\[\S\+\]")" ]; then
					break;
				fi
			done

			while [ $nend -lt $nmax ]; do
				nend=$((nend+1))
				if [ -n "$(sed -n "$nend p" sys_partition.fex | grep "^\s*\[\S\+\]")" ]; then
					break;
				fi
			done
			[ $nend -ne $nmax ] && nend=$((nend-1))

			file="$(sed -n "${nstart},${nend}p" sys_partition.fex | \
					awk -F= '/^[[:space:]]*downloadfile[[:space:]]*=/{print $2}')"
			dlfile=${e#*:}
			case $name in
				bootloader_b|env_b|boot_b|vendor_boot_b)
					if [ -z "$file" ]; then
						sed -i "$linenum a\ \ \ \ downloadfile = \"${item#*:}\"" sys_partition.fex
					fi
					;;
				media_data)
					local cmd="$nstart i"
					local size=$(stat $mixedboardout/rootfs.ext4 --format="%s")

					size=$(((size+32*1024*1024-1)/(16*1024*1024)*16))  # at least size + 16M, and 16M align

					if [ -z "$(grep "^\s*name\s*=\s*rootfs" sys_partition.fex)" ]; then
						cmd+="[partition]\n"
						cmd+="    name         = rootfs\n"
						cmd+="    size         = ${size}M\n"
						cmd+="    downloadfile = \"drootfs.fex\"\n"
						cmd+="    user_type    = 0x8000\n"
						cmd+="\n"
					fi
					[ "$cmd" != "$nstart i" ] && sed -i "$cmd" sys_partition.fex
					;;
			esac
		done

		# Delete "^M" under Windows
		sed -i 's|
||g' sys_partition.fex

		readcfg dragon_toc.cfg key_para key > /dev/null
		if [ $? -ne 0 ]; then
			[ -z "$(grep "^\s*onlykey=boot_b,\s*dboot.fex," dragon_toc.cfg)" ] && \
			sed -i 's|^\(\s*onlykey=boot_b,\s*\)\S*,|\1dboot.fex,|g'    dragon_toc.cfg

			[ -z "$(grep "^\s*onlykey=boot_b,\s*dboot.fex," dragon_toc.cfg)" ] && \
			echo "onlykey=boot_b,dboot.fex,SCPFirmwareContentCertPK" >> dragon_toc.cfg
		else
			if [ -z "$(grep "^\s*onlykey=boot_b,\s*dboot.fex," dragon_toc.cfg)" ]; then
				sed -i '/^optee=/a boot_b=SCPFirmwareContentCertPK' dragon_toc.cfg
				sed -i '/^item=optee/a\onlykey=boot_b,dboot.fex,boot_b.crtpt' dragon_toc.cfg
			fi
		fi

		cp $LICHEE_BOARD_CONFIG_DIR/$mixed_fw_type/test_config.fex .
		maybe_busybox dos2unix test_config.fex
		cp test_config.fex boot-resource/
		script test_config.fex > /dev/null
		cp test_config.bin boot-resource/

		cp $mixedboardout/env.img denv.fex
		cp $mixedboardout/boot.img dboot.fex
		cp $mixedboardout/rootfs.ext4 drootfs.fex
		echo "android:$PACK_MIXED_FIRMWARE" > mixed-image-type.txt
	)
	if [ $? -ne 0 ]; then
		pack_error "${FUNCNAME[0]} fail"
		return 1
	fi
	return 0
}

function do_pack_dragonboard()
{
	local link_real=$(get_realpath ${LICHEE_PLAT_OUT} ./)
	printf "packing for dragonboard\n"

	ln -sf ${link_real}/boot.img boot.fex
	ln -sf ${link_real}/rootfs.ext4 rootfs.fex
	ln -sf ${link_real}/rootfs.ubifs rootfs-ubifs.fex

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		do_signature
	else
		echo "normal"
	fi
}

function do_pack_dragonabts()
{
	local link_real=$(get_realpath ${LICHEE_PLAT_OUT} ./)
	printf "packing for dragonabts\n"

	ln -sf ${link_real}/boot.img boot.fex
	ln -sf ${link_real}/rootfs.ext4 rootfs.fex
	ln -sf ${link_real}/rootfs.ubifs rootfs-ubifs.fex

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		do_signature
	else
		echo "normal"
	fi
}

function do_pack_linux()
{
	local link_real=$(get_realpath ${LICHEE_PLAT_OUT} ./)
	local recovery_path=${link_real}/recovery.img

	printf "packing for linux\n"

	do_fit_image
	if [ $? -eq 0 ]; then
		[ -f kernel.itb ] && mv kernel.itb   kernel.fex
		[ -f kernel-dtb.itb ] && mv kernel-dtb.itb   kernel-dtb.fex
	else
		[ -f ${link_real}/bootB.img ] && ln -sf ${link_real}/bootB.img bootB.fex
		ln -sf ${link_real}/boot.img        boot.fex

		# Those files is ready for SPINor.
		ln -sf ${link_real}/uImage          kernel.fex
		if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
			ln -sf ${link_real}/rootfs.img rootfs_nor.fex
		else
			ln -sf ${link_real}/rootfs.squashfs rootfs_nor.fex
		fi
	fi

	if [ x"${PACK_PLATFORM}" = x"openwrt" ]; then
		ln -sf ${link_real}/rootfs.img     rootfs.fex
	else
		ln -sf ${link_real}/rootfs.ext4     rootfs.fex
	fi

	ln -sf ${link_real}/rootfs.ubifs     rootfs-ubifs.fex

	if [ -f "$recovery_path" ]; then
		ln -sf ${recovery_path}     recovery.fex
	fi

	if [ "x${PACK_SECURE}" = "xsecure" ]; then
		echo "secure"
		do_signature
	else
		echo "normal"
	fi
}

function create_kernel_fit_image()
{
	local its_name=$1

	printf "create_kernel_fit_image\n"

	if [ ! -f ${LICHEE_PACK_OUT_DIR}/${its_name}.its ]; then
		printf "can not found ${its_name}.its\n"
		return 1
	fi

	mkimage -f ${its_name}.its ${its_name}.itb
	if [ $? -ne 0 ]; then
		pack_error "mkimage ${its_name}.itb error\n"
		exit 1
	fi
}

function do_fit_image()
{
	printf "do_fit_image\n"

	create_kernel_fit_image kernel
	if [ $? -ne 0 ]; then
		return 1
	fi

	create_kernel_fit_image kernel-dtb
	if [ $? -ne 0 ]; then
		return 1
	fi
}

function main()
{
	local output_resources=${FLAGS_output_resources:-false}
	local from_resources=${FLAGS_from_resources}

	local support_secure_type
	case x$LICHEE_PACK_SECURE_TYPE in
		xnone|xsecure|xany)
			support_secure_type=$LICHEE_PACK_SECURE_TYPE
			;;
		x)
			support_secure_type=any
			;;
		*)
			pack_error "Unsupport pack secure type: $LICHEE_PACK_SECURE_TYPE"
			return 1
			;;
	esac

	if [ "$support_secure_type" != "any" ] && [ "$support_secure_type" != "$PACK_SECURE" ]; then
		pack_error "This platform only support secure type [$support_secure_type], but current using [$PACK_SECURE], please check!!!"
		pack_error "Now, we try using secure type [$support_secure_type]!!!"
		PACK_SECURE=$support_secure_type
	fi

	if [ "$output_resources" == "false" ] && [ -z "$from_resources" ]; then
		do_prepare
		do_ini_to_dts
		do_common
		do_pack_${PACK_TYPE}
		do_finish
		return $?
	fi

	if [ "$output_resources" == "true" ]; then
		do_prepare
		do_ini_to_dts
	elif [ -n "$from_resources" ]; then
		if [ ! -d $from_resources ]; then
			pack_error "Cannot find resources path: $from_resources"
			return 1
		fi

		local count=0
		while [ -e ${LICHEE_PACK_OUT_DIR} -a  $count -lt 20 ]; do
			rm -rf ${LICHEE_PACK_OUT_DIR}
			count=$((count+1))
		done
		cp -rax $from_resources ${LICHEE_PACK_OUT_DIR}
		(
			cd $LICHEE_OUT_DIR
			if [ "${LICHEE_PACK_OUT_DIR}" != "$LICHEE_OUT_DIR/pack_out" ]; then
				rm -rf pack_out
				ln -sf ${LICHEE_IC}/${LICHEE_BOARD}/pack_out pack_out
			fi
		)

		if [ "${PACK_PLATFORM}" == "android" ] && [ -n "$PACK_MIXED_FIRMWARE" ]; then
			local resource_type="$(cat ${LICHEE_PACK_OUT_DIR}/mixed-image-type.txt)"
			local mixed_fw_type="android:$PACK_MIXED_FIRMWARE"
			if [ "$resource_type" != "android:$PACK_MIXED_FIRMWARE" ]; then
				pack_error "mixed firmware type [$mixed_fw_type] but resource type [$resource_type]"
				exit 1
			fi
			pack_info "mixed firmware type [$mixed_fw_type]"
		fi

		cd ${LICHEE_PACK_OUT_DIR}
		do_common
		do_pack_${PACK_TYPE}
		do_finish
	fi
	return $?
}

main "$@"

2025-06-01_101035.png





在线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn