Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Copyright (C) 2008-2012 OpenWrt.org
- #
- # This is free software, licensed under the GNU General Public License v2.
- # See /LICENSE for more information.
- #
- include $(TOPDIR)/rules.mk
- include $(INCLUDE_DIR)/image.mk
- include $(INCLUDE_DIR)/host.mk
- SQUASHFSCOMP:=xz
- FLASH_BLOCKSIZE:=64
- FLASH_SZ:=128
- UBOOT_SZ:=4
- UBOOT_ENV_SZ:=1
- KERNEL_SZ:=23
- ROOTFS_SZ:=0
- ROOTFS_ADDR=$(shell printf %x $$(((($(UBOOT_SZ) + $(UBOOT_ENV_SZ) + $(KERNEL_SZ)) * $(FLASH_BLOCKSIZE)) * 1024)))
- JFFS2_ADDR=$(shell printf %x $$(((($(UBOOT_SZ) + $(UBOOT_ENV_SZ) + $(KERNEL_SZ) + $(ROOTFS_SZ)) * $(FLASH_BLOCKSIZE)) * 1024)))
- SQUASHFS_SZ=$(shell printf %x $$((($(1) * $(FLASH_BLOCKSIZE)) * 1024)))
- rootfs_size=$(shell du -B $(FLASH_BLOCKSIZE)k $(BIN_DIR)/$(IMG_PREFIX)-$(1).img | awk '{print $$1}')
- jffs_size=$(shell expr $$(((($(FLASH_SZ) - $(UBOOT_SZ) - $(UBOOT_ENV_SZ) - $(KERNEL_SZ) - $(ROOTFS_SZ))* $(FLASH_BLOCKSIZE)) * 1024)))
- define MkuImage
- # Should get zImage size and sed it in the
- # zipit-z2_template.dts first to allow for expanding/contracting kernel size
- $(shell sed -e 's:DT_SZ_KERNEL:170000:' -e 's:DT_ADDR_SQUASH:$(call ROOTFS_ADDR):' -e 's:DT_SZ_SQUASH:$(call SQUASHFS_SZ,$(ROOTFS_SZ)):' -e 's:DT_ADDR_JFFS2:$(call JFFS2_ADDR):' <$(DTS_DIR)/zipit-z2_template.dts >$(DTS_DIR)/zipit-z2.new.dts)
- $(call Image/BuildDTB,$(DTS_DIR)/zipit-z2.new.dts,$(DTS_DIR)/zipit-z2.dtb)
- cat $(KDIR)/zImage $(DTS_DIR)/zipit-z2.dtb > $(KDIR_TMP)/zImage-dtb
- mkimage -A Arm \
- -O linux \
- -C none \
- -T kernel \
- -a 0xA0008000 -e 0xA0008000 \
- -n uImage-dtb -d $(KDIR_TMP)/zImage-dtb $(KDIR_TMP)/uImage
- dd if=$(KDIR_TMP)/uImage of=$(BIN_DIR)/$(IMG_PREFIX)-uImage bs=$(FLASH_BLOCKSIZE)k conv=sync
- endef
- # Build a fake flash image for usage in Qemu
- define Image/Build/Gumstix
- dd if=/dev/zero bs=128k count=256 of=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-qemu-flash.img
- dd if=$(BIN_DIR)/openwrt-pxa-gumstix-u-boot.bin conv=notrunc bs=128k \
- of=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-qemu-flash.img
- dd if=$(KDIR)/root.$(1) conv=notrunc bs=128k seek=2 \
- of=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-qemu-flash.img
- dd if=$(KDIR)/uImage conv=notrunc bs=128k seek=248 \
- of=$(BIN_DIR)/$(IMG_PREFIX)-$(1)-qemu-flash.img
- endef
- define Image/Build/jffs2-64k
- dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-$(1).img bs=64k conv=sync
- endef
- # $(call Image/Build/firmware,$(1))
- define Image/Build/squashfs
- $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
- dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-$(1).img bs=$(FLASH_BLOCKSIZE)k conv=sync
- $(eval ROOTFS_SZ=$(call rootfs_size,$(1)))
- endef
- define Image/Build/firmware
- # Build SquashFS First
- $(call Image/Build/squashfs,$(1))
- # Build Kernel 2nd
- $(call MkuImage,$(1))
- # Should verify size of squash/kernel to make sure it will fit in flash and error if too big
- # Build empty JFFS last
- mkdir -p $(KDIR_TMP)/empty_jffs
- $(STAGING_DIR_HOST)/bin/mkfs.jffs2 -v -X lzma -y 80:lzma -y 70:zlib \
- --pad=$(call jffs_size,$(1)) \
- --little-endian --squash -e 64KiB \
- -d '$(KDIR_TMP)/empty_jffs' \
- -o '$(BIN_DIR)/$(IMG_PREFIX)-overlay.jffs2'
- # Combine everything into one 'firmware' file
- cat $(BIN_DIR)/$(IMG_PREFIX)-uImage \
- $(BIN_DIR)/$(IMG_PREFIX)-$(1).img \
- $(BIN_DIR)/$(IMG_PREFIX)-overlay.jffs2 >$(BIN_DIR)/$(IMG_PREFIX)-firmware.img
- endef
- define Image/Build
- $(call Image/Build/$(1),$(1))
- $(call Image/Build/$(PROFILE),$(1))
- $(call Image/Build/firmware,$(1))
- endef
- $(eval $(call BuildImage))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement