Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 1 | adeb |
Joel Fernandes | 652141b | 2018-04-01 21:15:48 -0700 | [diff] [blame] | 2 | -------- |
Joel Fernandes | 0301c04 | 2018-03-30 16:28:57 -0700 | [diff] [blame] | 3 | |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 4 | **adeb** (also known as **androdeb**) provides a powerful Linux shell |
Joel Fernandes | c755196 | 2018-07-10 14:12:19 -0700 | [diff] [blame] | 5 | environment where one can run popular and mainstream Linux tracing, compiling, |
| 6 | editing and other development tools on an existing Android device. All the |
| 7 | commands typically available on a modern Linux system are supported in |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 8 | adeb. |
Joel Fernandes | 6398170 | 2018-04-01 20:30:55 -0700 | [diff] [blame] | 9 | |
| 10 | Usecases |
| 11 | -------- |
Joel Fernandes | 8ff0b5f | 2018-04-01 21:13:03 -0700 | [diff] [blame] | 12 | 1. Powerful development environment with all tools ready to go (editors, |
Joel Fernandes | 6398170 | 2018-04-01 20:30:55 -0700 | [diff] [blame] | 13 | compilers, tracers, perl/python etc) for your on-device development. |
| 14 | |
Joel Fernandes | 8ff0b5f | 2018-04-01 21:13:03 -0700 | [diff] [blame] | 15 | 2. No more cross-compiler needed: Because it comes with gcc and clang, one can |
Joel Fernandes | 6398170 | 2018-04-01 20:30:55 -0700 | [diff] [blame] | 16 | build target packages natively without needing to do any cross compilation. We even |
Joel Fernandes | afea46d | 2018-04-01 21:08:23 -0700 | [diff] [blame] | 17 | ship git, and have support to run apt-get to get any missing development packages |
| 18 | from the web. |
Joel Fernandes | 6398170 | 2018-04-01 20:30:55 -0700 | [diff] [blame] | 19 | |
Joel Fernandes | 1fdb318 | 2018-04-01 21:13:27 -0700 | [diff] [blame] | 20 | 3. Using these one can run popular tools such as BCC that are difficult to run |
Joel Fernandes (Google) | fa32e59 | 2018-05-29 11:49:20 -0700 | [diff] [blame] | 21 | in an Android environment due to lack of packages, dependencies and |
| 22 | cross-compilation needed for their operation. [Check BCC on Android using |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 23 | adeb](https://github.com/joelagnel/adeb/blob/master/BCC.md) for more |
Joel Fernandes (Google) | fa32e59 | 2018-05-29 11:49:20 -0700 | [diff] [blame] | 24 | information on that. |
Joel Fernandes | 6398170 | 2018-04-01 20:30:55 -0700 | [diff] [blame] | 25 | |
Joel Fernandes | 1fdb318 | 2018-04-01 21:13:27 -0700 | [diff] [blame] | 26 | 4. No more crippled tools: Its often a theme to build a static binary with |
Joel Fernandes | 6398170 | 2018-04-01 20:30:55 -0700 | [diff] [blame] | 27 | features disabled, because you couldn't cross-compile the feature's dependencies. One |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 28 | classic example is perf. However, thanks to adeb, we can build perf natively |
Joel Fernandes | 6398170 | 2018-04-01 20:30:55 -0700 | [diff] [blame] | 29 | on device without having to cripple it. |
| 30 | |
| 31 | Requirements for running |
| 32 | ------------------------ |
| 33 | Target: |
| 34 | An ARM64 android N or later device which has "adb root" supported. Typically |
| 35 | this is a build in a userdebug configuration. Device should have atleast 2 GB |
Joel Fernandes (Google) | fa32e59 | 2018-05-29 11:49:20 -0700 | [diff] [blame] | 36 | free space in the data partition. If you would like to use other architectures, |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 37 | see the [Other Architectures](https://github.com/joelagnel/adeb/blob/master/README.md#how-to-use-adeb-for-other-architectures-other-than-arm64) section. |
Joel Fernandes | 6398170 | 2018-04-01 20:30:55 -0700 | [diff] [blame] | 38 | |
| 39 | Host: |
| 40 | A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. |
Joel Fernandes | 2a4c77d | 2018-04-02 10:15:50 -0700 | [diff] [blame] | 41 | Host needs debootstrap and qemu-debootstrap packages. |
Joel | 7dd36e6 | 2018-04-03 12:35:23 -0700 | [diff] [blame] | 42 | To install it, run `sudo apt-get install qemu-user-static debootstrap`. |
Joel Fernandes | 2597650 | 2018-04-02 09:59:48 -0700 | [diff] [blame] | 43 | Other distributions may work but they are not tested. |
Joel Fernandes | 6398170 | 2018-04-01 20:30:55 -0700 | [diff] [blame] | 44 | |
Joel Fernandes | 9bb0c84 | 2018-04-01 20:38:35 -0700 | [diff] [blame] | 45 | Quick Start Instructions |
| 46 | ------------------------ |
Joel Fernandes (Google) | a1dd6a8 | 2018-07-25 16:47:53 -0700 | [diff] [blame] | 47 | * First clone this repository into adb and cd into it. |
Joel Fernandes | 9bb0c84 | 2018-04-01 20:38:35 -0700 | [diff] [blame] | 48 | ``` |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 49 | cd adeb |
Joel Fernandes | c755196 | 2018-07-10 14:12:19 -0700 | [diff] [blame] | 50 | |
| 51 | # Add some short cuts: |
Joel Fernandes | aefebd1 | 2018-07-10 14:17:19 -0700 | [diff] [blame] | 52 | sudo ln -s $(pwd)/adeb /usr/bin/adeb |
Joel Fernandes (Google) | db9005f | 2018-07-25 16:44:12 -0700 | [diff] [blame] | 53 | |
Erick Reyes | eb6bc73 | 2018-08-16 15:39:48 -0700 | [diff] [blame] | 54 | # Cached image downloads result in a huge speed-up. These are automatic if you |
| 55 | # cloned the repository using git. However, if you downloaded the repository |
| 56 | # as a zip file (or you want to host images elsewere), you could set the |
| 57 | # ADEB_REPO_URL environment variable in your bashrc file. |
Joel Fernandes (Google) | db9005f | 2018-07-25 16:44:12 -0700 | [diff] [blame] | 58 | # Disclaimer: Google is not liable for the below URL and this |
| 59 | # is just an example. |
Erick Reyes | dd195c0 | 2018-08-16 14:50:47 -0700 | [diff] [blame] | 60 | export ADEB_REPO_URL="github.com/joelagnel/adeb/" |
Joel Fernandes | 9bb0c84 | 2018-04-01 20:38:35 -0700 | [diff] [blame] | 61 | ``` |
| 62 | |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 63 | * Installing adeb onto your device: |
Joel Fernandes | 1618199 | 2018-07-11 20:59:08 -0700 | [diff] [blame] | 64 | First make sure device is connected to system |
| 65 | Then run, for the base image: |
Joel Fernandes | 9bb0c84 | 2018-04-01 20:38:35 -0700 | [diff] [blame] | 66 | ``` |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 67 | adeb prepare |
| 68 | ``` |
Joel Fernandes | b97601f | 2018-07-11 20:56:39 -0700 | [diff] [blame] | 69 | The previous command only downloads and installs the base image. |
| 70 | Instead if you want to download and install the full image, do: |
| 71 | ``` |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 72 | adeb prepare --full |
Joel Fernandes | 9bb0c84 | 2018-04-01 20:38:35 -0700 | [diff] [blame] | 73 | ``` |
| 74 | |
Joel Fernandes | c755196 | 2018-07-10 14:12:19 -0700 | [diff] [blame] | 75 | * Now run adeb shell to enter your new environment!: |
Joel Fernandes | 9bb0c84 | 2018-04-01 20:38:35 -0700 | [diff] [blame] | 76 | ``` |
Joel Fernandes | c755196 | 2018-07-10 14:12:19 -0700 | [diff] [blame] | 77 | adeb shell |
Joel Fernandes | 9bb0c84 | 2018-04-01 20:38:35 -0700 | [diff] [blame] | 78 | ``` |
Joel Fernandes | 961b69b | 2018-04-02 23:14:36 -0700 | [diff] [blame] | 79 | |
| 80 | * Once done, hit `CTRL + D` and you will exit out of the shell. |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 81 | To remove adeb from the device, run: |
Joel Fernandes | 961b69b | 2018-04-02 23:14:36 -0700 | [diff] [blame] | 82 | ``` |
Joel Fernandes | c755196 | 2018-07-10 14:12:19 -0700 | [diff] [blame] | 83 | adeb remove |
Joel Fernandes | 961b69b | 2018-04-02 23:14:36 -0700 | [diff] [blame] | 84 | ``` |
| 85 | If you have multiple devices connected, please add `-s <serialnumber>`. |
| 86 | Serial numbers of all devices connected can be obtained by `adb devices`. |
| 87 | |
ErickReyesR | 82574e1 | 2018-07-31 00:25:18 -0600 | [diff] [blame] | 88 | * To update an existing adeb clone on your host, run: |
Joel Fernandes | c6bb496 | 2018-07-08 11:00:32 -0700 | [diff] [blame] | 89 | ``` |
Joel Fernandes | c755196 | 2018-07-10 14:12:19 -0700 | [diff] [blame] | 90 | adeb git-pull |
Joel Fernandes | c6bb496 | 2018-07-08 11:00:32 -0700 | [diff] [blame] | 91 | ``` |
| 92 | |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 93 | More advanced usage instructions |
| 94 | -------------------------------- |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 95 | ### Install kernel headers in addition to preparing adeb device: |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 96 | ``` |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 97 | adeb prepare --kernelsrc /path/to/kernel-source |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 98 | ``` |
| 99 | |
Joel Fernandes | bc32b49 | 2018-04-01 21:15:24 -0700 | [diff] [blame] | 100 | ### Update kernel headers onto an already prepared device: |
Joel Fernandes | 1a0e259 | 2018-04-01 21:00:51 -0700 | [diff] [blame] | 101 | |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 102 | If you need to put kernel sources for an existing install, run: |
| 103 | ``` |
Joel Fernandes | c755196 | 2018-07-10 14:12:19 -0700 | [diff] [blame] | 104 | adeb prepare --kernelsrc /path/to/kernel-source --skip-install |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 105 | ``` |
| 106 | Note: The kernel sources should have been built (atleast build should have started). |
| 107 | |
Joel Fernandes | 1a0e259 | 2018-04-01 21:00:51 -0700 | [diff] [blame] | 108 | ### Build and prepare device with a custom rootfs locally: |
| 109 | |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 110 | The adeb fs will be prepared locally by downloading packages as needed: |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 111 | ``` |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 112 | adeb prepare --build |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 113 | ``` |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 114 | This is unlike the default behavior, where the adeb rootfs is itself pulled from the web. |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 115 | |
| 116 | If you wish to do a full build (that is locally prepare a rootfs with all packages, including bcc, then do): |
| 117 | ``` |
| 118 | adeb prepare --full --build |
| 119 | ``` |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 120 | |
Joel Fernandes | da816a8 | 2018-04-01 21:02:11 -0700 | [diff] [blame] | 121 | ### Add kernel headers to device in addition to building locally: |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 122 | ``` |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 123 | adeb prepare --build --kernelsrc /path/to/kernel-source/ |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 124 | ``` |
| 125 | |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 126 | ### Build/install a base image with BCC: |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 127 | ``` |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 128 | adeb prepare --build --bcc --kernelsrc /path/to/kernel-source/ |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 129 | ``` |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 130 | Note: BCC is built from source. Also `--kernelsrc` is recommended for tools to |
| 131 | function unless device has them already. |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 132 | |
Joel Fernandes | da816a8 | 2018-04-01 21:02:11 -0700 | [diff] [blame] | 133 | ### Extract the FS from the device, after its prepared: |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 134 | ``` |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 135 | adeb prepare --buildtar /path/ |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 136 | ``` |
| 137 | After device is prepared, it will extract the root fs from it |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 138 | and store it as a tar archive at `/path/adeb-fs.tgz`. This |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 139 | can be used later. |
| 140 | |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 141 | ### Use a previously prepared adeb rootfs tar from local: |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 142 | ``` |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 143 | adeb prepare --archive /path/adeb-fs.tgz |
Joel Fernandes | 93b7f2e | 2018-04-01 20:58:20 -0700 | [diff] [blame] | 144 | ``` |
Joel Fernandes (Google) | 9c3ae93 | 2018-05-28 14:34:48 -0700 | [diff] [blame] | 145 | |
| 146 | ### Build a standalone raw EXT4 image out of the FS: |
| 147 | ``` |
Joel Fernandes | 1618199 | 2018-07-11 20:59:08 -0700 | [diff] [blame] | 148 | adeb prepare --build-image /path/to/image.img |
Joel Fernandes (Google) | 9c3ae93 | 2018-05-28 14:34:48 -0700 | [diff] [blame] | 149 | ``` |
| 150 | This can then be passed to Qemu as -hda. Note: This option doesn't need a |
| 151 | device connected. |
Joel Fernandes (Google) | fa32e59 | 2018-05-29 11:49:20 -0700 | [diff] [blame] | 152 | |
Joel Fernandes (Google) | ac62874 | 2018-07-16 18:55:40 -0700 | [diff] [blame] | 153 | ### How to use adeb for other Architectures (other than ARM64) |
| 154 | By default adeb assumes the target Android device is based on ARM64 |
Joel Fernandes (Google) | fa32e59 | 2018-05-29 11:49:20 -0700 | [diff] [blame] | 155 | processor architecture. For other architectures, use the --arch option. For |
| 156 | example for x86_64 architecture, run: |
| 157 | ``` |
Joel Fernandes | 6975db2 | 2018-07-11 20:53:16 -0700 | [diff] [blame] | 158 | adeb prepare --build --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ |
Joel Fernandes (Google) | fa32e59 | 2018-05-29 11:49:20 -0700 | [diff] [blame] | 159 | ``` |
| 160 | Note: The --download option ignores the --arch flag. This is because we only |
| 161 | provide pre-built filesystems for ARM64 at the moment. |
Joel Fernandes (Google) | 76e8464 | 2018-07-27 20:04:30 -0700 | [diff] [blame] | 162 | |
| 163 | Common Trouble shooting |
| 164 | ----------------- |
| 165 | 1. Installing g++ with `apt-get install g++` fails. |
Joel Fernandes (Google) | 02db2fd | 2018-07-27 20:05:17 -0700 | [diff] [blame] | 166 | |
Liu Changcheng | f44ca95 | 2018-08-02 14:38:58 +0800 | [diff] [blame] | 167 | Solution: Run `adeb shell apt-get update` after the `adeb prepare` stage. |
| 168 | |
| 169 | 2. It's too slow to use debootstrap to create debian fs |
| 170 | |
| 171 | Solution: Use a local mirror, for example in China you could use |
| 172 | https://mirror.tuna.tsinghua.edu.cn/debian/ instead of debian official website |
| 173 | http://deb.debian.org/debian/ |