├── .gitmodules
├── Android.mk
├── COPYING
├── DONORS.md
├── README.md
├── device_defines.mk
├── hooks.h
├── install_zip
├── Android.mk
├── README.md
├── extract_boot_dev.sh
├── make_updater_script.sh
├── prebuilt-installer
│ ├── META-INF
│ │ └── com
│ │ │ └── google
│ │ │ └── android
│ │ │ ├── update-binary
│ │ │ └── updater-script
│ ├── multirom
│ │ ├── busybox
│ │ ├── exfat-fuse
│ │ ├── icons
│ │ │ ├── romic_android.png
│ │ │ ├── romic_androidl.png
│ │ │ ├── romic_aokp1.png
│ │ │ ├── romic_aokp2.png
│ │ │ ├── romic_cm1.png
│ │ │ ├── romic_cm2.png
│ │ │ ├── romic_default.png
│ │ │ ├── romic_du.png
│ │ │ ├── romic_firefox.png
│ │ │ ├── romic_linux.png
│ │ │ ├── romic_miui.png
│ │ │ ├── romic_omni.png
│ │ │ ├── romic_pa.png
│ │ │ ├── romic_pa2.png
│ │ │ ├── romic_slimkat.png
│ │ │ ├── romic_ubuntu1.png
│ │ │ ├── romic_ubuntu2.png
│ │ │ ├── romic_ubuntu3.png
│ │ │ └── romic_viperone.png
│ │ ├── lz4
│ │ ├── ntfs-3g
│ │ ├── res
│ │ │ ├── OxygenMono-LICENSE_OFL.txt
│ │ │ ├── OxygenMono-Regular.ttf
│ │ │ ├── Roboto-Bold.ttf
│ │ │ ├── Roboto-BoldItalic.ttf
│ │ │ ├── Roboto-Italic.ttf
│ │ │ ├── Roboto-Medium.ttf
│ │ │ ├── Roboto-Regular.ttf
│ │ │ ├── RobotoCondensed-Regular.ttf
│ │ │ ├── miri_135x135.png
│ │ │ ├── miri_180x180.png
│ │ │ ├── miri_54x54.png
│ │ │ ├── miri_60x60.png
│ │ │ ├── miri_72x72.png
│ │ │ └── miri_90x90.png
│ │ ├── ubuntu-init
│ │ │ ├── init
│ │ │ └── local
│ │ ├── ubuntu-touch-init
│ │ │ ├── init
│ │ │ └── scripts
│ │ │ │ └── touch
│ │ └── ubuntu-touch-sysimage-init
│ │ │ ├── init
│ │ │ └── scripts
│ │ │ └── touch
│ └── scripts
│ │ ├── extract_multirom.sh
│ │ └── inject_boot.sh
├── prebuilt-uninstaller
│ ├── META-INF
│ │ └── com
│ │ │ └── google
│ │ │ └── android
│ │ │ ├── update-binary
│ │ │ └── updater-script
│ └── scripts
│ │ ├── busybox
│ │ ├── clear_boot.sh
│ │ ├── erase_multirom.sh
│ │ └── lz4
└── rename_zip.sh
├── installer
├── README.md
├── manifest.txt
├── post_install
│ └── .placeforscripts
├── pre_install
│ └── .placeforscripts
├── rom
│ └── root.tar.gz
└── root_dir
│ └── rom_info.txt
├── kexec.c
├── kexec.h
├── lib
├── Android.mk
├── animation.c
├── animation.h
├── atomics.h
├── button.c
├── button.h
├── colors.c
├── colors.h
├── containers.c
├── containers.h
├── framebuffer.c
├── framebuffer.h
├── framebuffer_generic.c
├── framebuffer_png.c
├── framebuffer_qcom_overlay.c
├── framebuffer_truetype.c
├── fstab.c
├── fstab.h
├── inject.c
├── inject.h
├── input.c
├── input.h
├── input_priv.h
├── input_type_a.c
├── input_type_b.c
├── keyboard.c
├── keyboard.h
├── listview.c
├── listview.h
├── log.h
├── mrom_data.c
├── mrom_data.h
├── notification_card.c
├── notification_card.h
├── progressdots.c
├── progressdots.h
├── tabview.c
├── tabview.h
├── touch_tracker.c
├── touch_tracker.h
├── util.c
├── util.h
├── velocity_tracker.c
├── workers.c
└── workers.h
├── main.c
├── multirom.c
├── multirom.h
├── multirom_ui.c
├── multirom_ui.h
├── multirom_ui_landscape.c
├── multirom_ui_portrait.c
├── multirom_ui_themes.c
├── multirom_ui_themes.h
├── pong.c
├── pong.h
├── rcadditions.c
├── rcadditions.h
├── rom_info.txt
├── rom_quirks.c
├── rom_quirks.h
├── trampoline
├── Android.mk
├── adb.c
├── adb.h
├── devices.c
├── devices.h
├── encryption.c
├── encryption.h
└── trampoline.c
├── trampoline_encmnt
├── Android.mk
├── encmnt.c
├── encmnt_defines.h
├── pw_ui.c
└── pw_ui.h
└── version.h
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "kexec-tools"]
2 | path = kexec-tools
3 | url = https://github.com/Tasssadar/kexec-tools
4 | [submodule "adbd"]
5 | path = adbd
6 | url = https://github.com/Tasssadar/multirom_adbd.git
7 |
--------------------------------------------------------------------------------
/Android.mk:
--------------------------------------------------------------------------------
1 | # MultiROM
2 | ifeq ($(TARGET_RECOVERY_IS_MULTIROM),true)
3 | LOCAL_PATH:= $(call my-dir)
4 | include $(CLEAR_VARS)
5 |
6 | multirom_local_path := $(LOCAL_PATH)
7 |
8 | LOCAL_C_INCLUDES += $(multirom_local_path) \
9 | external/libpng \
10 | external/zlib \
11 | external/freetype/include \
12 | $(multirom_local_path)/lib
13 |
14 | LOCAL_SRC_FILES:= \
15 | kexec.c \
16 | main.c \
17 | multirom.c \
18 | multirom_ui.c \
19 | multirom_ui_landscape.c \
20 | multirom_ui_portrait.c \
21 | multirom_ui_themes.c \
22 | pong.c \
23 | rcadditions.c \
24 | rom_quirks.c \
25 |
26 | # With these, GCC optimizes aggressively enough so full-screen alpha blending
27 | # is quick enough to be done in an animation
28 | LOCAL_CFLAGS += -O3 -funsafe-math-optimizations
29 |
30 | #LOCAL_CFLAGS += -D_FORTIFY_SOURCE=2 -fstack-protector-all -O0 -g -fno-omit-frame-pointer -Wall
31 |
32 | LOCAL_MODULE:= multirom
33 | LOCAL_MODULE_TAGS := eng
34 |
35 | LOCAL_FORCE_STATIC_EXECUTABLE := true
36 | LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
37 | LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)
38 |
39 | LOCAL_STATIC_LIBRARIES := libcutils libc libmultirom_static
40 | LOCAL_WHOLE_STATIC_LIBRARIES := libm libcutils libpng libz libft2_mrom_static
41 |
42 | # clone libbootimg to /system/extras/ from
43 | # https://github.com/Tasssadar/libbootimg.git
44 | LOCAL_STATIC_LIBRARIES += libbootimg
45 | LOCAL_C_INCLUDES += system/extras/libbootimg/include
46 |
47 | include $(multirom_local_path)/device_defines.mk
48 |
49 | ifneq ($(MR_DEVICE_HOOKS),)
50 | ifeq ($(MR_DEVICE_HOOKS_VER),)
51 | $(info MR_DEVICE_HOOKS is set but MR_DEVICE_HOOKS_VER is not specified!)
52 | else
53 | LOCAL_CFLAGS += -DMR_DEVICE_HOOKS=$(MR_DEVICE_HOOKS_VER)
54 | LOCAL_SRC_FILES += ../../../$(MR_DEVICE_HOOKS)
55 | endif
56 | endif
57 |
58 | include $(BUILD_EXECUTABLE)
59 |
60 |
61 |
62 | # Trampoline
63 | include $(multirom_local_path)/trampoline/Android.mk
64 |
65 | # ZIP installer
66 | include $(multirom_local_path)/install_zip/Android.mk
67 |
68 | # Kexec-tools
69 | include $(multirom_local_path)/kexec-tools/Android.mk
70 |
71 | # adbd
72 | include $(multirom_local_path)/adbd/Android.mk
73 |
74 | # trampoline_encmnt
75 | ifeq ($(MR_ENCRYPTION),true)
76 | include $(multirom_local_path)/trampoline_encmnt/Android.mk
77 | endif
78 |
79 | # libmultirom
80 | include $(multirom_local_path)/lib/Android.mk
81 |
82 | endif
83 |
--------------------------------------------------------------------------------
/DONORS.md:
--------------------------------------------------------------------------------
1 | # MultiROM's Indiegogo campaign
2 |
3 | http://www.indiegogo.com/projects/multirom-for-nexus-7-2013/
4 |
5 | A crowdfunding campaign to get test devices took place from July 28th
6 | to August 27th 2013. Thanks all contributors, the campaign was successful,
7 | raising a total of $562. This enabled a purchase of _flo_ and resulted in
8 | MultiROM being ported to said device and the code became much more portable.
9 |
10 | These are the contributors who pledged $20 or more and got perk _The Code_:
11 | * jbaumert
12 | * viper08
13 | * marius15
14 | * x.nicow.x
15 | * Ben Hagen
16 |
17 | More contributors are named in the XDA thread or during build of
18 | `multirom_zip` target, but thanks goes to all who contributed, either
19 | by pledging money or by promoting the campaign. Thank you all.
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MultiROM
2 | MultiROM is a one-of-a-kind multi-boot solution. It can boot android ROM while
3 | keeping the one in internal memory intact or boot Ubuntu without formating
4 | the whole device. MultiROM can boot either from internal memory of the device
5 | or from USB flash drive.
6 |
7 | XDA threads:
8 | * grouper: http://forum.xda-developers.com/showthread.php?t=2011403
9 | * flo: http://forum.xda-developers.com/showthread.php?t=2457063
10 | * mako: http://forum.xda-developers.com/showthread.php?p=46223377
11 | * hammerhead: http://forum.xda-developers.com/showthread.php?t=2571011
12 |
13 | ###Sources
14 | MultiROM uses git submodules, so you need to clone them as well:
15 |
16 | git clone https://github.com/Tasssadar/multirom.git system/extras/multirom
17 | cd system/extras/multirom
18 | git submodule update --init
19 |
20 | It also needs libbootimg:
21 |
22 | git clone https://github.com/Tasssadar/libbootimg.git system/extras/libbootimg
23 |
24 | ###Build
25 | Clone repo to folder `system/extras/multirom` inside Android 4.x source tree.
26 | You can find device folders on my github, I currently use OmniROM tree for
27 | building (means branch android-4.4-mrom in device repos).
28 | MultiROM also needs libbootimg (https://github.com/Tasssadar/libbootimg)
29 | in folder `system/extras/libbootimg`. Use something like this to build:
30 |
31 | . build/envsetup.sh
32 | lunch full_grouper-userdebug
33 | make -j4 multirom trampoline
34 |
35 | To build installation ZIP file, use `multirom_zip` target:
36 |
37 | make -j4 multirom_zip
38 |
--------------------------------------------------------------------------------
/device_defines.mk:
--------------------------------------------------------------------------------
1 | # Defines from device files
2 | # Init default define values
3 | MULTIROM_DEFAULT_ROTATION := 0
4 |
5 | # This value is used to have different folders on USB drives
6 | # for different devices. Grouper didn't have that, hence the hack
7 | LOCAL_CFLAGS += -DTARGET_DEVICE="\"$(TARGET_DEVICE)\""
8 | ifeq ($(TARGET_DEVICE),grouper)
9 | LOCAL_CFLAGS += -DMR_MOVE_USB_DIR
10 | endif
11 |
12 | ifneq ($(TW_DEFAULT_ROTATION),)
13 | MULTIROM_DEFAULT_ROTATION := $(TW_DEFAULT_ROTATION)
14 | endif
15 | LOCAL_CFLAGS += -DMULTIROM_DEFAULT_ROTATION=$(MULTIROM_DEFAULT_ROTATION)
16 |
17 | # TWRP framebuffer flags
18 | ifeq ($(RECOVERY_GRAPHICS_USE_LINELENGTH), true)
19 | LOCAL_CFLAGS += -DRECOVERY_GRAPHICS_USE_LINELENGTH
20 | endif
21 |
22 | ifeq ($(MR_PIXEL_FORMAT),)
23 | MR_PIXEL_FORMAT := $(TARGET_RECOVERY_PIXEL_FORMAT)
24 | endif
25 |
26 | ifeq ($(MR_PIXEL_FORMAT),"RGBX_8888")
27 | LOCAL_CFLAGS += -DRECOVERY_RGBX
28 | else ifeq ($(MR_PIXEL_FORMAT),"BGRA_8888")
29 | LOCAL_CFLAGS += -DRECOVERY_BGRA
30 | else ifeq ($(MR_PIXEL_FORMAT),"RGB_565")
31 | LOCAL_CFLAGS += -DRECOVERY_RGB_565
32 | else ifeq ($(MR_PIXEL_FORMAT),"ABGR_8888")
33 | LOCAL_CFLAGS += -DRECOVERY_ABGR
34 | else
35 | $(info TARGET_RECOVERY_PIXEL_FORMAT or MR_PIXEL_FORMAT not set or have invalid value)
36 | endif
37 |
38 | ifeq ($(MR_DPI),)
39 | $(info MR_DPI not defined in device files)
40 | else ifeq ($(MR_DPI),hdpi)
41 | ifeq ($(MR_DPI_MUL),)
42 | MR_DPI_MUL := 1
43 | endif
44 | else ifeq ($(MR_DPI),xhdpi)
45 | ifeq ($(MR_DPI_MUL),)
46 | MR_DPI_MUL := 1.5
47 | endif
48 | else ifeq ($(MR_DPI),xxhdpi)
49 | ifeq ($(MR_DPI_MUL),)
50 | MR_DPI_MUL := 2.0
51 | endif
52 | endif
53 |
54 | ifeq ($(MR_DPI_FONT),)
55 | MR_DPI_FONT := 96
56 | endif
57 |
58 | LOCAL_CFLAGS += -DMR_DPI_FONT=$(MR_DPI_FONT)
59 |
60 | ifneq ($(MR_DPI_MUL),)
61 | LOCAL_CFLAGS += -DDPI_MUL=$(MR_DPI_MUL)
62 | else
63 | $(info MR_DPI_MUL not defined!)
64 | endif
65 |
66 | ifeq ($(MR_DISABLE_ALPHA),true)
67 | LOCAL_CFLAGS += -DMR_DISABLE_ALPHA
68 | endif
69 |
70 | ifneq ($(TW_BRIGHTNESS_PATH),)
71 | LOCAL_CFLAGS += -DTW_BRIGHTNESS_PATH=\"$(TW_BRIGHTNESS_PATH)\"
72 | endif
73 |
74 | ifeq ($(TW_SCREEN_BLANK_ON_BOOT), true)
75 | LOCAL_CFLAGS += -DTW_SCREEN_BLANK_ON_BOOT
76 | endif
77 |
78 | ifneq ($(MR_DEFAULT_BRIGHTNESS),)
79 | LOCAL_CFLAGS += -DMULTIROM_DEFAULT_BRIGHTNESS=\"$(MR_DEFAULT_BRIGHTNESS)\"
80 | else
81 | LOCAL_CFLAGS += -DMULTIROM_DEFAULT_BRIGHTNESS=40
82 | endif
83 |
84 | ifneq ($(MR_KEXEC_MEM_MIN),)
85 | LOCAL_CFLAGS += -DMR_KEXEC_MEM_MIN=\"$(MR_KEXEC_MEM_MIN)\"
86 | else
87 | $(info MR_KEXEC_MEM_MIN was not defined in device files!)
88 | endif
89 |
90 | ifeq ($(MR_KEXEC_DTB),true)
91 | LOCAL_CFLAGS += -DMR_KEXEC_DTB
92 | endif
93 |
94 | ifeq ($(MR_CONTINUOUS_FB_UPDATE),true)
95 | LOCAL_CFLAGS += -DMR_CONTINUOUS_FB_UPDATE
96 | endif
97 |
98 | LOCAL_CFLAGS += -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
99 |
100 | ifeq ($(MR_USE_MROM_FSTAB),true)
101 | LOCAL_CFLAGS += -DMR_USE_MROM_FSTAB
102 | endif
103 |
104 | ifeq ($(MR_ENCRYPTION),true)
105 | LOCAL_CFLAGS += -DMR_ENCRYPTION
106 | endif
107 |
108 | ifneq ($(MR_RD_ADDR),)
109 | LOCAL_CFLAGS += -DMR_RD_ADDR=$(MR_RD_ADDR)
110 | endif
111 |
--------------------------------------------------------------------------------
/hooks.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef MR_DEVICE_HOOKS_H
19 | #define MR_DEVICE_HOOKS_H
20 |
21 | #ifdef MR_DEVICE_HOOKS
22 |
23 | #if MR_DEVICE_HOOKS >= 1
24 | int mrom_hook_after_android_mounts(const char *busybox_path, const char *base_path, int type);
25 | #endif
26 |
27 | #if MR_DEVICE_HOOKS >= 2
28 | void mrom_hook_before_fb_close(void);
29 | #endif
30 |
31 | #if MR_DEVICE_HOOKS >= 3
32 | void tramp_hook_before_device_init(void);
33 | #endif
34 |
35 | #if MR_DEVICE_HOOKS >= 4
36 | int mrom_hook_allow_incomplete_fstab(void);
37 | #endif
38 |
39 | #if MR_DEVICE_HOOKS >= 5
40 | void mrom_hook_fixup_bootimg_cmdline(char *bootimg_cmdline, size_t bootimg_cmdline_cap);
41 | int mrom_hook_has_kexec(void);
42 | #endif
43 |
44 | #endif /* MR_DEVICE_HOOKS */
45 |
46 | #endif /* MR_DEVICE_HOOKS_H */
47 |
--------------------------------------------------------------------------------
/install_zip/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH:= $(call my-dir)
2 | include $(CLEAR_VARS)
3 |
4 | install_zip_path := $(multirom_local_path)/install_zip
5 |
6 | MULTIROM_ZIP_TARGET := $(PRODUCT_OUT)/multirom
7 | MULTIROM_INST_DIR := $(PRODUCT_OUT)/multirom_installer
8 | multirom_binary := $(TARGET_ROOT_OUT)/multirom
9 | trampoline_binary := $(TARGET_ROOT_OUT)/trampoline
10 |
11 | ifeq ($(MR_FSTAB),)
12 | $(info MR_FSTAB not defined in device files)
13 | endif
14 |
15 | multirom_extra_dep :=
16 | ifeq ($(MR_ENCRYPTION),true)
17 | multirom_extra_dep += trampoline_encmnt linker
18 | else
19 | MR_ENCRYPTION := false
20 | endif
21 |
22 | MR_DEVICES := $(TARGET_DEVICE)
23 | ifneq ($(MR_DEVICE_VARIANTS),)
24 | MR_DEVICES += $(MR_DEVICE_VARIANTS)
25 | endif
26 |
27 | $(MULTIROM_ZIP_TARGET): multirom trampoline signapk bbootimg mrom_kexec_static mrom_adbd $(multirom_extra_dep)
28 | @echo
29 | @echo
30 | @echo "A crowdfunding campaign for MultiROM took place in 2013. These people got perk 'The Tenth':"
31 | @echo " * Bibi"
32 | @echo " * flash5000"
33 | @echo "Thank you. See DONORS.md in MultiROM's folder for more informations."
34 | @echo
35 | @echo
36 |
37 | @echo ----- Making MultiROM ZIP installer ------
38 | rm -rf $(MULTIROM_INST_DIR)
39 | mkdir -p $(MULTIROM_INST_DIR)
40 | cp -a $(install_zip_path)/prebuilt-installer/* $(MULTIROM_INST_DIR)/
41 | cp -a $(TARGET_ROOT_OUT)/multirom $(MULTIROM_INST_DIR)/multirom/
42 | cp -a $(TARGET_ROOT_OUT)/trampoline $(MULTIROM_INST_DIR)/multirom/
43 | cp -a $(TARGET_OUT_OPTIONAL_EXECUTABLES)/mrom_kexec_static $(MULTIROM_INST_DIR)/multirom/kexec
44 | cp -a $(TARGET_OUT_OPTIONAL_EXECUTABLES)/mrom_adbd $(MULTIROM_INST_DIR)/multirom/adbd
45 |
46 | if $(MR_ENCRYPTION); then \
47 | mkdir -p $(MULTIROM_INST_DIR)/multirom/enc/res; \
48 | cp -a $(TARGET_ROOT_OUT)/trampoline_encmnt $(MULTIROM_INST_DIR)/multirom/enc/; \
49 | cp -a $(TARGET_OUT_EXECUTABLES)/linker $(MULTIROM_INST_DIR)/multirom/enc/; \
50 | cp -a $(install_zip_path)/prebuilt-installer/multirom/res/Roboto-Regular.ttf $(MULTIROM_INST_DIR)/multirom/enc/res/; \
51 | \
52 | cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libcryptfslollipop.so $(MULTIROM_INST_DIR)/multirom/enc/; \
53 | cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libcrypto.so $(MULTIROM_INST_DIR)/multirom/enc/; \
54 | cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libc.so $(MULTIROM_INST_DIR)/multirom/enc/; \
55 | cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libcutils.so $(MULTIROM_INST_DIR)/multirom/enc/; \
56 | cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libdl.so $(MULTIROM_INST_DIR)/multirom/enc/; \
57 | cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libhardware.so $(MULTIROM_INST_DIR)/multirom/enc/; \
58 | cp -a $(TARGET_OUT_SHARED_LIBRARIES)/liblog.so $(MULTIROM_INST_DIR)/multirom/enc/; \
59 | cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libm.so $(MULTIROM_INST_DIR)/multirom/enc/; \
60 | cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libstdc++.so $(MULTIROM_INST_DIR)/multirom/enc/; \
61 | cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libc++.so $(MULTIROM_INST_DIR)/multirom/enc/; \
62 | if [ -n "$(MR_ENCRYPTION_SETUP_SCRIPT)" ]; then sh "$(ANDROID_BUILD_TOP)/$(MR_ENCRYPTION_SETUP_SCRIPT)" "$(ANDROID_BUILD_TOP)" "$(MULTIROM_INST_DIR)/multirom/enc"; fi; \
63 | fi
64 |
65 | mkdir $(MULTIROM_INST_DIR)/multirom/infos
66 | if [ -n "$(MR_INFOS)" ]; then cp -r $(PWD)/$(MR_INFOS)/* $(MULTIROM_INST_DIR)/multirom/infos/; fi
67 | cp -a $(TARGET_OUT_OPTIONAL_EXECUTABLES)/bbootimg $(MULTIROM_INST_DIR)/scripts/
68 | cp $(PWD)/$(MR_FSTAB) $(MULTIROM_INST_DIR)/multirom/mrom.fstab
69 | $(install_zip_path)/extract_boot_dev.sh $(PWD)/$(MR_FSTAB) $(MULTIROM_INST_DIR)/scripts/bootdev
70 | $(install_zip_path)/make_updater_script.sh "$(MR_DEVICES)" $(MULTIROM_INST_DIR)/META-INF/com/google/android "Installing MultiROM for"
71 | rm -f $(MULTIROM_ZIP_TARGET).zip $(MULTIROM_ZIP_TARGET)-unsigned.zip
72 | cd $(MULTIROM_INST_DIR) && zip -qr ../$(notdir $@)-unsigned.zip *
73 | java -jar $(HOST_OUT_JAVA_LIBRARIES)/signapk.jar $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem $(DEFAULT_SYSTEM_DEV_CERTIFICATE).pk8 $(MULTIROM_ZIP_TARGET)-unsigned.zip $(MULTIROM_ZIP_TARGET).zip
74 | $(install_zip_path)/rename_zip.sh $(MULTIROM_ZIP_TARGET) $(TARGET_DEVICE) $(PWD)/$(multirom_local_path)/version.h
75 | @echo ----- Made MultiROM ZIP installer -------- $@.zip
76 |
77 | .PHONY: multirom_zip
78 | multirom_zip: $(MULTIROM_ZIP_TARGET)
79 |
80 |
81 |
82 | MULTIROM_UNINST_TARGET := $(PRODUCT_OUT)/multirom_uninstaller
83 | MULTIROM_UNINST_DIR := $(PRODUCT_OUT)/multirom_uninstaller
84 |
85 | $(MULTIROM_UNINST_TARGET): signapk bbootimg
86 | @echo ----- Making MultiROM uninstaller ------
87 | rm -rf $(MULTIROM_UNINST_DIR)
88 | mkdir -p $(MULTIROM_UNINST_DIR)
89 | cp -a $(install_zip_path)/prebuilt-uninstaller/* $(MULTIROM_UNINST_DIR)/
90 | cp -a $(TARGET_OUT_OPTIONAL_EXECUTABLES)/bbootimg $(MULTIROM_UNINST_DIR)/scripts/
91 | $(install_zip_path)/extract_boot_dev.sh $(PWD)/$(MR_FSTAB) $(MULTIROM_UNINST_DIR)/scripts/bootdev
92 | echo $(MR_RD_ADDR) > $(MULTIROM_UNINST_DIR)/scripts/rd_addr
93 | $(install_zip_path)/make_updater_script.sh "$(MR_DEVICES)" $(MULTIROM_UNINST_DIR)/META-INF/com/google/android "MultiROM uninstaller -"
94 | rm -f $(MULTIROM_UNINST_TARGET).zip $(MULTIROM_UNINST_TARGET)-unsigned.zip
95 | cd $(MULTIROM_UNINST_DIR) && zip -qr ../$(notdir $@)-unsigned.zip *
96 | java -jar $(HOST_OUT_JAVA_LIBRARIES)/signapk.jar $(DEFAULT_SYSTEM_DEV_CERTIFICATE).x509.pem $(DEFAULT_SYSTEM_DEV_CERTIFICATE).pk8 $(MULTIROM_UNINST_TARGET)-unsigned.zip $(MULTIROM_UNINST_TARGET).zip
97 | @echo ----- Made MultiROM uninstaller -------- $@.zip
98 |
99 | .PHONY: multirom_uninstaller
100 | multirom_uninstaller: $(MULTIROM_UNINST_TARGET)
101 |
--------------------------------------------------------------------------------
/install_zip/README.md:
--------------------------------------------------------------------------------
1 | # MultiROM ZIP installer
2 | This folder contains prebuilt part of the ZIP installer for MultiROM - the file
3 | which is flashed in recovery and it installs MultiROM to the device.
4 |
5 | To build the ZIP file, use target `multirom_zip`.
6 |
7 | make multirom_zip
8 |
9 | The zip file is automatically signed with testkey.
10 |
--------------------------------------------------------------------------------
/install_zip/extract_boot_dev.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | FSTAB="$1"
3 | DEST_FILE="$2"
4 |
5 | if [ $# != "2" ]; then
6 | echo "Usage: $0 [path to fstab] [path to dest dir]"
7 | exit 1
8 | fi
9 |
10 | itr=-1
11 | for tok in $(grep -v "^ *#.*$" "$FSTAB"); do
12 | case "$itr" in
13 | "-1") # mount point
14 | if [ "$tok" = "/boot" ]; then
15 | itr="0"
16 | fi
17 | ;;
18 | "0") # filesystem
19 | itr=$(($itr+1))
20 | ;;
21 | "1") # device
22 | if [ "${tok##/dev*}" ]; then
23 | echo "Unsupported fstab format!"
24 | exit 1
25 | fi
26 |
27 | echo "$tok" > "$DEST_FILE"
28 | echo "Used boot device: $tok"
29 | exit 0
30 | ;;
31 | esac
32 | done
33 |
34 | echo "Could not find /boot mountpoint in fstab!"
35 | exit 1
36 |
--------------------------------------------------------------------------------
/install_zip/make_updater_script.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | DEVICES=$1
3 | SCRIPT_PATH=$2
4 | TITLE=$3
5 | CHECK_PROPS="ro.product.device ro.build.product"
6 |
7 | if [ "$#" -ne "3" ]; then
8 | echo "Usage: $0 [device] [path to folder with updater-script] [ZIP title]"
9 | exit 1
10 | fi
11 |
12 | fail()
13 | {
14 | echo make_updater_script.sh has failed: $1
15 | exit 1
16 | }
17 |
18 | mv ${SCRIPT_PATH}/updater-script ${SCRIPT_PATH}/updater-script-base || fail "Failed to copy updater-script base"
19 |
20 | assert_str="assert("
21 | for dev in $DEVICES; do
22 | for prop in $CHECK_PROPS; do
23 | assert_str="${assert_str}getprop(\"$prop\") == \"$dev\" || "
24 | done
25 | assert_str="${assert_str}\n "
26 | done
27 |
28 | assert_str="${assert_str% || \\n *});\n"
29 |
30 | printf "$assert_str" > ${SCRIPT_PATH}/updater-script || fail "Failed to write assert line into updater-script!"
31 |
32 | echo "" >> ${SCRIPT_PATH}/updater-script
33 | echo "ui_print(\"$TITLE $DEVICES\");" >> ${SCRIPT_PATH}/updater-script
34 | echo "" >> ${SCRIPT_PATH}/updater-script
35 |
36 | cat ${SCRIPT_PATH}/updater-script-base >> ${SCRIPT_PATH}/updater-script || fail "Failed to add base updater-script file!"
37 | rm ${SCRIPT_PATH}/updater-script-base
38 |
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/META-INF/com/google/android/update-binary:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/META-INF/com/google/android/update-binary
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/META-INF/com/google/android/updater-script:
--------------------------------------------------------------------------------
1 | # Assert check for appropriate device is added during build,
2 | # see ../make_updater_script.sh and ../Android.mk
3 |
4 | show_progress(1.00000, 10);
5 |
6 | ui_print("Extracting binaries...");
7 | run_program("/sbin/busybox", "mount", "/data");
8 |
9 | delete_recursive("/tmp/multirom");
10 | run_program("/sbin/busybox", "mkdir", "/tmp/multirom");
11 | package_extract_dir("multirom", "/tmp/multirom/");
12 | package_extract_dir("scripts", "/tmp/");
13 |
14 | set_perm(0, 0, 0777, "/tmp/multirom/busybox");
15 | set_perm(0, 0, 0777, "/tmp/bbootimg");
16 | set_perm(0, 0, 0777, "/tmp/extract_multirom.sh");
17 | set_perm(0, 0, 0777, "/tmp/inject_boot.sh");
18 |
19 | assert(run_program("/tmp/extract_multirom.sh") == 0);
20 | ui_print("Injecting boot image...");
21 | assert(run_program("/tmp/inject_boot.sh") == 0);
22 |
23 | ui_print("Cleaning up...");
24 | delete_recursive("/tmp/boot");
25 | delete_recursive("/tmp/multirom");
26 | delete("/tmp/bbootimg");
27 | delete("/tmp/bootimg.cfg");
28 | delete("/tmp/initrd.img");
29 | delete("/tmp/zImage");
30 | delete("/tmp/boot.img");
31 | delete("/tmp/dtb.img");
32 | delete("/tmp/second.img");
33 | delete("/tmp/newboot.img");
34 | delete("/tmp/extract_multirom.sh");
35 | delete("/tmp/inject_boot.sh");
36 | delete("/tmp/bootdev");
37 | delete("/tmp/rd_addr");
38 | delete("/tmp/use_mrom_fstab");
39 |
40 | ui_print("Installation complete!");
41 |
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/busybox:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/busybox
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/exfat-fuse:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/exfat-fuse
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_android.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_android.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_androidl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_androidl.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_aokp1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_aokp1.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_aokp2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_aokp2.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_cm1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_cm1.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_cm2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_cm2.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_default.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_du.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_du.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_firefox.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_firefox.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_linux.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_linux.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_miui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_miui.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_omni.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_omni.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_pa.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_pa.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_pa2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_pa2.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_slimkat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_slimkat.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_ubuntu1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_ubuntu1.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_ubuntu2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_ubuntu2.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_ubuntu3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_ubuntu3.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/icons/romic_viperone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/icons/romic_viperone.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/lz4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/lz4
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/ntfs-3g:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/ntfs-3g
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/OxygenMono-LICENSE_OFL.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012, vernon adams (vern@newtypography.co.uk), with Reserved Font Names 'Oxygen'
2 | This Font Software is licensed under the SIL Open Font License, Version 1.1.
3 | This license is copied below, and is also available with a FAQ at:
4 | http://scripts.sil.org/OFL
5 |
6 |
7 | -----------------------------------------------------------
8 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9 | -----------------------------------------------------------
10 |
11 | PREAMBLE
12 | The goals of the Open Font License (OFL) are to stimulate worldwide
13 | development of collaborative font projects, to support the font creation
14 | efforts of academic and linguistic communities, and to provide a free and
15 | open framework in which fonts may be shared and improved in partnership
16 | with others.
17 |
18 | The OFL allows the licensed fonts to be used, studied, modified and
19 | redistributed freely as long as they are not sold by themselves. The
20 | fonts, including any derivative works, can be bundled, embedded,
21 | redistributed and/or sold with any software provided that any reserved
22 | names are not used by derivative works. The fonts and derivatives,
23 | however, cannot be released under any other type of license. The
24 | requirement for fonts to remain under this license does not apply
25 | to any document created using the fonts or their derivatives.
26 |
27 | DEFINITIONS
28 | "Font Software" refers to the set of files released by the Copyright
29 | Holder(s) under this license and clearly marked as such. This may
30 | include source files, build scripts and documentation.
31 |
32 | "Reserved Font Name" refers to any names specified as such after the
33 | copyright statement(s).
34 |
35 | "Original Version" refers to the collection of Font Software components as
36 | distributed by the Copyright Holder(s).
37 |
38 | "Modified Version" refers to any derivative made by adding to, deleting,
39 | or substituting -- in part or in whole -- any of the components of the
40 | Original Version, by changing formats or by porting the Font Software to a
41 | new environment.
42 |
43 | "Author" refers to any designer, engineer, programmer, technical
44 | writer or other person who contributed to the Font Software.
45 |
46 | PERMISSION & CONDITIONS
47 | Permission is hereby granted, free of charge, to any person obtaining
48 | a copy of the Font Software, to use, study, copy, merge, embed, modify,
49 | redistribute, and sell modified and unmodified copies of the Font
50 | Software, subject to the following conditions:
51 |
52 | 1) Neither the Font Software nor any of its individual components,
53 | in Original or Modified Versions, may be sold by itself.
54 |
55 | 2) Original or Modified Versions of the Font Software may be bundled,
56 | redistributed and/or sold with any software, provided that each copy
57 | contains the above copyright notice and this license. These can be
58 | included either as stand-alone text files, human-readable headers or
59 | in the appropriate machine-readable metadata fields within text or
60 | binary files as long as those fields can be easily viewed by the user.
61 |
62 | 3) No Modified Version of the Font Software may use the Reserved Font
63 | Name(s) unless explicit written permission is granted by the corresponding
64 | Copyright Holder. This restriction only applies to the primary font name as
65 | presented to the users.
66 |
67 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68 | Software shall not be used to promote, endorse or advertise any
69 | Modified Version, except to acknowledge the contribution(s) of the
70 | Copyright Holder(s) and the Author(s) or with their explicit written
71 | permission.
72 |
73 | 5) The Font Software, modified or unmodified, in part or in whole,
74 | must be distributed entirely under this license, and must not be
75 | distributed under any other license. The requirement for fonts to
76 | remain under this license does not apply to any document created
77 | using the Font Software.
78 |
79 | TERMINATION
80 | This license becomes null and void if any of the above conditions are
81 | not met.
82 |
83 | DISCLAIMER
84 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92 | OTHER DEALINGS IN THE FONT SOFTWARE.
93 |
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/OxygenMono-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/OxygenMono-Regular.ttf
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/Roboto-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/Roboto-Bold.ttf
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/Roboto-BoldItalic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/Roboto-BoldItalic.ttf
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/Roboto-Italic.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/Roboto-Italic.ttf
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/Roboto-Medium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/Roboto-Medium.ttf
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/Roboto-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/Roboto-Regular.ttf
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/RobotoCondensed-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/RobotoCondensed-Regular.ttf
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/miri_135x135.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/miri_135x135.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/miri_180x180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/miri_180x180.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/miri_54x54.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/miri_54x54.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/miri_60x60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/miri_60x60.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/miri_72x72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/miri_72x72.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/res/miri_90x90.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-installer/multirom/res/miri_90x90.png
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/multirom/ubuntu-init/local:
--------------------------------------------------------------------------------
1 | # Local filesystem mounting -*- shell-script -*-
2 |
3 | pre_mountroot()
4 | {
5 | [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top"
6 | run_scripts /scripts/local-top
7 | [ "$quiet" != "y" ] && log_end_msg
8 |
9 | # Don't wait for a root device that doesn't have a corresponding
10 | # device in /dev (ie, mtd0)
11 | if [ "${ROOT#/dev}" = "${ROOT}" ]; then
12 | return
13 | fi
14 |
15 | while [ -z "${FSTYPE}" ]; do
16 | FSTYPE=$(wait-for-root "${ROOT}" ${ROOTDELAY:-30})
17 |
18 | # Load ubi with the correct MTD partition and return since
19 | # fstype doesn't work with a char device like ubi.
20 | if [ -n "$UBIMTD" ]; then
21 | modprobe ubi mtd=$UBIMTD
22 | return
23 | fi
24 |
25 | # Run failure hooks, hoping one of them can fix up the system
26 | # and we can restart the wait loop. If they all fail, abort
27 | # and move on to the panic handler and shell.
28 | if [ -z "${FSTYPE}" ] && ! try_failure_hooks; then
29 | break
30 | fi
31 | done
32 |
33 | # We've given up, but we'll let the user fix matters if they can
34 | while [ -z "${FSTYPE}" -a ! -e "${ROOT}" ]; do
35 | # give hint about renamed root
36 | case "${ROOT}" in
37 | /dev/hd*)
38 | suffix="${ROOT#/dev/hd}"
39 | major="${suffix%[[:digit:]]}"
40 | major="${major%[[:digit:]]}"
41 | if [ -d "/sys/block/sd${major}" ]; then
42 | echo "WARNING bootdevice may be renamed. Try root=/dev/sd${suffix}"
43 | fi
44 | ;;
45 | /dev/sd*)
46 | suffix="${ROOT#/dev/sd}"
47 | major="${suffix%[[:digit:]]}"
48 | major="${major%[[:digit:]]}"
49 | if [ -d "/sys/block/hd${major}" ]; then
50 | echo "WARNING bootdevice may be renamed. Try root=/dev/hd${suffix}"
51 | fi
52 | ;;
53 | esac
54 | echo "Gave up waiting for root device. Common problems:"
55 | echo " - Boot args (cat /proc/cmdline)"
56 | echo " - Check rootdelay= (did the system wait long enough?)"
57 | echo " - Check root= (did the system wait for the right device?)"
58 | echo " - Missing modules (cat /proc/modules; ls /dev)"
59 | panic "ALERT! ${ROOT} does not exist. Dropping to a shell!"
60 | done
61 | }
62 |
63 | mountroot()
64 | {
65 | pre_mountroot
66 |
67 | # Get the root filesystem type if not set
68 | if [ -z "${ROOTFSTYPE}" ]; then
69 | [ -n "${FSTYPE}" ] || FSTYPE=$(blkid -s TYPE -o value "${ROOT}")
70 | ROOTFSTYPE="${FSTYPE}"
71 | else
72 | FSTYPE=${ROOTFSTYPE}
73 | fi
74 |
75 | [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
76 | run_scripts /scripts/local-premount
77 | [ "$quiet" != "y" ] && log_end_msg
78 |
79 | if [ "${readonly}" = "y" ] && \
80 | [ -z "$LOOP" ]; then
81 | roflag=-r
82 | else
83 | roflag=-w
84 | fi
85 |
86 | # FIXME This has no error checking
87 | [ -n "${FSTYPE}" ] && modprobe ${FSTYPE}
88 |
89 | # FIXME This has no error checking
90 | # Mount root
91 | mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} ${rootmnt}
92 | mountroot_status="$?"
93 | if [ "$LOOP" ]; then
94 | if [ "$mountroot_status" != 0 ]; then
95 | if [ ${FSTYPE} = ntfs ] || [ ${FSTYPE} = vfat ]; then
96 | panic "
97 | Could not mount the partition ${ROOT}.
98 | This could also happen if the file system is not clean because of an operating
99 | system crash, an interrupted boot process, an improper shutdown, or unplugging
100 | of a removable device without first unmounting or ejecting it. To fix this,
101 | simply reboot into Windows, let it fully start, log in, run 'chkdsk /r', then
102 | gracefully shut down and reboot back into Windows. After this you should be
103 | able to reboot again and resume the installation.
104 | (filesystem = ${FSTYPE}, error code = $mountroot_status)
105 | "
106 | fi
107 | fi
108 |
109 | mkdir -p /host
110 | mount -o move ${rootmnt} /host
111 |
112 | while [ ! -e "/host/${LOOP#/}" ]; do
113 | panic "ALERT! /host/${LOOP#/} does not exist. Dropping to a shell!"
114 | done
115 |
116 | # Get the loop filesystem type if not set
117 | if [ -z "${LOOPFSTYPE}" ]; then
118 | eval $(fstype < "/host/${LOOP#/}")
119 | else
120 | FSTYPE="${LOOPFSTYPE}"
121 | fi
122 | if [ "$FSTYPE" = "unknown" ] && [ -x /sbin/blkid ]; then
123 | FSTYPE=$(/sbin/blkid -s TYPE -o value "/host/${LOOP#/}")
124 | [ -z "$FSTYPE" ] && FSTYPE="unknown"
125 | fi
126 |
127 | if [ ${readonly} = y ]; then
128 | roflag=-r
129 | else
130 | roflag=-w
131 | fi
132 |
133 | # FIXME This has no error checking
134 | modprobe loop
135 | modprobe ${FSTYPE}
136 |
137 | # FIXME This has no error checking
138 | mount ${roflag} -o loop -t ${FSTYPE} ${LOOPFLAGS} "/host/${LOOP#/}" ${rootmnt}
139 |
140 | if [ -d ${rootmnt}/host ]; then
141 | mount -o move /host ${rootmnt}/host
142 | fi
143 | elif [ "$ROOTSUBDIR" ]; then
144 | if [ "$mountroot_status" != 0 ]; then
145 | panic "
146 | Could not mount the partition ${ROOT}.
147 | This could also happen if the file system is not clean because of an operating
148 | system crash, an interrupted boot process, an improper shutdown, or unplugging
149 | of a removable device without first unmounting or ejecting it.
150 | (filesystem = ${FSTYPE}, error code = $mountroot_status)
151 | "
152 | fi
153 |
154 | mkdir -p /host
155 | mount -o move ${rootmnt} /host
156 |
157 | if [ ! -d "/host/$ROOTSUBDIR" ]; then
158 | panic "Failed to bind folder ${ROOTSUBDIR} as root: folder does not exist."
159 | fi
160 |
161 | mount -o bind /host/$ROOTSUBDIR ${rootmnt}
162 | if [ -d ${rootmnt}/host ]; then
163 | mount -o move /host ${rootmnt}/host
164 | fi
165 | fi
166 |
167 | [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
168 | run_scripts /scripts/local-bottom
169 | [ "$quiet" != "y" ] && log_end_msg
170 | }
171 |
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/scripts/extract_multirom.sh:
--------------------------------------------------------------------------------
1 | #!/sbin/sh
2 | base=""
3 | if [ -d "/data/media/multirom" ] ; then
4 | base="/data/media/multirom"
5 | elif [ -d "/data/media/0/multirom" ] ; then
6 | base="/data/media/0/multirom"
7 | else
8 | if [ -d "/data/media/0" ] ; then
9 | base="/data/media/0/multirom"
10 | else
11 | base="/data/media/multirom"
12 | fi
13 |
14 | mkdir "$base"
15 | chown root:root "$base"
16 | chmod 770 "$base"
17 |
18 | mkdir "$base/roms"
19 | chown media_rw:media_rw "$base/roms"
20 | chmod 777 "$base/roms"
21 |
22 | touch "$base/.nomedia"
23 | chown media_rw:media_rw "$base/.nomedia"
24 | fi
25 |
26 | rm "$base/boot.img-ubuntu"*
27 | rm "$base/infos/"*
28 | rm "$base/res/"*
29 | cp -r /tmp/multirom/* "$base/"
30 | chmod 755 "$base/multirom"
31 | chmod 755 "$base/busybox"
32 | chmod 750 "$base/trampoline"
33 | chmod 755 "$base/kexec"
34 | chmod 755 "$base/ntfs-3g"
35 | chmod 755 "$base/exfat-fuse"
36 | chmod 755 "$base/lz4"
37 | chmod 755 "$base/ubuntu-init/init"
38 | chmod 644 "$base/ubuntu-init/local"
39 | chmod 755 "$base/ubuntu-touch-init/init"
40 | chmod 644 "$base/ubuntu-touch-init/scripts/touch"
41 | chmod 755 "$base/ubuntu-touch-sysimage-init/init"
42 | chmod 644 "$base/ubuntu-touch-sysimage-init/scripts/touch"
43 |
44 | # This makes does not allows access for media scanner on android, but
45 | # still is enough for ubuntu
46 | chmod 770 "$base"
47 | chown root:root "$base"
48 |
--------------------------------------------------------------------------------
/install_zip/prebuilt-installer/scripts/inject_boot.sh:
--------------------------------------------------------------------------------
1 | #!/sbin/sh
2 | BOOT_DEV="$(cat /tmp/bootdev)"
3 |
4 | if [ ! -e "$BOOT_DEV" ]; then
5 | echo "BOOT_DEV \"$BOOT_DEV\" does not exist!"
6 | return 1
7 | fi
8 |
9 | chmod 755 /tmp/multirom/trampoline
10 | chmod 755 /tmp/multirom/busybox
11 | chmod 755 /tmp/multirom/lz4
12 | /tmp/multirom/trampoline --inject="$BOOT_DEV" --mrom_dir="/tmp/multirom" -f
13 | return $?
14 |
--------------------------------------------------------------------------------
/install_zip/prebuilt-uninstaller/META-INF/com/google/android/update-binary:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-uninstaller/META-INF/com/google/android/update-binary
--------------------------------------------------------------------------------
/install_zip/prebuilt-uninstaller/META-INF/com/google/android/updater-script:
--------------------------------------------------------------------------------
1 | # Assert check for appropriate device is added during build,
2 | # see ../make_updater_script.sh and ../Android.mk
3 |
4 | show_progress(1.00000, 10);
5 |
6 | ui_print("Extracting binaries...");
7 | run_program("/sbin/busybox", "mount", "/data");
8 |
9 | package_extract_dir("scripts", "/tmp/");
10 |
11 | set_perm(0, 0, 0777, "/tmp/busybox");
12 | set_perm(0, 0, 0777, "/tmp/bbootimg");
13 | set_perm(0, 0, 0777, "/tmp/lz4");
14 | set_perm(0, 0, 0777, "/tmp/erase_multirom.sh");
15 | set_perm(0, 0, 0777, "/tmp/clear_boot.sh");
16 |
17 | ui_print("Removing MultiROM from boot.img...");
18 | assert(run_program("/tmp/clear_boot.sh") == 0);
19 | ui_print("Erasing MultiROM's data folder...");
20 | assert(run_program("/tmp/erase_multirom.sh") == 0);
21 |
22 | ui_print("Cleaning up...");
23 | delete_recursive("/tmp/boot");
24 | delete_recursive("/tmp/multirom");
25 | delete("/tmp/lz4");
26 | delete("/tmp/bootimg.cfg");
27 | delete("/tmp/initrd.img");
28 | delete("/tmp/zImage");
29 | delete("/tmp/dtb.img");
30 | delete("/tmp/second.img");
31 | delete("/tmp/bbootimg");
32 | delete("/tmp/boot.img");
33 | delete("/tmp/newboot.img");
34 | delete("/tmp/busybox");
35 | delete("/tmp/erase_multirom.sh");
36 | delete("/tmp/clear_boot.sh");
37 | delete("/tmp/bootdev");
38 | delete("/tmp/rd_addr");
39 |
40 | ui_print("MultiROM was removed!");
41 |
--------------------------------------------------------------------------------
/install_zip/prebuilt-uninstaller/scripts/busybox:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-uninstaller/scripts/busybox
--------------------------------------------------------------------------------
/install_zip/prebuilt-uninstaller/scripts/clear_boot.sh:
--------------------------------------------------------------------------------
1 | #!/sbin/sh
2 | BUSYBOX="/tmp/busybox"
3 | LZ4="/tmp/lz4"
4 | BOOT_DEV="$(cat /tmp/bootdev)"
5 | RD_ADDR="$(cat /tmp/rd_addr)"
6 |
7 | CMPR_GZIP=0
8 | CMPR_LZ4=1
9 |
10 | if [ ! -e "$BOOT_DEV" ]; then
11 | echo "BOOT_DEV \"$BOOT_DEV\" does not exist!"
12 | return 1
13 | fi
14 |
15 | dd if=$BOOT_DEV of=/tmp/boot.img
16 | /tmp/bbootimg -x /tmp/boot.img /tmp/bootimg.cfg /tmp/zImage /tmp/initrd.img /tmp/second.img /tmp/dtb.img
17 | if [ ! -f /tmp/zImage ] ; then
18 | echo "Failed to extract boot.img"
19 | return 1
20 | fi
21 |
22 | rm -r /tmp/boot
23 | mkdir /tmp/boot
24 |
25 | cd /tmp/boot
26 | rd_cmpr=-1
27 | magic=$($BUSYBOX hexdump -n 4 -v -e '/1 "%02X"' "../initrd.img")
28 | case "$magic" in
29 | 1F8B*) # GZIP
30 | $BUSYBOX gzip -d -c "../initrd.img" | $BUSYBOX cpio -i
31 | rd_cmpr=CMPR_GZIP;
32 | ;;
33 | 02214C18) # LZ4
34 | $LZ4 -d "../initrd.img" stdout | $BUSYBOX cpio -i
35 | rd_cmpr=CMPR_LZ4;
36 | ;;
37 | *)
38 | echo "invalid ramdisk magic $magic"
39 | ;;
40 | esac
41 |
42 | if [ rd_cmpr == -1 ] || [ ! -f /tmp/boot/init ] ; then
43 | echo "Failed to extract ramdisk!"
44 | return 1
45 | fi
46 |
47 | # restore init
48 | if [ -e /tmp/boot/main_init ] ; then
49 | rm /tmp/boot/init
50 | mv /tmp/boot/main_init /tmp/boot/init
51 | fi
52 |
53 | chmod 750 /tmp/boot/init
54 |
55 | # restore ueventd and watchdogd symlink
56 | if [ -L /tmp/boot/sbin/ueventd ] ; then
57 | ln -sf ../init /tmp/boot/sbin/ueventd
58 | fi
59 | if [ -L /tmp/boot/sbin/watchdogd ] ; then
60 | ln -sf ../init /tmp/boot/sbin/watchdogd
61 | fi
62 |
63 | if [ -e /tmp/boot/mrom.fstab ] ; then
64 | rm /tmp/boot/mrom.fstab
65 | fi
66 |
67 | # Remove encryption files
68 | rm -rf /tmp/boot/mrom_enc
69 |
70 | # pack the image again
71 | cd /tmp/boot
72 |
73 | case $rd_cmpr in
74 | CMPR_GZIP)
75 | find . | $BUSYBOX cpio -o -H newc | $BUSYBOX gzip > "../initrd.img"
76 | ;;
77 | CMPR_LZ4)
78 | find . | $BUSYBOX cpio -o -H newc | $LZ4 stdin "../initrd.img"
79 | ;;
80 | esac
81 |
82 | echo "bootsize = 0x0" >> /tmp/bootimg.cfg
83 | if [ -n "$RD_ADDR" ]; then
84 | echo "Using ramdisk addr $RD_ADDR"
85 | echo "ramdiskaddr = $RD_ADDR" >> /tmp/bootimg.cfg
86 | fi
87 |
88 | cd /tmp
89 |
90 | dtb_cmd=""
91 | if [ -f "dtb.img" ]; then
92 | dtb_cmd="-d dtb.img"
93 | fi
94 |
95 | /tmp/bbootimg --create newboot.img -f bootimg.cfg -k zImage -r initrd.img $dtb_cmd
96 |
97 | if [ ! -e "/tmp/newboot.img" ] ; then
98 | echo "Failed to inject boot.img!"
99 | return 1
100 | fi
101 |
102 | echo "Writing new boot.img..."
103 | dd bs=4096 if=/tmp/newboot.img of=$BOOT_DEV
104 | return $?
105 |
--------------------------------------------------------------------------------
/install_zip/prebuilt-uninstaller/scripts/erase_multirom.sh:
--------------------------------------------------------------------------------
1 | #!/sbin/sh
2 | base=""
3 | if [ -d "/data/media/multirom" ] ; then
4 | base="/data/media/multirom"
5 | elif [ -d "/data/media/0/multirom" ] ; then
6 | base="/data/media/0/multirom"
7 | else
8 | echo "MultiROM folder was not found"
9 | exit 0
10 | fi
11 |
12 | /tmp/busybox chattr -R -i "$base"
13 | rm -r "$base"
14 | return $?
15 |
--------------------------------------------------------------------------------
/install_zip/prebuilt-uninstaller/scripts/lz4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/install_zip/prebuilt-uninstaller/scripts/lz4
--------------------------------------------------------------------------------
/install_zip/rename_zip.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | ZIP_PATH="$1"
3 | DEVICE="$2"
4 | VERSION_H="$3"
5 |
6 | if [ $# != "3" ]; then
7 | echo "Usage: $0 [zip path base] [device] [path to version.h]"
8 | exit 1
9 | fi
10 |
11 | SRC_PATH="$ZIP_PATH.zip"
12 |
13 | if [ ! -f "$VERSION_H" ] || [ ! -f "$SRC_PATH" ]; then
14 | echo "File not found"
15 | exit 1
16 | fi
17 |
18 |
19 | ver_main="$(cat $VERSION_H | grep VERSION_MULTIROM)"
20 | ver_main=${ver_main#*define VERSION_MULTIROM }
21 | ver_dev="$(cat $VERSION_H | grep VERSION_DEV_FIX)"
22 | ver_dev=${ver_dev#*define VERSION_DEV_FIX \"}
23 | ver_dev=${ver_dev%\"}
24 |
25 | out_name="${ZIP_PATH}-$(date +%Y%m%d)-v${ver_main}${ver_dev}-UNOFFICIAL-${DEVICE}.zip"
26 | echo "--- Creating $out_name"
27 | cp -a "$ZIP_PATH.zip" "$out_name" || exit 1
28 | cd "$(dirname ${out_name})" && md5sum "$(basename ${out_name})" > "${out_name}.md5sum"
29 |
--------------------------------------------------------------------------------
/installer/README.md:
--------------------------------------------------------------------------------
1 | # MultiROM reference installer
2 | This is a reference installer file structure.
3 | It should be used only for Linux
4 | based ROMs, where classic update.zip format is unsuitable.
5 |
6 | ## Installation file
7 | The installation file itself is a ZIP archive, renamed to `*.mrom` so that
8 | recovery can know what is just ZIP archive and what is MultiROM
9 | installer
10 | file.
11 | I recommend not to use compression when making this ZIP, the installation
12 | will be faster and the ROM is already compressed in .tar.gz files.
13 |
14 | While this format should be versatile enough, feel free to contact me if you
15 | need something changed - if it is reasonable, there will be no problem
16 | adding changes you need.
17 |
18 | ### Content
19 | * **manifest.txt** - File with info for the recovery. Read the comments in that
20 | file to know more.
21 |
22 | * **rom** - Folder with tar.gz archives containing each of the ROM base folders
23 | (e.g. `root.tar.gz`, `system.tar.gz`, ...). These can be split to
24 | multiple files (and should be, if the file is bigger than ~800 MB).
25 | Pattern is name_XX.tar.gz, so for example `root_00.tar.gz` and
26 | `root_01.tar.gz`. Numbering __must__ start at 00!
27 | Command `tar --numeric-owner --overwrite -xf` is used to extract
28 | these tar files.
29 |
30 | * **root_dir** - Content of this folder will be copied to root of the ROM
31 | folder - `/sdcard/multirom/roms/*rom_name*`. It can contain
32 | `rom_info.txt` if it's Linux ROM or the `boot` folder and/or
33 | `boot.img` if it's Android-based ROM.
34 |
35 | * **pre_install, post_install** - Sh scripts in these folders will be ran
36 | before/after the installation. They must return success return
37 | code else the installation is aborted. Path to root
38 | folder/folder where images are mounted is
39 | passed as argument to this script, script can then cd to one of
40 | the base folders and do whatever it wants to. Scripts are ran
41 | in alphabetical order (use numbers, `01_script.sh`, `02_script.sh`).
42 | **All** files from both directories are extracted to `/tmp/script/`,
43 | which means you can put e.g. binary blobs in there and copy them
44 | to proper place in the sh scripts or pack some binaries needed
45 | by the scripts (e.g. gnutar, remember to set chmod before running them).
46 |
--------------------------------------------------------------------------------
/installer/manifest.txt:
--------------------------------------------------------------------------------
1 | # This file contains info for recovery installation process
2 | # Should be placed in root of installation zip file and must be
3 | # named "manifest.txt".
4 | # Make sure you got the syntax correct, as the parser is probably pretty
5 | # dumb. Lines with comments must start with #. Beware the whitespaces.
6 | # If you need to use " character in string, just use it, no need to escape it
7 | # MultiROM searches for first and last " on the line.
8 | # These comments should not be deleted.
9 |
10 | # Manifest version
11 | manifest_ver="1"
12 |
13 | # Min MultiROM version
14 | min_mrom_ver="5"
15 |
16 | # Supported devices codenames. These are checked against
17 | # ro.product.device property
18 | devices="grouper tilapia"
19 |
20 | # ROM name. If not specified, name of the installation file is used,
21 | # which is recommmended. Don't use spaces.
22 | #rom_name="Generic_ROM"
23 |
24 | # Installation text, it is displayed in recovery during installation.
25 | # Use \n to make newlines
26 | install_text="Generic ROM 1.2.3.4\nWelcome to Generic ROM!\n\n This installation process may take a while"
27 |
28 | # Enable installation to internal ext4 memory
29 | enable_internal="1"
30 |
31 | # USB flash drive installation, set to empty string to disable.
32 | # You can install to either subdirectory or ext4 disk image.
33 | # Subdirectory is prefered.
34 | # usb_dir_fs - list of supported fs types
35 | # usb_img_fs - list of supported underlaying fs types, images are always ext4
36 | usb_dir_fs="ext2 ext3 ext4"
37 | usb_img_fs="vfat ntfs"
38 |
39 | # ROM base folders - the ones in root of ROM folder.
40 | # There can only be maximum of 5 base folders!
41 | # If USB drive with filesystem for images is used, each of these is ext4 image
42 | # If this is a Linux ROM, you usually want just "root". If it is Android-based,
43 | # you probably want "cache", "system" and "data"
44 | # Specify also min and default size of the image created for USB drives
45 | # in megabytes. Min value is used to check free space if it is not installed
46 | # to image.
47 | # Syntax: name:MIN:DEFAULT name2:MIN:DEFAULT ...
48 | # Example: base_folders="data:50:1024 system:450:640 cache:50:450"
49 | base_folders="root:1000:1500"
50 |
--------------------------------------------------------------------------------
/installer/post_install/.placeforscripts:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/installer/post_install/.placeforscripts
--------------------------------------------------------------------------------
/installer/pre_install/.placeforscripts:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/installer/pre_install/.placeforscripts
--------------------------------------------------------------------------------
/installer/rom/root.tar.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tasssadar/multirom/3b11f02e770480750e821b5afcf4f8de2500a2d3/installer/rom/root.tar.gz
--------------------------------------------------------------------------------
/installer/root_dir/rom_info.txt:
--------------------------------------------------------------------------------
1 | # This file contains info about ROMs capabilites and boot process.
2 | # It should be placed in ROM's folder (eg. /media/multirom/roms/*rom_name*)
3 | # and must be named "rom_info.txt".
4 | # Make sure you got the syntax correct, as the parser is probably pretty
5 | # dumb. Lines with comments must start with #. Beware the whitespaces.
6 | # If you need to use " character in string, just use it, no need to escape it
7 | # MultiROM searches for first and last " on the line.
8 | # These comments should not be deleted.
9 |
10 | # So far, the only supported ROM type for these files is kexec-based linux
11 | type="kexec"
12 |
13 | # Paths to root of the ROM.
14 | # Both image and folder can be specified at one time, MultiROM will use
15 | # the one which it can find. If both are present, folder is used.
16 | # Must _not_ contain spaces.
17 | # Path is from root of the root partition, but you will usually want
18 | # to use following alias:
19 | # - %m - ROM's folder (eg. /media/multirom/roms/*rom_name*)
20 | root_dir="%m/root"
21 | root_img="%m/root.img"
22 | root_img_fs="ext4"
23 |
24 | # Path to kernel and initrd. Kernel path _must_ be specified.
25 | # Paths are relative to the folder in which is this file
26 | # Those can be outside the root folder/image, or use %r if it is in there:
27 | # kernel_path="%r/boot/vmlinuz"
28 | # If ROM is in images, it will mount the image and load it from there.
29 | # You can use * _at the end of the filename_ as wildcard character.
30 | kernel_path="%r/boot/vmlinuz"
31 | initrd_path="%r/boot/initrd.img"
32 |
33 | # Set up the cmdline
34 | # img_cmdline and dir_cmdline are appended to base_cmdline.
35 | # Several aliases are used:
36 | # - %b - base command line from bootloader. You want this as first thing in cmdline.
37 | # - %d - root device. is either "UUID=..." (USB drive) or "/dev/mmcblk0p9" or "/dev/mmcblk0p10"
38 | # - %r - root fs type
39 | # - %s - root directory, from root of the root device
40 | # - %i - root image, from root of the root device
41 | # - %f - fs of the root image
42 | base_cmdline="%b root=%d rootfstype=%r rw console=tty0 access=m2 quiet splash rootflags=defaults,noatime,nodiratime"
43 | img_cmdline="loop=%i loopfstype=%f"
44 | dir_cmdline="rootsubdir=%s"
45 |
--------------------------------------------------------------------------------
/kexec.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | #include "kexec.h"
23 | #include "lib/containers.h"
24 | #include "lib/log.h"
25 | #include "lib/util.h"
26 |
27 | // kexec --load-hardboot ./zImage --command-line="$(cat /proc/cmdline)" --mem-min=0xA0000000 --initrd=./rd.img
28 | // --mem-min should be somewhere in System RAM (see /proc/iomem). Location just above kernel seems to work fine.
29 | // It must not conflict with vmalloc ram. Vmalloc area seems to be allocated from top of System RAM.
30 |
31 | void kexec_init(struct kexec *k, const char *path)
32 | {
33 | k->args = NULL;
34 | kexec_add_arg(k, path);
35 | }
36 |
37 | void kexec_destroy(struct kexec *k)
38 | {
39 | list_clear(&k->args, &free);
40 | }
41 |
42 | int kexec_load_exec(struct kexec *k)
43 | {
44 | int i, len;
45 |
46 | INFO("Loading kexec:\n");
47 | for(i = 0; k->args && k->args[i]; ++i)
48 | {
49 | len = strlen(k->args[i]);
50 |
51 | if(len < 480)
52 | INFO(" %s\n", k->args[i]);
53 | else
54 | {
55 | char buff[481];
56 | char *itr;
57 | const char *end = k->args[i]+len;
58 | int chunk = 0;
59 |
60 | for(itr = k->args[i]; itr < end; itr += chunk)
61 | {
62 | chunk = imin(480, end - itr);
63 |
64 | memcpy(buff, itr, chunk);
65 | buff[chunk] = 0;
66 |
67 | INFO(" %s\n", buff);
68 | }
69 | }
70 | }
71 |
72 | if(run_cmd(k->args) == 0)
73 | return 0;
74 | else
75 | {
76 | ERROR("kexec call failed, re-running it to get info:\n");
77 | char *r = run_get_stdout(k->args);
78 | if(!r)
79 | ERROR("run_get_stdout returned NULL!\n");
80 |
81 | char *p = strtok(r, "\n\r");
82 | while(p)
83 | {
84 | ERROR(" %s\n", p);
85 | p = strtok(NULL, "\n\r");
86 | }
87 | free(r);
88 |
89 | return -1;
90 | }
91 | }
92 |
93 | void kexec_add_arg(struct kexec *k, const char *arg)
94 | {
95 | list_add(&k->args, strdup(arg));
96 | }
97 |
98 | void kexec_add_arg_prefix(struct kexec *k, const char *prefix, const char *value)
99 | {
100 | int len = strlen(prefix) + strlen(value) + 1;
101 | char *arg = malloc(len);
102 | snprintf(arg, len, "%s%s", prefix, value);
103 |
104 | list_add(&k->args, arg);
105 | }
106 |
107 | void kexec_add_kernel(struct kexec *k, const char *path, int hardboot)
108 | {
109 | if(hardboot)
110 | kexec_add_arg(k, "--load-hardboot");
111 | else
112 | kexec_add_arg(k, "-l");
113 | kexec_add_arg(k, path);
114 | }
115 |
--------------------------------------------------------------------------------
/kexec.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef KEXEC_H
19 | #define KEXEC_H
20 |
21 | struct kexec
22 | {
23 | char **args;
24 | };
25 |
26 | void kexec_init(struct kexec *k, const char *path);
27 | void kexec_destroy(struct kexec *k);
28 | int kexec_load_exec(struct kexec *k);
29 | void kexec_add_arg(struct kexec *k, const char *arg);
30 | void kexec_add_arg_prefix(struct kexec *k, const char *prefix, const char *value);
31 | void kexec_add_kernel(struct kexec *k, const char *path, int hardboot);
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/lib/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH:= $(call my-dir)
2 |
3 | common_SRC_FILES := \
4 | animation.c \
5 | button.c \
6 | colors.c \
7 | containers.c \
8 | framebuffer.c \
9 | framebuffer_generic.c \
10 | framebuffer_png.c \
11 | framebuffer_truetype.c \
12 | fstab.c \
13 | inject.c \
14 | input.c \
15 | listview.c \
16 | keyboard.c \
17 | mrom_data.c \
18 | notification_card.c \
19 | progressdots.c \
20 | tabview.c \
21 | touch_tracker.c \
22 | util.c \
23 | workers.c \
24 |
25 | common_C_INCLUDES := $(multirom_local_path)/lib \
26 | external/libpng \
27 | external/zlib \
28 | external/freetype/include \
29 | system/extras/libbootimg/include \
30 |
31 | # With these, GCC optimizes aggressively enough so full-screen alpha blending
32 | # is quick enough to be done in an animation
33 | common_C_FLAGS := -O3 -funsafe-math-optimizations
34 |
35 | ifeq ($(MR_INPUT_TYPE),)
36 | MR_INPUT_TYPE := type_b
37 | endif
38 | common_SRC_FILES += input_$(MR_INPUT_TYPE).c
39 |
40 | ifeq ($(MR_USE_QCOM_OVERLAY),true)
41 | common_C_FLAGS += -DMR_USE_QCOM_OVERLAY
42 | common_SRC_FILES += framebuffer_qcom_overlay.c
43 | ifneq ($(MR_QCOM_OVERLAY_HEADER),)
44 | common_C_FLAGS += -DMR_QCOM_OVERLAY_HEADER=\"../../../../$(MR_QCOM_OVERLAY_HEADER)\"
45 | else
46 | $(error MR_USE_QCOM_OVERLAY is true but MR_QCOM_OVERLAY_HEADER was not specified!)
47 | endif
48 | ifneq ($(MR_QCOM_OVERLAY_CUSTOM_PIXEL_FORMAT),)
49 | common_C_FLAGS += -DMR_QCOM_OVERLAY_CUSTOM_PIXEL_FORMAT=$(MR_QCOM_OVERLAY_CUSTOM_PIXEL_FORMAT)
50 | endif
51 | ifeq ($(MR_QCOM_OVERLAY_USE_VSYNC),true)
52 | common_C_FLAGS += -DMR_QCOM_OVERLAY_USE_VSYNC
53 | endif
54 | endif
55 |
56 |
57 |
58 | include $(CLEAR_VARS)
59 |
60 | LOCAL_MODULE := libmultirom_static
61 | LOCAL_MODULE_TAGS := eng
62 | LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
63 | LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)
64 | LOCAL_CFLAGS += $(common_C_FLAGS)
65 | LOCAL_C_INCLUDES += $(common_C_INCLUDES)
66 | LOCAL_SRC_FILES := $(common_SRC_FILES)
67 |
68 | include $(multirom_local_path)/device_defines.mk
69 |
70 | include $(BUILD_STATIC_LIBRARY)
71 |
72 |
73 |
74 | include $(CLEAR_VARS)
75 |
76 | LOCAL_MODULE := libmultirom
77 | LOCAL_MODULE_TAGS := eng
78 | LOCAL_SHARED_LIBRARIES := libcutils libc libm libpng libz libft2
79 | LOCAL_CFLAGS += $(common_C_FLAGS)
80 | LOCAL_SRC_FILES := $(common_SRC_FILES)
81 | LOCAL_C_INCLUDES += $(common_C_INCLUDES)
82 |
83 | include $(multirom_local_path)/device_defines.mk
84 |
85 | include $(BUILD_SHARED_LIBRARY)
86 |
87 |
88 |
89 | # We need static libtruetype but it isn't in standard android makefile :(
90 | LOCAL_PATH := external/freetype/
91 | include $(CLEAR_VARS)
92 |
93 | # compile in ARM mode, since the glyph loader/renderer is a hotspot
94 | # when loading complex pages in the browser
95 | #
96 | LOCAL_ARM_MODE := arm
97 |
98 | LOCAL_SRC_FILES := \
99 | src/base/ftbbox.c \
100 | src/base/ftbitmap.c \
101 | src/base/ftfstype.c \
102 | src/base/ftglyph.c \
103 | src/base/ftlcdfil.c \
104 | src/base/ftstroke.c \
105 | src/base/fttype1.c \
106 | src/base/ftbase.c \
107 | src/base/ftsystem.c \
108 | src/base/ftinit.c \
109 | src/base/ftgasp.c \
110 | src/raster/raster.c \
111 | src/sfnt/sfnt.c \
112 | src/smooth/smooth.c \
113 | src/autofit/autofit.c \
114 | src/truetype/truetype.c \
115 | src/cff/cff.c \
116 | src/psnames/psnames.c \
117 | src/pshinter/pshinter.c
118 |
119 | ifeq ($(shell if [ -e "$(ANDROID_BUILD_TOP)/external/freetype/src/gzip/ftgzip.c" ]; then echo "hasgzip"; fi),hasgzip)
120 | LOCAL_SRC_FILES += src/gzip/ftgzip.c
121 | endif
122 |
123 | ifeq ($(shell if [ -e "$(ANDROID_BUILD_TOP)/external/freetype/src/base/ftxf86.c" ]; then echo "found"; fi),found)
124 | LOCAL_SRC_FILES += src/base/ftxf86.c
125 | else
126 | LOCAL_SRC_FILES += \
127 | src/base/ftfntfmt.c \
128 | src/base/ftmm.c
129 | endif
130 |
131 | LOCAL_C_INCLUDES += \
132 | $(LOCAL_PATH)/builds \
133 | $(LOCAL_PATH)/include \
134 | external/libpng \
135 | external/zlib
136 |
137 | LOCAL_CFLAGS += -W -Wall
138 | LOCAL_CFLAGS += -fPIC -DPIC
139 | LOCAL_CFLAGS += "-DDARWIN_NO_CARBON"
140 | LOCAL_CFLAGS += "-DFT2_BUILD_LIBRARY"
141 |
142 | LOCAL_STATIC_LIBRARIES += libpng libz
143 |
144 | # the following is for testing only, and should not be used in final builds
145 | # of the product
146 | #LOCAL_CFLAGS += "-DTT_CONFIG_OPTION_BYTECODE_INTERPRETER"
147 |
148 | LOCAL_CFLAGS += -O2
149 |
150 | LOCAL_MODULE:= libft2_mrom_static
151 | include $(BUILD_STATIC_LIBRARY)
152 |
--------------------------------------------------------------------------------
/lib/animation.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef ANIMATION_H
19 | #define ANIMATION_H
20 |
21 | enum
22 | {
23 | ANIM_TYPE_ITEM,
24 | ANIM_TYPE_CALLBACK,
25 | };
26 |
27 | enum
28 | {
29 | INTERPOLATOR_LINEAR,
30 | INTERPOLATOR_DECELERATE,
31 | INTERPOLATOR_ACCELERATE,
32 | INTERPOLATOR_OVERSHOOT,
33 | INTERPOLATOR_ACCEL_DECEL,
34 | };
35 |
36 | typedef void (*animation_callback)(void*); // data
37 | typedef void (*animation_callback_step)(void*, float); // data, interpolated
38 | typedef int (*animation_cancel_check)(void*, void*); // data, item
39 |
40 | #define ANIM_INVALID_ID UINT32_MAX
41 |
42 | #define ANIM_HEADER \
43 | uint32_t id; \
44 | uint32_t start_offset; \
45 | uint32_t duration; \
46 | uint32_t elapsed; \
47 | int interpolator; \
48 | void *on_finished_data; \
49 | animation_callback on_finished_call; \
50 | void *on_step_data; \
51 | animation_callback_step on_step_call; \
52 | void *cancel_check_data; \
53 | animation_cancel_check cancel_check;
54 |
55 | typedef struct
56 | {
57 | ANIM_HEADER
58 | } anim_header;
59 |
60 | typedef struct
61 | {
62 | ANIM_HEADER
63 | void *item;
64 |
65 | int destroy_item_when_finished;
66 |
67 | int start[4];
68 | int last[4];
69 |
70 | int targetX, targetY;
71 | int targetW, targetH;
72 | } item_anim;
73 |
74 | typedef void (*call_anim_callback)(void*, float); // data, interpolated
75 | typedef struct
76 | {
77 | ANIM_HEADER
78 |
79 | call_anim_callback callback;
80 | void *data;
81 | } call_anim;
82 |
83 | void anim_init(float duration_coef);
84 | void anim_stop(int wait_for_finished);
85 | void anim_cancel(uint32_t id, int only_not_started);
86 | void anim_cancel_for(void *fb_item, int only_not_started);
87 | void anim_push_context(void);
88 | void anim_pop_context(void);
89 | int anim_item_cancel_check(void *item_my, void *item_destroyed);
90 |
91 | item_anim *item_anim_create(void *fb_item, int duration, int interpolator);
92 | void item_anim_add(item_anim *anim);
93 | void item_anim_add_after(item_anim *anim);
94 |
95 | call_anim *call_anim_create(void *data, call_anim_callback callback, int duration, int interpolator);
96 | void call_anim_add(call_anim *anim);
97 |
98 |
99 | #endif
100 |
--------------------------------------------------------------------------------
/lib/atomics.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef ATOMICS_H
19 | #define ATOMICS_H
20 |
21 | #if (PLATFORM_SDK_VERSION >= 21)
22 | #include
23 | #else
24 | #include
25 | typedef struct { volatile int __val; } atomic_int;
26 | #define ATOMIC_VAR_INIT(value) { .__val = value }
27 | #define atomic_compare_exchange_strong(valptr, oldval, newval) (!__atomic_cmpxchg((oldval)->__val, newval, &((valptr)->__val)))
28 | #endif
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/lib/button.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 |
20 | #include "button.h"
21 | #include "input.h"
22 | #include "util.h"
23 | #include "colors.h"
24 | #include "log.h"
25 | #include "containers.h"
26 |
27 | void button_init_ui(button *b, const char *text, int size)
28 | {
29 | b->touch_id = -1;
30 |
31 | if(text != NULL)
32 | {
33 | b->c[CLR_NORMAL][0] = C_HIGHLIGHT_BG;
34 | b->c[CLR_NORMAL][1] = C_HIGHLIGHT_TEXT;
35 | b->c[CLR_HOVER][0] = C_HIGHLIGHT_HOVER;
36 | b->c[CLR_HOVER][1] = C_HIGHLIGHT_TEXT;
37 | b->c[CLR_DIS][0] = GRAY;
38 | b->c[CLR_DIS][1] = WHITE;
39 | b->c[CLR_CHECK][0] = C_HIGHLIGHT_BG;
40 | b->c[CLR_CHECK][1] = C_HIGHLIGHT_TEXT;
41 |
42 | b->rect = fb_add_rect_lvl(b->level_off + LEVEL_RECT, b->x, b->y, b->w, b->h, b->c[CLR_NORMAL][0]);
43 |
44 | fb_text_proto *p = fb_text_create(0, 0, b->c[CLR_NORMAL][1], size, text);
45 | p->level = b->level_off + LEVEL_TEXT;
46 | p->style = STYLE_MEDIUM;
47 | b->text = fb_text_finalize(p);
48 | center_text(b->text, b->x, b->y, b->w, b->h);
49 | }
50 | else
51 | {
52 | b->text = NULL;
53 | b->rect = NULL;
54 | }
55 |
56 | add_touch_handler(&button_touch_handler, b);
57 | }
58 |
59 | void button_destroy(button *b)
60 | {
61 | rm_touch_handler(&button_touch_handler, b);
62 | keyaction_remove(&button_keyaction_call, b);
63 |
64 | if(b->text)
65 | {
66 | fb_rm_rect(b->rect);
67 | fb_rm_text(b->text);
68 | }
69 |
70 | free(b);
71 | }
72 |
73 | void button_move(button *b, int x, int y)
74 | {
75 | b->x = x;
76 | b->y = y;
77 |
78 | if(b->text)
79 | {
80 | b->rect->x = x;
81 | b->rect->y = y;
82 |
83 | center_text(b->text, b->x, b->y, b->w, b->h);
84 | }
85 | }
86 |
87 | void button_set_hover(button *b, int hover)
88 | {
89 | if((hover == 1) == ((b->flags & BTN_HOVER) != 0))
90 | return;
91 |
92 | if(hover)
93 | b->flags |= BTN_HOVER;
94 | else
95 | b->flags &= ~(BTN_HOVER);
96 |
97 | if(b->text)
98 | {
99 | button_update_colors(b);
100 | fb_request_draw();
101 | }
102 | }
103 |
104 | void button_enable(button *b, int enable)
105 | {
106 | if(enable)
107 | b->flags &= ~(BTN_DISABLED);
108 | else
109 | {
110 | b->flags |= BTN_DISABLED;
111 | b->flags &= ~(BTN_HOVER);
112 | }
113 |
114 | if(b->text)
115 | {
116 | button_update_colors(b);
117 | fb_request_draw();
118 | }
119 | }
120 |
121 | int button_touch_handler(touch_event *ev, void *data)
122 | {
123 | button *b = (button*)data;
124 |
125 | if(b->flags & BTN_DISABLED)
126 | return -1;
127 |
128 | if(b->touch_id == -1 && (ev->changed & TCHNG_ADDED) && !ev->consumed)
129 | {
130 | if(!in_rect(ev->x, ev->y, b->x, b->y, b->w, b->h))
131 | return -1;
132 |
133 | b->touch_id = ev->id;
134 | }
135 |
136 | if(b->touch_id != ev->id)
137 | return -1;
138 |
139 | if(ev->changed & TCHNG_POS)
140 | button_set_hover(b, in_rect(ev->x, ev->y, b->x, b->y, b->w, b->h));
141 |
142 | if(ev->changed & TCHNG_REMOVED)
143 | {
144 | if((b->flags & BTN_HOVER) && b->clicked)
145 | (*b->clicked)(b->clicked_data);
146 | button_set_hover(b, 0);
147 | b->touch_id = -1;
148 | }
149 |
150 | return 0;
151 | }
152 |
153 | void button_set_color(button *b, int idx, int text, uint32_t color)
154 | {
155 | b->c[idx][text] = color;
156 | button_update_colors(b);
157 | }
158 |
159 | void button_update_colors(button *b)
160 | {
161 | int state = CLR_NORMAL;
162 | if(b->flags & BTN_DISABLED)
163 | state = CLR_DIS;
164 | else if(b->flags & BTN_HOVER)
165 | state = CLR_HOVER;
166 | else if(b->flags & BTN_CHECKED)
167 | state = CLR_CHECK;
168 |
169 | if(b->text)
170 | {
171 | b->rect->color = b->c[state][0];
172 | fb_text_set_color(b->text, b->c[state][1]);
173 | }
174 | }
175 |
176 | void button_set_checked(button *b, int checked)
177 | {
178 | if((checked == 1) == ((b->flags & BTN_CHECKED) != 0))
179 | return;
180 |
181 | if(checked)
182 | b->flags |= BTN_CHECKED;
183 | else
184 | b->flags &= ~(BTN_CHECKED);
185 |
186 | button_update_colors(b);
187 | fb_request_draw();
188 | }
189 |
190 | int button_keyaction_call(void *data, int act)
191 | {
192 | button *b = data;
193 | switch(act)
194 | {
195 | case KEYACT_UP:
196 | case KEYACT_DOWN:
197 | case KEYACT_CLEAR:
198 | {
199 | if(act != KEYACT_CLEAR && b->keyact_frame == NULL)
200 | {
201 | fb_add_rect_notfilled(b->level_off + LEVEL_RECT, b->x, b->y, b->w, b->h, C_KEYACT_FRAME, KEYACT_FRAME_W, &b->keyact_frame);
202 | fb_request_draw();
203 | return 0;
204 | }
205 | else
206 | {
207 | list_clear(&b->keyact_frame, &fb_remove_item);
208 | fb_request_draw();
209 | return (act == KEYACT_CLEAR) ? 0 : 1;
210 | }
211 | }
212 | case KEYACT_CONFIRM:
213 | {
214 | if(b->clicked && !(b->flags & BTN_DISABLED))
215 | (*b->clicked)(b->clicked_data);
216 | return 0;
217 | }
218 | default:
219 | return 0;
220 | }
221 | }
222 |
--------------------------------------------------------------------------------
/lib/button.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef BUTTON_H
19 | #define BUTTON_H
20 |
21 | #include "framebuffer.h"
22 | #include "input.h"
23 |
24 | enum
25 | {
26 | BTN_HOVER = 0x01,
27 | BTN_DISABLED = 0x02,
28 | BTN_CHECKED = 0x04,
29 | };
30 |
31 | enum
32 | {
33 | CLR_NORMAL = 0,
34 | CLR_HOVER,
35 | CLR_DIS,
36 | CLR_CHECK,
37 |
38 | CLR_MAX
39 | };
40 |
41 | typedef struct
42 | {
43 | FB_ITEM_HEAD
44 |
45 | fb_img *text;
46 | fb_rect *rect;
47 | fb_rect **keyact_frame;
48 | int level_off;
49 |
50 | uint32_t c[CLR_MAX][2];
51 |
52 | int flags;
53 | int touch_id;
54 |
55 | void *clicked_data;
56 | void (*clicked)(void*); // clicked_data
57 | } button;
58 |
59 | void button_init_ui(button *b, const char *text, int size);
60 | void button_destroy(button *b);
61 | void button_move(button *b, int x, int y);
62 | void button_set_hover(button *b, int hover);
63 | void button_enable(button *b, int enable);
64 | void button_set_checked(button *b, int checked);
65 | void button_set_color(button *b, int idx, int text, uint32_t color);
66 | void button_update_colors(button *b);
67 | int button_touch_handler(touch_event *ev, void *data);
68 | int button_keyaction_call(void *data, int act);
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/lib/colors.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include "colors.h"
19 | #include "util.h"
20 |
21 | static const struct mrom_color_theme color_themes[] = {
22 | // 0 - red/white, default
23 | {
24 | .background = 0xFFDCDCDC,
25 | .highlight_bg = 0xFFF72F2F,
26 | .highlight_hover = 0xFFF85555,
27 | .highlight_text = 0xFFFFFFFF,
28 | .text = 0xFF000000,
29 | .text_secondary = 0xFF4D4D4D,
30 | .ncard_bg = 0xFF37474F,
31 | .ncard_text = 0xFFFFFFFF,
32 | .ncard_text_secondary = 0xFFE6E6E6,
33 | .ncard_shadow = 0x54000000,
34 | .rom_highlight = 0xFFFFFFFF,
35 | .rom_highlight_shadow = 0x54000000,
36 | .keyaction_frame = 0xFF0000FF,
37 | .btn_fake_shadow = 0xFFA1A1A1,
38 | },
39 | // 1 - orange/white
40 | {
41 | .background = 0xFFDCDCDC,
42 | .highlight_bg = 0xFFFF5722,
43 | .highlight_hover = 0xFFFF8A65,
44 | .highlight_text = 0xFFFFFFFF,
45 | .text = 0xFF000000,
46 | .text_secondary = 0xFF4D4D4D,
47 | .ncard_bg = 0xFF37474F,
48 | .ncard_text = 0xFFFFFFFF,
49 | .ncard_text_secondary = 0xFFE6E6E6,
50 | .ncard_shadow = 0x54000000,
51 | .rom_highlight = 0xFFFFFFFF,
52 | .rom_highlight_shadow = 0x54000000,
53 | .keyaction_frame = 0xFFFF0000,
54 | .btn_fake_shadow = 0xFFA1A1A1,
55 | },
56 | // 2 - blue/white
57 | {
58 | .background = 0xFFDCDCDC,
59 | .highlight_bg = 0xFF5677FC,
60 | .highlight_hover = 0xFF91A7FF,
61 | .highlight_text = 0xFFFFFFFF,
62 | .text = 0xFF000000,
63 | .text_secondary = 0xFF4D4D4D,
64 | .ncard_bg = 0xFF37474F,
65 | .ncard_text = 0xFFFFFFFF,
66 | .ncard_text_secondary = 0xFFE6E6E6,
67 | .ncard_shadow = 0x54000000,
68 | .rom_highlight = 0xFFFFFFFF,
69 | .rom_highlight_shadow = 0x54000000,
70 | .keyaction_frame = 0xFFFF0000,
71 | .btn_fake_shadow = 0xFFA1A1A1,
72 | },
73 | // 3 - purple/white
74 | {
75 | .background = 0xFFDCDCDC,
76 | .highlight_bg = 0xFF673AB7,
77 | .highlight_hover = 0xFF9575CD,
78 | .highlight_text = 0xFFFFFFFF,
79 | .text = 0xFF000000,
80 | .text_secondary = 0xFF4D4D4D,
81 | .ncard_bg = 0xFF37474F,
82 | .ncard_text = 0xFFFFFFFF,
83 | .ncard_text_secondary = 0xFFE6E6E6,
84 | .ncard_shadow = 0x54000000,
85 | .rom_highlight = 0xFFFFFFFF,
86 | .rom_highlight_shadow = 0x54000000,
87 | .keyaction_frame = 0xFFFF0000,
88 | .btn_fake_shadow = 0xFFA1A1A1,
89 | },
90 | // 4 - green/white
91 | {
92 | .background = 0xFFDCDCDC,
93 | .highlight_bg = 0xFF259B24,
94 | .highlight_hover = 0xFF72D572,
95 | .highlight_text = 0xFFFFFFFF,
96 | .text = 0xFF000000,
97 | .text_secondary = 0xFF4D4D4D,
98 | .ncard_bg = 0xFF37474F,
99 | .ncard_text = 0xFFFFFFFF,
100 | .ncard_text_secondary = 0xFFE6E6E6,
101 | .ncard_shadow = 0x54000000,
102 | .rom_highlight = 0xFFFFFFFF,
103 | .rom_highlight_shadow = 0x54000000,
104 | .keyaction_frame = 0xFFFF0000,
105 | .btn_fake_shadow = 0xFFA1A1A1,
106 | },
107 | // 5 - dark blue
108 | {
109 | .background = 0xFF263238,
110 | .highlight_bg = 0xFF607D8B,
111 | .highlight_hover = 0xFF90A4AE,
112 | .highlight_text = 0xFFFFFFFF,
113 | .text = 0xFFFFFFFF,
114 | .text_secondary = 0xFFE6E6E6,
115 | .ncard_bg = 0xFF37474F,
116 | .ncard_text = 0xFFFFFFFF,
117 | .ncard_text_secondary = 0xFFE6E6E6,
118 | .ncard_shadow = 0x54000000,
119 | .rom_highlight = 0xFF607D8B,
120 | .rom_highlight_shadow = 0x54000000,
121 | .keyaction_frame = 0xFFFF0000,
122 | .btn_fake_shadow = 0xFF1C2529,
123 | },
124 | // 6 - dark blue/black
125 | {
126 | .background = 0xFF000000,
127 | .highlight_bg = 0xFF263238,
128 | .highlight_hover = 0xFF607D8B,
129 | .highlight_text = 0xFFFFFFFF,
130 | .text = 0xFFFFFFFF,
131 | .text_secondary = 0xFFE6E6E6,
132 | .ncard_bg = 0xFF37474F,
133 | .ncard_text = 0xFFFFFFFF,
134 | .ncard_text_secondary = 0xFFE6E6E6,
135 | .ncard_shadow = 0x54424242,
136 | .rom_highlight = 0xFF263238,
137 | .rom_highlight_shadow = 0x54424242,
138 | .keyaction_frame = 0xFFFF0000,
139 | .btn_fake_shadow = 0x00000000,
140 | },
141 | };
142 |
143 | const struct mrom_color_theme *color_theme = &color_themes[0];
144 |
145 | void colors_select(size_t color_theme_idx)
146 | {
147 | if(color_theme_idx >= ARRAY_SIZE(color_themes))
148 | return;
149 | color_theme = &color_themes[color_theme_idx];
150 | }
151 |
152 | const struct mrom_color_theme *colors_get(size_t color_theme_idx)
153 | {
154 | if(color_theme_idx >= ARRAY_SIZE(color_themes))
155 | return NULL;
156 | return &color_themes[color_theme_idx];
157 | }
158 |
159 | int colors_count(void)
160 | {
161 | return ARRAY_SIZE(color_themes);
162 | }
163 |
--------------------------------------------------------------------------------
/lib/colors.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef MROM_COLORS_H
19 | #define MROM_COLORS_H
20 |
21 | #include
22 |
23 | struct mrom_color_theme
24 | {
25 | uint32_t background;
26 | uint32_t highlight_bg;
27 | uint32_t highlight_hover;
28 | uint32_t highlight_text;
29 | uint32_t text;
30 | uint32_t text_secondary;
31 | uint32_t ncard_bg;
32 | uint32_t ncard_text;
33 | uint32_t ncard_text_secondary;
34 | uint32_t ncard_shadow;
35 | uint32_t rom_highlight;
36 | uint32_t rom_highlight_shadow;
37 | uint32_t keyaction_frame;
38 | uint32_t btn_fake_shadow;
39 | };
40 |
41 | extern const struct mrom_color_theme *color_theme;
42 | #define C_BACKGROUND (color_theme->background)
43 | #define C_HIGHLIGHT_BG (color_theme->highlight_bg)
44 | #define C_HIGHLIGHT_HOVER (color_theme->highlight_hover)
45 | #define C_HIGHLIGHT_TEXT (color_theme->highlight_text)
46 | #define C_TEXT (color_theme->text)
47 | #define C_TEXT_SECONDARY (color_theme->text_secondary)
48 | #define C_NCARD_BG (color_theme->ncard_bg)
49 | #define C_NCARD_TEXT (color_theme->ncard_text)
50 | #define C_NCARD_TEXT_SECONDARY (color_theme->ncard_text_secondary)
51 | #define C_NCARD_SHADOW (color_theme->ncard_shadow)
52 | #define C_ROM_HIGHLIGHT (color_theme->rom_highlight)
53 | #define C_ROM_HIGHLIGHT_SHADOW (color_theme->rom_highlight_shadow)
54 | #define C_KEYACT_FRAME (color_theme->keyaction_frame)
55 | #define C_BTN_FAKE_SHADOW (color_theme->btn_fake_shadow)
56 |
57 | void colors_select(size_t color_theme_idx);
58 | const struct mrom_color_theme *colors_get(size_t color_theme_idx);
59 | int colors_count(void);
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/lib/containers.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 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 | #ifndef CONTAINERS_H
18 | #define CONTAINERS_H
19 |
20 | // auto-conversion of pointer type occurs only for
21 | // void*, not for void** nor void***
22 | typedef void* ptrToList; // void ***
23 | typedef void* listItself; // void **
24 | typedef void* callback;
25 | typedef void(*callbackPtr)(void*);
26 |
27 | void list_add(ptrToList list_p, void *item);
28 | void list_add_at(ptrToList list_p, int idx, void *item);
29 | int list_add_from_list(ptrToList list_p, listItself src_p);
30 | int list_rm(ptrToList list_p, void *item, callback destroy_callback_p);
31 | int list_rm_noreorder(ptrToList list_p, void *item, callback destroy_callback_p);
32 | int list_rm_opt(ptrToList list_p, void *item, callback destroy_callback_p, int reorder);
33 | listItself list_rm_at(ptrToList list_p, int idx, callback destroy_callback_p); // returns pointer to the next item in list or NULL
34 | int list_size(listItself list);
35 | int list_item_count(listItself list);
36 | int list_copy(ptrToList dest_p, listItself src);
37 | int list_move(ptrToList dest_p, ptrToList source_p);
38 | void list_clear(ptrToList list_p, callback destroy_callback_p);
39 | void list_swap(ptrToList a_p, ptrToList b_p);
40 |
41 | typedef struct
42 | {
43 | char **keys;
44 | void **values;
45 | size_t size;
46 | } map;
47 |
48 | map *map_create(void);
49 | void map_destroy(map *m, void (*destroy_callback)(void*));
50 | void map_add(map *m, const char *key, void *val, void (*destroy_callback)(void*));
51 | void map_add_not_exist(map *m, const char *key, void *val);
52 | void map_rm(map *m, const char *key, void (*destroy_callback)(void*));
53 | int map_find(map *m, const char *key);
54 | void *map_get_val(map *m, const char *key);
55 | void *map_get_ref(map *m, const char *key);
56 |
57 | typedef struct
58 | {
59 | int *keys;
60 | void **values;
61 | size_t size;
62 | } imap;
63 |
64 | imap *imap_create(void);
65 | void imap_destroy(imap *m, void (*destroy_callback)(void*));
66 | void imap_add(imap *m, int key, void *val, void (*destroy_callback)(void*));
67 | void imap_add_not_exist(imap *m, int key, void *val);
68 | void imap_rm(imap *m, int key, void (*destroy_callback)(void*));
69 | int imap_find(imap *m, int key);
70 | void *imap_get_val(imap *m, int key);
71 | void *imap_get_ref(imap *m, int key);
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/lib/framebuffer_generic.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | #include "framebuffer.h"
30 | #include "log.h"
31 | #include "util.h"
32 |
33 | // only double-buffering is implemented, this define is just
34 | // for the code to know how many buffers we use
35 | #define NUM_BUFFERS 2
36 |
37 | struct fb_generic_data {
38 | px_type *mapped[NUM_BUFFERS];
39 | int active_buff;
40 | };
41 |
42 | static int impl_open(struct framebuffer *fb)
43 | {
44 | fb->vi.bits_per_pixel = PIXEL_SIZE * 8;
45 | INFO("Pixel format: %dx%d @ %dbpp\n", fb->vi.xres, fb->vi.yres, fb->vi.bits_per_pixel);
46 |
47 | #ifdef RECOVERY_BGRA
48 | INFO("Pixel format: BGRA_8888\n");
49 | fb->vi.red.offset = 8;
50 | fb->vi.red.length = 8;
51 | fb->vi.green.offset = 16;
52 | fb->vi.green.length = 8;
53 | fb->vi.blue.offset = 24;
54 | fb->vi.blue.length = 8;
55 | fb->vi.transp.offset = 0;
56 | fb->vi.transp.length = 8;
57 | #elif defined(RECOVERY_RGBX)
58 | INFO("Pixel format: RGBX_8888\n");
59 | fb->vi.red.offset = 24;
60 | fb->vi.red.length = 8;
61 | fb->vi.green.offset = 16;
62 | fb->vi.green.length = 8;
63 | fb->vi.blue.offset = 8;
64 | fb->vi.blue.length = 8;
65 | fb->vi.transp.offset = 0;
66 | fb->vi.transp.length = 8;
67 | #elif defined(RECOVERY_RGB_565)
68 | INFO("Pixel format: RGB_565\n");
69 | fb->vi.blue.offset = 0;
70 | fb->vi.green.offset = 5;
71 | fb->vi.red.offset = 11;
72 | fb->vi.blue.length = 5;
73 | fb->vi.green.length = 6;
74 | fb->vi.red.length = 5;
75 | fb->vi.blue.msb_right = 0;
76 | fb->vi.green.msb_right = 0;
77 | fb->vi.red.msb_right = 0;
78 | fb->vi.transp.offset = 0;
79 | fb->vi.transp.length = 0;
80 | #elif defined(RECOVERY_ABGR)
81 | INFO("Pixel format: ABGR_8888\n");
82 | fb->vi.red.offset = 0;
83 | fb->vi.red.length = 8;
84 | fb->vi.green.offset = 8;
85 | fb->vi.green.length = 8;
86 | fb->vi.blue.offset = 16;
87 | fb->vi.blue.length = 8;
88 | fb->vi.transp.offset = 24;
89 | fb->vi.transp.length = 8;
90 | #else
91 | #error "Unknown pixel format"
92 | #endif
93 |
94 | fb->vi.vmode = FB_VMODE_NONINTERLACED;
95 | fb->vi.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
96 |
97 | // mmap and memset to 0 before setting the vi to prevent screen flickering during init
98 | px_type *mapped = mmap(0, fb->fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb->fd, 0);
99 |
100 | if (mapped == MAP_FAILED)
101 | return -1;
102 |
103 | memset(mapped, 0, fb->fi.smem_len);
104 | munmap(mapped, fb->fi.smem_len);
105 |
106 | if (ioctl(fb->fd, FBIOPUT_VSCREENINFO, &fb->vi) < 0)
107 | {
108 | ERROR("failed to set fb0 vi info");
109 | return -1;
110 | }
111 |
112 | if (ioctl(fb->fd, FBIOGET_FSCREENINFO, &fb->fi) < 0)
113 | return -1;
114 |
115 | mapped = mmap(0, fb->fi.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb->fd, 0);
116 |
117 | if (mapped == MAP_FAILED)
118 | return -1;
119 |
120 | struct fb_generic_data *data = mzalloc(sizeof(struct fb_generic_data));
121 | data->mapped[0] = mapped;
122 | data->mapped[1] = (px_type*) (((uint8_t*)mapped) + (fb->vi.yres * fb->fi.line_length));
123 |
124 | fb->impl_data = data;
125 |
126 | #ifdef TW_SCREEN_BLANK_ON_BOOT
127 | ioctl(fb->fd, FBIOBLANK, FB_BLANK_POWERDOWN);
128 | ioctl(fb->fd, FBIOBLANK, FB_BLANK_UNBLANK);
129 | #endif
130 |
131 | return 0;
132 | }
133 |
134 | static void impl_close(struct framebuffer *fb)
135 | {
136 | struct fb_generic_data *data = fb->impl_data;
137 | if(data)
138 | {
139 | munmap(data->mapped[0], fb->fi.smem_len);
140 | free(data);
141 | fb->impl_data = NULL;
142 | }
143 | }
144 |
145 | static int impl_update(struct framebuffer *fb)
146 | {
147 | struct fb_generic_data *data = fb->impl_data;
148 |
149 | fb->vi.yres_virtual = fb->vi.yres * NUM_BUFFERS;
150 | fb->vi.yoffset = data->active_buff * fb->vi.yres;
151 |
152 | if (ioctl(fb->fd, FBIOPUT_VSCREENINFO, &fb->vi) < 0)
153 | {
154 | ERROR("active fb swap failed");
155 | return -1;
156 | }
157 |
158 | return 0;
159 | }
160 |
161 | static void *impl_get_frame_dest(struct framebuffer *fb)
162 | {
163 | struct fb_generic_data *data = fb->impl_data;
164 | data->active_buff = !data->active_buff;
165 | return data->mapped[data->active_buff];
166 | }
167 |
168 | const struct fb_impl fb_impl_generic = {
169 | .name = "Generic",
170 | .impl_id = FB_IMPL_GENERIC,
171 |
172 | .open = impl_open,
173 | .close = impl_close,
174 | .update = impl_update,
175 | .get_frame_dest = impl_get_frame_dest,
176 | };
177 |
--------------------------------------------------------------------------------
/lib/fstab.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef FSTAB_H
19 | #define FSTAB_H
20 |
21 | struct fstab_part
22 | {
23 | char *path;
24 | char *device;
25 | char *type;
26 | char *options_raw;
27 | unsigned long mountflags;
28 | char *options;
29 | char *options2;
30 | int disabled;
31 | };
32 |
33 | struct fstab
34 | {
35 | int version;
36 | int count;
37 | char *path;
38 | struct fstab_part **parts;
39 | };
40 |
41 | struct fstab *fstab_create_empty(int version);
42 | struct fstab *fstab_load(const char *path, int resolve_symlinks);
43 | struct fstab *fstab_auto_load(void);
44 | void fstab_destroy(struct fstab *f);
45 | void fstab_destroy_part(struct fstab_part *p);
46 | void fstab_dump(struct fstab *f);
47 | struct fstab_part *fstab_find_first_by_path(struct fstab *f, const char *path);
48 | struct fstab_part *fstab_find_next_by_path(struct fstab *f, const char *path, struct fstab_part *prev);
49 | void fstab_parse_options(char *opt, struct fstab_part *p);
50 | int fstab_save(struct fstab *f, const char *path);
51 | int fstab_disable_parts(struct fstab *f, const char *path);
52 | void fstab_add_part(struct fstab *f, const char *dev, const char *path, const char *type, const char *options, const char *options2);
53 | void fstab_add_part_struct(struct fstab *f, struct fstab_part *p);
54 | struct fstab_part *fstab_clone_part(struct fstab_part *p);
55 | void fstab_update_device(struct fstab *f, const char *oldDev, const char *newDev);
56 |
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/lib/inject.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | #include "inject.h"
25 | #include "mrom_data.h"
26 | #include "log.h"
27 | #include "util.h"
28 | #include "../version.h"
29 |
30 | // clone libbootimg to /system/extras/ from
31 | // https://github.com/Tasssadar/libbootimg.git
32 | #include
33 |
34 | #if LIBBOOTIMG_VERSION < 0x000200
35 | #error "libbootimg version 0.2.0 or higher is required. Please update libbootimg."
36 | #endif
37 |
38 | #define TMP_RD_UNPACKED_DIR "/mrom_rd"
39 |
40 | static int get_img_trampoline_ver(struct bootimg *img)
41 | {
42 | int ver = 0;
43 | if(strncmp((char*)img->hdr.name, "tr_ver", 6) == 0)
44 | ver = atoi((char*)img->hdr.name + 6);
45 | return ver;
46 | }
47 |
48 | static int copy_rd_files(UNUSED const char *path, UNUSED const char *busybox_path)
49 | {
50 | char buf[256];
51 |
52 | if (access(TMP_RD_UNPACKED_DIR"/main_init", F_OK) < 0 &&
53 | rename(TMP_RD_UNPACKED_DIR"/init", TMP_RD_UNPACKED_DIR"/main_init") < 0)
54 | {
55 | ERROR("Failed to move /init to /main_init!\n");
56 | return -1;
57 | }
58 |
59 | snprintf(buf, sizeof(buf), "%s/trampoline", mrom_dir());
60 | if(copy_file(buf, TMP_RD_UNPACKED_DIR"/init") < 0)
61 | {
62 | ERROR("Failed to copy trampoline to /init!\n");
63 | return -1;
64 | }
65 | chmod(TMP_RD_UNPACKED_DIR"/init", 0750);
66 |
67 | remove(TMP_RD_UNPACKED_DIR"/sbin/ueventd");
68 | remove(TMP_RD_UNPACKED_DIR"/sbin/watchdogd");
69 | symlink("../main_init", TMP_RD_UNPACKED_DIR"/sbin/ueventd");
70 | symlink("../main_init", TMP_RD_UNPACKED_DIR"/sbin/watchdogd");
71 |
72 | #ifdef MR_USE_MROM_FSTAB
73 | snprintf(buf, sizeof(buf), "%s/mrom.fstab", mrom_dir());
74 | copy_file(buf, TMP_RD_UNPACKED_DIR"/mrom.fstab");
75 | #else
76 | remove(TMP_RD_UNPACKED_DIR"/mrom.fstab");
77 | #endif
78 |
79 | #ifdef MR_ENCRYPTION
80 | remove_dir(TMP_RD_UNPACKED_DIR"/mrom_enc");
81 |
82 | if(mr_system("busybox cp -a \"%s/enc\" \"%s/mrom_enc\"", mrom_dir(), TMP_RD_UNPACKED_DIR) != 0)
83 | {
84 | ERROR("Failed to copy encryption files!\n");
85 | return -1;
86 | }
87 | #endif
88 | return 0;
89 | }
90 |
91 | #define RD_GZIP 1
92 | #define RD_LZ4 2
93 | static int inject_rd(const char *path)
94 | {
95 | int result = -1;
96 | uint32_t magic = 0;
97 |
98 | FILE *f = fopen(path, "re");
99 | if(!f)
100 | {
101 | ERROR("Couldn't open %s!\n", path);
102 | return -1;
103 | }
104 | fread(&magic, sizeof(magic), 1, f);
105 | fclose(f);
106 |
107 | remove_dir(TMP_RD_UNPACKED_DIR);
108 | mkdir(TMP_RD_UNPACKED_DIR, 0755);
109 |
110 | // Decompress initrd
111 | int type;
112 | char buff[256];
113 | char busybox_path[256];
114 | snprintf(busybox_path, sizeof(busybox_path), "%s/busybox", mrom_dir());
115 |
116 | char *cmd[] = { busybox_path, "sh", "-c", buff, NULL };
117 |
118 | if((magic & 0xFFFF) == 0x8B1F)
119 | {
120 | type = RD_GZIP;
121 | snprintf(buff, sizeof(buff), "B=\"%s\"; cd \"%s\"; \"$B\" gzip -d -c \"%s\" | \"$B\" cpio -i", busybox_path, TMP_RD_UNPACKED_DIR, path);
122 | }
123 | else if(magic == 0x184C2102)
124 | {
125 | type = RD_LZ4;
126 | snprintf(buff, sizeof(buff), "cd \"%s\"; \"%s/lz4\" -d \"%s\" stdout | \"%s\" cpio -i", TMP_RD_UNPACKED_DIR, mrom_dir(), path, busybox_path);
127 | }
128 | else
129 | {
130 | ERROR("Unknown ramdisk magic 0x%08X, can't update trampoline\n", magic);
131 | goto success;
132 | }
133 |
134 | int r = run_cmd(cmd);
135 | if(r != 0)
136 | {
137 | ERROR("Failed to unpack ramdisk! %s\n", buff);
138 | goto fail;
139 | }
140 |
141 | // Update files
142 | if(copy_rd_files(path, busybox_path) < 0)
143 | goto fail;
144 |
145 | // Pack initrd again
146 | switch(type)
147 | {
148 | case RD_GZIP:
149 | snprintf(buff, sizeof(buff), "B=\"%s\"; cd \"%s\"; \"$B\" find . | \"$B\" cpio -o -H newc | \"$B\" gzip > \"%s\"", busybox_path, TMP_RD_UNPACKED_DIR, path);
150 | break;
151 | case RD_LZ4:
152 | snprintf(buff, sizeof(buff), "B=\"%s\"; cd \"%s\"; \"$B\" find . | \"$B\" cpio -o -H newc | \"%s/lz4\" stdin \"%s\"", busybox_path, TMP_RD_UNPACKED_DIR, mrom_dir(), path);
153 | break;
154 | }
155 |
156 | r = run_cmd(cmd);
157 | if(r != 0)
158 | {
159 | ERROR("Failed to pack ramdisk!\n");
160 | goto fail;
161 | }
162 |
163 | success:
164 | result = 0;
165 | fail:
166 | remove_dir(TMP_RD_UNPACKED_DIR);
167 | return result;
168 | }
169 |
170 | int inject_bootimg(const char *img_path, int force)
171 | {
172 | int res = -1;
173 | struct bootimg img;
174 | int img_ver;
175 | char initrd_path[256];
176 | static const char *initrd_tmp_name = "/inject-initrd.img";
177 |
178 | if(libbootimg_init_load(&img, img_path, LIBBOOTIMG_LOAD_ALL) < 0)
179 | {
180 | ERROR("Could not open boot image (%s)!\n", img_path);
181 | return -1;
182 | }
183 |
184 | img_ver = get_img_trampoline_ver(&img);
185 | if(!force && img_ver == VERSION_TRAMPOLINE)
186 | {
187 | INFO("No need to update trampoline.\n");
188 | res = 0;
189 | goto exit;
190 | }
191 |
192 | INFO("Updating trampoline from ver %d to %d\n", img_ver, VERSION_TRAMPOLINE);
193 |
194 | if(libbootimg_dump_ramdisk(&img, initrd_tmp_name) < 0)
195 | {
196 | ERROR("Failed to dump ramdisk to %s!\n", initrd_path);
197 | goto exit;
198 | }
199 |
200 | if(inject_rd(initrd_tmp_name) >= 0)
201 | {
202 | // Update the boot.img
203 | snprintf((char*)img.hdr.name, BOOT_NAME_SIZE, "tr_ver%d", VERSION_TRAMPOLINE);
204 | #ifdef MR_RD_ADDR
205 | img.hdr.ramdisk_addr = MR_RD_ADDR;
206 | #endif
207 |
208 | if(libbootimg_load_ramdisk(&img, initrd_tmp_name) < 0)
209 | {
210 | ERROR("Failed to load ramdisk from %s!\n", initrd_tmp_name);
211 | goto exit;
212 | }
213 |
214 | char tmp[256];
215 | strcpy(tmp, img_path);
216 | strcat(tmp, ".new");
217 | if(libbootimg_write_img(&img, tmp) >= 0)
218 | {
219 | INFO("Writing boot.img updated with trampoline v%d\n", VERSION_TRAMPOLINE);
220 | if(copy_file(tmp, img_path) < 0)
221 | ERROR("Failed to copy %s to %s!\n", tmp, img_path);
222 | else
223 | res = 0;
224 | remove(tmp);
225 | }
226 | else
227 | ERROR("Failed to libbootimg_write_img!\n");
228 | }
229 |
230 | exit:
231 | libbootimg_destroy(&img);
232 | remove("/inject-initrd.img");
233 | return res;
234 | }
235 |
--------------------------------------------------------------------------------
/lib/inject.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef INJECT_H
19 | #define INJECT_H
20 |
21 | int inject_bootimg(const char *img_path, int force);
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/lib/input.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef INPUT_H
19 | #define INPUT_H
20 |
21 | #include
22 | #include "framebuffer.h"
23 |
24 | #define KEY_VOLUMEUP 115
25 | #define KEY_VOLUMEDOWN 114
26 | #define KEY_POWER 116
27 |
28 | enum
29 | {
30 | TCHNG_POS = 0x01,
31 | //TCHNG_PRESSURE = 0x02, // unused
32 | TCHNG_ADDED = 0x04,
33 | TCHNG_REMOVED = 0x08
34 | };
35 |
36 | typedef struct
37 | {
38 | int id;
39 | int x, orig_x;
40 | int y, orig_y;
41 | int changed;
42 | int consumed;
43 |
44 | struct timeval time;
45 | int64_t us_diff;
46 | } touch_event;
47 |
48 | typedef int (*touch_callback)(touch_event*, void*); // event, data
49 |
50 | void start_input_thread(void);
51 | void start_input_thread_wait(int wait_for_start);
52 | void stop_input_thread(void);
53 |
54 | int get_last_key(void);
55 | int wait_for_key(void);
56 | int is_any_key_pressed(void);
57 |
58 | void add_touch_handler(touch_callback callback, void *data);
59 | void rm_touch_handler(touch_callback callback, void *data);
60 | void add_touch_handler_async(touch_callback callback, void *data);
61 | void rm_touch_handler_async(touch_callback callback, void *data);
62 |
63 | void input_push_context(void);
64 | void input_pop_context(void);
65 |
66 |
67 | enum
68 | {
69 | KEYACT_NONE = 0,
70 | KEYACT_UP,
71 | KEYACT_DOWN,
72 | KEYACT_CONFIRM,
73 | KEYACT_CLEAR,
74 | };
75 |
76 | #define KEYACT_FRAME_W (8*DPI_MUL)
77 |
78 | typedef int (*keyaction_call)(void *, int); // data, action
79 | void keyaction_add(void *parent, keyaction_call call, void *data);
80 | void keyaction_remove(keyaction_call call, void *data);
81 | void keyaction_clear(void);
82 | void keyaction_clear_active(void);
83 | int keyaction_handle_keyevent(int key, int press);
84 | void keyaction_enable(int enable);
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/lib/input_priv.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef INPUT_PRIV_H
19 | #define INPUT_PRIV_H
20 |
21 | #include
22 | #include "input.h"
23 |
24 | #define MAX_DEVICES 16
25 | #define MAX_FINGERS 10
26 |
27 | // for touch calculation
28 | extern int mt_screen_res[2];
29 | extern touch_event mt_events[MAX_FINGERS];
30 | extern int mt_slot;
31 | extern int mt_switch_xy;
32 | extern int mt_range_x[2];
33 | extern int mt_range_y[2];
34 |
35 | typedef struct
36 | {
37 | void *data;
38 | touch_callback callback;
39 | } touch_handler;
40 |
41 | struct handler_list_it
42 | {
43 | touch_handler *handler;
44 |
45 | struct handler_list_it *prev;
46 | struct handler_list_it *next;
47 | };
48 |
49 | typedef struct handler_list_it handler_list_it;
50 |
51 | typedef struct
52 | {
53 | int handlers_mode;
54 | handler_list_it *handlers;
55 | } handlers_ctx;
56 |
57 | void touch_commit_events(struct timeval ev_time);
58 | inline int calc_mt_pos(int val, int *range, int d_max);
59 |
60 | // Implemented in input_touch*.c files
61 | void handle_abs_event(struct input_event *ev);
62 | void handle_syn_event(struct input_event *ev);
63 | void init_touch_specifics(void);
64 | void destroy_touch_specifics(void);
65 |
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/lib/input_type_a.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | // Implementation of "Protocol Example A" from kernel's
19 | // Documentation/input/multi-touch-protocol.txt
20 |
21 | // This protocol requires client to keep track of ids,
22 | // I don't really like this implementation, but I can't
23 | // come up with anything better :/
24 |
25 | #include
26 | #include
27 | #include
28 |
29 | #include "input.h"
30 | #include "input_priv.h"
31 | #include "util.h"
32 |
33 | static int *active_touches = NULL;
34 | static int *curr_touches = NULL;
35 |
36 | static void idlist_clear(int *list)
37 | {
38 | int i;
39 | for(i = 0; i < MAX_FINGERS && list[i] != -1; ++i)
40 | list[i] = -1;
41 | }
42 |
43 | static int *idlist_init(void)
44 | {
45 | int *res = malloc(MAX_FINGERS*sizeof(int));
46 |
47 | int i;
48 | for(i = 0; i < MAX_FINGERS; ++i)
49 | res[i] = -1;
50 |
51 | return res;
52 | }
53 |
54 | static void idlist_swap(int **list_a, int **list_b)
55 | {
56 | int *tmp = *list_a;
57 | *list_a = *list_b;
58 | *list_b = tmp;
59 | }
60 |
61 | static int idlist_add(int *list, int id)
62 | {
63 | int i;
64 | for(i = 0; i < MAX_FINGERS; ++i)
65 | {
66 | if(list[i] == id)
67 | return -1;
68 |
69 | if(list[i] == -1)
70 | {
71 | list[i] = id;
72 | return 0;
73 | }
74 | }
75 | assert(0);
76 | return -1;
77 | }
78 |
79 | static int idlist_rm(int *list, int id)
80 | {
81 | int i;
82 | for(i = 0; i < MAX_FINGERS; ++i)
83 | {
84 | if(list[i] == -1)
85 | return -1;
86 |
87 | if(list[i] == id)
88 | {
89 | for(++i; i < MAX_FINGERS && list[i] != -1; ++i)
90 | list[i-1] = list[i];
91 | list[i-1] = -1;
92 | return 0;
93 | }
94 | }
95 | return -1;
96 | }
97 |
98 | void init_touch_specifics(void)
99 | {
100 | active_touches = idlist_init();
101 | curr_touches = idlist_init();
102 | }
103 |
104 | void destroy_touch_specifics(void)
105 | {
106 | free(active_touches);
107 | free(curr_touches);
108 | active_touches = NULL;
109 | curr_touches = NULL;
110 | }
111 |
112 | void handle_abs_event(struct input_event *ev)
113 | {
114 | switch(ev->code)
115 | {
116 | case ABS_MT_TRACKING_ID:
117 | {
118 | mt_events[mt_slot++].id = ev->value;
119 | break;
120 | }
121 | case ABS_MT_POSITION_X:
122 | case ABS_MT_POSITION_Y:
123 | {
124 | if((ev->code == ABS_MT_POSITION_X) ^ (mt_switch_xy != 0))
125 | {
126 | mt_events[mt_slot].orig_x = calc_mt_pos(ev->value, mt_range_x, mt_screen_res[0]);
127 | if(mt_switch_xy)
128 | mt_events[mt_slot].orig_x = mt_screen_res[0] - mt_events[mt_slot].orig_x;
129 | }
130 | else
131 | mt_events[mt_slot].orig_y = calc_mt_pos(ev->value, mt_range_y, mt_screen_res[1]);
132 |
133 | mt_events[mt_slot].changed |= TCHNG_POS;
134 | break;
135 | }
136 | }
137 | }
138 |
139 | void handle_syn_event(struct input_event *ev)
140 | {
141 | if(ev->code != SYN_REPORT)
142 | return;
143 |
144 | idlist_swap(&curr_touches, &active_touches);
145 |
146 | int i;
147 | for(i = 0; i < mt_slot; ++i)
148 | {
149 | idlist_add(active_touches, mt_events[i].id);
150 | if(idlist_rm(curr_touches, mt_events[i].id) == -1)
151 | mt_events[i].changed |= TCHNG_ADDED;
152 | }
153 |
154 | for(i = 0; mt_slot < MAX_FINGERS && i < MAX_FINGERS && curr_touches[i] != -1; ++i)
155 | {
156 | mt_events[mt_slot].id = curr_touches[i];
157 | mt_events[mt_slot].changed = TCHNG_REMOVED;
158 | curr_touches[i] = -1;
159 | ++mt_slot;
160 | }
161 |
162 | mt_slot = 0;
163 | touch_commit_events(ev->time);
164 | }
165 |
--------------------------------------------------------------------------------
/lib/input_type_b.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | // Implementation of "Protocol Example B" from kernel's
19 | // Documentation/input/multi-touch-protocol.txt
20 |
21 | #include
22 | #include "input.h"
23 | #include "input_priv.h"
24 | #include "util.h"
25 |
26 | void init_touch_specifics(void)
27 | {
28 |
29 | }
30 |
31 | void destroy_touch_specifics(void)
32 | {
33 |
34 | }
35 |
36 | void handle_abs_event(struct input_event *ev)
37 | {
38 | switch(ev->code)
39 | {
40 | case ABS_MT_SLOT:
41 | if(ev->value < (int)ARRAY_SIZE(mt_events))
42 | mt_slot = ev->value;
43 | break;
44 | case ABS_MT_TRACKING_ID:
45 | {
46 | if(ev->value != -1)
47 | {
48 | mt_events[mt_slot].id = ev->value;
49 | mt_events[mt_slot].changed |= TCHNG_ADDED;
50 | }
51 | else
52 | mt_events[mt_slot].changed |= TCHNG_REMOVED;
53 | break;
54 | }
55 | case ABS_MT_POSITION_X:
56 | case ABS_MT_POSITION_Y:
57 | {
58 | if((ev->code == ABS_MT_POSITION_X) ^ (mt_switch_xy != 0))
59 | {
60 | mt_events[mt_slot].orig_x = calc_mt_pos(ev->value, mt_range_x, mt_screen_res[0]);
61 | if(mt_switch_xy)
62 | mt_events[mt_slot].orig_x = mt_screen_res[0] - mt_events[mt_slot].orig_x;
63 | }
64 | else
65 | mt_events[mt_slot].orig_y = calc_mt_pos(ev->value, mt_range_y, mt_screen_res[1]);
66 |
67 | mt_events[mt_slot].changed |= TCHNG_POS;
68 | break;
69 | }
70 | }
71 | }
72 |
73 | void handle_syn_event(struct input_event *ev)
74 | {
75 | if(ev->code == SYN_REPORT)
76 | touch_commit_events(ev->time);
77 | }
78 |
--------------------------------------------------------------------------------
/lib/keyboard.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 |
20 | #include "containers.h"
21 | #include "keyboard.h"
22 | #include "util.h"
23 | #include "log.h"
24 | #include "workers.h"
25 |
26 | #define KS(x) ((x-1) << 16)
27 | #define GET_KS(x) ((x & 0xFF0000)>> 16)
28 |
29 | #define KF(x) ((x) << 8)
30 | #define GET_KF(x) ((x & 0xFF00) >> 8)
31 | #define KFLAG_HALF KF(0x01)
32 | #define KFLAG_PLUS_HALF KF(0x02)
33 |
34 | static const char *specialKeys[] = {
35 | NULL, // OSK_EMPTY
36 | "OK", // OSK_ENTER
37 | "<", // OSK_BACKSPACE
38 | "X", // OSK_CLEAR
39 | "abc", // OSK_CHARSET1
40 | "ABC", // OSK_CHARSET2
41 | "?123",// OSK_CHARSET3
42 | "=\\<",// OSK_CHARSET4
43 | };
44 |
45 | // One keycode
46 | // bits | 0 | 8 | 16 |
47 | // data | character | flags | colspan |
48 | static const uint32_t pinKeycodeMap[] = {
49 | OSK_EMPTY | KFLAG_HALF, '1', '2', '3', OSK_EMPTY,
50 | OSK_EMPTY | KFLAG_HALF, '4', '5', '6', OSK_CLEAR,
51 | OSK_EMPTY | KFLAG_HALF, '7', '8', '9', OSK_BACKSPACE,
52 | OSK_EMPTY | KFLAG_HALF, '0' | KS(3), OSK_ENTER,
53 | 0
54 | };
55 |
56 | // rows, cols
57 | static const uint32_t pinKeycodeMapDimensions[] = { 4, 5 };
58 |
59 | static const uint32_t normalKeycodeMapCharset1[] = {
60 | 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
61 | OSK_EMPTY| KFLAG_HALF, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l',
62 | OSK_CHARSET2 | KFLAG_PLUS_HALF, 'z', 'x', 'c', 'v', 'b', 'n', 'm', OSK_BACKSPACE | KFLAG_PLUS_HALF, OSK_EMPTY,
63 | OSK_CHARSET3 | KS(2), ' ' | KS(5), '.', OSK_ENTER | KS(2),
64 | 0
65 | };
66 |
67 | static const uint32_t normalKeycodeMapCharset2[] = {
68 | 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P',
69 | OSK_EMPTY| KFLAG_HALF, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L',
70 | OSK_CHARSET1 | KFLAG_PLUS_HALF, 'Z', 'X', 'C', 'V', 'B', 'N', 'M', OSK_BACKSPACE | KFLAG_PLUS_HALF, OSK_EMPTY,
71 | OSK_CHARSET3 | KS(2), ' ' | KS(5), '.', OSK_ENTER | KS(2),
72 | 0
73 | };
74 |
75 | static const uint32_t normalKeycodeMapCharset3[] = {
76 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
77 | OSK_EMPTY | KFLAG_HALF, '@', '#', '$', '%', '&', '-', '+', '(', ')',
78 | OSK_CHARSET4 | KFLAG_PLUS_HALF, '*', '"', '\'', ':', ';', '!', '?', OSK_BACKSPACE | KFLAG_PLUS_HALF, OSK_EMPTY,
79 | OSK_CHARSET1 | KS(2), ',', '_', ' ' | KS(3), '/', OSK_ENTER | KS(2),
80 | 0
81 | };
82 |
83 | static const uint32_t normalKeycodeMapCharset4[] = {
84 | '~', '`', '|', '<', '>', '-', '+', '!', '?', ';',
85 | OSK_EMPTY | KFLAG_HALF, '^', '\\', '$', '%', '&', '-', '+', '{', '}',
86 | OSK_CHARSET3 | KFLAG_PLUS_HALF, '*', '"', '\'', ':', ';', '[', ']', OSK_BACKSPACE | KFLAG_PLUS_HALF, OSK_EMPTY,
87 | OSK_CHARSET1 | KS(2), ',', ' ' | KS(4), '/', OSK_ENTER | KS(2),
88 | 0
89 | };
90 |
91 | static const uint32_t *normalKeycodeMapCharsetMapping[] = {
92 | normalKeycodeMapCharset4, // OSK_CHARSET4
93 | normalKeycodeMapCharset3, // OSK_CHARSET3
94 | normalKeycodeMapCharset2, // OSK_CHARSET2
95 | normalKeycodeMapCharset1, // OSK_CHARSET1
96 | };
97 |
98 | // rows, cols
99 | static const uint32_t normalKeycodeMapDimensions[] = { 4, 10 };
100 |
101 | #define PADDING (8*DPI_MUL)
102 |
103 | struct keyboard_btn_data {
104 | struct keyboard *k;
105 | int btn_idx;
106 | };
107 |
108 | static int keyboard_init_map(struct keyboard *k, const uint32_t *map, const uint32_t *dimen);
109 |
110 |
111 | static int keyboard_charset_switch_worker(UNUSED uint32_t diff, void *data)
112 | {
113 | void **keyboard_bnt_data_old = NULL;
114 | struct keyboard_btn_data *d = data;
115 | uint8_t keycode = (d->k->keycode_map[d->btn_idx] & 0xFF);
116 |
117 | fb_batch_start();
118 | list_clear(&d->k->btns, &button_destroy);
119 | list_swap(&d->k->keyboard_bnt_data, &keyboard_bnt_data_old);
120 | keyboard_init_map(d->k, normalKeycodeMapCharsetMapping[keycode - OSK_CHARSET4], normalKeycodeMapDimensions);
121 | fb_batch_end();
122 | fb_request_draw();
123 |
124 | list_clear(&keyboard_bnt_data_old, free);
125 | return 1;
126 | }
127 |
128 | static void keyboard_btn_clicked(void *data)
129 | {
130 | struct keyboard_btn_data *d = data;
131 | uint8_t keycode = (d->k->keycode_map[d->btn_idx] & 0xFF);
132 |
133 | if(keycode >= OSK_CHARSET4 && keycode <= OSK_CHARSET1)
134 | workers_add(keyboard_charset_switch_worker, data);
135 | else if(d->k->key_pressed)
136 | d->k->key_pressed(d->k->key_pressed_data, keycode);
137 | }
138 |
139 | int keyboard_init_map(struct keyboard *k, const uint32_t *map, const uint32_t *dimen)
140 | {
141 | button *btn;
142 | int i, idx = 0;
143 | uint32_t col = 0;
144 | char buf[2] = { 0 };
145 | uint8_t code;
146 |
147 | int x = k->x + PADDING;
148 | int y = k->y + PADDING;
149 | int w;
150 | const int btn_w = (k->w - PADDING*(dimen[1]+1)) /dimen[1];
151 | const int btn_h = (k->h - PADDING*(dimen[0]+1)) /dimen[0];
152 |
153 | for(i = 0; map[i]; ++i)
154 | {
155 | code = (map[i] & 0xFF);
156 | w = (GET_KS(map[i])+1)*btn_w + PADDING*GET_KS(map[i]);
157 |
158 | if(map[i] & KFLAG_HALF)
159 | w /= 2;
160 | else if(map[i] & KFLAG_PLUS_HALF)
161 | w = w*1.5 + PADDING*0.5;
162 |
163 | if(code != OSK_EMPTY)
164 | {
165 | btn = mzalloc(sizeof(button));
166 | btn->x = x;
167 | btn->y = y;
168 | btn->w = w;
169 | btn->h = btn_h;
170 |
171 | struct keyboard_btn_data *d = mzalloc(sizeof(struct keyboard_btn_data));
172 | d->k = k;
173 | d->btn_idx = i;
174 | btn->clicked_data = d;
175 | btn->clicked = keyboard_btn_clicked;
176 |
177 | buf[0] = (map[i] & 0xFF);
178 | button_init_ui(btn, ((int8_t)buf[0]) >= 0 ? buf : specialKeys[0xFF - (map[i] & 0xFF)], SIZE_NORMAL);
179 | list_add(&k->btns, btn);
180 | list_add(&k->keyboard_bnt_data, d);
181 | }
182 |
183 | col += GET_KS(map[i])+1;
184 | if(col < dimen[1])
185 | x += w + PADDING;
186 | else
187 | {
188 | x = k->x + PADDING;
189 | y += btn_h + PADDING;
190 | col = 0;
191 | }
192 | }
193 |
194 | k->keycode_map = map;
195 | return 0;
196 | }
197 |
198 | struct keyboard *keyboard_create(int type, int x, int y, int w, int h)
199 | {
200 | struct keyboard *k = mzalloc(sizeof(struct keyboard));
201 | k->x = x;
202 | k->y = y;
203 | k->w = w;
204 | k->h = h;
205 |
206 | switch(type)
207 | {
208 | case KEYBOARD_PIN:
209 | keyboard_init_map(k, pinKeycodeMap, pinKeycodeMapDimensions);
210 | break;
211 | case KEYBOARD_NORMAL:
212 | default:
213 | keyboard_init_map(k, normalKeycodeMapCharset1, normalKeycodeMapDimensions);
214 | break;
215 | }
216 |
217 | return k;
218 | }
219 |
220 | void keyboard_destroy(struct keyboard *k)
221 | {
222 | list_clear(&k->btns, &button_destroy);
223 | list_clear(&k->keyboard_bnt_data, free);
224 | free(k);
225 | }
226 |
227 | void keyboard_set_callback(struct keyboard *k, keyboard_on_pressed_callback callback, void *data)
228 | {
229 | k->key_pressed = callback;
230 | k->key_pressed_data = data;
231 | }
232 |
--------------------------------------------------------------------------------
/lib/keyboard.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef KEYBOARD_H
19 | #define KEYBOARD_H
20 |
21 | #include
22 |
23 | #include "framebuffer.h"
24 | #include "button.h"
25 |
26 | #define OSK_EMPTY 0xFF
27 | #define OSK_ENTER 0xFE
28 | #define OSK_BACKSPACE 0xFD
29 | #define OSK_CLEAR 0xFC
30 | #define OSK_CHARSET1 0xFB
31 | #define OSK_CHARSET2 0xFA
32 | #define OSK_CHARSET3 0xF9
33 | #define OSK_CHARSET4 0xF8
34 |
35 | typedef void (*keyboard_on_pressed_callback)(void *data, uint8_t keycode);
36 | struct keyboard
37 | {
38 | FB_ITEM_POS
39 | button **btns;
40 | void **keyboard_bnt_data;
41 | const uint32_t *keycode_map;
42 | keyboard_on_pressed_callback key_pressed;
43 | void *key_pressed_data;
44 | };
45 |
46 | #define KEYBOARD_PIN 0
47 | #define KEYBOARD_NORMAL 1
48 |
49 | struct keyboard *keyboard_create(int type, int x, int y, int w, int h);
50 | void keyboard_set_callback(struct keyboard *k, keyboard_on_pressed_callback callback, void *data);
51 | void keyboard_destroy(struct keyboard *k);
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/lib/listview.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef LISTVIEW_H
19 | #define LISTVIEW_H
20 |
21 | #include "input.h"
22 | #include "framebuffer.h"
23 | #include "touch_tracker.h"
24 |
25 | enum
26 | {
27 | IT_VISIBLE = 0x01,
28 | IT_HOVER = 0x02,
29 | IT_SELECTED = 0x04,
30 | };
31 |
32 | typedef struct
33 | {
34 | int id;
35 | void *data;
36 | int flags;
37 | fb_item_pos *parent_rect;
38 | int touchX, touchY;
39 | } listview_item;
40 |
41 | typedef struct
42 | {
43 | int id;
44 | listview_item *hover;
45 | int fast_scroll;
46 | } listview_touch_data;
47 |
48 | typedef struct
49 | {
50 | FB_ITEM_HEAD
51 |
52 | fb_item_pos last_rendered_pos;
53 |
54 | int pos; // scroll pos
55 | int fullH; // height of all items
56 |
57 | listview_item **items;
58 | listview_item *selected;
59 |
60 | void (*item_draw)(int, int, int, listview_item *); // x, y, w, item
61 | void (*item_hide)(void*); // data
62 | int (*item_height)(listview_item *); // item
63 |
64 | void (*item_destroy)(listview_item *);
65 | void (*item_selected)(listview_item *, listview_item *); // prev, now
66 | void (*item_confirmed)(listview_item *); // item - confirmed by keyaction
67 |
68 | fb_item_header **ui_items;
69 | fb_rect *scroll_mark;
70 | fb_rect *overscroll_marks[2];
71 | fb_rect *scroll_line;
72 | int keyact_item_selected;
73 |
74 | listview_touch_data touch;
75 | touch_tracker *tracker;
76 | } listview;
77 |
78 | int listview_touch_handler(touch_event *ev, void *data);
79 |
80 | void listview_init_ui(listview *view);
81 | void listview_destroy(listview *view);
82 | listview_item *listview_add_item(listview *view, int id, void *data);
83 | void listview_clear(listview *view);
84 | inline void listview_update_ui(listview *view);
85 | void listview_update_ui_args(listview *view, int only_if_moved, int mutex_locked);
86 | void listview_enable_scroll(listview *view, int enable);
87 | void listview_update_scroll_mark(listview *view);
88 | void listview_update_overscroll_mark(listview *v, int side, float overscroll);
89 | void listview_scroll_by(listview *view, int y);
90 | void listview_scroll_to(listview *view, int pct);
91 | int listview_ensure_visible(listview *view, listview_item *it);
92 | int listview_ensure_selected_visible(listview *view);
93 | listview_item *listview_item_at(listview *view, int y_pos);
94 | inline int listview_select_item(listview *view, listview_item *it);
95 | void listview_update_keyact_frame(listview *view);
96 | int listview_keyaction_call(void *data, int act);
97 |
98 | void *rom_item_create(const char *text, const char *partition, const char *icon);
99 | void rom_item_draw(int x, int y, int w, listview_item *it);
100 | void rom_item_hide(void *data);
101 | int rom_item_height(listview_item *it);
102 | void rom_item_destroy(listview_item *it);
103 |
104 | #endif
105 |
--------------------------------------------------------------------------------
/lib/log.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 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 | #ifndef _INIT_LOG_H_
18 | #define _INIT_LOG_H_
19 |
20 | #include "mrom_data.h"
21 |
22 | #ifdef LOG_TO_STDOUT
23 | #include
24 | #define ERROR(fmt, ...) fprintf(stderr, "%s: " fmt "\n", mrom_log_tag(), ##__VA_ARGS__)
25 | #define INFO(fmt, ...) printf("%s: " fmt "\n", mrom_log_tag(), ##__VA_ARGS__)
26 | #else
27 | #include
28 |
29 | #define ERROR(fmt, ...) klog_write(3, "<3>%s: " fmt, mrom_log_tag(), ##__VA_ARGS__)
30 | #define INFO(fmt, ...) klog_write(6, "<6>%s: " fmt, mrom_log_tag(), ##__VA_ARGS__)
31 | #endif
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/lib/mrom_data.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 | #include
20 |
21 | #include "mrom_data.h"
22 |
23 | static char multirom_dir[128] = { 0 };
24 | static char log_tag[64] = { 0 };
25 |
26 | void mrom_set_dir(const char *mrom_dir)
27 | {
28 | snprintf(multirom_dir, sizeof(multirom_dir), "%s", mrom_dir);
29 | }
30 |
31 | void mrom_set_log_tag(const char *tag)
32 | {
33 | snprintf(log_tag, sizeof(log_tag), "%s", tag);
34 | }
35 |
36 | const char *mrom_log_tag(void)
37 | {
38 | return log_tag;
39 | }
40 |
41 | const char *mrom_dir(void)
42 | {
43 | return multirom_dir;
44 | }
45 |
46 | int mrom_is_second_boot(void)
47 | {
48 | int i;
49 | int res = 0;
50 | FILE *f = NULL;
51 | char buff[2048];
52 |
53 | static const char *kmsg_paths[] = {
54 | "/proc/last_kmsg",
55 | "/sys/fs/pstore/console-ramoops",
56 | NULL,
57 | };
58 |
59 | f = fopen("/proc/cmdline", "re");
60 | if(f)
61 | {
62 | if(fgets(buff, sizeof(buff), f) && strstr(buff, "mrom_kexecd=1"))
63 | {
64 | res = 1;
65 | goto exit;
66 | }
67 |
68 | fclose(f);
69 | f = NULL;
70 | }
71 |
72 | for(i = 0; !f && kmsg_paths[i]; ++i)
73 | f = fopen(kmsg_paths[i], "re");
74 |
75 | if(!f)
76 | return 0;
77 |
78 | while(fgets(buff, sizeof(buff), f))
79 | {
80 | if(strstr(buff, SECOND_BOOT_KMESG))
81 | {
82 | res = 1;
83 | goto exit;
84 | }
85 | }
86 |
87 | exit:
88 | fclose(f);
89 | return res;
90 | }
91 |
--------------------------------------------------------------------------------
/lib/mrom_data.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef MROM_DATA_H
19 | #define MROM_DATA_H
20 |
21 | #define SECOND_BOOT_KMESG "MultiromSaysNextBootShouldBeSecondMagic108\n"
22 |
23 | void mrom_set_dir(const char *mrom_dir);
24 | void mrom_set_log_tag(const char *tag);
25 |
26 | const char *mrom_log_tag(void);
27 | const char *mrom_dir(void);
28 | int mrom_is_second_boot(void);
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/lib/notification_card.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef NOTIFICATION_CARD_H
19 | #define NOTIFICATION_CARD_H
20 |
21 | #include "framebuffer.h"
22 |
23 | enum // order from right to left
24 | {
25 | BTN_POSITIVE,
26 | BTN_NEGATIVE,
27 |
28 | BTN_COUNT
29 | };
30 |
31 | enum
32 | {
33 | NCARD_POS_AUTO,
34 | NCARD_POS_TOP,
35 | NCARD_POS_BOTTOM,
36 | NCARD_POS_CENTER,
37 | };
38 |
39 | typedef void (*ncard_callback)(void*);
40 |
41 | typedef struct
42 | {
43 | char *text;
44 | void *callback_data;
45 | ncard_callback callback;
46 | } ncard_builder_btn;
47 |
48 | typedef struct
49 | {
50 | char *title;
51 | char *text;
52 | ncard_builder_btn *buttons[BTN_COUNT];
53 | int pos;
54 | fb_item_pos *avoid_item;
55 | int cancelable;
56 | ncard_callback on_hidden_call;
57 | void *on_hidden_data;
58 | int reveal_from_black;
59 | } ncard_builder;
60 |
61 | ncard_builder *ncard_create_builder(void);
62 | void ncard_set_title(ncard_builder *b, const char *title);
63 | void ncard_set_text(ncard_builder *b, const char *text);
64 | void ncard_set_pos(ncard_builder *b, int pos);
65 | void ncard_set_cancelable(ncard_builder *b, int cancelable);
66 | void ncard_avoid_item(ncard_builder *b, void *item);
67 | void ncard_add_btn(ncard_builder *b, int btn_type, const char *text, ncard_callback callback, void *callback_data);
68 | void ncard_set_on_hidden(ncard_builder *b, ncard_callback callback, void *data);
69 | void ncard_set_from_black(ncard_builder *b, int from_black);
70 |
71 | void ncard_set_top_offset(int offset);
72 | void ncard_show(ncard_builder *b, int destroy_builder);
73 | void ncard_hide(void);
74 | int ncard_is_visible(void);
75 | int ncard_try_cancel(void);
76 | void ncard_hide_callback(void *data);
77 | void ncard_destroy_builder(ncard_builder *b);
78 |
79 | #endif
80 |
--------------------------------------------------------------------------------
/lib/progressdots.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 |
20 | #include "progressdots.h"
21 | #include "colors.h"
22 | #include "workers.h"
23 | #include "util.h"
24 | #include "animation.h"
25 |
26 | static void progdots_anim_finished(void *data)
27 | {
28 | progdots *p = data;
29 |
30 | item_anim *a = item_anim_create(p->rect, 1000, INTERPOLATOR_ACCEL_DECEL);
31 | if(p->rect->x == p->x)
32 | a->targetX = p->x + PROGDOTS_W - p->rect->w;
33 | else
34 | a->targetX = p->x;
35 | a->start_offset = 300;
36 | a->on_finished_call = progdots_anim_finished;
37 | a->on_finished_data = p;
38 | item_anim_add(a);
39 | }
40 |
41 | progdots *progdots_create(int x, int y)
42 | {
43 | progdots *p = mzalloc(sizeof(progdots));
44 | p->x = x;
45 | p->y = y;
46 |
47 | p->rect = fb_add_rect(x, y, PROGDOTS_H*4, PROGDOTS_H, C_HIGHLIGHT_BG);
48 | item_anim *a = item_anim_create(p->rect, 1000, INTERPOLATOR_ACCEL_DECEL);
49 | a->targetX = x + PROGDOTS_W - p->rect->w;
50 | a->on_finished_call = progdots_anim_finished;
51 | a->on_finished_data = p;
52 | item_anim_add(a);
53 | return p;
54 | }
55 |
56 | void progdots_destroy(progdots *p)
57 | {
58 | anim_cancel_for(p->rect, 0);
59 | fb_rm_rect(p->rect);
60 | free(p);
61 | }
62 |
--------------------------------------------------------------------------------
/lib/progressdots.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef PROGRESSDOTS_H
19 | #define PROGRESSDOTS_H
20 |
21 | #include "framebuffer.h"
22 |
23 | #define PROGDOTS_W (400*DPI_MUL)
24 | #define PROGDOTS_H (10*DPI_MUL)
25 | #define PROGDOTS_CNT 8
26 |
27 | typedef struct
28 | {
29 | FB_ITEM_POS
30 |
31 | fb_rect *rect;
32 | } progdots;
33 |
34 | progdots *progdots_create(int x, int y);
35 | void progdots_destroy(progdots *p);
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/lib/tabview.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef TABVIEW_H
19 | #define TABVIEW_H
20 |
21 | #include
22 | #include "framebuffer.h"
23 | #include "input.h"
24 | #include "touch_tracker.h"
25 |
26 | struct tabview_page;
27 |
28 | typedef struct {
29 | FB_ITEM_POS
30 |
31 | int pos;
32 | int anim_pos_start;
33 | int anim_pos_diff;
34 | int fullW;
35 |
36 | struct tabview_page **pages;
37 | int count;
38 | int curr_page;
39 |
40 | uint32_t anim_id;
41 | pthread_mutex_t mutex;
42 |
43 | void (*on_page_changed_by_swipe)(int); // new_page
44 | void (*on_pos_changed)(float);
45 |
46 | int last_reported_pos;
47 |
48 | int touch_id;
49 | int touch_moving;
50 | touch_tracker *tracker;
51 | } tabview;
52 |
53 | tabview *tabview_create(int x, int y, int w, int h);
54 | int tabview_touch_handler(touch_event *ev, void *data);
55 | void tabview_destroy(tabview *t);
56 | void tabview_add_page(tabview *t, int idx);
57 | void tabview_rm_page(tabview *t, int idx);
58 | void tabview_add_item(tabview *t, int page_idx, void *fb_item);
59 | void tabview_add_items(tabview *t, int page_idx, void *fb_items);
60 | void tabview_rm_item(tabview *t, int page_idx, void *fb_item);
61 | void tabview_update_positions(tabview *t);
62 | void tabview_set_active_page(tabview *t, int page_idx, int anim_duration);
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/lib/touch_tracker.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 |
20 | #include "touch_tracker.h"
21 | #include "util.h"
22 |
23 | touch_tracker *touch_tracker_create(void)
24 | {
25 | touch_tracker *t = mzalloc(sizeof(touch_tracker));
26 | return t;
27 | }
28 |
29 | void touch_tracker_destroy(touch_tracker *t)
30 | {
31 | free(t);
32 | }
33 |
34 | void touch_tracker_start(touch_tracker *t, touch_event *ev)
35 | {
36 | t->distance_abs_x = t->distance_abs_y = 0;
37 | t->distance_x = t->distance_y = 0;
38 | t->start_x = ev->x;
39 | t->start_y = ev->y;
40 | t->last_x = ev->x;
41 | t->last_y = ev->y;
42 | t->prev_x = ev->x;
43 | t->prev_y = ev->y;
44 | memcpy(&t->time_start, &ev->time, sizeof(struct timeval));
45 | }
46 |
47 | void touch_tracker_finish(touch_tracker *t, touch_event *ev)
48 | {
49 | t->period = timeval_us_diff(ev->time, t->time_start);
50 | }
51 |
52 | void touch_tracker_add(touch_tracker *t, touch_event *ev)
53 | {
54 | t->prev_x = t->last_x;
55 | t->prev_y = t->last_y;
56 | t->distance_x += ev->x - t->last_x;
57 | t->distance_y += ev->y - t->last_y;
58 | t->distance_abs_x += iabs(ev->x - t->last_x);
59 | t->distance_abs_y += iabs(ev->y - t->last_y);
60 | t->last_x = ev->x;
61 | t->last_y = ev->y;
62 | }
63 |
64 | float touch_tracker_get_velocity(touch_tracker *t, int axis)
65 | {
66 | if(axis == TRACKER_X)
67 | return ((((float)t->distance_x) / t->period) * 1000000) / DPI_MUL;
68 | else
69 | return ((((float)t->distance_y) / t->period) * 1000000) / DPI_MUL;
70 | }
71 |
72 | float touch_tracker_get_velocity_abs(touch_tracker *t, int axis)
73 | {
74 | if(axis == TRACKER_X)
75 | return ((((float)t->distance_abs_x) / t->period) * 1000000) / DPI_MUL;
76 | else
77 | return ((((float)t->distance_abs_y) / t->period) * 1000000) / DPI_MUL;
78 | }
79 |
--------------------------------------------------------------------------------
/lib/touch_tracker.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef TOUCH_TRACKER_H
19 | #define TOUCH_TRACKER_H
20 |
21 | #include
22 | #include
23 | #include "input.h"
24 |
25 | #define TRACKER_X 0
26 | #define TRACKER_Y 1
27 |
28 | typedef struct
29 | {
30 | struct timeval time_start;
31 | int64_t period;
32 | int distance_x, distance_y;
33 | int distance_abs_x, distance_abs_y;
34 | int last_x, last_y;
35 | int prev_x, prev_y;
36 | int start_x, start_y;
37 | } touch_tracker;
38 |
39 | touch_tracker *touch_tracker_create(void);
40 | void touch_tracker_destroy(touch_tracker *t);
41 | void touch_tracker_start(touch_tracker *t, touch_event *ev);
42 | void touch_tracker_finish(touch_tracker *t, touch_event *ev);
43 | void touch_tracker_add(touch_tracker *t, touch_event *ev);
44 | float touch_tracker_get_velocity(touch_tracker *t, int axis);
45 | float touch_tracker_get_velocity_abs(touch_tracker *t, int axis);
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/lib/util.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 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 | #ifndef _INIT_UTIL_H_
18 | #define _INIT_UTIL_H_
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | #define UNUSED __attribute__((unused))
26 |
27 | #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
28 |
29 | #define REBOOT_SYSTEM 0
30 | #define REBOOT_RECOVERY 1
31 | #define REBOOT_BOOTLOADER 2
32 | #define REBOOT_SHUTDOWN 3
33 |
34 | time_t gettime(void);
35 | unsigned int decode_uid(const char *s);
36 | int mkdir_recursive(const char *pathname, mode_t mode);
37 | int mkdir_recursive_with_perms(const char *pathname, mode_t mode, const char *owner, const char *group);
38 | void sanitize(char *p);
39 | int make_link(const char *oldpath, const char *newpath);
40 | void remove_link(const char *oldpath, const char *newpath);
41 | int wait_for_file(const char *filename, int timeout);
42 | int copy_file(const char *from, const char *to);
43 | int copy_dir(const char *from, const char *to);
44 | int mkdir_with_perms(const char *path, mode_t mode, const char *owner, const char *group);
45 | int write_file(const char *path, const char *value);
46 | int remove_dir(const char *dir);
47 | int run_cmd(char **cmd);
48 | int run_cmd_with_env(char **cmd, char *const *envp);
49 | char *run_get_stdout(char **cmd);
50 | char *run_get_stdout_with_exit(char **cmd, int *exit_code);
51 | char *run_get_stdout_with_exit_with_env(char **cmd, int *exit_code, char *const *envp);
52 | char *readlink_recursive(const char *link);
53 | void stdio_to_null();
54 | char *parse_string(char *src);
55 | uint32_t timespec_diff(struct timespec *f, struct timespec *s);
56 | inline int64_t timeval_us_diff(struct timeval now, struct timeval prev);
57 | void emergency_remount_ro(void);
58 | int create_loop_device(const char *dev_path, const char *img_path, int loop_num, int loop_chmod);
59 | int mount_image(const char *src, const char *dst, const char *fs, int flags, const void *data);
60 | void do_reboot(int type);
61 | int mr_system(const char *shell_fmt, ...);
62 |
63 | inline int imin(int a, int b);
64 | inline int imax(int a, int b);
65 | inline int iabs(int a);
66 | inline int in_rect(int x, int y, int rx, int ry, int rw, int rh);
67 |
68 | inline void *mzalloc(size_t size); // alloc and fill with 0s
69 | char *strtoupper(const char *str);
70 | int strstartswith(const char *haystack, const char *needle);
71 | int strendswith(const char *haystack, const char *needle);
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/lib/velocity_tracker.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 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
18 |
19 | #include "touch_tracker.h"
20 | #include "util.h"
21 |
22 | touch_tracker *touch_tracker_create(void)
23 | {
24 | touch_tracker *t = mzalloc(sizeof(touch_tracker));
25 | return t;
26 | }
27 |
28 | void touch_tracker_destroy(touch_tracker *t)
29 | {
30 | free(t);
31 | }
32 |
33 | void touch_tracker_start(touch_tracker *t, touch_event *ev)
34 | {
35 | t->distance_abs_x = t->distance_abs_y = 0;
36 | t->start_x = ev->x;
37 | t->start_y = ev->y;
38 | t->last_x = ev->x;
39 | t->last_y = ev->y;
40 | memcpy(&v->time_start, &ev->time, sizeof(struct timeval));
41 | }
42 |
43 | void touch_tracker_finish(touch_tracker *t, touch_event *ev)
44 | {
45 | t->distance_x = ev->x - t->start_x;
46 | t->distance_y = ev->y - t->start_y;
47 | t->period = timeval_us_diff(ev->time, t->time_start);
48 | }
49 |
50 | void touch_tracker_add(touch_tracker *t, touch_event *ev)
51 | {
52 | t->distance_abs_x += iabs(ev->x - t->last_x);
53 | t->distance_abs_y += iabs(ev->y - t->last_y);
54 | t->last_x = ev->x;
55 | t->last_y = ev->y;
56 | }
57 |
58 | float touch_tracker_get_velocity(touch_tracker *t, int axis)
59 | {
60 | if(axis == TRACKER_X)
61 | return ((((float)t->distance_x) / t->period) * 1000000) / DPI_MUL;
62 | else
63 | return ((((float)t->distance_y) / t->period) * 1000000) / DPI_MUL;
64 | }
65 |
66 | float touch_tracker_get_velocity_abs(touch_tracker *t, int axis)
67 | {
68 | if(axis == TRACKER_X)
69 | return ((((float)t->distance_abs_x) / t->period) * 1000000) / DPI_MUL;
70 | else
71 | return ((((float)t->distance_abs_y) / t->period) * 1000000) / DPI_MUL;
72 | }
73 |
--------------------------------------------------------------------------------
/lib/workers.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | #include "util.h"
23 | #include "workers.h"
24 | #include "log.h"
25 | #include "containers.h"
26 |
27 | struct worker
28 | {
29 | void *data;
30 | worker_call call;
31 | };
32 |
33 | struct worker_thread
34 | {
35 | pthread_t thread;
36 | pthread_mutex_t mutex;
37 | struct worker **workers;
38 | volatile int run;
39 | };
40 |
41 | static struct worker_thread worker_thread = {
42 | .mutex = PTHREAD_MUTEX_INITIALIZER,
43 | .workers = NULL,
44 | .run = 0,
45 | };
46 |
47 | #define SLEEP_CONST 10
48 | static void *worker_thread_work(void *data)
49 | {
50 | struct worker_thread *t = (struct worker_thread*)data;
51 | struct worker **w;
52 |
53 | struct timespec last, curr;
54 | uint32_t diff = 0, prev_sleep = 0;
55 | clock_gettime(CLOCK_MONOTONIC, &last);
56 |
57 | while(t->run)
58 | {
59 | pthread_mutex_lock(&t->mutex);
60 |
61 | clock_gettime(CLOCK_MONOTONIC, &curr);
62 | diff = timespec_diff(&last, &curr);
63 |
64 | for(w = t->workers; w && *w;)
65 | {
66 | if((*w)->call(diff, (*w)->data))
67 | w = list_rm_at(&worker_thread.workers, w - t->workers, &free);
68 | else
69 | ++w;
70 | }
71 |
72 | pthread_mutex_unlock(&t->mutex);
73 |
74 | last = curr;
75 | if(diff <= SLEEP_CONST+prev_sleep)
76 | {
77 | prev_sleep = SLEEP_CONST+prev_sleep-diff;
78 | usleep(prev_sleep*1000);
79 | }
80 | else
81 | prev_sleep = 0;
82 | }
83 | return NULL;
84 | }
85 |
86 | void workers_start(void)
87 | {
88 | if(worker_thread.run != 0)
89 | return;
90 |
91 | worker_thread.run = 1;
92 | pthread_create(&worker_thread.thread, NULL, worker_thread_work, &worker_thread);
93 | }
94 |
95 | void workers_stop(void)
96 | {
97 | if(worker_thread.run != 1)
98 | return;
99 |
100 | worker_thread.run = 0;
101 | pthread_join(worker_thread.thread, NULL);
102 |
103 | list_clear(&worker_thread.workers, &free);
104 | }
105 |
106 | void workers_add(worker_call call, void *data)
107 | {
108 | if(worker_thread.run != 1)
109 | {
110 | ERROR("workers: adding worker when the thread isn't running'\n");
111 | return;
112 | }
113 |
114 | struct worker *w = mzalloc(sizeof(struct worker));
115 | w->call = call;
116 | w->data = data;
117 |
118 | pthread_mutex_lock(&worker_thread.mutex);
119 | list_add(&worker_thread.workers, w);
120 | pthread_mutex_unlock(&worker_thread.mutex);
121 | }
122 |
123 | void workers_remove(worker_call call, void *data)
124 | {
125 | if(worker_thread.run != 1)
126 | {
127 | ERROR("workers: removing worker when the thread isn't running'\n");
128 | return;
129 | }
130 |
131 | pthread_mutex_lock(&worker_thread.mutex);
132 | if(worker_thread.workers)
133 | {
134 | int i;
135 | struct worker *w;
136 | for(i = 0; worker_thread.workers[i]; ++i)
137 | {
138 | w = worker_thread.workers[i];
139 | if(w->call == call && w->data == data)
140 | {
141 | list_rm_at(&worker_thread.workers, i, &free);
142 | break;
143 | }
144 | }
145 | }
146 | pthread_mutex_unlock(&worker_thread.mutex);
147 | }
148 |
149 | pthread_t workers_get_thread_id(void)
150 | {
151 | return worker_thread.thread;
152 | }
153 |
--------------------------------------------------------------------------------
/lib/workers.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef WORKERS_H
19 | #define WORKERS_H
20 |
21 | #include
22 | #include
23 |
24 | typedef int (*worker_call)(uint32_t, void *); // ms_diff, data. Returns 1 if it should be removed
25 |
26 | void workers_start(void);
27 | void workers_stop(void);
28 | void workers_add(worker_call call, void *data);
29 | void workers_remove(worker_call call, void *data);
30 | pthread_t workers_get_thread_id(void);
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/main.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #include "multirom.h"
29 | #include "lib/framebuffer.h"
30 | #include "lib/log.h"
31 | #include "version.h"
32 | #include "lib/util.h"
33 | #include "lib/mrom_data.h"
34 |
35 | #define EXEC_MASK (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
36 | #define KEEP_REALDATA "/dev/.keep_realdata"
37 | #define REALDATA "/realdata"
38 |
39 |
40 | static void do_kexec(void)
41 | {
42 | emergency_remount_ro();
43 |
44 | execl("/kexec", "/kexec", "-e", NULL);
45 |
46 | ERROR("kexec -e failed! (%d: %s)", errno, strerror(errno));
47 | while(1);
48 | }
49 |
50 | int main(int argc, const char *argv[])
51 | {
52 | int i;
53 | const char *rom_to_boot = NULL;
54 |
55 | for(i = 1; i < argc; ++i)
56 | {
57 | if(strcmp(argv[i], "-v") == 0)
58 | {
59 | printf("%d%s\n", VERSION_MULTIROM, VERSION_DEV_FIX);
60 | fflush(stdout);
61 | return 0;
62 | }
63 | else if(strncmp(argv[i], "--boot-rom=", sizeof("--boot-rom")) == 0)
64 | {
65 | rom_to_boot = argv[i] + sizeof("--boot-rom");
66 | }
67 | }
68 |
69 | srand(time(0));
70 | klog_init();
71 |
72 | // output all messages to dmesg,
73 | // but it is possible to filter out INFO messages
74 | klog_set_level(6);
75 |
76 | mrom_set_log_tag("multirom");
77 |
78 | ERROR("Running MultiROM v%d%s\n", VERSION_MULTIROM, VERSION_DEV_FIX);
79 |
80 | // root is mounted read only in android and MultiROM uses
81 | // it to store some temp files, so remount it.
82 | // Yes, there is better solution to this.
83 | if(rom_to_boot)
84 | mount(NULL, "/", NULL, MS_REMOUNT, NULL);
85 |
86 | int exit = multirom(rom_to_boot);
87 |
88 | if(rom_to_boot)
89 | mount(NULL, "/", NULL, MS_RDONLY | MS_REMOUNT, NULL);
90 |
91 | if(exit >= 0)
92 | {
93 | if(exit & EXIT_REBOOT_RECOVERY)
94 | do_reboot(REBOOT_RECOVERY);
95 | else if(exit & EXIT_REBOOT_BOOTLOADER)
96 | do_reboot(REBOOT_BOOTLOADER);
97 | else if(exit & EXIT_SHUTDOWN)
98 | do_reboot(REBOOT_SHUTDOWN);
99 | else if(exit & EXIT_REBOOT)
100 | do_reboot(REBOOT_SYSTEM);
101 |
102 | if(exit & EXIT_KEXEC)
103 | {
104 | do_kexec();
105 | return 0;
106 | }
107 |
108 | // indicates trampoline to keep /realdata mounted
109 | if(!(exit & EXIT_UMOUNT))
110 | close(open(KEEP_REALDATA, O_WRONLY | O_CREAT, 0000));
111 | }
112 |
113 | return 0;
114 | }
115 |
--------------------------------------------------------------------------------
/multirom.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef MULTIROM_H
19 | #define MULTIROM_H
20 |
21 | #include
22 | #include
23 |
24 | #include "lib/fstab.h"
25 | #include "lib/containers.h"
26 | #include "kexec.h"
27 | #include "rcadditions.h"
28 |
29 | enum
30 | {
31 | ROM_DEFAULT = 0,
32 |
33 | ROM_ANDROID_INTERNAL = 1,
34 | ROM_ANDROID_USB_IMG = 2,
35 | ROM_ANDROID_USB_DIR = 3,
36 |
37 | ROM_LINUX_INTERNAL = 4,
38 | ROM_LINUX_USB = 5,
39 |
40 | ROM_UNSUPPORTED_INT = 6,
41 | ROM_UNSUPPORTED_USB = 7,
42 | ROM_UNKNOWN = 8
43 | };
44 |
45 | #define M(x) (1 << x)
46 | #define MASK_INTERNAL (M(ROM_DEFAULT) | M(ROM_ANDROID_INTERNAL) | M(ROM_UNSUPPORTED_INT) | M(ROM_LINUX_INTERNAL))
47 | #define MASK_USB_ROMS (M(ROM_ANDROID_USB_IMG) | M(ROM_ANDROID_USB_DIR) | M(ROM_UNSUPPORTED_USB) | M(ROM_LINUX_USB))
48 | #define MASK_ANDROID (M(ROM_ANDROID_USB_DIR) | M(ROM_ANDROID_USB_IMG) | M(ROM_ANDROID_INTERNAL))
49 | #define MASK_UNSUPPORTED (M(ROM_UNSUPPORTED_USB) | M(ROM_UNSUPPORTED_INT))
50 | #define MASK_LINUX (M(ROM_LINUX_INTERNAL) | M(ROM_LINUX_USB))
51 | #define MASK_KEXEC (MASK_LINUX)
52 |
53 | enum
54 | {
55 | EXIT_REBOOT = 0x01,
56 | EXIT_UMOUNT = 0x02,
57 | EXIT_REBOOT_RECOVERY = 0x04,
58 | EXIT_REBOOT_BOOTLOADER = 0x08,
59 | EXIT_SHUTDOWN = 0x10,
60 | EXIT_KEXEC = 0x20,
61 |
62 | EXIT_REBOOT_MASK = (EXIT_REBOOT | EXIT_REBOOT_RECOVERY | EXIT_REBOOT_BOOTLOADER | EXIT_SHUTDOWN),
63 | };
64 |
65 | enum
66 | {
67 | AUTOBOOT_NAME = 0x00,
68 | AUTOBOOT_LAST = 0x01,
69 | AUTOBOOT_FORCE_CURRENT = 0x02,
70 | AUTOBOOT_CHECK_KEYS = 0x04,
71 | };
72 |
73 | struct usb_partition
74 | {
75 | char *name;
76 | char *mount_path;
77 | char *uuid;
78 | char *fs;
79 | int keep_mounted;
80 | };
81 |
82 | struct rom_info {
83 | // for future vals?
84 | map *str_vals;
85 | };
86 |
87 | struct multirom_rom
88 | {
89 | int id;
90 | char *name;
91 | char *base_path;
92 | char *icon_path;
93 | int type;
94 | int has_bootimg;
95 | struct usb_partition *partition;
96 | };
97 |
98 | struct multirom_status
99 | {
100 | int is_second_boot;
101 | int is_running_in_primary_rom;
102 | int auto_boot_seconds;
103 | int auto_boot_type;
104 | int colors;
105 | int brightness;
106 | int enable_adb;
107 | int hide_internal;
108 | char *int_display_name;
109 | int rotation;
110 | int force_generic_fb;
111 | float anim_duration_coef;
112 | struct multirom_rom *auto_boot_rom;
113 | struct multirom_rom *current_rom;
114 | struct multirom_rom **roms;
115 | struct usb_partition **partitions;
116 | char *curr_rom_part;
117 | struct fstab *fstab;
118 | struct rcadditions rc;
119 | };
120 |
121 | int multirom(const char *rom_to_boot);
122 | int multirom_find_base_dir(void);
123 | void multirom_emergency_reboot(void);
124 | int multirom_default_status(struct multirom_status *s);
125 | void multirom_find_usb_roms(struct multirom_status *s);
126 | int multirom_generate_rom_id(void);
127 | struct multirom_rom *multirom_get_internal(struct multirom_status *s);
128 | struct multirom_rom *multirom_get_rom(struct multirom_status *s, const char *name, const char *part_uuid);
129 | struct multirom_rom *multirom_get_rom_by_id(struct multirom_status *s, int id);
130 | int multirom_load_status(struct multirom_status *s);
131 | void multirom_import_internal(void);
132 | void multirom_dump_status(struct multirom_status *s);
133 | int multirom_save_status(struct multirom_status *s);
134 | void multirom_fixup_rom_name(struct multirom_rom *rom, char *name, const char *def);
135 | int multirom_prepare_for_boot(struct multirom_status *s, struct multirom_rom *to_boot);
136 | void multirom_free_status(struct multirom_status *s);
137 | void multirom_free_rom(void *rom);
138 | int multirom_init_fb(int rotation);
139 | int multirom_prep_android_mounts(struct multirom_status *s, struct multirom_rom *rom);
140 | int multirom_create_media_link(struct multirom_status *s);
141 | int multirom_process_android_fstab(char *fstab_name, int has_fw, struct fstab_part **fw_part);
142 | int multirom_get_api_level(const char *path);
143 | int multirom_get_rom_type(struct multirom_rom *rom);
144 | int multirom_get_trampoline_ver(void);
145 | int multirom_has_kexec(void);
146 | int multirom_load_kexec(struct multirom_status *s, struct multirom_rom *rom);
147 | int multirom_get_bootloader_cmdline(struct multirom_status *s, char *str, size_t size);
148 | int multirom_find_file(char *res, const char *name_part, const char *path);
149 | int multirom_fill_kexec_linux(struct multirom_status *s, struct multirom_rom *rom, struct kexec *kexec);
150 | int multirom_fill_kexec_android(struct multirom_status *s, struct multirom_rom *rom, struct kexec *kexec);
151 | int multirom_extract_bytes(const char *dst, FILE *src, size_t size);
152 | int multirom_update_partitions(struct multirom_status *s);
153 | void multirom_destroy_partition(void *part);
154 | void multirom_set_usb_refresh_thread(struct multirom_status *s, int run);
155 | void multirom_set_usb_refresh_handler(void (*handler)(void));
156 | int multirom_mount_usb(struct usb_partition *part);
157 | int multirom_copy_log(char *klog, const char *dest_path_relative);
158 | int multirom_scan_partition_for_roms(struct multirom_status *s, struct usb_partition *p);
159 | struct usb_partition *multirom_get_partition(struct multirom_status *s, char *uuid);
160 | int multirom_path_exists(char *base, char *filename);
161 | struct rom_info *multirom_parse_rom_info(struct multirom_status *s, struct multirom_rom *rom);
162 | void multirom_destroy_rom_info(struct rom_info *info);
163 | char **multirom_get_rom_info_str(struct rom_info *info, char *key);
164 | int multirom_replace_aliases_cmdline(char **s, struct rom_info *i, struct multirom_status *status, struct multirom_rom *rom);
165 | int multirom_replace_aliases_root_path(char **s, struct multirom_rom *rom);
166 | char *multirom_get_klog(void);
167 | int multirom_get_battery(void);
168 | int multirom_run_scripts(const char *type, struct multirom_rom *rom);
169 | int multirom_update_rd_trampoline(const char *path);
170 | char *multirom_find_fstab_in_rc(const char *rcfile);
171 | void multirom_find_rom_icon(struct multirom_rom *rom);
172 |
173 | #endif
174 |
--------------------------------------------------------------------------------
/multirom_ui.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef MULTIROM_UI_H
19 | #define MULTIROM_UI_H
20 |
21 | #include "multirom.h"
22 | #include "lib/input.h"
23 | #include "lib/listview.h"
24 |
25 | enum
26 | {
27 | TAB_INTERNAL = 0,
28 | TAB_USB,
29 | TAB_MISC,
30 |
31 | TAB_COUNT
32 | };
33 |
34 | enum
35 | {
36 | UI_EXIT_BOOT_ROM = 1,
37 | UI_EXIT_REBOOT = 2,
38 | UI_EXIT_REBOOT_RECOVERY = 3,
39 | UI_EXIT_REBOOT_BOOTLOADER = 4,
40 | UI_EXIT_SHUTDOWN = 5
41 | };
42 |
43 | int multirom_ui(struct multirom_status *s, struct multirom_rom **to_boot);
44 | void multirom_ui_init_header(void);
45 | void multirom_ui_change_header_selector_pos(float pos);
46 | void multirom_ui_destroy_tab(int tab);
47 | int multirom_ui_destroy_msgbox(void);
48 | void multirom_ui_switch(int tab);
49 | void multirom_ui_switch_btn(void *data);
50 | void multirom_ui_fill_rom_list(listview *view, int mask);
51 | void multirom_ui_auto_boot(void);
52 | void multirom_ui_refresh_usb_handler(void);
53 | void multirom_ui_start_pong(void *data);
54 | void multirom_ui_init_theme(int tab);
55 | void multirom_ui_destroy_theme(void);
56 |
57 | void *multirom_ui_tab_rom_init(int tab_type);
58 | void multirom_ui_tab_rom_destroy(void *data);
59 | void multirom_ui_tab_rom_boot(void);
60 | void multirom_ui_tab_rom_confirmed(listview_item *it);
61 | void multirom_ui_tab_rom_refresh_usb(int action);
62 | void multirom_ui_tab_rom_update_usb(void);
63 | void multirom_ui_tab_rom_set_empty(void *data, int empty);
64 |
65 | void *multirom_ui_tab_misc_init(void);
66 | void multirom_ui_tab_misc_destroy(void *data);
67 | void multirom_ui_tab_misc_copy_log(void *data);
68 | void multirom_ui_tab_misc_change_clr(void *data);
69 |
70 | void multirom_ui_reboot_btn(void *data);
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/multirom_ui_themes.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include "multirom_ui.h"
19 | #include "multirom_ui_themes.h"
20 | #include "multirom.h"
21 | #include "lib/util.h"
22 | #include "lib/log.h"
23 |
24 | multirom_themes_info *multirom_ui_init_themes(void)
25 | {
26 | multirom_themes_info *i = mzalloc(sizeof(multirom_themes_info));
27 |
28 | i->data = mzalloc(sizeof(multirom_theme_data));
29 |
30 | #define ADD_THEME(RES) \
31 | extern struct multirom_theme theme_info_ ## RES; \
32 | list_add(&i->themes, &theme_info_ ## RES);
33 |
34 | // universal themes which scale according to DPI_MUL
35 | ADD_THEME(landscape);
36 | ADD_THEME(portrait);
37 | return i;
38 | }
39 |
40 | void multirom_ui_free_themes(multirom_themes_info *i)
41 | {
42 | list_clear(&i->themes, NULL);
43 | free(i->data);
44 | free(i);
45 | }
46 |
47 | multirom_theme *multirom_ui_select_theme(multirom_themes_info *i, int w, int h)
48 | {
49 | if(i->themes == NULL)
50 | return NULL;
51 |
52 | multirom_theme *universal = NULL;
53 | const int uni_type = (w > h) ? TH_LANDSCAPE : TH_PORTRAIT;
54 |
55 | multirom_theme **itr;
56 | for(itr = i->themes; *itr; ++itr)
57 | {
58 | if((*itr)->width == w && (*itr)->height == h)
59 | return *itr;
60 |
61 | if((*itr)->width == uni_type)
62 | universal = *itr;
63 | }
64 |
65 | if(universal)
66 | INFO("Using universal theme (%d)\n", uni_type);
67 |
68 | return universal;
69 | }
70 |
--------------------------------------------------------------------------------
/multirom_ui_themes.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef MULTIROM_UI_P_H
19 | #define MULTIROM_UI_P_H
20 |
21 | #include "lib/framebuffer.h"
22 | #include "lib/button.h"
23 | #include "lib/progressdots.h"
24 | #include "lib/listview.h"
25 | #include "lib/tabview.h"
26 | #include "multirom_ui.h"
27 |
28 | // universal themes has these as width and height,
29 | // instead of real resolution
30 | #define TH_PORTRAIT (-1)
31 | #define TH_LANDSCAPE (-2)
32 |
33 | typedef struct
34 | {
35 | listview *list;
36 | button **buttons;
37 | void **ui_elements;
38 | fb_text *title_text;
39 | fb_text *usb_text;
40 | button *boot_btn;
41 | progdots *usb_prog;
42 | } tab_data_roms;
43 |
44 | typedef struct
45 | {
46 | button **buttons;
47 | void **ui_elements;
48 | } tab_data_misc;
49 |
50 | typedef struct
51 | {
52 | fb_text *tab_texts[TAB_COUNT];
53 | fb_rect *selected_tab_rect;
54 | fb_rect *selected_rect[TAB_COUNT-1];
55 | button *tab_btns[TAB_COUNT];
56 | tabview *tabs;
57 | int selected_tab;
58 | void *tab_data[TAB_COUNT];
59 | } multirom_theme_data;
60 |
61 | struct multirom_theme
62 | {
63 | int16_t width;
64 | int16_t height;
65 |
66 | void (*destroy)(multirom_theme_data *t);
67 | void (*init_header)(multirom_theme_data *t);
68 | void (*header_set_tab_selector_pos)(multirom_theme_data *t, float pos);
69 | void (*tab_rom_init)(multirom_theme_data *t, tab_data_roms *d, int tab_type);
70 | void (*tab_misc_init)(multirom_theme_data *t, tab_data_misc *d, int color_scheme);
71 | int (*get_tab_width)(multirom_theme_data *t);
72 | int (*get_tab_height)(multirom_theme_data *t);
73 | };
74 | typedef struct multirom_theme multirom_theme;
75 |
76 | typedef struct
77 | {
78 | multirom_theme **themes;
79 | multirom_theme_data *data;
80 | } multirom_themes_info;
81 |
82 | multirom_themes_info *multirom_ui_init_themes(void);
83 | void multirom_ui_free_themes(multirom_themes_info *info);
84 | multirom_theme *multirom_ui_select_theme(multirom_themes_info *i, int w, int h);
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/pong.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef PONG_H
19 | #define PONG_H
20 |
21 | #include "lib/input.h"
22 |
23 | void pong(void);
24 | int pong_touch_handler(touch_event *ev, void *data);
25 | void pong_spawn_ball(int side);
26 | void pong_calc_movement(void);
27 | void pong_add_score(int side);
28 | void pong_handle_ai(void);
29 | int pong_do_movement(int step);
30 | int pong_get_collision(int x, int y);
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/rcadditions.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | #include "lib/log.h"
25 | #include "rcadditions.h"
26 |
27 | static void append_string_buffer(char **buf, const char *what) {
28 | size_t old_len = 0;
29 | if(*buf)
30 | old_len += strlen(*buf);
31 |
32 | *buf = realloc(*buf, old_len + strlen(what) + 1);
33 | (*buf)[old_len] = 0;
34 | strcat(*buf, what);
35 | }
36 |
37 | void rcadditions_append_trigger(struct rcadditions *r, const char *trigger, const char *what) {
38 | if(r->triggers == NULL)
39 | r->triggers = map_create();
40 |
41 | char **ref = (char**)map_get_ref(r->triggers, trigger);
42 | if(ref == NULL)
43 | map_add_not_exist(r->triggers, trigger, strdup(what));
44 | else
45 | append_string_buffer(ref, what);
46 | }
47 |
48 | void rcadditions_append_file(struct rcadditions *r, const char *what) {
49 | append_string_buffer(&r->eof_append, what);
50 | }
51 |
52 | void rcadditions_append_contexts(struct rcadditions *r, const char *what) {
53 | append_string_buffer(&r->file_contexts_append, what);
54 | }
55 |
56 | void rcadditions_free(struct rcadditions *r)
57 | {
58 | free(r->eof_append);
59 | r->eof_append = NULL;
60 |
61 | free(r->file_contexts_append);
62 | r->file_contexts_append = NULL;
63 |
64 | map_destroy(r->triggers, &free);
65 | r->triggers = NULL;
66 | }
67 |
68 | void rcadditions_write_to_files(struct rcadditions *r)
69 | {
70 | if(r->eof_append || r->triggers)
71 | {
72 | FILE *f = fopen("/init.multirom.rc", "we");
73 | if(!f)
74 | {
75 | ERROR("Failed to create init.multirom.rc: %s\n", strerror(errno));
76 | return;
77 | }
78 |
79 | fputs("# This file is autogenerated by MultiROM during boot\n\n", f);
80 |
81 | if(r->triggers)
82 | {
83 | size_t i = 0;
84 | for(; i < r->triggers->size; ++i)
85 | {
86 | fprintf(f, "on %s\n", r->triggers->keys[i]);
87 | fputs((char*)r->triggers->values[i], f);
88 | fputc('\n', f);
89 | }
90 | }
91 |
92 | if(r->eof_append)
93 | {
94 | fputc('\n', f);
95 | fputs(r->eof_append, f);
96 | }
97 | fclose(f);
98 |
99 | chmod("/init.multirom.rc", 0750);
100 |
101 | f = fopen("/init.rc", "ae");
102 | if(!f)
103 | {
104 | ERROR("Failed to open init.rc: %s\n", strerror(errno));
105 | return;
106 | }
107 | fputs("\n# Added by MultiROM\nimport /init.multirom.rc\n", f);
108 | fclose(f);
109 | }
110 |
111 | if(r->file_contexts_append)
112 | {
113 | FILE *f = fopen("/file_contexts", "ae");
114 | if(!f)
115 | {
116 | ERROR("Failed to open file_contexts: %s\n", strerror(errno));
117 | return;
118 | }
119 | fputs("\n# Added by multirom during boot\n", f);
120 | fputs(r->file_contexts_append, f);
121 | fclose(f);
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/rcadditions.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef RCADDITIONS_H
19 | #define RCADDITIONS_H
20 |
21 | #include "lib/containers.h"
22 |
23 | struct rcadditions
24 | {
25 | map *triggers;
26 | char *eof_append;
27 | char *file_contexts_append;
28 | };
29 |
30 | void rcadditions_append_trigger(struct rcadditions *r, const char *trigger, const char *what);
31 | void rcadditions_append_file(struct rcadditions *r, const char *what);
32 | void rcadditions_append_contexts(struct rcadditions *r, const char *what);
33 | void rcadditions_free(struct rcadditions *r);
34 | void rcadditions_write_to_files(struct rcadditions *r);
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/rom_info.txt:
--------------------------------------------------------------------------------
1 | # This file contains info about ROMs capabilites and boot process.
2 | # It should be placed in ROM's folder (eg. /media/multirom/roms/*rom_name*)
3 | # and must be named "rom_info.txt".
4 | # Make sure you got the syntax correct, as the parser is probably pretty
5 | # dumb. Lines with comments must start with #. Beware the whitespaces.
6 | # If you need to use " character in string, just use it, no need to escape it
7 | # MultiROM searches for first and last " on the line.
8 | # These comments should not be deleted.
9 |
10 | # So far, the only supported ROM type for these files is kexec-based linux
11 | type="kexec"
12 |
13 | # Paths to root of the ROM.
14 | # Both image and folder can be specified at one time, MultiROM will use
15 | # the one which it can find. If both are present, folder is used.
16 | # Must _not_ contain spaces.
17 | # Path is from root of the root partition, but you will usually want
18 | # to use following alias:
19 | # - %m - ROM's folder (eg. /media/multirom/roms/*rom_name*)
20 | root_dir="%m/root"
21 | root_img="%m/root.img"
22 | root_img_fs="ext4"
23 |
24 | # Path to kernel and initrd. Kernel path _must_ be specified.
25 | # Paths are relative to the folder in which is this file
26 | # Those can be outside the root folder/image, or use %r if it is in there:
27 | # kernel_path="%r/boot/vmlinuz"
28 | # If ROM is in images, it will mount the image and load it from there.
29 | # You can use * _at the end of the filename_ as wildcard character.
30 | kernel_path="%r/boot/vmlinuz"
31 | initrd_path="%r/boot/initrd.img"
32 |
33 | # Set up the cmdline
34 | # img_cmdline and dir_cmdline are appended to base_cmdline.
35 | # Several aliases are used:
36 | # - %b - base command line from bootloader. You want this as first thing in cmdline.
37 | # - %d - root device. is either "UUID=..." (USB drive) or "/dev/mmcblk0p9" or "/dev/mmcblk0p10"
38 | # - %r - root fs type
39 | # - %s - root directory, from root of the root device
40 | # - %i - root image, from root of the root device
41 | # - %f - fs of the root image
42 | base_cmdline="%b root=%d rootfstype=%r rw console=tty0 access=m2 quiet splash rootflags=defaults,noatime,nodiratime"
43 | img_cmdline="loop=%i loopfstype=%f"
44 | dir_cmdline="rootsubdir=%s"
45 |
--------------------------------------------------------------------------------
/rom_quirks.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | #include "rom_quirks.h"
27 | #include "lib/log.h"
28 | #include "lib/util.h"
29 |
30 | static void workaround_mount_in_sh(const char *path)
31 | {
32 | char line[512];
33 | char *tmp_name = NULL;
34 | FILE *f_in, *f_out;
35 |
36 | f_in = fopen(path, "re");
37 | if(!f_in)
38 | return;
39 |
40 | const int size = strlen(path) + 5;
41 | tmp_name = malloc(size);
42 | snprintf(tmp_name, size, "%s-new", path);
43 | f_out = fopen(tmp_name, "we");
44 | if(!f_out)
45 | {
46 | fclose(f_in);
47 | free(tmp_name);
48 | return;
49 | }
50 |
51 | while(fgets(line, sizeof(line), f_in))
52 | {
53 | if(strstr(line, "mount ") && strstr(line, "/system"))
54 | fputc('#', f_out);
55 | fputs(line, f_out);
56 | }
57 |
58 | fclose(f_in);
59 | fclose(f_out);
60 | rename(tmp_name, path);
61 | free(tmp_name);
62 | }
63 |
64 | static void inject_file_contexts(void)
65 | {
66 | FILE *f;
67 | char line[512];
68 |
69 | f = fopen("/file_contexts", "re");
70 | if(!f)
71 | {
72 | ERROR("Failed to open /file_contexts!");
73 | return;
74 | }
75 |
76 | while(fgets(line, sizeof(line), f))
77 | {
78 | if(strstartswith(line, "/data/media/multirom"))
79 | {
80 | INFO("/file_contexts has been already injected.");
81 | fclose(f);
82 | return;
83 | }
84 | }
85 |
86 | fclose(f);
87 |
88 | INFO("Injecting /file_contexts\n");
89 | f = fopen("/file_contexts", "ae");
90 | if(!f)
91 | {
92 | ERROR("Failed to open /file_contexts for appending!");
93 | return;
94 | }
95 |
96 | fputs("\n"
97 | "# MultiROM folders\n"
98 | "/data/media/multirom(/.*)? <>\n"
99 | "/data/media/0/multirom(/.*)? <>\n"
100 | "/realdata/media/multirom(/.*)? <>\n"
101 | "/realdata/media/0/multirom(/.*)? <>\n"
102 | "/mnt/mrom(/.*)? <>\n",
103 | f);
104 | fclose(f);
105 | }
106 |
107 | void rom_quirks_on_initrd_finalized(void)
108 | {
109 | // walk over all _regular_ files in /
110 | DIR *d = opendir("/");
111 | if(d)
112 | {
113 | struct dirent *dt;
114 | char buff[128];
115 | while((dt = readdir(d)))
116 | {
117 | if(dt->d_type != DT_REG)
118 | continue;
119 |
120 | // The Android L and later releases have SELinux
121 | // set to "enforcing" and "restorecon_recursive /data" line in init.rc.
122 | // Restorecon on /data goes into /data/media/0/multirom/roms/ and changes
123 | // context of all secondary ROMs files to that of /data, including the files
124 | // in secondary ROMs /system dirs. We need to prevent that.
125 | // Right now, we do that by adding entries into /file_contexts that say
126 | // MultiROM folders don't have any context
127 | if(strcmp(dt->d_name, "file_contexts") == 0)
128 | inject_file_contexts();
129 |
130 | // franco.Kernel includes script init.fk.sh which remounts /system as read only
131 | // comment out lines with mount and /system in all .sh scripts in /
132 | if(strendswith(dt->d_name, ".sh"))
133 | {
134 | snprintf(buff, sizeof(buff), "/%s", dt->d_name);
135 | workaround_mount_in_sh(buff);
136 | }
137 | }
138 | closedir(d);
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/rom_quirks.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 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 | #ifndef ROM_QUIRKS_H
18 | #define ROM_QUIRKS_H
19 |
20 | struct multirom_rom;
21 |
22 | void rom_quirks_on_initrd_finalized(void);
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/trampoline/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH:= $(call my-dir)
2 | include $(CLEAR_VARS)
3 |
4 | LOCAL_C_INCLUDES += $(multirom_local_path) $(multirom_local_path)/lib
5 | LOCAL_SRC_FILES:= \
6 | trampoline.c \
7 | devices.c \
8 | adb.c \
9 |
10 | LOCAL_MODULE:= trampoline
11 | LOCAL_MODULE_TAGS := eng
12 |
13 | LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
14 | LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)
15 | LOCAL_STATIC_LIBRARIES := libcutils libc libmultirom_static libbootimg
16 | LOCAL_FORCE_STATIC_EXECUTABLE := true
17 |
18 | ifeq ($(MR_INIT_DEVICES),)
19 | $(info MR_INIT_DEVICES was not defined in device files!)
20 | endif
21 | LOCAL_SRC_FILES += ../../../../$(MR_INIT_DEVICES)
22 |
23 | # for adb
24 | LOCAL_CFLAGS += -DPRODUCT_MODEL="\"$(PRODUCT_MODEL)\"" -DPRODUCT_MANUFACTURER="\"$(PRODUCT_MANUFACTURER)\""
25 |
26 | # to find fstab
27 | LOCAL_CFLAGS += -DTARGET_DEVICE="\"$(TARGET_DEVICE)\""
28 |
29 | ifneq ($(MR_DEVICE_HOOKS),)
30 | ifeq ($(MR_DEVICE_HOOKS_VER),)
31 | $(info MR_DEVICE_HOOKS is set but MR_DEVICE_HOOKS_VER is not specified!)
32 | else
33 | LOCAL_CFLAGS += -DMR_DEVICE_HOOKS=$(MR_DEVICE_HOOKS_VER)
34 | LOCAL_SRC_FILES += ../../../../$(MR_DEVICE_HOOKS)
35 | endif
36 | endif
37 |
38 | ifeq ($(MR_ENCRYPTION),true)
39 | LOCAL_CFLAGS += -DMR_ENCRYPTION
40 | LOCAL_SRC_FILES += encryption.c
41 | endif
42 |
43 | include $(BUILD_EXECUTABLE)
44 |
--------------------------------------------------------------------------------
/trampoline/adb.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | #include "adb.h"
32 | #include "../lib/util.h"
33 | #include "../lib/log.h"
34 |
35 | static pthread_t adb_thread;
36 | static volatile int run_thread = 0;
37 | static pid_t adb_pid = -1;
38 |
39 | static char busybox_path[64] = { 0 };
40 | static char adbd_path[64] = { 0 };
41 |
42 | static char * const ENV[] = {
43 | "PATH=/sbin:/bin:/usr/bin:/usr/sbin:/mrom_bin",
44 | "LD_LIBRARY_PATH=.:/sbin",
45 | "ANDROID_ROOT=/system",
46 | "ANDROID_DATA=/data",
47 | "EXTERNAL_STORAGE=/sdcard",
48 | "ANDROID_PROPERTY_WORKSPACE=8,49152",
49 | "SHELL=/mrom_bin/sh",
50 |
51 | NULL
52 | };
53 |
54 | static void *adb_thread_work(void *mrom_path)
55 | {
56 | int enabled = adb_is_enabled((char*)mrom_path);
57 | free(mrom_path);
58 |
59 | if(enabled == 0)
60 | return NULL;
61 |
62 | adb_init_usb();
63 |
64 | if(adb_init_busybox() < 0)
65 | return NULL;
66 |
67 | adb_init_fs();
68 |
69 | chmod(adbd_path, 0755);
70 |
71 | while(run_thread)
72 | {
73 | adb_pid = fork();
74 | if(adb_pid == 0) // child
75 | {
76 | umask(077);
77 | setsid();
78 | stdio_to_null();
79 | setpgid(0, getpid());
80 |
81 | static char * const cmd[] = { adbd_path, NULL };
82 | execve(cmd[0], cmd, ENV);
83 | exit(0);
84 | }
85 | else
86 | {
87 | int status = 0;
88 | waitpid(adb_pid, &status, 0);
89 | }
90 | usleep(300000);
91 | }
92 |
93 | adb_cleanup();
94 |
95 | return NULL;
96 | }
97 |
98 | void adb_init(char *mrom_path)
99 | {
100 | if(run_thread)
101 | return;
102 |
103 | sprintf(busybox_path, "%s/busybox", mrom_path);
104 | sprintf(adbd_path, "%s/adbd", mrom_path);
105 |
106 | INFO("Starting adbd\n");
107 | run_thread = 1;
108 | pthread_create(&adb_thread, NULL, adb_thread_work, strdup(mrom_path));
109 | }
110 |
111 | void adb_quit(void)
112 | {
113 | if(!run_thread)
114 | return;
115 |
116 | INFO("Stopping adbd\n");
117 |
118 | run_thread = 0;
119 |
120 | if(adb_pid != -1)
121 | {
122 | kill(adb_pid, 9);
123 | adb_pid = -1;
124 | }
125 |
126 | pthread_join(adb_thread, NULL);
127 | }
128 |
129 | void adb_init_usb(void)
130 | {
131 | mkdir_with_perms("/dev/usb-ffs", 0770, "shell", "shell");
132 | mkdir_with_perms("/dev/usb-ffs/adb", 0770, "shell", "shell");
133 | mount("adb", "/dev/usb-ffs/adb", "functionfs", 0, "uid=2000,gid=2000");
134 |
135 | write_file("/sys/class/android_usb/android0/enable", "0");
136 |
137 | char serial[64] = { 0 };
138 | adb_get_serial(serial, sizeof(serial));
139 |
140 | // this vid and pid is used in TWRP, CWM and AOSP recovery
141 | // for all devices, so I guess it is universal
142 | write_file("/sys/class/android_usb/android0/idVendor", "18d1");
143 | write_file("/sys/class/android_usb/android0/idProduct", "d001");
144 | write_file("/sys/class/android_usb/android0/f_ffs/aliases", "adb");
145 | write_file("/sys/class/android_usb/android0/functions", "adb");
146 | write_file("/sys/class/android_usb/android0/iManufacturer", PRODUCT_MANUFACTURER);
147 | write_file("/sys/class/android_usb/android0/iProduct", PRODUCT_MODEL);
148 | write_file("/sys/class/android_usb/android0/iSerial", serial);
149 |
150 | write_file("/sys/class/android_usb/android0/enable", "1");
151 | write_file("/sys/devices/platform/android_usb/usb_function_switch", "3");
152 | }
153 |
154 | int adb_init_busybox(void)
155 | {
156 | mkdir("/mrom_bin", 0777);
157 |
158 | copy_file(busybox_path, "/mrom_bin/busybox");
159 | chmod("/mrom_bin/busybox", 0755);
160 |
161 | static const char *install_cmd[] = {
162 | "/mrom_bin/busybox", "--install", "/mrom_bin/", NULL
163 | };
164 |
165 | if(run_cmd((char**)install_cmd) != 0)
166 | {
167 | ERROR("adb: failed to --install busybox\n");
168 | return -1;
169 | }
170 |
171 | mkdir("/dev/pts", 0666);
172 | if(mount("devpts", "/dev/pts", "devpts", 0, NULL) < 0)
173 | {
174 | ERROR("Failed to mount devpts: %d (%s)\n", errno, strerror(errno));
175 | return -1;
176 | }
177 |
178 | return 0;
179 | }
180 |
181 | void adb_init_fs(void)
182 | {
183 | mkdir("/sdcard", 0777);
184 | if(strstr(adbd_path, "/realdata/media/0/multirom"))
185 | mount("/realdata/media/0/", "/sdcard/", "auto", MS_BIND, "");
186 | else
187 | mount("/realdata/media/", "/sdcard/", "auto", MS_BIND, "");
188 | }
189 |
190 | void adb_cleanup(void)
191 | {
192 | if(umount("/sdcard") >= 0)
193 | remove_dir("/sdcard");
194 |
195 | remove_dir("/mrom_bin");
196 |
197 | umount("/dev/pts");
198 | rmdir("/dev/pts");
199 |
200 | umount("/dev/usb-ffs/adb");
201 | rmdir("/dev/usb-ffs/adb");
202 | rmdir("/dev/usb-ffs");
203 | }
204 |
205 | int adb_get_serial(char *serial, int maxlen)
206 | {
207 | FILE *f = fopen("/proc/cmdline", "re");
208 | if(!f)
209 | return -1;
210 |
211 | int res = -1;
212 |
213 | char cmdline[1024];
214 | static const char *tag = "androidboot.serialno=";
215 | if(fgets(cmdline, sizeof(cmdline), f))
216 | {
217 | char *start = strstr(cmdline, tag);
218 | if(start)
219 | {
220 | start += strlen(tag);
221 | char *end = strchr(start, ' ');
222 | if(end && end-start < maxlen)
223 | {
224 | strncpy(serial, start, end-start);
225 | res = 0;
226 | }
227 | }
228 | }
229 | fclose(f);
230 | return res;
231 | }
232 |
233 | int adb_is_enabled(char *mrom_path)
234 | {
235 | char cfg[64];
236 | char *cmd[] = { busybox_path, "grep", "^enable_adb=1$", cfg, NULL };
237 | sprintf(cfg, "%s/multirom.ini", mrom_path);
238 |
239 | return run_cmd(cmd) == 0 ? 1 : 0;
240 | }
241 |
--------------------------------------------------------------------------------
/trampoline/adb.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef ADB_H
19 | #define ADB_H
20 |
21 | void adb_init(char *mrom_path);
22 | void adb_quit(void);
23 | void adb_init_usb(void);
24 | int adb_init_busybox(void);
25 | void adb_init_fs(void);
26 | void adb_cleanup(void);
27 | int adb_get_serial(char *serial, int maxlen);
28 | int adb_is_enabled(char *mrom_path);
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/trampoline/devices.h:
--------------------------------------------------------------------------------
1 | #ifndef DEVICES_H
2 | #define DEVICES_H
3 |
4 | void devices_init(void);
5 |
6 | #include
7 |
8 | extern void devices_close(void);
9 | extern void handle_device_fd(void);
10 | extern int add_dev_perms(const char *name, const char *attr,
11 | mode_t perm, unsigned int uid,
12 | unsigned int gid, unsigned short prefix);
13 | int get_device_fd(void);
14 |
15 | #endif
--------------------------------------------------------------------------------
/trampoline/encryption.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | #include "../lib/fstab.h"
28 | #include "../lib/util.h"
29 | #include "../lib/log.h"
30 | #include "encryption.h"
31 | #include "../trampoline_encmnt/encmnt_defines.h"
32 |
33 | static char encmnt_cmd_arg[64] = { 0 };
34 | static char *const encmnt_cmd[] = { "/mrom_enc/trampoline_encmnt", encmnt_cmd_arg, NULL };
35 | static char *const encmnt_envp[] = { "LD_LIBRARY_PATH=/mrom_enc/", NULL };
36 | static int g_decrypted = 0;
37 |
38 | int encryption_before_mount(struct fstab *fstab)
39 | {
40 | int exit_code = -1;
41 | char *output = NULL, *itr;
42 | int res = ENC_RES_ERR;
43 |
44 | mkdir_recursive("/system/bin", 0755);
45 | remove("/system/bin/linker");
46 | symlink("/mrom_enc/linker", "/system/bin/linker");
47 | chmod("/mrom_enc/linker", 0775);
48 | chmod("/mrom_enc/trampoline_encmnt", 0775);
49 |
50 | remove("/vendor");
51 | symlink("/mrom_enc/vendor", "/vendor");
52 |
53 | mkdir("/firmware", 0775);
54 | struct fstab_part *fwpart = fstab_find_first_by_path(fstab, "/firmware");
55 | if(fwpart && strcmp(fwpart->type, "emmc") != 0)
56 | {
57 | if(mount(fwpart->device, "/firmware", fwpart->type, fwpart->mountflags, NULL) < 0)
58 | ERROR("Mounting /firmware for encryption failed with %s\n", strerror(errno));
59 | }
60 |
61 | INFO("Running trampoline_encmnt\n");
62 |
63 | strcpy(encmnt_cmd_arg, "decrypt");
64 | output = run_get_stdout_with_exit_with_env(encmnt_cmd, &exit_code, encmnt_envp);
65 | if(exit_code != 0 || !output)
66 | {
67 | ERROR("Failed to run trampoline_encmnt, exit code %d: %s\n", exit_code, output);
68 | goto exit;
69 | }
70 |
71 | itr = output + strlen(output) - 1;
72 | while(itr >= output && isspace(*itr))
73 | *itr-- = 0;
74 |
75 | if(strcmp(output, ENCMNT_BOOT_INTERNAL_OUTPUT) == 0)
76 | {
77 | INFO("trampoline_encmnt requested to boot internal ROM.\n");
78 | res = ENC_RES_BOOT_INTERNAL;
79 | goto exit;
80 | }
81 |
82 | if(!strstartswith(output, "/dev"))
83 | {
84 | ERROR("Invalid trampoline_encmnt output: %s\n", output);
85 | goto exit;
86 | }
87 |
88 | g_decrypted = 1;
89 |
90 | struct fstab_part *datap = fstab_find_first_by_path(fstab, "/data");
91 | if(!datap)
92 | {
93 | ERROR("Failed to find /data in fstab!\n");
94 | goto exit;
95 | }
96 |
97 | INFO("Updating device %s to %s in fstab due to encryption.\n", datap->device, output);
98 | fstab_update_device(fstab, datap->device, output);
99 |
100 | res = ENC_RES_OK;
101 | exit:
102 | free(output);
103 | return res;
104 | }
105 |
106 | void encryption_destroy(void)
107 | {
108 | int res = -1;
109 | int exit_code = -1;
110 | char *output = NULL;
111 | struct stat info;
112 |
113 | if(g_decrypted)
114 | {
115 | strcpy(encmnt_cmd_arg, "remove");
116 | output = run_get_stdout_with_exit_with_env(encmnt_cmd, &exit_code, encmnt_envp);
117 | if(exit_code != 0)
118 | ERROR("Failed to run trampoline_encmnt: %s\n", output);
119 | g_decrypted = 0;
120 | free(output);
121 | }
122 |
123 | // Make sure we're removing our symlink and not ROM's linker
124 | if(lstat("/system/bin/linker", &info) >= 0 && S_ISLNK(info.st_mode))
125 | remove("/system/bin/linker");
126 | }
127 |
128 | int encryption_cleanup(void)
129 | {
130 | remove("/vendor");
131 |
132 | if(access("/firmware", R_OK) >= 0 && umount("/firmware") < 0)
133 | ERROR("encryption_cleanup: failed to unmount /firmware: %s\n", strerror(errno));
134 |
135 | rmdir("/firmware");
136 | return 0;
137 | }
138 |
--------------------------------------------------------------------------------
/trampoline/encryption.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef ENCRYPTION_H
19 | #define ENCRYPTION_H
20 |
21 | #define ENC_RES_ERR -1
22 | #define ENC_RES_OK 0
23 | #define ENC_RES_BOOT_INTERNAL 1
24 |
25 | #ifdef MR_ENCRYPTION
26 | int encryption_before_mount(struct fstab *fstab);
27 | void encryption_destroy(void);
28 | int encryption_cleanup(void);
29 | #else
30 | int encryption_before_mount(struct fstab *fstab) { return ENC_RES_OK; }
31 | void encryption_destroy(void) { }
32 | int encryption_cleanup(void) { return 0; }
33 | #endif
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/trampoline_encmnt/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH:= $(call my-dir)
2 | include $(CLEAR_VARS)
3 |
4 | LOCAL_MODULE:= trampoline_encmnt
5 | LOCAL_MODULE_TAGS := eng
6 | LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
7 | LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)
8 | LOCAL_SHARED_LIBRARIES := libcryptfslollipop libcutils
9 | LOCAL_STATIC_LIBRARIES := libmultirom_static
10 | LOCAL_WHOLE_STATIC_LIBRARIES := libm libpng libz libft2_mrom_static
11 |
12 | ifneq ($(wildcard bootable/recovery/crypto/lollipop/cryptfs.h),)
13 | mr_twrp_path := bootable/recovery
14 | else ifneq ($(wildcard bootable/recovery-twrp/crypto/lollipop/cryptfs.h),)
15 | mr_twrp_path := bootable/recovery-twrp
16 | else
17 | $(error Failed to find path to TWRP, which is required to build MultiROM with encryption support)
18 | endif
19 |
20 | LOCAL_C_INCLUDES += $(multirom_local_path) $(mr_twrp_path) $(mr_twrp_path)/crypto/scrypt/lib/crypto external/openssl/include external/boringssl/include
21 |
22 | LOCAL_SRC_FILES := \
23 | encmnt.c \
24 | pw_ui.c \
25 | ../rom_quirks.c \
26 |
27 | include $(multirom_local_path)/device_defines.mk
28 |
29 | include $(BUILD_EXECUTABLE)
30 |
--------------------------------------------------------------------------------
/trampoline_encmnt/encmnt.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | #include "../lib/log.h"
25 | #include "../lib/fstab.h"
26 | #include "../lib/framebuffer.h"
27 | #include "../lib/util.h"
28 |
29 | #include "crypto/lollipop/cryptfs.h"
30 |
31 | #include "pw_ui.h"
32 | #include "encmnt_defines.h"
33 |
34 | #define CMD_NONE 0
35 | #define CMD_DECRYPT 1
36 | #define CMD_REMOVE 2
37 | #define CMD_PWTYPE 3
38 |
39 | static int get_footer_from_opts(char *output, size_t output_size, const char *opts2)
40 | {
41 | char *r, *saveptr;
42 | char *dup = strdup(opts2);
43 | int res = -1;
44 | int i;
45 |
46 | r = strtok_r(dup, ",", &saveptr);
47 |
48 | static const char *names[] = {
49 | "encryptable=",
50 | "forceencrypt=",
51 | NULL
52 | };
53 |
54 | while(r)
55 | {
56 | for(i = 0; names[i]; ++i)
57 | {
58 | if(strstartswith(r, names[i]))
59 | {
60 | snprintf(output, output_size, "%s", r + strlen(names[i]));
61 | res = 0;
62 | goto exit;
63 | }
64 | }
65 |
66 | r = strtok_r(NULL, ",", &saveptr);
67 | }
68 |
69 | exit:
70 | free(dup);
71 | return res;
72 | }
73 |
74 | static void print_help(char *argv[]) {
75 | printf("Usage: %s COMMAND ARGUMENTS\n"
76 | "Available commands:\n"
77 | " decrypt PASSWORD - decrypt data using PASSWORD.\n"
78 | " Prints out dm block device path on success.\n"
79 | " remove - unmounts encrypted data\n"
80 | " pwtype - prints password type as integer\n",
81 | argv[0]);
82 | }
83 |
84 | static int handle_pwtype(int stdout_fd)
85 | {
86 | if(cryptfs_check_footer() < 0)
87 | {
88 | ERROR("cryptfs_check_footer failed!");
89 | return -1;
90 | }
91 |
92 | int pwtype = cryptfs_get_password_type();
93 | if(pwtype < 0)
94 | {
95 | ERROR("cryptfs_get_password_type failed!");
96 | return -1;
97 | }
98 |
99 | char buff[32];
100 | snprintf(buff, sizeof(buff), "%d\n", pwtype);
101 | write(stdout_fd, buff, strlen(buff));
102 | fsync(stdout_fd);
103 | return 0;
104 | }
105 |
106 | static int handle_decrypt(int stdout_fd, const char *password)
107 | {
108 | DIR *d;
109 | struct dirent *de;
110 | char buff[256];
111 | int res = -1;
112 | static const char *default_password = "default_password";
113 |
114 | if(cryptfs_check_footer() < 0)
115 | {
116 | ERROR("cryptfs_check_footer failed!");
117 | return -1;
118 | }
119 |
120 | int pwtype = cryptfs_get_password_type();
121 | if(pwtype < 0)
122 | {
123 | ERROR("cryptfs_get_password_type failed!");
124 | return -1;
125 | }
126 | else if (pwtype == CRYPT_TYPE_DEFAULT)
127 | password = default_password;
128 |
129 | if(password)
130 | {
131 | if(cryptfs_check_passwd(password) < 0)
132 | {
133 | ERROR("cryptfs_check_passwd failed!");
134 | return -1;
135 | }
136 | }
137 | else
138 | {
139 | switch(pw_ui_run(pwtype))
140 | {
141 | default:
142 | case ENCMNT_UIRES_ERROR:
143 | ERROR("pw_ui_run() failed!\n");
144 | return -1;
145 | case ENCMNT_UIRES_BOOT_INTERNAL:
146 | INFO("Wants to boot internal!\n");
147 | write(stdout_fd, ENCMNT_BOOT_INTERNAL_OUTPUT, strlen(ENCMNT_BOOT_INTERNAL_OUTPUT));
148 | fsync(stdout_fd);
149 | return 0;
150 | case ENCMNT_UIRES_PASS_OK:
151 | break;
152 | }
153 | }
154 |
155 | d = opendir("/dev/block/");
156 | if(!d)
157 | {
158 | ERROR("Failed to open /dev/block, wth? %s", strerror(errno));
159 | return -1;
160 | }
161 |
162 | // find the block device
163 | while((de = readdir(d)))
164 | {
165 | if(de->d_type == DT_BLK && strncmp(de->d_name, "dm-", 3) == 0)
166 | {
167 | snprintf(buff, sizeof(buff), "/dev/block/%s\n", de->d_name);
168 | INFO("Found block device %s\n", buff);
169 | write(stdout_fd, buff, strlen(buff));
170 | fsync(stdout_fd);
171 | res = 0;
172 | break;
173 | }
174 | }
175 |
176 | closedir(d);
177 | return res;
178 | }
179 |
180 | static int handle_remove(void)
181 | {
182 | if(delete_crypto_blk_dev("userdata") < 0)
183 | {
184 | ERROR("delete_crypto_blk_dev failed!");
185 | return -1;
186 | }
187 | return 0;
188 | }
189 |
190 | int main(int argc, char *argv[])
191 | {
192 | int i;
193 | int res = 1;
194 | int cmd = CMD_NONE;
195 | int stdout_fd;
196 | char footer_location[256];
197 | struct fstab *fstab;
198 | struct fstab_part *p;
199 | char *argument = NULL;
200 |
201 | klog_init();
202 |
203 | // output all messages to dmesg,
204 | // but it is possible to filter out INFO messages
205 | klog_set_level(6);
206 |
207 | mrom_set_log_tag("trampoline_encmnt");
208 | mrom_set_dir("/mrom_enc/");
209 |
210 | for(i = 1; i < argc; ++i)
211 | {
212 | if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
213 | {
214 | print_help(argv);
215 | return 0;
216 | }
217 | else if(cmd == CMD_NONE)
218 | {
219 | if(strcmp(argv[i], "decrypt") == 0)
220 | cmd = CMD_DECRYPT;
221 | else if(strcmp(argv[i], "remove") == 0)
222 | cmd = CMD_REMOVE;
223 | else if(strcmp(argv[i], "pwtype") == 0)
224 | cmd = CMD_PWTYPE;
225 | }
226 | else if(!argument)
227 | {
228 | argument = argv[i];
229 | }
230 | }
231 |
232 | if(argc == 1 || cmd == CMD_NONE)
233 | {
234 | print_help(argv);
235 | return 0;
236 | }
237 |
238 | fstab = fstab_auto_load();
239 | if(!fstab)
240 | {
241 | ERROR("Failed to load fstab!");
242 | return 1;
243 | }
244 |
245 | p = fstab_find_first_by_path(fstab, "/data");
246 | if(!p)
247 | {
248 | ERROR("Failed to find /data partition in fstab\n");
249 | goto exit;
250 | }
251 |
252 | if(get_footer_from_opts(footer_location, sizeof(footer_location), p->options2) < 0)
253 | goto exit;
254 |
255 | INFO("Setting encrypted partition data to %s %s %s\n", p->device, footer_location, p->type);
256 | set_partition_data(p->device, footer_location, p->type);
257 |
258 | // cryptfs prints informations, we don't want that
259 | stdout_fd = dup(1);
260 | freopen("/dev/null", "ae", stdout);
261 |
262 | switch(cmd)
263 | {
264 | case CMD_PWTYPE:
265 | if(handle_pwtype(stdout_fd) < 0)
266 | goto exit;
267 | break;
268 | case CMD_DECRYPT:
269 | if(handle_decrypt(stdout_fd, argument) < 0)
270 | goto exit;
271 | break;
272 | case CMD_REMOVE:
273 | if(handle_remove() < 0)
274 | goto exit;
275 | break;
276 | }
277 |
278 | res = 0;
279 | exit:
280 | fstab_destroy(fstab);
281 | return res;
282 | }
283 |
--------------------------------------------------------------------------------
/trampoline_encmnt/encmnt_defines.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef ENCMNT_DEFINES_H
19 | #define ENCMNT_DEFINES_H
20 |
21 | #define ENCMNT_BOOT_INTERNAL_OUTPUT "boot-internal-requested"
22 |
23 | #define ENCMNT_UIRES_BOOT_INTERNAL 1
24 | #define ENCMNT_UIRES_PASS_OK 0
25 | #define ENCMNT_UIRES_ERROR -1
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/trampoline_encmnt/pw_ui.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef PW_UI_H
19 | #define PW_UI_H
20 |
21 | int pw_ui_run(int pwtype);
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of MultiROM.
3 | *
4 | * MultiROM is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * MultiROM is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with MultiROM. If not, see .
16 | */
17 |
18 | #ifndef VERSION_H
19 | #define VERSION_H
20 | #define VERSION_MULTIROM 33
21 | #define VERSION_TRAMPOLINE 27
22 |
23 | // For device-specific fixes. Use letters, the version will then be like "12a"
24 | #define VERSION_DEV_FIX ""
25 | #endif
26 |
--------------------------------------------------------------------------------