Skip to content
This repository was archived by the owner on Nov 23, 2022. It is now read-only.

Commit

Permalink
allow flashing sparse images
Browse files Browse the repository at this point in the history
if the image has the right magic bytes to be a sparse image,
use simg2img to flash the image

create a rule to make a fully dynamic simg2img which results in a
much smaller increase in gzip ramdisk size (2KB vs 40KB)

Change-Id: I1b0f6bc127da46103888b1154a9bddd8ac02c01d
  • Loading branch information
HashBang173 authored and Dees-Troy committed Feb 3, 2016
1 parent cac6ace commit ed974bb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ LOCAL_C_INCLUDES += \
system/vold \
system/extras/ext4_utils \
system/core/adb \
system/core/libsparse

LOCAL_C_INCLUDES += bionic external/openssl/include $(LOCAL_PATH)/libmincrypt/includes
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 23; echo $$?),0)
Expand Down Expand Up @@ -351,7 +352,8 @@ LOCAL_ADDITIONAL_DEPENDENCIES := \
fsck.fat \
fatlabel \
mkfs.fat \
permissive.sh
permissive.sh \
simg2img_twrp

ifneq ($(TARGET_ARCH), arm64)
ifneq ($(TARGET_ARCH), x86_64)
Expand Down Expand Up @@ -586,6 +588,7 @@ include $(commands_recovery_local_path)/injecttwrp/Android.mk \
$(commands_recovery_local_path)/dosfstools/Android.mk \
$(commands_recovery_local_path)/etc/Android.mk \
$(commands_recovery_local_path)/toybox/Android.mk \
$(commands_recovery_local_path)/simg2img/Android.mk \
$(commands_recovery_local_path)/libpixelflinger/Android.mk

ifeq ($(TW_INCLUDE_CRYPTO), true)
Expand Down
24 changes: 21 additions & 3 deletions partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extern "C" {
#include <sys/xattr.h>
#include <linux/xattr.h>
#endif
#include <sparse_format.h>

using namespace std;

Expand Down Expand Up @@ -407,12 +408,12 @@ bool TWPartition::Process_Fstab_Line(string Line, bool Display_Error) {
} else if (Mount_Point == "/system_image") {
Display_Name = "System Image";
Backup_Display_Name = Display_Name;
Can_Flash_Img = false;
Can_Flash_Img = true;
Can_Be_Backed_Up = true;
} else if (Mount_Point == "/vendor_image") {
Display_Name = "Vendor Image";
Backup_Display_Name = Display_Name;
Can_Flash_Img = false;
Can_Flash_Img = true;
Can_Be_Backed_Up = true;
}
}
Expand Down Expand Up @@ -2375,7 +2376,24 @@ bool TWPartition::Flash_Image_DD(string Filename) {
string Command;

gui_msg(Msg("flashing=Flashing {1}...")(Display_Name));
Command = "dd bs=8388608 if='" + Filename + "' of=" + Actual_Block_Device;

uint32_t magic = 0;
int fd = open(Filename.c_str(), O_RDONLY);
if (fd < 0) {
gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(Filename)(strerror(errno)));
return false;
}
if (read(fd, &magic, sizeof(magic)) != sizeof(magic)) {
gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(Filename)(strerror(errno)));
close(fd);
return false;
}
close(fd);
if (magic == SPARSE_HEADER_MAGIC) {
Command = "simg2img '" + Filename + "' " + Actual_Block_Device;
} else {
Command = "dd bs=8388608 if='" + Filename + "' of=" + Actual_Block_Device;
}
LOGINFO("Flash command: '%s'\n", Command.c_str());
TWFunc::Exec_Cmd(Command);
return true;
Expand Down
1 change: 1 addition & 0 deletions prebuilt/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/e2fsck
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/mke2fs
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/tune2fs
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/resize2fs
RELINK_SOURCE_FILES += $(TARGET_RECOVERY_ROOT_OUT)/sbin/simg2img
ifneq ($(TARGET_ARCH), x86_64)
RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/linker
endif
Expand Down
14 changes: 14 additions & 0 deletions simg2img/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
LOCAL_PATH := system/core/libsparse

include $(CLEAR_VARS)
LOCAL_SRC_FILES := simg2img.c \
sparse_crc32.c
LOCAL_MODULE := simg2img_twrp
LOCAL_MODULE_STEM := simg2img
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := \
libsparse \
libz
LOCAL_CFLAGS := -Werror
include $(BUILD_EXECUTABLE)

0 comments on commit ed974bb

Please sign in to comment.