mirror of
				https://github.com/meizu-m86/twrp_multirom_m86
				synced 2025-11-04 06:15:41 +08:00 
			
		
		
		
	Implementing separate DTB support & other PRO5 specific fixes
This commit is contained in:
		@@ -548,9 +548,12 @@ bool MultiROM::initBackup(const std::string& name)
 | 
			
		||||
 | 
			
		||||
	std::string boot = getRomsPath() + name;
 | 
			
		||||
	normalizeROMPath(boot);
 | 
			
		||||
        std::string dtb = boot;
 | 
			
		||||
        dtb += "/dtb.img";
 | 
			
		||||
	boot += "/boot.img";
 | 
			
		||||
 | 
			
		||||
	translateToRealdata(boot);
 | 
			
		||||
	translateToRealdata(dtb);
 | 
			
		||||
 | 
			
		||||
	if(!fakeBootPartition(boot.c_str()))
 | 
			
		||||
	{
 | 
			
		||||
@@ -558,6 +561,12 @@ bool MultiROM::initBackup(const std::string& name)
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if(!fakeDTBPartition(dtb.c_str()))
 | 
			
		||||
	{
 | 
			
		||||
		restoreMounts();
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	PartitionManager.Update_System_Details();
 | 
			
		||||
 | 
			
		||||
	if(hadInternalStorage)
 | 
			
		||||
@@ -587,6 +596,7 @@ void MultiROM::deinitBackup()
 | 
			
		||||
	bool hadInternalStorage = (DataManager::GetStrValue("tw_storage_path").find(REALDATA) == 0);
 | 
			
		||||
 | 
			
		||||
	restoreBootPartition();
 | 
			
		||||
	restoreDTBPartition();
 | 
			
		||||
	restoreMounts();
 | 
			
		||||
 | 
			
		||||
	DataManager::SetValue("multirom_do_backup", 0);
 | 
			
		||||
@@ -980,6 +990,8 @@ void MultiROM::restoreMounts()
 | 
			
		||||
		"    i=$(( $i + 1 ));"
 | 
			
		||||
		"done;");
 | 
			
		||||
 | 
			
		||||
	system("/sbin/umount_all");
 | 
			
		||||
 | 
			
		||||
	// script might have mounted it several times over, we _have_ to umount it all
 | 
			
		||||
	system("sync;"
 | 
			
		||||
		"i=0;"
 | 
			
		||||
@@ -1199,7 +1211,7 @@ bool MultiROM::flashZip(std::string rom, std::string file)
 | 
			
		||||
	int sideloaded = 0;
 | 
			
		||||
	bool restore_script = false;
 | 
			
		||||
	EdifyHacker hacker;
 | 
			
		||||
	std::string boot, sysimg, loop_device;
 | 
			
		||||
	std::string boot, dtb, sysimg, loop_device;
 | 
			
		||||
	TWPartition *data, *sys;
 | 
			
		||||
 | 
			
		||||
	gui_print("Flashing ZIP file %s\n", file.c_str());
 | 
			
		||||
@@ -1223,14 +1235,20 @@ bool MultiROM::flashZip(std::string rom, std::string file)
 | 
			
		||||
 | 
			
		||||
	boot = getRomsPath() + rom;
 | 
			
		||||
	normalizeROMPath(boot);
 | 
			
		||||
        dtb = boot;
 | 
			
		||||
        dtb += "/dtb.img";
 | 
			
		||||
	boot += "/boot.img";
 | 
			
		||||
 | 
			
		||||
	translateToRealdata(file);
 | 
			
		||||
	translateToRealdata(boot);
 | 
			
		||||
	translateToRealdata(dtb);
 | 
			
		||||
 | 
			
		||||
	if(!fakeBootPartition(boot.c_str()))
 | 
			
		||||
		goto exit;
 | 
			
		||||
 | 
			
		||||
	if(!fakeDTBPartition(dtb.c_str()))
 | 
			
		||||
		goto exit;
 | 
			
		||||
 | 
			
		||||
	if(hacker.getProcessFlags() & EDIFY_BLOCK_UPDATES)
 | 
			
		||||
	{
 | 
			
		||||
		gui_print("ZIP uses block updates\n");
 | 
			
		||||
@@ -1274,6 +1292,7 @@ exit:
 | 
			
		||||
		gui_print("ZIP successfully installed\n");
 | 
			
		||||
 | 
			
		||||
	restoreBootPartition();
 | 
			
		||||
	restoreDTBPartition();
 | 
			
		||||
	restoreMounts();
 | 
			
		||||
 | 
			
		||||
	sideloaded = DataManager::GetIntValue("tw_mrom_sideloaded");
 | 
			
		||||
@@ -1779,9 +1798,9 @@ bool MultiROM::createImage(const std::string& base, const char *img, int size)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	char cmd[256];
 | 
			
		||||
 | 
			
		||||
//KEK
 | 
			
		||||
	// make_ext4fs errors out if it has unknown path
 | 
			
		||||
	if(TWFunc::Path_Exists("/file_contexts") &&
 | 
			
		||||
	if(TWFunc::Path_Exists("/ffile_contexts") &&
 | 
			
		||||
		(!strcmp(img, "data") ||
 | 
			
		||||
		 !strcmp(img, "system") ||
 | 
			
		||||
		 !strcmp(img, "cache"))) {
 | 
			
		||||
@@ -1917,7 +1936,7 @@ bool MultiROM::extractBootForROM(std::string base)
 | 
			
		||||
	char path[256];
 | 
			
		||||
	struct bootimg img;
 | 
			
		||||
 | 
			
		||||
	gui_print("Extracting contents of boot.img...\n");
 | 
			
		||||
	gui_print("Extracting contents of boot.img...%s\n",(base + "/boot.img").c_str());
 | 
			
		||||
	if(libbootimg_init_load(&img, (base + "/boot.img").c_str(), LIBBOOTIMG_LOAD_RAMDISK) < 0)
 | 
			
		||||
	{
 | 
			
		||||
		gui_print("Failed to load bootimg!\n");
 | 
			
		||||
@@ -2889,6 +2908,39 @@ bool MultiROM::fakeBootPartition(const char *fakeImg)
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool MultiROM::fakeDTBPartition(const char *fakeImg)
 | 
			
		||||
{
 | 
			
		||||
        std::string dtb_dev = MR_DTB_DEV;
 | 
			
		||||
	if(access((dtb_dev + "-orig").c_str(), F_OK) >= 0)
 | 
			
		||||
	{
 | 
			
		||||
		gui_print("Failed to fake dtb partition, %s-orig already exists!\n", MR_DTB_DEV);
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if(access(fakeImg, F_OK) < 0)
 | 
			
		||||
	{
 | 
			
		||||
		int fd = creat(fakeImg, 0644);
 | 
			
		||||
		if(fd < 0)
 | 
			
		||||
		{
 | 
			
		||||
			gui_print("Failed to create fake dtb image file %s (%s)!\n", fakeImg, strerror(errno));
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		close(fd);
 | 
			
		||||
 | 
			
		||||
		system_args("dd if=/dev/zero of=\"%s\" count=37 bs=4096", fakeImg);
 | 
			
		||||
		gui_print("Creating empty dtb.img\n");
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	system_args("echo '%s' > /tmp/mrom_fakedtbpart", dtb_dev.c_str());
 | 
			
		||||
	system_args("mv \"%s\" \"%s-orig\"", dtb_dev.c_str(), dtb_dev.c_str());
 | 
			
		||||
	system_args("ln -s \"%s\" \"%s\"", fakeImg, dtb_dev.c_str());
 | 
			
		||||
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MultiROM::restoreBootPartition()
 | 
			
		||||
{
 | 
			
		||||
#ifdef BOARD_BOOTIMAGE_PARTITION_SIZE
 | 
			
		||||
@@ -2919,6 +2971,20 @@ void MultiROM::restoreBootPartition()
 | 
			
		||||
	remove("/tmp/mrom_fakebootpart");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MultiROM::restoreDTBPartition()
 | 
			
		||||
{
 | 
			
		||||
        std::string m_dtb_dev = MR_DTB_DEV;
 | 
			
		||||
	if(access((m_dtb_dev + "-orig").c_str(), F_OK) < 0)
 | 
			
		||||
	{
 | 
			
		||||
		gui_print("Failed to restore dtb partition, %s-orig does not exist!\n", m_dtb_dev.c_str());
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	system_args("rm \"%s\"", m_dtb_dev.c_str());
 | 
			
		||||
	system_args("mv \"%s\"-orig \"%s\"", m_dtb_dev.c_str(), m_dtb_dev.c_str());
 | 
			
		||||
	remove("/tmp/mrom_fakedtbpart");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MultiROM::failsafeCheckPartition(const char *path)
 | 
			
		||||
{
 | 
			
		||||
	std::string dev;
 | 
			
		||||
 
 | 
			
		||||
@@ -180,7 +180,9 @@ public:
 | 
			
		||||
	static bool patchInit(std::string name);
 | 
			
		||||
	static bool disableFlashKernelAct(std::string name, std::string loc);
 | 
			
		||||
	static bool fakeBootPartition(const char *fakeImg);
 | 
			
		||||
	static bool fakeDTBPartition(const char *fakeImg);
 | 
			
		||||
	static void restoreBootPartition();
 | 
			
		||||
	static void restoreDTBPartition();
 | 
			
		||||
	static void failsafeCheckPartition(const char *path);
 | 
			
		||||
	static bool compareFiles(const char *path1, const char *path2);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -220,7 +220,7 @@ int EdifyFunc::replaceOffendings(std::list<EdifyElement*> **parentList, std::lis
 | 
			
		||||
 | 
			
		||||
        static const char * const forbidden_images[] = {
 | 
			
		||||
            "radio", "bootloader", "NON-HLOS.bin", "emmc_appsboot.mbn",
 | 
			
		||||
            "rpm.mbn", "logo.bin", "sdi.mbn", "tz.mbn", "sbl1.mbn",
 | 
			
		||||
            "rpm.mbn", "logo.bin", "sdi.mbn", "tz.mbn", "sbl1.mbn", "ldfw","recovery.img",
 | 
			
		||||
            NULL
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user