imx6: convert ventana images to squashfs+ubifs overlay
[openwrt.git] / target / linux / imx6 / image / Makefile
index aad1527..a4de7d9 100644 (file)
 include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/image.mk
 
-BOARDS := \
-       imx6dl-wandboard \
-       imx6q-gw5400-a
+#################################################
+# Images
+#################################################
 
-# emit FIT images, DTB's and generic zImage
-define Image/BuildKernel
-       $(foreach board,$(BOARDS),
-               cp $(LINUX_DIR)/arch/arm/boot/dts/$(board).dtb $(BIN_DIR)/$(IMG_PREFIX)-$(board).dtb
+# build a ubi for a specific flash geometry/layout which can contain
+# volumes with the following data from ubinize-$(DEVICE_NAME).cfg:
+#   - 'boot.ubifs' volume: kernel+dtbs+bootscript
+#   - 'root.squashfs' volume: rootfs
+# $(1): name (used for suffix)
+# $(2): PAGESIZE (-m param to mkfs.ubifs/ubinize)
+# $(3): ERASESIZE (logical eraseblock size: -e param to mkfs.ubifs)
+# $(4): BLOCKSIZE (-p param to ubinize)
+# $(5): MAXSIZE (maximum file-system size in LEB's -c param to mkfs.ubifs)
+#
+define Build/ubi-boot-overlay
+       # ubi-boot-overlay $(DEVICE_NAME) $(word 1, $(1))
 
-               $(call Image/BuildKernel/MkFIT,$(board),$(KDIR)/zImage,$(BIN_DIR)/$(IMG_PREFIX)-$(board).dtb,none,0x10008000,0x10008000)
-               cp $(KDIR)/fit-$(board).itb $(BIN_DIR)/$(IMG_PREFIX)-$(board)-uImage.itb
+       # boot filesystem
+       rm -rf $(TARGET_ROOTFS_DIR)/boot-$(DEVICE_NAME)_$(word 1, $(1))
+       mkdir -p $(TARGET_ROOTFS_DIR)/boot-$(DEVICE_NAME)_$(word 1, $(1))
+       $(CP) $< $(TARGET_ROOTFS_DIR)/boot-$(DEVICE_NAME)_$(word 1, $(1))/$(IMG_PREFIX)-uImage
+       ln -sf $(IMG_PREFIX)-uImage \
+               $(TARGET_ROOTFS_DIR)/boot-$(DEVICE_NAME)_$(word 1, $(1))/uImage
+       $(foreach dts,$(shell echo $(DEVICE_DTS)), \
+               $(CP) $(LINUX_DIR)/arch/$(ARCH)/boot/dts/$(dts).dtb \
+                       $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
+               $(CP) $(LINUX_DIR)/arch/$(ARCH)/boot/dts/$(dts).dtb \
+                       $(TARGET_ROOTFS_DIR)/boot-$(DEVICE_NAME)_$(word 1, $(1))/$(IMG_PREFIX)-$(dts).dtb; \
+               ln -sf $(IMG_PREFIX)-$(dts).dtb \
+                       $(TARGET_ROOTFS_DIR)/boot-$(DEVICE_NAME)_$(word 1, $(1))/$(dts).dtb; \
+       )
+       mkimage -A arm -O linux -T script -C none -a 0 -e 0 \
+               -n '$(DEVICE_ID) OpenWrt bootscript' \
+               -d ./bootscript-$(DEVICE_NAME) \
+               $(TARGET_ROOTFS_DIR)/boot-$(DEVICE_NAME)_$(word 1, $(1))/6x_bootscript-$(DEVICE_NAME)
+       $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
+               --space-fixup --force-compr=zlib --squash-uids \
+               -m $(word 2, $(1)) -e $(word 3, $(1)) -c $(word 5, $(1)) \
+               -o $(KDIR)/boot-$(DEVICE_NAME)-bootfs_$(word 1, $(1)).ubifs \
+               -d $(TARGET_ROOTFS_DIR)/boot-$(DEVICE_NAME)_$(word 1, $(1))
+       $(CP) $(KDIR)/boot-$(DEVICE_NAME)-bootfs_$(word 1, $(1)).ubifs \
+               $(BIN_DIR)/$(IMG_PREFIX)-$(DEVICE_NAME)-bootfs_$(word 1, $(1)).ubifs
 
- ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
-               $(call Image/BuildKernel/MkFIT,$(board),$(KDIR)/zImage-initramfs,$(BIN_DIR)/$(IMG_PREFIX)-$(board).dtb,none,0x10008000,0x10008000,-initramfs)
-               cp $(KDIR)/fit-$(board)-initramfs.itb $(BIN_DIR)/$(IMG_PREFIX)-$(board)-uImage-initramfs.itb
- endif
+       # ubi
+       rm -rf p $(KDIR)/$(DEVICE_NAME)_$(word 1, $(1))
+       mkdir -p $(KDIR)/$(DEVICE_NAME)_$(word 1, $(1))
+       $(CP) $(word 2, $^) \
+               $(KDIR)/$(DEVICE_NAME)_$(word 1, $(1))/
+       $(CP) $(KDIR)/boot-$(DEVICE_NAME)-bootfs_$(word 1, $(1)).ubifs \
+               $(KDIR)/$(DEVICE_NAME)_$(word 1, $(1))/boot.ubifs
+       $(CP) ./ubinize-$(DEVICE_NAME).cfg \
+               $(KDIR)/$(DEVICE_NAME)_$(word 1, $(1))/ubinize.cfg
+       ( cd $(KDIR)/$(DEVICE_NAME)_$(word 1, $(1)); \
+               $(STAGING_DIR_HOST)/bin/ubinize \
+               -m $(word 2, $(1)) -p $(word 4, $(1)) -s $(word 2, $(1)) \
+               -o $@ \
+               ubinize.cfg \
        )
+endef
 
-       cp $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-zImage
+#################################################
+# Devices
+#################################################
 
- ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
-       cp $(KDIR)/zImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs
- endif
-endef
+KERNEL_LOADADDR=0x10008000
 
-# board-specific sysupgrade image
-define BuildFirmware/Generic
-       dd if=$(BIN_DIR)/openwrt-$(1)-uImage.itb of=$(KDIR)/uImage.pad bs=64k conv=sync; \
-       dd if=$(KDIR)/root.$(2) of=$(KDIR)/root.$(2).pad bs=128k conv=sync; \
-       sh $(TOPDIR)/scripts/combined-image.sh \
-               $(KDIR)/uImage.pad \
-               $(KDIR)/root.$(2).pad \
-               $(BIN_DIR)/$(IMG_PREFIX)-$(patsubst jffs2-%,jffs2,$(patsubst squashfs-%,squashfs,$(1)))-sysupgrade.bin
+define Device/Default
+       DEVICE_DTS :=
+       FILESYSTEMS := squashfs ext4
+       KERNEL_INSTALL := 1
+       KERNEL_SUFFIX := -uImage
+       KERNEL_NAME := zImage
+       KERNEL := kernel-bin | uImage none
+       IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1).$$(2)
+       IMAGES :=
 endef
 
-define Image/Build
-       $(call Image/Build/$(1),$(1))
-       $(foreach board,$(BOARDS),
-               $(call BuildFirmware/Generic,$(board),$(1))
-       )
+DEVICE_VARS += DEVICE_DTS
+
+define Device/ventana
+       PROFILES = Generic VENTANA
+       DEVICE_DTS:= \
+               imx6dl-gw51xx \
+               imx6dl-gw52xx \
+               imx6dl-gw53xx \
+               imx6dl-gw54xx \
+               imx6dl-gw551x \
+               imx6dl-gw552x \
+               imx6q-gw51xx \
+               imx6q-gw52xx \
+               imx6q-gw53xx \
+               imx6q-gw54xx \
+               imx6q-gw5400-a \
+               imx6q-gw551x \
+               imx6q-gw552x
+       IMAGES := nand-factory_normal.ubi nand-factory_large.ubi
+       IMAGE/nand-factory_normal.ubi := ubi-boot-overlay normal 2048 124KiB 128KiB 8124
+       IMAGE/nand-factory_large.ubi := ubi-boot-overlay large 4096 248KiB 256KiB 8124
 endef
 
-# rootfs and board-specific combined kernel+rootfs for convenience
-define Image/Build/squashfs
-       $(call prepare_generic_squashfs,$(KDIR)/root.$(1))
-       dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/openwrt-$(BOARD)-$(1).img bs=128k conv=sync
-       $(foreach board,$(BOARDS),
-               ( \
-               dd if=$(BIN_DIR)/openwrt-$(board)-uImage.itb bs=2048k conv=sync; \
-               dd if=$(KDIR)/root.$(1) bs=64k conv=sync; \
-               ) > $(BIN_DIR)/$(IMG_PREFIX)-$(board)-$(1).bin
-       )
+define Device/wandboard
+       PROFILES = Generic IMX6DL_WANDBOARD
+       DEVICE_DTS := imx6dl-wandboard
 endef
 
+TARGET_DEVICES += \
+       ventana \
+       wandboard
+
 $(eval $(call BuildImage))