Need help to make the appropriate amendments to my makefile mt7620.mk
. If we write the following, it overwrites the existing macros for KERNEL, right?:
KERNEL := $(KERNEL_DTB) | etc
xyz-initramfs-kernel.bin boots fine via TFTP when it's built with:
KERNEL := $(KERNEL_DTB) | uImage lzma
Presumably because the vmlinux-initramfs
which goes in at the start is kosher.
I'm trying to produce a factory.bin
which will pass the OEM firmware's pre-upgrade checks. I need these steps in this order (according to OEM makefile):
- build vmlinux as normal
- lzma it
( this is $(KERNEL_DTB)
)
- append magic string
xYz
- pad the above to specific kernel size
- append ramfs (I suppose rootfs, also)
- pad the above to specific image size
- run mkimage or uImage to prepend the 64 byte header
When I supply any of these images to tftp boot them - they boot (only outputting Starting kernel ...
if I choose vmlinux and not vmlinux-initramfs) or reset depending on what's wrong. Help?
I've been trawling the other makefiles and commands - I'm none the wiser.
So, my makefile portion:
define Device/zyxel_wre6505
MTK_SOC := mt7620a
# image size is 3977216, less 64 byte mkimage haeder
IMAGE_SIZE:= 3977152
# kernel size must be 1179648 (0x120000) bytes, less 64 byte mkimage header
KRNL_SIZE := 1179584
DEVICE_VENDOR := ZyXEL
DEVICE_MODEL := WRE650
KERNEL := $(KERNEL_DTB) | append-string-newline EdI0412zYx | pad-to 1179584
IMAGES += factory.bin
IMAGE/factory.bin:= append-kernel | append-rootfs | pad-to $$$$(IMAGE_SIZE) | uImage lzma
DEVICE_PACKAGES := ...
SUPPORTED_DEVICES += zyxel_wre6505
endef
TARGET_DEVICES += zyxel_wre6505
This briefly (tftp)boots and resets:
done
Bytes transferred = 3977216 (3cb000 hex)
NetBootFileXferSize= 003cb000
Automatic boot of image at addr 0x80A00000 ...
## Booting image at 80a00000 ...
Image Name: MIPS OpenWrt Linux-4.14.134
Image Type: MIPS Linux Kernel Image (lzma compressed)
Data Size: 3977152 Bytes = 3.8 MB
Load Address: 80000000
Entry Point: 80000000
Verifying Checksum ... OK
Uncompressing Kernel Image ... OK
No initrd
## Transferring control to Linux (at address 80000000) ...
## Giving linux memsize in MB, 64
Starting kernel ...
U-Boot 1.1.3 (Apr 13 2015 - 19:08:43)
I realise that rootfs and ramfs are not the same thing - how do I reconcile this?
Here's the OEM makefile:
KERNELZ = $(IMAGEDIR)/zImage
RAMDISK = $(IMAGEDIR)/ramdisk
IMAGE = $(IMAGEDIR)/$(USER)_uImage
ROMFS_DIR = $(ROOTDIR)/romfs
RAMDISK_SIZE := $(shell echo $(CONFIG_BLK_DEV_RAM_SIZE))
MKIMAGE_DIR = $(ROOTDIR)/user/mkimage
CUR_DIR = $(shell pwd)
COMP = lzma
ROMFS_DIRS = \
tmp \
bin \
dev dev/pts \
home \
etc \
etc_ro etc_ro/web etc_ro/ppp etc_ro/ppp/peers etc_ro/ppp/plugins etc_ro/ppp/3g \
etc_ro/wlan etc_ro/Wireless etc_ro/xml etc_ro/usb \
etc_ro/linuxigd etc_ro/Wireless/RT2860AP etc_ro/Wireless/RT61AP etc_ro/Wireless/iNIC \
lib lib/modules lib/ipsec \
mnt \
proc \
sbin \
sys \
media \
usr usr/bin usr/sbin usr/codepages \
var
clean:
rm -f mkimage
romfs:
[ -d $(ROMFSDIR)/$$i ] || mkdir -p $(ROMFSDIR)
for i in $(ROMFS_DIRS); do \
[ -d $(ROMFSDIR)/$$i ] || mkdir -p $(ROMFSDIR)/$$i; \
done
#generate device node
ifneq ($(LINUXDIR),linux-2.4.x)
@if [ \! -d $(ROMFSDIR)/dev ];then mkdir -p $(ROMFSDIR)/dev;fi;
./makedevlinks $(ROMFSDIR)
endif
$(ROMFSINST) /etc_ro/rcS
$(ROMFSINST) /etc_ro/inittab
$(ROMFSINST) /etc_ro/motd
$(ROMFSINST) /etc/fstab
$(ROMFSINST) /etc_ro/wlan/MT7620_AP_2T2R-4L_V13.BIN
$(ROMFSINST) /etc_ro/Wireless/RT2860AP/RT2860_default_novlan
$(ROMFSINST) /etc_ro/Wireless/RT2860AP/RT2860_default_vlan
$(ROMFSINST) /etc_ro/Wireless/iNIC/RT2860AP.dat
$(ROMFSINST) -e CONFIG_RT2860V2_AP_RBUS_PCI_COEX_SUPPORT /etc_ro/Wireless/RT2860APCard.dat
$(ROMFSINST) -e CONFIG_RT5592_AP /etc_ro/Wireless/iNIC/RT5592_PCIe_2T2R_V1_7.bin
$(ROMFSINST) -e CONFIG_RT5592_AP_INCLUDE /etc_ro/Wireless/iNIC/RT5592_PCIe_2T2R_V1_7.bin
romfs.post::
@cp -af drivers $(ROMFSDIR)/lib/modules/2.6.36/kernel/
@cp -af gpio $(ROMFSDIR)/bin/
@cp -af mii_mgr $(ROMFSDIR)/bin/
[ -d $(IMAGEDIR) ] || mkdir -p $(IMAGEDIR)
#Squash File System
rm -f $(RAMDISK)
ifeq ($(LINUXDIR),linux-2.4.x)
$(CONFIG_CROSS_COMPILER_PATH)/mksquashfs_lzma-3.0 $(ROMFSDIR) $(RAMDISK)
else
#linux2.6.x support squashfs with lzma
ifeq ($(CONFIG_BLK_DEV_INITRD),)
ifeq ($(LINUXDIR),linux-2.6.21.x)
$(CONFIG_CROSS_COMPILER_PATH)/mksquashfs_lzma-3.2 $(ROMFSDIR) $(RAMDISK)
endif
ifeq ($(LINUXDIR),linux-2.6.36MT.x)
$(CONFIG_CROSS_COMPILER_PATH)/mksquashfs_lzma-4.2 $(ROMFSDIR) $(RAMDISK)
endif
ifeq ($(LINUXDIR),linux-2.6.36.x)
$(CONFIG_CROSS_COMPILER_PATH)/mksquashfs_lzma-4.2 $(ROMFSDIR) $(RAMDISK)
endif
endif
endif
ifeq ($(CONFIG_BLK_DEV_INITRD),y)
ifeq ($(LINUXDIR),linux-2.4.x)
gzip -9 -f $(RAMDISK)
cp $(RAMDISK).gz $(ROOTDIR)/$(LINUXDIR)/arch/mips/ramdisk/ramdisk.gz 2>/dev/null
endif
endif
mkimage: $(MKIMAGE_DIR)/crc32.c $(MKIMAGE_DIR)/mkimage.c
$(HOSTCC) $(HOST_CFLAGS) -DUSE_HOSTCC -o $@ -I$(MKIMAGE_DIR)/include $^
image: mkimage
$(CROSS_COMPILE)objcopy -O binary -R .note -R .comment -S $(ROOTDIR)/$(LINUXDIR)/vmlinux $(KERNELZ)
cd $(IMAGEDIR) ; rm -f $(KERNELZ).*; $(COMP) -9 -f -S .$(COMP) $(KERNELZ)
ifeq ($(CONFIG_BLK_DEV_INITRD),)
ifeq ($(CONFIG_ROOTFS_IN_FLASH_NO_PADDING),)
@#============================================================
@# uboot hdr(64B) + mtdblock0(192KB) + mtdblock1(64KB) +
@# mtdblock2(64KB) + mtdblock3 + mtdblock4 + mtdblock5
@#
@# Padding size of mtdblock3 is equal to "MTD_KRN_PART_SIZE
@# - 64B - the size of compressed kernel image"
@#
@# In Other Words:
@# MTD Kernel Partition Size is MUST bigger than
@# "Original Kernel Image Size + 64B"
@#============================================================
#========<< This is README not Warning Message>>==============
# Please make sure that original kernel image size can't
# bigger or equal to Kernel Partition Size.
#
# For Example:
#
# Original kernel image size is 563421 Bytes(0x898DD Bytes).
# Flash sector size is 0x10000, so MTD kernel
# partition size MUST bigger than 0x90000.
#
# #make menuconfig
#
# Kernel/Library/Defaults Selection --->
# [*] Customize Kernel Settings (NEW)
# Machine selection --->
# (90000) MTD Kernel Partition Size (Unit:Bytes)
#=============================================================
# Original Kernel Image Size
# EDIMAX: Arvin add
@cp -f $(KERNELZ).$(COMP) $(KERNELZ).$(COMP).org
@echo "EdI0412zYx" >> $(KERNELZ).$(COMP)
@wc -c $(KERNELZ).$(COMP)
# Padded Kernel Image Size
ifeq ($(findstring 0x, $(CONFIG_MTD_KERNEL_PART_SIZ)),0x)
@SIZE=`wc -c $(KERNELZ).$(COMP) | awk '{ print $$1 }'` ; \
MTD_KRN_PART_SIZE=`printf "%d" $(CONFIG_MTD_KERNEL_PART_SIZ)` ; \
PAD=`expr $$MTD_KRN_PART_SIZE - 64 - $$SIZE` ; \
dd if=/dev/zero count=1 bs=$$PAD 2> /dev/null | tr \\000 \\377 >> $(KERNELZ).$(COMP)
else
@SIZE=`wc -c $(KERNELZ).$(COMP) | awk '{ print $$1 }'` ; \
MTD_KRN_PART_SIZE=`printf "%d" 0x$(CONFIG_MTD_KERNEL_PART_SIZ)` ; \
PAD=`expr $$MTD_KRN_PART_SIZE - 64 - $$SIZE` ; \
dd if=/dev/zero count=1 bs=$$PAD 2> /dev/null | tr \\000 \\377 >> $(KERNELZ).$(COMP)
endif
endif
@wc -c $(KERNELZ).$(COMP)
# Original RootFs Size
@du -sb $(ROMFSDIR)
# Compressed RootFs Size
@wc -c $(RAMDISK)
# Padded Kernel Image + Compressed Rootfs Size
@cat $(RAMDISK) >> $(KERNELZ).$(COMP)
@wc -c $(KERNELZ).$(COMP)
#===========================================
endif
ifeq ($(CONFIG_ROOTFS_IN_FLASH_NO_PADDING),y)
@cd $(IMAGEDIR) ; \
ISIZE=`wc -c $(KERNELZ).$(COMP) | awk '{print $$1}'` ; \
RSIZE=`wc -c $(RAMDISK) | awk '{print $$1}'` ; \
KRN_SIZE=`expr $$ISIZE - $$RSIZE + 64` ; \
ENTRY=`readelf -h $(ROOTDIR)/$(LINUXDIR)/vmlinux | grep "Entry" | awk '{print $$4}'` ; \
$(CUR_DIR)/mkimage -A mips -O linux -T kernel -C $(COMP) -a 80000000 -e $$ENTRY -k $$KRN_SIZE -n "Linux Kernel Image" -d $(KERNELZ).$(COMP) $(IMAGE)
else
@cd $(IMAGEDIR) ; $(CUR_DIR)/mkimage -A mips -O linux -T kernel -C $(COMP) -a 80000000 -e $(shell readelf -h $(ROOTDIR)/$(LINUXDIR)/vmlinux | grep "Entry" | awk '{print $$4}') -n "Linux Kernel Image" -d $(KERNELZ).$(COMP) $(IMAGE)
endif