From 58eccdac4fb6b384dde8723876e69dafb8bf2368 Mon Sep 17 00:00:00 2001
From: John Crispin <john@openwrt.org>
Date: Thu, 3 Apr 2014 14:26:24 +0000
Subject: [PATCH] lantiq: fix vr9 ubi handling

Signed-off-by: John Crispin <blogic@openwrt.org>

SVN-Revision: 40364
---
 target/linux/lantiq/config-default            |  2 --
 target/linux/lantiq/dts/FRITZ3370.dts         | 31 +++++++++----------
 target/linux/lantiq/image/Makefile            | 29 ++++++++++++++---
 target/linux/lantiq/image/ubinize-overlay.cfg | 21 +++++++++++++
 target/linux/lantiq/xrx200/config-default     |  2 +-
 target/linux/lantiq/xrx200/profiles/avm.mk    |  3 ++
 target/linux/lantiq/xrx200/target.mk          |  2 +-
 7 files changed, 66 insertions(+), 24 deletions(-)
 create mode 100644 target/linux/lantiq/image/ubinize-overlay.cfg

diff --git a/target/linux/lantiq/config-default b/target/linux/lantiq/config-default
index c42c20dad2..1efab8b24a 100644
--- a/target/linux/lantiq/config-default
+++ b/target/linux/lantiq/config-default
@@ -87,8 +87,6 @@ CONFIG_LANTIQ_PHY=y
 CONFIG_LANTIQ_WDT=y
 CONFIG_LANTIQ_XRX200=y
 CONFIG_LEDS_GPIO=y
-# CONFIG_LZO_COMPRESS is not set
-# CONFIG_LZO_DECOMPRESS is not set
 CONFIG_MDIO_BOARDINFO=y
 CONFIG_MIPS=y
 # CONFIG_MIPS_HUGE_TLB_SUPPORT is not set
diff --git a/target/linux/lantiq/dts/FRITZ3370.dts b/target/linux/lantiq/dts/FRITZ3370.dts
index 0017ddedf1..c0202bab0f 100644
--- a/target/linux/lantiq/dts/FRITZ3370.dts
+++ b/target/linux/lantiq/dts/FRITZ3370.dts
@@ -6,7 +6,7 @@
 	model = "FRITZ3370 - Fritz!Box WLAN 3370";
 
 	chosen {
-		bootargs = "console=ttyLTQ0,115200";
+		bootargs = "console=ttyLTQ0,115200 ubi.mtd=1,512 root=/dev/mtdblock9";
 	};
 
 	memory@0 {
@@ -23,8 +23,13 @@
 				#size-cells = <1>;
 
 				partition@0 {
-					label = "firmware";
-					reg = <0x00000 0x3400000>;
+					label = "kernel";
+					reg = <0x0 0x400000>;
+				};
+
+				partition@400000 {
+					label = "rootfs_ubi";
+					reg = <0x400000 0x3000000>;
 				};
 
 				partition@3400000 {
@@ -55,23 +60,16 @@
 					lantiq,groups = "spi", "spi_cs4";
 					lantiq,function = "gpio";
 				};
-				nand_out {
-					lantiq,groups = "nand cle", "nand ale",	"nand rd", "ebu a23", "ebu a24";
-					lantiq,function = "ebu";
-					lantiq,direction = <1>;
-					lantiq,pull = <0>;
-				};
-				nand_in {
-					lantiq,groups = "nand rdy";
-					lantiq,function = "ebu";
-					lantiq,direction = <0>;
-					lantiq,open-drain = <1>;
-					lantiq,pull = <2>;
-				};
 				mdio {
 					lantiq,groups = "mdio";
 					lantiq,function = "mdio";
 				};
+				nand {
+					lantiq,groups = "nand cle", "nand ale",
+							"nand rd", "nand cs1", "nand rdy";
+					lantiq,function = "ebu";
+					lantiq,pull = <1>;
+				};
 				phy-rst {
 					lantiq,pins = "io37", "io44";
 					lantiq,pull = <0>;
@@ -104,6 +102,7 @@
 				#size-cells = <0>;
 				reg = <0>;
 				mac-address = [ 00 11 22 33 44 55 ];
+				lantiq,switch;
 
 				ethernet@0 {
 					compatible = "lantiq,xrx200-pdi-port";
diff --git a/target/linux/lantiq/image/Makefile b/target/linux/lantiq/image/Makefile
index 28cb96c8b7..34591c7b50 100644
--- a/target/linux/lantiq/image/Makefile
+++ b/target/linux/lantiq/image/Makefile
@@ -54,10 +54,10 @@ define TPLinkImageLzma
 endef
 
 define MkImageEVA
-	lzma2eva 0x80002000 0x80002000 $(KDIR)/vmlinux-$(1).lzma $(KDIR)/$(1).eva.prealign
-	dd if=$(KDIR)/$(1).eva.prealign of=$(KDIR)/$(1).eva.align.64k bs=64k conv=sync
-	dd if=$(KDIR)/$(1).eva.prealign of=$(KDIR)/$(1).eva.align.128k bs=128k conv=sync
-	cat ./eva.dummy.squashfs >> $(KDIR)/$(1).eva.align.64k
+	lzma2eva 0x80002000 0x80002000 $(KDIR)/vmlinux$(2)-$(1).lzma $(KDIR)/$(1)$(2).eva.prealign
+	dd if=$(KDIR)/$(1)$(2).eva.prealign of=$(KDIR)/$(1)$(2).eva.align.64k bs=64k conv=sync
+	dd if=$(KDIR)/$(1)$(2).eva.prealign of=$(KDIR)/$(1)$(2).eva.align.128k bs=128k conv=sync
+	cat ./eva.dummy.squashfs >> $(KDIR)/$(1)$(2).eva.align.64k
 endef
 
 define CompressGzip
@@ -93,6 +93,21 @@ define Image/BuildEVA/squashfs
 	$(call prepare_generic_squashfs,$(BIN_DIR)/$(IMG_PREFIX)-$(2)-$(1).image.eva)
 endef
 
+define Image/BuildEVA/ubifs
+
+ifneq ($($(PROFILE)_UBIFS_OPTS),)
+	$(CP) $(KDIR)/root.ubifs $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-rootfs.ubifs
+endif
+endef
+
+define Image/BuildEVA/ubi
+
+ifneq ($($(PROFILE)_UBI_OPTS),)
+	$(CP) $(KDIR)/root.ubi $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-rootfs.ubi
+	$(CP) $(KDIR)/root-overlay.ubi $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-rootfs-overlay.ubi
+endif
+endef
+
 define Image/BuildLoader/squashfs
 	dd if=$(KDIR)/loader-$(2).bin of=$(KDIR)/loader-$(2).bin.padded bs=1536k conv=sync
 	cat $(KDIR)/loader-$(2).bin.padded $(KDIR)/root.$(1) > $(BIN_DIR)/$(IMG_PREFIX)-$(2)-$(1).image
@@ -197,6 +212,12 @@ define Image/BuildKernelEVA/Template
 	$(call MkImageEVA,$(1))
 	$(CP) $(KDIR)/$(1).eva.align.64k $(BIN_DIR)/$(IMG_PREFIX)-$(1).eva.align.64k
 	$(CP) $(KDIR)/$(1).eva.align.128k $(BIN_DIR)/$(IMG_PREFIX)-$(1).eva.align.128k
+ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
+	$(call PatchKernelLzma,$(1),-initramfs)
+	$(call MkImageEVA,$(1),-initramfs)
+	$(CP) $(KDIR)/$(1)-initramfs.eva.align.64k $(BIN_DIR)/$(IMG_PREFIX)-$(1)-initramfs.eva.align.64k
+	$(CP) $(KDIR)/$(1)-initramfs.eva.align.128k $(BIN_DIR)/$(IMG_PREFIX)-$(1)-initramfs.eva.align.128k
+endif
 endef
 
 define Image/BuildKernelGzip/Template
diff --git a/target/linux/lantiq/image/ubinize-overlay.cfg b/target/linux/lantiq/image/ubinize-overlay.cfg
new file mode 100644
index 0000000000..ce8e5d97af
--- /dev/null
+++ b/target/linux/lantiq/image/ubinize-overlay.cfg
@@ -0,0 +1,21 @@
+[rootfs]
+# Volume mode (other option is static)
+mode=ubi
+# Source image
+image=root.squashfs
+# Volume ID in UBI image
+vol_id=0
+# Allow for dynamic resize
+vol_type=dynamic
+# Volume name
+vol_name=rootfs
+[rootfs_data]
+# Volume mode (other option is static)
+mode=ubi
+# Volume ID in UBI image
+vol_id=1
+# Allow for dynamic resize
+vol_type=dynamic
+# Volume name
+vol_name=rootfs_data
+vol_size=1MiB
diff --git a/target/linux/lantiq/xrx200/config-default b/target/linux/lantiq/xrx200/config-default
index 4d25f21f14..4550431ee4 100644
--- a/target/linux/lantiq/xrx200/config-default
+++ b/target/linux/lantiq/xrx200/config-default
@@ -29,7 +29,7 @@ CONFIG_MTD_NAND_XWAY=y
 CONFIG_MTD_UBI=y
 CONFIG_MTD_UBI_BEB_LIMIT=20
 # CONFIG_MTD_UBI_FASTMAP is not set
-# CONFIG_MTD_UBI_GLUEBI is not set
+CONFIG_MTD_UBI_GLUEBI=y
 CONFIG_MTD_UBI_WL_THRESHOLD=4096
 CONFIG_NLS=y
 CONFIG_PCIE_LANTIQ=y
diff --git a/target/linux/lantiq/xrx200/profiles/avm.mk b/target/linux/lantiq/xrx200/profiles/avm.mk
index 77c1a0ad14..7eb6830bee 100644
--- a/target/linux/lantiq/xrx200/profiles/avm.mk
+++ b/target/linux/lantiq/xrx200/profiles/avm.mk
@@ -7,4 +7,7 @@ define Profile/FRITZ3370
 	ltq-vdsl-app ppp-mod-pppoa
 endef
 
+FRITZ3370_UBIFS_OPTS:="-m 2048 -e 126KiB -c 4096"
+FRITZ3370_UBI_OPTS:="-m 2048 -p 128KiB -s 512"
+
 $(eval $(call Profile,FRITZ3370))
diff --git a/target/linux/lantiq/xrx200/target.mk b/target/linux/lantiq/xrx200/target.mk
index 47d9be6f17..0c646685a6 100644
--- a/target/linux/lantiq/xrx200/target.mk
+++ b/target/linux/lantiq/xrx200/target.mk
@@ -5,7 +5,7 @@ FEATURES:=squashfs atm mips16 jffs2 ubifs
 CPU_TYPE:=34kc
 CPU_SUBTYPE:=dsp
 
-DEFAULT_PACKAGES+=kmod-leds-gpio kmod-gpio-button-hotplug
+DEFAULT_PACKAGES+=kmod-leds-gpio kmod-gpio-button-hotplug swconfig
 
 define Target/Description
 	Lantiq XRX200
-- 
2.30.2