Jump to content


Photo

Vu+ 4K Multiboot


  • Please log in to reply
592 replies to this topic

Re: Vu+ 4K Multiboot #581 rantanplan

  • PLi® Contributor
  • 1,860 posts

+87
Good

Posted 18 June 2023 - 23:09

@Huevos

peace



Re: Vu+ 4K Multiboot #582 longtimeuser

  • Member
  • 10 posts

+1
Neutral

Posted 22 March 2024 - 16:47

VU+ Ultimo 4K

BPanther's Neutrino Image rev20570

openpli 9.0

...

 

==> crash on "Multiboot Image Auswahl" (Auswahl=selection)

due to missing file "/sys/firmware/devicetree/base/chosen/bootargs"

 

my first approach: providing this file via own intit.d/multiboot.sh script (extract data from STARTUP on boot partition /dev/mmcblk0p1 to file and mount --bind new /sys/firmware structure)

result: no crash, but missing and incomplete entries in multiboot select screen.

 

my second approach: adapt "/usr/lib/enigma2/python/Tools/Multiboot.py" accordingly

 

here we go: (original source taken from here: h**ps://gitlab.openpli.org/openpli/enigma2/-/blob/release-9.0/lib/python/Tools/Multiboot.py

from Components.SystemInfo import SystemInfo
from Components.Console import Console
from Tools.Directories import fileHas, fileExists
import os
import glob
import tempfile
import subprocess


class tmp:
	dir = None

bootargs = ""


def getMultibootStartupDevice():
	global bootargs
	tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
	if SystemInfo["hasKexec"]: # kexec kernel multiboot
		bootList = ("/dev/mmcblk0p4", "/dev/mmcblk0p7", "/dev/mmcblk0p9")
	else: #legacy multiboot
		bootList = ("/dev/mmcblk0p1", "/dev/mmcblk1p1", "/dev/mmcblk0p3", "/dev/mmcblk0p4", "/dev/mtdblock2", "/dev/block/by-name/bootoptions")
	for device in bootList:
		if os.path.exists(device):
			if os.path.exists("/dev/block/by-name/flag"):
				Console().ePopen('mount --bind %s %s' % (device, tmp.dir))
			else:
				Console().ePopen('mount %s %s' % (device, tmp.dir))
			if os.path.isfile(os.path.join(tmp.dir, "STARTUP")):
				print('[Multiboot] Startupdevice found:', device)
				bootargs = open(os.path.join(tmp.dir, "STARTUP"), 'r').read().split("'")[1]
				print('[Multiboot] bootargs:', bootargs)
				return device
			Console().ePopen('umount %s' % tmp.dir)
	if not os.path.ismount(tmp.dir):
		os.rmdir(tmp.dir)


def getparam(line, param):
	return line.replace("userdataroot", "rootuserdata").rsplit('%s=' % param, 1)[1].split(' ', 1)[0]


def getMultibootslots():
	bootslots = {}
	mode12found = False
	if SystemInfo["MultibootStartupDevice"]:
		for file in glob.glob(os.path.join(tmp.dir, 'STARTUP_*')):
			if 'MODE_' in file:
				mode12found = True
				slotnumber = file.rsplit('_', 3)[1]
			else:
				slotnumber = file.rsplit('_', 1)[1]
			if slotnumber.isdigit() and slotnumber not in bootslots:
				slot = {}
				for line in open(file).readlines():
					if 'root=' in line:
						device = getparam(line, 'root')
						if "UUID=" in device:
							slotx = str(getUUIDtoSD(device))
							if slotx is not None:
								device = slotx
						if os.path.exists(device) or device == 'ubi0:ubifs':
							slot['device'] = device
							slot['startupfile'] = os.path.basename(file)
							if 'rootsubdir' in line:
								slot['rootsubdir'] = getparam(line, 'rootsubdir')
						break
				if slot:
					bootslots[int(slotnumber)] = slot
		Console().ePopen('umount %s' % tmp.dir)
		if not os.path.ismount(tmp.dir):
			os.rmdir(tmp.dir)
		if not mode12found and SystemInfo["canMode12"]:
			#the boot device has ancient content and does not contain the correct STARTUP files
			for slot in range(1, 5):
				bootslots[slot] = {'device': '/dev/mmcblk0p%s' % (slot * 2 + 1), 'startupfile': None}
	print('[Multiboot] Bootslots found:', bootslots)
	return bootslots


def getBootargs():
	if os.path.isfile('/sys/firmware/devicetree/base/chosen/bootargs'):
		return open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read()
	else:
		if bootargs == "":
			getMultibootStartupDevice()
		return bootargs


def getCurrentImage():
	if SystemInfo["canMultiBoot"]:
		if SystemInfo["hasKexec"]:	# kexec kernel multiboot
			rootsubdir = [x for x in getBootargs().split() if x.startswith("rootsubdir")]
			char = "/" if "/" in rootsubdir[0] else "="
			return int(rootsubdir[0].rsplit(char, 1)[1][11:])
		else: #legacy multiboot
			slot = [x[-1] for x in getBootargs().split() if x.startswith('rootsubdir')]
			if slot:
				return int(slot[0])
			else:
				device = getparam(getBootargs(), 'root')
				for slot in SystemInfo["canMultiBoot"].keys():
					if SystemInfo["canMultiBoot"][slot]['device'] == device:
						return slot


def getCurrentImageMode():
	return bool(SystemInfo["canMultiBoot"]) and SystemInfo["canMode12"] and int(getBootargs().replace('\0', '').split('=')[-1])


def deleteImage(slot):
	tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
	Console().ePopen('mount %s %s' % (SystemInfo["canMultiBoot"][slot]['device'], tmp.dir))
	enigma2binaryfile = os.path.join(os.sep.join(filter(None, [tmp.dir, SystemInfo["canMultiBoot"][slot].get('rootsubdir', '')])), 'usr/bin/enigma2')
	if os.path.exists(enigma2binaryfile):
		os.rename(enigma2binaryfile, '%s.bak' % enigma2binaryfile)
	Console().ePopen('umount %s' % tmp.dir)
	if not os.path.ismount(tmp.dir):
		os.rmdir(tmp.dir)


def restoreImages():
	for slot in SystemInfo["canMultiBoot"]:
		tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
		Console().ePopen('mount %s %s' % (SystemInfo["canMultiBoot"][slot]['device'], tmp.dir))
		enigma2binaryfile = os.path.join(os.sep.join(filter(None, [tmp.dir, SystemInfo["canMultiBoot"][slot].get('rootsubdir', '')])), 'usr/bin/enigma2')
		if os.path.exists('%s.bak' % enigma2binaryfile):
			os.rename('%s.bak' % enigma2binaryfile, enigma2binaryfile)
		Console().ePopen('umount %s' % tmp.dir)
		if not os.path.ismount(tmp.dir):
			os.rmdir(tmp.dir)


def getUUIDtoSD(UUID): # returns None on failure
	check = "/sbin/blkid"
	if fileExists(check):
		lines = subprocess.check_output([check]).decode(encoding="utf8", errors="ignore").split("\n")
		for line in lines:
			if UUID in line.replace('"', ''):
				return line.split(":")[0].strip()
	else:
		return None


def getImagelist():
	imagelist = {}
	if SystemInfo["canMultiBoot"]:
		tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
		for slot in sorted(SystemInfo["canMultiBoot"].keys()):
			if SystemInfo["canMultiBoot"][slot]['device'] == 'ubi0:ubifs':
				Console().ePopen('mount -t ubifs %s %s' % (SystemInfo["canMultiBoot"][slot]['device'], tmp.dir))
			else:
				Console().ePopen('mount %s %s' % (SystemInfo["canMultiBoot"][slot]['device'], tmp.dir))
			imagedir = os.sep.join(filter(None, [tmp.dir, SystemInfo["canMultiBoot"][slot].get('rootsubdir', '')]))
			if os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2')):
				try:
					from datetime import datetime
					date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "var/lib/opkg/status")).st_mtime).strftime('%Y-%m-%d')
					if date.startswith("1970"):
						date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/share/bootlogo.mvi")).st_mtime).strftime('%Y-%m-%d')
					date = max(date, datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/enigma2")).st_mtime).strftime('%Y-%m-%d'))
				except:
					date = _("Unknown")
				imagename = open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6]
				if imagename == "" and os.path.isfile(os.path.join(imagedir, 'etc/image-version')):
					imagename = open(os.path.join(imagedir, "etc/issue")).readlines()[0].capitalize().strip()
					imageversion = {}
					with open(os.path.join(imagedir, 'etc/image-version')) as ivfile:
						for line in ivfile:
							key, val = line.partition("=")[::2]
							imageversion[key.strip()] = val.replace("\n", "")
					imagename = imageversion["creator"].split(" ")[0]+" "+str(int(imageversion["version"][0:3]))+"."+str(int(imageversion["version"][3:6]))
				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/neutrino')):
				try:
					from datetime import datetime
					date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/neutrino")).st_mtime).strftime('%Y-%m-%d')
				except:
					date = _("Unknown")
				imageversion = {}
				with open(os.path.join(imagedir, 'usr/lib/enigma.info')) as ivfile:
					for line in ivfile:
						key, val = line.partition("=")[::2]
						imageversion[key.strip()] = val.replace("\n", "")
				imagename = imageversion["displaydistro"].replace("-Neutrino", "") + " " + imageversion["imgversion"]
				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2.bak')):
				imagelist[slot] = {'imagename': _("Deleted image")}
			else:
				imagelist[slot] = {'imagename': _("Empty slot")}
			Console().ePopen('umount %s' % tmp.dir)
		if not os.path.ismount(tmp.dir):
			os.rmdir(tmp.dir)
	return imagelist

result: p2_s.jpg?rlkey=ltn5aa8tasrf37c1w2h4psg18 h**ps://www.dropbox.com/scl/fi/1jvi44vy6azi0kiultoqe/p2_s.jpg?rlkey=ltn5aa8tasrf37c1w2h4psg18&dl=0

 

feel free to include my changes in future releases... ;)



Re: Vu+ 4K Multiboot #583 WanWizard

  • PLi® Core member
  • 70,506 posts

+1,810
Excellent

Posted 22 March 2024 - 19:00

Release code is never the latest code, so shouldn't be taken as a starting point, always use the develop branch.

 

Also, if you post a suggested update, post a (git) diff, so we can actually see what is changed. Or send us a Pull Request on github, so it can be merged if accepted, and is attributed to you.


Currently in use: VU+ Duo 4K (2xFBC S2), VU+ Solo 4K (1xFBC S2), uClan Usytm 4K Ultimate (S2+T2), Octagon SF8008 (S2+T2), Zgemma H9.2H (S2+T2)

Due to my bad health, I will not be very active at times and may be slow to respond. I will not read the forum or PM on a regular basis.

Many answers to your question can be found in our new and improved wiki.


Re: Vu+ 4K Multiboot #584 longtimeuser

  • Member
  • 10 posts

+1
Neutral

Posted 22 March 2024 - 20:14

@WanWizard

 

here is the diff to the current develop branch:

12a13,14
> bootargs = ""
> 
27a30,31
> 				bootargs = open(os.path.join(tmp.dir, "STARTUP"), 'r').read().split("'")[1]
> 				print('[Multiboot] bootargs:', bootargs)
75a80,88
> def getBootargs():
> 	if os.path.isfile('/sys/firmware/devicetree/base/chosen/bootargs'):
> 		return open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read()
> 	else:
> 		if bootargs == "":
> 			getMultibootStartupDevice()
> 		return bootargs
> 
> 
79c92
< 			rootsubdir = [x for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith("rootsubdir")]
---
> 			rootsubdir = [x for x in getBootargs().split() if x.startswith("rootsubdir")]
83c96
< 			slot = [x[-1] for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith('rootsubdir')]
---
> 			slot = [x[-1] for x in getBootargs().split() if x.startswith('rootsubdir')]
87c100
< 				device = getparam(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read(), 'root')
---
> 				device = getparam(getBootargs(), 'root')
94c107
< 	return bool(BoxInfo.getItem("canMultiBoot")) and BoxInfo.getItem("canMode12") and int(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().replace('\0', '').split('=')[-1])
---
> 	return bool(BoxInfo.getItem("canMultiBoot")) and BoxInfo.getItem("canMode12") and int(getBootargs().replace('\0', '').split('=')[-1])
150c163,184
< 				imagelist[slot] = {'imagename': "%s (%s)" % (open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6], date)}
---
> 				imagename = open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6]
> 				if imagename == "" and os.path.isfile(os.path.join(imagedir, 'etc/image-version')):
> 					imageversion = {}
> 					with open(os.path.join(imagedir, 'etc/image-version')) as ivfile:
> 						for line in ivfile:
> 							key, val = line.partition("=")[::2]
> 							imageversion[key.strip()] = val.replace("\n", "")
> 					imagename = imageversion["creator"].split(" ")[0]+" "+str(int(imageversion["version"][0:3]))+"."+str(int(imageversion["version"][3:6]))
> 				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
> 			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/neutrino')):
> 				try:
> 					from datetime import datetime
> 					date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/neutrino")).st_mtime).strftime('%Y-%m-%d')
> 				except:
> 					date = _("Unknown")
> 				imageversion = {}
> 				with open(os.path.join(imagedir, 'usr/lib/enigma.info')) as ivfile:
> 					for line in ivfile:
> 						key, val = line.partition("=")[::2]
> 						imageversion[key.strip()] = val.replace("\n", "")
> 				imagename = imageversion["displaydistro"].replace("-Neutrino", "") + " " + imageversion["imgversion"]
> 				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}

 



Re: Vu+ 4K Multiboot #585 Dimitrij

  • PLi® Core member
  • 10,325 posts

+350
Excellent

Posted 23 March 2024 - 08:27

longtimeuser

 

/tmp/a/old.file

/tmp/b/new.file

cd /tmp
diff -Nuar a b >patch.diff

Edited by Dimitrij, 23 March 2024 - 08:28.

GigaBlue UHD Quad 4K /Lunix3-4K/Duo 4K


Re: Vu+ 4K Multiboot #586 longtimeuser

  • Member
  • 10 posts

+1
Neutral

Posted 31 March 2024 - 13:28

@Dimitrij

sorry for the delay, I was absent for one week

directory a contains old.py directory b contains new.py

old.py was derived form here: h**ps://gitlab.openpli.org/openpli/enigma2/-/blob/develop/lib/python/Tools/Multiboot.py?ref_type=heads

in diff output both files are specified as "new.py", for whatever reason

diff -Nuar a/new.py b/new.py
--- a/new.py	1970-01-01 01:00:00.000000000 +0100
+++ b/new.py	2024-03-22 20:12:34.340600100 +0100
@@ -0,0 +1,192 @@
+from Components.SystemInfo import BoxInfo
+from Components.Console import Console
+from Tools.Directories import fileHas, fileExists
+import os
+import glob
+import tempfile
+import subprocess
+
+
+class tmp:
+	dir = None
+
+bootargs = ""
+
+
+def getMultibootStartupDevice():
+	tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
+	if BoxInfo.getItem("hasKexec"): # kexec kernel multiboot
+		bootList = ("/dev/mmcblk0p4", "/dev/mmcblk0p7", "/dev/mmcblk0p9")
+	else: #legacy multiboot
+		bootList = ("/dev/mmcblk0p1", "/dev/mmcblk1p1", "/dev/mmcblk0p3", "/dev/mmcblk0p4", "/dev/mtdblock2", "/dev/block/by-name/bootoptions")
+	for device in bootList:
+		if os.path.exists(device):
+			if os.path.exists("/dev/block/by-name/flag"):
+				Console().ePopen('mount --bind %s %s' % (device, tmp.dir))
+			else:
+				Console().ePopen('mount %s %s' % (device, tmp.dir))
+			if os.path.isfile(os.path.join(tmp.dir, "STARTUP")):
+				print('[Multiboot] Startupdevice found:', device)
+				bootargs = open(os.path.join(tmp.dir, "STARTUP"), 'r').read().split("'")[1]
+				print('[Multiboot] bootargs:', bootargs)
+				return device
+			Console().ePopen('umount %s' % tmp.dir)
+	if not os.path.ismount(tmp.dir):
+		os.rmdir(tmp.dir)
+
+
+def getparam(line, param):
+	return line.replace("userdataroot", "rootuserdata").rsplit('%s=' % param, 1)[1].split(' ', 1)[0]
+
+
+def getMultibootslots():
+	bootslots = {}
+	mode12found = False
+	if BoxInfo.getItem("MultibootStartupDevice"):
+		for file in glob.glob(os.path.join(tmp.dir, 'STARTUP_*')):
+			if 'MODE_' in file:
+				mode12found = True
+				slotnumber = file.rsplit('_', 3)[1]
+			else:
+				slotnumber = file.rsplit('_', 1)[1]
+			if slotnumber.isdigit() and slotnumber not in bootslots:
+				slot = {}
+				for line in open(file).readlines():
+					if 'root=' in line:
+						device = getparam(line, 'root')
+						if "UUID=" in device:
+							slotx = str(getUUIDtoSD(device))
+							if slotx is not None:
+								device = slotx
+						if os.path.exists(device) or device == 'ubi0:ubifs':
+							slot['device'] = device
+							slot['startupfile'] = os.path.basename(file)
+							if 'rootsubdir' in line:
+								slot['rootsubdir'] = getparam(line, 'rootsubdir')
+						break
+				if slot:
+					bootslots[int(slotnumber)] = slot
+		Console().ePopen('umount %s' % tmp.dir)
+		if not os.path.ismount(tmp.dir):
+			os.rmdir(tmp.dir)
+		if not mode12found and BoxInfo.getItem("canMode12"):
+			#the boot device has ancient content and does not contain the correct STARTUP files
+			for slot in range(1, 5):
+				bootslots[slot] = {'device': '/dev/mmcblk0p%s' % (slot * 2 + 1), 'startupfile': None}
+	print('[Multiboot] Bootslots found:', bootslots)
+	return bootslots
+
+
+def getBootargs():
+	if os.path.isfile('/sys/firmware/devicetree/base/chosen/bootargs'):
+		return open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read()
+	else:
+		if bootargs == "":
+			getMultibootStartupDevice()
+		return bootargs
+
+
+def getCurrentImage():
+	if BoxInfo.getItem("canMultiBoot"):
+		if BoxInfo.getItem("hasKexec"):	# kexec kernel multiboot
+			rootsubdir = [x for x in getBootargs().split() if x.startswith("rootsubdir")]
+			char = "/" if "/" in rootsubdir[0] else "="
+			return int(rootsubdir[0].rsplit(char, 1)[1][11:])
+		else: #legacy multiboot
+			slot = [x[-1] for x in getBootargs().split() if x.startswith('rootsubdir')]
+			if slot:
+				return int(slot[0])
+			else:
+				device = getparam(getBootargs(), 'root')
+				for slot in BoxInfo.getItem("canMultiBoot").keys():
+					if BoxInfo.getItem("canMultiBoot")[slot]['device'] == device:
+						return slot
+
+
+def getCurrentImageMode():
+	return bool(BoxInfo.getItem("canMultiBoot")) and BoxInfo.getItem("canMode12") and int(getBootargs().replace('\0', '').split('=')[-1])
+
+
+def deleteImage(slot):
+	tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
+	Console().ePopen('mount %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
+	enigma2binaryfile = os.path.join(os.sep.join(filter(None, [tmp.dir, BoxInfo.getItem("canMultiBoot")[slot].get('rootsubdir', '')])), 'usr/bin/enigma2')
+	if os.path.exists(enigma2binaryfile):
+		os.rename(enigma2binaryfile, '%s.bak' % enigma2binaryfile)
+	Console().ePopen('umount %s' % tmp.dir)
+	if not os.path.ismount(tmp.dir):
+		os.rmdir(tmp.dir)
+
+
+def restoreImages():
+	for slot in BoxInfo.getItem("canMultiBoot"):
+		tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
+		Console().ePopen('mount %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
+		enigma2binaryfile = os.path.join(os.sep.join(filter(None, [tmp.dir, BoxInfo.getItem("canMultiBoot")[slot].get('rootsubdir', '')])), 'usr/bin/enigma2')
+		if os.path.exists('%s.bak' % enigma2binaryfile):
+			os.rename('%s.bak' % enigma2binaryfile, enigma2binaryfile)
+		Console().ePopen('umount %s' % tmp.dir)
+		if not os.path.ismount(tmp.dir):
+			os.rmdir(tmp.dir)
+
+
+def getUUIDtoSD(UUID): # returns None on failure
+	check = "/sbin/blkid"
+	if fileExists(check):
+		lines = subprocess.check_output([check]).decode(encoding="utf8", errors="ignore").split("\n")
+		for line in lines:
+			if UUID in line.replace('"', ''):
+				return line.split(":")[0].strip()
+	else:
+		return None
+
+
+def getImagelist():
+	imagelist = {}
+	if BoxInfo.getItem("canMultiBoot"):
+		tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
+		for slot in sorted(BoxInfo.getItem("canMultiBoot").keys()):
+			if BoxInfo.getItem("canMultiBoot")[slot]['device'] == 'ubi0:ubifs':
+				Console().ePopen('mount -t ubifs %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
+			else:
+				Console().ePopen('mount %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
+			imagedir = os.sep.join(filter(None, [tmp.dir, BoxInfo.getItem("canMultiBoot")[slot].get('rootsubdir', '')]))
+			if os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2')):
+				try:
+					from datetime import datetime
+					date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "var/lib/opkg/status")).st_mtime).strftime('%Y-%m-%d')
+					if date.startswith("1970"):
+						date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/share/bootlogo.mvi")).st_mtime).strftime('%Y-%m-%d')
+					date = max(date, datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/enigma2")).st_mtime).strftime('%Y-%m-%d'))
+				except:
+					date = _("Unknown")
+				imagename = open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6]
+				if imagename == "" and os.path.isfile(os.path.join(imagedir, 'etc/image-version')):
+					imageversion = {}
+					with open(os.path.join(imagedir, 'etc/image-version')) as ivfile:
+						for line in ivfile:
+							key, val = line.partition("=")[::2]
+							imageversion[key.strip()] = val.replace("\n", "")
+					imagename = imageversion["creator"].split(" ")[0]+" "+str(int(imageversion["version"][0:3]))+"."+str(int(imageversion["version"][3:6]))
+				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
+			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/neutrino')):
+				try:
+					from datetime import datetime
+					date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/neutrino")).st_mtime).strftime('%Y-%m-%d')
+				except:
+					date = _("Unknown")
+				imageversion = {}
+				with open(os.path.join(imagedir, 'usr/lib/enigma.info')) as ivfile:
+					for line in ivfile:
+						key, val = line.partition("=")[::2]
+						imageversion[key.strip()] = val.replace("\n", "")
+				imagename = imageversion["displaydistro"].replace("-Neutrino", "") + " " + imageversion["imgversion"]
+				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
+			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2.bak')):
+				imagelist[slot] = {'imagename': _("Deleted image")}
+			else:
+				imagelist[slot] = {'imagename': _("Empty slot")}
+			Console().ePopen('umount %s' % tmp.dir)
+		if not os.path.ismount(tmp.dir):
+			os.rmdir(tmp.dir)
+	return imagelist
diff -Nuar a/old.py b/old.py
--- a/old.py	2024-03-22 20:00:45.199600100 +0100
+++ b/old.py	1970-01-01 01:00:00.000000000 +0100
@@ -1,158 +0,0 @@
-from Components.SystemInfo import BoxInfo
-from Components.Console import Console
-from Tools.Directories import fileHas, fileExists
-import os
-import glob
-import tempfile
-import subprocess
-
-
-class tmp:
-	dir = None
-
-
-def getMultibootStartupDevice():
-	tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
-	if BoxInfo.getItem("hasKexec"): # kexec kernel multiboot
-		bootList = ("/dev/mmcblk0p4", "/dev/mmcblk0p7", "/dev/mmcblk0p9")
-	else: #legacy multiboot
-		bootList = ("/dev/mmcblk0p1", "/dev/mmcblk1p1", "/dev/mmcblk0p3", "/dev/mmcblk0p4", "/dev/mtdblock2", "/dev/block/by-name/bootoptions")
-	for device in bootList:
-		if os.path.exists(device):
-			if os.path.exists("/dev/block/by-name/flag"):
-				Console().ePopen('mount --bind %s %s' % (device, tmp.dir))
-			else:
-				Console().ePopen('mount %s %s' % (device, tmp.dir))
-			if os.path.isfile(os.path.join(tmp.dir, "STARTUP")):
-				print('[Multiboot] Startupdevice found:', device)
-				return device
-			Console().ePopen('umount %s' % tmp.dir)
-	if not os.path.ismount(tmp.dir):
-		os.rmdir(tmp.dir)
-
-
-def getparam(line, param):
-	return line.replace("userdataroot", "rootuserdata").rsplit('%s=' % param, 1)[1].split(' ', 1)[0]
-
-
-def getMultibootslots():
-	bootslots = {}
-	mode12found = False
-	if BoxInfo.getItem("MultibootStartupDevice"):
-		for file in glob.glob(os.path.join(tmp.dir, 'STARTUP_*')):
-			if 'MODE_' in file:
-				mode12found = True
-				slotnumber = file.rsplit('_', 3)[1]
-			else:
-				slotnumber = file.rsplit('_', 1)[1]
-			if slotnumber.isdigit() and slotnumber not in bootslots:
-				slot = {}
-				for line in open(file).readlines():
-					if 'root=' in line:
-						device = getparam(line, 'root')
-						if "UUID=" in device:
-							slotx = str(getUUIDtoSD(device))
-							if slotx is not None:
-								device = slotx
-						if os.path.exists(device) or device == 'ubi0:ubifs':
-							slot['device'] = device
-							slot['startupfile'] = os.path.basename(file)
-							if 'rootsubdir' in line:
-								slot['rootsubdir'] = getparam(line, 'rootsubdir')
-						break
-				if slot:
-					bootslots[int(slotnumber)] = slot
-		Console().ePopen('umount %s' % tmp.dir)
-		if not os.path.ismount(tmp.dir):
-			os.rmdir(tmp.dir)
-		if not mode12found and BoxInfo.getItem("canMode12"):
-			#the boot device has ancient content and does not contain the correct STARTUP files
-			for slot in range(1, 5):
-				bootslots[slot] = {'device': '/dev/mmcblk0p%s' % (slot * 2 + 1), 'startupfile': None}
-	print('[Multiboot] Bootslots found:', bootslots)
-	return bootslots
-
-
-def getCurrentImage():
-	if BoxInfo.getItem("canMultiBoot"):
-		if BoxInfo.getItem("hasKexec"):	# kexec kernel multiboot
-			rootsubdir = [x for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith("rootsubdir")]
-			char = "/" if "/" in rootsubdir[0] else "="
-			return int(rootsubdir[0].rsplit(char, 1)[1][11:])
-		else: #legacy multiboot
-			slot = [x[-1] for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith('rootsubdir')]
-			if slot:
-				return int(slot[0])
-			else:
-				device = getparam(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read(), 'root')
-				for slot in BoxInfo.getItem("canMultiBoot").keys():
-					if BoxInfo.getItem("canMultiBoot")[slot]['device'] == device:
-						return slot
-
-
-def getCurrentImageMode():
-	return bool(BoxInfo.getItem("canMultiBoot")) and BoxInfo.getItem("canMode12") and int(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().replace('\0', '').split('=')[-1])
-
-
-def deleteImage(slot):
-	tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
-	Console().ePopen('mount %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
-	enigma2binaryfile = os.path.join(os.sep.join(filter(None, [tmp.dir, BoxInfo.getItem("canMultiBoot")[slot].get('rootsubdir', '')])), 'usr/bin/enigma2')
-	if os.path.exists(enigma2binaryfile):
-		os.rename(enigma2binaryfile, '%s.bak' % enigma2binaryfile)
-	Console().ePopen('umount %s' % tmp.dir)
-	if not os.path.ismount(tmp.dir):
-		os.rmdir(tmp.dir)
-
-
-def restoreImages():
-	for slot in BoxInfo.getItem("canMultiBoot"):
-		tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
-		Console().ePopen('mount %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
-		enigma2binaryfile = os.path.join(os.sep.join(filter(None, [tmp.dir, BoxInfo.getItem("canMultiBoot")[slot].get('rootsubdir', '')])), 'usr/bin/enigma2')
-		if os.path.exists('%s.bak' % enigma2binaryfile):
-			os.rename('%s.bak' % enigma2binaryfile, enigma2binaryfile)
-		Console().ePopen('umount %s' % tmp.dir)
-		if not os.path.ismount(tmp.dir):
-			os.rmdir(tmp.dir)
-
-
-def getUUIDtoSD(UUID): # returns None on failure
-	check = "/sbin/blkid"
-	if fileExists(check):
-		lines = subprocess.check_output([check]).decode(encoding="utf8", errors="ignore").split("\n")
-		for line in lines:
-			if UUID in line.replace('"', ''):
-				return line.split(":")[0].strip()
-	else:
-		return None
-
-
-def getImagelist():
-	imagelist = {}
-	if BoxInfo.getItem("canMultiBoot"):
-		tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
-		for slot in sorted(BoxInfo.getItem("canMultiBoot").keys()):
-			if BoxInfo.getItem("canMultiBoot")[slot]['device'] == 'ubi0:ubifs':
-				Console().ePopen('mount -t ubifs %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
-			else:
-				Console().ePopen('mount %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
-			imagedir = os.sep.join(filter(None, [tmp.dir, BoxInfo.getItem("canMultiBoot")[slot].get('rootsubdir', '')]))
-			if os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2')):
-				try:
-					from datetime import datetime
-					date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "var/lib/opkg/status")).st_mtime).strftime('%Y-%m-%d')
-					if date.startswith("1970"):
-						date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/share/bootlogo.mvi")).st_mtime).strftime('%Y-%m-%d')
-					date = max(date, datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/enigma2")).st_mtime).strftime('%Y-%m-%d'))
-				except:
-					date = _("Unknown")
-				imagelist[slot] = {'imagename': "%s (%s)" % (open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6], date)}
-			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2.bak')):
-				imagelist[slot] = {'imagename': _("Deleted image")}
-			else:
-				imagelist[slot] = {'imagename': _("Empty slot")}
-			Console().ePopen('umount %s' % tmp.dir)
-		if not os.path.ismount(tmp.dir):
-			os.rmdir(tmp.dir)
-	return imagelist


Edited by longtimeuser, 31 March 2024 - 13:30.


Re: Vu+ 4K Multiboot #587 Dimitrij

  • PLi® Core member
  • 10,325 posts

+350
Excellent

Posted 31 March 2024 - 15:21

/tmp/a/Multiboot.py   old file

/tmp/b/Multiboot.py   new file


GigaBlue UHD Quad 4K /Lunix3-4K/Duo 4K


Re: Vu+ 4K Multiboot #588 longtimeuser

  • Member
  • 10 posts

+1
Neutral

Posted 31 March 2024 - 19:47

Got it. Output is now much shorter:

diff -Nuar a/Multiboot.py b/Multiboot.py
--- a/Multiboot.py	2024-03-22 20:00:45.199600100 +0100
+++ b/Multiboot.py	2024-03-22 20:12:34.340600100 +0100
@@ -10,6 +10,8 @@
 class tmp:
 	dir = None
 
+bootargs = ""
+
 
 def getMultibootStartupDevice():
 	tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
@@ -25,6 +27,8 @@
 				Console().ePopen('mount %s %s' % (device, tmp.dir))
 			if os.path.isfile(os.path.join(tmp.dir, "STARTUP")):
 				print('[Multiboot] Startupdevice found:', device)
+				bootargs = open(os.path.join(tmp.dir, "STARTUP"), 'r').read().split("'")[1]
+				print('[Multiboot] bootargs:', bootargs)
 				return device
 			Console().ePopen('umount %s' % tmp.dir)
 	if not os.path.ismount(tmp.dir):
@@ -73,25 +77,34 @@
 	return bootslots
 
 
+def getBootargs():
+	if os.path.isfile('/sys/firmware/devicetree/base/chosen/bootargs'):
+		return open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read()
+	else:
+		if bootargs == "":
+			getMultibootStartupDevice()
+		return bootargs
+
+
 def getCurrentImage():
 	if BoxInfo.getItem("canMultiBoot"):
 		if BoxInfo.getItem("hasKexec"):	# kexec kernel multiboot
-			rootsubdir = [x for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith("rootsubdir")]
+			rootsubdir = [x for x in getBootargs().split() if x.startswith("rootsubdir")]
 			char = "/" if "/" in rootsubdir[0] else "="
 			return int(rootsubdir[0].rsplit(char, 1)[1][11:])
 		else: #legacy multiboot
-			slot = [x[-1] for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith('rootsubdir')]
+			slot = [x[-1] for x in getBootargs().split() if x.startswith('rootsubdir')]
 			if slot:
 				return int(slot[0])
 			else:
-				device = getparam(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read(), 'root')
+				device = getparam(getBootargs(), 'root')
 				for slot in BoxInfo.getItem("canMultiBoot").keys():
 					if BoxInfo.getItem("canMultiBoot")[slot]['device'] == device:
 						return slot
 
 
 def getCurrentImageMode():
-	return bool(BoxInfo.getItem("canMultiBoot")) and BoxInfo.getItem("canMode12") and int(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().replace('\0', '').split('=')[-1])
+	return bool(BoxInfo.getItem("canMultiBoot")) and BoxInfo.getItem("canMode12") and int(getBootargs().replace('\0', '').split('=')[-1])
 
 
 def deleteImage(slot):
@@ -147,7 +160,28 @@
 					date = max(date, datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/enigma2")).st_mtime).strftime('%Y-%m-%d'))
 				except:
 					date = _("Unknown")
-				imagelist[slot] = {'imagename': "%s (%s)" % (open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6], date)}
+				imagename = open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6]
+				if imagename == "" and os.path.isfile(os.path.join(imagedir, 'etc/image-version')):
+					imageversion = {}
+					with open(os.path.join(imagedir, 'etc/image-version')) as ivfile:
+						for line in ivfile:
+							key, val = line.partition("=")[::2]
+							imageversion[key.strip()] = val.replace("\n", "")
+					imagename = imageversion["creator"].split(" ")[0]+" "+str(int(imageversion["version"][0:3]))+"."+str(int(imageversion["version"][3:6]))
+				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
+			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/neutrino')):
+				try:
+					from datetime import datetime
+					date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/neutrino")).st_mtime).strftime('%Y-%m-%d')
+				except:
+					date = _("Unknown")
+				imageversion = {}
+				with open(os.path.join(imagedir, 'usr/lib/enigma.info')) as ivfile:
+					for line in ivfile:
+						key, val = line.partition("=")[::2]
+						imageversion[key.strip()] = val.replace("\n", "")
+				imagename = imageversion["displaydistro"].replace("-Neutrino", "") + " " + imageversion["imgversion"]
+				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
 			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2.bak')):
 				imagelist[slot] = {'imagename': _("Deleted image")}
 			else:

 



Re: Vu+ 4K Multiboot #589 longtimeuser

  • Member
  • 10 posts

+1
Neutral

Posted 31 March 2024 - 19:57

sorry, checked again, and forgot one important statement: "global bootargs"

 

so here again:

diff -Nuar a/Multiboot.py b/Multiboot.py
--- a/Multiboot.py	2024-03-22 20:00:45.199600100 +0100
+++ b/Multiboot.py	2024-03-31 20:51:41.078000000 +0200
@@ -10,8 +10,11 @@
 class tmp:
 	dir = None
 
+bootargs = ""
+
 
 def getMultibootStartupDevice():
+	global bootargs
 	tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
 	if BoxInfo.getItem("hasKexec"): # kexec kernel multiboot
 		bootList = ("/dev/mmcblk0p4", "/dev/mmcblk0p7", "/dev/mmcblk0p9")
@@ -25,6 +28,8 @@
 				Console().ePopen('mount %s %s' % (device, tmp.dir))
 			if os.path.isfile(os.path.join(tmp.dir, "STARTUP")):
 				print('[Multiboot] Startupdevice found:', device)
+				bootargs = open(os.path.join(tmp.dir, "STARTUP"), 'r').read().split("'")[1]
+				print('[Multiboot] bootargs:', bootargs)
 				return device
 			Console().ePopen('umount %s' % tmp.dir)
 	if not os.path.ismount(tmp.dir):
@@ -73,25 +78,34 @@
 	return bootslots
 
 
+def getBootargs():
+	if os.path.isfile('/sys/firmware/devicetree/base/chosen/bootargs'):
+		return open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read()
+	else:
+		if bootargs == "":
+			getMultibootStartupDevice()
+		return bootargs
+
+
 def getCurrentImage():
 	if BoxInfo.getItem("canMultiBoot"):
 		if BoxInfo.getItem("hasKexec"):	# kexec kernel multiboot
-			rootsubdir = [x for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith("rootsubdir")]
+			rootsubdir = [x for x in getBootargs().split() if x.startswith("rootsubdir")]
 			char = "/" if "/" in rootsubdir[0] else "="
 			return int(rootsubdir[0].rsplit(char, 1)[1][11:])
 		else: #legacy multiboot
-			slot = [x[-1] for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith('rootsubdir')]
+			slot = [x[-1] for x in getBootargs().split() if x.startswith('rootsubdir')]
 			if slot:
 				return int(slot[0])
 			else:
-				device = getparam(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read(), 'root')
+				device = getparam(getBootargs(), 'root')
 				for slot in BoxInfo.getItem("canMultiBoot").keys():
 					if BoxInfo.getItem("canMultiBoot")[slot]['device'] == device:
 						return slot
 
 
 def getCurrentImageMode():
-	return bool(BoxInfo.getItem("canMultiBoot")) and BoxInfo.getItem("canMode12") and int(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().replace('\0', '').split('=')[-1])
+	return bool(BoxInfo.getItem("canMultiBoot")) and BoxInfo.getItem("canMode12") and int(getBootargs().replace('\0', '').split('=')[-1])
 
 
 def deleteImage(slot):
@@ -147,7 +161,28 @@
 					date = max(date, datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/enigma2")).st_mtime).strftime('%Y-%m-%d'))
 				except:
 					date = _("Unknown")
-				imagelist[slot] = {'imagename': "%s (%s)" % (open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6], date)}
+				imagename = open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6]
+				if imagename == "" and os.path.isfile(os.path.join(imagedir, 'etc/image-version')):
+					imageversion = {}
+					with open(os.path.join(imagedir, 'etc/image-version')) as ivfile:
+						for line in ivfile:
+							key, val = line.partition("=")[::2]
+							imageversion[key.strip()] = val.replace("\n", "")
+					imagename = imageversion["creator"].split(" ")[0]+" "+str(int(imageversion["version"][0:3]))+"."+str(int(imageversion["version"][3:6]))
+				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
+			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/neutrino')):
+				try:
+					from datetime import datetime
+					date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/neutrino")).st_mtime).strftime('%Y-%m-%d')
+				except:
+					date = _("Unknown")
+				imageversion = {}
+				with open(os.path.join(imagedir, 'usr/lib/enigma.info')) as ivfile:
+					for line in ivfile:
+						key, val = line.partition("=")[::2]
+						imageversion[key.strip()] = val.replace("\n", "")
+				imagename = imageversion["displaydistro"].replace("-Neutrino", "") + " " + imageversion["imgversion"]
+				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
 			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2.bak')):
 				imagelist[slot] = {'imagename': _("Deleted image")}
 			else:

 



Re: Vu+ 4K Multiboot #590 WanWizard

  • PLi® Core member
  • 70,506 posts

+1,810
Excellent

Posted 1 April 2024 - 14:34

globals? WOT?


Currently in use: VU+ Duo 4K (2xFBC S2), VU+ Solo 4K (1xFBC S2), uClan Usytm 4K Ultimate (S2+T2), Octagon SF8008 (S2+T2), Zgemma H9.2H (S2+T2)

Due to my bad health, I will not be very active at times and may be slow to respond. I will not read the forum or PM on a regular basis.

Many answers to your question can be found in our new and improved wiki.


Re: Vu+ 4K Multiboot #591 littlesat

  • PLi® Core member
  • 57,163 posts

+698
Excellent

Posted 1 April 2024 - 15:00

Indeed not recommended….

WaveFrontier 28.2E | 23.5E | 19.2E | 16E | 13E | 10/9E | 7E | 5E | 1W | 4/5W | 15W


Re: Vu+ 4K Multiboot #592 longtimeuser

  • Member
  • 10 posts

+1
Neutral

Posted 2 April 2024 - 16:04

one can add the global variable bootargs to the tmp class, which is in fact also a global variable.

 

so here again:

diff -Nuar a/Multiboot.py b/Multiboot.py
--- a/Multiboot.py	2024-03-22 20:00:45.199600100 +0100
+++ b/Multiboot.py	2024-04-02 16:57:13.839200100 +0200
@@ -1,4 +1,4 @@
-from Components.SystemInfo import BoxInfo
+from Components.SystemInfo import SystemInfo
 from Components.Console import Console
 from Tools.Directories import fileHas, fileExists
 import os
@@ -9,11 +9,12 @@
 
 class tmp:
 	dir = None
+	bootargs = ""
 
 
 def getMultibootStartupDevice():
 	tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
-	if BoxInfo.getItem("hasKexec"): # kexec kernel multiboot
+	if SystemInfo["hasKexec"]: # kexec kernel multiboot
 		bootList = ("/dev/mmcblk0p4", "/dev/mmcblk0p7", "/dev/mmcblk0p9")
 	else: #legacy multiboot
 		bootList = ("/dev/mmcblk0p1", "/dev/mmcblk1p1", "/dev/mmcblk0p3", "/dev/mmcblk0p4", "/dev/mtdblock2", "/dev/block/by-name/bootoptions")
@@ -25,6 +26,8 @@
 				Console().ePopen('mount %s %s' % (device, tmp.dir))
 			if os.path.isfile(os.path.join(tmp.dir, "STARTUP")):
 				print('[Multiboot] Startupdevice found:', device)
+				tmp.bootargs = open(os.path.join(tmp.dir, "STARTUP"), 'r').read().split("'")[1]
+				print('[Multiboot] bootargs:', tmp.bootargs)
 				return device
 			Console().ePopen('umount %s' % tmp.dir)
 	if not os.path.ismount(tmp.dir):
@@ -38,7 +41,7 @@
 def getMultibootslots():
 	bootslots = {}
 	mode12found = False
-	if BoxInfo.getItem("MultibootStartupDevice"):
+	if SystemInfo["MultibootStartupDevice"]:
 		for file in glob.glob(os.path.join(tmp.dir, 'STARTUP_*')):
 			if 'MODE_' in file:
 				mode12found = True
@@ -65,7 +68,7 @@
 		Console().ePopen('umount %s' % tmp.dir)
 		if not os.path.ismount(tmp.dir):
 			os.rmdir(tmp.dir)
-		if not mode12found and BoxInfo.getItem("canMode12"):
+		if not mode12found and SystemInfo["canMode12"]:
 			#the boot device has ancient content and does not contain the correct STARTUP files
 			for slot in range(1, 5):
 				bootslots[slot] = {'device': '/dev/mmcblk0p%s' % (slot * 2 + 1), 'startupfile': None}
@@ -73,31 +76,40 @@
 	return bootslots
 
 
+def getBootargs():
+	if os.path.isfile('/sys/firmware/devicetree/base/chosen/bootargs'):
+		return open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read()
+	else:
+		if tmp.bootargs == "":
+			getMultibootStartupDevice()
+		return tmp.bootargs
+
+
 def getCurrentImage():
-	if BoxInfo.getItem("canMultiBoot"):
-		if BoxInfo.getItem("hasKexec"):	# kexec kernel multiboot
-			rootsubdir = [x for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith("rootsubdir")]
+	if SystemInfo["canMultiBoot"]:
+		if SystemInfo["hasKexec"]:	# kexec kernel multiboot
+			rootsubdir = [x for x in getBootargs().split() if x.startswith("rootsubdir")]
 			char = "/" if "/" in rootsubdir[0] else "="
 			return int(rootsubdir[0].rsplit(char, 1)[1][11:])
 		else: #legacy multiboot
-			slot = [x[-1] for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith('rootsubdir')]
+			slot = [x[-1] for x in getBootargs().split() if x.startswith('rootsubdir')]
 			if slot:
 				return int(slot[0])
 			else:
-				device = getparam(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read(), 'root')
-				for slot in BoxInfo.getItem("canMultiBoot").keys():
-					if BoxInfo.getItem("canMultiBoot")[slot]['device'] == device:
+				device = getparam(getBootargs(), 'root')
+				for slot in SystemInfo["canMultiBoot"].keys():
+					if SystemInfo["canMultiBoot"][slot]['device'] == device:
 						return slot
 
 
 def getCurrentImageMode():
-	return bool(BoxInfo.getItem("canMultiBoot")) and BoxInfo.getItem("canMode12") and int(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().replace('\0', '').split('=')[-1])
+	return bool(SystemInfo["canMultiBoot"]) and SystemInfo["canMode12"] and int(getBootargs().replace('\0', '').split('=')[-1])
 
 
 def deleteImage(slot):
 	tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
-	Console().ePopen('mount %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
-	enigma2binaryfile = os.path.join(os.sep.join(filter(None, [tmp.dir, BoxInfo.getItem("canMultiBoot")[slot].get('rootsubdir', '')])), 'usr/bin/enigma2')
+	Console().ePopen('mount %s %s' % (SystemInfo["canMultiBoot"][slot]['device'], tmp.dir))
+	enigma2binaryfile = os.path.join(os.sep.join(filter(None, [tmp.dir, SystemInfo["canMultiBoot"][slot].get('rootsubdir', '')])), 'usr/bin/enigma2')
 	if os.path.exists(enigma2binaryfile):
 		os.rename(enigma2binaryfile, '%s.bak' % enigma2binaryfile)
 	Console().ePopen('umount %s' % tmp.dir)
@@ -106,10 +118,10 @@
 
 
 def restoreImages():
-	for slot in BoxInfo.getItem("canMultiBoot"):
+	for slot in SystemInfo["canMultiBoot"]:
 		tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
-		Console().ePopen('mount %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
-		enigma2binaryfile = os.path.join(os.sep.join(filter(None, [tmp.dir, BoxInfo.getItem("canMultiBoot")[slot].get('rootsubdir', '')])), 'usr/bin/enigma2')
+		Console().ePopen('mount %s %s' % (SystemInfo["canMultiBoot"][slot]['device'], tmp.dir))
+		enigma2binaryfile = os.path.join(os.sep.join(filter(None, [tmp.dir, SystemInfo["canMultiBoot"][slot].get('rootsubdir', '')])), 'usr/bin/enigma2')
 		if os.path.exists('%s.bak' % enigma2binaryfile):
 			os.rename('%s.bak' % enigma2binaryfile, enigma2binaryfile)
 		Console().ePopen('umount %s' % tmp.dir)
@@ -130,14 +142,14 @@
 
 def getImagelist():
 	imagelist = {}
-	if BoxInfo.getItem("canMultiBoot"):
+	if SystemInfo["canMultiBoot"]:
 		tmp.dir = tempfile.mkdtemp(prefix="Multiboot")
-		for slot in sorted(BoxInfo.getItem("canMultiBoot").keys()):
-			if BoxInfo.getItem("canMultiBoot")[slot]['device'] == 'ubi0:ubifs':
-				Console().ePopen('mount -t ubifs %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
+		for slot in sorted(SystemInfo["canMultiBoot"].keys()):
+			if SystemInfo["canMultiBoot"][slot]['device'] == 'ubi0:ubifs':
+				Console().ePopen('mount -t ubifs %s %s' % (SystemInfo["canMultiBoot"][slot]['device'], tmp.dir))
 			else:
-				Console().ePopen('mount %s %s' % (BoxInfo.getItem("canMultiBoot")[slot]['device'], tmp.dir))
-			imagedir = os.sep.join(filter(None, [tmp.dir, BoxInfo.getItem("canMultiBoot")[slot].get('rootsubdir', '')]))
+				Console().ePopen('mount %s %s' % (SystemInfo["canMultiBoot"][slot]['device'], tmp.dir))
+			imagedir = os.sep.join(filter(None, [tmp.dir, SystemInfo["canMultiBoot"][slot].get('rootsubdir', '')]))
 			if os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2')):
 				try:
 					from datetime import datetime
@@ -147,7 +159,29 @@
 					date = max(date, datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/enigma2")).st_mtime).strftime('%Y-%m-%d'))
 				except:
 					date = _("Unknown")
-				imagelist[slot] = {'imagename': "%s (%s)" % (open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6], date)}
+				imagename = open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6]
+				if imagename == "" and os.path.isfile(os.path.join(imagedir, 'etc/image-version')):
+					imagename = open(os.path.join(imagedir, "etc/issue")).readlines()[0].capitalize().strip()
+					imageversion = {}
+					with open(os.path.join(imagedir, 'etc/image-version')) as ivfile:
+						for line in ivfile:
+							key, val = line.partition("=")[::2]
+							imageversion[key.strip()] = val.replace("\n", "")
+					imagename = imageversion["creator"].split(" ")[0]+" "+str(int(imageversion["version"][0:3]))+"."+str(int(imageversion["version"][3:6]))
+				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
+			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/neutrino')):
+				try:
+					from datetime import datetime
+					date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/neutrino")).st_mtime).strftime('%Y-%m-%d')
+				except:
+					date = _("Unknown")
+				imageversion = {}
+				with open(os.path.join(imagedir, 'usr/lib/enigma.info')) as ivfile:
+					for line in ivfile:
+						key, val = line.partition("=")[::2]
+						imageversion[key.strip()] = val.replace("\n", "")
+				imagename = imageversion["displaydistro"].replace("-Neutrino", "") + " " + imageversion["imgversion"]
+				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
 			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2.bak')):
 				imagelist[slot] = {'imagename': _("Deleted image")}
 			else:


Edited by longtimeuser, 2 April 2024 - 16:05.


Re: Vu+ 4K Multiboot #593 longtimeuser

  • Member
  • 10 posts

+1
Neutral

Posted 2 April 2024 - 16:17

sorry again, compared not the dev branch. here is the right one (also shorter):

diff -Nuar a/Multiboot.py b/Multiboot.py
--- a/Multiboot.py	2024-03-22 20:00:45.199600100 +0100
+++ b/Multiboot.py	2024-04-02 16:54:18.855200100 +0200
@@ -9,6 +9,7 @@
 
 class tmp:
 	dir = None
+	bootargs = ""
 
 
 def getMultibootStartupDevice():
@@ -25,6 +26,8 @@
 				Console().ePopen('mount %s %s' % (device, tmp.dir))
 			if os.path.isfile(os.path.join(tmp.dir, "STARTUP")):
 				print('[Multiboot] Startupdevice found:', device)
+				tmp.bootargs = open(os.path.join(tmp.dir, "STARTUP"), 'r').read().split("'")[1]
+				print('[Multiboot] bootargs:', tmp.bootargs)
 				return device
 			Console().ePopen('umount %s' % tmp.dir)
 	if not os.path.ismount(tmp.dir):
@@ -73,25 +76,34 @@
 	return bootslots
 
 
+def getBootargs():
+	if os.path.isfile('/sys/firmware/devicetree/base/chosen/bootargs'):
+		return open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read()
+	else:
+		if tmp.bootargs == "":
+			getMultibootStartupDevice()
+		return tmp.bootargs
+
+
 def getCurrentImage():
 	if BoxInfo.getItem("canMultiBoot"):
 		if BoxInfo.getItem("hasKexec"):	# kexec kernel multiboot
-			rootsubdir = [x for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith("rootsubdir")]
+			rootsubdir = [x for x in getBootargs().split() if x.startswith("rootsubdir")]
 			char = "/" if "/" in rootsubdir[0] else "="
 			return int(rootsubdir[0].rsplit(char, 1)[1][11:])
 		else: #legacy multiboot
-			slot = [x[-1] for x in open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().split() if x.startswith('rootsubdir')]
+			slot = [x[-1] for x in getBootargs().split() if x.startswith('rootsubdir')]
 			if slot:
 				return int(slot[0])
 			else:
-				device = getparam(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read(), 'root')
+				device = getparam(getBootargs(), 'root')
 				for slot in BoxInfo.getItem("canMultiBoot").keys():
 					if BoxInfo.getItem("canMultiBoot")[slot]['device'] == device:
 						return slot
 
 
 def getCurrentImageMode():
-	return bool(BoxInfo.getItem("canMultiBoot")) and BoxInfo.getItem("canMode12") and int(open('/sys/firmware/devicetree/base/chosen/bootargs', 'r').read().replace('\0', '').split('=')[-1])
+	return bool(BoxInfo.getItem("canMultiBoot")) and BoxInfo.getItem("canMode12") and int(getBootargs().replace('\0', '').split('=')[-1])
 
 
 def deleteImage(slot):
@@ -147,7 +159,28 @@
 					date = max(date, datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/enigma2")).st_mtime).strftime('%Y-%m-%d'))
 				except:
 					date = _("Unknown")
-				imagelist[slot] = {'imagename': "%s (%s)" % (open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6], date)}
+				imagename = open(os.path.join(imagedir, "etc/issue")).readlines()[-2].capitalize().strip()[:-6]
+				if imagename == "" and os.path.isfile(os.path.join(imagedir, 'etc/image-version')):
+					imageversion = {}
+					with open(os.path.join(imagedir, 'etc/image-version')) as ivfile:
+						for line in ivfile:
+							key, val = line.partition("=")[::2]
+							imageversion[key.strip()] = val.replace("\n", "")
+					imagename = imageversion["creator"].split(" ")[0]+" "+str(int(imageversion["version"][0:3]))+"."+str(int(imageversion["version"][3:6]))
+				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
+			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/neutrino')):
+				try:
+					from datetime import datetime
+					date = datetime.fromtimestamp(os.stat(os.path.join(imagedir, "usr/bin/neutrino")).st_mtime).strftime('%Y-%m-%d')
+				except:
+					date = _("Unknown")
+				imageversion = {}
+				with open(os.path.join(imagedir, 'usr/lib/enigma.info')) as ivfile:
+					for line in ivfile:
+						key, val = line.partition("=")[::2]
+						imageversion[key.strip()] = val.replace("\n", "")
+				imagename = imageversion["displaydistro"].replace("-Neutrino", "") + " " + imageversion["imgversion"]
+				imagelist[slot] = {'imagename': "%s (%s)" % (imagename, date)}
 			elif os.path.isfile(os.path.join(imagedir, 'usr/bin/enigma2.bak')):
 				imagelist[slot] = {'imagename': _("Deleted image")}
 			else:

 




2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users