1#!/bin/bash
2
3# Copyright (C) 2021 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17set -e
18
19if [ -z "${ANDROID_BUILD_TOP}" ]; then
20    WD="$(pwd)"
21else
22    WD="${ANDROID_BUILD_TOP}"
23fi
24if [ -z "${OUT_DIR}" ]; then
25    OUT_DIR="${WD}/out"
26fi
27
28function download_project() {
29  local branch=$1
30  local target=$2
31  shift 2
32  local file_list=("$@")
33
34  local bid_file="${WD}/prebuilts/build-artifacts3/aosp_kernel-common-${branch}/${target}/bid"
35  local bid=$(<$bid_file)
36  local download_url="https://ci.android.com/builds/submitted/${bid}/${target}/latest/raw"
37  local dist_base="${OUT_DIR}/prebuilt_cached/artifacts/common-${branch//./_}-${target}"
38
39  mkdir -p "$dist_base"
40  for f in "${file_list[@]}"; do
41    wget "${download_url}/${f}" -O "${dist_base}/${f}"
42  done
43}
44
45function download-android12-5.10-kernel_aarch64() {
46  local file_list=(
47    "BUILD_INFO"
48    "Image"
49    "Image.lz4"
50    "System.map"
51    "vmlinux"
52    "vmlinux.symvers"
53    "modules.builtin"
54    "modules.builtin.modinfo"
55  )
56
57  download_project "android12-5.10" "kernel_aarch64" "${file_list[@]}"
58}
59
60function download-android12-5.10-kernel_debug_aarch64() {
61  local file_list=(
62    "BUILD_INFO"
63    "Image"
64    "Image.lz4"
65    "System.map"
66    "vmlinux"
67    "vmlinux.symvers"
68    "modules.builtin"
69    "modules.builtin.modinfo"
70  )
71
72  download_project "android12-5.10" "kernel_debug_aarch64" "${file_list[@]}"
73}
74
75function download-android12-5.10-kernel_x86_64() {
76  local file_list=(
77    "BUILD_INFO"
78    "bzImage"
79    "System.map"
80    "vmlinux"
81    "vmlinux.symvers"
82    "modules.builtin"
83    "modules.builtin.modinfo"
84  )
85
86  download_project "android12-5.10" "kernel_x86_64" "${file_list[@]}"
87}
88
89function download-android12-5.10-kernel_debug_x86_64() {
90  local file_list=(
91    "BUILD_INFO"
92    "bzImage"
93    "System.map"
94    "vmlinux"
95    "vmlinux.symvers"
96    "modules.builtin"
97    "modules.builtin.modinfo"
98  )
99
100  download_project "android12-5.10" "kernel_debug_x86_64" "${file_list[@]}"
101}
102
103function download-android12-5.10-kernel_virt_aarch64() {
104  local file_list=(
105    "BUILD_INFO"
106    "initramfs.img"
107  )
108
109  download_project "android12-5.10" "kernel_virt_aarch64" "${file_list[@]}"
110}
111
112function download-android12-5.10-kernel_virt_x86_64() {
113  local file_list=(
114    "BUILD_INFO"
115    "initramfs.img"
116  )
117
118  download_project "android12-5.10" "kernel_virt_x86_64" "${file_list[@]}"
119}
120
121download-android12-5.10-kernel_aarch64
122download-android12-5.10-kernel_debug_aarch64
123download-android12-5.10-kernel_x86_64
124download-android12-5.10-kernel_debug_x86_64
125download-android12-5.10-kernel_virt_aarch64
126download-android12-5.10-kernel_virt_x86_64
127