Skip to content

Commit

Permalink
Generate extra userdata partition if needed
Browse files Browse the repository at this point in the history
* To support variants of devices which may come in 16/32/64GB variants.

Change-Id: I74c32d8316f0450a1445fe95a95e5cabb7a9dd1b
(cherry picked from commit ab46c15)
  • Loading branch information
intervigilium authored and Brint E. Kriebel committed Jun 6, 2014
1 parent 1510a8e commit cb92821
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ define generate-userimage-prop-dictionary
$(if $(INTERNAL_USERIMAGES_EXT_VARIANT),$(hide) echo "fs_type=$(INTERNAL_USERIMAGES_EXT_VARIANT)" >> $(1))
$(if $(BOARD_SYSTEMIMAGE_PARTITION_SIZE),$(hide) echo "system_size=$(BOARD_SYSTEMIMAGE_PARTITION_SIZE)" >> $(1))
$(if $(BOARD_USERDATAIMAGE_PARTITION_SIZE),$(hide) echo "userdata_size=$(BOARD_USERDATAIMAGE_PARTITION_SIZE)" >> $(1))
$(if $(BOARD_USERDATAEXTRAIMAGE_PARTITION_SIZE),$(hide) echo "userdataextra_size=$(BOARD_USERDATAEXTRAIMAGE_PARTITION_SIZE)" >> $(1))
$(if $(BOARD_USERDATAEXTRAIMAGE_PARTITION_NAME),$(hide) echo "userdataextra_name=$(BOARD_USERDATAEXTRAIMAGE_PARTITION_NAME)" >> $(1))
$(if $(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "cache_fs_type=$(BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
$(if $(BOARD_CACHEIMAGE_PARTITION_SIZE),$(hide) echo "cache_size=$(BOARD_CACHEIMAGE_PARTITION_SIZE)" >> $(1))
$(if $(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE),$(hide) echo "vendor_fs_type=$(BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE)" >> $(1))
Expand Down
29 changes: 29 additions & 0 deletions core/generate_extra_images.mk
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,35 @@ ALL_MODULES.$(LOCAL_MODULE).INSTALLED += $(INSTALLED_1G_USERDATAIMAGE_TARGET)
endif


#----------------------------------------------------------------------
# Generate extra userdata images (for variants with multiple mmc sizes)
#----------------------------------------------------------------------
ifneq ($(BOARD_USERDATAEXTRAIMAGE_PARTITION_SIZE),)

ifndef BOARD_USERDATAEXTRAIMAGE_PARTITION_NAME
BOARD_USERDATAEXTRAIMAGE_PARTITION_NAME := extra
endif

BUILT_USERDATAEXTRAIMAGE_TARGET := $(PRODUCT_OUT)/userdata_$(BOARD_USERDATAEXTRAIMAGE_PARTITION_NAME).img

define build-userdataextraimage-target
$(call pretty,"Target EXTRA userdata fs image: $(INSTALLED_USERDATAEXTRAIMAGE_TARGET)")
@mkdir -p $(TARGET_OUT_DATA)
$(hide) $(MKEXTUSERIMG) -s $(TARGET_OUT_DATA) $@ ext4 data $(BOARD_USERDATAEXTRAIMAGE_PARTITION_SIZE)
$(hide) chmod a+r $@
$(hide) $(call assert-max-image-size,$@,$(BOARD_USERDATAEXTRAIMAGE_PARTITION_SIZE),yaffs)
endef

INSTALLED_USERDATAEXTRAIMAGE_TARGET := $(BUILT_USERDATAEXTRAIMAGE_TARGET)
$(INSTALLED_USERDATAEXTRAIMAGE_TARGET): $(INSTALLED_USERDATAIMAGE_TARGET)
$(build-userdataextraimage-target)

ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_USERDATAEXTRAIMAGE_TARGET)
ALL_MODULES.$(LOCAL_MODULE).INSTALLED += $(INSTALLED_USERDATAEXTRAIMAGE_TARGET)

endif


#----------------------------------------------------------------------
# Generate NAND images
#----------------------------------------------------------------------
Expand Down
13 changes: 11 additions & 2 deletions tools/releasetools/build_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ def BuildImage(in_dir, prop_dict, out_file):
if "extfs_sparse_flag" in prop_dict:
build_command.append(prop_dict["extfs_sparse_flag"])
#run_fsck = True
build_command.extend([in_dir, out_file, fs_type,
prop_dict["mount_point"]])
if "is_userdataextra" in prop_dict:
build_command.extend([in_dir, out_file, fs_type,
"data"])
else:
build_command.extend([in_dir, out_file, fs_type,
prop_dict["mount_point"]])
if "partition_size" in prop_dict:
build_command.append(prop_dict["partition_size"])
if "selinux_fc" in prop_dict:
Expand Down Expand Up @@ -125,6 +129,11 @@ def copy_prop(src_p, dest_p):
elif mount_point == "data":
copy_prop("fs_type", "fs_type")
copy_prop("userdata_size", "partition_size")
elif mount_point == "data_extra":
copy_prop("fs_type", "fs_type")
copy_prop("userdataextra_size", "partition_size")
copy_prop("userdataextra_name", "partition_name")
d["is_userdataextra"] = True
elif mount_point == "cache":
copy_prop("cache_fs_type", "fs_type")
copy_prop("cache_size", "partition_size")
Expand Down
1 change: 1 addition & 0 deletions tools/releasetools/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ def CheckSize(data, target, info_dict):
mount_point = "/" + target

if info_dict["fstab"]:
if mount_point == "/userdata_extra": mount_point = "/data"
if mount_point == "/userdata": mount_point = "/data"
p = info_dict["fstab"][mount_point]
fs_type = p.fs_type
Expand Down
37 changes: 37 additions & 0 deletions tools/releasetools/img_from_target_files
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,42 @@ def AddUserdata(output_zip):
os.rmdir(temp_dir)


def AddUserdataExtra(output_zip):
"""Create extra userdata image and store it in output_zip."""

image_props = build_image.ImagePropFromGlobalDict(OPTIONS.info_dict,
"data_extra")
# If no userdataextra_size is provided for extfs, skip userdata_extra.img.
if (image_props.get("fs_type", "").startswith("ext") and
not image_props.get("partition_size")):
return

extra_name = image_props.get("partition_name", "extra")

print "creating userdata_%s.img..." % extra_name

# The name of the directory it is making an image out of matters to
# mkyaffs2image. So we create a temp dir, and within it we create an
# empty dir named "data", and build the image from that.
temp_dir = tempfile.mkdtemp()
user_dir = os.path.join(temp_dir, "data")
os.mkdir(user_dir)
img = tempfile.NamedTemporaryFile()

fstab = OPTIONS.info_dict["fstab"]
if fstab:
image_props["fs_type" ] = fstab["/data"].fs_type
succ = build_image.BuildImage(user_dir, image_props, img.name)
assert succ, "build userdata_%s.img image failed" % extra_name

# Disable size check since this fetches original data partition size
#common.CheckSize(img.name, "userdata_extra.img", OPTIONS.info_dict)
output_zip.write(img.name, "userdata_%s.img" % extra_name)
img.close()
os.rmdir(user_dir)
os.rmdir(temp_dir)


def AddCache(output_zip):
"""Create an empty cache image and store it in output_zip."""

Expand Down Expand Up @@ -273,6 +309,7 @@ def main(argv):
AddSystem(output_zip)
AddVendor(output_zip)
AddUserdata(output_zip)
AddUserdataExtra(output_zip)
AddCache(output_zip)
CopyInfo(output_zip)
AddRadio(output_zip)
Expand Down

0 comments on commit cb92821

Please sign in to comment.