Android Automotive OS on Raspberry Pi 4

Salvatore Amodio
3 min readApr 12, 2021

--

Today, I would like to share part of my project carried out in Teoresi Group for my Bachelor’s Degree in Computer Science. The topic of the thesis was the design and development of an embedded system based on Android Automotive for V2X applications. I decided to put aside the V2X aspects and focus on creating the embedded system because when I started I was going crazy looking for a solution, so I decided to share it with the hope that it will be of help to someone.

Premise

To date, Google doesn’t recommend Raspberry Pi as an Android development board so in addition to the main source (AOSP) I integrated files taken from a Gitbub repository that guaranteed compatibility (android_rpi) that I found when I came across the article “Android 10 on Raspberry Pi 4“ from which I took inspiration. I am going to describe the whole process in detail starting from the cloning up to the flashing in 3 steps.

Android Automotive on Raspberry PI 4 connected to the monitor via HDMI port

Download

The first step is to configure the work environment to be able to cloning Android source files. The work environment I chose was Ubuntu Long Term Support (LTS), release 18.04, because the AOSP branch is more tested for this distribution of operating systems. Once you have overcome the configuration pitfalls, such as installing the Repo Launcher and Git, you are ready to initialize the Repo with the Android branch you intend to download (Android 10 in this case).

$ repo init -u https://android.googlesource.com \
/platform/manifest -b android10.0.0_r40
$ git clone https://github.com/android-rpi/local_manifests \
.repo/local_manifests -b arpi-10

The last command adds the sources that allow the compatibility of Raspberry Pi 4 with Android. Mainly these are files that help the construction of the kernel and what concerns the hardware features to be tied to the system. Finally you can start the synchronization.

$ repo sync

Build

Before moving on to the next step, you need to install the packages that are required for the build.

$ sudo apt install gcc-arm-linux-gnueabihf libssl-dev \
python3 make bison flex

After that you can already start the build for the kernel.

$ cd kernel/arpi$ ARCH=arm scripts/kconfig/merge_config.sh \
arch/arm/configs/bcm2711_defconfig \
kernel/configs/android-base.config \
kernel/configs/android-recommended.config
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make zImage
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make dtbs
$ cd -

Then you need to change some settings in the directory where the features of the device are present “device/arpi/rpi4”, so that the system build step is done for auto.

rpi4.mk
@@ line 17
- USE_OEM_TV_APP: = true
- $(call inherit-product,device/google/atv/products/atv_base.mk)
+ $(call inherit-product,device/generic/car/common/car.mk)

As you can see the android_rpi base image is Android TV. The system image that will be generated will be larger than the previous one, so as a last modification the space assigned to the system partition must be expanded.

BoardConfig.mk
@@ line 37
- BOARD_SYSTEMIMAGE_PARTITION_SIZE := 805306368
+ BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1073741824

Finally, after initializing the environment, the build can be concluded by executing the last instructions:

$ source build/envsetup.sh
$ lunch rpi4-eng
$ make -j8 ramdisk systemimage vendorimage

Flash

The last step involves the preparation of the micro SD card to be able to flash the images that have been created. The memory needs to be divided into four partitions:

  • p1: 128 mb for boot (file system = fat32, flag = boot, lba)
  • p2: 1024 mb for /system (file system = unknown)
  • p3: 128 mb for /vendor (file system = unknown)
  • p4: remaining space /userdata (file system = ext4)

Then it is necessary to overwrite the partitions with the images created with the following commands:

$ cd out/target/product/rpi4
$ sudo dd if=system.img of=/dev/sdb2 bs=1M
$ sudo dd if=system.img of=/dev/sdb3 bs=1M
$ cd -

After mounting the boot partition and copying the files inside, the procedure is finished and you can insert the micro SD card into the board and start it.

$ cp device/arpi/rpi4/boot/* \
kernel/arpi/arch/arm/boot/zImage \
kernel/arpi/arch/arm/boot/dts/bcm2711-rpi-4-b.dtb \
$ out/target/product/rpi4/ramdisk.img /media/salvatore/BOOT$ mkdir /media/salvatore/BOOT/overlays
$ cp kernel/arpi/arch/arm/boot/dts/overlays/ \
vc4-kms-v3d-pi4.dtbo /media/salvatore/BOOT/overlays/

Final Consideration

At the end of the process Raspberry Pi 4 is a full-fledged android device, so connecting it to a WiFi and knowing its IP address you can exstabilish connession via ADB and install whatever application you want. It’s great.

--

--

Salvatore Amodio
Salvatore Amodio

Written by Salvatore Amodio

Master’s Degree in Artificial Intelligence

Responses (2)