Skip to content

Commit 1cc973c

Browse files
glaroquepraneethbajjuri
authored andcommitted
feat(android): AM62X|AM62P: add secure build application note
Add new Application Note to explain how to enable some security features and set some custom key for signing TA and AVB. Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
1 parent 6018356 commit 1cc973c

7 files changed

Lines changed: 301 additions & 0 deletions

File tree

configs/AM62PX/AM62PX_android_toc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ android/Application_Notes_Android_Dual_Screen
99
android/Application_Notes_Android_Low_Power
1010
android/Application_Notes_Android_Multimedia_Video
1111
android/Application_Notes_Android_SD_CARD
12+
android/Application_Notes_Android_Secure_Build
1213
android/Application_Notes_Camera
1314
android/Application_Notes_Partitions
1415
android/Application_Notes_Sample_Maps_App

configs/AM62X/AM62X_android_toc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ android/Application_Notes_Android_Bootloader_SD_Card
99
android/Application_Notes_Android_Dual_Screen
1010
android/Application_Notes_Android_Low_Power
1111
android/Application_Notes_Android_SD_CARD
12+
android/Application_Notes_Android_Secure_Build
1213
android/Application_Notes_Camera
1314
android/Application_Notes_Partitions
1415
android/Application_Notes_Sample_Maps_App
Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
.. _Application_Notes_Android_Secure_Build:
2+
3+
#####################################
4+
Android Secure Build Application Note
5+
#####################################
6+
7+
This page describes how to setup secure Android build.
8+
9+
The process is an example, feel free to adapt following your needs.
10+
11+
.. warning::
12+
13+
This process is only supported with Android user images
14+
15+
Fetching Bootloader, Kernel, and Android
16+
----------------------------------------
17+
18+
- Bootloaders:
19+
20+
.. code-block:: console
21+
22+
$ export YOUR_PATH=~/src/
23+
$ mkdir ${YOUR_PATH}/ti-bootloader-aosp/ && cd $_
24+
$ repo init -u https://git.ti.com/git/android/manifest.git -b android16-release -m releases/RLS_11_00_00_Bootloader.xml
25+
$ repo sync
26+
27+
- Kernel:
28+
29+
.. code-block:: console
30+
31+
$ mkdir ${YOUR_PATH}/ti-kernel-aosp/ && cd $_
32+
$ repo init -u https://git.ti.com/git/android/manifest.git -b android16-release -m releases/RLS_11_00_00_Kernel.xml
33+
$ repo sync
34+
35+
- Android:
36+
37+
.. code-block:: console
38+
39+
$ export YOUR_PATH=~/src/
40+
$ mkdir ${YOUR_PATH}/ti-aosp-16 && cd $_
41+
$ repo init -u https://git.ti.com/git/android/manifest.git -b android16-release -m releases/RLS_11_00_00.xml
42+
$ repo sync
43+
44+
Build Secure Bootloaders
45+
------------------------
46+
47+
- Generate TA cryptographic keys:
48+
49+
.. code-block:: console
50+
51+
$ cd ${YOUR_PATH}/ti-bootloader-aosp/build
52+
$ ./secure.sh generate_ta_keys
53+
$ ls -1 .keys/
54+
ta.key
55+
ta_pub.key
56+
57+
- Generate AVB public/private keys:
58+
59+
.. code-block:: console
60+
61+
$ cd ${YOUR_PATH}/ti-bootloader-aosp/build
62+
$ ./secure.sh generate_avb_keys
63+
$ ls -1 .keys/
64+
avb.key
65+
avb_pub.key
66+
67+
That will generate ``avb.key`` and ``avb_pub.key`` under ``build/.keys``.
68+
69+
The bootloaders scripts will detect that ``avb_pub.key`` is present and will include it into U-Boot.
70+
71+
.. ifconfig:: CONFIG_part_variant in ('AM62X')
72+
73+
The user can also specify the absolute path of the avb_pub key in yaml config (``build/config/boards/am62x-sk.yaml``):
74+
75+
.. ifconfig:: CONFIG_part_variant in ('AM62PX')
76+
77+
The user can also specify the absolute path of the avb_pub key in yaml config (``build/config/boards/am62p-sk.yaml``):
78+
79+
.. code-block:: yaml
80+
81+
secure:
82+
avb_pub_key: ${YOUR_PATH}/ti/avb_pub.key
83+
84+
.. table:: Security Keys
85+
86+
+---------------------+-----------------------------------------------------------------------------+
87+
| Key | Description |
88+
+=====================+=============================================================================+
89+
| ``avb.key`` | (Optional) Private key used by Android to sign images |
90+
+---------------------+-----------------------------------------------------------------------------+
91+
| ``avb_pub.key`` | (Optional) Public key used by U-Boot to verify Android images |
92+
+---------------------+-----------------------------------------------------------------------------+
93+
| ``ta.key`` | (Optional) Private key used to sign Trusted Application (OP-TEE) |
94+
+---------------------+-----------------------------------------------------------------------------+
95+
| ``ta_pub.key`` | (Optional) Public key used to sign Trusted Application (OP-TEE) |
96+
+---------------------+-----------------------------------------------------------------------------+
97+
98+
99+
Build and copy secure images to Android:
100+
101+
.. code-block:: console
102+
103+
$ ./build/release_android.sh --aosp=~${YOUR_PATH}/ti-aosp-16 --mode=factory
104+
105+
.. warning::
106+
107+
By default on factory mode, OP-TEE is built with this flag:
108+
109+
- ``CFG_RPMB_WRITE_KEY``:
110+
111+
This flag configure the RPMB if this one is not initialized yet.
112+
113+
This operation is performed one time only, once the RPMB is initialized with the key we cannot override it anymore.
114+
115+
.. note::
116+
117+
**RPMB corruptions**:
118+
119+
If we do several flashes with different builds, we may be faced with RPMB corruptions.
120+
Indeed some metadata are stored in the RPMB and by default if there is a mismatch OP-TEE fails to load Trusted Applications.
121+
Thus the OP-TEE keymaster service fails and the device doesn't boot.
122+
To avoid this situation we can add the flag ``CFG_REE_FS_ALLOW_RESET=y`` in `build_optee.sh`:
123+
124+
Allow secure storage in the REE FS to be entirely deleted without causing anti-rollback errors.
125+
This is used to reset the secure storage to a clean, empty state.
126+
127+
**Testing Case**:
128+
129+
If you want to test and be sure to reuse RPMB partition you can set ``CFG_RPMB_TESTKEY=y`` in `build_optee.sh`:
130+
131+
OP-TEE can either embed a built-in RPMB key or derive it from platform specific secrets.
132+
The former case might be useful during development while the later is recommended for production devices.
133+
134+
Copy ``avb.key`` in Android:
135+
136+
.. code-block:: console
137+
138+
$ cd ${YOUR_PATH}/ti-bootloader-aosp/build
139+
$ cp .keys/avb.key "${YOUR_PATH}/ti-aosp-16/device/ti/am62x/"
140+
141+
Replace the following configs in ``device/ti/am62x/BoardConfigCommon.mk``::
142+
143+
BOARD_AVB_ALGORITHM := SHA256_RSA4096
144+
BOARD_AVB_KEY_PATH := device/ti/am62x/avb.key
145+
BOARD_AVB_BOOT_KEY_PATH := device/ti/am62x/avb.key
146+
BOARD_AVB_INIT_BOOT_KEY_PATH := device/ti/am62x/avb.key
147+
BOARD_AVB_VBMETA_VENDOR_DLKM_KEY_PATH := device/ti/am62x/avb.key
148+
BOARD_AVB_VBMETA_SYSTEM_DLKM_KEY_PATH := device/ti/am62x/avb.key
149+
150+
151+
Check images generated in Android:
152+
153+
.. code-block:: console
154+
155+
$ cd ~${YOUR_PATH}/ti-aosp-16
156+
$ git status
157+
158+
159+
Build Kernel
160+
------------
161+
162+
Before building Kernel we need to modify it to support RPMB features.
163+
164+
Download patch : :download:`RPMB_enabling.patch <patches/RPMB_enabling.patch>` and put it ``${YOUR_PATH}/ti-kernel-aosp/common`` folder.
165+
166+
Update symbol list and build kernel:
167+
168+
.. code-block:: console
169+
170+
$ cd ${YOUR_PATH}/ti-kernel-aosp/common
171+
$ git am RPMB_enabling.patch
172+
$ cd ${YOUR_PATH}/ti-kernel-aosp/
173+
$ export DIST_DIR=${YOUR_PATH}/ti-aosp-16/device/ti/am62x-kernel/kernel/6.12
174+
$ ./update_symbol_list.sh -d ti -b private/devices/ti/am6x
175+
$ ./tools/bazel run --config=ti //private/devices/ti/am6x:ti_dist -- --destdir=$DIST_DIR
176+
177+
Build Android
178+
-------------
179+
180+
.. ifconfig:: CONFIG_part_variant in ('AM62X')
181+
182+
.. code-block:: console
183+
184+
$ cd ${YOUR_PATH}/ti-aosp-16
185+
$ source build/envsetup.sh
186+
$ lunch am62x-bp2a-user
187+
188+
$ export FACTORY_BUILD=true
189+
$ m -j$(nproc) # OR nice -n19 build/soong/soong_ui.bash --make-mode -j$(nproc)
190+
191+
.. ifconfig:: CONFIG_part_variant in ('AM62PX')
192+
193+
.. code-block:: console
194+
195+
$ cd ${YOUR_PATH}/ti-aosp-16
196+
$ source build/envsetup.sh
197+
$ lunch am62p-bp2a-user
198+
199+
$ export FACTORY_BUILD=true
200+
$ m -j$(nproc) # OR nice -n19 build/soong/soong_ui.bash --make-mode -j$(nproc)
201+
202+
Flash Android
203+
-------------
204+
205+
To reflash on a device which already has Android installed, run:
206+
207+
Reboot to U-Boot
208+
209+
.. code-block:: console
210+
211+
$ adb reboot bootloader
212+
213+
Flash using the script: in a different terminal,
214+
215+
.. ifconfig:: CONFIG_part_variant in ('AM62X')
216+
217+
change directory to ``out/target/product/am62x`` and run the ``flashall.sh`` script:
218+
219+
.. code-block:: console
220+
221+
# for AM62x SK EVM (GP)
222+
$ sudo ./flashall.sh --board am62x-sk
223+
224+
# for AM62x SK EVM (HS-FS)
225+
$ sudo ./flashall.sh --board am62x-sk --hsfs
226+
227+
.. ifconfig:: CONFIG_part_variant in ('AM62PX')
228+
229+
change directory to ``out/target/product/am62p`` and run the ``flashall.sh`` script:
230+
231+
.. code-block:: console
232+
233+
# for AM62P SK EVM
234+
$ sudo ./flashall.sh --board am62px-sk
235+
236+
.. warning::
237+
238+
**Device Locking and Unlock Capability**
239+
240+
After flashing with secure build, the device will be locked and ``fastboot flashing unlock`` commands will be disabled by default.
241+
242+
To enable unlock capability, you have several options:
243+
244+
**Option 1: Enable at compile time**
245+
246+
Set the U-Boot environment variable before compilation:
247+
248+
.. code-block:: console
249+
250+
fastboot.unlock_ability=1
251+
252+
**Option 2: Enable at runtime**
253+
254+
Set the U-Boot environment variable in the console (note that ``saveenv`` is disabled in factory mode, so these settings will be lost at each reboot):
255+
256+
.. code-block:: console
257+
258+
=> setenv fastboot.unlock_ability 1
259+
260+
**Unlock Process**
261+
262+
When running ``fastboot flashing unlock`` or ``fastboot flashing unlock_critical``, the system will prompt for confirmation in the console. To bypass this confirmation prompt, you can set (these settings will also be lost at each reboot):
263+
264+
.. code-block:: console
265+
266+
=> setenv fastboot.unlock_confirm 1
267+
=> setenv fastboot.unlock_critical_confirm 1

source/android/Overview_Building_the_SDK.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ The following build flags are available. **Default** values are **highlighted**.
119119
* - ``TARGET_SDCARD_BOOT``
120120
- **false**/true
121121
- Boot from SD card instead of eMMC
122+
* - ``FACTORY_BUILD``
123+
- **false**/true
124+
- Enable factory build (TA AVB, OEMLock HAL, RPMB support, device lock/unlock support, some security features in keymint). See :ref:`Application_Notes_Android_Secure_Build` for more details.
122125

123126
After building is complete, the necessary images will be available in
124127
:file:`${YOUR_PATH}/ti-aosp-16/out/target/product/am62*/`.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
From 2bda1c49b87eb6b11984c49f5148e4966e3809fe Mon Sep 17 00:00:00 2001
2+
From: Guillaume La Roque <glaroque@baylibre.com>
3+
Date: Wed, 24 Sep 2025 15:41:56 +0200
4+
Subject: [PATCH] arm64: configs: gki_defconfig: enable RPMB support
5+
6+
Enable RPMB support.
7+
8+
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
9+
---
10+
arch/arm64/configs/gki_defconfig | 1 +
11+
1 file changed, 1 insertion(+)
12+
13+
diff --git a/arch/arm64/configs/gki_defconfig b/arch/arm64/configs/gki_defconfig
14+
index 758da1125107..c64b968caeae 100644
15+
--- a/arch/arm64/configs/gki_defconfig
16+
+++ b/arch/arm64/configs/gki_defconfig
17+
@@ -344,6 +344,7 @@ CONFIG_VIRTIO_BLK=m
18+
CONFIG_BLK_DEV_UBLK=y
19+
CONFIG_BLK_DEV_NVME=y
20+
CONFIG_NVME_MULTIPATH=y
21+
+CONFIG_RPMB=y
22+
CONFIG_SRAM=y
23+
CONFIG_SRAM_DMA_HEAP=y
24+
CONFIG_UID_SYS_STATS=y
25+
--
26+
2.34.1
27+

source/devices/AM62PX/android/Application_Notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ Application Notes
1717
/android/Application_Notes_Android_Multimedia_Video
1818
/android/Application_Notes_Sample_Maps_App
1919
/android/Application_Notes_Simple_UI_App
20+
/android/Application_Notes_Android_Secure_Build

source/devices/AM62X/android/Application_Notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ Application Notes
1717
/android/Application_Notes_Simple_UI_App
1818
/android/Application_Notes_Sample_Maps_App
1919
Application_Notes_BeaglePlay
20+
/android/Application_Notes_Android_Secure_Build

0 commit comments

Comments
 (0)