sunxi: add support for Lamobo R1
[openwrt/openwrt.git] / target / linux / sunxi / image / Makefile
index 3a9f64d9af1ef67ce9d54715d882b86027d204a9..f627ee3e3ef98b14564dc4e8fe6e7c8695471031 100644 (file)
@@ -6,22 +6,34 @@
 #
 include $(TOPDIR)/rules.mk
 include $(INCLUDE_DIR)/image.mk
+include $(INCLUDE_DIR)/host.mk
+
+FAT32_BLOCK_SIZE=1024
+FAT32_BLOCKS=$(shell echo $$(($(CONFIG_SUNXI_SD_BOOT_PARTSIZE)*1024*1024/$(FAT32_BLOCK_SIZE))))
+
+BOARDS:= \
+       sun4i-a10-cubieboard \
+       sun4i-a10-olinuxino-lime \
+       sun4i-a10-pcduino \
+       sun5i-a13-olinuxino \
+       sun6i-a31-colombus \
+       sun6i-a31-m9 \
+       sun7i-a20-bananapi \
+       sun7i-a20-bananapro \
+       sun7i-a20-cubieboard2 \
+       sun7i-a20-cubietruck \
+       sun7i-a20-olinuxino-lime \
+       sun7i-a20-olinuxino-micro \
+       sun7i-a20-pcduino3 \
+       sun7i-a20-lamobo-r1
 
-define sanitize_profile_name
-$(shell echo $(PROFILE) | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g')
-endef
-
-define Image/BuildKernel/Template
-
-       $(CP) $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-zImage
-       echo -ne '\x00\x00\x00\x00' >> $(BIN_DIR)/$(IMG_PREFIX)-zImage
-       $(call Image/BuildKernel/MkuImage, \
-               none, 0x40008000, 0x40008000, \
-               $(BIN_DIR)/$(IMG_PREFIX)-zImage, \
-               $(BIN_DIR)/$(IMG_PREFIX)-uImage \
-       )
-
- ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
+define Image/BuildKernel
+       mkimage -A arm -O linux -T kernel -C none \
+               -a 0x40008000 -e 0x40008000 \
+               -n 'ARM OpenWrt Linux-$(LINUX_VERSION)' \
+               -d $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-uImage
+       
+    ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
        $(CP) $(KDIR)/zImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs
        echo -ne '\x00\x00\x00\x00' >> $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs
        $(call Image/BuildKernel/MkuImage, \
@@ -29,93 +41,91 @@ define Image/BuildKernel/Template
                $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs, \
                $(BIN_DIR)/$(IMG_PREFIX)-uImage-initramfs \
        )
- endif
-
- ifneq ($(1),)
-       $(CP) $(LINUX_DIR)/arch/arm/boot/dts/$(1).dtb $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb
+    endif
 
-       $(CP) $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage
-       cat $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb >> $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage
-       $(call Image/BuildKernel/MkuImage, \
-               none, 0x40008000, 0x40008000, \
-               $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage, \
-               $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-uImage \
+       $(foreach board,$(BOARDS),
+               $(CP) $(DTS_DIR)/$(board).dtb $(BIN_DIR)/
        )
+endef
 
-  ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
-       $(CP) $(KDIR)/zImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage-initramfs
-       cat $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb >> $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage-initramfs
-       $(call Image/BuildKernel/MkuImage, \
-               none, 0x40008000, 0x40008000, \
-               $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage-initramfs, \
-               $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-uImage-initramfs \
-       )
-  endif
- endif
+define Image/Build/SDCard
+       rm -f $(KDIR)/boot.img
+       mkdosfs $(KDIR)/boot.img -C $(FAT32_BLOCKS)
+       
+       mcopy -i $(KDIR)/boot.img $(BIN_DIR)/uboot-sunxi-$(PROFILE)/openwrt-sunxi-$(PROFILE)-boot.scr ::boot.scr
+       mcopy -i $(KDIR)/boot.img $(BIN_DIR)/$(2).dtb ::dtb
+       mcopy -i $(KDIR)/boot.img $(BIN_DIR)/$(IMG_PREFIX)-uImage ::uImage
+       
+       ./gen_sunxi_sdcard_img.sh \
+               $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-sdcard-vfat-$(1).img \
+               $(KDIR)/boot.img \
+               $(KDIR)/root.$(1) \
+               $(CONFIG_SUNXI_SD_BOOT_PARTSIZE) \
+               $(CONFIG_TARGET_ROOTFS_PARTSIZE) \
+               $(BIN_DIR)/uboot-sunxi-$(PROFILE)/openwrt-sunxi-$(PROFILE)-u-boot-with-spl.bin
 endef
 
-define Image/InstallKernel/Template
+define Image/Build/Profile/A10-OLinuXino-Lime
+       $(call Image/Build/SDCard,$(1),sun4i-a10-olinuxino-lime)
+endef
 
- ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_KERNEL),)
-       $(INSTALL_DIR) $(TARGET_DIR)/boot
-   ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_UIMAGE),)
-       $(CP) $(BIN_DIR)/$(IMG_PREFIX)-uImage $(TARGET_DIR)/boot/
-       ln -sf $(IMG_PREFIX)-uImage $(TARGET_DIR)/boot/uImage
-   endif
-   ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_ZIMAGE),)
-       $(CP) $(BIN_DIR)/$(IMG_PREFIX)-zImage $(TARGET_DIR)/boot/
-       ln -sf $(IMG_PREFIX)-zImage $(TARGET_DIR)/boot/zImage
-   endif
- endif
+define Image/Build/Profile/A13-OLinuXino
+       $(call Image/Build/SDCard,$(1),sun5i-a13-olinuxino)
+endef
 
- ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_DTB),)
-       $(INSTALL_DIR) $(TARGET_DIR)/boot
-  ifneq ($(1),)
-       $(CP) $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb $(TARGET_DIR)/boot/
-       ln -sf $(IMG_PREFIX)-$(1).dtb $(TARGET_DIR)/boot/$(1).dtb
-  endif
- endif
+define Image/Build/Profile/A20-OLinuXino_Lime
+       $(call Image/Build/SDCard,$(1),sun7i-a20-olinuxino-lime)
 endef
 
-define Image/mkfs/targz
+define Image/Build/Profile/A20-OLinuXino_MICRO
+       $(call Image/Build/SDCard,$(1),sun7i-a20-olinuxino-micro)
+endef
 
-       $(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-rootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
+define Image/Build/Profile/Bananapi
+       $(call Image/Build/SDCard,$(1),sun7i-a20-bananapi)
 endef
 
-define Image/Build/ubifs
+define Image/Build/Profile/Bananapro
+       $(call Image/Build/SDCard,$(1),sun7i-a20-bananapro)
+endef
 
- ifneq ($($(PROFILE)_UBIFS_OPTS),)
-       $(CP) $(KDIR)/root.ubifs $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-rootfs.ubifs
- endif
+define Image/Build/Profile/Lamobo_R1
+       $(call Image/Build/SDCard,$(1),sun7i-a20-lamobo-r1)
 endef
 
-define Image/Build/ubi
+define Image/Build/Profile/Cubieboard
+       $(call Image/Build/SDCard,$(1),sun4i-a10-cubieboard)
+endef
 
- ifneq ($($(PROFILE)_UBI_OPTS),)
-       $(CP) $(KDIR)/root.ubi $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-rootfs.ubi
- endif
+define Image/Build/Profile/Cubieboard2
+       $(call Image/Build/SDCard,$(1),sun7i-a20-cubieboard2)
 endef
 
+define Image/Build/Profile/Cubietruck
+       $(call Image/Build/SDCard,$(1),sun7i-a20-cubietruck)
+endef
 
-Image/BuildKernel/Template/generic=$(call Image/BuildKernel/Template)
-Image/InstallKernel/Template/generic=$(call Image/InstallKernel/Template)
+define Image/Build/Profile/OLIMEX_A13_SOM
+       $(call Image/Build/SDCard,$(1),sun5i-a13-olinuxino)
+endef
 
-Image/BuildKernel/Template/CUBIEBOARD=$(call Image/BuildKernel/Template,sun4i-a10-cubieboard)
-Image/InstallKernel/Template/CUBIEBOARD=$(call Image/InstallKernel/Template,sun4i-a10-cubieboard)
+define Image/Build/Profile/Mele_M9
+       $(call Image/Build/SDCard,$(1),sun6i-a31-hummingbird)
+endef
 
-define Image/BuildKernel
-       $(call Image/BuildKernel/Template/$(PROFILE))
+define Image/Build/Profile/Linksprite_pcDuino
+       $(call Image/Build/SDCard,$(1),sun4i-a10-pcduino)
 endef
 
-define Image/InstallKernel
-       $(call Image/InstallKernel/Template/$(PROFILE))
+define Image/Build/Profile/Linksprite_pcDuino3
+       $(call Image/Build/SDCard,$(1),sun7i-a20-pcduino3)
 endef
 
 define Image/Build
-       $(if $(Image/Build/$(1)), \
-               $(call Image/Build/$(1),$(1)), \
-               $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-$(1).img \
-       )
+       $(call Image/Build/$(1),$(1))
+       $(call Image/Build/Profile/$(PROFILE),$(1))
+       
+       dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/openwrt-$(BOARD)-root.$(1) bs=128k conv=sync
 endef
 
 $(eval $(call BuildImage))