diff options
author | Florian Mayer <fmayer@google.com> | 2022-10-31 15:58:18 -0700 |
---|---|---|
committer | Florian Mayer <fmayer@google.com> | 2022-11-01 15:29:31 -0700 |
commit | 6325c52ed092f5f0284d353b7ac1795e90191be4 (patch) | |
tree | 9e4cdd3e19848ddc570b90564308ce004502a4ba /mtectrl | |
parent | 56f1b53b09819836976e1228eec8cce5566c61a4 (diff) | |
download | extras-6325c52ed092f5f0284d353b7ac1795e90191be4.tar.gz |
[mtectrl] Add more comments
Change-Id: I2f775f7e784301678b22fb92a7c29156d4c9d65c
Diffstat (limited to 'mtectrl')
-rw-r--r-- | mtectrl/mtectrl.cc | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/mtectrl/mtectrl.cc b/mtectrl/mtectrl.cc index ba6cea0b..bea12a6c 100644 --- a/mtectrl/mtectrl.cc +++ b/mtectrl/mtectrl.cc @@ -57,10 +57,50 @@ bool UpdateProp(const char* prop_name, const misc_memtag_message& m) { } void PrintUsage(const char* progname) { - std::cerr << "Usage: " << progname - << " [-s PROPERTY_NAME] none|memtag|memtag-once|memtag-kernel|memtag-kernel-once[,.." - ".] [default|force_on|force_off]\n" - << " " << progname << " -s PROPERTY_NAME\n"; + std::cerr + << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" + "!!! YOU PROBABLY DO NOT NEED TO USE THIS !!!\n" + "!!! USE THE `arm64.memtag.bootctl` SYSTEM PROPERTY INSTEAD. !!!\n" + "!!! This program is an implementation detail that is used !!!\n" + "!!! by the system to apply MTE settings. !!!\n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" + "\n" + << "USAGE: " << progname + << "\n" + " [-s PROPERTY_NAME]\n" + " [none,][memtag,][memtag-once,][memtag-kernel,][memtag-kernel-once,][memtag-off,]\n" + " [default|force_on|force_off]\n" + " [-t PATH_TO_FAKE_MISC_PARTITION]\n" + + "OPTIONS:\n" + " -s PROPERTY_NAME\n" + " Sets the system property 'PROPERTY_NAME' to the new MTE mode (if provided), or to\n" + " the current value from the /misc partition.\n" + " [none,][memtag,][memtag-once,][memtag-kernel,][memtag-kernel-once,][memtag-off,]\n" + " A set of MTE options to be applied, if provided. Multiple options may be\n" + " specified as a ','-delimited list, e.g. 'memtag,memtag-kernel'.\n" + " The options are described below:\n" + " - none: default settings for MTE for the product will be applied on next\n" + " reboot.\n" + " - memtag: MTE is persistently enabled in userspace upon the next reboot.\n" + " - memtag-once: MTE is enabled in userspace, only for the next reboot.\n" + " - memtag-kernel: MTE is persistently enabled in the kernel upon the next \n" + " reboot.\n" + " - memtag-kernel-once: MTE is enabled in the kernel, only for the next reboot.\n" + " - memtag-off: MTE is persistently disabled in both userspace and kernel upon \n" + " the next reboot.\n" + " [default|force_on|force_off]\n" + " An alternative method of configuring the MTE options to be applied, if provided.\n" + " This control is generally to be used by device_config only, and it overwrites\n" + " the previously described settings that are expected to be utilized by the user.\n" + " The options are described below:\n" + " - default: This flag is not overwriting the MTE mode, and so the setting\n" + " should be inherited from the userspace controls (if present), or the\n" + " default value from the bootloader's ROM.\n" + " - force_on: MTE is persistently enabled in userspace, overwriting the userspace\n" + " setting.\n" + " - force_off: MTE is persistently disabled in userspace and the kernel, \n" + " overwriting the userspace setting.\n"; } int StringToMode(const char* value) { @@ -110,6 +150,12 @@ int main(int argc, char** argv) { while ((opt = getopt(argc, argv, "s:t:")) != -1) { switch (opt) { case 's': + // Set property in argument to state of misc partition. If given by + // itself, sets the property to the current state. We do this on device + // boot, + // + // Otherwise, applies new state and then sets property to newly applied + // state. set_prop = optarg; break; case 't': { @@ -144,6 +190,8 @@ int main(int argc, char** argv) { } if (!value && set_prop) { + // -s <property> is given on its own. This means we want to read the state + // of the misc partition into the property. std::string err; misc_memtag_message m = {}; if (!read_memtag_message(&m, &err)) { @@ -156,8 +204,8 @@ int main(int argc, char** argv) { // This is an expected case, as the partition gets initialized to all zero. return 0; } - // UpdateProp failing is an unexpected case, as a message with a valid - // header should not have an invalid memtag_mode. + // Unlike above, setting the system property here can fail if the misc partition + // was corrupted by another program (e.g. the bootloader). return UpdateProp(set_prop, m) ? 0 : 1; } |