Ysurac / openmptcprouter-vps

OpenMPTCProuter VPS scripts
GNU General Public License v3.0
154 stars 68 forks source link

Added support U-Boot for OMR-VPS #94

Open GermanAizek opened 7 months ago

GermanAizek commented 7 months ago

@Ysurac, Since there have already been 2 issues (https://github.com/Ysurac/openmptcprouter/issues/3137 and https://github.com/Ysurac/openmptcprouter/issues/3148) about possibility using VPS on systems with u-boot loader, most devices are routers, switches, single-board computers and mini-PCs. I decided to help you with porting, and so let's get started:

  1. this conditional block

https://github.com/Ysurac/openmptcprouter-vps/blob/c0c962700743545da6cdefa3de73415a99e6fd63/debian9-x86_64.sh#L370C1-L379C3

functionally, I don't know shell well, I'm more into programming languages, but it should look something like this

if [ -z "$(dpkg-query -l | grep grub)" ]; then
    if [ -d /boot/grub2 ]; then
        apt-get -y install grub2
    elif [ -d /boot/grub ]; then
        apt-get -y install grub-legacy
    fi
    if [ -n "$(grep 'net.ifnames=0' /boot/grub/grub.cfg)" ] && [ ! -f /etc/default/grub ]; then
        echo 'GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"' > /etc/default/grub
    elif [ ! -f /boot/boot.cmd ]; then
                # edit bootargs variable in /boot/boot.cmd - append `net.ifnames=0 biosdevname=0` to it, but not at end.
                # when I added parameters to end, initramfs reported broken bootargs parameters.
                mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
        fi
fi

more info: https://superuser.com/questions/1209732/grub-cmdline-linux-analogue-for-u-boot

R-sajadi commented 7 months ago

The following occurred during the installation process:

1) Saving to: 'STDOUT'

                          85%[==========================================>        ]  72.00K  83.3KB/s               

Check user... why 85% dowload?

2)Get:1 http://security.debian.org/debian-security bookworm-security InRelease [48.0 kB] Hit:2 http://deb.debian.org/debian bookworm InRelease Get:3 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB] why Hit?

3)Failed to stop iperf3.service: Unit iperf3.service not loaded.

4) Processing triggers for man-db (2.11.2-2) ... Processing triggers for libc-bin (2.36-9+deb12u4) ... WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

-- pip3 install needed python modules If you see any error here, I really don't care: it's about a module not used for home users WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. netjsonconfig 1.0.2 requires jsonschema~=4.4.0, but you have jsonschema 4.21.1 which is incompatible. WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. netjsonconfig 1.0.2 requires jinja2~=3.0.0, but you have jinja2 3.1.3 which is incompatible. netjsonconfig 1.0.2 requires jsonschema~=4.4.0, but you have jsonschema 4.21.1 which is incompatible. WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv --2024-02-06 11:04:03-- https://www.openmptcprouter.com/server-test/omr-admin.service.in Resolving www.openmptcprouter.com (www.openmptcprouter.com)... 138.199.46.68, 2400:52e0:1500::868:1 Connecting to www.openmptcprouter.com (www.openmptcprouter.com)|138.199.46.68|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 338 [application/octet-stream] Saving to: '/lib/systemd/system/omr-admin.service'

/lib/systemd/system/omr-admin. 100%[==================================================>] 338 --.-KB/s in 0s

2024-02-06 11:04:04 (115 MB/s) - '/lib/systemd/system/omr-admin.service' saved [338/338]

--2024-02-06 11:04:04-- https://www.openmptcprouter.com/server-test/omr-admin-ipv6.service.in Resolving www.openmptcprouter.com (www.openmptcprouter.com)... 138.199.46.68, 2400:52e0:1500::868:1 Connecting to www.openmptcprouter.com (www.openmptcprouter.com)|138.199.46.68|:443... connected. GnuTLS: The TLS connection was non-properly terminated. Unable to establish SSL connection.

GermanAizek commented 7 months ago

2)Get:1 http://security.debian.org/debian-security bookworm-security InRelease [48.0 kB] Hit:2 http://deb.debian.org/debian bookworm InRelease Get:3 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]

In my case, everything was successfully installed, but kernel does not start because there is no u-boot configuration. In your case, I would try to replace http with https, or specify debian repos mirrors. In my country, there are no blocks linux repositories, on contrary, microsoft can be blocked in our country, but linux this is sacred.

R-sajadi commented 7 months ago

Thanks for your reply and help, let's try to run VPS on Raspberry Pi

R-sajadi commented 7 months ago

@Ysurac, Since there have already been 2 issues (Ysurac/openmptcprouter#3137 and Ysurac/openmptcprouter#3148) about possibility using VPS on systems with u-boot loader, most devices are routers, switches, single-board computers and mini-PCs. I decided to help you with porting, and so let's get started:

  1. this conditional block

https://github.com/Ysurac/openmptcprouter-vps/blob/c0c962700743545da6cdefa3de73415a99e6fd63/debian9-x86_64.sh#L370C1-L379C3

functionally, I don't know shell well, I'm more into programming languages, but it should look something like this

if [ -z "$(dpkg-query -l | grep grub)" ]; then
  if [ -d /boot/grub2 ]; then
      apt-get -y install grub2
  elif [ -d /boot/grub ]; then
      apt-get -y install grub-legacy
  fi
  if [ -n "$(grep 'net.ifnames=0' /boot/grub/grub.cfg)" ] && [ ! -f /etc/default/grub ]; then
      echo 'GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"' > /etc/default/grub
  elif [ ! -f /boot/boot.cmd ]; then
                # edit bootargs variable in /boot/boot.cmd - append `net.ifnames=0 biosdevname=0` to it, but not at end.
                # when I added parameters to end, initramfs reported broken bootargs parameters.
                mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
        fi
fi

more info: https://superuser.com/questions/1209732/grub-cmdline-linux-analogue-for-u-boot

Did you make these changes to configure u boot, was the result successful?

GermanAizek commented 7 months ago

@Ysurac,

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

there is problem in command for debian9-x86_64.sh, -A parameter specifies architecture arm - armhf, arm64 - arm64. How can I get this behavior using shell? $(dpkg --print-architecture) not suitable, it can return armhf or arm64

image

GermanAizek commented 7 months ago

Did you make these changes to configure u boot, was the result successful?

There is no result, we still need to rewrite script so that it works on both bootloaders.

Ysurac commented 7 months ago

I think we can always use arm64 now. What do you have in /boot/boot.cmd ?

GermanAizek commented 7 months ago

I think we can always use arm64 now. What do you have in /boot/boot.cmd ?

I just saw comment that shouldn't be edited boot.cmd , there is .txt

orangepi@orangepi3-lts:~$ cat /boot/boot.cmd 
# DO NOT EDIT THIS FILE
#
# Please edit /boot/orangepiEnv.txt to set supported parameters
#

# default values
setenv load_addr "0x45000000"
setenv overlay_error "false"
setenv rootdev "/dev/mmcblk0p1"
setenv verbosity "1"
setenv rootfstype "ext4"
setenv console "both"
setenv docker_optimizations "on"
setenv bootlogo "false"

# Print boot source
itest.b *0x10028 == 0x00 && echo "U-boot loaded from SD"
itest.b *0x10028 == 0x02 && echo "U-boot loaded from eMMC or secondary SD"
itest.b *0x10028 == 0x03 && echo "U-boot loaded from SPI"

echo "Boot script loaded from ${devtype}"

if test -e ${devtype} ${devnum} ${prefix}orangepiEnv.txt; then
        load ${devtype} ${devnum} ${load_addr} ${prefix}orangepiEnv.txt
        env import -t ${load_addr} ${filesize}
fi

if test "${console}" = "display" || test "${console}" = "both"; then setenv consoleargs "console=ttyS0,115200 console=tty1"; fi
if test "${console}" = "serial"; then setenv consoleargs "console=ttyS0,115200"; fi
if test "${bootlogo}" = "true"; then setenv consoleargs "bootsplash.bootfile=bootsplash.orangepi ${consoleargs}"; fi

# get PARTUUID of first partition on SD/eMMC it was loaded from
# mmc 0 is always mapped to device u-boot (2016.09+) was loaded from
if test "${devtype}" = "mmc"; then part uuid mmc 0:1 partuuid; fi

setenv bootargs "root=${rootdev} rootwait net.ifnames=0 biosdevname=0 rootfstype=${rootfstype} ${consoleargs} consoleblank=0 loglevel=${verbosity} ubootpart=${partuuid} usb-storage.quirks=${usbstoragequirks} ${extraargs} ${extraboardargs}"

if test "${docker_optimizations}" = "on"; then setenv bootargs "${bootargs} cgroup_enable=memory swapaccount=1"; fi

load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}dtb/${fdtfile}
fdt addr ${fdt_addr_r}
fdt resize 65536
for overlay_file in ${overlays}; do
        if load ${devtype} ${devnum} ${load_addr} ${prefix}dtb/allwinner/overlay/${overlay_prefix}-${overlay_file}.dtbo; then
                echo "Applying kernel provided DT overlay ${overlay_prefix}-${overlay_file}.dtbo"
                fdt apply ${load_addr} || setenv overlay_error "true"
        fi
done
for overlay_file in ${user_overlays}; do
        if load ${devtype} ${devnum} ${load_addr} ${prefix}overlay-user/${overlay_file}.dtbo; then
                echo "Applying user provided DT overlay ${overlay_file}.dtbo"
                fdt apply ${load_addr} || setenv overlay_error "true"
        fi
done
if test "${overlay_error}" = "true"; then
        echo "Error applying DT overlays, restoring original DT"
        load ${devtype} ${devnum} ${fdt_addr_r} ${prefix}dtb/${fdtfile}
else
        if load ${devtype} ${devnum} ${load_addr} ${prefix}dtb/allwinner/overlay/${overlay_prefix}-fixup.scr; then
                echo "Applying kernel provided DT fixup script (${overlay_prefix}-fixup.scr)"
                source ${load_addr}
        fi
        if test -e ${devtype} ${devnum} ${prefix}fixup.scr; then
                load ${devtype} ${devnum} ${load_addr} ${prefix}fixup.scr
                echo "Applying user provided fixup script (fixup.scr)"
                source ${load_addr}
        fi
fi

load ${devtype} ${devnum} ${ramdisk_addr_r} ${prefix}uInitrd
load ${devtype} ${devnum} ${kernel_addr_r} ${prefix}Image

booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}

# Recompile with:
# mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
orangepi@orangepi3-lts:~$ cat /boot/orangepiEnv.txt
verbosity=1
bootlogo=false
console=both
disp_mode=1920x1080p60
overlay_prefix=sun50i-h6
rootdev=UUID=5ce619d5-0a9b-4295-8436-014d19a33fb6
rootfstype=ext4
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u
GermanAizek commented 7 months ago

@Ysurac

orangepi@orangepi3-lts:~$ uname -a
Linux orangepi3-lts 5.16.17-sun50iw6 #3.0.8 SMP Tue Sep 6 20:11:50 CST 2022 aarch64 GNU/Linux
Ysurac commented 7 months ago

For u-boot, I think data can be added via an "extraargs" variables in orangepiEnv.txt For kernel, should work with 5.16 but far better with at least a 6.1. Maybe there is an unofficial kernel somewhere ?

GermanAizek commented 7 months ago

For u-boot, I think data can be added via an "extraargs" variables in orangepiEnv.txt For kernel, should work with 5.16 but far better with at least a 6.1. Maybe there is an unofficial kernel somewhere ?

I know only one mainline kernel, where author was able to return pci express support port on Orange Pi 3 (not LTS), which authors themselves broke and did not fix anymore.

https://github.com/ingamedeo/orangepi3-h6-mainline

GermanAizek commented 7 months ago

unnamed

GermanAizek commented 7 months ago

They did not fix problem with port and then removed connector itself, only orangepi 3 have been pci-e

GermanAizek commented 7 months ago

@Ysurac, I can try to get version up to 6.1, but I think there will be a lot merge conflicts, but I have no experience.

GermanAizek commented 7 months ago

@Ysurac, I didn't notice something, but there is already 6.3.9

the experimental/ folder contains a new PCIe sunxi module, gmac patches and a dts for newer kernels.

image