• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <android-base/logging.h>
18 #include <android-base/strings.h>
19 #include <bootloader_message/bootloader_message.h>
20 
21 #include <iostream>
22 
main(int argc,char ** argv)23 int main(int argc, char** argv) {
24   if (argc != 2) {
25     std::cerr
26         << "Usage: " << argv[0]
27         << " [none|memtag|memtag_once|memtag_kernel|memtag_kernel_once]\n";
28     return 1;
29   }
30   std::string value = argv[1];
31   misc_memtag_message m = {.version = MISC_MEMTAG_MESSAGE_VERSION,
32                            .magic = MISC_MEMTAG_MAGIC_HEADER};
33   for (const auto& field : android::base::Split(value, ",")) {
34     if (field == "memtag") {
35       m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG;
36     } else if (field == "memtag-once") {
37       m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG_ONCE;
38     } else if (field == "memtag-kernel") {
39       m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG_KERNEL;
40     } else if (field == "memtag-kernel-once") {
41       m.memtag_mode |= MISC_MEMTAG_MODE_MEMTAG_KERNEL_ONCE;
42     } else if (field != "none") {
43       LOG(ERROR) << "Unknown value for arm64.memtag.bootctl: " << field;
44       return 1;
45     }
46   }
47   std::string err;
48   if (!WriteMiscMemtagMessage(m, &err)) {
49     LOG(ERROR) << "Failed to apply arm64.memtag.bootctl: " << value << ". "
50                << err;
51     return 1;
52   } else {
53     LOG(INFO) << "Applied arm64.memtag.bootctl: " << value;
54     return 0;
55   }
56 }
57