1package {
2    default_applicable_licenses: ["Android-Apache-2.0"],
3}
4
5microdroid_shell_and_utilities = [
6    "reboot",
7    "sh",
8    "toolbox",
9    "toybox",
10]
11
12microdroid_rootdirs = [
13    "dev",
14    "proc",
15    "sys",
16
17    "system",
18    "vendor",
19    "debug_ramdisk",
20    "mnt",
21    "data",
22
23    "apex",
24    "linkerconfig",
25    "second_stage_resources",
26    "postinstall",
27]
28
29microdroid_symlinks = [
30    {
31        target: "/sys/kernel/debug",
32        name: "d",
33    },
34    {
35        target: "/system/etc",
36        name: "etc",
37    },
38]
39
40android_system_image {
41    name: "microdroid",
42    use_avb: true,
43    avb_private_key: ":avb_testkey_rsa4096",
44    avb_algorithm: "SHA256_RSA4096",
45    partition_name: "system",
46    deps: [
47        "init_second_stage",
48        "microdroid_init_rc",
49        "microdroid_build_prop",
50        "ueventd.rc",
51        "libbinder",
52        "libstdc++",
53        "logcat",
54        "logd",
55        "run-as",
56        "secilc",
57
58        // "com.android.adbd" requires these,
59        "libadbd_auth",
60        "libadbd_fs",
61
62        // "com.android.art" requires
63        "heapprofd_client_api",
64
65        "apexd",
66        "debuggerd",
67        "linker",
68        "linkerconfig",
69        "servicemanager",
70        "tombstoned",
71        "cgroups.json",
72        "public.libraries.android.txt",
73
74        "plat_sepolicy_and_mapping.sha256",
75    ] + microdroid_shell_and_utilities,
76    multilib: {
77        common: {
78            deps: [
79                "com.android.runtime",
80                "plat_sepolicy.cil",
81                "plat_mapping_file",
82                "plat_file_contexts",
83                "plat_hwservice_contexts",
84                "plat_property_contexts",
85                "plat_service_contexts",
86                "plat_keystore2_key_contexts",
87            ],
88        },
89    },
90    linker_config_src: "linker.config.json",
91    base_dir: "system",
92    dirs: microdroid_rootdirs,
93    symlinks: microdroid_symlinks,
94    file_contexts: "microdroid_file_contexts",
95}
96
97prebuilt_etc {
98    name: "microdroid_init_rc",
99    filename: "init.rc",
100    src: "init.rc",
101    relative_install_path: "init/hw",
102    installable: false, // avoid collision with system partition's init.rc
103}
104
105prebuilt_root {
106    name: "microdroid_build_prop",
107    filename: "build.prop",
108    src: "build.prop",
109    installable: false,
110}
111
112android_filesystem {
113    name: "microdroid_vendor",
114    use_avb: true,
115    deps: [
116        "microdroid_fstab",
117        "microdroid_precompiled_sepolicy",
118        "microdroid_precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
119    ],
120    multilib: {
121        common: {
122            deps: [
123                "microdroid_vendor_sepolicy.cil",
124                "microdroid_plat_pub_versioned.cil",
125                "microdroid_plat_sepolicy_vers.txt",
126            ],
127        },
128    },
129    avb_private_key: ":avb_testkey_rsa4096",
130    avb_algorithm: "SHA256_RSA4096",
131    file_contexts: "microdroid_vendor_file_contexts",
132}
133
134logical_partition {
135    name: "microdroid_super",
136    sparse: true,
137    size: "auto",
138    default_group: [
139        {
140            name: "system",
141            filesystem: ":microdroid",
142        },
143        {
144            name: "vendor",
145            filesystem: ":microdroid_vendor",
146        },
147    ],
148}
149
150// TODO(jiyong): change the name to init, cause it's confusing
151microdroid_boot_cmdline = "rdinit=/bin/init_vendor " +
152    "panic=-1 " +
153    // TODO(b/181936135) make the ratelimiting conditional; ratelimiting on prod build
154    "printk.devkmsg=on " +
155    "androidboot.first_stage_console=1 " +
156    "androidboot.hardware=microdroid "
157
158bootimg {
159    name: "microdroid_boot-5.10",
160    ramdisk_module: "microdroid_ramdisk-5.10",
161    // We don't have kernel for arm and x86. But Soong demands one when it builds for
162    // arm or x86 target. Satisfy that by providing an empty file as the kernel.
163    kernel_prebuilt: "empty_kernel",
164    arch: {
165        arm64: {
166            kernel_prebuilt: ":kernel_prebuilts-5.10-arm64",
167            cmdline: microdroid_boot_cmdline +
168                "androidboot.boot_devices=10000.pci",
169        },
170        x86_64: {
171            kernel_prebuilt: ":kernel_prebuilts-5.10-x86_64",
172            cmdline: microdroid_boot_cmdline +
173                "pci=noacpi " +
174                "androidboot.boot_devices=pci0000:00/0000:00:01.0," + // os
175                "pci0000:00/0000:00:03.0," + // payload
176                "pci0000:00/0000:00:04.0", // userdata
177        },
178    },
179    dtb_prebuilt: "dummy_dtb.img",
180    header_version: "4",
181    partition_name: "boot",
182    use_avb: true,
183    avb_private_key: ":avb_testkey_rsa4096",
184}
185
186android_filesystem {
187    name: "microdroid_ramdisk-5.10",
188    deps: [
189        "init_first_stage_soong",
190    ],
191    dirs: [
192        "dev",
193        "proc",
194        "sys",
195
196        // TODO(jiyong): remove these
197        "mnt",
198        "debug_ramdisk",
199        "second_stage_resources",
200    ],
201    type: "compressed_cpio",
202}
203
204bootimg {
205    name: "microdroid_vendor_boot-5.10",
206    ramdisk_module: "microdroid_vendor_ramdisk-5.10",
207    dtb_prebuilt: "dummy_dtb.img",
208    header_version: "4",
209    vendor_boot: true,
210    partition_name: "vendor_boot",
211    use_avb: true,
212    avb_private_key: ":avb_testkey_rsa4096",
213}
214
215android_filesystem {
216    name: "microdroid_vendor_ramdisk-5.10",
217    arch: {
218        arm64: {
219            deps: ["virt_device_prebuilts_kernel_modules-5.10-arm64"],
220        },
221        x86_64: {
222            deps: ["virt_device_prebuilts_kernel_modules-5.10-x86_64"],
223        },
224    },
225    deps: [
226        "microdroid_fstab",
227    ],
228    base_dir: "first_stage_ramdisk",
229    type: "compressed_cpio",
230    symlinks: [
231        {
232            target: "etc/fstab",
233            name: "first_stage_ramdisk/fstab.microdroid",
234        },
235        {
236            target: "first_stage_ramdisk/lib",
237            name: "lib",
238        },
239    ],
240}
241
242prebuilt_etc {
243    name: "microdroid_fstab",
244    src: "fstab",
245    filename: "fstab",
246    installable: false,
247}
248
249prebuilt_etc {
250    name: "microdroid_bootloader",
251    src: ":microdroid_bootloader_gen",
252    arch: {
253        x86_64: {
254            // For unknown reason, the signed bootloader doesn't work on x86_64. Until the problem
255            // is fixed, let's use the unsigned bootloader for the architecture.
256            // TODO(b/185115783): remove this
257            src: ":cuttlefish_crosvm_bootloader",
258        },
259    },
260    filename: "microdroid_bootloader",
261}
262
263// See external/avb/avbtool.py
264// MAX_VBMETA_SIZE=64KB, MAX_FOOTER_SIZE=4KB
265avb_hash_footer_kb = "68"
266
267genrule {
268    name: "microdroid_bootloader_gen",
269    tools: ["avbtool"],
270    srcs: [
271        ":cuttlefish_crosvm_bootloader",
272        ":avb_testkey_rsa4096",
273    ],
274    out: ["bootloader-signed"],
275    // 1. Copy the input to the output becaise avbtool modifies --image in
276    // place.
277    // 2. Check if the file is big enough. For arm and x86 we have fake
278    // bootloader file whose size is 1. It can't pass avbtool.
279    // 3. Add the hash footer. The partition size is set to (image size + 68KB)
280    // rounded up to 4KB boundary.
281    cmd: "cp $(location :cuttlefish_crosvm_bootloader) $(out) && " +
282        "if [ $$(stat --format=%s $(out)) -gt 4096 ]; then " +
283        "$(location avbtool) add_hash_footer " +
284        "--algorithm SHA256_RSA4096 " +
285        "--partition_name bootloader " +
286        "--key $(location :avb_testkey_rsa4096) " +
287        "--partition_size $$(( " + avb_hash_footer_kb + " * 1024 + ( $$(stat --format=%s $(out)) + 4096 - 1 ) / 4096 * 4096 )) " +
288        "--image $(out)" +
289        "; fi",
290}
291
292prebuilt_etc {
293    name: "microdroid_uboot_env",
294    src: ":microdroid_uboot_env_gen",
295    arch: {
296        x86_64: {
297            src: ":microdroid_uboot_env_gen_x86_64",
298        },
299    },
300    filename: "uboot_env.img",
301}
302
303genrule {
304    name: "microdroid_uboot_env_gen",
305    tools: ["mkenvimage_host"],
306    srcs: ["uboot-env.txt"],
307    out: ["output.img"],
308    cmd: "$(location mkenvimage_host) -s 4096 -o $(out) $(in)",
309}
310
311genrule {
312    name: "microdroid_uboot_env_gen_x86_64",
313    tools: ["mkenvimage_host"],
314    srcs: ["uboot-env-x86_64.txt"],
315    out: ["output.img"],
316    cmd: "$(location mkenvimage_host) -s 4096 -o $(out) $(in)",
317}
318
319// sepolicy sha256 for vendor
320prebuilt_etc {
321    name: "microdroid_precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
322    src: ":plat_sepolicy_and_mapping.sha256_gen",
323    filename: "precompiled_sepolicy.plat_sepolicy_and_mapping.sha256",
324    relative_install_path: "selinux",
325    installable: false,
326}
327
328genrule {
329    name: "microdroid_precompiled_sepolicy_gen",
330    tools: ["secilc"],
331    srcs: [
332        ":plat_sepolicy.cil",
333        ":plat_mapping_file",
334        ":microdroid_plat_pub_versioned.cil",
335        ":microdroid_vendor_sepolicy.cil",
336    ],
337    out: ["precompiled_sepolicy"],
338    cmd: "$(location secilc) -m -M true -G -c 30 $(in) -o $(out) -f /dev/null",
339}
340
341prebuilt_etc {
342    name: "microdroid_precompiled_sepolicy",
343    src: ":microdroid_precompiled_sepolicy_gen",
344    filename: "precompiled_sepolicy",
345    relative_install_path: "selinux",
346    installable: false,
347}
348
349vbmeta {
350    name: "microdroid_vbmeta",
351    partition_name: "vbmeta",
352    private_key: ":avb_testkey_rsa4096",
353    partitions: [
354        "microdroid_vendor",
355        "microdroid_vendor_boot-5.10",
356    ],
357    chained_partitions: [
358        {
359            name: "vbmeta_system",
360            rollback_index_location: 1,
361            private_key: ":avb_testkey_rsa4096",
362        },
363        {
364            name: "boot",
365            rollback_index_location: 2,
366            private_key: ":avb_testkey_rsa4096",
367        },
368    ],
369}
370
371vbmeta {
372    name: "microdroid_vbmeta_system",
373    partition_name: "vbmeta_system",
374    private_key: ":avb_testkey_rsa4096",
375    partitions: [
376        "microdroid",
377    ],
378}
379
380prebuilt_etc {
381    name: "microdroid_cdisk.json",
382    src: "microdroid_cdisk.json",
383}
384
385prebuilt_etc {
386    name: "microdroid_cdisk_env.json",
387    src: "microdroid_cdisk_env.json",
388}
389
390prebuilt_etc {
391    name: "microdroid_cdisk_userdata.json",
392    src: "microdroid_cdisk_userdata.json",
393}
394
395prebuilt_etc {
396    name: "microdroid_payload.json",
397    src: "microdroid_payload.json",
398}
399