Difference between revisions of "User:Oogwaymaki"

From PINE64
Jump to navigation Jump to search
Line 359: Line 359:
edit the new boot.text file to look like this:
edit the new boot.text file to look like this:


root@dd0f8cc09d17:/src/multiboot# cat boot.text
setenv kernel_addr_z 0x44080000


setenv bootargs loglevel=0 silent console=tty0 vt.global_cursor_default=0


if test "${volume_key}" = "up" ; then
echo "yes im here"
setenv devtype mmc
setenv devnum 0
setenv distro_bootpart 1
if load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_z} /multiboot/jumpdrive/Image.gz; then
  unzip ${kernel_addr_z} ${kernel_addr_r}
  if load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} /multiboot/jumpdrive/sun50i-a64-pinephone.dtb; then
    if load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} /multiboot/jumpdrive/initramfs.gz; then
      booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r};
    else
      booti ${kernel_addr_r} - ${fdt_addr_r};
    fi;
  fi;
fi
exit
fi
if test "${volume_key}" = "down" ; then
echo "down"
setenv bootdev 0
setenv bootargs init=/init.sh rw console=tty0 console=ttyS0,115200 no_console_suspend earlycon=uart,mmio32,0x01c28000 panic=10 consoleblank=0 loglevel=1 cma=256M PMOS_NO_OUTPUT_REDIRECT pmos_boot=/dev/mmcblk${bootdev}p1 pmos_root=/dev/mmcblk${bootdev}p3
printenv
echo Loading DTB
load mmc ${mmc_bootdev}:1 ${fdt_addr_r} /media/boot/multiboot/postmarketos/sun50i-a64-pinephone-1.1.dtb
echo Loading Initramfs
load mmc ${mmc_bootdev}:1 ${ramdisk_addr_r} /media/boot/multiboot/postmarketos/uInitrd-postmarketos-allwinner
echo Loading Kernel
load mmc ${mmc_bootdev}:1 ${kernel_addr_r} /media/boot/multiboot/postmarketos/vmlinuz-postmarketos-allwinner
gpio set 115
echo Resizing FDT
fdt addr ${fdt_addr_r}
fdt resize
echo Booting kernel
gpio set 116
gpio clear 98
booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
else
setenv devtype mmc
setenv devnum 1
setenv partnum 4
load ${devtype} ${devnum}:2 ${scriptaddr} /boot.scr
source ${scriptaddr}
fi
root@dd0f8cc09d17:/src/multiboot#
compile it:
# mkimage -C none -A arm -T script -d boot.text boot.scr




#





Revision as of 02:24, 26 June 2020


Example of it working with mobian:

https://www.youtube.com/user/enterusernamo/featured

Summary:

After following these steps:

- You'll have a Custom UBOOT (Crust ENABLED) that allows MultiBOOT Using 3 different OS's depending on key combo of volume up / volume down or none pressing on boot
- You'll be able to experiment on SD Card without Touching your EMMC
- You'll learn how to take a part a PINE PHONE IMAGE (most, and put each OS On one partition
=========================================================================================================


All the information here, has been discussed in the open source community on web sites. I have simply developed a process on how to do this on the pine phone.

We use utilities such as Cross Compilation, Uboot, Patches, which will be credited.

First step, make sure you have a cross compiler for your Computer, for particularly the arm device, you will need to download a few packages, I assume we're using Debian Linux (if your using another OS you can find similar commands by searching on the web or to make it simpler download a docker Debian image, and install the pre-requisites which I will list here for Debian)

You an also use vagrant/virtual box VMware or other virtualization platforms.


First please install these Dependencies:

apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu build-essential autoconf libtool cmake pkg-config git python-dev swig3.0 libpcre3-dev nodejs-dev crossbuild-essential-arm64 git losetup rsync

The following main sources are needed:

This will download quite a few sources needed for Uboot and existing OS's available to PinePhone

https://github.com/crust-firmware/meta.git

We will also apply this patch:

https://megous.com/git/u-boot/patch/?id=0ab6225154c3d8b74f06fb3b181b52a9a64b4602

(I will attach the one I used I had to modify the above patch to work with the code.)

The crust-firmware also says you need to download the or1k compiler:

https://musl.cc/or1k-linux-musl-cross.tgz

I suggest untarring this in the /opt folder.


1. Once you have these dependency:

# cd /usr/src
# git clone https://github.com/crust-firmware/meta.git
# cd /usr/src/meta


Edit the following file Make file 

# Cross compiler
CROSS_aarch64	 = aarch64-linux-musl-
CROSS_or1k	 = or1k-linux-musl-

# General options
DEBUG		?= 0
REPRODUCIBLE	?= 0

# Board selection
BOARD		?= pinebook



Example:

# Cross compiler
CROSS_aarch64	 =  /usr/bin/aarch64-linux-gnu-
CROSS_or1k	 = /opt/or1k-linux-musl-cross/bin/or1k-linux-musl-

# General options
DEBUG		?= 0
REPRODUCIBLE	?= 0

# Board selection
BOARD		?= pinephone

# make

(this should take a 10-30 mins depending on speed..I hope less than 30 mins!!)

After making apply the patch..

# make again

now, go to your sdcard
(use a CLEAN scard NO Partitions)

fdisk /dev/sd#
create 4 primary partitions,
the 1rst one should be the "boot" partition containing Uboot stuff, I'd suggest a gigabyte
the other 3 could be your choice

After creating partitions flash the image:

# cd build/pinephone

Do not use wrong drive, and copy exactly as this erases and puts the new Uboot on the sdcard
the first 512 sectors are partition you do NOT want to write that or you lose your partition
# dd if=u-boot-sunxi-with-spl.bin of=/dev/sdb bs=1024 seek=8 conv=sync


make sure your disk is ok


# fdisk -l
Disk model: e microSD       
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x50fdd1d4

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sdb1            2048   2099199   2097152    1G 83 Linux
/dev/sdb2         2099200  65013759  62914560   30G 83 Linux
/dev/sdb3        65013760 127928319  62914560   30G 83 Linux
/dev/sdb4       127928320 251131903 123203584 58.8G 83 Linux
root@wifirouter:/usr/src# 

If it looks like above its ok.

Lets start with the first OS were going to use:

JUMPDRIVE (allows booting the EMMC and fixing it if we break it!!!)

Download it here:

https://github.com/dreemurrs-embedded/Jumpdrive/releases/download/0.4/pine64-pinephone.img.xz


then use losetup to mount the image to copy the files needed

root@wifirouter:/home/dave# losetup -P -f pine64-pinephone.img 

it'll mount a loop back

root@wifirouter:/home/dave# ls /dev/loop0*
/dev/loop0  /dev/loop0p1

Mount there first image:

root@wifirouter:/home/dave# mkdir /media/jumpdrive
root@wifirouter:/home/dave# mount /dev/loop0p1 /media/jumpdrive/

mount the sd card:

root@wifirouter:/media# mkdir /media/boot
root@wifirouter:/media# fdisk -l

Your pine phone looks like this DO NOT TOUCH EMMC You don't need to

Disk model: e eMMC          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 4932F07F-4DC2-4A88-BEA9-6E165C4A5136

Device        Start      End  Sectors  Size Type
/dev/sda1       256     4095     3840  1.9M Linux filesystem
/dev/sda2      4097     6144     2048    1M Linux filesystem
/dev/sda3      6146    22460    16315    8M Linux filesystem
/dev/sda4     22461   153515   131055   64M Linux filesystem
/dev/sda5    153516   285156   131641 64.3M Linux filesystem
/dev/sda6    285157   416015   130859 63.9M Linux filesystem
/dev/sda7    416016   546875   130860 63.9M Linux filesystem
/dev/sda8    546876  5546875  5000000  2.4G Linux filesystem
/dev/sda9   5546876 10546875  5000000  2.4G Linux filesystem
/dev/sda10 10546876 28515591 17968716  8.6G Linux filesystem


Disk /dev/sdb: 119.8 GiB, 128579534848 bytes, 251131904 sectors
Disk model: e microSD       
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x50fdd1d4

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sdb1            2048   2099199   2097152    1G 83 Linux
/dev/sdb2         2099200  65013759  62914560   30G 83 Linux
/dev/sdb3        65013760 127928319  62914560   30G 83 Linux
/dev/sdb4       127928320 251131903 123203584 58.8G 83 Linux
root@wifirouter:/media# mount /dev/sdb1 /media/boot/
root@wifirouter:/media# cd /media/boot
root@wifirouter:/media/boot# mkdir boot

root@wifirouter:/media/boot# mkdir -p multiboot/jumpdrive
root@wifirouter:/media/boot# cp * multiboot/jumpdrive 


End result should be like this ( this is complete file)

root@wifirouter:/media/boot/multiboot/jumpdrive# ls -la
total 4988
drwxr-xr-x 2 root  root     4096 Jun 25 05:51 .
drwxr-xr-x 3 root  root     4096 Jun 25 05:46 ..
-rwxr-xr-x 1 32011 32011 3991895 Jun 25 05:45 Image.gz
-rwxr-xr-x 1 32011 32011 1068435 Jun 25 05:45 initramfs.gz
-rwxr-xr-x 1 32011 32011   33457 Jun 25 05:45 sun50i-a64-pinephone.dtb
root@wifirouter:/media/boot/multiboot/jumpdrive# pwd

Now we need to create the boot.txt for uboot to load:

Your text file should look like this:

----
setenv kernel_addr_z 0x44080000

setenv bootargs loglevel=0 silent console=tty0 vt.global_cursor_default=0

if test "${volume_key}" = "up" ; then 
echo "yes im here"
setenv devtype mmc
setenv devnum 0
setenv distro_bootpart 1
if load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_z} /multiboot/jumpdrive/Image.gz; then
  unzip ${kernel_addr_z} ${kernel_addr_r}
  if load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} /multiboot/jumpdrive/sun50i-a64-pinephone.dtb; then
    if load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} /multiboot/jumpdrive/initramfs.gz; then
      booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r};
    else
      booti ${kernel_addr_r} - ${fdt_addr_r};
    fi;
  fi;
fi
exit
fi
if test "${volume_key}" = "down" ; then 
echo "down"
ext4load mmc 0:2 ${kernel_addr_r} /boot/Image
ext4load mmc 0:2 ${fdt_addr_r} /boot/dtb/sun50i-a64-pinephone-1.2.dtb
setenv bootargs root=/dev/mmcblk0p2 rw console=ttyS0,115200 console=tty1 initrd=/boot/initrd.img quiet
booti ${kernel_addr_r} - ${fdt_addr_r} 
else
setenv devtype mmc
setenv devnum 1
setenv partnum 4
load ${devtype} ${devnum}:2 ${scriptaddr} /boot.scr
source ${scriptaddr}
fi
------

Compile the boot script:

mkimage -C none -A arm -T script -d boot.text boot.scr

# cp boot.scr /media/boot/boot

This should now be working with JumpDrive..

# Now lets download PostMarketOS

# wget http://images.postmarketos.org/pinephone/pine-pinephone-20200624-phosh-crust.img.xz

root@wifirouter:/home/dave# unxz pine-pinephone-20200624-phosh-crust.img.xz
root@wifirouter:/home/dave# losetup -P -f pine-pinephone-20200624-phosh-crust.img

root@wifirouter:/home/dave# ls /dev/loop1*
/dev/loop1  /dev/loop1p1  /dev/loop1p2

root@wifirouter:/home/dave# mount /dev/loop1p1 /media/postmarketboot/
root@wifirouter:/home/dave# mount /dev/loop1p2 /media/postmarket/

root@wifirouter:/home/dave# fdisk -l /dev/loop1

Disk /dev/loop1: 1.4 GiB, 1504706560 bytes, 2938880 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0eef1887

Device       Boot  Start     End Sectors  Size Id Type
/dev/loop1p1 *      2048  249855  247808  121M 83 Linux
/dev/loop1p2      249856 2938879 2689024  1.3G 83 Linux
root@wifirouter:/home/dave# 

root@wifirouter:/media# ls -la /media/postmarketboot/
total 40202
drwxr-xr-x  3 root root     1024 Jun 24 08:40 .
drwxr-xr-x 16 root root     4096 Jun 25 21:24 ..
-rw-r--r--  1 root root      949 Jun 17 05:19 boot.scr
-rw-r--r--  1 root root  1431266 Jun 24 08:40 initramfs-postmarketos-allwinner
-rw-r--r--  1 root root  6875596 Jun 24 08:40 initramfs-postmarketos-allwinner-extra
drwx------  2 root root    12288 Jun 24 08:42 lost+found
-rw-r--r--  1 root root    33835 Jun 24 08:40 sun50i-a64-pinephone-1.1.dtb
-rw-r--r--  1 root root 15601736 Jun 24 08:40 uImage-postmarketos-allwinner
-rw-r--r--  1 root root  1431330 Jun 24 08:40 uInitrd-postmarketos-allwinner
-rw-r--r--  1 root root 15601672 Jun 21 16:57 vmlinuz-postmarketos-allwinner
root@wifirouter:/media# 

Take a look at how the boot.scr works with postmarketos:

oot@wifirouter:/media# cat /media/postmarketboot/boot.scr 
'Vi?_^??;u??npostmarketosmgpio set 98
gpio set 114

if test ${mmc_bootdev} -eq 0 ; then
	echo "Booting from SD";
	setenv bootdev 0;
else
	echo "Booting from eMMC";
	setenv bootdev 2;
fi;

setenv bootargs init=/init.sh rw console=tty0 console=ttyS0,115200 no_console_suspend earlycon=uart,mmio32,0x01c28000 panic=10 consoleblank=0 loglevel=1 cma=256M PMOS_NO_OUTPUT_REDIRECT pmos_boot=/dev/mmcblk${bootdev}p1 pmos_root=/dev/mmcblk${bootdev}p2

printenv

echo Loading DTB
load mmc ${mmc_bootdev}:1 ${fdt_addr_r} sun50i-a64-pinephone-1.1.dtb

echo Loading Initramfs
load mmc ${mmc_bootdev}:1 ${ramdisk_addr_r} uInitrd-postmarketos-allwinner

echo Loading Kernel
load mmc ${mmc_bootdev}:1 ${kernel_addr_r} vmlinuz-postmarketos-allwinner

gpio set 115

echo Resizing FDT
fdt addr ${fdt_addr_r}
fdt resize

echo Booting kernel
gpio set 116
gpio clear 98
booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}


=========

# mkdir -p /media/boot/multiboot/postmarketos/
# cd /media/postmarketbootl
# cp -r * /media/boot/multiboot/postmarketos/

# mkfs.ext4 /dev/sdb#
# mkdir -p /media/newpostmarketbin
# mount /dev/sdb# /media/newpostmarketbin
# cd /media/postmarketos
# rsync -avh * /media/newpostmarketbin

now edit the boot.text

to reflect the changes of the images




edit the new boot.text file to look like this:

root@dd0f8cc09d17:/src/multiboot# cat boot.text 
setenv kernel_addr_z 0x44080000

setenv bootargs loglevel=0 silent console=tty0 vt.global_cursor_default=0

if test "${volume_key}" = "up" ; then 
echo "yes im here"
setenv devtype mmc
setenv devnum 0
setenv distro_bootpart 1
if load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_z} /multiboot/jumpdrive/Image.gz; then
  unzip ${kernel_addr_z} ${kernel_addr_r}
  if load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} /multiboot/jumpdrive/sun50i-a64-pinephone.dtb; then
    if load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} /multiboot/jumpdrive/initramfs.gz; then
      booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r};
    else
      booti ${kernel_addr_r} - ${fdt_addr_r};
    fi;
  fi;
fi
exit
fi
if test "${volume_key}" = "down" ; then 
echo "down"

setenv bootdev 0
setenv bootargs init=/init.sh rw console=tty0 console=ttyS0,115200 no_console_suspend earlycon=uart,mmio32,0x01c28000 panic=10 consoleblank=0 loglevel=1 cma=256M PMOS_NO_OUTPUT_REDIRECT pmos_boot=/dev/mmcblk${bootdev}p1 pmos_root=/dev/mmcblk${bootdev}p3

printenv

echo Loading DTB
load mmc ${mmc_bootdev}:1 ${fdt_addr_r} /media/boot/multiboot/postmarketos/sun50i-a64-pinephone-1.1.dtb

echo Loading Initramfs
load mmc ${mmc_bootdev}:1 ${ramdisk_addr_r} /media/boot/multiboot/postmarketos/uInitrd-postmarketos-allwinner

echo Loading Kernel
load mmc ${mmc_bootdev}:1 ${kernel_addr_r} /media/boot/multiboot/postmarketos/vmlinuz-postmarketos-allwinner

gpio set 115

echo Resizing FDT
fdt addr ${fdt_addr_r}
fdt resize

echo Booting kernel
gpio set 116
gpio clear 98
booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}

else
setenv devtype mmc
setenv devnum 1
setenv partnum 4
load ${devtype} ${devnum}:2 ${scriptaddr} /boot.scr
source ${scriptaddr}
fi


root@dd0f8cc09d17:/src/multiboot# 

compile it:

# mkimage -C none -A arm -T script -d boot.text boot.scr






Sites Referenced/Inspiration:

https://www.96boards.org/documentation/iot/
https://github.com/dreemurrs-embedded/Jumpdrive
https://github.com/dreemurrs-embedded/Pineloader
https://www.thegeekstuff.com/2014/12/patch-command-examples/
https://stackoverflow.com/questions/9980186/how-to-create-a-patch-for-a-whole-directory-to-update-it
https://courses.linuxchix.org/kernel-hacking-2002/11-creating-applying-and-submitting-patches.html

patch from the link above to work: