Commit graph

37 commits

Author SHA1 Message Date
Tom Cherry
96e5f9b5b8 Allow mapping of raw block devices to partition names
Allow mapping of raw block devices (those without a partition table)
to partition names for first stage mount and ueventd.  For example, a
block device `vdb` that contains only an ext4 metadata partition could
be mapped to `metadata` such that /dev/block/by-name/metadata is
created.

The mapping is provided by the `androidboot.partition_map` bootconfig
or kernel command line parameter.

Bug: 159943320
Test: boot with raw vdb,metadata;vdc,userdata partitions
Change-Id: Ib6a939d6fb88b85c46c81d613425a127627a734b
2021-07-30 10:35:58 -07:00
Tom Cherry
47031c8c88 ueventd: add no_fnm_pathname option
If a `*` appears within (but not at the end) of a /dev or /sys path in
a ueventd.rc file, then that path is matched with fnmatch() using the
FNM_PATHNAME, which means `*` will not match `/`.  That is not always
the intended behavior and this change creates the no_fnm_pathname
option, which will not use the FNM_PATHNAME flag and will have `*`
match `/`.

Bug: 172880724
Test: these unit tests
Change-Id: I85b813d89237dbf3af47564e5cbf6806df5d412f
2020-12-07 14:58:19 -08:00
Tri Vo
ff89b8d8c2 ueventd: duplicate /dev/ashmem
We want ashmem to only be used via libcutils API, with long-term goal
being deprecation of ashmem with memfd. To do that we route libcutils to
a new source of ashmem fds. We then phase out uses of /dev/ashmem that
doesn't go through libcutils using SELinux.

In Q, we introduced ashmemd as the source of ashmem fds to libcutils.
However, having a separate process and, consequently, binder hops to
handle /dev/ashmem results in performance/memory overhead.

To address the overhead, replace ashmemd with a duplicate of
/dev/ashmem. Name it /dev/ashmem<boot_id>, where boot_id is a random
number generated on each boot. This way we make sure that developers
don't accidentally depend on /dev/ashmem<boot_id>, as that name can't be
hardcoded.

Bug: 139855428
Test: writing "add"/"remove" to /sys/class/misc/ashmem/uevent correctly
adds/removes /dev/ashmem and /dev/ashmem/boot_id
Change-Id: I36d23116048bfcd99903ba46cc133161835a2cfa
2019-09-25 12:49:38 -07:00
Tom Cherry
7c1d87e490 init: fix clang-tidy performance issues
Test: boot, init unit tests
Change-Id: Iccf34d2fedfa543dd9f29e010cbb6d8fe9cf5983
2019-07-10 12:59:02 -07:00
Tom Cherry
457e28f129 ueventd: require opt-in for modalias handling
Some devices have modules.alias and modules.dep for modprobe and other
purposes but do not want to opt into ueventd auto loading their
modules.  Therefore we add a flag that can be added to ueventd
configuration files to opt into this behavior.

Bug: 111916071
Bug: 112048758
Test: check that modules are loaded with this opt-in
Test: check that modules are not loaded without this opt-in
Change-Id: Ifb281b273059b4671eea1ca5bc726c9e79f3adfb
2018-08-01 13:29:05 -07:00
Tom Cherry
5f0198bfbb ueventd: add a test for ueventd_parser.cpp
Test: this unit test
Change-Id: Ib23f23ea5b362bb458adf8208573e5dc80ad6cf0
2018-07-17 15:28:51 -07:00
Tom Cherry
7421fa1aed ueventd: let scripts provide firmware directories
Since some vendors will have firmware in mount points in
/mnt/vendor/..., we extend the ueventd script language to allow
specifying the firmware directories.

Also, move the existing 4 directories to ueventd.rc as a primary user
of this mechanism.

Bug: 111337229
Test: boot sailfish; firmwares load
Change-Id: I0854b0b786ad761e40d2332312c637610432fce2
2018-07-13 15:34:25 -07:00
Bowgo Tsai
8eec38f4e4 Adds /dev/block/by-name/<partition> symlinks
During uevent processing, some "by-name" symlinks will be created.
    /dev/block/<type>/<device>/by-name/<partition>

<type> can be: platform, pci or vbd.
<device> might be: soc.0/f9824900.sdhci, soc.0/f9824900.sdhci, etc.
<partition> might be: system, vendor, system_a, system_b, etc.

e.g., on a non-A/B device:
    /dev/block/platform/soc.0/f9824900.sdhci/by-name/system
    /dev/block/platform/soc.0/f9824900.sdhci/by-name/vendor

On a A/B device:
    /dev/block/platform/soc/1da4000.ufshc/by-name/system_a
    /dev/block/platform/soc/1da4000.ufshc/by-name/system_b
    /dev/block/platform/soc/1da4000.ufshc/by-name/vendor_a
    /dev/block/platform/soc/1da4000.ufshc/by-name/vendor_b

However, those symlinks are "device-specific".

This change adds the "generic" symlinks in ueventd, in addition to
the existing symlinks, when the possible "boot devices" are specified
in device tree. e.g.,

    &firmware_android {
	compatible = "android,firmware";
	boot_devices ="soc/1da4000.ufshc,soc.0/f9824900.sdhci";
    }

The following symlinks will then be created on the aforementioned non-A/B
and A/B devices, respectively.

    /dev/block/by-name/system
    /dev/block/by-name/vendor

    /dev/block/by-name/system_a
    /dev/block/by-name/system_b
    /dev/block/by-name/vendor_a
    /dev/block/by-name/vendor_b

Note that both <type> and <device> are skipped in the newly create symlinks.
It assumes there is no more than one devices with the same <partition>,
which is the assumption of current first stage mount flow.

Finally, when 'boot_devices' in DT is absent, it fallbacks to extract
'boot_devices' from fstab settings. e.g., using 'soc/1da4000.ufshc',
'soc.0/f9824900.sdhci' for a fstab with the following content:

   /dev/block/platform/soc/1da4000.ufshc/by-name/system
   /dev/block/platform/soc.0/f9824900.sdhci/by-name/vendor

Bug: 78613232
Test: adb shell ls /dev/block/by-name
Change-Id: Iec920b5a72409b6a2bdbeeb290f0a3acd2046b5d
2018-05-19 07:57:35 +08:00
Tom Cherry
9c8d6dd7de ueventd: fix subsystem list logic issues
1) Check subsystems list before doing usb subsystem logic.  This allows
   developers to handle usb* subsystems in ueventd.rc files.
2) Fix a bug where each subsystem_ instance is not reinitialized, but
   rather only the name_ member was set.

Test: boot bullhead
Test: check that multiple uevent_devname subsystems work when
      specified in ueventd.rc
Change-Id: Ifcac04763afcaf72a3b14ef5f3a6cb89981b51a1
2017-08-18 10:39:48 -07:00
Tom Cherry
0c8d6d2730 init: split security functions out of init.cpp
This change splits out the selinux initialization and supporting
functionality into selinux.cpp and splits the security related
initialization of the rng, etc to security.cpp.  It also provides
additional documentation for SEPolicy loading as this has been
requested by some teams.

It additionally cleans up sehandle and sehandle_prop.  The former is
static within selinux.cpp and new wrapper functions are created around
selabel_lookup*() to better serve the users.  The latter is moved to
property_service.cpp as it is isolated to that file for its usage.

Test: boot bullhead
Merged-In: Idc95d493cebc681fbe686b5160502f36af149f60
Change-Id: Idc95d493cebc681fbe686b5160502f36af149f60
2017-08-14 09:40:01 -07:00
Tom Cherry
b4dd881ffd ueventd: remove character device symlinks (/dev/usb/*)
While refactoring ueventd, I was looking for code the character device
symlinks (/dev/usb/*) that ueventd creates, such that I could test it
on a real device.  I found none in our tree, and history showing Xoom,
which was last supported years ago, was the last user.  If this code
is in fact obsolete, let's remove it.

Test: boot bullhead
Test: init unit tests

Change-Id: I601f7165eb06d36b31b6dcf69ee9e0a449d81a96
2017-06-26 13:58:57 -07:00
Tom Cherry
81f5d3ebef init: create android::init:: namespace
With some small fixups along the way

Test: Boot bullhead
Test: init unit tests
Change-Id: I7beaa473cfa9397f845f810557d1631b4a462d6a
2017-06-23 13:21:20 -07:00
Sandeep Patil
cd2ba0d184 Revert "Revert "ueventd: remove PlatformDeviceList""
This reverts commit 516ff99711.

Bug: 62864413
Bug: 62864413

Change-Id: Ie3980cd536c2c83adace063f0950128f68561105
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-06-21 15:04:57 -07:00
Tom Cherry
516ff99711 Revert "ueventd: remove PlatformDeviceList"
Bug: 62864413

This reverts commit c94ce7b130.

Change-Id: I014360251e5cda89c87adfec46d8b1e5000f3a9c
2017-06-21 18:42:07 +00:00
Tom Cherry
c94ce7b130 ueventd: remove PlatformDeviceList
In order to create symlinks for USB and block devices, the path for
their parent platform device must be known.

Previously, ueventd would save each platform device that it encounters
to a list and query this list when creating the symlinks.  That,
however, is racy because the uevent socket does not differentiate
uevents from RegenerateUevents() and uevents sent by the kernel when
probing a device first the first time.  The below scenario is the
faulty  case:

1) Kernel probes parent platform device for a block device
2) ueventd calls RegenerateUevents() and starts processing uevents
3) Kernel probes block device and sends its uevents
4) ueventd picks up the block device uevent during its uevent processing,
   without yet regenerating the platform device uevent, causing improper
   symlinks to be created.

This change stops storing the platform devices in a list, and instead
traverses up the directory structure for each USB or block device
until it reaches a platform device, defined as one whose subsystem is
the platform bus.  This fixes the race and simplifies the ueventd
code.

Bug: 62436493
Bug: 62681642
Test: Boot bullhead
Test: Boot sailfish
Test: Init unit tests
Test: Boot hikey + hotplug/unplug sdcard
Change-Id: I21636355d8e434f30e0cba568598a6cf139e67f9
2017-06-20 21:21:14 +00:00
Tom Cherry
c583305ed7 ueventd: parallelize uevent handling
fork() subprocesses to handle uevents in parallel.

This reduces coldboot time on bullhead from ~446ms to ~230ms.
This reduces coldboot time on sailfish from ~690ms to ~360ms.
This reduces coldboot time on ryu from ~187ms to ~122ms.

Bug: 33785894

Test: boot bullhead x40, observe no major differences in /dev and /sys
Test: boot sailfish x40, observe no major differences in /dev and /sys
Test: boot ryu x40, observe no major differences in /dev and /sys
Test: boottime tests on bullhead and sailfish
Test: init unit tests

Change-Id: Ie2f63e000b8af78d187477d31fe109f20304d749
2017-06-02 21:45:56 +00:00
Tom Cherry
ed506f7356 ueventd: Break devices.cpp into discrete classes
devices.cpp handles too many things for creating one class.  This
change breaks it up into various files and classes.

* Parsing is moved to ueventd_parser.cpp
* Reading from the uevent socket and Cold booting is moved to a
  UeventListener class, in uevent_listener.cpp
* Firmware handling is moved to firmware_handler.cpp
* The remaining contents form a DeviceHandler class within devices.cpp

Bug: 33785894

Test: boot bullhead x40, observe no major differences in /dev and /sys
Test: boot sailfish x40, observe no major differences in /dev and /sys
Test: init unit tests

Change-Id: I846a2e5995fbb344c7a8e349065c18a934fa6aba
2017-05-25 16:17:19 -07:00
Tom Cherry
fe062055cb ueventd: replace ueventd_parser.cpp with init_parser.cpp
Previously init_parser.cpp was made generic and capable of parsing any
number of differently named 'sections' or prefixed lines.  We now use
these capabilities to do the parsing for ueventd.

Bug: 36250207
Bug: 33785894

Test: boot bullhead and ensure the right /dev nodes exist
      with the right permissions set
Test: verify no boot time difference
Change-Id: I698ca962d414f8135af32f6c9cd778841b2b8b53
2017-04-25 11:24:24 -07:00
Tom Cherry
cc054c9da8 ueventd: create classes for dev and sys permissions
Create classes for dev and sys permissions and store these permissions
in std::vector instead of the C list.

Test: boot bullhead
Test: init unit tests

Change-Id: I874039a3db29b4c70149506da8e407123ab7eca2
2017-04-17 19:33:04 +00:00
Tom Cherry
1ab8f55344 ueventd: convert platform_names from C list to std::vector
Also simplify this code a bit.

There's only one consumer that removes the /devices/platform prefix,
so have them handle it instead of storing two copies of the string.

Remove an unneeded search for '/' in get_character_device_symlinks()
as a / will always be the next character after a parent path, by
nature of FindPlatformDevice().

Test: boot bullhead
Test: init unit tests

Change-Id: I9d0482d137b1342ae7509ae993ff99198be814f0
2017-04-14 10:23:52 -07:00
Tom Cherry
e3e48214b7 ueventd: replace char* with std::string in struct uevent
Bug: 36250207

Test: Boot bullhead
Test: Boot sailfish, observe no boot time regression
Test: init unit tests

Change-Id: Ib82833bea56bdafbe1d7a045126aaa91a8725d98
2017-04-14 10:23:52 -07:00
Tom Cherry
2e344f9d22 ueventd: replace char** links with std::vector<std::string>
Additionally replace the associated C string parsing with C++ and write
unit tests.

Bug: 33785894
Bug: 36250207
Test: Boot bullhead + unit tests
Change-Id: Iee1f72d248bca3bd2e1227045628935b3dd6195a
2017-04-08 00:05:50 +00:00
Treehugger Robot
ab5ab1ebd4 Merge "init: more header cleanup" 2017-04-07 02:44:07 +00:00
Tom Cherry
3f5eaae526 init: more header cleanup
Remove includes of "log.h" that really want <android-base/logging.h>
Fix header include order
Remove headers included in .cpp files that their associated .h already includes
Remove some unused headers

Test: boot bullhead
Change-Id: I2b415adfe86a5c8bbe4fb1ebc53c7b0ee2253824
2017-04-06 18:06:34 -07:00
Tom Cherry
c44f6a4073 ueventd: Write tests for the get_*_symlinks() functions
Bug: 33785894
Bug: 36250207
Test: Boot bullhead + new unit tests
Change-Id: Ia0f290542eb1cffce5ae876dfedb453dde960253
2017-04-05 18:21:39 -07:00
Sandeep Patil
35403ebaf8 init: early_mount: add support to mount non-verity partitions early
This is done by parsing 'androidboot.fstab=<fstab>' kernel cmdline
option to get the fstab file that *only* specifies partitions to be
mounted early (i.e. in init's first stage).

Note that, the same fstab file may not be used as an argument to
mount_all later in the boot as that will cause fs_mgr to fail with
EBUSY.

TODO:
- Possibly add a new mount_mode so the same fstab can be used for
early_mount, 'mount_all --early/--late' etc.
- Add support for dm-verity enabled partitions to mount early.
- Add support for getting fstab arguments through DT instead of kernel
cmdline.

Bug: 27805372

Test:
Boot angler by passing a seperate fstab file using the kernel
cmdline option to mount vendor partition early, remove the vendor
partition entry from the main fstab file for the test.

Boot sailfish by passing a seperate fstab entry via device tree
to mount vendor partition early. Remove vendor partition entry from
the main fstab file for the test

Change-Id: I18785b893c54c8cee960ab44d5e8f83e5d624aa8
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-13 11:17:51 -08:00
Sandeep Patil
44a3ee2cd1 init: remove the existing early_mount code
keeps parts of the code that are still needed for the fs_mgr
+ dt based implementation

b/27805372

Test: boot angler, sailfish without regressions

Change-Id: I1b08f8b7b4f2e67118d328443a5011c0f5ead919
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-09 15:39:06 -08:00
Sandeep Patil
957e4ab0b5 init: refactor: add support for doing early coldboot
We don't want to spend time creating devices that are unncessesary
during early (init first-stage) mount. So, refactor the devices code
tha allows us to call into coldboot and has the

- ability to only create devices that are specified by the caller
- ability to stop coldboot cycle when all devices that the caller is
interested in
- ability to run coldboot for a specific syspath
- ability to run ueventd code unmodified

Test: Tested boot on angler, sailfish

Change-Id: Id8f3492380696760414eadc20d624d300c904f8e
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-02-09 15:30:20 -08:00
Hung-ying Tyan
99c4a8a6b3 Mount /vendor and /odm early
Right now these two partitions are mounted in the fs stage of the init
process. As a result, many vendor/ODM files needed earlier in the boot
process (e.g., init.<hardware>.rc, fstab.<hardware>.rc,
uevent.<hardware>.rc, SELinux policy files etc) can only live on the root
partition.

To prevent vendors/ODMs from polluting the root partition, this patch makes
it possible to mount the vendor and ODM partitions in the first stage of the
init process. The fstab info of both partitions to be mounted early is
composed from new kernel cmdline arguments android.early.prefix and
android.early.fstab.

For example, with:
android.early.prefix=/sys/devices/1010000.msdc0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/
android.early.fstab=mmcblk0p10+/odm+ext4+ro+verify\nmmcblk0p09+/vendor+ext4+ro+verify

the final fstab string will be:
/sys/devices/1010000.msdc0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p10 /odm ext4 ro verify
/sys/devices/1010000.msdc0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/mmcblk0p09 /vendor ext4 ro verify

The android.early.prefix is optional. When it is missing, the final fstab
string will be directly converted from android.early.fstab.

This patch also makes sure that the early mounted partitions are dm-verity
enabled so that they are trust worthy to store system files.

BUG=27805372

Change-Id: I3cf32482a5ec65445ba3aedab2164c7ba8f12694
2016-08-17 17:21:35 +08:00
Elliott Hughes
f3cf438714 Build init as C++.
This is just the minimal change to keep it building.

Change-Id: I245c5b8413a1db114576c81462eb5737f5ffcef2
2015-02-04 08:59:10 -08:00
Daniel Leung
c0c1ffea58 init/ueventd: adds wildcard matching for ueventd rules
The sysfs nodes can change from devices to devices for
a particular class of peripheral. Some of them even change
after suspend/resume, e.g. rfkill for USB bluetooth adapters.

This patch adds to the way how ueventd rules with wildcard are
handled. In addition to matching the prefix with a trailing
wildcard, now rules can have wildcard anywhere in the rule.
The wildcard matching is implemented using fnmatch(), where
its matching is simliar to shell pathname expansion. It suits
this particular usage model well. To avoid abuse, the number of
slashes has to match between path name and the rule.

For example, instead of creating a rule to match:

  /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/bluetooth/hci0/rfkill*

, this would suffice:

  /sys/devices/pci0000:00/0000:00:1d.0/*/*/*/*/bluetooth/hci0/rfkill*

The prefix matching behavior is retained, such that those
rules do not have to pay for processing penalty with fnmatch().

Change-Id: I3ae6a39c838f6d12801cb71958e481b016f731f5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2014-06-20 09:28:37 -07:00
Brian Swetland
bc57d4ce92 init: support owner/permission setting for sysfs attributes of devices
This should be much nicer than peppering init.rc with chown/chmod
directives.

Also, remove some dead code and obsolete comments.

Change-Id: I10895f10a9cf2f1226c8d12976cd3db3743da9ec
2010-10-26 15:37:06 -07:00
Colin Cross
f83d0b9af5 init: Move uevent handling to an external ueventd process
Change-Id: Iea6c56013062ade633a1754f7bcf8cf09b3dedc1
2010-04-21 20:59:38 -07:00
Colin Cross
0dd7ca6e87 init: Move device_fd to devices.c
Change-Id: I11ed0f3e1b95d2cff4fdbd80b915c01572f76b0e
2010-04-13 22:47:08 -07:00
The Android Open Source Project
dd7bc3319d auto import from //depot/cupcake/@135843 2009-03-03 19:32:55 -08:00
The Android Open Source Project
e54eebbf1a auto import from //depot/cupcake/@135843 2009-03-03 18:29:04 -08:00
The Android Open Source Project
4f6e8d7a00 Initial Contribution 2008-10-21 07:00:00 -07:00