MOHAMMAD HADI Posted December 15, 2017 Posted December 15, 2017 Ok, I updated the boot manager so it is now more portable and added some convenience features as well. Be aware that it is not beginner friendly, you need at least some knowledge about writing and editing u-boot scripts, Uart cable is not needed but can be useful during testing and setting up. I rewrote the script in python using curses so It's now more elegent (in my opinion anyway) I tried to get it as close as I can to look like grub2 interface: Now let's explain How it works: First, the sdcard must contain at least two fat32 partitions: -First partition(fat32) (label=RECOVERY) content: Quote ├── aml_autoscript ├── dtb.img ├── Image ├── multiboot.script ├── multiboot.txt ├── uInitrd └── update.zip This partition contains the main boot manager files: 1-aml_autoscript is the script that is used to update the u-boot environment to allow for our method to work 2-dtb.img a dtb file, make sure to replace it with the appropriate one for your device I compiled it from coreelec source https://github.com/CoreELEC/device-trees- amlogic 3-Image is the kernel image of the boot manager 4- multiboot.script is the script that is executed to display the boot manager 5-update.zip use this in your update app in android to flash the aml_autoscript above and make the bootloader ready for our boot manager -Second Partition(fat32) (label=BOOT) content: Quote ├── config.yaml └── multiboot ├── COREELEC ├── Debian-3-xfce ├── Debian_Server-3 └── kernel-3.14 This partition contains at least the config.yaml file that contains general settings for the boot manager and the boot entries to be listed. Mote that I have a folder(multiboot) that contains the boot files for my distros(kernel,initrd,dtb and boot script) you don't have to put them in this partition you can put them anywhere (another partition on the sd card, a USB drive or even in the internal EMMC) just make sure to have the correct path and device id for them in the config.yaml file. Also If you want to use the remote control instead of a keyboard to select the os place the correct remote.conf of your remote in the root of this partition. the structure of config.yaml is like this: generalSettings: default: 5 rememberboot: true timeout: 10 menu: - bootscript: /multiboot/COREELEC/u-boot.script device: mmc 0:2 devicefs: fat name: COREELEC - bootscript: /multiboot/armbian-3.14.29-mate/u-boot.script device: mmc 0:2 devicefs: fat name: armbian-3.14.29-mate - bootscript: /multiboot/dvb_test/u-boot.script device: mmc 0:2 devicefs: fat name: dvb_test - bootscript: /multiboot/kernel-3.14/u-boot.script first you set the general settings: - timeout: this is how many seconds the boot manager should wait before booting into the default boot entry - default: this is the zero based index of the default distro that the boot manager will boot to after timeout, note that index 0 is reserved for the internal EMMC boot so your menu starts at index 1. - rememberboot: if this is set to true then the manager will remember the entry that you selected and save it's index in the default entry above so the next time you boot this will be your default entry. after that you add your menu entries: - name: is the name of the distribution displayed in the boot menu - bootscript: this is the path of the bootscript of the distribution (note that this boot script should be capable of booting the distro on it's on, so it must have the correct path of the boot files and pass the correct root parameter to the kernel, see the example u-boot.script files that are included in each distibution) - device is the device that contains the bootscipt using u-boot format so the first mmc and second partition would be mmc 0:2 , the second mmc and third partiton would be mmc 1:3 . - devicefs is the filesystem type of the above device, this is usually fat because most of these tv boxes support loading files of only fat32 partitions (except some boards like khadas vim and odroid whose bootloader support ext4 partitions) now let's see an example of a disto bootscript: Quote setenv env_addr "0x10400000" setenv kernel_addr "0x11000000" setenv initrd_addr "0x13000000"setenv path "/multiboot/Debian-3-xfce" setenv boot_start booti ${kernel_addr} ${initrd_addr} ${dtb_mem_addr} if fatload mmc 0:2 ${kernel_addr} ${path}/zImage; then if fatload mmc 0:2 ${initrd_addr} ${path}/uInitrd; then if fatload mmc 0:2 ${env_addr} ${path}/uEnv.ini; then env import -t ${env_addr} ${filesize};fi; if fatload mmc 0:2 ${dtb_mem_addr} ${path}/dtb.img; then run boot_start; else store dtb read ${dtb_mem_addr}; run boot_start;fi;fi;fi; this the same bootscript that was shipped with balbes150 image I only edited the device to mmc 0:2 because this is where I have my kernel and other boot files, also I prepended the correct path before each file name. In the uEnv.ini file of this distro I edited the root parameter to use a partition labeled "Debian-3-xfce" and created that partiton using gparted Quote bootargs=root=LABEL=Debian-3-xfce rootflags=data=writeback rw console=ttyS0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 mac=${mac} I prepared a boot image that contains the boot manager and two distibutions, Coreelec and Debian server. download the image here and burn it to a new sdcard then use the update application in android and update using update.zip, after that you'll see the boot menu after the reboot https://drive.google.com/open?id=1dhpcqNrqbW493SK8J_Er9b-ZipJkTfd3 Below is the old method Hi, This is my quick and dirty solution to multiboot any amlogic device(actually it can be used on any device that uses u-boot with slight modification): ***Warning: the following method was only tested on one device which is KII PRO, I made this method for my own use ,it is a long and a bit complicated to setup for non-experienced users if you want to try it you are trying it at your own risk, I take no responsibility for any damage that may occur to your device. Preparing the sd card for multiboot: 1- Download the zip file from the attachments multiboot.zip 2-wipe everything in your sdcard (i used a 16 gb card) and create 2 partitions: -The first one is a fat32 partition, this can be small partition (for me i made it 1gb) it will contain the boot files for the main multiboot system and for any other distributions,i labeled this partition "BOOT". -The second partition is ext4 partition which will contain the rootfs of your distributions in raw image format, this need to be a big partition i suggest you assign all remaining available space to this partition, also you need to label it "ROOTFS" (this is mandatory). you can use whatever tools you want(gparted,fdisk...etc) 3-mount the partitions and extract the zip file to the root of your boot partition(the fat32 partition) and create an empty folder called ‘multiboot’ inside the root of the first and second partitions, so the first partition content should look like this ▶ tree . ├── aml_autoscript ├── aml_autoscript.zip ├── multiboot ├── config.txt ├── dtb.img ├── s905_autoscript ├── s905_autoscript.cmd ├── umbInitrd └── zImage and the second partition should look like this ▶ tree /run/media/mohammad/ROOTFS/ └── multiboot the ‘multiboot’ folder in the first partition should contains folders with the name of the distro and inside them are the bootfiles of that distro(kernel,dtb,initramfs and s905_autoscript file) the ‘multiboot’ folder in the second partition should contain the same folders as in the first partition and inside the folder there should be an ext4 image of the rootfs of the distro 4- The dtb file i used is for kii pro tv box and you should replace that with the dtb of your device, you can get that from any of balbes150 distributions(3.14.29 kernel). Now you'r ready to boot, all you need is some distros Preparing the distros: You can make a partition for each distro on your sd card and use it to store the rootfs but i chose a more portable solution by making a raw partition image for each distro and pass it to the initramfs to be mounted as a loop device. I will be using one of balbes150 distros as an example (Armbian_5.32_S9xxx_Ubuntu_xenial_3.14.29_mate_20170907.img.xz) 1-First extract the file ▶xz -k -v -d Armbian_5.32_S9xxx_Ubuntu_xenial_3.14.29_mate_20170907.img.xz 2- Now mount the resulting file partitions to some directories, I use kpartx to do it for me automatically ▶sudo kpartx -av Armbian_5.32_S9xxx_Ubuntu_xenial_3.14.29_mate_20170907.img add map loop0p1 (254:0): 0 262144 linear 7:0 2048 add map loop0p2 (254:1): 0 8812544 linear 7:0 264192 now mount the loop devices (i use udiskctl) ▶ udisksctl mount -b /dev/mapper/loop0p1 Mounted /dev/dm-0 at /run/media/mohammad/BOOT1. ▶ udisksctl mount -b /dev/mapper/loop0p2 Mounted /dev/dm-1 at /run/media/mohammad/ROOTFS1. df -h Filesystem Size Used Avail Use% Mounted on /dev/sdb1 2.0G 215M 1.8G 11% /run/media/mohammad/BOOT #this is my sd card #1 partition /dev/sdb2 13G 6.8G 4.8G 59% /run/media/mohammad/ROOTFS #this is my sd card #2 partition /dev/mapper/loop0p1 128M 53M 76M 42% /run/media/mohammad/BOOT1 #this is the mounted distro image #1 partition /dev/mapper/loop0p2 4.1G 2.9G 1.1G 75% /run/media/mohammad/ROOTFS1 #this is the mounted distro image #2 partition 3- create a folder with the name of the distro in the multiboot folder you created earlier (in the first and second partitions of your sd card) then copy all the boot files of your distro to the folder in the first partition ▶ mkdir /run/media/mohammad/BOOT/multiboot/armbian-3.14.29-mate #this is the first(fat32)partition ▶ mkdir /run/media/mohammad/ROOTFS/multiboot/armbian-3.14.29-mate #this is the second (ext4) partition ▶ cp /run/media/mohammad/BOOT1/* /run/media/mohammad/BOOT/multiboot/armbian-3.14.29-mate/ 4- now you need to create an ext4 partition image to contain the rootfs of your distro for me I made a 4GB image fallocate -l 4G system.img mkfs.ext4 system.img 5-mount the image ▶ sudo losetup $(losetup -f) system.img ▶ udiskctl mount -b /dev/loop1 Mounted /dev/loop1 at /run/media/mohammad/71545ae9-33c7-4d99-963e-a5a915464078. 6-copy all the files from the rootfs of your distro image to the newly created image ▶ cp /run/media/mohammad/ROOTFS1/* /run/media/mohammad/71545ae9-33c7-4d99-963e-a5a915464078/ UPDATE: edit the "/etc/fstab" inside the system.img file nano /run/media/mohammad/71545ae9-33c7-4d99-963e-a5a915464078/etc/fstab and comment out the lines that start with "LABEL=ROOTFS" and "LABEL=BOOT" by adding a hash at start of each line then add these lines to the file : /dev/mmcblk1p1 /mnt vfat defaults 0 2 /mnt/multiboot/armbian-3.14.29-mate/ /boot none bind this will fix the 0hdmi.service problem 7- unmount everything ▶ umount /dev/loop1 ▶ umount /dev/mapper/loop0p1 ▶ umount /dev/mapper/loop0p2 8-copy the system.img file to your distro folder in the second partition of your sd card ▶ cp system.img /run/media/mohammad/ROOTFS/multiboot/armbian-3.14.29-mate 9- move to your distro folder in the first partition of your sdcard: ▶ cd /run/media/mohammad/BOOT/multiboot/armbian-3.14.29-mate 10- now you need to edit the s905_autoscript.cmd file ( I use nano editor, you can use any text editor you like), you need to make two types of edits in this file - add loop=${mbpath}/system.img to the kernel arguments - add ${mbpath}/ before each of uInitrd, zImage and dtb.img so this Quote setenv kernel_loadaddr "0x11000000" setenv initrd_loadaddr "0x13000000" setenv condev "console=ttyS0,115200n8 console=tty0 no_console_suspend consoleblank=0" setenv bootargs "root=LABEL=ROOTFS rootflags=data=writeback rw ${condev} fsck.repair=yes net.ifnames=0 mac=${mac}" setenv boot_start booti ${kernel_loadaddr} ${initrd_loadaddr} ${dtb_mem_addr} if fatload usb 0 ${initrd_loadaddr} uInitrd; then if fatload usb 0 ${kernel_loadaddr} zImage; then if fatload usb 0 ${dtb_mem_addr} dtb.img; then run boot_start; else store dtb read ${dtb_mem_addr}; run boot_start;fi;fi;fi; if fatload usb 1 ${initrd_loadaddr} uInitrd; then if fatload usb 1 ${kernel_loadaddr} zImage; then if fatload usb 1 ${dtb_mem_addr} dtb.img; then run boot_start; else store dtb read ${dtb_mem_addr}; run boot_start;fi;fi;fi; if fatload usb 2 ${initrd_loadaddr} uInitrd; then if fatload usb 2 ${kernel_loadaddr} zImage; then if fatload usb 2 ${dtb_mem_addr} dtb.img; then run boot_start; else store dtb read ${dtb_mem_addr}; run boot_start;fi;fi;fi; if fatload usb 3 ${initrd_loadaddr} uInitrd; then if fatload usb 3 ${kernel_loadaddr} zImage; then if fatload usb 3 ${dtb_mem_addr} dtb.img; then run boot_start; else store dtb read ${dtb_mem_addr}; run boot_start;fi;fi;fi; if fatload mmc 0 ${initrd_loadaddr} uInitrd; then if fatload mmc 0 ${kernel_loadaddr} zImage; then if fatload mmc 0 ${dtb_mem_addr} dtb.img; then run boot_start; else store dtb read ${dtb_mem_addr}; run boot_start;fi;fi;fi; becomes this Quote setenv kernel_loadaddr "0x11000000" setenv initrd_loadaddr "0x13000000" setenv condev "console=ttyAML0,115200n8 console=tty0 no_console_suspend consoleblank=0" setenv bootargs "root=LABEL=ROOTFS loop=${mbpath}/system.img rootflags=data=writeback rw ${condev} fsck.repair=yes net.ifnames=0 mac=${mac}" setenv boot_start booti ${kernel_loadaddr} ${initrd_loadaddr} ${dtb_mem_addr} if fatload mmc 0 ${initrd_loadaddr} ${mbpath}/uInitrd; then if fatload mmc 0 ${kernel_loadaddr} ${mbpath}/zImage; then if fatload mmc 0 ${dtb_mem_addr} ${mbpath}/dtb.img; then run boot_start; else store dtb read ${dtb_mem_addr};run boot_start;fi;fi;fi; Note that I removed the lines of booting from usb to decrease the boot time because I know that I’m booting from the sd card, you can leave them if you want. 11- compile the script ▶ mkimage -A arm64 -O linux -T script -C none -d s905_autoscript.cmd s905_autoscript 12-copy the dtb file of your device ▶ cp dtb/gxbb_p200_2G.dtb dtb.img Modifying u-boot and booting: insert the sd card in the tvbox and then go to the update and backup app and select zip file to update from and choose aml_autoscript.zip that is on the root of the sd card, the device should reboot and you should now be able to use the multiboot function UPDATE: after booting into the distro disable the resize2fs service using the following command sudo systemctl disable resize2fs Notes(mostly for other developers): 1-I’m a very bad shell programmer, I mostly used snippet from stackoverflow to write the main script (bin/wselector) if you could improve the script or anything in my method that would be appreciated. 2-boot time is very good but there is always a possibility to improve it, somethings that I can think of are: -buiding a smaller kernel by disabling everything in the kernel except for the framebuffer,mmc and nand driver, fat32 and ext4 filesystem,unfortunately whenever I disable something in the kernel it fails to build -maybe building a minimum dtb file so that the kernel doesn’t spend time initializing peripherals we don’t need. -building all binaries in umbInitrd staticaly 6
zamar19 Posted April 28, 2018 Posted April 28, 2018 Great effort! Can you try using BerryBoot ARM Bootloader instead to simplify multiboot for novices?
zamar19 Posted April 28, 2018 Posted April 28, 2018 Can you make a similar tutorial for multiboot with making a separate partition for each distro on your sd card and use it to store the rootfs and other distro files? Also better explain, how to prepare multiboot sdcard for other ARM devices - what would be different as an example for Orange PI, and where to get these different files from?
MOHAMMAD HADI Posted June 15, 2018 Author Posted June 15, 2018 On 4/28/2018 at 4:48 AM, zamar19 said: Great effort! Can you try using BerryBoot ARM Bootloader instead to simplify multiboot for novices? berryboot sucks, because It uses one kernel and kernel modules for the systems you boot. So, you can't boot 3.14.29 kernel and mainline kernel at the same time
MOHAMMAD HADI Posted June 15, 2018 Author Posted June 15, 2018 On 4/28/2018 at 6:09 AM, zamar19 said: Can you make a similar tutorial for multiboot with making a separate partition for each distro on your sd card and use it to store the rootfs and other distro files? Also better explain, how to prepare multiboot sdcard for other ARM devices - what would be different as an example for Orange PI, and where to get these different files from? 2 I will update this topic with a more portable way which would boot from sdcard or USB and support booting from sdcard partitions. I was trying to make a GUI application like the raspberry pi noobs instead of the ncurses interface above but unfortunately, my c programming skills are very basic so I will keep using ncurses but with a slightly better look. If someone can write a GUI for It I would appreciate it. 1
MOHAMMAD HADI Posted June 28, 2018 Author Posted June 28, 2018 I updated the topic with the new boot manager 1
MOHAMMAD HADI Posted July 7, 2018 Author Posted July 7, 2018 I updated the image to support Ir remote so you don't need to use your keyboard 2
zamakhshary Posted September 25, 2018 Posted September 25, 2018 Nice work I tried to do it on s912 device i can see the mutiboot screen, corelec and debian server cannot complete the installation the ir remite stopped working even when i got the remote.confg file from the device itself and replaced it on sd card Please help me where have i went wrong Thx
MOHAMMAD HADI Posted September 26, 2018 Author Posted September 26, 2018 10 hours ago, zamakhshary said: tried to do it on s912 device i can see the mutiboot screen, corelec and debian server cannot complete the installation what do you mean cannot complete installation? did you replace the dtbs? you need to replace the dtb file for each system with the appropriate one for your device, for example - for coreelec go into the directory multiboot/COREELEC and then copy the correct dtb for your device from the device_trees folder to the main COREELEC folder and name it dtb.img - for Debian go into the directory multiboot/Debian_Server-3/ and copy your dtb from the dtb folder into the Debian_Server-3 rename it to dtb.img 10 hours ago, zamakhshary said: the ir remite stopped working even when i got the remote.confg file from the device itself and replaced it on sd card You replaced the main dtb.img file in the fat32 partition ? where did you get your dtb file from ? if you got the file from Coreelec then you need to disable the meson-remote node in the dts file and enable the meson-ir node and then compile the dtb file, this is because amlogic devices have two drivers for the remote, Coreelec uses the meson-remote while I used the meson-ir for simplicity. If you don't know how to edit your edit and compile device trees just give me the name of the device tree that you used and I will compile it for you Regards
zamakhshary Posted September 26, 2018 Posted September 26, 2018 On 12/15/2017 at 7:27 AM, MOHAMMAD HADI said: Dear Mohd , thank you for your support , my device is beelink GT1 ultimate , i got the DTB file from the corelec latest version , i confirmed it is the right one for my device , as i was running coreelc on it , then replaced the dtb file for both systems on SD card and on the recovery partition too , started the device it shows the mutli boot screen but i can only load android , if i tried to boot corelec , it doesnt complete the setup for the remote you are right i have no experience to do it but if you can share a link to learn me i will appreciate it thx
MOHAMMAD HADI Posted September 26, 2018 Author Posted September 26, 2018 1 hour ago, zamakhshary said: Dear Mohd , thank you for your support , my device is beelink GT1 ultimate , i got the DTB file from the corelec latest version , i confirmed it is the right one for my device , as i was running coreelc on it , then replaced the dtb file for both systems on SD card and on the recovery partition too , started the device it shows the mutli boot screen but i can only load android , if i tried to boot corelec , it doesnt complete the setup for the remote you are right i have no experience to do it but if you can share a link to learn me i will appreciate it thx looking at https://discourse.coreelec.org/t/which-dtb-do-i-use/389 I see that there are two types of GT1 ultimate gxm_q200_2g and gxm_q200_3g, which one do you use ? anyway I modified and compiled both dtbs for you https://drive.google.com/open?id=1OZmXRInsRMlF0vCUtcuQlIMNjl-sSwMm https://drive.google.com/open?id=1HRKjoRZUgYoWvuKH97kmtxivIjXHBfrM use the correct one (that you normally use for Coreelec) also please note that these dtbs (with the modified remote driver) are only to be used in the recovery partition, don't copy it to your distributions (use the dtbs of your distributions instead) Regards
zamakhshary Posted September 26, 2018 Posted September 26, 2018 1- i have burnt the SD card , changed the DTB file in the recovery partition only with the correct file for my device (gxm_q200_3g) left every thing else as it is 2- started tv box, insrted SDcard, update , reboot 3- device didnot reboot only shutdown , i started manually 4- the multi boot screen appeared chose coreelec 5- box stuck on logo screen i dont know where i went wrong , i think that the distributions are for 905 amlogic and this box is 905 appreciate your help thx
zamakhshary Posted September 26, 2018 Posted September 26, 2018 update: i changed the coreelec DTB imf to the correct one (gxm_q200_3g) booting then stops at (starting unbind framebuffer console ) after that the device reboot and doesnt boot again any ideas ?
MOHAMMAD HADI Posted September 26, 2018 Author Posted September 26, 2018 3 hours ago, zamakhshary said: update: i changed the coreelec DTB imf to the correct one (gxm_q200_3g) booting then stops at (starting unbind framebuffer console ) after that the device reboot and doesnt boot again any ideas ? sorry, no idea regarding this problem, did you try the debian distro ? Regards
zamakhshary Posted September 27, 2018 Posted September 27, 2018 The debian distro also doesnt work Is there a method where i can make my own distros to your image? as the problem is most probably related to distros
zamakhshary Posted September 30, 2018 Posted September 30, 2018 @MOHAMMAD HADI Could you please help Thx
MOHAMMAD HADI Posted September 30, 2018 Author Posted September 30, 2018 On 9/27/2018 at 9:36 PM, zamakhshary said: The debian distro also doesnt work Is there a method where i can make my own distros to your image? as the problem is most probably related to distros Well. the Debian distro included is built by 150balbes and tested by hundreds of users, so I would say the problem is in the boot menu, of course you can add your distros and the included details above explain how to do that. Unfortunately I don't understand what's going on on your device without details, if you have a Uart cable you can attach it to the box and post the log to see what's going on. Regards
Vichr Hor Posted October 23, 2018 Posted October 23, 2018 On 9/30/2018 at 8:17 PM, MOHAMMAD HADI said: Well. the Debian distro included is built by 150balbes and tested by hundreds of users, so I would say the problem is in the boot menu, of course you can add your distros and the included details above explain how to do that. Unfortunately I don't understand what's going on on your device without details, if you have a Uart cable you can attach it to the box and post the log to see what's going on. Regards Dear Mohammad, thank you very much for the image file of coreelec and Debian server, I can run it on my KII PRO without problems. I have searched for similar multiboot long time. I want to ask how can I add new system to the burned sd card (for example desktop linux (with xfce). Is it possible to simply add it or must I create new image file with all the systems and then burn the sd card once again? Thank you for your reply
Vichr Hor Posted October 24, 2018 Posted October 24, 2018 Dear Mohammad, I have tried to update Coreelec via autoupdate in Coreelec and now I can not boot in Coreelec. Can I fix it without reburning the SD card once again? Thank you. Best Regards
erbas Posted January 26, 2019 Posted January 26, 2019 @MOHAMMAD HADI Friend can tell me why I can not boot Libreelec, build balbes150 The build of it uses the new 4.x.x kernel My box and KI Pro (S905D) If I can say if it is possible, I thank you! Thank you, https://forum.libreelec.tv/thread/12330-test-libreelec-images-with-kodi-18-for-s9xxx/?postID=108875#post108875
Recommended Posts