@arrmo Slow down there chief
If you made any modifcation to loader.c, undo that. There is no reason to touch the loader's source code. Anything that starts with 0x80.... or similar refers to where it will be offloaded into RAM. This is why when you boot you see Load Address start with 0x8.
From your bootlog, kernel got placed in ram at 0x80500000, boot process moved it to top of RAM aka 0x80000000
## Booting image at 80500000 ...
Image Name: MIPS OpenWrt Linux-4.14.180
Image Type: MIPS Linux Kernel Image (uncompressed)
Data Size: 1343693 Bytes = 1.3 MB
Load Address: 80000000
Entry Point: 80000000
Verifying Checksum ... OK
OK
I think you are missing the point of the loader. It looks to me like you are just adding the loader to the kernel, instead of replacing it with the kernel.
Understand the purpose of the image commands:
loader-okli: is for making a simple loader for a compressed kernel for bootloaders that can only load uncompressed or non-lzma compressed kernels.
Example:
define Build/loader-okli
dd if=$(KDIR)/loader-$(word 1,$(1)).$(LOADER_TYPE) bs=$(word 2,$(1)) conv=sync of="$@.new"
[...]
KERNEL := kernel-bin | uImage lzma -M 0x4f4b4c49 | loader-okli $(1) 7680
Despite loader-okli being the last command, it actually places the loader in the front of the kernel (the in-file in dd is the loader, the out-file leaves space for the rest)
loader-okli-compile: is for loading a kernel in a different part of the flash, hence the variable LOADER_FLASH_OFFS (flash offset)
define Build/loader-okli-compile
$(call Build/loader-common,FLASH_OFFS=$(LOADER_FLASH_OFFS) FLASH_MAX=0)
endef
Notice how in loader-okli-compile there is not interaction with a recipe target $@
. It literally just spits out the 4 kb loader binary. This is why the loader.uImage line is necessary, since the binary by itself is not bootable.
From my commit:
COMPILE/loader-ens202ext.bin := loader-okli-compile
COMPILE/loader-ens202ext.uImage := append-loader-okli ens202ext | \
pad-to $$$$(BLOCKSIZE) | lzma | uImage lzma
This creates a uImage wrapping around the loader. This is because the bootloader is going to launch the loader ONLY, which will then find the actual kernel and launch that.
It's hard to see whats really happening unless you look at the custom factory.bin recipe engenius_ens202ext-factory
...
See that for factory.bin, we start with kernel + rootfs
IMAGE/factory.bin := append-squashfs-fakeroot-be | pad-to $$$$(BLOCKSIZE) | \
append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | \
check-size | engenius_ens202ext-factory
Everything you see here, fakeroot + the ACTUAL kernel + rootfs gets passed to engenius_ens202ext-factory
as the recipe target $@
Then:
$(CP) $(KDIR)/loader-ens202ext.uImage $@.tmp/openwrt-senao-ens202ext-uImage-lzma.bin && \
$(CP) $@ $@.tmp/openwrt-senao-ens202ext-root.squashfs && \
First line is: okli loader gets copied to the uImage-lzma.bin, this is to be booted
Second line is: the entire target $@
is copied to root.squashfs, which is "seen" by the bootloader as rootfs.
Remember the target passed to the image command is kernel + rootfs.
Therefore the partition meant for the kernel does not have the kernel at all. Rather, the space for the kernel has the loader ONLY, and the space for rootfs has kernel + rootfs. Everything is shifted over.
This is a huge waste of space until one implements the virtual_flash node.
The value I set for LOADER_FLASH_OFFS is 0x230000
This is because...
here is /proc/mtd from original software (which is actually old openwrt)
root@ENS202EXT:/# cat /proc/mtd
dev: size erasesize name
mtd0: 00040000 00010000 "u-boot"
mtd1: 00010000 00010000 "u-boot-env"
mtd2: 00050000 00010000 "custom"
mtd3: 00180000 00010000 "kernel"
mtd4: 00bd0000 00010000 "rootfs"
mtd5: 00200000 00010000 "failsafe"
mtd6: 00010000 00010000 "ART"
Here is the partition table after all the changes (from the bootlog posted earlier)
[ 0.478112] Creating 9 MTD partitions on "spi0.0":
[ 0.486305] 0x000000000000-0x000000040000 : "u-boot"
[ 0.496478] 0x000000040000-0x000000050000 : "u-boot-env"
[ 0.507339] 0x000000050000-0x0000000a0000 : "custom"
[ 0.517415] 0x0000000a0000-0x0000000b0000 : "loader"
[ 0.527672] 0x0000000b0000-0x000000220000 : "firmware2"
[ 0.538259] 0x000000220000-0x000000230000 : "fakeroot"
[ 0.548666] 0x000000230000-0x000000df0000 : "firmware1"
[ 0.559316] 0x000000df0000-0x000000ff0000 : "failsafe"
[ 0.569699] 0x000000ff0000-0x000001000000 : "art"
The bootloader always attempts to boot at 0x0a0000. This is where the kernel used to be. The old kernel partition took up 1536k (0x18) of space, which makes the next partition start at 0x220000 (0xa + 0x8 = 0x12). That partition used to be the rootfs partition. I needed 1 more block because I had to do the same thing for rootfs (a fake/substitute for rootfs). Therefore, the actual kernel starts at 0x230000 for me. Remember that offset is relative to start of flash, not relative to where the loader is.