joelagnel / adeb

A debian-based shell environment designed for Android and adb
Apache License 2.0
318 stars 98 forks source link

Extend adeb to connect to a target through ssh #18

Closed qais-yousef closed 5 years ago

qais-yousef commented 5 years ago

I managed to use adeb image to create an environment on which I can run eBPF on non android system (buildroot initramfs with no desk mounted). It would be nice to extend adeb to streamline the process for non android system.

The steps I had to do to get this working:

  1. adeb prepare --kernelsrc /path/to/kernel --build-image deb.img --bcc
  2. mount deb.img ./tmp && chroot tmp
  3. cd bcc-master && ./build-bcc.sh
  4. Create /lib/modules/$(uname -r)/build (for kernel headers)
  5. scp the image to the device and ssh and chroot in a similar manner to adb

I am happy to send patches to get this work done. But it would be nice to know first if the concept is OK and if there's any preference on methodology.

What I think needs doing is:

  1. squash steps 2-4 and hide them behind --build-image and --bcc options. I don't see why bcc-master needs to be compiled at the target and can be done offline at the host.

I'm not sure how you manage step 4 at the moment. It would be nice to do this offline at the host too.

These are my quick thoughts. I'll try to get some patches ready meanwhile ;-)

qais-yousef commented 5 years ago

OK I can see that you use BCC_KERNEL_SOURCE to avoid creating /lib/modules/$(uname -r)/build. Nice

joelagnel commented 5 years ago

Yes, you are welcomed to send patches for building BCC within the image. That would be quite useful. Thanks. About compiling on the target, that is needed if the target is of a different architecture than the host.

Also about kernel headers, moving forward I want to get this working so we can just use kernel headers from the kernel itself which will eliminate the extra step we do (for BCC_KERNEL_SOURCE) https://lore.kernel.org/patchwork/patch/1040685/ If you want, I can CC you on those kernel patches as well (just let me know your email address) and your review/contributions there are also welcomed.

qais-yousef commented 5 years ago

About compiling on the target, that is needed if the target is of a different architecture than the host.

Oh yes. But there's a nice trick that I accidentally discovered. When you chroot to a debian image that was created for a different arch it'll recognize that and assume the right arch, ie: arm64 and you won't appear to be cross compiling anymore.

Also I was caught more than once when cross compiling a binary and trying to execute it on x86 expecting a wrong arch error but instead it magically ran; only to discover thatt the system is smart to know it's for a different arch and transparently uses qemu-$(arch). Neat!

Will send a PR for that soon.

If you want, I can CC you on those kernel patches as well (just let me know your email address) and your review/contributions there are also welcomed.

Yes please. I can probably give you my tested-by. qais.yousef@arm.com