From d0757421a7d2d8f6b634d00ea25e6abf6d7b4699 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Thu, 2 Dec 2010 21:27:54 +0000 Subject: brcm47xx: Add edimax PS1208mfg support Thank you clemvangelis for the patches. (closes #7672) git-svn-id: svn://svn.openwrt.org/openwrt/trunk@24217 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- .../files-2.6.34/drivers/mtd/maps/bcm47xx-flash.c | 49 +++++++++++++++++++--- .../files-2.6.36/drivers/mtd/maps/bcm47xx-flash.c | 49 +++++++++++++++++++--- .../files-2.6.37/drivers/mtd/maps/bcm47xx-flash.c | 49 +++++++++++++++++++--- target/linux/brcm47xx/image/Makefile | 5 +++ .../brcm47xx/image/lzma-loader/src/decompress.c | 9 +++- target/linux/brcm47xx/profiles/PS-1208MFG.mk | 18 ++++++++ 6 files changed, 160 insertions(+), 19 deletions(-) create mode 100644 target/linux/brcm47xx/profiles/PS-1208MFG.mk (limited to 'target/linux/brcm47xx') diff --git a/target/linux/brcm47xx/files-2.6.34/drivers/mtd/maps/bcm47xx-flash.c b/target/linux/brcm47xx/files-2.6.34/drivers/mtd/maps/bcm47xx-flash.c index 3159bf3f64..4585c4f9ee 100644 --- a/target/linux/brcm47xx/files-2.6.34/drivers/mtd/maps/bcm47xx-flash.c +++ b/target/linux/brcm47xx/files-2.6.34/drivers/mtd/maps/bcm47xx-flash.c @@ -71,6 +71,15 @@ struct trx_header { u32 offsets[TRX_MAX_OFFSET]; /* Offsets of partitions from start of header */ }; +/* for Edimax Print servers which use an additional header + * then the firmware on flash looks like : + * EDIMAX HEADER | TRX HEADER + * As this header is 12 bytes long we have to handle it + * and skip it to find the TRX header + */ +#define EDIMAX_PS_HEADER_MAGIC 0x36315350 /* "PS16" */ +#define EDIMAX_PS_HEADER_LEN 0xc /* 12 bytes long for edimax header */ + #define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y)) #define NVRAM_SPACE 0x8000 #define WINDOW_ADDR 0x1fc00000 @@ -145,6 +154,15 @@ find_cfe_size(struct mtd_info *mtd, size_t size) len != sizeof(buf)) continue; + if (le32_to_cpu(trx->magic) == EDIMAX_PS_HEADER_MAGIC) { + if (mtd->read(mtd, off + EDIMAX_PS_HEADER_LEN, + sizeof(buf), &len, buf) || len != sizeof(buf)) { + continue; + } else { + printk(KERN_NOTICE"Found edimax header\n"); + } + } + /* found a TRX header */ if (le32_to_cpu(trx->magic) == TRX_MAGIC) { goto found; @@ -217,7 +235,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos, remove_wait_queue(&wait_q, &wait); /* - * Next, writhe data to flash. + * Next, write data to flash. */ ret = mtd->write (mtd, pos, len, &retlen, buf); @@ -267,9 +285,10 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) { struct trx_header trx, *trx2; unsigned char buf[512], *block; - int off, blocksize; + int off, blocksize, trxoff = 0; u32 i, crc = ~0; size_t len; + bool edimax = false; blocksize = mtd->erasesize; if (blocksize < 0x10000) @@ -285,6 +304,19 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) len != sizeof(trx)) continue; + /* found an edimax header */ + if (le32_to_cpu(trx.magic) == EDIMAX_PS_HEADER_MAGIC) { + /* read the correct trx header */ + if (mtd->read(mtd, off + EDIMAX_PS_HEADER_LEN, + sizeof(trx), &len, (char *) &trx) || + len != sizeof(trx)) { + continue; + } else { + printk(KERN_NOTICE"Found an edimax ps header\n"); + edimax = true; + } + } + /* found a TRX header */ if (le32_to_cpu(trx.magic) == TRX_MAGIC) { part->offset = le32_to_cpu(trx.offsets[2]) ? : @@ -293,6 +325,10 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) part->size -= part->offset; part->offset += off; + if (edimax) { + off += EDIMAX_PS_HEADER_LEN; + trxoff = EDIMAX_PS_HEADER_LEN; + } goto found; } @@ -304,6 +340,7 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) return -1; found: + printk(KERN_NOTICE"TRX offset : %lx\n", trxoff); if (part->size == 0) return 0; @@ -328,7 +365,7 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) /* read first eraseblock from the trx */ block = kmalloc(mtd->erasesize, GFP_KERNEL); trx2 = (struct trx_header *) block; - if (mtd->read(mtd, off, mtd->erasesize, &len, block) || len != mtd->erasesize) { + if (mtd->read(mtd, off - trxoff, mtd->erasesize, &len, block) || len != mtd->erasesize) { printk("Error accessing the first trx eraseblock\n"); return 0; } @@ -338,10 +375,10 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) printk("new trx = [0x%08x, 0x%08x, 0x%08x], len=0x%08x crc32=0x%08x\n", trx.offsets[0], trx.offsets[1], trx.offsets[2], trx.len, trx.crc32); /* Write updated trx header to the flash */ - memcpy(block, &trx, sizeof(trx)); + memcpy(block + trxoff, &trx, sizeof(trx)); if (mtd->unlock) - mtd->unlock(mtd, off, mtd->erasesize); - erase_write(mtd, off, mtd->erasesize, block); + mtd->unlock(mtd, off - trxoff, mtd->erasesize); + erase_write(mtd, off - trxoff, mtd->erasesize, block); if (mtd->sync) mtd->sync(mtd); kfree(block); diff --git a/target/linux/brcm47xx/files-2.6.36/drivers/mtd/maps/bcm47xx-flash.c b/target/linux/brcm47xx/files-2.6.36/drivers/mtd/maps/bcm47xx-flash.c index 3159bf3f64..4585c4f9ee 100644 --- a/target/linux/brcm47xx/files-2.6.36/drivers/mtd/maps/bcm47xx-flash.c +++ b/target/linux/brcm47xx/files-2.6.36/drivers/mtd/maps/bcm47xx-flash.c @@ -71,6 +71,15 @@ struct trx_header { u32 offsets[TRX_MAX_OFFSET]; /* Offsets of partitions from start of header */ }; +/* for Edimax Print servers which use an additional header + * then the firmware on flash looks like : + * EDIMAX HEADER | TRX HEADER + * As this header is 12 bytes long we have to handle it + * and skip it to find the TRX header + */ +#define EDIMAX_PS_HEADER_MAGIC 0x36315350 /* "PS16" */ +#define EDIMAX_PS_HEADER_LEN 0xc /* 12 bytes long for edimax header */ + #define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y)) #define NVRAM_SPACE 0x8000 #define WINDOW_ADDR 0x1fc00000 @@ -145,6 +154,15 @@ find_cfe_size(struct mtd_info *mtd, size_t size) len != sizeof(buf)) continue; + if (le32_to_cpu(trx->magic) == EDIMAX_PS_HEADER_MAGIC) { + if (mtd->read(mtd, off + EDIMAX_PS_HEADER_LEN, + sizeof(buf), &len, buf) || len != sizeof(buf)) { + continue; + } else { + printk(KERN_NOTICE"Found edimax header\n"); + } + } + /* found a TRX header */ if (le32_to_cpu(trx->magic) == TRX_MAGIC) { goto found; @@ -217,7 +235,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos, remove_wait_queue(&wait_q, &wait); /* - * Next, writhe data to flash. + * Next, write data to flash. */ ret = mtd->write (mtd, pos, len, &retlen, buf); @@ -267,9 +285,10 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) { struct trx_header trx, *trx2; unsigned char buf[512], *block; - int off, blocksize; + int off, blocksize, trxoff = 0; u32 i, crc = ~0; size_t len; + bool edimax = false; blocksize = mtd->erasesize; if (blocksize < 0x10000) @@ -285,6 +304,19 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) len != sizeof(trx)) continue; + /* found an edimax header */ + if (le32_to_cpu(trx.magic) == EDIMAX_PS_HEADER_MAGIC) { + /* read the correct trx header */ + if (mtd->read(mtd, off + EDIMAX_PS_HEADER_LEN, + sizeof(trx), &len, (char *) &trx) || + len != sizeof(trx)) { + continue; + } else { + printk(KERN_NOTICE"Found an edimax ps header\n"); + edimax = true; + } + } + /* found a TRX header */ if (le32_to_cpu(trx.magic) == TRX_MAGIC) { part->offset = le32_to_cpu(trx.offsets[2]) ? : @@ -293,6 +325,10 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) part->size -= part->offset; part->offset += off; + if (edimax) { + off += EDIMAX_PS_HEADER_LEN; + trxoff = EDIMAX_PS_HEADER_LEN; + } goto found; } @@ -304,6 +340,7 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) return -1; found: + printk(KERN_NOTICE"TRX offset : %lx\n", trxoff); if (part->size == 0) return 0; @@ -328,7 +365,7 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) /* read first eraseblock from the trx */ block = kmalloc(mtd->erasesize, GFP_KERNEL); trx2 = (struct trx_header *) block; - if (mtd->read(mtd, off, mtd->erasesize, &len, block) || len != mtd->erasesize) { + if (mtd->read(mtd, off - trxoff, mtd->erasesize, &len, block) || len != mtd->erasesize) { printk("Error accessing the first trx eraseblock\n"); return 0; } @@ -338,10 +375,10 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) printk("new trx = [0x%08x, 0x%08x, 0x%08x], len=0x%08x crc32=0x%08x\n", trx.offsets[0], trx.offsets[1], trx.offsets[2], trx.len, trx.crc32); /* Write updated trx header to the flash */ - memcpy(block, &trx, sizeof(trx)); + memcpy(block + trxoff, &trx, sizeof(trx)); if (mtd->unlock) - mtd->unlock(mtd, off, mtd->erasesize); - erase_write(mtd, off, mtd->erasesize, block); + mtd->unlock(mtd, off - trxoff, mtd->erasesize); + erase_write(mtd, off - trxoff, mtd->erasesize, block); if (mtd->sync) mtd->sync(mtd); kfree(block); diff --git a/target/linux/brcm47xx/files-2.6.37/drivers/mtd/maps/bcm47xx-flash.c b/target/linux/brcm47xx/files-2.6.37/drivers/mtd/maps/bcm47xx-flash.c index 3159bf3f64..4585c4f9ee 100644 --- a/target/linux/brcm47xx/files-2.6.37/drivers/mtd/maps/bcm47xx-flash.c +++ b/target/linux/brcm47xx/files-2.6.37/drivers/mtd/maps/bcm47xx-flash.c @@ -71,6 +71,15 @@ struct trx_header { u32 offsets[TRX_MAX_OFFSET]; /* Offsets of partitions from start of header */ }; +/* for Edimax Print servers which use an additional header + * then the firmware on flash looks like : + * EDIMAX HEADER | TRX HEADER + * As this header is 12 bytes long we have to handle it + * and skip it to find the TRX header + */ +#define EDIMAX_PS_HEADER_MAGIC 0x36315350 /* "PS16" */ +#define EDIMAX_PS_HEADER_LEN 0xc /* 12 bytes long for edimax header */ + #define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y)) #define NVRAM_SPACE 0x8000 #define WINDOW_ADDR 0x1fc00000 @@ -145,6 +154,15 @@ find_cfe_size(struct mtd_info *mtd, size_t size) len != sizeof(buf)) continue; + if (le32_to_cpu(trx->magic) == EDIMAX_PS_HEADER_MAGIC) { + if (mtd->read(mtd, off + EDIMAX_PS_HEADER_LEN, + sizeof(buf), &len, buf) || len != sizeof(buf)) { + continue; + } else { + printk(KERN_NOTICE"Found edimax header\n"); + } + } + /* found a TRX header */ if (le32_to_cpu(trx->magic) == TRX_MAGIC) { goto found; @@ -217,7 +235,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos, remove_wait_queue(&wait_q, &wait); /* - * Next, writhe data to flash. + * Next, write data to flash. */ ret = mtd->write (mtd, pos, len, &retlen, buf); @@ -267,9 +285,10 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) { struct trx_header trx, *trx2; unsigned char buf[512], *block; - int off, blocksize; + int off, blocksize, trxoff = 0; u32 i, crc = ~0; size_t len; + bool edimax = false; blocksize = mtd->erasesize; if (blocksize < 0x10000) @@ -285,6 +304,19 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) len != sizeof(trx)) continue; + /* found an edimax header */ + if (le32_to_cpu(trx.magic) == EDIMAX_PS_HEADER_MAGIC) { + /* read the correct trx header */ + if (mtd->read(mtd, off + EDIMAX_PS_HEADER_LEN, + sizeof(trx), &len, (char *) &trx) || + len != sizeof(trx)) { + continue; + } else { + printk(KERN_NOTICE"Found an edimax ps header\n"); + edimax = true; + } + } + /* found a TRX header */ if (le32_to_cpu(trx.magic) == TRX_MAGIC) { part->offset = le32_to_cpu(trx.offsets[2]) ? : @@ -293,6 +325,10 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) part->size -= part->offset; part->offset += off; + if (edimax) { + off += EDIMAX_PS_HEADER_LEN; + trxoff = EDIMAX_PS_HEADER_LEN; + } goto found; } @@ -304,6 +340,7 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) return -1; found: + printk(KERN_NOTICE"TRX offset : %lx\n", trxoff); if (part->size == 0) return 0; @@ -328,7 +365,7 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) /* read first eraseblock from the trx */ block = kmalloc(mtd->erasesize, GFP_KERNEL); trx2 = (struct trx_header *) block; - if (mtd->read(mtd, off, mtd->erasesize, &len, block) || len != mtd->erasesize) { + if (mtd->read(mtd, off - trxoff, mtd->erasesize, &len, block) || len != mtd->erasesize) { printk("Error accessing the first trx eraseblock\n"); return 0; } @@ -338,10 +375,10 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part) printk("new trx = [0x%08x, 0x%08x, 0x%08x], len=0x%08x crc32=0x%08x\n", trx.offsets[0], trx.offsets[1], trx.offsets[2], trx.len, trx.crc32); /* Write updated trx header to the flash */ - memcpy(block, &trx, sizeof(trx)); + memcpy(block + trxoff, &trx, sizeof(trx)); if (mtd->unlock) - mtd->unlock(mtd, off, mtd->erasesize); - erase_write(mtd, off, mtd->erasesize, block); + mtd->unlock(mtd, off - trxoff, mtd->erasesize); + erase_write(mtd, off - trxoff, mtd->erasesize, block); if (mtd->sync) mtd->sync(mtd); kfree(block); diff --git a/target/linux/brcm47xx/image/Makefile b/target/linux/brcm47xx/image/Makefile index f8c09b97d4..034200c50a 100644 --- a/target/linux/brcm47xx/image/Makefile +++ b/target/linux/brcm47xx/image/Makefile @@ -49,6 +49,10 @@ define Image/Build/USR $(STAGING_DIR_HOST)/bin/trx2usr $(BIN_DIR)/$(IMG_PREFIX)-$(1).trx $(BIN_DIR)/openwrt-$(2)-$(3).bin endef +define Image/Build/Edi + $(STAGING_DIR_HOST)/bin/trx2edips $(BIN_DIR)/$(IMG_PREFIX)-$(1).trx $(BIN_DIR)/openwrt-$(2)-$(3).bin +endef + define trxalign/jffs2-128k -a 0x20000 -f $(KDIR)/root.$(1) endef @@ -87,6 +91,7 @@ define Image/Build/jffs2-64k $(call Image/Build/CyberTAN,$(1),wrt350n_v1,EWCG,1.04.1,$(patsubst jffs2-%,jffs2,$(1))) $(call Image/Build/Motorola,$(1),wa840g,2,$(patsubst jffs2-%,jffs2,$(1))) $(call Image/Build/Motorola,$(1),we800g,3,$(patsubst jffs2-%,jffs2,$(1))) + $(call Image/Build/Edi,$(1),ps1208mfg,$(patsubst jffs2-%,jffs2,$(1))) endef define Image/Build/squashfs diff --git a/target/linux/brcm47xx/image/lzma-loader/src/decompress.c b/target/linux/brcm47xx/image/lzma-loader/src/decompress.c index ce2876a304..05681b152d 100644 --- a/target/linux/brcm47xx/image/lzma-loader/src/decompress.c +++ b/target/linux/brcm47xx/image/lzma-loader/src/decompress.c @@ -87,6 +87,9 @@ struct trx_header { unsigned int offsets[3]; /* Offsets of partitions from start of header */ }; +#define EDIMAX_PS_HEADER_MAGIC 0x36315350 /* "PS16" */ +#define EDIMAX_PS_HEADER_LEN 0xc /* 12 bytes long for edimax header */ + /* beyound the image end, size not known in advance */ extern unsigned char workspace[]; @@ -135,8 +138,12 @@ void entry(unsigned long icache_size, unsigned long icache_lsize, /* look for trx header, 32-bit data access */ for (data = ((unsigned char *) KSEG1ADDR(BCM4710_FLASH)); - ((struct trx_header *)data)->magic != TRX_MAGIC; data += 65536); + ((struct trx_header *)data)->magic != TRX_MAGIC && + ((struct trx_header *)data)->magic != EDIMAX_PS_HEADER_MAGIC; + data += 65536); + if (((struct trx_header *)data)->magic == EDIMAX_PS_HEADER_MAGIC) + data += EDIMAX_PS_HEADER_LEN; /* compressed kernel is in the partition 0 or 1 */ if (((struct trx_header *)data)->offsets[1] > 65536) data += ((struct trx_header *)data)->offsets[0]; diff --git a/target/linux/brcm47xx/profiles/PS-1208MFG.mk b/target/linux/brcm47xx/profiles/PS-1208MFG.mk new file mode 100644 index 0000000000..e17e0ecff3 --- /dev/null +++ b/target/linux/brcm47xx/profiles/PS-1208MFG.mk @@ -0,0 +1,18 @@ +# +# Copyright (C) 2007-2010 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +define Profile/Ps1208mfg + NAME:=Edimax PS-1208MFG + PACKAGES:=-firewall -dropbear -dnsmasq -mtd -ppp -wpad-mini block-hotplug kmod-usb-storage kmod-usb2 kmod-usb-ohci -iptables -kmod-switch kmod-fs-ext4 block-extroot +endef + +define Profile/Ps1208mfg/Description + Package set optimize for edimax PS-1208MFG printserver +endef + +$(eval $(call Profile,Ps1208mfg)) + -- cgit v1.2.3