System-core-init: Implement device triggers

Android system/core/init/readme describes two triggers, which are
not implemented in the code yet.
They are:
device-added-<path>
device-removed-<path>
Triggers of these forms occur when a device node is added or removed.
These triggers are very important for PnP devices. For example when
system goes to suspend, the inbuilt usb in some devices is power-off
causing whole driver to be removed. When they are driver restarts on
resume the sysfs files permission will be reset to root again. This
will cause processes with non-root access to fail.
These triggers allows to change ownership again.
Android ueventd.*.rc file allows to modify permissions of file
matching the path sent by udev event, but doesn't allow to set
permissions in sysfs files or other files.
Also this patch goes through device triggers at the end of boot
process and fires them to account for uevents before the init
process was created.

Change-Id: Ib7f47124f324fdba4da332c7d1ea5040f45eeb13
Signed-off-by: srinivas pandruvada <srinivas.pandruvada@intel.com>
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
libdiskconfig: HACK Don't do space checks on zero-size images

If an image file is of zero size, assume we just want to expand it
to fit the available images.

Change-Id: If8f22eb12d3a5179960d4359307bb177e3323e8a
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
config_mbr: Fix partition table generation

config_mbr() doesn't produce a valid partition table if there was not
one to begin with; the magic sequence 0xAA55 is not written to the last
2 bytes of the MBR. If this MBR signature is missing, the kernel will
refuse to inspect the partition table.

We add a step to config_mbr which blanks out bytes 440-512 of the MBR
and properly writes the MBR signature before doing anything else.
This fixes a problem where diskinstaller had to be run twice if there
was no partition table present on the target volume.

Change-Id: I4a8d173bef231d10e8fbcd0d8aecf54d1cf92474
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
software-accelerated Pixel Flinger v1.0

BZ: 46856

This patch is derived from the software-accelerated Pixel Flinger on froyo code base.
The typical graphic workloads on VirtualBox are improved 3X.

The commit id on ABSP/GB-stable is 67e50490231b86fa19a32420d0ffa3a952159bd1
under system/core project.

With this patch, the system can boot OK to HC home screen of VirtualBox

removed the redundant white spaces

JIRA: ANDROID-645

Change-Id: I573339d380dfc710429d243ffd845cb3d23edd24
Orig-Change-Id: I5a32a860967ee45b16e357cac3b1df01d06e7e0c
Category: aosp improvement
Domain: PUPDR-Recovery
Orig-Change-Id: I799af498b50f4e2ad27d0d2343414f6d474bfc69
Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com>
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Xiaokang Qin <xiaokang.qin@intel.com>
Use progressive offset in buffer for successive writes

The code for copying from one raw file to another looped
back and tried again with a suitably smaller number of bytes
if the entire buffer was not written on the first try.
However, it failed to advance an offset in the buffer past
the bytes that were written.  This could conceivably happen
under rare circumstances, leading to a corrupted disk image.

This fix defines an offset into the buffer, advancing it by
the number of bytes written on each successive retry.

Signed-off-by: Paul Drews <paul.drews@intel.com>

Change-Id: I76b8e0b3c0d3b0c32bd2114d0867ac7489808279
diskconfig: Fix disk_layout.conf size parsing

If the user was appending 'K' to their lengths (which is valid
but redundant) it was being treated as megabytes instead of
kilobytes.

Change-Id: I979ec4d01f1342de1f3209b946201ca87bad32a7
libdiskconfig: Enable Mac OS X host build

Change-Id: Iacc7d5463364d0cd15ca9fabaa58ad05857d9e78
Signed-off-by: Andrew P. Boie <andrew.p.boie@intel.com>
add modprobe-like capability and automatic ueventd loading

Author: Jianxun Zhang <jianxun.zhang@intel.com>
Author: Daniel Leung <daniel.leung@intel.com>
Author: Andrew Boie <andrew.p.boie@intel.com>

- insmod_by_dep() added to libcutils; loads a module into kernel.
Modules the target module depends on will be loaded first. Loading
will be stopped when an error occurs.

- rmmod_by_dep() added to libcutils; removes a module from kernel.
It also tries to remove other modules the target module depends
on until an error occurs.

- Implement wildcard matching for ueventd rules.
The PCI and USB addresses for devices can change from devices
from devices for a particular class of peripheral, for example,
bluetooth. The ueventd rules created with these addresses are
then device-specific.

This changes the way ueventd rules with wildcard are handled.
Instead of matching just the prefix with a trailing wildcard,
now these 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.

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/*/bluetooth/hci0/rfkill*

- Let ueventd auto-load kernel modules. Implements the functionality
for ueventd to auto-load kernel modules when uevents are triggered.
Since /system may not be mounted when uevents are fired,
a deferred loading mechanism is implemented. Once mapping of
module and alias is available, these modules are then loaded.
Modules can also be blacklisted so they will not be loaded
automatically. One example would be the Wifi driver, as
Android's has to control its loading and unloading.

- add 'probemod' builtin command. This command accepts the name of a
kernel module plus a set of command line arguments. The module will
be loaded, along with all its dependencies, using the libcutils
insmod_by_dep() API.

- Drivers in kernel can request modules by launching a program in
user space, the program's path by default is "/sbin/modprobe".
Because Android system has no modprobe and ueventd is the only
program handling the module aliases so far, This patch provides a
cheap approach to handle kernel's requests in ueventd executable.

- Add new builtin init command "coldboot". The main purpose is to
provide an approach in init.*.rc files to fire uevents for devices
under the path which is passed as the the argument. This should be
called after /system is mounted so any queued events that need to
load a module can be fired.
adb: reserve a wakelock when clients are connected over socket

USB OTG connections already have a wakelock reserved, but if a network
socket connection is made, the device can unexpectedly suspend
in the middle of a session. The lock is released when the client
disconnects.

Change-Id: Id5ac01699fab9350955c9814042259542fc6a694
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Fix warnings about unused parameters

Change-Id: I29139ffa688fb9215956b4d585dd4c47f70612b8
Signed-off-by: Pauli Nieminen <pauli.nieminen@linux.intel.com>
bootchart: add threads support

Grab information about threads not only processes. This gives us
additional important information about the boot processes especially
for heavy processes such as system server and zygote.

Issue: ANDROID-609

Change-Id: Ia941da116de1589c46101f262db64b0bc730e643
Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
Fix build failure when switching between build variants

When switching from the eng to the userdebug build variant, the init
binary compilation returns error ar linking stage:
.../obj/EXECUTABLES/init_intermediates/init.o: In function `bootchart_init_action':
system/core/init/init.c:729: undefined reference to `bootchart_init'
.../obj/EXECUTABLES/init_intermediates/init.o: In function `main':
system/core/init/init.c:881: undefined reference to `bootchart_step'
system/core/init/init.c:882: undefined reference to `bootchart_finish'
collect2: ld returned 1 exit status
make: *** [.../obj/EXECUTABLES/init_intermediates/LINKED/init] Error 1

Issue: ANDROID-1757
Change-Id: Ide50286e190ffeb75ec56bdfa2f5c612e0ae2392
Signed-off-by: Alin Dobre <alin.m.dobre@intel.com>
Use SSE2 enhanced memset for capable x86 processors

Originally, if TARGET_ARCH_VARIANT is x86-atom, the SSE2 enhanced
memset is used. This patch extends this to all x86 processors which
support SSE2 (i.e. ARCH_X86_HAVE_SSE2 is true).

For: AIA-502
Change-Id: Ibb7ff6ff1ce48da4262e4284618c26f2b516c8bf
Depends-Change-Id: I61c66496df66f6d8adc45cddd48f8750fc95f83c
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
util.c: Fix file_read() with sysfs nodes

Sysfs nodes always report a file size of 4096 regardless of how much
data can be read. Hence don't fail if read() can't get the full size;
specifically look for errors or 0 (which is EOF).

Change-Id: Ief1ffbe08ac5e4daa80805713efa4f2af0a1a33e
init: wildcard matching for chmod/chown in init.rc

Implement wildcard matching for the builtin command
chmod and chown for use in init.rc.

For security reason, the number of slashes has to match.
For example, to match /dir_a/dir_b/dir_c/dir_d/file,
the path needs to be /dir_a/*/*/*/file. Simply doing
/dir_a/*/file does not work.

Issue: AXIA-576
Change-Id: I21b5aa58b3d3142725bc73ff31afb65d4fd4bc99
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
libcutils: wait for properties and value comparison

Add a property_try_get() function to wait for property to appear.
This can be used to block operations until some properties are set.

Add property_cmp() and property_try_cmp() to compare property
to specified value.

Also add a trygetprop, cmpprop, trycmpprop command in toolbox
to use these.

Issue: AXIA-539
Change-Id: I9d531e57c84140cebe6440efe3d3195c505932fa
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
init: HACK: Try multiple times to open console

If the console is set to be a USB-to-serial adapter, there is
a bootup race for the creation of its associated device nodes
and init's one-time console detection.

If the console can't be opened, try polling up to 5 seconds. Log
an error if it ultimately fails.

A better solution would be to reimplement the console functionality
to be hot-pluggable, but this would require much more invasive changes
to make it robust.

Change-Id: I20b19095a2f22efffafe2a7ac22d2be753a62d4b
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
devices: allow sending on device-add notifications for major/minor-less devices

This is usefull for getting device plug/unplug notifications for
things like USB ethernet adapters which do not have major/minor
numbers.

Change-Id: I8f032ef983aeb36dd013fafc4a5df5238decbb17
Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
ADBD: set sent file permissions per android fs config table.

This fix allows the standard CTS installation to succeed while
preserving the previous fix's intent to allow init to operate
properly.

The first CTS APK installation failed when adbd, the adb daemon, on
the target invoked pm (package manager). "pm" runs as another user
than adbd and could not open the APK because adbd had cleared the
"other" read permission.

For: AXIA-813
Change-Id: If27a628072f51ffac78db7b5448670ea4666575f
Signed-off-by: Bruce E. Robertson <bruce.e.robertson@intel.com>

Conflicts:
	adb/file_sync_service.c
init: Add 'readprops' command

This reads the contents of a text file and sets system properties
based on its contents.

Change-Id: Ic03de7ee9afb8a12439d0dff343560011e152beb
For: AXIA-102
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>