mofanv / darknetz

runs several layers of a deep learning model in TrustZone
MIT License
86 stars 29 forks source link

Not able to run darknetz #12

Closed ychen404 closed 4 years ago

ychen404 commented 4 years ago

Hi,

I am having problem integrating darknetz with op-tee. I am able to run op-tee and pass all the test item of xtest without integrating darknetz. But once I copy the darknetz folder and the tzdatasets folder to op-tee using the following two commands provided on this repo.

cp -a darknetp/. optee/optee_examples/darknetp/
cp -a tz_datasets/. optee/out-br/target/root/

Then I run into kernel panic and the following is the error message from the normal world terminal.

Unpacking initramfs...
Initramfs unpacking failed: write error
Freeing initrd memory: 328932K
workingset: timestamp_bits=30 max_order=19 bucket_order=0
squashfs: version 4.0 (2009/01/31) Phillip Lougher
9p: Installing v9fs 9p2000 file system support
io scheduler mq-deadline registered
io scheduler kyber registered
physmap-flash 4000000.flash: physmap platform flash device: [mem 0x04000000-0x07ffffff]
4000000.flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
libphy: Fixed MDIO Bus: probed
usbcore: registered new interface driver usb-storage
rtc-pl031 9010000.pl031: registered as rtc0
ledtrig-cpu: registered to indicate activity on CPUs
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
optee: probing for conduit method from DT.
optee: revision 3.8 (aeb5ba43)
optee: dynamic shared memory is enabled
optee: initialized driver
oprofile: no performance counters
oprofile: using timer interrupt.
NET: Registered protocol family 17
9pnet: Installing 9P2000 support
Registering SWP/SWPB emulation handler
rtc-pl031 9010000.pl031: setting system clock to 2020-04-21T00:42:18 UTC (1587429738)
ALSA device list:
  No soundcards found.
Freeing unused kernel memory: 1024K
Run /init as init process

Failed to execute /init (error -2)
Run /sbin/init as init process
Run /etc/init as init process
Run /bin/init as init process
Run /bin/sh as init process
Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.
CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.5.0 #1
Hardware name: Generic DT based system
[<801114f8>] (unwind_backtrace) from [<8010c8b8>] (show_stack+0x10/0x14)
[<8010c8b8>] (show_stack) from [<8076c45c>] (dump_stack+0x84/0x98)
[<8076c45c>] (dump_stack) from [<80121e48>] (panic+0x11c/0x31c)
[<80121e48>] (panic) from [<80783fd8>] (kernel_init+0x108/0x110)
[<80783fd8>] (kernel_init) from [<801010e8>] (ret_from_fork+0x14/0x2c)
Exception stack(0xc00c9fb0 to 0xc00c9ff8)
9fa0:                                     00000000 00000000 00000000 00000000
9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
9fe0: 00000000 00000000 00000000 00000000 00000013 00000000
CPU0: stopping
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.5.0 #1
Hardware name: Generic DT based system
[<801114f8>] (unwind_backtrace) from [<8010c8b8>] (show_stack+0x10/0x14)
[<8010c8b8>] (show_stack) from [<8076c45c>] (dump_stack+0x84/0x98)
[<8076c45c>] (dump_stack) from [<8010ffb4>] (handle_IPI+0x3f4/0x41c)
[<8010ffb4>] (handle_IPI) from [<8045e534>] (gic_handle_irq+0x8c/0x90)
[<8045e534>] (gic_handle_irq) from [<80101a8c>] (__irq_svc+0x6c/0xa8)
Exception stack(0x80b01f10 to 0x80b01f58)
1f00:                                     00000000 00003280 c20cf034 8011a000
1f20: ffffe000 00000000 80b04c28 80b04c64 00000001 00000000 80a6ab88 8094e260
1f40: 00000000 80b01f60 80109360 80109364 60000113 ffffffff
[<80101a8c>] (__irq_svc) from [<80109364>] (arch_cpu_idle+0x38/0x3c)
[<80109364>] (arch_cpu_idle) from [<801515ec>] (do_idle+0x1a4/0x260)
[<801515ec>] (do_idle) from [<801519a4>] (cpu_startup_entry+0x18/0x1c)
[<801519a4>] (cpu_startup_entry) from [<80a00eb4>] (start_kernel+0x484/0x4b4)
---[ end Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance. ]---

Following is the error message from Secure World

D/TC:0 0 get_aslr_seed:1304 Cannot find valid kaslr-seed
D/TC:0 0 add_phys_mem:586 VCORE_UNPG_RX_PA type TEE_RAM_RX 0x0e100000 size 0x00075000
D/TC:0 0 add_phys_mem:586 VCORE_UNPG_RW_PA type TEE_RAM_RW 0x0e175000 size 0x0018b000
D/TC:0 0 add_phys_mem:586 TA_RAM_START type TA_RAM 0x0e300000 size 0x00d00000
D/TC:0 0 add_phys_mem:586 TEE_SHMEM_START type NSEC_SHM 0x7fe00000 size 0x00200000
D/TC:0 0 add_phys_mem:586 ROUNDDOWN(0x09040000, CORE_MMU_PGDIR_SIZE) type IO_SEC 0x09000000 size 0x00100000
D/TC:0 0 add_phys_mem:586 ROUNDDOWN(0x0e000000, CORE_MMU_PGDIR_SIZE) type IO_SEC 0x0e000000 size 0x00100000
D/TC:0 0 add_phys_mem:586 ROUNDDOWN((0x08000000 + 0), CORE_MMU_PGDIR_SIZE) type IO_SEC 0x08000000 size 0x00100000
D/TC:0 0 add_phys_mem:586 ROUNDDOWN((0x08000000 + 0x10000), CORE_MMU_PGDIR_SIZE) type IO_SEC 0x08000000 size 0x00100000
D/TC:0 0 add_phys_mem:599 Physical mem map overlaps 0x8000000
D/TC:0 0 verify_special_mem_areas:524 No NSEC DDR memory area defined
D/TC:0 0 add_va_space:625 type RES_VASPACE size 0x00a00000
D/TC:0 0 add_va_space:625 type SHM_VASPACE size 0x02000000
D/TC:0 0 dump_mmap_table:737 type TEE_RAM_RX   va 0x0e100000..0x0e174fff pa 0x0e100000..0x0e174fff size 0x00075000 (smallpg)
D/TC:0 0 dump_mmap_table:737 type TEE_RAM_RW   va 0x0e175000..0x0e2fffff pa 0x0e175000..0x0e2fffff size 0x0018b000 (smallpg)
D/TC:0 0 dump_mmap_table:737 type SHM_VASPACE  va 0x0e300000..0x102fffff pa 0x00000000..0x01ffffff size 0x02000000 (pgdir)
D/TC:0 0 dump_mmap_table:737 type RES_VASPACE  va 0x10300000..0x10cfffff pa 0x00000000..0x009fffff size 0x00a00000 (pgdir)
D/TC:0 0 dump_mmap_table:737 type IO_SEC       va 0x10d00000..0x10dfffff pa 0x08000000..0x080fffff size 0x00100000 (pgdir)
D/TC:0 0 dump_mmap_table:737 type IO_SEC       va 0x10e00000..0x10efffff pa 0x09
000000..0x090fffff size 0x00100000 (pgdir)
D/TC:0 0 dump_mmap_table:737 type IO_SEC       va 0x10f00000..0x10ffffff pa 0x0e000000..0x0e0fffff size 0x00100000 (pgdir)
D/TC:0 0 dump_mmap_table:737 type TA_RAM       va 0x11000000..0x11cfffff pa 0x0e300000..0x0effffff size 0x00d00000 (pgdir)
D/TC:0 0 dump_mmap_table:737 type NSEC_SHM     va 0x11d00000..0x11efffff pa 0x7fe00000..0x7fffffff size 0x00200000 (pgdir)
D/TC:0 0 core_mmu_alloc_l2:265 L2 table used: 1/5
I/TC: 
D/TC:0 0 init_canaries:164 #Stack canaries for stack_tmp[0] with top at 0xe19ae38
D/TC:0 0 init_canaries:164 watch *0xe19ae3c
D/TC:0 0 init_canaries:164 #Stack canaries for stack_tmp[1] with top at 0xe19b778
D/TC:0 0 init_canaries:164 watch *0xe19b77c
D/TC:0 0 init_canaries:164 #Stack canaries for stack_tmp[2] with top at 0xe19c0b8
D/TC:0 0 init_canaries:164 watch *0xe19c0bc
D/TC:0 0 init_canaries:164 #Stack canaries for stack_tmp[3] with top at 0xe19c9f8
D/TC:0 0 init_canaries:164 watch *0xe19c9fc
D/TC:0 0 init_canaries:165 #Stack canaries for stack_abt[0] with top at 0xe19d238
D/TC:0 0 init_canaries:165 watch *0xe19d23c
D/TC:0 0 init_canaries:165 #Stack canaries for stack_abt[1] with top at 0xe19da78
D/TC:0 0 init_canaries:165 watch *0xe19da7c
D/TC:0 0 init_canaries:165 #Stack canaries for stack_abt[2] with top at 0xe19e2b8
D/TC:0 0 init_canaries:165 watch *0xe19e2bc
D/TC:0 0 init_canaries:165 #Stack canaries for stack_abt[3] with top at 0xe19eaf8
D/TC:0 0 init_canaries:165 watch *0xe19eafc
D/TC:0 0 init_canaries:167 #Stack canaries for stack_thread[0] with top at 0xe1a0b38
D/TC:0 0 init_canaries:167 watch *0xe1a0b3c
D/TC:0 0 init_canaries:167 #Stack canaries for stack_thread[1] with top at 0xe1a2b78
D/TC:0 0 init_canaries:167 watch *0xe1a2b7c
I/TC: Non-secure external DT found
D/TC:0 0 carve_out_phys_mem:286 No need to carve out 0xe100000 size 0x200000
D/TC:0 0 carve_out_phys_mem:286 No need to carve out 0xe300000 size 0xd00000
D/TC:0 0 dt_add_psci_node:729 PSCI Device Tree node already exists!
I/TC: Switching console to device: /pl011@9040000
I/TC: OP-TEE version: 3.8.0-263-gaeb5ba4 (gcc version 8.3.0 (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))) #1 Sat Apr 18 07:30:35 UTC 2020 arm
D/TC:0 0 init_primary_helper:1171 Executing at offset 0 with virtual load address 0xe100000
D/TC:0 0 check_ta_store:635 TA store: "Secure Storage TA"
D/TC:0 0 check_ta_store:635 TA store: "REE"
D/TC:0 0 mobj_mapped_shm_init:447 Shared memory address range: e300000, 10300000
D/TC:0 0 gic_it_set_cpu_mask:251 cpu_mask: writing 0xff to 0x10d00828
D/TC:0 0 gic_it_set_cpu_mask:253 cpu_mask: 0xff
D/TC:0 0 gic_it_set_prio:266 prio: writing 0x1 to 0x10d00428
I/TC: Initialized
D/TC:0 0 init_primary_helper:1184 Primary CPU switching to normal world boot
D/TC:0   psci_cpu_on:211 core pos: 1: ns_entry 0x40102620
D/TC:1   init_secondary_helper:1208 Secondary CPU Switching to normal world boot
D/TC:1   tee_entry_exchange_capabilities:102 Dynamic shared memory is enabled
D/TC:1 0 core_mmu_alloc_l2:265 L2 table used: 2/5
D/TC:? 0 tee_ta_init_pseudo_ta_session:284 Lookup pseudo TA 7011a688-ddde-4053-a5a9-7b3c4ddf13b8
D/TC:? 0 tee_ta_init_pseudo_ta_session:297 Open device.pta
D/TC:? 0 tee_ta_init_pseudo_ta_session:311 device.pta : 7011a688-ddde-4053-a5a9-7b3c4ddf13b8
D/TC:? 0 tee_ta_close_session:499 csess 0xe191dd0 id 1
D/TC:? 0 tee_ta_close_session:518 Destroy session

I have no idea how integrating darknetz can lead to booting issue. Any help is appreciated!

mofanv commented 4 years ago

Hi @ychen404 ,

Seems there is a problem when packing initramfs. Can you please try to remove the data folder from optee/out-br/target/root/, and only keep darknetp/ in the optee_examples/ folder?

Another issue could be the OPTEE version is not compatible. Please try to downgrade it to 3.4.0 following https://github.com/OP-TEE/optee_docs/blob/master/building/gits/build.rst

ychen404 commented 4 years ago

Hi @mofanv

I removed the data folder from opt/out-br/target/root/ and only kept darknetp in the optee_examples folder. Now the OS can boot without getting initramfs issue. But when i tried to run darknetp in the Normal World, I got the following error message.

Prepare session with the TA
darknetp: TEEC_Opensession failed with code 0xffff000c origin 0x3
ychen404 commented 4 years ago

I will try to downgrade op-tee to 3.4.0. Do I need to replace the build folder using your link, https://github.com/OP-TEE/optee_docs/blob/master/building/gits/build.rst

Or, it is fine to use the build folder from git as follows? ./repo init -u https://github.com/OP-TEE/manifest.git -m default.xml -b 3.4.0

Thanks!

mofanv commented 4 years ago

I'd suggest removing the OPTEE project and do all things from the beginning to avoid any possible issues. Could you try to clone the OPTEE again, and then use the following command to initialize the branch (same in the link I sent above)?

repo init -u https://github.com/OP-TEE/manifest.git -m rpi3.xml -b 3.4.0

Please let me know whether version 3.4.0 fix errors or not. Thanks.

ychen404 commented 4 years ago

Hi Fan,

I am using QEMU v7. Can I use the branch 3.4.0 for default.xml instead?

On Thu, Apr 30, 2020 at 2:34 AM Mo, Fan Vincent notifications@github.com wrote:

I'd suggest removing the OPTEE project and do all things from the beginning to avoid any possible issues. Could you try to clone the OPTEE again, and then use the following command to initialize the branch (same in the link I sent above)?

repo init -u https://github.com/OP-TEE/manifest.git -m rpi3.xml -b 3.4.0

Please let me know whether version 3.4.0 fix errors or not. Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mofanv/darknetz/issues/12#issuecomment-621723948, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJO3TW4FFI2MIPDH7H4GDTRPFA23ANCNFSM4MM4LGKA .

mofanv commented 4 years ago

Yes. go ahead. QEMU v7 should work with default.xml

LiTszOn commented 4 years ago

Hi! I encountered the same problem as @ychen404, that I also got the darknetp: TEEC_Opensession failed with code 0xffff000c origin 0x3 error message after removing data folder from opt/out-br/target/root/. I am using QEMU v7 with branch 3.4.0. Please let me know about any idea of how it can be fixed. Thanks in advance!

mofanv commented 4 years ago

@LiTszOn Hi, is there any error when you run the hello_world example?

LiTszOn commented 4 years ago

@mofanv Many thanks for your swift reply! No, there is no error when I run hello_world, which outputs

Invoking TA to increment 42 TA incremented value to 43

There is also no error when I run random,hotp etc.

ychen404 commented 4 years ago

@mofanv Still not working with 3.4.0. I have no error running hello world.

# darknetp 
Prepare session with the TA
darknetp: TEEC_Opensession failed with code 0xffff0008 origin 0x3
ychen404 commented 4 years ago

@mofanv It is working now after reducing the required memory size to 2 MB. Thanks.

LiTszOn commented 4 years ago

@ychen404 Thanks for your feedback. May I know if you constrain the required memory size to 2 MB by specifying -m 2M in the Makefile under optee/build?

ychen404 commented 4 years ago

No, the memory size is defined in a header file, which locates at:

ta/include/user_ta_header_defines.h

You only need to change

#define TA_DATA_SIZE

To 2 MB.

LiTszOn commented 4 years ago

@ychen404 Thank you for your prompt reply!! It works now, thanks a lot!!

ychen404 commented 4 years ago

@mofanv I am having trouble running optee 3.4.0 on Raspberry Pi 3b+. I used the following command to init the repo, as you recommended.

repo init -u https://github.com/OP-TEE/manifest.git -m rpi3.xml -b 3.4.0

But I am getting the following invalid path error.

ManifestInvalidPathError: <linkfile> invalid "src": ../toolchains/aarch64/bin/aarch64-linux-gnu-gdb: bad component

Can you point me some directions. Thanks.

mofanv commented 4 years ago

It is highly probable that this is an OPTEE problem, I'd suggest you ask the OPTEE team because they know this better.