From 5649b31a177f98e0f6601ec03c0e0b4fc0ae07e0 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 22 Mar 2017 08:46:55 -0700 Subject: [PATCH 1/3] fs_config_generate: unit test Test -D and -F flag of fs_config_generate Test: gTest host fs_config-unit-tests Bug: 36071012 Change-Id: I23a655b17b7c55817f2aacc760700ff1b0728db3 --- tools/fs_config/Android.mk | 33 +++++++ .../android_filesystem_config_test_data.h | 40 +++++++++ tools/fs_config/fs_config_generate.c | 4 + tools/fs_config/fs_config_test.cpp | 86 +++++++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 tools/fs_config/android_filesystem_config_test_data.h create mode 100644 tools/fs_config/fs_config_test.cpp diff --git a/tools/fs_config/Android.mk b/tools/fs_config/Android.mk index 65f8a081a2..4a2b566e45 100644 --- a/tools/fs_config/Android.mk +++ b/tools/fs_config/Android.mk @@ -195,3 +195,36 @@ ANDROID_FS_CONFIG_H := my_fs_config_h := fs_config_generate_bin := my_gen_oem_aid := + +# ----------------------------------------------------------------------------- +# Unit tests. +# ----------------------------------------------------------------------------- + +test_c_flags := \ + -fstack-protector-all \ + -g \ + -Wall \ + -Wextra \ + -Werror \ + -fno-builtin \ + -DANDROID_FILESYSTEM_CONFIG='"android_filesystem_config_test_data.h"' + +################################## +# test executable +include $(CLEAR_VARS) +LOCAL_MODULE := fs_config_generate_test +LOCAL_SRC_FILES := fs_config_generate.c +LOCAL_SHARED_LIBRARIES := libcutils +LOCAL_CFLAGS := $(test_c_flags) +LOCAL_MODULE_RELATIVE_PATH := fs_config-unit-tests +LOCAL_GTEST := false +include $(BUILD_HOST_NATIVE_TEST) + +################################## +# gTest tool +include $(CLEAR_VARS) +LOCAL_MODULE := fs_config-unit-tests +LOCAL_CFLAGS += $(test_c_flags) -DHOST +LOCAL_SHARED_LIBRARIES := liblog libcutils libbase +LOCAL_SRC_FILES := fs_config_test.cpp +include $(BUILD_HOST_NATIVE_TEST) diff --git a/tools/fs_config/android_filesystem_config_test_data.h b/tools/fs_config/android_filesystem_config_test_data.h new file mode 100644 index 0000000000..2b98415340 --- /dev/null +++ b/tools/fs_config/android_filesystem_config_test_data.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +/* Test Data */ + +#undef NO_ANDROID_FILESYSTEM_CONFIG_DEVICE_DIRS +#undef NO_ANDROID_FILESYSTEM_CONFIG_DEVICE_FILES + +static const struct fs_path_config android_device_dirs[] = { + {00555, AID_ROOT, AID_SYSTEM, 0, "system/etc"}, + {00555, AID_ROOT, AID_SYSTEM, 0, "vendor/etc"}, + {00555, AID_ROOT, AID_SYSTEM, 0, "oem/etc"}, + {00555, AID_ROOT, AID_SYSTEM, 0, "odm/etc"}, +}; + +static const struct fs_path_config android_device_files[] = { + {00444, AID_ROOT, AID_SYSTEM, 0, "system/etc/fs_config_dirs"}, + {00444, AID_ROOT, AID_SYSTEM, 0, "vendor/etc/fs_config_dirs"}, + {00444, AID_ROOT, AID_SYSTEM, 0, "oem/etc/fs_config_dirs"}, + {00444, AID_ROOT, AID_SYSTEM, 0, "odm/etc/fs_config_dirs"}, + {00444, AID_ROOT, AID_SYSTEM, 0, "system/etc/fs_config_files"}, + {00444, AID_ROOT, AID_SYSTEM, 0, "vendor/etc/fs_config_files"}, + {00444, AID_ROOT, AID_SYSTEM, 0, "oem/etc/fs_config_files"}, + {00444, AID_ROOT, AID_SYSTEM, 0, "odm/etc/fs_config_files"}, +}; diff --git a/tools/fs_config/fs_config_generate.c b/tools/fs_config/fs_config_generate.c index c06213f677..e08642fa45 100644 --- a/tools/fs_config/fs_config_generate.c +++ b/tools/fs_config/fs_config_generate.c @@ -28,7 +28,11 @@ * the binary format used in the /system/etc/fs_config_dirs and * the /system/etc/fs_config_files to be used by the runtimes. */ +#ifdef ANDROID_FILESYSTEM_CONFIG +#include ANDROID_FILESYSTEM_CONFIG +#else #include "android_filesystem_config.h" +#endif #ifdef NO_ANDROID_FILESYSTEM_CONFIG_DEVICE_DIRS static const struct fs_path_config android_device_dirs[] = { diff --git a/tools/fs_config/fs_config_test.cpp b/tools/fs_config/fs_config_test.cpp new file mode 100644 index 0000000000..49e89e32b7 --- /dev/null +++ b/tools/fs_config/fs_config_test.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "android_filesystem_config_test_data.h" + +// must run test in the test directory +const static char fs_config_generate_command[] = "./fs_config_generate_test"; + +static std::string popenToString(std::string command) { + std::string ret; + + FILE* fp = popen(command.c_str(), "r"); + if (fp) { + if (!android::base::ReadFdToString(fileno(fp), &ret)) ret = ""; + pclose(fp); + } + return ret; +} + +static void confirm(std::string&& data, const fs_path_config* config, + ssize_t num_config) { + const struct fs_path_config_from_file* pc = + reinterpret_cast(data.c_str()); + size_t len = data.size(); + + ASSERT_TRUE(config != NULL); + ASSERT_LT(0, num_config); + + while (len > 0) { + uint16_t host_len = pc->len; + if (host_len > len) break; + + EXPECT_EQ(config->mode, pc->mode); + EXPECT_EQ(config->uid, pc->uid); + EXPECT_EQ(config->gid, pc->gid); + EXPECT_EQ(config->capabilities, pc->capabilities); + EXPECT_STREQ(config->prefix, pc->prefix); + + EXPECT_LT(0, num_config); + --num_config; + if (num_config >= 0) ++config; + pc = reinterpret_cast( + reinterpret_cast(pc) + host_len); + len -= host_len; + } + EXPECT_EQ(0, num_config); +} + +/* See local android_filesystem_config.h for test data */ + +TEST(fs_conf_test, dirs) { + confirm(popenToString( + android::base::StringPrintf("%s -D", fs_config_generate_command)), + android_device_dirs, arraysize(android_device_dirs)); +} + +TEST(fs_conf_test, files) { + confirm(popenToString( + android::base::StringPrintf("%s -F", fs_config_generate_command)), + android_device_files, arraysize(android_device_files)); +} From 256d339413a54adeceb505f9d2f062856bcbba43 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 22 Mar 2017 08:46:55 -0700 Subject: [PATCH 2/3] fs_config_generate: add -P option Add a -P option to fs_config_generate that allows us to filter on a comma separated partition whitelist or minus prefixed -blacklist. A partition is defined as accessible as / or system//. No change for legacy, where no -P flag is specified. For system.img, but not vendor, oem or odm file references: fs_config_generate -P -vendor,-oem,-odm For vendor.img file references: fs_config_generate -P vendor For oem.img file references: fs_config_generate -P oem For odm.img file references: fs_config_generate -P odm Add and fortify tests for each of these cases. SideEffects: none Test: gTest host fs_config-unit-test Bug: 36071012 Change-Id: I0537453bb289d41ef98ad76e69f78ae49358a1b3 --- tools/fs_config/README | 23 ++- .../android_filesystem_config_test_data.h | 16 ++ tools/fs_config/fs_config_generate.c | 128 +++++++++++++--- tools/fs_config/fs_config_test.cpp | 137 ++++++++++++++++++ 4 files changed, 284 insertions(+), 20 deletions(-) diff --git a/tools/fs_config/README b/tools/fs_config/README index 99191318ef..5af407f86a 100644 --- a/tools/fs_config/README +++ b/tools/fs_config/README @@ -156,9 +156,28 @@ properties are preserved during runtime operations. The host files in the ${OUT} directory are used in the final stages when building the filesystem images to set the file and directory properties. +For systems with separate partition images, such as vendor or oem, +fs_config_generate can be instructed to filter the specific file references +to land in each partition's etc/fs_config_dirs or etc/fs_config_files +locations. The filter can be instructed to blacklist a partition's data by +providing the comma separated minus sign prefixed partition names. The filter +can be instructed to whitelist partition data by providing the partition name. + +For example: +- For system.img, but not vendor, oem or odm file references: + -P -vendor,-oem,-odm + This makes sure the results only contain content associated with the + system, and not vendor, oem or odm, blacklisting their content. +- For vendor.img file references: -P vendor +- For oem.img file references: -P oem +- For odm.img file references: -P odm + fs_config_generate --help reports: Generate binary content for fs_config_dirs (-D) and fs_config_files (-F) -from device-specific android_filesystem_config.h override +from device-specific android_filesystem_config.h override. Filter based +on a comma separated partition list (-P) whitelist or prefixed by a +minus blacklist. Partitions are identified as path references to +/ or system/ -Usage: fs_config_generate -D|-F [-o output-file] +Usage: fs_config_generate -D|-F [-P list] [-o output-file] diff --git a/tools/fs_config/android_filesystem_config_test_data.h b/tools/fs_config/android_filesystem_config_test_data.h index 2b98415340..07bc8e5efb 100644 --- a/tools/fs_config/android_filesystem_config_test_data.h +++ b/tools/fs_config/android_filesystem_config_test_data.h @@ -26,6 +26,14 @@ static const struct fs_path_config android_device_dirs[] = { {00555, AID_ROOT, AID_SYSTEM, 0, "vendor/etc"}, {00555, AID_ROOT, AID_SYSTEM, 0, "oem/etc"}, {00555, AID_ROOT, AID_SYSTEM, 0, "odm/etc"}, + {00755, AID_SYSTEM, AID_ROOT, 0, "system/oem/etc"}, + {00755, AID_SYSTEM, AID_ROOT, 0, "system/odm/etc"}, + {00755, AID_SYSTEM, AID_ROOT, 0, "system/vendor/etc"}, + {00755, AID_SYSTEM, AID_ROOT, 0, "data/misc"}, + {00755, AID_SYSTEM, AID_ROOT, 0, "oem/data/misc"}, + {00755, AID_SYSTEM, AID_ROOT, 0, "odm/data/misc"}, + {00755, AID_SYSTEM, AID_ROOT, 0, "vendor/data/misc"}, + {00555, AID_SYSTEM, AID_ROOT, 0, "etc"}, }; static const struct fs_path_config android_device_files[] = { @@ -37,4 +45,12 @@ static const struct fs_path_config android_device_files[] = { {00444, AID_ROOT, AID_SYSTEM, 0, "vendor/etc/fs_config_files"}, {00444, AID_ROOT, AID_SYSTEM, 0, "oem/etc/fs_config_files"}, {00444, AID_ROOT, AID_SYSTEM, 0, "odm/etc/fs_config_files"}, + {00644, AID_SYSTEM, AID_ROOT, 0, "system/vendor/etc/fs_config_dirs"}, + {00644, AID_SYSTEM, AID_ROOT, 0, "system/oem/etc/fs_config_dirs"}, + {00644, AID_SYSTEM, AID_ROOT, 0, "system/odm/etc/fs_config_dirs"}, + {00644, AID_SYSTEM, AID_ROOT, 0, "system/vendor/etc/fs_config_files"}, + {00644, AID_SYSTEM, AID_ROOT, 0, "system/oem/etc/fs_config_files"}, + {00644, AID_SYSTEM, AID_ROOT, 0, "system/odm/etc/fs_config_files"}, + {00644, AID_SYSTEM, AID_ROOT, 0, "etc/fs_config_files"}, + {00666, AID_ROOT, AID_SYSTEM, 0, "data/misc/oem"}, }; diff --git a/tools/fs_config/fs_config_generate.c b/tools/fs_config/fs_config_generate.c index e08642fa45..cb7ff9da7e 100644 --- a/tools/fs_config/fs_config_generate.c +++ b/tools/fs_config/fs_config_generate.c @@ -14,9 +14,11 @@ * limitations under the License. */ +#include #include #include #include +#include #include #include @@ -35,35 +37,50 @@ #endif #ifdef NO_ANDROID_FILESYSTEM_CONFIG_DEVICE_DIRS - static const struct fs_path_config android_device_dirs[] = { -}; +static const struct fs_path_config android_device_dirs[] = { }; #endif #ifdef NO_ANDROID_FILESYSTEM_CONFIG_DEVICE_FILES static const struct fs_path_config android_device_files[] = { #ifdef NO_ANDROID_FILESYSTEM_CONFIG_DEVICE_DIRS - { 0, AID_ROOT, AID_ROOT, 0, "system/etc/fs_config_dirs" }, + {0000, AID_ROOT, AID_ROOT, 0, "system/etc/fs_config_dirs"}, + {0000, AID_ROOT, AID_ROOT, 0, "vendor/etc/fs_config_dirs"}, + {0000, AID_ROOT, AID_ROOT, 0, "oem/etc/fs_config_dirs"}, + {0000, AID_ROOT, AID_ROOT, 0, "odm/etc/fs_config_dirs"}, #endif - { 0, AID_ROOT, AID_ROOT, 0, "system/etc/fs_config_files" }, + {0000, AID_ROOT, AID_ROOT, 0, "system/etc/fs_config_files"}, + {0000, AID_ROOT, AID_ROOT, 0, "vendor/etc/fs_config_files"}, + {0000, AID_ROOT, AID_ROOT, 0, "oem/etc/fs_config_files"}, + {0000, AID_ROOT, AID_ROOT, 0, "odm/etc/fs_config_files"}, }; #endif static void usage() { fprintf(stderr, "Generate binary content for fs_config_dirs (-D) and fs_config_files (-F)\n" - "from device-specific android_filesystem_config.h override\n\n" - "Usage: fs_config_generate -D|-F [-o output-file]\n"); + "from device-specific android_filesystem_config.h override. Filter based\n" + "on a comma separated partition list (-P) whitelist or prefixed by a\n" + "minus blacklist. Partitions are identified as path references to\n" + "/ or system//\n\n" + "Usage: fs_config_generate -D|-F [-P list] [-o output-file]\n"); } -int main(int argc, char** argv) { - const struct fs_path_config *pc; - const struct fs_path_config *end; - bool dir = false, file = false; - FILE *fp = stdout; - int opt; +/* If tool switches to C++, use android-base/macros.h array_size() */ +#ifndef ARRAY_SIZE /* popular macro */ +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif - while((opt = getopt(argc, argv, "DFho:")) != -1) { - switch(opt) { +int main(int argc, char** argv) { + const struct fs_path_config* pc; + const struct fs_path_config* end; + bool dir = false, file = false; + const char* partitions = NULL; + FILE* fp = stdout; + int opt; + static const char optstring[] = "DFP:ho:"; + + while ((opt = getopt(argc, argv, optstring)) != -1) { + switch (opt) { case 'D': if (file) { fprintf(stderr, "Must specify only -D or -F\n"); @@ -80,6 +97,30 @@ int main(int argc, char** argv) { } file = true; break; + case 'P': + if (partitions) { + fprintf(stderr, "Specify only one partition list\n"); + usage(); + exit(EXIT_FAILURE); + } + while (*optarg && isspace(*optarg)) ++optarg; + if (!optarg[0]) { + fprintf(stderr, "Partition list empty\n"); + usage(); + exit(EXIT_FAILURE); + } + if (!optarg[1]) { + fprintf(stderr, "Partition list too short \"%s\"\n", optarg); + usage(); + exit(EXIT_FAILURE); + } + if ((optarg[0] == '-') && strchr(optstring, optarg[1]) && !optarg[2]) { + fprintf(stderr, "Partition list is a flag \"%s\"\n", optarg); + usage(); + exit(EXIT_FAILURE); + } + partitions = optarg; + break; case 'o': if (fp != stdout) { fprintf(stderr, "Specify only one output file\n"); @@ -101,6 +142,12 @@ int main(int argc, char** argv) { } } + if (optind < argc) { + fprintf(stderr, "Unknown non-argument \"%s\"\n", argv[optind]); + usage(); + exit(EXIT_FAILURE); + } + if (!file && !dir) { fprintf(stderr, "Must specify either -F or -D\n"); usage(); @@ -109,19 +156,64 @@ int main(int argc, char** argv) { if (dir) { pc = android_device_dirs; - end = &android_device_dirs[sizeof(android_device_dirs) / sizeof(android_device_dirs[0])]; + end = &android_device_dirs[ARRAY_SIZE(android_device_dirs)]; } else { pc = android_device_files; - end = &android_device_files[sizeof(android_device_files) / sizeof(android_device_files[0])]; + end = &android_device_files[ARRAY_SIZE(android_device_files)]; } - for(; (pc < end) && pc->prefix; pc++) { + for (; (pc < end) && pc->prefix; pc++) { + bool submit; char buffer[512]; ssize_t len = fs_config_generate(buffer, sizeof(buffer), pc); if (len < 0) { fprintf(stderr, "Entry too large\n"); exit(EXIT_FAILURE); } - if (fwrite(buffer, 1, len, fp) != (size_t)len) { + submit = true; + if (partitions) { + char* partitions_copy = strdup(partitions); + char* arg = partitions_copy; + char* sv = NULL; /* Do not leave uninitialized, NULL is known safe. */ + /* Deal with case all iterated partitions are blacklists with no match */ + bool all_blacklist_but_no_match = true; + submit = false; + + if (!partitions_copy) { + fprintf(stderr, "Failed to allocate a copy of %s\n", partitions); + exit(EXIT_FAILURE); + } + /* iterate through (officially) comma separated list of partitions */ + while (!!(arg = strtok_r(arg, ",:; \t\n\r\f", &sv))) { + static const char system[] = "system/"; + size_t plen; + bool blacklist = false; + if (*arg == '-') { + blacklist = true; + ++arg; + } else { + all_blacklist_but_no_match = false; + } + plen = strlen(arg); + /* deal with evil callers */ + while (arg[plen - 1] == '/') { + --plen; + } + /* check if we have / or /system// */ + if ((!strncmp(pc->prefix, arg, plen) && (pc->prefix[plen] == '/')) || + (!strncmp(pc->prefix, system, strlen(system)) && + !strncmp(pc->prefix + strlen(system), arg, plen) && + (pc->prefix[strlen(system) + plen] == '/'))) { + all_blacklist_but_no_match = false; + /* we have a match !!! */ + if (!blacklist) submit = true; + break; + } + arg = NULL; + } + free(partitions_copy); + if (all_blacklist_but_no_match) submit = true; + } + if (submit && (fwrite(buffer, 1, len, fp) != (size_t)len)) { fprintf(stderr, "Write failure\n"); exit(EXIT_FAILURE); } diff --git a/tools/fs_config/fs_config_test.cpp b/tools/fs_config/fs_config_test.cpp index 49e89e32b7..f95a4cad6f 100644 --- a/tools/fs_config/fs_config_test.cpp +++ b/tools/fs_config/fs_config_test.cpp @@ -18,9 +18,11 @@ #include #include +#include #include #include +#include #include #include #include @@ -84,3 +86,138 @@ TEST(fs_conf_test, files) { android::base::StringPrintf("%s -F", fs_config_generate_command)), android_device_files, arraysize(android_device_files)); } + +static const char vendor_str[] = "vendor/"; +static const char vendor_alt_str[] = "system/vendor/"; +static const char oem_str[] = "oem/"; +static const char oem_alt_str[] = "system/oem/"; +static const char odm_str[] = "odm/"; +static const char odm_alt_str[] = "system/odm/"; + +TEST(fs_conf_test, system_dirs) { + std::vector dirs; + const fs_path_config* config = android_device_dirs; + for (size_t num = arraysize(android_device_dirs); num; --num) { + if (!android::base::StartsWith(config->prefix, vendor_str) && + !android::base::StartsWith(config->prefix, vendor_alt_str) && + !android::base::StartsWith(config->prefix, oem_str) && + !android::base::StartsWith(config->prefix, oem_alt_str) && + !android::base::StartsWith(config->prefix, odm_str) && + !android::base::StartsWith(config->prefix, odm_alt_str)) { + dirs.emplace_back(*config); + } + ++config; + } + confirm(popenToString(android::base::StringPrintf( + "%s -D -P -vendor,-oem,-odm", fs_config_generate_command)), + &dirs[0], dirs.size()); +} + +TEST(fs_conf_test, vendor_dirs) { + std::vector dirs; + const fs_path_config* config = android_device_dirs; + for (size_t num = arraysize(android_device_dirs); num; --num) { + if (android::base::StartsWith(config->prefix, vendor_str) || + android::base::StartsWith(config->prefix, vendor_alt_str)) { + dirs.emplace_back(*config); + } + ++config; + } + confirm(popenToString(android::base::StringPrintf( + "%s -D -P vendor", fs_config_generate_command)), + &dirs[0], dirs.size()); +} + +TEST(fs_conf_test, oem_dirs) { + std::vector dirs; + const fs_path_config* config = android_device_dirs; + for (size_t num = arraysize(android_device_dirs); num; --num) { + if (android::base::StartsWith(config->prefix, oem_str) || + android::base::StartsWith(config->prefix, oem_alt_str)) { + dirs.emplace_back(*config); + } + ++config; + } + confirm(popenToString(android::base::StringPrintf( + "%s -D -P oem", fs_config_generate_command)), + &dirs[0], dirs.size()); +} + +TEST(fs_conf_test, odm_dirs) { + std::vector dirs; + const fs_path_config* config = android_device_dirs; + for (size_t num = arraysize(android_device_dirs); num; --num) { + if (android::base::StartsWith(config->prefix, odm_str) || + android::base::StartsWith(config->prefix, odm_alt_str)) { + dirs.emplace_back(*config); + } + ++config; + } + confirm(popenToString(android::base::StringPrintf( + "%s -D -P odm", fs_config_generate_command)), + &dirs[0], dirs.size()); +} + +TEST(fs_conf_test, system_files) { + std::vector files; + const fs_path_config* config = android_device_files; + for (size_t num = arraysize(android_device_files); num; --num) { + if (!android::base::StartsWith(config->prefix, vendor_str) && + !android::base::StartsWith(config->prefix, vendor_alt_str) && + !android::base::StartsWith(config->prefix, oem_str) && + !android::base::StartsWith(config->prefix, oem_alt_str) && + !android::base::StartsWith(config->prefix, odm_str) && + !android::base::StartsWith(config->prefix, odm_alt_str)) { + files.emplace_back(*config); + } + ++config; + } + confirm(popenToString(android::base::StringPrintf( + "%s -F -P -vendor,-oem,-odm", fs_config_generate_command)), + &files[0], files.size()); +} + +TEST(fs_conf_test, vendor_files) { + std::vector files; + const fs_path_config* config = android_device_files; + for (size_t num = arraysize(android_device_files); num; --num) { + if (android::base::StartsWith(config->prefix, vendor_str) || + android::base::StartsWith(config->prefix, vendor_alt_str)) { + files.emplace_back(*config); + } + ++config; + } + confirm(popenToString(android::base::StringPrintf( + "%s -F -P vendor", fs_config_generate_command)), + &files[0], files.size()); +} + +TEST(fs_conf_test, oem_files) { + std::vector files; + const fs_path_config* config = android_device_files; + for (size_t num = arraysize(android_device_files); num; --num) { + if (android::base::StartsWith(config->prefix, oem_str) || + android::base::StartsWith(config->prefix, oem_alt_str)) { + files.emplace_back(*config); + } + ++config; + } + confirm(popenToString(android::base::StringPrintf( + "%s -F -P oem", fs_config_generate_command)), + &files[0], files.size()); +} + +TEST(fs_conf_test, odm_files) { + std::vector files; + const fs_path_config* config = android_device_files; + for (size_t num = arraysize(android_device_files); num; --num) { + if (android::base::StartsWith(config->prefix, odm_str) || + android::base::StartsWith(config->prefix, odm_alt_str)) { + files.emplace_back(*config); + } + ++config; + } + confirm(popenToString(android::base::StringPrintf( + "%s -F -P odm", fs_config_generate_command)), + &files[0], files.size()); +} From 1fd588cfb241cd05b00332d9bc98c9dd0b9b5f06 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 22 Mar 2017 15:53:12 -0700 Subject: [PATCH 3/3] fs_config_generator: Add fs_config_(dirs|files)_(vendor|oem|odm) Add build targets to generate the vendor, oem and odm slices of the fs_config_dirs and fs_config_files targets for each of the respective filesystems, and automatically trigger the individual and enabled partition build objects based as dependents of fs_config_dirs and fs_config_files. Sensitive to the following board definition pairs: BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE BOARD_USES_VENDORIMAGE BOARD_OEMIMAGE_FILE_SYSTEM_TYPE BOARD_USES_OEMIMAGE BOARD_ODMIMAGE_FILE_SYSTEM_TYPE BOARD_USES_ODMIMAGE Which when defined and set means the images are generated for vendor, oem or odm respectively. Test: manually build w/ m 'fs_config_(dirs|files)_(vendor|oem|odm)' and check the expected products, or fails if not pertinent. Test: build for product that produces split to system and vendor and subsequently boots with vendor products correctly configured. Bug: 36071012 Change-Id: I44289a3dd50b7657367c826ad813c671a3de6afc --- tools/fs_config/Android.mk | 114 ++++++++++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 2 deletions(-) diff --git a/tools/fs_config/Android.mk b/tools/fs_config/Android.mk index 4a2b566e45..7e5c88e8c2 100644 --- a/tools/fs_config/Android.mk +++ b/tools/fs_config/Android.mk @@ -113,6 +113,11 @@ LOCAL_C_INCLUDES := $(dir $(my_fs_config_h)) $(dir $(my_gen_oem_aid)) include $(BUILD_HOST_EXECUTABLE) fs_config_generate_bin := $(LOCAL_INSTALLED_MODULE) +# List of all supported vendor, oem and odm Partitions +fs_config_generate_extra_partition_list := $(strip \ + $(if $(BOARD_USES_VENDORIMAGE)$(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE),vendor) \ + $(if $(BOARD_USES_OEMIMAGE)$(BOARD_OEMIMAGE_FILE_SYSTEM_TYPE),oem) \ + $(if $(BOARD_USES_ODMIMAGE)$(BOARD_ODMIMAGE_FILE_SYSTEM_TYPE),odm)) ################################## # Generate the system/etc/fs_config_dirs binary file for the target @@ -121,10 +126,13 @@ include $(CLEAR_VARS) LOCAL_MODULE := fs_config_dirs LOCAL_MODULE_CLASS := ETC +LOCAL_REQUIRED_MODULES := $(foreach t,$(fs_config_generate_extra_partion_list),$(LOCAL_MODULE)_$(t)) include $(BUILD_SYSTEM)/base_rules.mk $(LOCAL_BUILT_MODULE): $(fs_config_generate_bin) @mkdir -p $(dir $@) - $< -D -o $@ + $< -D $(if $(fs_config_generate_extra_partition_list), \ + -P '$(subst $(space),$(comma),$(addprefix -,$(fs_config_generate_extra_partition_list)))') \ + -o $@ ################################## # Generate the system/etc/fs_config_files binary file for the target @@ -133,10 +141,112 @@ include $(CLEAR_VARS) LOCAL_MODULE := fs_config_files LOCAL_MODULE_CLASS := ETC +LOCAL_REQUIRED_MODULES := $(foreach t,$(fs_config_generate_extra_partion_list),$(LOCAL_MODULE)_$(t)) include $(BUILD_SYSTEM)/base_rules.mk $(LOCAL_BUILT_MODULE): $(fs_config_generate_bin) @mkdir -p $(dir $@) - $< -F -o $@ + $< -F $(if $(fs_config_generate_extra_partition_list), \ + -P '$(subst $(space),$(comma),$(addprefix -,$(fs_config_generate_extra_partition_list)))') \ + -o $@ + +ifneq ($(filter vendor,$(fs_config_generate_extra_partition_list)),) +################################## +# Generate the vendor/etc/fs_config_dirs binary file for the target +# Add fs_config_dirs or fs_config_dirs_vendor to PRODUCT_PACKAGES in +# the device make file to enable. +include $(CLEAR_VARS) + +LOCAL_MODULE := fs_config_dirs_vendor +LOCAL_MODULE_CLASS := ETC +LOCAL_INSTALLED_MODULE_STEM := fs_config_dirs +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc +include $(BUILD_SYSTEM)/base_rules.mk +$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin) + @mkdir -p $(dir $@) + $< -D -P vendor -o $@ + +################################## +# Generate the vendor/etc/fs_config_files binary file for the target +# Add fs_config_files or fs_config_files_vendor to PRODUCT_PACKAGES in +# the device make file to enable +include $(CLEAR_VARS) + +LOCAL_MODULE := fs_config_files_vendor +LOCAL_MODULE_CLASS := ETC +LOCAL_INSTALLED_MODULE_STEM := fs_config_files +LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc +include $(BUILD_SYSTEM)/base_rules.mk +$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin) + @mkdir -p $(dir $@) + $< -F -P vendor -o $@ + +endif + +ifneq ($(filter oem,$(fs_config_generate_extra_partition_list)),) +################################## +# Generate the oem/etc/fs_config_dirs binary file for the target +# Add fs_config_dirs or fs_config_dirs_oem to PRODUCT_PACKAGES in +# the device make file to enable +include $(CLEAR_VARS) + +LOCAL_MODULE := fs_config_dirs_oem +LOCAL_MODULE_CLASS := ETC +LOCAL_INSTALLED_MODULE_STEM := fs_config_dirs +LOCAL_MODULE_PATH := $(TARGET_OUT_OEM)/etc +include $(BUILD_SYSTEM)/base_rules.mk +$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin) + @mkdir -p $(dir $@) + $< -D -P oem -o $@ + +################################## +# Generate the oem/etc/fs_config_files binary file for the target +# Add fs_config_files or fs_config_files_oem to PRODUCT_PACKAGES in +# the device make file to enable +include $(CLEAR_VARS) + +LOCAL_MODULE := fs_config_files_oem +LOCAL_MODULE_CLASS := ETC +LOCAL_INSTALLED_MODULE_STEM := fs_config_files +LOCAL_MODULE_PATH := $(TARGET_OUT_OEM)/etc +include $(BUILD_SYSTEM)/base_rules.mk +$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin) + @mkdir -p $(dir $@) + $< -F -P oem -o $@ + +endif + +ifneq ($(filter odm,$(fs_config_generate_extra_partition_list)),) +################################## +# Generate the odm/etc/fs_config_dirs binary file for the target +# Add fs_config_dirs or fs_config_dirs_odm to PRODUCT_PACKAGES in +# the device make file to enable +include $(CLEAR_VARS) + +LOCAL_MODULE := fs_config_dirs_odm +LOCAL_MODULE_CLASS := ETC +LOCAL_INSTALLED_MODULE_STEM := fs_config_dirs +LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/etc +include $(BUILD_SYSTEM)/base_rules.mk +$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin) + @mkdir -p $(dir $@) + $< -D -P odm -o $@ + +################################## +# Generate the odm/etc/fs_config_files binary file for the target +# Add fs_config_files of fs_config_files_odm to PRODUCT_PACKAGES in +# the device make file to enable +include $(CLEAR_VARS) + +LOCAL_MODULE := fs_config_files_odm +LOCAL_MODULE_CLASS := ETC +LOCAL_INSTALLED_MODULE_STEM := fs_config_files +LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/etc +include $(BUILD_SYSTEM)/base_rules.mk +$(LOCAL_BUILT_MODULE): $(fs_config_generate_bin) + @mkdir -p $(dir $@) + $< -F -P odm -o $@ + +endif # The newer passwd/group targets are only generated if you # use the new TARGET_FS_CONFIG_GEN method.