From b700bbdede249dd290dc67ff2ebdaf730e3ffa6a Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Sat, 1 Mar 2014 09:32:10 +0100 Subject: move target/tools to tools, use ADK_HOST_NEED variable to build a tool, when required. Add archivers to tools, remove prereq checks for them. Rename host_ dir in preparation for shared openadk source via nfs/smb from different host systems. Make some abi cleanup --- .gitignore | 1 - README | 6 +- mk/build.mk | 42 +- mk/host.mk | 2 +- mk/image.mk | 12 +- mk/kernel-vars.mk | 2 +- mk/package.mk | 2 +- mk/pkg-bottom.mk | 6 +- mk/vars.mk | 40 +- package/base-files/Makefile | 2 +- package/gcc/Makefile | 6 +- rules.mk | 1 + scripts/create.sh | 5 +- scripts/scan-tools.sh | 36 - target/config/Config.in | 23 + target/config/Config.in.tools | 40 + target/linux/config/Config.in.kernel | 8 +- target/microblaze/Makefile | 9 +- target/mips/Makefile | 14 +- target/tools/addpattern/Makefile | 4 - target/tools/addpattern/addpattern.c | 252 ----- target/tools/lzma-loader/.svn/entries | 300 ------ .../.svn/text-base/LzmaDecode.c.svn-base | 663 ------------ .../.svn/text-base/LzmaDecode.h.svn-base | 100 -- .../lzma-loader/.svn/text-base/Makefile.svn-base | 77 -- .../lzma-loader/.svn/text-base/README.svn-base | 55 - .../.svn/text-base/decompress.c.svn-base | 186 ---- .../.svn/text-base/decompress.lds.in.svn-base | 20 - .../lzma-loader/.svn/text-base/head.S.svn-base | 160 --- .../.svn/text-base/loader.lds.in.svn-base | 17 - target/tools/lzma-loader/Makefile | 5 - target/tools/lzma-loader/src/LzmaDecode.c | 663 ------------ target/tools/lzma-loader/src/LzmaDecode.h | 100 -- target/tools/lzma-loader/src/LzmaDecode.o | Bin 6248 -> 0 bytes target/tools/lzma-loader/src/Makefile | 78 -- target/tools/lzma-loader/src/README | 55 - target/tools/lzma-loader/src/data.lds | 1 - target/tools/lzma-loader/src/data.o | Bin 3996 -> 0 bytes target/tools/lzma-loader/src/decompress | Bin 71097 -> 0 bytes target/tools/lzma-loader/src/decompress.c | 186 ---- target/tools/lzma-loader/src/decompress.image | Bin 3484 -> 0 bytes target/tools/lzma-loader/src/decompress.lds | 20 - target/tools/lzma-loader/src/decompress.lds.in | 20 - target/tools/lzma-loader/src/decompress.o | Bin 2680 -> 0 bytes target/tools/lzma-loader/src/head.S | 160 --- target/tools/lzma-loader/src/head.o | Bin 1204 -> 0 bytes target/tools/lzma-loader/src/loader | Bin 3804 -> 0 bytes target/tools/lzma-loader/src/loader.elf | Bin 8486 -> 0 bytes target/tools/lzma-loader/src/loader.gz | Bin 2374 -> 0 bytes target/tools/lzma-loader/src/loader.lds | 17 - target/tools/lzma-loader/src/loader.lds.in | 17 - target/tools/lzma-loader/src/loader.o | Bin 8486 -> 0 bytes target/tools/lzma/Makefile | 31 - target/tools/lzma/patches/001-large_files.patch | 13 - target/tools/lzma/patches/002-lzmp.patch | 1059 -------------------- target/tools/lzma/patches/003-compile_fixes.patch | 26 - target/tools/lzma/patches/100-static_library.patch | 70 -- target/tools/mkfimage/Makefile | 4 - target/tools/mkfimage/mkfimage.c | 72 -- target/tools/mtd-utils/Makefile | 24 - target/tools/mtd-utils/patches/lzo.patch | 88 -- target/tools/rules.mk | 7 - target/tools/squashfs/Makefile | 29 - target/tools/squashfs/patches/cppflags.patch | 12 - target/tools/srec2bin/Makefile | 4 - target/tools/srec2bin/srec2bin.c | 521 ---------- target/tools/trx/Makefile | 4 - target/tools/trx/trx.c | 366 ------- target/tools/xz/Makefile | 28 - toolchain/gcc/Makefile | 4 +- tools/Makefile | 30 +- tools/addpattern/Makefile | 4 + tools/addpattern/addpattern.c | 252 +++++ tools/adk/Makefile | 8 +- tools/bc/Makefile | 6 +- tools/cdrtools/Makefile | 6 +- tools/cpio/Makefile | 4 +- tools/genext2fs/Makefile | 6 +- tools/gperf/Makefile | 6 +- tools/lzma-loader/.svn/entries | 300 ++++++ .../.svn/text-base/LzmaDecode.c.svn-base | 663 ++++++++++++ .../.svn/text-base/LzmaDecode.h.svn-base | 100 ++ tools/lzma-loader/.svn/text-base/Makefile.svn-base | 77 ++ tools/lzma-loader/.svn/text-base/README.svn-base | 55 + .../.svn/text-base/decompress.c.svn-base | 186 ++++ .../.svn/text-base/decompress.lds.in.svn-base | 20 + tools/lzma-loader/.svn/text-base/head.S.svn-base | 160 +++ .../.svn/text-base/loader.lds.in.svn-base | 17 + tools/lzma-loader/Makefile | 5 + tools/lzma-loader/src/LzmaDecode.c | 663 ++++++++++++ tools/lzma-loader/src/LzmaDecode.h | 100 ++ tools/lzma-loader/src/LzmaDecode.o | Bin 0 -> 6248 bytes tools/lzma-loader/src/Makefile | 78 ++ tools/lzma-loader/src/README | 55 + tools/lzma-loader/src/data.lds | 1 + tools/lzma-loader/src/data.o | Bin 0 -> 3996 bytes tools/lzma-loader/src/decompress | Bin 0 -> 71097 bytes tools/lzma-loader/src/decompress.c | 186 ++++ tools/lzma-loader/src/decompress.image | Bin 0 -> 3484 bytes tools/lzma-loader/src/decompress.lds | 20 + tools/lzma-loader/src/decompress.lds.in | 20 + tools/lzma-loader/src/decompress.o | Bin 0 -> 2680 bytes tools/lzma-loader/src/head.S | 160 +++ tools/lzma-loader/src/head.o | Bin 0 -> 1204 bytes tools/lzma-loader/src/loader | Bin 0 -> 3804 bytes tools/lzma-loader/src/loader.elf | Bin 0 -> 8486 bytes tools/lzma-loader/src/loader.gz | Bin 0 -> 2374 bytes tools/lzma-loader/src/loader.lds | 17 + tools/lzma-loader/src/loader.lds.in | 17 + tools/lzma-loader/src/loader.o | Bin 0 -> 8486 bytes tools/lzma/Makefile | 30 + tools/lzma/patches/001-large_files.patch | 13 + tools/lzma/patches/002-lzmp.patch | 1059 ++++++++++++++++++++ tools/lzma/patches/003-compile_fixes.patch | 26 + tools/lzma/patches/100-static_library.patch | 70 ++ tools/mkcrypt/Makefile | 4 +- tools/mkfimage/Makefile | 4 + tools/mkfimage/mkfimage.c | 72 ++ tools/mkimage/Makefile | 4 +- tools/mtd-utils/Makefile | 24 + tools/mtd-utils/patches/lzo.patch | 88 ++ tools/squashfs/Makefile | 29 + tools/squashfs/patches/cppflags.patch | 12 + tools/srec2bin/Makefile | 4 + tools/srec2bin/srec2bin.c | 521 ++++++++++ tools/syslinux/Makefile | 13 +- tools/trx/Makefile | 4 + tools/trx/trx.c | 366 +++++++ tools/xz/Makefile | 28 + 129 files changed, 5700 insertions(+), 5668 deletions(-) delete mode 100644 target/tools/addpattern/Makefile delete mode 100644 target/tools/addpattern/addpattern.c delete mode 100644 target/tools/lzma-loader/.svn/entries delete mode 100644 target/tools/lzma-loader/.svn/text-base/LzmaDecode.c.svn-base delete mode 100644 target/tools/lzma-loader/.svn/text-base/LzmaDecode.h.svn-base delete mode 100644 target/tools/lzma-loader/.svn/text-base/Makefile.svn-base delete mode 100644 target/tools/lzma-loader/.svn/text-base/README.svn-base delete mode 100644 target/tools/lzma-loader/.svn/text-base/decompress.c.svn-base delete mode 100644 target/tools/lzma-loader/.svn/text-base/decompress.lds.in.svn-base delete mode 100644 target/tools/lzma-loader/.svn/text-base/head.S.svn-base delete mode 100644 target/tools/lzma-loader/.svn/text-base/loader.lds.in.svn-base delete mode 100644 target/tools/lzma-loader/Makefile delete mode 100644 target/tools/lzma-loader/src/LzmaDecode.c delete mode 100644 target/tools/lzma-loader/src/LzmaDecode.h delete mode 100644 target/tools/lzma-loader/src/LzmaDecode.o delete mode 100644 target/tools/lzma-loader/src/Makefile delete mode 100644 target/tools/lzma-loader/src/README delete mode 100644 target/tools/lzma-loader/src/data.lds delete mode 100644 target/tools/lzma-loader/src/data.o delete mode 100755 target/tools/lzma-loader/src/decompress delete mode 100644 target/tools/lzma-loader/src/decompress.c delete mode 100755 target/tools/lzma-loader/src/decompress.image delete mode 100644 target/tools/lzma-loader/src/decompress.lds delete mode 100644 target/tools/lzma-loader/src/decompress.lds.in delete mode 100644 target/tools/lzma-loader/src/decompress.o delete mode 100644 target/tools/lzma-loader/src/head.S delete mode 100644 target/tools/lzma-loader/src/head.o delete mode 100755 target/tools/lzma-loader/src/loader delete mode 100755 target/tools/lzma-loader/src/loader.elf delete mode 100644 target/tools/lzma-loader/src/loader.gz delete mode 100644 target/tools/lzma-loader/src/loader.lds delete mode 100644 target/tools/lzma-loader/src/loader.lds.in delete mode 100755 target/tools/lzma-loader/src/loader.o delete mode 100644 target/tools/lzma/Makefile delete mode 100644 target/tools/lzma/patches/001-large_files.patch delete mode 100644 target/tools/lzma/patches/002-lzmp.patch delete mode 100644 target/tools/lzma/patches/003-compile_fixes.patch delete mode 100644 target/tools/lzma/patches/100-static_library.patch delete mode 100644 target/tools/mkfimage/Makefile delete mode 100644 target/tools/mkfimage/mkfimage.c delete mode 100644 target/tools/mtd-utils/Makefile delete mode 100644 target/tools/mtd-utils/patches/lzo.patch delete mode 100644 target/tools/rules.mk delete mode 100644 target/tools/squashfs/Makefile delete mode 100644 target/tools/squashfs/patches/cppflags.patch delete mode 100644 target/tools/srec2bin/Makefile delete mode 100644 target/tools/srec2bin/srec2bin.c delete mode 100644 target/tools/trx/Makefile delete mode 100644 target/tools/trx/trx.c delete mode 100644 target/tools/xz/Makefile create mode 100644 tools/addpattern/Makefile create mode 100644 tools/addpattern/addpattern.c create mode 100644 tools/lzma-loader/.svn/entries create mode 100644 tools/lzma-loader/.svn/text-base/LzmaDecode.c.svn-base create mode 100644 tools/lzma-loader/.svn/text-base/LzmaDecode.h.svn-base create mode 100644 tools/lzma-loader/.svn/text-base/Makefile.svn-base create mode 100644 tools/lzma-loader/.svn/text-base/README.svn-base create mode 100644 tools/lzma-loader/.svn/text-base/decompress.c.svn-base create mode 100644 tools/lzma-loader/.svn/text-base/decompress.lds.in.svn-base create mode 100644 tools/lzma-loader/.svn/text-base/head.S.svn-base create mode 100644 tools/lzma-loader/.svn/text-base/loader.lds.in.svn-base create mode 100644 tools/lzma-loader/Makefile create mode 100644 tools/lzma-loader/src/LzmaDecode.c create mode 100644 tools/lzma-loader/src/LzmaDecode.h create mode 100644 tools/lzma-loader/src/LzmaDecode.o create mode 100644 tools/lzma-loader/src/Makefile create mode 100644 tools/lzma-loader/src/README create mode 100644 tools/lzma-loader/src/data.lds create mode 100644 tools/lzma-loader/src/data.o create mode 100755 tools/lzma-loader/src/decompress create mode 100644 tools/lzma-loader/src/decompress.c create mode 100755 tools/lzma-loader/src/decompress.image create mode 100644 tools/lzma-loader/src/decompress.lds create mode 100644 tools/lzma-loader/src/decompress.lds.in create mode 100644 tools/lzma-loader/src/decompress.o create mode 100644 tools/lzma-loader/src/head.S create mode 100644 tools/lzma-loader/src/head.o create mode 100755 tools/lzma-loader/src/loader create mode 100755 tools/lzma-loader/src/loader.elf create mode 100644 tools/lzma-loader/src/loader.gz create mode 100644 tools/lzma-loader/src/loader.lds create mode 100644 tools/lzma-loader/src/loader.lds.in create mode 100755 tools/lzma-loader/src/loader.o create mode 100644 tools/lzma/Makefile create mode 100644 tools/lzma/patches/001-large_files.patch create mode 100644 tools/lzma/patches/002-lzmp.patch create mode 100644 tools/lzma/patches/003-compile_fixes.patch create mode 100644 tools/lzma/patches/100-static_library.patch create mode 100644 tools/mkfimage/Makefile create mode 100644 tools/mkfimage/mkfimage.c create mode 100644 tools/mtd-utils/Makefile create mode 100644 tools/mtd-utils/patches/lzo.patch create mode 100644 tools/squashfs/Makefile create mode 100644 tools/squashfs/patches/cppflags.patch create mode 100644 tools/srec2bin/Makefile create mode 100644 tools/srec2bin/srec2bin.c create mode 100644 tools/trx/Makefile create mode 100644 tools/trx/trx.c create mode 100644 tools/xz/Makefile diff --git a/.gitignore b/.gitignore index a4d67734a..fc81d7882 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,6 @@ /host_*/ /pkg_*/ /root_*/ -/bin/ /firmware/ /build_*/ /config/*.o diff --git a/README b/README index 820cc95c9..3e280c165 100644 --- a/README +++ b/README @@ -8,16 +8,11 @@ Before you can start you need to install some tools: - gcc - binutils - GNU make -- GNU m4 - GNU awk - GNU sed - tar - patch - gzip -- bzip2 -- lzop -- lzma -- xz - wget - libc headers - ncurses5 headers @@ -39,3 +34,4 @@ To switch to another target configuration, simply run "make switch". This will backup your existing configuration and will start with an empty one. Sunshine! + Waldemar Brodkorb diff --git a/mk/build.mk b/mk/build.mk index eadccdcb3..d6fd9b20c 100644 --- a/mk/build.mk +++ b/mk/build.mk @@ -91,7 +91,7 @@ POSTCONFIG= -@\ if [ -f .adkinit ];then rm .adkinit;\ else \ if [ -f .config.old ];then \ - $(TOPDIR)/bin/pkgrebuild;\ + $(TOPDIR)/host_$(GNU_HOST_NAME)/usr/bin/pkgrebuild;\ rebuild=0; \ if [ "$$(grep ^BUSYBOX .config|md5sum)" != "$$(grep ^BUSYBOX .config.old|md5sum)" ];then \ touch .rebuild.busybox;\ @@ -138,7 +138,7 @@ include $(TOPDIR)/rules.mk all: world ${TOPDIR}/package/Depends.mk: ${TOPDIR}/.config $(wildcard ${TOPDIR}/package/*/Makefile) - $(BIN_DIR)/depmaker > ${TOPDIR}/package/Depends.mk + $(STAGING_HOST_DIR)/usr/bin/depmaker > ${TOPDIR}/package/Depends.mk .NOTPARALLEL: .PHONY: all world clean cleantarget cleandir distclean image_clean @@ -155,12 +155,12 @@ ifeq ($(ADK_NATIVE),y) else ifeq ($(ADK_TOOLCHAIN),y) ifeq ($(ADK_TOOLCHAIN_ONLY),y) - $(MAKE) -f mk/build.mk toolchain/fixup tools/install package/compile + $(MAKE) -f mk/build.mk tools/install toolchain/fixup package/compile else - $(MAKE) -f mk/build.mk toolchain/fixup tools/install package/compile root_clean package/install + $(MAKE) -f mk/build.mk tools/install toolchain/fixup package/compile root_clean package/install endif else - $(MAKE) -f mk/build.mk toolchain/fixup tools/install target/config-prepare target/compile package/compile root_clean package/install target/install package_index + $(MAKE) -f mk/build.mk tools/install toolchain/fixup target/config-prepare target/compile package/compile root_clean package/install target/install package_index endif endif @@ -250,13 +250,13 @@ root_clean: clean: @$(TRACE) clean $(MAKE) -C $(CONFIG) clean - for d in ${STAGING_PKG_DIR}; do \ - for f in $$(ls $$d/[a-z]* 2>/dev/null |grep -v [A-Z] 2>/dev/null); do \ - while read file ; do \ - rm ${STAGING_DIR}/$$file 2>/dev/null;\ - done < $$f ; \ - rm $$f ; \ - done \ + for f in $$(ls ${STAGING_PKG_DIR}/ 2>/dev/null |grep -v [A-Z]|grep -v stamps 2>/dev/null); do \ + while read file ; do \ + echo ${STAGING_DIR}/$$file ;\ + rm ${STAGING_DIR}/$$file 2>/dev/null;\ + done < $$f ; \ + echo ${STAGING_PKG_DIR}/$$f ;\ + rm ${STAGING_PKG_DIR}/$$f ; \ done rm -rf $(BUILD_DIR) $(FW_DIR) $(TARGET_DIR) \ ${TOPDIR}/package/pkglist.d @@ -619,24 +619,24 @@ bulkallmod: if [ -f .exit ];then echo "Bulk build failed!"; cat .exit;rm .exit; exit 1;fi \ done -${TOPDIR}/bin/pkgmaker: $(TOPDIR)/tools/adk/pkgmaker.c $(TOPDIR)/tools/adk/sortfile.c $(TOPDIR)/tools/adk/strmap.c - @mkdir -p ${TOPDIR}/bin +$(TOPDIR)/host_$(GNU_HOST_NAME)/usr/bin/pkgmaker: $(TOPDIR)/tools/adk/pkgmaker.c $(TOPDIR)/tools/adk/sortfile.c $(TOPDIR)/tools/adk/strmap.c + @mkdir -p host_$(GNU_HOST_NAME)/usr/bin @$(CC_FOR_BUILD) -g -o $@ tools/adk/pkgmaker.c tools/adk/sortfile.c tools/adk/strmap.c -${TOPDIR}/bin/pkgrebuild: $(TOPDIR)/tools/adk/pkgrebuild.c $(TOPDIR)/tools/adk/strmap.c +$(TOPDIR)/host_$(GNU_HOST_NAME)/usr/bin/pkgrebuild: $(TOPDIR)/tools/adk/pkgrebuild.c $(TOPDIR)/tools/adk/strmap.c @$(CC_FOR_BUILD) -g -o $@ tools/adk/pkgrebuild.c tools/adk/strmap.c -package/Config.in.auto menu .menu: $(wildcard ${TOPDIR}/package/*/Makefile) ${TOPDIR}/bin/pkgmaker ${TOPDIR}/bin/pkgrebuild +package/Config.in.auto menu .menu: $(wildcard ${TOPDIR}/package/*/Makefile) $(TOPDIR)/host_$(GNU_HOST_NAME)/usr/bin/pkgmaker $(TOPDIR)/host_$(GNU_HOST_NAME)/usr/bin/pkgrebuild @echo "Generating menu structure ..." - @$(TOPDIR)/bin/pkgmaker + @$(TOPDIR)/host_$(GNU_HOST_NAME)/usr/bin/pkgmaker @:>.menu -${TOPDIR}/bin/depmaker: $(TOPDIR)/tools/adk/depmaker.c - $(CC_FOR_BUILD) -g -o $(TOPDIR)/bin/depmaker $(TOPDIR)/tools/adk/depmaker.c +$(TOPDIR)/host_$(GNU_HOST_NAME)/usr/bin/depmaker: $(TOPDIR)/tools/adk/depmaker.c + $(CC_FOR_BUILD) -g -o $@ $(TOPDIR)/tools/adk/depmaker.c -dep: $(TOPDIR)/bin/depmaker +dep: $(TOPDIR)/host_$(GNU_HOST_NAME)/usr/bin/depmaker @echo "Generating dependencies ..." - @$(TOPDIR)/bin/depmaker > ${TOPDIR}/package/Depends.mk + @$(TOPDIR)/host_$(GNU_HOST_NAME)/usr/bin/depmaker > ${TOPDIR}/package/Depends.mk .PHONY: menu dep diff --git a/mk/host.mk b/mk/host.mk index 3fcca0664..aa88bab44 100644 --- a/mk/host.mk +++ b/mk/host.mk @@ -37,7 +37,7 @@ _HOST_PATCH_COOKIE= ${WRKDIST}/.prepared _HOST_CONFIGURE_COOKIE= ${WRKDIR}/.host_configure_done _HOST_BUILD_COOKIE= ${WRKDIR}/.host_build_done _HOST_FAKE_COOKIE= ${HOST_WRKINST}/.host_fake_done -_HOST_COOKIE= ${STAGING_PKG_DIR}/${PKG_NAME}${PKG_VERSION}-${PKG_RELEASE}-host +_HOST_COOKIE= ${STAGING_PKG_DIR}/stamps/${PKG_NAME}${PKG_VERSION}-${PKG_RELEASE}-host hostextract: ${_HOST_EXTRACT_COOKIE} hostpatch: ${_HOST_PATCH_COOKIE} diff --git a/mk/image.mk b/mk/image.mk index 9b60c2400..571752eaf 100644 --- a/mk/image.mk +++ b/mk/image.mk @@ -136,15 +136,15 @@ endif ${FW_DIR}/${ROOTFSTARBALL}: ${TARGET_DIR} kernel-package cd ${TARGET_DIR}; find . | sed -n '/^\.\//s///p' | \ sed "s#\(.*\)#:0:0::::::\1#" | sort | \ - ${BIN_DIR}/cpio -o -Hustar -P | gzip -n9 >$@ + ${STAGING_HOST_DIR}/usr/bin/cpio -o -Hustar -P | gzip -n9 >$@ ${FW_DIR}/${ROOTFSUSERTARBALL}: ${TARGET_DIR} cd ${TARGET_DIR}; find . | grep -v ./boot/ | sed -n '/^\.\//s///p' | \ sed "s#\(.*\)#:0:0::::::\1#" | sort | \ - ${BIN_DIR}/cpio -o -Hustar -P | gzip -n9 >$@ + ${STAGING_HOST_DIR}/usr/bin/cpio -o -Hustar -P | gzip -n9 >$@ ${FW_DIR}/${INITRAMFS}_list: ${TARGET_DIR} - bash ${LINUX_DIR}/scripts/gen_initramfs_list.sh -u squash -g squash \ + $(BASH) ${LINUX_DIR}/scripts/gen_initramfs_list.sh -u squash -g squash \ ${TARGET_DIR}/ >$@ ( \ echo "nod /dev/console 0644 0 0 c 5 1"; \ @@ -162,12 +162,12 @@ ${FW_DIR}/${INITRAMFS}: ${FW_DIR}/${INITRAMFS}_list ${ADK_COMPRESSION_TOOL} -c >$@ ${BUILD_DIR}/root.squashfs: ${TARGET_DIR} - ${STAGING_HOST_DIR}/bin/mksquashfs ${TARGET_DIR} \ + ${STAGING_HOST_DIR}/usr/bin/mksquashfs ${TARGET_DIR} \ ${BUILD_DIR}/root.squashfs -comp xz \ -nopad -noappend -root-owned $(MAKE_TRACE) ${FW_DIR}/${ROOTFSJFFS2}: ${TARGET_DIR} - ${STAGING_HOST_DIR}/bin/mkfs.jffs2 $(ADK_JFFS2_OPTS) -q -r ${TARGET_DIR} \ + ${STAGING_HOST_DIR}/usr/bin/mkfs.jffs2 $(ADK_JFFS2_OPTS) -q -r ${TARGET_DIR} \ --pad=$(ADK_TARGET_MTD_SIZE) -o ${FW_DIR}/${ROOTFSJFFS2} $(MAKE_TRACE) createinitramfs: ${FW_DIR}/${INITRAMFS}_list @@ -242,7 +242,7 @@ ${FW_DIR}/${ROOTFSISO}: ${TARGET_DIR} kernel-package ${TARGET_DIR}/boot/syslinux echo 'DEFAULT /boot/kernel root=/dev/sr0 init=/init' > \ ${TARGET_DIR}/boot/syslinux/isolinux.cfg - ${BIN_DIR}/mkisofs -R -uid 0 -gid 0 -o $@ \ + ${STAGING_HOST_DIR}/usr/bin/mkisofs -R -uid 0 -gid 0 -o $@ \ -b boot/syslinux/isolinux.bin \ -c boot/syslinux/boot.cat -no-emul-boot \ -boot-load-size 4 -boot-info-table ${TARGET_DIR} diff --git a/mk/kernel-vars.mk b/mk/kernel-vars.mk index d668f7edb..0b3e7ddbb 100644 --- a/mk/kernel-vars.mk +++ b/mk/kernel-vars.mk @@ -25,4 +25,4 @@ ADK_KCPPFLAGS+= -DBCM47XX_OVERRIDE_FLASHSIZE=0x800000 \ endif KERNEL_MAKE_ENV+= KCPPFLAGS='${ADK_KCPPFLAGS}' \ - PATH="${BIN_DIR}:$$PATH" + PATH="${STAGING_HOST_DIR}/usr/bin:$$PATH" diff --git a/mk/package.mk b/mk/package.mk index 125ed3d26..264cd06e0 100644 --- a/mk/package.mk +++ b/mk/package.mk @@ -249,7 +249,7 @@ endif find usr ! -type d 2>/dev/null | \ grep -E -v -e '^usr/lib/pkgconfig' -e '^usr/share' -e '^usr/doc' -e '^usr/src' -e '^usr/man' -e '^usr/info' -e '^usr/lib/libc.so' -e '^usr/bin/[a-z0-9-]+-config' | \ tee '$${STAGING_PKG_DIR}/$(1)' | \ - $(BIN_DIR)/cpio -padlmu '$${STAGING_DIR}' + $(STAGING_HOST_DIR)/usr/bin/cpio -padlmu '$${STAGING_DIR}' @cd '$${STAGING_DIR}'; grep 'usr/lib/.*\.la$$$$' \ '$${STAGING_PKG_DIR}/$(1)' | while read fn; do \ chmod u+w $$$$fn; \ diff --git a/mk/pkg-bottom.mk b/mk/pkg-bottom.mk index d82a653ea..3988a676f 100644 --- a/mk/pkg-bottom.mk +++ b/mk/pkg-bottom.mk @@ -171,11 +171,11 @@ ifneq (,$(filter dev,${PKG_OPTS})) @mkdir -p $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/include @test -d ${WRKINST}/usr/include && cd ${WRKINST}/usr/include; \ find . -name \*.h | \ - $(BIN_DIR)/cpio -padlmu $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/include + $(STAGING_HOST_DIR)/usr/bin/cpio -padlmu $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/include @mkdir -p $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/lib/pkgconfig @test -d ${WRKINST}/usr/lib/pkgconfig && cd ${WRKINST}/usr/lib/pkgconfig; \ find . -name \*.pc | \ - $(BIN_DIR)/cpio -padlmu $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/lib/pkgconfig + $(STAGING_HOST_DIR)/usr/bin/cpio -padlmu $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/lib/pkgconfig @for a in ${WRKINST}/usr/bin/*-config*; do \ [[ -e $$a ]] || continue; \ mkdir -p $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(PKG_LIBNAME)-dev/usr/bin; \ @@ -191,7 +191,7 @@ endif find usr ! -type d 2>/dev/null | \ grep -E -v -e '^usr/lib/pkgconfig' -e '^usr/share' -e '^usr/src' -e '^usr/doc' -e '^usr/local' -e '^usr/man' -e '^usr/info' -e '^usr/lib/libc.so' -e '^usr/bin/[a-z0-9-]+-config*' -e '^/usr/lib/libpthread_nonshared.a' | \ tee '${STAGING_PKG_DIR}/${PKG_NAME}' | \ - $(BIN_DIR)/cpio -padlmu '${STAGING_DIR}' + $(STAGING_HOST_DIR)/usr/bin/cpio -padlmu '${STAGING_DIR}' @cd '${STAGING_DIR}'; grep 'usr/lib/.*\.la$$' \ '${STAGING_PKG_DIR}/${PKG_NAME}' | while read fn; do \ chmod u+w $$fn; \ diff --git a/mk/vars.mk b/mk/vars.mk index 427b5b4ec..a9b213e4c 100644 --- a/mk/vars.mk +++ b/mk/vars.mk @@ -16,34 +16,38 @@ BUILD_DIR:= ${BASE_DIR}/build_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIB BUILD_DIR_PFX:= $(BASE_DIR)/build_* STAGING_PKG_DIR:= ${BASE_DIR}/pkg_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC} STAGING_PKG_DIR_PFX:= ${BASE_DIR}/pkg_* -STAGING_HOST_DIR:= ${BASE_DIR}/host_${CPU_ARCH}_${ADK_TARGET_SUFFIX}_${ADK_TARGET_LIBC} +STAGING_HOST_DIR:= ${BASE_DIR}/host_${GNU_HOST_NAME} STAGING_HOST_DIR_PFX:= ${BASE_DIR}/host_* # use headers and foo-config from system ifeq ($(ADK_NATIVE),y) STAGING_TARGET_DIR:= SCRIPT_TARGET_DIR:= /usr/bin else -STAGING_TARGET_DIR:= ${BASE_DIR}/target_${CPU_ARCH}_${ADK_TARGET_SUFFIX}_${ADK_TARGET_LIBC} +ifeq ($(ADK_TARGET_ABI),) +STAGING_TARGET_DIR:= ${BASE_DIR}/target_${CPU_ARCH}_${ADK_TARGET_LIBC} +STAGING_DIR:= ${BASE_DIR}/target_${CPU_ARCH}_${ADK_TARGET_LIBC} +STAGING_HOST2TARGET:= ../target_${CPU_ARCH}_${ADK_TARGET_LIBC} +TOOLCHAIN_BUILD_DIR= $(BASE_DIR)/toolchain_build_${CPU_ARCH}_${ADK_TARGET_LIBC} +else +STAGING_TARGET_DIR:= ${BASE_DIR}/target_${CPU_ARCH}_${ADK_TARGET_LIBC}_${ADK_TARGET_ABI} +STAGING_DIR:= ${BASE_DIR}/target_${CPU_ARCH}_${ADK_TARGET_LIBC}_${ADK_TARGET_ABI} +STAGING_HOST2TARGET:= ../target_${CPU_ARCH}_${ADK_TARGET_LIBC}_${ADK_TARGET_ABI} +TOOLCHAIN_BUILD_DIR= $(BASE_DIR)/toolchain_build_${CPU_ARCH}_${ADK_TARGET_LIBC}_${ADK_TARGET_ABI} +endif SCRIPT_TARGET_DIR:= ${STAGING_TARGET_DIR}/scripts endif -STAGING_DIR:= ${BASE_DIR}/target_${CPU_ARCH}_${ADK_TARGET_SUFFIX}_${ADK_TARGET_LIBC} STAGING_TARGET_DIR_PFX:=${BASE_DIR}/target_* -# relation from STAGING_HOST_DIR to STAGING_TARGET_DIR (for gcc to find -# its sysroot while staying relocatable) -STAGING_HOST2TARGET:= ../target_${CPU_ARCH}_${ADK_TARGET_SUFFIX}_${ADK_TARGET_LIBC} -TOOLCHAIN_BUILD_DIR= $(BASE_DIR)/toolchain_build_${CPU_ARCH}_${ADK_TARGET_SUFFIX}_${ADK_TARGET_LIBC} TOOLCHAIN_BUILD_DIR_PFX=$(BASE_DIR)/toolchain_build_* TOOLS_BUILD_DIR= $(BASE_DIR)/tools_build -BIN_DIR:= $(BASE_DIR)/bin SCRIPT_DIR:= $(BASE_DIR)/scripts FW_DIR:= $(BASE_DIR)/firmware/${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC} FW_DIR_PFX:= $(BASE_DIR)/firmware PACKAGE_DIR:= $(FW_DIR)/packages TARGET_DIR:= $(BASE_DIR)/root_${ADK_TARGET_SYSTEM}_${CPU_ARCH}_${ADK_TARGET_LIBC} TARGET_DIR_PFX:= $(BASE_DIR)/root_* -TARGET_PATH= ${SCRIPT_DIR}:${BIN_DIR}:${STAGING_TARGET_DIR}/scripts:${STAGING_HOST_DIR}/bin:${STAGING_HOST_DIR}/usr/bin:${_PATH} -HOST_PATH= ${SCRIPT_DIR}:${BIN_DIR}:${STAGING_HOST_DIR}/bin:${STAGING_HOST_DIR}/usr/bin:${_PATH} -AUTOTOOL_PATH= ${BIN_DIR}:${STAGING_HOST_DIR}/bin:${STAGING_HOST_DIR}/usr/bin:${STAGING_TARGET_DIR}/scripts:${_PATH} +TARGET_PATH= ${SCRIPT_DIR}:${STAGING_TARGET_DIR}/scripts:${STAGING_HOST_DIR}/bin:${STAGING_HOST_DIR}/usr/bin:${_PATH} +HOST_PATH= ${SCRIPT_DIR}:${STAGING_HOST_DIR}/bin:${STAGING_HOST_DIR}/usr/bin:${_PATH} +AUTOTOOL_PATH= ${STAGING_HOST_DIR}/bin:${STAGING_HOST_DIR}/usr/bin:${STAGING_TARGET_DIR}/scripts:${_PATH} REAL_GNU_TARGET_NAME= $(CPU_ARCH)-$(ADK_VENDOR)-linux-$(ADK_TARGET_SUFFIX) GNU_TARGET_NAME= $(CPU_ARCH)-$(ADK_VENDOR)-linux @@ -185,7 +189,7 @@ PKG_INSTALL:= IPKG_TMP=$(BUILD_DIR)/tmp \ IPKG_INSTROOT=$(TARGET_DIR) \ IPKG_CONF_DIR=$(STAGING_TARGET_DIR)/etc \ IPKG_OFFLINE_ROOT=$(TARGET_DIR) \ - BIN_DIR=$(BIN_DIR) \ + BIN_DIR=$(STAGING_HOST_DIR)/usr/bin \ ${BASH} ${SCRIPT_DIR}/ipkg \ -force-defaults -force-depends install PKG_STATE_DIR:= $(TARGET_DIR)/usr/lib/ipkg @@ -208,21 +212,21 @@ EXTRACT_CMD= mkdir -p ${WRKDIR}; \ cd ${WRKDIR} && \ for file in ${FULLDISTFILES}; do case $$file in \ *.cpio) \ - cat $$file | $(BIN_DIR)/cpio -i -d ;; \ + cat $$file | $(STAGING_HOST_DIR)/usr/bin/cpio -i -d ;; \ *.tar) \ tar -xf $$file ;; \ *.cpio.Z | *.cpio.gz | *.cgz | *.mcz) \ - gzip -dc $$file | $(BIN_DIR)/cpio -i -d ;; \ + gzip -dc $$file | $(STAGING_HOST_DIR)/usr/bin/cpio -i -d ;; \ *.tar.xz | *.txz) \ - xz -dc $$file | tar -xf - ;; \ + $(STAGING_HOST_DIR)/usr/bin/xz -dc $$file | tar -xf - ;; \ *.tar.Z | *.tar.gz | *.taz | *.tgz) \ gzip -dc $$file | tar -xf - ;; \ *.cpio.bz2 | *.cbz) \ - bzip2 -dc $$file | $(BIN_DIR)/cpio -i -d ;; \ + $(STAGING_HOST_DIR)/usr/bin/bzip2 -dc $$file | $(STAGING_HOST_DIR)/usr/bin/cpio -i -d ;; \ *.tar.bz2 | *.tbz | *.tbz2) \ - bzip2 -dc $$file | tar -xf - ;; \ + $(STAGING_HOST_DIR)/usr/bin/bzip2 -dc $$file | tar -xf - ;; \ *.zip) \ - cat $$file | $(BIN_DIR)/cpio -ivd -H zip ;; \ + cat $$file | $(STAGING_HOST_DIR)/usr/bin/cpio -ivd -H zip ;; \ *.arm) \ cp $$file ${WRKDIR} ;; \ *) \ diff --git a/package/base-files/Makefile b/package/base-files/Makefile index 0eb3a40b3..ad09f8d3d 100644 --- a/package/base-files/Makefile +++ b/package/base-files/Makefile @@ -85,7 +85,7 @@ endif echo "::1 localhost" >> $(IDIR_BASE_FILES)/etc/hosts echo "127.0.1.1 $(ADK_RUNTIME_HOSTNAME)" >> $(IDIR_BASE_FILES)/etc/hosts test -z $(ADK_RUNTIME_PASSWORD) || \ - $(SED) 's,\*NP\*,'"$$(${TOPDIR}/bin/mkcrypt \ + $(SED) 's,\*NP\*,'"$$($(STAGING_HOST_DIR)/usr/bin/mkcrypt \ ${ADK_RUNTIME_PASSWORD}),g" $(IDIR_BASE_FILES)/etc/shadow git log -1|head -1|sed -e 's#commit ##' \ > $(IDIR_BASE_FILES)/etc/adkversion diff --git a/package/gcc/Makefile b/package/gcc/Makefile index 4b8480342..9e043401a 100644 --- a/package/gcc/Makefile +++ b/package/gcc/Makefile @@ -26,13 +26,13 @@ TARGET_CFLAGS:= '' TARGET_CXXFLAGS:= $(filter-out -fstack-protector,$(TARGET_CXXFLAGS)) ifeq ($(ADK_TARGET_SYSTEM_LEMOTE_YEELONG),y) -CONFIGURE_ARGS+= --with-abi=$(ADK_TARGET_ABI) +CONFIGURE_ARGS+= --with-abi=$(ADK_TARGET_MIPS_ABI) endif ifeq ($(ADK_TARGET_SYSTEM_QEMU_MIPS64),y) -CONFIGURE_ARGS+= --with-abi=$(ADK_TARGET_ABI) +CONFIGURE_ARGS+= --with-abi=$(ADK_TARGET_MIPS_ABI) endif ifeq ($(ADK_TARGET_SYSTEM_QEMU_MIPS64EL),y) -CONFIGURE_ARGS+= --with-abi=$(ADK_TARGET_ABI) +CONFIGURE_ARGS+= --with-abi=$(ADK_TARGET_MIPS_ABI) endif ifeq ($(ADK_TOOLCHAIN_GCC_SJLJ),y) diff --git a/rules.mk b/rules.mk index 8865327f8..c4f7594ee 100644 --- a/rules.mk +++ b/rules.mk @@ -39,6 +39,7 @@ ADK_TARGET_ABI_CFLAGS:= $(strip $(subst ",, $(ADK_TARGET_ABI_CFLAGS))) ADK_TARGET_ABI_LDFLAGS:= $(strip $(subst ",, $(ADK_TARGET_ABI_LDFLAGS))) ADK_TARGET_KERNEL_LDFLAGS:= $(strip $(subst ",, $(ADK_TARGET_KERNEL_LDFLAGS))) ADK_TARGET_ABI:= $(strip $(subst ",, $(ADK_TARGET_ABI))) +ADK_TARGET_MIPS_ABI:= $(strip $(subst ",, $(ADK_TARGET_MIPS_ABI))) ADK_TARGET_IP:= $(strip $(subst ",, $(ADK_TARGET_IP))) ADK_TARGET_SUFFIX:= $(strip $(subst ",, $(ADK_TARGET_SUFFIX))) ADK_TARGET_CMDLINE:= $(strip $(subst ",, $(ADK_TARGET_CMDLINE))) diff --git a/scripts/create.sh b/scripts/create.sh index 634a87643..f5309f884 100755 --- a/scripts/create.sh +++ b/scripts/create.sh @@ -28,11 +28,12 @@ # root partition and an OpenADK cfgfs partition. TOPDIR=$(pwd) +HOST=$(gcc -dumpmachine) me=$0 case :$PATH: in -(*:$TOPDIR/bin:*) ;; -(*) export PATH=$PATH:$TOPDIR/bin ;; +(*:$TOPDIR/host_$HOST/usr/bin:*) ;; +(*) export PATH=$PATH:$TOPDIR/host_$HOST/usr/bin ;; esac test -n "$KSH_VERSION" || if ! which mksh >/dev/null 2>&1; then diff --git a/scripts/scan-tools.sh b/scripts/scan-tools.sh index a060d24fc..af3223b0b 100644 --- a/scripts/scan-tools.sh +++ b/scripts/scan-tools.sh @@ -112,30 +112,6 @@ if ! which gzip >/dev/null 2>&1; then out=1 fi -if ! which bzip2 >/dev/null 2>&1; then - echo You must install bzip2 to continue. - echo - out=1 -fi - -if ! which lzop >/dev/null 2>&1; then - echo You must install lzop to continue. - echo - out=1 -fi - -if ! which lzma >/dev/null 2>&1; then - echo You must install lzma to continue. - echo - out=1 -fi - -if ! which xz >/dev/null 2>&1; then - echo You must install xz-utils to continue. - echo - out=1 -fi - if ! which patch >/dev/null 2>&1; then echo You must install patch to continue. echo @@ -219,18 +195,6 @@ if ! which perl >/dev/null 2>&1; then out=1 fi -if ! which m4 >/dev/null 2>&1; then - echo "You must install m4 (macro processor) to continue." - echo - out=1 -fi - -if ! which bc >/dev/null 2>&1; then - echo "You need bc to continue." - echo - out=1 -fi - if ! which xargs >/dev/null 2>&1; then echo "You need xargs to continue." echo diff --git a/target/config/Config.in b/target/config/Config.in index 68e2eefb0..f59bdd5b7 100644 --- a/target/config/Config.in +++ b/target/config/Config.in @@ -117,6 +117,17 @@ config ADK_n64 boolean config ADK_TARGET_ABI + string + default "o32" if ADK_o32 + default "n32" if ADK_n32 + default "n64" if ADK_n64 + default "32" if ADK_32 + default "x32" if ADK_x32 + default "64" if ADK_64 + default "eabi" if ADK_EABI + default "eabihf" if ADK_EABIHF + +config ADK_TARGET_MIPS_ABI string default "32" if ADK_o32 default "n32" if ADK_n32 @@ -650,6 +661,7 @@ config ADK_TARGET_LIB_EGLIBC prompt "Embedded GNU C library" boolean select ADK_eglibc + select ADK_HOST_NEED_GPERF depends on \ ADK_LINUX_ARM || \ ADK_LINUX_ARMEB || \ @@ -719,6 +731,11 @@ config ADK_TARGET_SUFFIX default "muslgnueabihf" if ADK_TARGET_LIB_MUSL && ADK_EABIHF default "muslgnueabi" if ADK_TARGET_LIB_MUSL && ADK_EABI default "musl" if ADK_TARGET_LIB_MUSL && !ADK_EABI + default "n64" if ADK_n64 + default "n32" if ADK_n32 + default "o32" if ADK_o32 + default "32" if ADK_32 + default "x32" if ADK_x32 default "gnu" choice @@ -767,6 +784,7 @@ config ADK_TARGET_ROOTFS_INITRAMFS_PIGGYBACK config ADK_TARGET_ROOTFS_SQUASHFS bool "Compressed read-only root filesystem (squashfs)" select ADK_KERNEL_SQUASHFS + select ADK_HOST_NEED_SQUASHFS depends on ADK_TARGET_WITH_MTD help highly compressed read-only filesystem for MTD flash systems. @@ -775,6 +793,7 @@ config ADK_TARGET_ROOTFS_JFFS2 bool "Compressed read-write root filesystem (jffs2)" select ADK_KERNEL_MISC_FILESYSTEMS select ADK_KERNEL_JFFS2 + select ADK_HOST_NEED_JFFS2 depends on ADK_TARGET_WITH_MTD help compressed read-write filesystem for MTD flash systems. @@ -833,6 +852,7 @@ config ADK_TARGET_ROOTFS_GENEXT2FS depends on ADK_TARGET_WITH_CF select ADK_KERNEL_EXT2_FS select ADK_KERNEL_SCSI + select ADK_HOST_NEED_GENEXT2FS help Use this option if you have a compact flash based system. (ext2 filesystem is used.) @@ -853,6 +873,8 @@ config ADK_TARGET_ROOTFS_ISO select ADK_KERNEL_JOLIET select ADK_KERNEL_SCSI select ADK_KERNEL_BLK_DEV_SR + select ADK_HOST_NEED_MKISOFS + select ADK_HOST_NEED_SYSLINUX depends on ADK_HOST_LINUX depends on ADK_LINUX_X86 help @@ -860,6 +882,7 @@ config ADK_TARGET_ROOTFS_ISO config ADK_TARGET_ROOTFS_ARCHIVE bool "Archive usable for different filesystems" + select ADK_HOST_NEED_GENEXT2FS if ADK_HARDWARE_QEMU select ADK_KERNEL_EXT2_FS if ADK_HARDWARE_QEMU depends on !ADK_LINUX_MICROBLAZE help diff --git a/target/config/Config.in.tools b/target/config/Config.in.tools index 31246458d..cf92eadee 100644 --- a/target/config/Config.in.tools +++ b/target/config/Config.in.tools @@ -1,3 +1,43 @@ +config ADK_HOST_NEED_MKISOFS + boolean + default n + +config ADK_HOST_NEED_SYSLINUX + boolean + default n + +config ADK_HOST_NEED_GPERF + boolean + default n + +config ADK_HOST_NEED_SQUASHFS + boolean + default n + +config ADK_HOST_NEED_JFFS2 + boolean + default n + +config ADK_HOST_NEED_GENEXT2FS + boolean + default n + +config ADK_HOST_NEED_LZOP + boolean + default n + +config ADK_HOST_NEED_LZMA + boolean + default n + +config ADK_HOST_NEED_BZIP2 + boolean + default n + +config ADK_HOST_NEED_XZ + boolean + default n + config ADK_TOOLS_ADDPATTERN_ARGS string default "-p W54G -v v4.20.6" if ADK_TARGET_BROADCOM_MODEL_LINKSYS_WRT54G diff --git a/target/linux/config/Config.in.kernel b/target/linux/config/Config.in.kernel index db1ab5c57..d928cea09 100644 --- a/target/linux/config/Config.in.kernel +++ b/target/linux/config/Config.in.kernel @@ -11,18 +11,22 @@ config ADK_KERNEL_INITRAMFS_COMPRESSION_NONE boolean config ADK_KERNEL_INITRAMFS_COMPRESSION_XZ + select ADK_HOST_NEED_XZ boolean config ADK_KERNEL_INITRAMFS_COMPRESSION_LZMA + select ADK_HOST_NEED_LZMA boolean config ADK_KERNEL_INITRAMFS_COMPRESSION_LZO + select ADK_HOST_NEED_LZOP boolean -config ADK_KERNEL_INITRAMFS_COMPRESSION_GZIP +config ADK_KERNEL_INITRAMFS_COMPRESSION_BZIP2 + select ADK_HOST_NEED_BZIP2 boolean -config ADK_KERNEL_INITRAMFS_COMPRESSION_BZIP2 +config ADK_KERNEL_INITRAMFS_COMPRESSION_GZIP boolean config ADK_KERNEL_RD_GZIP diff --git a/target/microblaze/Makefile b/target/microblaze/Makefile index 7a411aa95..c3b6dfa7e 100644 --- a/target/microblaze/Makefile +++ b/target/microblaze/Makefile @@ -9,11 +9,6 @@ include $(TOPDIR)/mk/image.mk KERNEL:=$(LINUX_DIR)/arch/microblaze/boot/$(ADK_TARGET_KERNEL) -tools-compile: - $(MAKE) -C ../tools/mtd-utils all - $(MAKE) -C ../tools/xz all - $(MAKE) -C ../tools/squashfs all - ifeq ($(ADK_TARGET_QEMU_MICROBLAZE_MODEL_ML605),y) MODEL:=petalogix-ml605 DTB:=-dtb target/microblaze/ml605.dtb @@ -24,7 +19,7 @@ DTB:= endif ifeq ($(ADK_TARGET_FS),squashfs) -imageinstall: tools-compile $(BUILD_DIR)/root.squashfs +imageinstall: $(BUILD_DIR)/root.squashfs qemu-img create -f raw $(FW_DIR)/$(ROOTFSSQUASHFS) $(ADK_TARGET_MTD_SIZE) dd conv=notrunc if=$(BUILD_DIR)/root.squashfs of=$(FW_DIR)/$(ROOTFSSQUASHFS) @cp $(KERNEL) $(FW_DIR)/$(TARGET_KERNEL) @@ -34,7 +29,7 @@ ifneq ($(ADK_HARDWARE_QEMU),) endif endif ifeq ($(ADK_TARGET_FS),jffs2) -imageinstall: tools-compile $(FW_DIR)/$(ROOTFSJFFS2) +imageinstall: $(FW_DIR)/$(ROOTFSJFFS2) @cp $(KERNEL) $(FW_DIR)/$(TARGET_KERNEL) ifneq ($(ADK_HARDWARE_QEMU),) @echo "Start qemu with following options:" diff --git a/target/mips/Makefile b/target/mips/Makefile index 31cbc319a..5ebbe5d7d 100644 --- a/target/mips/Makefile +++ b/target/mips/Makefile @@ -11,16 +11,8 @@ KERNEL:=$(LINUX_DIR)/$(ADK_TARGET_KERNEL) OSTRIP:=-R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -tools-compile: - $(MAKE) -C ../tools/trx all - $(MAKE) -C ../tools/addpattern all - $(MAKE) -C ../tools/srec2bin all - $(MAKE) -C ../tools/squashfs all - $(MAKE) -C ../tools/lzma all - $(MAKE) -C ../tools/lzma-loader all - ifeq ($(ADK_TARGET_SYSTEM_BROADCOM_BCM47XX),y) -kernel-install: tools-compile +kernel-install: ${TARGET_CROSS}objcopy ${OSTRIP} -S ${LINUX_DIR}/vmlinuz.elf \ ${BUILD_DIR}/${TARGET_KERNEL} @@ -39,7 +31,7 @@ endif endif ifeq ($(ADK_TARGET_SYSTEM_LINKSYS_AG241),y) -kernel-install: tools-compile +kernel-install: ${TARGET_CROSS}objcopy -S -O srec $(KERNEL) $(LINUX_DIR)/vmlinux.srec PATH='${TARGET_PATH}' srec2bin $(LINUX_DIR)/vmlinux.srec $(LINUX_DIR)/vmlinux.bin (dd if=/dev/zero bs=16 count=1; cat $(LINUX_DIR)/vmlinux.bin) > $(LINUX_DIR)/vmlinux.tmp @@ -56,7 +48,7 @@ kernel-install: $(TARGET_CROSS)objcopy $(OSTRIP) -S $(KERNEL) $(BUILD_DIR)/$(TARGET_KERNEL) endif ifeq ($(ADK_TARGET_SYSTEM_FON_FON2100),y) -kernel-install: tools-compile +kernel-install: $(TARGET_CROSS)objcopy $(OSTRIP) -S $(KERNEL) $(BUILD_DIR)/$(TARGET_KERNEL) ${BUILD_DIR}/${ROOTFSSQUASHFS}: ${BUILD_DIR}/root.squashfs diff --git a/target/tools/addpattern/Makefile b/target/tools/addpattern/Makefile deleted file mode 100644 index 596daeb52..000000000 --- a/target/tools/addpattern/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -include $(TOPDIR)/rules.mk - -all: addpattern.c - $(CC_FOR_BUILD) $(FLAGS_FOR_BUILD) -o ${STAGING_HOST_DIR}/bin/addpattern addpattern.c diff --git a/target/tools/addpattern/addpattern.c b/target/tools/addpattern/addpattern.c deleted file mode 100644 index 8133bf26e..000000000 --- a/target/tools/addpattern/addpattern.c +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright (C) 2004 Manuel Novoa III - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* July 29, 2004 - * - * This is a hacked replacement for the 'addpattern' utility used to - * create wrt54g .bin firmware files. It isn't pretty, but it does - * the job for me. - * - * Extensions: - * -v allows setting the version string on the command line. - * -{0|1} sets the (currently ignored) hw_ver flag in the header - * to 0 or 1 respectively. - */ - -/* January 12, 2005 - * - * Modified by rodent at rodent dot za dot net - * Support added for the new WRT54G v2.2 and WRT54GS v1.1 "flags" - * Without the flags set to 0x7, the above units will refuse to flash. - * - * Extensions: - * -{0|1|2} sets {0|1} sets hw_ver flag to 0/1. {2} sets hw_ver to 1 - * and adds the new hardware "flags" for the v2.2/v1.1 units -*/ - -/* January 1, 2007 - * - * Modified by juan.i.gonzalez at subdown dot net - * Support added for the AG241v2 and similar - * - * Extensions: - * -r #.# adds revision hardware flags. AG241v2 and similar. - * - * AG241V2 firmware sets the hw_ver to 0x44. - * - * Example: -r 2.0 - * - * Convert 2.0 to 20 to be an integer, and add 0x30 to skip special ASCII - * #define HW_Version ((HW_REV * 10) + 0x30) -> from cyutils.h -*/ - -#include -#include -#include -#include -#include -#include - -/**********************************************************************/ - -#define CODE_ID "U2ND" /* from code_pattern.h */ -#define CODE_PATTERN "W54S" /* from code_pattern.h */ -#define PBOT_PATTERN "PBOT" - -#define CYBERTAN_VERSION "v3.37.2" /* from cyutils.h */ - -/* WRT54G v2.2 and WRT54GS v1.1 "flags" (from 3.37.32 firmware cyutils.h) */ -#define SUPPORT_4712_CHIP 0x0001 -#define SUPPORT_INTEL_FLASH 0x0002 -#define SUPPORT_5325E_SWITCH 0x0004 - -struct code_header { /* from cyutils.h */ - char magic[4]; - char res1[4]; /* for extra magic */ - char fwdate[3]; - char fwvern[3]; - char id[4]; /* U2ND */ - char hw_ver; /* 0: for 4702, 1: for 4712 -- new in 2.04.3 */ - char unused; - unsigned char flags[2]; /* SUPPORT_ flags new for 3.37.2 (WRT54G v2.2 and WRT54GS v1.1) */ - unsigned char res2[10]; -} ; - -/**********************************************************************/ - -void usage(void) __attribute__ (( __noreturn__ )); - -void usage(void) -{ - fprintf(stderr, "Usage: addpattern [-i trxfile] [-o binfile] [-p pattern] [-g] [-b] [-v v#.#.#] [-r #.#] [-{0|1|2|4}] -h\n"); - exit(EXIT_FAILURE); -} - -int main(int argc, char **argv) -{ - char buf[1024]; /* keep this at 1k or adjust garbage calc below */ - struct code_header *hdr; - FILE *in = stdin; - FILE *out = stdout; - char *ifn = NULL; - char *ofn = NULL; - char *pattern = CODE_PATTERN; - char *pbotpat = PBOT_PATTERN; - char *version = CYBERTAN_VERSION; - int gflag = 0; - int pbotflag = 0; - int c; - int v0, v1, v2; - size_t off, n; - time_t t; - struct tm *ptm; - - hdr = (struct code_header *) buf; - memset(hdr, 0, sizeof(struct code_header)); - - while ((c = getopt(argc, argv, "i:o:p:gbv:0124hr:")) != -1) { - switch (c) { - case 'i': - ifn = optarg; - break; - case 'o': - ofn = optarg; - break; - case 'p': - pattern = optarg; - break; - case 'g': - gflag = 1; - break; - case 'b': - pbotflag = 1; - break; - case 'v': /* extension to allow setting version */ - version = optarg; - break; - case '0': - hdr->hw_ver = 0; - break; - case '1': - hdr->hw_ver = 1; - break; - case '2': /* new 54G v2.2 and 54GS v1.1 flags */ - hdr->hw_ver = 1; - hdr->flags[0] |= SUPPORT_4712_CHIP; - hdr->flags[0] |= SUPPORT_INTEL_FLASH; - hdr->flags[0] |= SUPPORT_5325E_SWITCH; - break; - case '4': - /* V4 firmware sets the flags to 0x1f */ - hdr->hw_ver = 0; - hdr->flags[0] = 0x1f; - break; - case 'r': - hdr->hw_ver = (char)(atof(optarg)*10)+0x30; - break; - - case 'h': - default: - usage(); - } - } - - if (optind != argc || optind == 1) { - fprintf(stderr, "illegal arg \"%s\"\n", argv[optind]); - usage(); - } - - if (strlen(pattern) != 4) { - fprintf(stderr, "illegal pattern \"%s\": length != 4\n", pattern); - usage(); - } - - if (ifn && !(in = fopen(ifn, "r"))) { - fprintf(stderr, "can not open \"%s\" for reading\n", ifn); - usage(); - } - - if (ofn && !(out = fopen(ofn, "w"))) { - fprintf(stderr, "can not open \"%s\" for writing\n", ofn); - usage(); - } - - if (time(&t) == (time_t)(-1)) { - fprintf(stderr, "time call failed\n"); - return EXIT_FAILURE; - } - - ptm = localtime(&t); - - if (3 != sscanf(version, "v%d.%d.%d", &v0, &v1, &v2)) { - fprintf(stderr, "bad version string \"%s\"\n", version); - return EXIT_FAILURE; - } - - memcpy(&hdr->magic, pattern, 4); - if (pbotflag) - memcpy(&hdr->res1, pbotpat, 4); - hdr->fwdate[0] = ptm->tm_year % 100; - hdr->fwdate[1] = ptm->tm_mon + 1; - hdr->fwdate[2] = ptm->tm_mday; - hdr->fwvern[0] = v0; - hdr->fwvern[1] = v1; - hdr->fwvern[2] = v2; - memcpy(&hdr->id, CODE_ID, strlen(CODE_ID)); - - off = sizeof(struct code_header); - - fprintf(stderr, "writing firmware v%d.%d.%d on %d/%d/%d (y/m/d)\n", - v0, v1, v2, - hdr->fwdate[0], hdr->fwdate[1], hdr->fwdate[2]); - - - while ((n = fread(buf + off, 1, sizeof(buf)-off, in) + off) > 0) { - off = 0; - if (n < sizeof(buf)) { - if (ferror(in)) { - FREAD_ERROR: - fprintf(stderr, "fread error\n"); - return EXIT_FAILURE; - } - if (gflag) { - gflag = sizeof(buf) - n; - memset(buf + n, 0xff, gflag); - n = sizeof(buf); - } - } - if (!fwrite(buf, n, 1, out)) { - FWRITE_ERROR: - fprintf(stderr, "fwrite error\n"); - return EXIT_FAILURE; - } - } - - if (ferror(in)) { - goto FREAD_ERROR; - } - - if (fflush(out)) { - goto FWRITE_ERROR; - } - - fclose(in); - fclose(out); - - return EXIT_SUCCESS; -} diff --git a/target/tools/lzma-loader/.svn/entries b/target/tools/lzma-loader/.svn/entries deleted file mode 100644 index 2934ab892..000000000 --- a/target/tools/lzma-loader/.svn/entries +++ /dev/null @@ -1,300 +0,0 @@ -10 - -dir -29646 -svn://svn.openwrt.org/openwrt/trunk/target/linux/brcm47xx/image/lzma-loader/src -svn://svn.openwrt.org/openwrt - - - -2010-12-02T21:27:54.805904Z -24217 -hauke - - - - - - - - - - - - - - -3c298f89-4303-0410-b956-a3cf2f4a3e73 - -head.S -file - - - - -2011-11-10T10:12:04.000000Z -566bfb5f462e85d45d1d0c4faca0dadd -2010-06-26T20:41:49.877730Z -21945 -nbd - - - - - - - - - - - - - - - - - - - - - -3585 - -decompress.c -file - - - - -2011-11-10T10:12:04.000000Z -b9ae9d76bf7f1f35ce46b5e496a02aa1 -2010-12-02T21:27:54.805904Z -24217 -hauke - - - - - - - - - - - - - - - - - - - - - -5426 - -LzmaDecode.c -file - - - - -2011-11-10T10:12:04.000000Z -14403972ddbcfadbe017a6aeb3e8fae1 -2010-06-26T20:41:49.877730Z -21945 -nbd - - - - - - - - - - - - - - - - - - - - - -17104 - -decompress.lds.in -file - - - - -2011-11-10T10:12:04.000000Z -c80cc6ad34b26e0af3c1d764218a3a61 -2010-06-26T20:41:49.877730Z -21945 -nbd - - - - - - - - - - - - - - - - - - - - - -186 - -loader.lds.in -file - - - - -2011-11-10T10:12:04.000000Z -f06b23d31242fb56a60b864b741c1266 -2010-06-26T20:41:49.877730Z -21945 -nbd - - - - - - - - - - - - - - - - - - - - - -151 - -LzmaDecode.h -file - - - - -2011-11-10T10:12:04.000000Z -12fcb710de789e54587079c021ae5e33 -2010-06-26T20:41:49.877730Z -21945 -nbd - - - - - - - - - - - - - - - - - - - - - -2465 - -Makefile -file - - - - -2011-11-10T10:12:04.000000Z -61400e27cb7c0099046d83e2146e0053 -2010-06-26T20:41:49.877730Z -21945 -nbd - - - - - - - - - - - - - - - - - - - - - -2325 - -README -file - - - - -2011-11-10T10:12:04.000000Z -b29e81088cc18e92dede243f094c4134 -2010-06-26T20:41:49.877730Z -21945 -nbd - - - - - - - - - - - - - - - - - - - - - -2464 - diff --git a/target/tools/lzma-loader/.svn/text-base/LzmaDecode.c.svn-base b/target/tools/lzma-loader/.svn/text-base/LzmaDecode.c.svn-base deleted file mode 100644 index 951700bdd..000000000 --- a/target/tools/lzma-loader/.svn/text-base/LzmaDecode.c.svn-base +++ /dev/null @@ -1,663 +0,0 @@ -/* - LzmaDecode.c - LZMA Decoder - - LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25) - http://www.7-zip.org/ - - LZMA SDK is licensed under two licenses: - 1) GNU Lesser General Public License (GNU LGPL) - 2) Common Public License (CPL) - It means that you can select one of these two licenses and - follow rules of that license. - - SPECIAL EXCEPTION: - Igor Pavlov, as the author of this code, expressly permits you to - statically or dynamically link your code (or bind by name) to the - interfaces of this file without subjecting your linked code to the - terms of the CPL or GNU LGPL. Any modifications or additions - to this file, however, are subject to the LGPL or CPL terms. -*/ - -#include "LzmaDecode.h" - -#ifndef Byte -#define Byte unsigned char -#endif - -#define kNumTopBits 24 -#define kTopValue ((UInt32)1 << kNumTopBits) - -#define kNumBitModelTotalBits 11 -#define kBitModelTotal (1 << kNumBitModelTotalBits) -#define kNumMoveBits 5 - -typedef struct _CRangeDecoder -{ - Byte *Buffer; - Byte *BufferLim; - UInt32 Range; - UInt32 Code; - #ifdef _LZMA_IN_CB - ILzmaInCallback *InCallback; - int Result; - #endif - int ExtraBytes; -} CRangeDecoder; - -Byte RangeDecoderReadByte(CRangeDecoder *rd) -{ - if (rd->Buffer == rd->BufferLim) - { - #ifdef _LZMA_IN_CB - UInt32 size; - rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size); - rd->BufferLim = rd->Buffer + size; - if (size == 0) - #endif - { - rd->ExtraBytes = 1; - return 0xFF; - } - } - return (*rd->Buffer++); -} - -/* #define ReadByte (*rd->Buffer++) */ -#define ReadByte (RangeDecoderReadByte(rd)) - -void RangeDecoderInit(CRangeDecoder *rd, - #ifdef _LZMA_IN_CB - ILzmaInCallback *inCallback - #else - Byte *stream, UInt32 bufferSize - #endif - ) -{ - int i; - #ifdef _LZMA_IN_CB - rd->InCallback = inCallback; - rd->Buffer = rd->BufferLim = 0; - #else - rd->Buffer = stream; - rd->BufferLim = stream + bufferSize; - #endif - rd->ExtraBytes = 0; - rd->Code = 0; - rd->Range = (0xFFFFFFFF); - for(i = 0; i < 5; i++) - rd->Code = (rd->Code << 8) | ReadByte; -} - -#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code; -#define RC_FLUSH_VAR rd->Range = range; rd->Code = code; -#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; } - -UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits) -{ - RC_INIT_VAR - UInt32 result = 0; - int i; - for (i = numTotalBits; i > 0; i--) - { - /* UInt32 t; */ - range >>= 1; - - result <<= 1; - if (code >= range) - { - code -= range; - result |= 1; - } - /* - t = (code - range) >> 31; - t &= 1; - code -= range & (t - 1); - result = (result + result) | (1 - t); - */ - RC_NORMALIZE - } - RC_FLUSH_VAR - return result; -} - -int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd) -{ - UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob; - if (rd->Code < bound) - { - rd->Range = bound; - *prob += (kBitModelTotal - *prob) >> kNumMoveBits; - if (rd->Range < kTopValue) - { - rd->Code = (rd->Code << 8) | ReadByte; - rd->Range <<= 8; - } - return 0; - } - else - { - rd->Range -= bound; - rd->Code -= bound; - *prob -= (*prob) >> kNumMoveBits; - if (rd->Range < kTopValue) - { - rd->Code = (rd->Code << 8) | ReadByte; - rd->Range <<= 8; - } - return 1; - } -} - -#define RC_GET_BIT2(prob, mi, A0, A1) \ - UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \ - if (code < bound) \ - { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \ - else \ - { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \ - RC_NORMALIZE - -#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;) - -int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd) -{ - int mi = 1; - int i; - #ifdef _LZMA_LOC_OPT - RC_INIT_VAR - #endif - for(i = numLevels; i > 0; i--) - { - #ifdef _LZMA_LOC_OPT - CProb *prob = probs + mi; - RC_GET_BIT(prob, mi) - #else - mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd); - #endif - } - #ifdef _LZMA_LOC_OPT - RC_FLUSH_VAR - #endif - return mi - (1 << numLevels); -} - -int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd) -{ - int mi = 1; - int i; - int symbol = 0; - #ifdef _LZMA_LOC_OPT - RC_INIT_VAR - #endif - for(i = 0; i < numLevels; i++) - { - #ifdef _LZMA_LOC_OPT - CProb *prob = probs + mi; - RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i)) - #else - int bit = RangeDecoderBitDecode(probs + mi, rd); - mi = mi + mi + bit; - symbol |= (bit << i); - #endif - } - #ifdef _LZMA_LOC_OPT - RC_FLUSH_VAR - #endif - return symbol; -} - -Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd) -{ - int symbol = 1; - #ifdef _LZMA_LOC_OPT - RC_INIT_VAR - #endif - do - { - #ifdef _LZMA_LOC_OPT - CProb *prob = probs + symbol; - RC_GET_BIT(prob, symbol) - #else - symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd); - #endif - } - while (symbol < 0x100); - #ifdef _LZMA_LOC_OPT - RC_FLUSH_VAR - #endif - return symbol; -} - -Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte) -{ - int symbol = 1; - #ifdef _LZMA_LOC_OPT - RC_INIT_VAR - #endif - do - { - int bit; - int matchBit = (matchByte >> 7) & 1; - matchByte <<= 1; - #ifdef _LZMA_LOC_OPT - { - CProb *prob = probs + ((1 + matchBit) << 8) + symbol; - RC_GET_BIT2(prob, symbol, bit = 0, bit = 1) - } - #else - bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd); - symbol = (symbol << 1) | bit; - #endif - if (matchBit != bit) - { - while (symbol < 0x100) - { - #ifdef _LZMA_LOC_OPT - CProb *prob = probs + symbol; - RC_GET_BIT(prob, symbol) - #else - symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd); - #endif - } - break; - } - } - while (symbol < 0x100); - #ifdef _LZMA_LOC_OPT - RC_FLUSH_VAR - #endif - return symbol; -} - -#define kNumPosBitsMax 4 -#define kNumPosStatesMax (1 << kNumPosBitsMax) - -#define kLenNumLowBits 3 -#define kLenNumLowSymbols (1 << kLenNumLowBits) -#define kLenNumMidBits 3 -#define kLenNumMidSymbols (1 << kLenNumMidBits) -#define kLenNumHighBits 8 -#define kLenNumHighSymbols (1 << kLenNumHighBits) - -#define LenChoice 0 -#define LenChoice2 (LenChoice + 1) -#define LenLow (LenChoice2 + 1) -#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) -#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) -#define kNumLenProbs (LenHigh + kLenNumHighSymbols) - -int LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState) -{ - if(RangeDecoderBitDecode(p + LenChoice, rd) == 0) - return RangeDecoderBitTreeDecode(p + LenLow + - (posState << kLenNumLowBits), kLenNumLowBits, rd); - if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0) - return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid + - (posState << kLenNumMidBits), kLenNumMidBits, rd); - return kLenNumLowSymbols + kLenNumMidSymbols + - RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd); -} - -#define kNumStates 12 - -#define kStartPosModelIndex 4 -#define kEndPosModelIndex 14 -#define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) - -#define kNumPosSlotBits 6 -#define kNumLenToPosStates 4 - -#define kNumAlignBits 4 -#define kAlignTableSize (1 << kNumAlignBits) - -#define kMatchMinLen 2 - -#define IsMatch 0 -#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) -#define IsRepG0 (IsRep + kNumStates) -#define IsRepG1 (IsRepG0 + kNumStates) -#define IsRepG2 (IsRepG1 + kNumStates) -#define IsRep0Long (IsRepG2 + kNumStates) -#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) -#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) -#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) -#define LenCoder (Align + kAlignTableSize) -#define RepLenCoder (LenCoder + kNumLenProbs) -#define Literal (RepLenCoder + kNumLenProbs) - -#if Literal != LZMA_BASE_SIZE -StopCompilingDueBUG -#endif - -#ifdef _LZMA_OUT_READ - -typedef struct _LzmaVarState -{ - CRangeDecoder RangeDecoder; - Byte *Dictionary; - UInt32 DictionarySize; - UInt32 DictionaryPos; - UInt32 GlobalPos; - UInt32 Reps[4]; - int lc; - int lp; - int pb; - int State; - int PreviousIsMatch; - int RemainLen; -} LzmaVarState; - -int LzmaDecoderInit( - unsigned char *buffer, UInt32 bufferSize, - int lc, int lp, int pb, - unsigned char *dictionary, UInt32 dictionarySize, - #ifdef _LZMA_IN_CB - ILzmaInCallback *inCallback - #else - unsigned char *inStream, UInt32 inSize - #endif - ) -{ - LzmaVarState *vs = (LzmaVarState *)buffer; - CProb *p = (CProb *)(buffer + sizeof(LzmaVarState)); - UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp)); - UInt32 i; - if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState)) - return LZMA_RESULT_NOT_ENOUGH_MEM; - vs->Dictionary = dictionary; - vs->DictionarySize = dictionarySize; - vs->DictionaryPos = 0; - vs->GlobalPos = 0; - vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1; - vs->lc = lc; - vs->lp = lp; - vs->pb = pb; - vs->State = 0; - vs->PreviousIsMatch = 0; - vs->RemainLen = 0; - dictionary[dictionarySize - 1] = 0; - for (i = 0; i < numProbs; i++) - p[i] = kBitModelTotal >> 1; - RangeDecoderInit(&vs->RangeDecoder, - #ifdef _LZMA_IN_CB - inCallback - #else - inStream, inSize - #endif - ); - return LZMA_RESULT_OK; -} - -int LzmaDecode(unsigned char *buffer, - unsigned char *outStream, UInt32 outSize, - UInt32 *outSizeProcessed) -{ - LzmaVarState *vs = (LzmaVarState *)buffer; - CProb *p = (CProb *)(buffer + sizeof(LzmaVarState)); - CRangeDecoder rd = vs->RangeDecoder; - int state = vs->State; - int previousIsMatch = vs->PreviousIsMatch; - Byte previousByte; - UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3]; - UInt32 nowPos = 0; - UInt32 posStateMask = (1 << (vs->pb)) - 1; - UInt32 literalPosMask = (1 << (vs->lp)) - 1; - int lc = vs->lc; - int len = vs->RemainLen; - UInt32 globalPos = vs->GlobalPos; - - Byte *dictionary = vs->Dictionary; - UInt32 dictionarySize = vs->DictionarySize; - UInt32 dictionaryPos = vs->DictionaryPos; - - if (len == -1) - { - *outSizeProcessed = 0; - return LZMA_RESULT_OK; - } - - while(len > 0 && nowPos < outSize) - { - UInt32 pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos]; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - len--; - } - if (dictionaryPos == 0) - previousByte = dictionary[dictionarySize - 1]; - else - previousByte = dictionary[dictionaryPos - 1]; -#else - -int LzmaDecode( - Byte *buffer, UInt32 bufferSize, - int lc, int lp, int pb, - #ifdef _LZMA_IN_CB - ILzmaInCallback *inCallback, - #else - unsigned char *inStream, UInt32 inSize, - #endif - unsigned char *outStream, UInt32 outSize, - UInt32 *outSizeProcessed) -{ - UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp)); - CProb *p = (CProb *)buffer; - CRangeDecoder rd; - UInt32 i; - int state = 0; - int previousIsMatch = 0; - Byte previousByte = 0; - UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; - UInt32 nowPos = 0; - UInt32 posStateMask = (1 << pb) - 1; - UInt32 literalPosMask = (1 << lp) - 1; - int len = 0; - if (bufferSize < numProbs * sizeof(CProb)) - return LZMA_RESULT_NOT_ENOUGH_MEM; - for (i = 0; i < numProbs; i++) - p[i] = kBitModelTotal >> 1; - RangeDecoderInit(&rd, - #ifdef _LZMA_IN_CB - inCallback - #else - inStream, inSize - #endif - ); -#endif - - *outSizeProcessed = 0; - while(nowPos < outSize) - { - int posState = (int)( - (nowPos - #ifdef _LZMA_OUT_READ - + globalPos - #endif - ) - & posStateMask); - #ifdef _LZMA_IN_CB - if (rd.Result != LZMA_RESULT_OK) - return rd.Result; - #endif - if (rd.ExtraBytes != 0) - return LZMA_RESULT_DATA_ERROR; - if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0) - { - CProb *probs = p + Literal + (LZMA_LIT_SIZE * - ((( - (nowPos - #ifdef _LZMA_OUT_READ - + globalPos - #endif - ) - & literalPosMask) << lc) + (previousByte >> (8 - lc)))); - - if (state < 4) state = 0; - else if (state < 10) state -= 3; - else state -= 6; - if (previousIsMatch) - { - Byte matchByte; - #ifdef _LZMA_OUT_READ - UInt32 pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - matchByte = dictionary[pos]; - #else - matchByte = outStream[nowPos - rep0]; - #endif - previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte); - previousIsMatch = 0; - } - else - previousByte = LzmaLiteralDecode(probs, &rd); - outStream[nowPos++] = previousByte; - #ifdef _LZMA_OUT_READ - dictionary[dictionaryPos] = previousByte; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - #endif - } - else - { - previousIsMatch = 1; - if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1) - { - if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0) - { - if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0) - { - #ifdef _LZMA_OUT_READ - UInt32 pos; - #endif - if ( - (nowPos - #ifdef _LZMA_OUT_READ - + globalPos - #endif - ) - == 0) - return LZMA_RESULT_DATA_ERROR; - state = state < 7 ? 9 : 11; - #ifdef _LZMA_OUT_READ - pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - previousByte = dictionary[pos]; - dictionary[dictionaryPos] = previousByte; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - #else - previousByte = outStream[nowPos - rep0]; - #endif - outStream[nowPos++] = previousByte; - continue; - } - } - else - { - UInt32 distance; - if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0) - distance = rep1; - else - { - if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0) - distance = rep2; - else - { - distance = rep3; - rep3 = rep2; - } - rep2 = rep1; - } - rep1 = rep0; - rep0 = distance; - } - len = LzmaLenDecode(p + RepLenCoder, &rd, posState); - state = state < 7 ? 8 : 11; - } - else - { - int posSlot; - rep3 = rep2; - rep2 = rep1; - rep1 = rep0; - state = state < 7 ? 7 : 10; - len = LzmaLenDecode(p + LenCoder, &rd, posState); - posSlot = RangeDecoderBitTreeDecode(p + PosSlot + - ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << - kNumPosSlotBits), kNumPosSlotBits, &rd); - if (posSlot >= kStartPosModelIndex) - { - int numDirectBits = ((posSlot >> 1) - 1); - rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits); - if (posSlot < kEndPosModelIndex) - { - rep0 += RangeDecoderReverseBitTreeDecode( - p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd); - } - else - { - rep0 += RangeDecoderDecodeDirectBits(&rd, - numDirectBits - kNumAlignBits) << kNumAlignBits; - rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd); - } - } - else - rep0 = posSlot; - rep0++; - } - if (rep0 == (UInt32)(0)) - { - /* it's for stream version */ - len = -1; - break; - } - if (rep0 > nowPos - #ifdef _LZMA_OUT_READ - + globalPos - #endif - ) - { - return LZMA_RESULT_DATA_ERROR; - } - len += kMatchMinLen; - do - { - #ifdef _LZMA_OUT_READ - UInt32 pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - previousByte = dictionary[pos]; - dictionary[dictionaryPos] = previousByte; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - #else - previousByte = outStream[nowPos - rep0]; - #endif - outStream[nowPos++] = previousByte; - len--; - } - while(len > 0 && nowPos < outSize); - } - } - - #ifdef _LZMA_OUT_READ - vs->RangeDecoder = rd; - vs->DictionaryPos = dictionaryPos; - vs->GlobalPos = globalPos + nowPos; - vs->Reps[0] = rep0; - vs->Reps[1] = rep1; - vs->Reps[2] = rep2; - vs->Reps[3] = rep3; - vs->State = state; - vs->PreviousIsMatch = previousIsMatch; - vs->RemainLen = len; - #endif - - *outSizeProcessed = nowPos; - return LZMA_RESULT_OK; -} diff --git a/target/tools/lzma-loader/.svn/text-base/LzmaDecode.h.svn-base b/target/tools/lzma-loader/.svn/text-base/LzmaDecode.h.svn-base deleted file mode 100644 index f58944e3c..000000000 --- a/target/tools/lzma-loader/.svn/text-base/LzmaDecode.h.svn-base +++ /dev/null @@ -1,100 +0,0 @@ -/* - LzmaDecode.h - LZMA Decoder interface - - LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25) - http://www.7-zip.org/ - - LZMA SDK is licensed under two licenses: - 1) GNU Lesser General Public License (GNU LGPL) - 2) Common Public License (CPL) - It means that you can select one of these two licenses and - follow rules of that license. - - SPECIAL EXCEPTION: - Igor Pavlov, as the author of this code, expressly permits you to - statically or dynamically link your code (or bind by name) to the - interfaces of this file without subjecting your linked code to the - terms of the CPL or GNU LGPL. Any modifications or additions - to this file, however, are subject to the LGPL or CPL terms. -*/ - -#ifndef __LZMADECODE_H -#define __LZMADECODE_H - -/* #define _LZMA_IN_CB */ -/* Use callback for input data */ - -/* #define _LZMA_OUT_READ */ -/* Use read function for output data */ - -/* #define _LZMA_PROB32 */ -/* It can increase speed on some 32-bit CPUs, - but memory usage will be doubled in that case */ - -/* #define _LZMA_LOC_OPT */ -/* Enable local speed optimizations inside code */ - -#ifndef UInt32 -#ifdef _LZMA_UINT32_IS_ULONG -#define UInt32 unsigned long -#else -#define UInt32 unsigned int -#endif -#endif - -#ifdef _LZMA_PROB32 -#define CProb UInt32 -#else -#define CProb unsigned short -#endif - -#define LZMA_RESULT_OK 0 -#define LZMA_RESULT_DATA_ERROR 1 -#define LZMA_RESULT_NOT_ENOUGH_MEM 2 - -#ifdef _LZMA_IN_CB -typedef struct _ILzmaInCallback -{ - int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize); -} ILzmaInCallback; -#endif - -#define LZMA_BASE_SIZE 1846 -#define LZMA_LIT_SIZE 768 - -/* -bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb) -bufferSize += 100 in case of _LZMA_OUT_READ -by default CProb is unsigned short, -but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int) -*/ - -#ifdef _LZMA_OUT_READ -int LzmaDecoderInit( - unsigned char *buffer, UInt32 bufferSize, - int lc, int lp, int pb, - unsigned char *dictionary, UInt32 dictionarySize, - #ifdef _LZMA_IN_CB - ILzmaInCallback *inCallback - #else - unsigned char *inStream, UInt32 inSize - #endif -); -#endif - -int LzmaDecode( - unsigned char *buffer, - #ifndef _LZMA_OUT_READ - UInt32 bufferSize, - int lc, int lp, int pb, - #ifdef _LZMA_IN_CB - ILzmaInCallback *inCallback, - #else - unsigned char *inStream, UInt32 inSize, - #endif - #endif - unsigned char *outStream, UInt32 outSize, - UInt32 *outSizeProcessed); - -#endif diff --git a/target/tools/lzma-loader/.svn/text-base/Makefile.svn-base b/target/tools/lzma-loader/.svn/text-base/Makefile.svn-base deleted file mode 100644 index 3320e565d..000000000 --- a/target/tools/lzma-loader/.svn/text-base/Makefile.svn-base +++ /dev/null @@ -1,77 +0,0 @@ -# -# Makefile for Broadcom BCM947XX boards -# -# Copyright 2001-2003, Broadcom Corporation -# All Rights Reserved. -# -# THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY -# KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM -# SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE. -# -# Copyright 2004 Manuel Novoa III -# Modified to support bzip'd kernels. -# Of course, it would be better to integrate bunzip capability into CFE. -# -# Copyright 2005 Oleg I. Vdovikin -# Cleaned up, modified for lzma support, removed from kernel -# - -TEXT_START := 0x80001000 -BZ_TEXT_START := 0x80400000 - -OBJCOPY := $(CROSS_COMPILE)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S - -CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \ - -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 -mno-abicalls -fno-pic \ - -ffunction-sections -pipe -mlong-calls -fno-common \ - -mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap -CFLAGS += -DLOADADDR=$(TEXT_START) -D_LZMA_IN_CB - -ASFLAGS = $(CFLAGS) -D__ASSEMBLY__ -DBZ_TEXT_START=$(BZ_TEXT_START) - -SEDFLAGS := s/BZ_TEXT_START/$(BZ_TEXT_START)/;s/TEXT_START/$(TEXT_START)/ - -OBJECTS := head.o data.o - -all: loader.gz loader.elf - -# Don't build dependencies, this may die if $(CC) isn't gcc -dep: - -install: - -loader.gz: loader - gzip -nc9 $< > $@ - -loader.elf: loader.o - cp $< $@ - -loader: loader.o - $(OBJCOPY) $< $@ - -loader.o: loader.lds $(OBJECTS) - $(LD) -static --gc-sections -no-warn-mismatch -T loader.lds -o $@ $(OBJECTS) - -loader.lds: loader.lds.in Makefile - @sed "$(SEDFLAGS)" < $< > $@ - -data.o: data.lds decompress.image - $(LD) -no-warn-mismatch -T data.lds -r -o $@ -b binary decompress.image -b elf32-tradlittlemips - -data.lds: - @echo "SECTIONS { .data : { code_start = .; *(.data) code_stop = .; }}" > $@ - -decompress.image: decompress - $(OBJCOPY) $< $@ - -decompress: decompress.lds decompress.o LzmaDecode.o - $(LD) -static --gc-sections -no-warn-mismatch -T decompress.lds -o $@ decompress.o LzmaDecode.o - -decompress.lds: decompress.lds.in Makefile - @sed "$(SEDFLAGS)" < $< > $@ - -mrproper: clean - -clean: - rm -f loader.gz loader decompress *.lds *.o *.image diff --git a/target/tools/lzma-loader/.svn/text-base/README.svn-base b/target/tools/lzma-loader/.svn/text-base/README.svn-base deleted file mode 100644 index 16649e950..000000000 --- a/target/tools/lzma-loader/.svn/text-base/README.svn-base +++ /dev/null @@ -1,55 +0,0 @@ -/* - * LZMA compressed kernel decompressor for bcm947xx boards - * - * Copyright (C) 2005 by Oleg I. Vdovikin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -The code is intended to decompress kernel, being compressed using lzma utility -build using 7zip LZMA SDK. This utility is located in the LZMA_Alone directory - -decompressor code expects that your .trx file consist of three partitions: - -1) decompressor itself (this is gziped code which pmon/cfe will extract and run -on boot-up instead of real kernel) -2) LZMA compressed kernel (both streamed and regular modes are supported now) -3) Root filesystem - -Please be sure to apply the following patch for use this new trx layout (it will -allow using both new and old trx files for root filesystem lookup code) - ---- linuz/arch/mips/brcm-boards/bcm947xx/setup.c 2005-01-23 19:24:27.503322896 +0300 -+++ linux/arch/mips/brcm-boards/bcm947xx/setup.c 2005-01-23 19:29:05.237100944 +0300 -@@ -221,7 +221,9 @@ - /* Try looking at TRX header for rootfs offset */ - if (le32_to_cpu(trx->magic) == TRX_MAGIC) { - bcm947xx_parts[1].offset = off; -- if (le32_to_cpu(trx->offsets[1]) > off) -+ if (le32_to_cpu(trx->offsets[2]) > off) -+ off = le32_to_cpu(trx->offsets[2]); -+ else if (le32_to_cpu(trx->offsets[1]) > off) - off = le32_to_cpu(trx->offsets[1]); - continue; - } - - -Revision history: - 0.02 Initial release - 0.03 Added Mineharu Takahara patch to pass actual - output size to decoder (stream mode compressed input is not - a requirement anymore) - 0.04 Reordered functions using lds script diff --git a/target/tools/lzma-loader/.svn/text-base/decompress.c.svn-base b/target/tools/lzma-loader/.svn/text-base/decompress.c.svn-base deleted file mode 100644 index 05681b152..000000000 --- a/target/tools/lzma-loader/.svn/text-base/decompress.c.svn-base +++ /dev/null @@ -1,186 +0,0 @@ -/* - * LZMA compressed kernel decompressor for bcm947xx boards - * - * Copyright (C) 2005 by Oleg I. Vdovikin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * Please note, this was code based on the bunzip2 decompressor code - * by Manuel Novoa III (mjn3@codepoet.org), although the only thing left - * is an idea and part of original vendor code - * - * - * 12-Mar-2005 Mineharu Takahara - * pass actual output size to decoder (stream mode - * compressed input is not a requirement anymore) - * - * 24-Apr-2005 Oleg I. Vdovikin - * reordered functions using lds script, removed forward decl - * - */ - -#include "LzmaDecode.h" - -#define BCM4710_FLASH 0x1fc00000 /* Flash */ - -#define KSEG0 0x80000000 -#define KSEG1 0xa0000000 - -#define KSEG1ADDR(a) ((((unsigned)(a)) & 0x1fffffffU) | KSEG1) - -#define Index_Invalidate_I 0x00 -#define Index_Writeback_Inv_D 0x01 - -#define cache_unroll(base,op) \ - __asm__ __volatile__( \ - ".set noreorder;\n" \ - ".set mips3;\n" \ - "cache %1, (%0);\n" \ - ".set mips0;\n" \ - ".set reorder\n" \ - : \ - : "r" (base), \ - "i" (op)); - -static __inline__ void blast_icache(unsigned long size, unsigned long lsize) -{ - unsigned long start = KSEG0; - unsigned long end = (start + size); - - while(start < end) { - cache_unroll(start,Index_Invalidate_I); - start += lsize; - } -} - -static __inline__ void blast_dcache(unsigned long size, unsigned long lsize) -{ - unsigned long start = KSEG0; - unsigned long end = (start + size); - - while(start < end) { - cache_unroll(start,Index_Writeback_Inv_D); - start += lsize; - } -} - -#define TRX_MAGIC 0x30524448 /* "HDR0" */ - -struct trx_header { - unsigned int magic; /* "HDR0" */ - unsigned int len; /* Length of file including header */ - unsigned int crc32; /* 32-bit CRC from flag_version to end of file */ - unsigned int flag_version; /* 0:15 flags, 16:31 version */ - 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[]; - -unsigned int offset; -unsigned char *data; - -/* flash access should be aligned, so wrapper is used */ -/* read byte from the flash, all accesses are 32-bit aligned */ -static int read_byte(void *object, unsigned char **buffer, UInt32 *bufferSize) -{ - static unsigned int val; - - if (((unsigned int)offset % 4) == 0) { - val = *(unsigned int *)data; - data += 4; - } - - *bufferSize = 1; - *buffer = ((unsigned char *)&val) + (offset++ & 3); - - return LZMA_RESULT_OK; -} - -static __inline__ unsigned char get_byte(void) -{ - unsigned char *buffer; - UInt32 fake; - - return read_byte(0, &buffer, &fake), *buffer; -} - -/* should be the first function */ -void entry(unsigned long icache_size, unsigned long icache_lsize, - unsigned long dcache_size, unsigned long dcache_lsize, - unsigned long fw_arg0, unsigned long fw_arg1, - unsigned long fw_arg2, unsigned long fw_arg3) -{ - unsigned int i; /* temp value */ - unsigned int lc; /* literal context bits */ - unsigned int lp; /* literal pos state bits */ - unsigned int pb; /* pos state bits */ - unsigned int osize; /* uncompressed size */ - - ILzmaInCallback callback; - callback.Read = read_byte; - - /* look for trx header, 32-bit data access */ - for (data = ((unsigned char *) KSEG1ADDR(BCM4710_FLASH)); - ((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]; - else - data += ((struct trx_header *)data)->offsets[1]; - - offset = 0; - - /* lzma args */ - i = get_byte(); - lc = i % 9, i = i / 9; - lp = i % 5, pb = i / 5; - - /* skip rest of the LZMA coder property */ - for (i = 0; i < 4; i++) - get_byte(); - - /* read the lower half of uncompressed size in the header */ - osize = ((unsigned int)get_byte()) + - ((unsigned int)get_byte() << 8) + - ((unsigned int)get_byte() << 16) + - ((unsigned int)get_byte() << 24); - - /* skip rest of the header (upper half of uncompressed size) */ - for (i = 0; i < 4; i++) - get_byte(); - - /* decompress kernel */ - if (LzmaDecode(workspace, ~0, lc, lp, pb, &callback, - (unsigned char*)LOADADDR, osize, &i) == LZMA_RESULT_OK) - { - blast_dcache(dcache_size, dcache_lsize); - blast_icache(icache_size, icache_lsize); - - /* Jump to load address */ - ((void (*)(unsigned long, unsigned long, unsigned long, - unsigned long)) LOADADDR)(fw_arg0, fw_arg1, fw_arg2, - fw_arg3); - } -} diff --git a/target/tools/lzma-loader/.svn/text-base/decompress.lds.in.svn-base b/target/tools/lzma-loader/.svn/text-base/decompress.lds.in.svn-base deleted file mode 100644 index 33f56f8a0..000000000 --- a/target/tools/lzma-loader/.svn/text-base/decompress.lds.in.svn-base +++ /dev/null @@ -1,20 +0,0 @@ -OUTPUT_ARCH(mips) -ENTRY(entry) -SECTIONS { - . = BZ_TEXT_START; - .text : { - *(.text.entry) - *(.text) - *(.rodata) - } - - .data : { - *(.data) - } - - .bss : { - *(.bss) - } - - workspace = .; -} diff --git a/target/tools/lzma-loader/.svn/text-base/head.S.svn-base b/target/tools/lzma-loader/.svn/text-base/head.S.svn-base deleted file mode 100644 index 3a33e4016..000000000 --- a/target/tools/lzma-loader/.svn/text-base/head.S.svn-base +++ /dev/null @@ -1,160 +0,0 @@ -/* Copyright 2005 Oleg I. Vdovikin (oleg@cs.msu.su) */ -/* cache manipulation adapted from Broadcom code */ -/* idea taken from original bunzip2 decompressor code */ -/* Copyright 2004 Manuel Novoa III (mjn3@codepoet.org) */ -/* Licensed under the linux kernel's version of the GPL.*/ - -#include -#include - -#define KSEG0 0x80000000 - -#define C0_CONFIG $16 -#define C0_TAGLO $28 -#define C0_TAGHI $29 - -#define CONF1_DA_SHIFT 7 /* D$ associativity */ -#define CONF1_DA_MASK 0x00000380 -#define CONF1_DA_BASE 1 -#define CONF1_DL_SHIFT 10 /* D$ line size */ -#define CONF1_DL_MASK 0x00001c00 -#define CONF1_DL_BASE 2 -#define CONF1_DS_SHIFT 13 /* D$ sets/way */ -#define CONF1_DS_MASK 0x0000e000 -#define CONF1_DS_BASE 64 -#define CONF1_IA_SHIFT 16 /* I$ associativity */ -#define CONF1_IA_MASK 0x00070000 -#define CONF1_IA_BASE 1 -#define CONF1_IL_SHIFT 19 /* I$ line size */ -#define CONF1_IL_MASK 0x00380000 -#define CONF1_IL_BASE 2 -#define CONF1_IS_SHIFT 22 /* Instruction cache sets/way */ -#define CONF1_IS_MASK 0x01c00000 -#define CONF1_IS_BASE 64 - -#define Index_Invalidate_I 0x00 -#define Index_Writeback_Inv_D 0x01 - - .text - LEAF(startup) - .set noreorder - addi sp, -48 - sw a0, 16(sp) - sw a1, 20(sp) - sw a2, 24(sp) - sw a3, 28(sp) - - /* Copy decompressor code to the right place */ - li t2, BZ_TEXT_START - add a0, t2, 0 - la a1, code_start - la a2, code_stop -$L1: - lw t0, 0(a1) - sw t0, 0(a0) - add a1, 4 - add a0, 4 - blt a1, a2, $L1 - nop - - /* At this point we need to invalidate dcache and */ - /* icache before jumping to new code */ - -1: /* Get cache sizes */ - .set mips32 - mfc0 s0,C0_CONFIG,1 - .set mips0 - - li s1,CONF1_DL_MASK - and s1,s0 - beq s1,zero,nodc - nop - - srl s1,CONF1_DL_SHIFT - li t0,CONF1_DL_BASE - sll s1,t0,s1 /* s1 has D$ cache line size */ - - li s2,CONF1_DA_MASK - and s2,s0 - srl s2,CONF1_DA_SHIFT - addiu s2,CONF1_DA_BASE /* s2 now has D$ associativity */ - - li t0,CONF1_DS_MASK - and t0,s0 - srl t0,CONF1_DS_SHIFT - li s3,CONF1_DS_BASE - sll s3,s3,t0 /* s3 has D$ sets per way */ - - multu s2,s3 /* sets/way * associativity */ - mflo t0 /* total cache lines */ - - multu s1,t0 /* D$ linesize * lines */ - mflo s2 /* s2 is now D$ size in bytes */ - - /* Initilize the D$: */ - mtc0 zero,C0_TAGLO - mtc0 zero,C0_TAGHI - - li t0,KSEG0 /* Just an address for the first $ line */ - addu t1,t0,s2 /* + size of cache == end */ - - .set mips3 -1: cache Index_Writeback_Inv_D,0(t0) - .set mips0 - bne t0,t1,1b - addu t0,s1 - -nodc: - /* Now we get to do it all again for the I$ */ - - move s3,zero /* just in case there is no icache */ - move s4,zero - - li t0,CONF1_IL_MASK - and t0,s0 - beq t0,zero,noic - nop - - srl t0,CONF1_IL_SHIFT - li s3,CONF1_IL_BASE - sll s3,t0 /* s3 has I$ cache line size */ - - li t0,CONF1_IA_MASK - and t0,s0 - srl t0,CONF1_IA_SHIFT - addiu s4,t0,CONF1_IA_BASE /* s4 now has I$ associativity */ - - li t0,CONF1_IS_MASK - and t0,s0 - srl t0,CONF1_IS_SHIFT - li s5,CONF1_IS_BASE - sll s5,t0 /* s5 has I$ sets per way */ - - multu s4,s5 /* sets/way * associativity */ - mflo t0 /* s4 is now total cache lines */ - - multu s3,t0 /* I$ linesize * lines */ - mflo s4 /* s4 is cache size in bytes */ - - /* Initilize the I$: */ - mtc0 zero,C0_TAGLO - mtc0 zero,C0_TAGHI - - li t0,KSEG0 /* Just an address for the first $ line */ - addu t1,t0,s4 /* + size of cache == end */ - - .set mips3 -1: cache Index_Invalidate_I,0(t0) - .set mips0 - bne t0,t1,1b - addu t0,s3 - -noic: - move a0,s3 /* icache line size */ - move a1,s4 /* icache size */ - move a2,s1 /* dcache line size */ - jal t2 - move a3,s2 /* dcache size */ - - .set reorder - END(startup) diff --git a/target/tools/lzma-loader/.svn/text-base/loader.lds.in.svn-base b/target/tools/lzma-loader/.svn/text-base/loader.lds.in.svn-base deleted file mode 100644 index 20f2ea98e..000000000 --- a/target/tools/lzma-loader/.svn/text-base/loader.lds.in.svn-base +++ /dev/null @@ -1,17 +0,0 @@ -OUTPUT_ARCH(mips) -ENTRY(startup) -SECTIONS { - . = TEXT_START; - .text : { - *(.text) - *(.rodata) - } - - .data : { - *(.data) - } - - .bss : { - *(.bss) - } -} diff --git a/target/tools/lzma-loader/Makefile b/target/tools/lzma-loader/Makefile deleted file mode 100644 index ad4a531b6..000000000 --- a/target/tools/lzma-loader/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -include $(TOPDIR)/rules.mk - -all: - $(MAKE) -C src CC="$(TARGET_CC)" LD="$(TARGET_CROSS)ld" CROSS_COMPILE="$(TARGET_CROSS)" \ - INCLUDE="-I$(LINUX_DIR)/arch/mips/include" diff --git a/target/tools/lzma-loader/src/LzmaDecode.c b/target/tools/lzma-loader/src/LzmaDecode.c deleted file mode 100644 index 951700bdd..000000000 --- a/target/tools/lzma-loader/src/LzmaDecode.c +++ /dev/null @@ -1,663 +0,0 @@ -/* - LzmaDecode.c - LZMA Decoder - - LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25) - http://www.7-zip.org/ - - LZMA SDK is licensed under two licenses: - 1) GNU Lesser General Public License (GNU LGPL) - 2) Common Public License (CPL) - It means that you can select one of these two licenses and - follow rules of that license. - - SPECIAL EXCEPTION: - Igor Pavlov, as the author of this code, expressly permits you to - statically or dynamically link your code (or bind by name) to the - interfaces of this file without subjecting your linked code to the - terms of the CPL or GNU LGPL. Any modifications or additions - to this file, however, are subject to the LGPL or CPL terms. -*/ - -#include "LzmaDecode.h" - -#ifndef Byte -#define Byte unsigned char -#endif - -#define kNumTopBits 24 -#define kTopValue ((UInt32)1 << kNumTopBits) - -#define kNumBitModelTotalBits 11 -#define kBitModelTotal (1 << kNumBitModelTotalBits) -#define kNumMoveBits 5 - -typedef struct _CRangeDecoder -{ - Byte *Buffer; - Byte *BufferLim; - UInt32 Range; - UInt32 Code; - #ifdef _LZMA_IN_CB - ILzmaInCallback *InCallback; - int Result; - #endif - int ExtraBytes; -} CRangeDecoder; - -Byte RangeDecoderReadByte(CRangeDecoder *rd) -{ - if (rd->Buffer == rd->BufferLim) - { - #ifdef _LZMA_IN_CB - UInt32 size; - rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size); - rd->BufferLim = rd->Buffer + size; - if (size == 0) - #endif - { - rd->ExtraBytes = 1; - return 0xFF; - } - } - return (*rd->Buffer++); -} - -/* #define ReadByte (*rd->Buffer++) */ -#define ReadByte (RangeDecoderReadByte(rd)) - -void RangeDecoderInit(CRangeDecoder *rd, - #ifdef _LZMA_IN_CB - ILzmaInCallback *inCallback - #else - Byte *stream, UInt32 bufferSize - #endif - ) -{ - int i; - #ifdef _LZMA_IN_CB - rd->InCallback = inCallback; - rd->Buffer = rd->BufferLim = 0; - #else - rd->Buffer = stream; - rd->BufferLim = stream + bufferSize; - #endif - rd->ExtraBytes = 0; - rd->Code = 0; - rd->Range = (0xFFFFFFFF); - for(i = 0; i < 5; i++) - rd->Code = (rd->Code << 8) | ReadByte; -} - -#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code; -#define RC_FLUSH_VAR rd->Range = range; rd->Code = code; -#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; } - -UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits) -{ - RC_INIT_VAR - UInt32 result = 0; - int i; - for (i = numTotalBits; i > 0; i--) - { - /* UInt32 t; */ - range >>= 1; - - result <<= 1; - if (code >= range) - { - code -= range; - result |= 1; - } - /* - t = (code - range) >> 31; - t &= 1; - code -= range & (t - 1); - result = (result + result) | (1 - t); - */ - RC_NORMALIZE - } - RC_FLUSH_VAR - return result; -} - -int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd) -{ - UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob; - if (rd->Code < bound) - { - rd->Range = bound; - *prob += (kBitModelTotal - *prob) >> kNumMoveBits; - if (rd->Range < kTopValue) - { - rd->Code = (rd->Code << 8) | ReadByte; - rd->Range <<= 8; - } - return 0; - } - else - { - rd->Range -= bound; - rd->Code -= bound; - *prob -= (*prob) >> kNumMoveBits; - if (rd->Range < kTopValue) - { - rd->Code = (rd->Code << 8) | ReadByte; - rd->Range <<= 8; - } - return 1; - } -} - -#define RC_GET_BIT2(prob, mi, A0, A1) \ - UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \ - if (code < bound) \ - { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \ - else \ - { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \ - RC_NORMALIZE - -#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;) - -int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd) -{ - int mi = 1; - int i; - #ifdef _LZMA_LOC_OPT - RC_INIT_VAR - #endif - for(i = numLevels; i > 0; i--) - { - #ifdef _LZMA_LOC_OPT - CProb *prob = probs + mi; - RC_GET_BIT(prob, mi) - #else - mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd); - #endif - } - #ifdef _LZMA_LOC_OPT - RC_FLUSH_VAR - #endif - return mi - (1 << numLevels); -} - -int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd) -{ - int mi = 1; - int i; - int symbol = 0; - #ifdef _LZMA_LOC_OPT - RC_INIT_VAR - #endif - for(i = 0; i < numLevels; i++) - { - #ifdef _LZMA_LOC_OPT - CProb *prob = probs + mi; - RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i)) - #else - int bit = RangeDecoderBitDecode(probs + mi, rd); - mi = mi + mi + bit; - symbol |= (bit << i); - #endif - } - #ifdef _LZMA_LOC_OPT - RC_FLUSH_VAR - #endif - return symbol; -} - -Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd) -{ - int symbol = 1; - #ifdef _LZMA_LOC_OPT - RC_INIT_VAR - #endif - do - { - #ifdef _LZMA_LOC_OPT - CProb *prob = probs + symbol; - RC_GET_BIT(prob, symbol) - #else - symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd); - #endif - } - while (symbol < 0x100); - #ifdef _LZMA_LOC_OPT - RC_FLUSH_VAR - #endif - return symbol; -} - -Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte) -{ - int symbol = 1; - #ifdef _LZMA_LOC_OPT - RC_INIT_VAR - #endif - do - { - int bit; - int matchBit = (matchByte >> 7) & 1; - matchByte <<= 1; - #ifdef _LZMA_LOC_OPT - { - CProb *prob = probs + ((1 + matchBit) << 8) + symbol; - RC_GET_BIT2(prob, symbol, bit = 0, bit = 1) - } - #else - bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd); - symbol = (symbol << 1) | bit; - #endif - if (matchBit != bit) - { - while (symbol < 0x100) - { - #ifdef _LZMA_LOC_OPT - CProb *prob = probs + symbol; - RC_GET_BIT(prob, symbol) - #else - symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd); - #endif - } - break; - } - } - while (symbol < 0x100); - #ifdef _LZMA_LOC_OPT - RC_FLUSH_VAR - #endif - return symbol; -} - -#define kNumPosBitsMax 4 -#define kNumPosStatesMax (1 << kNumPosBitsMax) - -#define kLenNumLowBits 3 -#define kLenNumLowSymbols (1 << kLenNumLowBits) -#define kLenNumMidBits 3 -#define kLenNumMidSymbols (1 << kLenNumMidBits) -#define kLenNumHighBits 8 -#define kLenNumHighSymbols (1 << kLenNumHighBits) - -#define LenChoice 0 -#define LenChoice2 (LenChoice + 1) -#define LenLow (LenChoice2 + 1) -#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) -#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) -#define kNumLenProbs (LenHigh + kLenNumHighSymbols) - -int LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState) -{ - if(RangeDecoderBitDecode(p + LenChoice, rd) == 0) - return RangeDecoderBitTreeDecode(p + LenLow + - (posState << kLenNumLowBits), kLenNumLowBits, rd); - if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0) - return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid + - (posState << kLenNumMidBits), kLenNumMidBits, rd); - return kLenNumLowSymbols + kLenNumMidSymbols + - RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd); -} - -#define kNumStates 12 - -#define kStartPosModelIndex 4 -#define kEndPosModelIndex 14 -#define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) - -#define kNumPosSlotBits 6 -#define kNumLenToPosStates 4 - -#define kNumAlignBits 4 -#define kAlignTableSize (1 << kNumAlignBits) - -#define kMatchMinLen 2 - -#define IsMatch 0 -#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) -#define IsRepG0 (IsRep + kNumStates) -#define IsRepG1 (IsRepG0 + kNumStates) -#define IsRepG2 (IsRepG1 + kNumStates) -#define IsRep0Long (IsRepG2 + kNumStates) -#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) -#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) -#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) -#define LenCoder (Align + kAlignTableSize) -#define RepLenCoder (LenCoder + kNumLenProbs) -#define Literal (RepLenCoder + kNumLenProbs) - -#if Literal != LZMA_BASE_SIZE -StopCompilingDueBUG -#endif - -#ifdef _LZMA_OUT_READ - -typedef struct _LzmaVarState -{ - CRangeDecoder RangeDecoder; - Byte *Dictionary; - UInt32 DictionarySize; - UInt32 DictionaryPos; - UInt32 GlobalPos; - UInt32 Reps[4]; - int lc; - int lp; - int pb; - int State; - int PreviousIsMatch; - int RemainLen; -} LzmaVarState; - -int LzmaDecoderInit( - unsigned char *buffer, UInt32 bufferSize, - int lc, int lp, int pb, - unsigned char *dictionary, UInt32 dictionarySize, - #ifdef _LZMA_IN_CB - ILzmaInCallback *inCallback - #else - unsigned char *inStream, UInt32 inSize - #endif - ) -{ - LzmaVarState *vs = (LzmaVarState *)buffer; - CProb *p = (CProb *)(buffer + sizeof(LzmaVarState)); - UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp)); - UInt32 i; - if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState)) - return LZMA_RESULT_NOT_ENOUGH_MEM; - vs->Dictionary = dictionary; - vs->DictionarySize = dictionarySize; - vs->DictionaryPos = 0; - vs->GlobalPos = 0; - vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1; - vs->lc = lc; - vs->lp = lp; - vs->pb = pb; - vs->State = 0; - vs->PreviousIsMatch = 0; - vs->RemainLen = 0; - dictionary[dictionarySize - 1] = 0; - for (i = 0; i < numProbs; i++) - p[i] = kBitModelTotal >> 1; - RangeDecoderInit(&vs->RangeDecoder, - #ifdef _LZMA_IN_CB - inCallback - #else - inStream, inSize - #endif - ); - return LZMA_RESULT_OK; -} - -int LzmaDecode(unsigned char *buffer, - unsigned char *outStream, UInt32 outSize, - UInt32 *outSizeProcessed) -{ - LzmaVarState *vs = (LzmaVarState *)buffer; - CProb *p = (CProb *)(buffer + sizeof(LzmaVarState)); - CRangeDecoder rd = vs->RangeDecoder; - int state = vs->State; - int previousIsMatch = vs->PreviousIsMatch; - Byte previousByte; - UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3]; - UInt32 nowPos = 0; - UInt32 posStateMask = (1 << (vs->pb)) - 1; - UInt32 literalPosMask = (1 << (vs->lp)) - 1; - int lc = vs->lc; - int len = vs->RemainLen; - UInt32 globalPos = vs->GlobalPos; - - Byte *dictionary = vs->Dictionary; - UInt32 dictionarySize = vs->DictionarySize; - UInt32 dictionaryPos = vs->DictionaryPos; - - if (len == -1) - { - *outSizeProcessed = 0; - return LZMA_RESULT_OK; - } - - while(len > 0 && nowPos < outSize) - { - UInt32 pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos]; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - len--; - } - if (dictionaryPos == 0) - previousByte = dictionary[dictionarySize - 1]; - else - previousByte = dictionary[dictionaryPos - 1]; -#else - -int LzmaDecode( - Byte *buffer, UInt32 bufferSize, - int lc, int lp, int pb, - #ifdef _LZMA_IN_CB - ILzmaInCallback *inCallback, - #else - unsigned char *inStream, UInt32 inSize, - #endif - unsigned char *outStream, UInt32 outSize, - UInt32 *outSizeProcessed) -{ - UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp)); - CProb *p = (CProb *)buffer; - CRangeDecoder rd; - UInt32 i; - int state = 0; - int previousIsMatch = 0; - Byte previousByte = 0; - UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; - UInt32 nowPos = 0; - UInt32 posStateMask = (1 << pb) - 1; - UInt32 literalPosMask = (1 << lp) - 1; - int len = 0; - if (bufferSize < numProbs * sizeof(CProb)) - return LZMA_RESULT_NOT_ENOUGH_MEM; - for (i = 0; i < numProbs; i++) - p[i] = kBitModelTotal >> 1; - RangeDecoderInit(&rd, - #ifdef _LZMA_IN_CB - inCallback - #else - inStream, inSize - #endif - ); -#endif - - *outSizeProcessed = 0; - while(nowPos < outSize) - { - int posState = (int)( - (nowPos - #ifdef _LZMA_OUT_READ - + globalPos - #endif - ) - & posStateMask); - #ifdef _LZMA_IN_CB - if (rd.Result != LZMA_RESULT_OK) - return rd.Result; - #endif - if (rd.ExtraBytes != 0) - return LZMA_RESULT_DATA_ERROR; - if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0) - { - CProb *probs = p + Literal + (LZMA_LIT_SIZE * - ((( - (nowPos - #ifdef _LZMA_OUT_READ - + globalPos - #endif - ) - & literalPosMask) << lc) + (previousByte >> (8 - lc)))); - - if (state < 4) state = 0; - else if (state < 10) state -= 3; - else state -= 6; - if (previousIsMatch) - { - Byte matchByte; - #ifdef _LZMA_OUT_READ - UInt32 pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - matchByte = dictionary[pos]; - #else - matchByte = outStream[nowPos - rep0]; - #endif - previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte); - previousIsMatch = 0; - } - else - previousByte = LzmaLiteralDecode(probs, &rd); - outStream[nowPos++] = previousByte; - #ifdef _LZMA_OUT_READ - dictionary[dictionaryPos] = previousByte; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - #endif - } - else - { - previousIsMatch = 1; - if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1) - { - if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0) - { - if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0) - { - #ifdef _LZMA_OUT_READ - UInt32 pos; - #endif - if ( - (nowPos - #ifdef _LZMA_OUT_READ - + globalPos - #endif - ) - == 0) - return LZMA_RESULT_DATA_ERROR; - state = state < 7 ? 9 : 11; - #ifdef _LZMA_OUT_READ - pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - previousByte = dictionary[pos]; - dictionary[dictionaryPos] = previousByte; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - #else - previousByte = outStream[nowPos - rep0]; - #endif - outStream[nowPos++] = previousByte; - continue; - } - } - else - { - UInt32 distance; - if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0) - distance = rep1; - else - { - if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0) - distance = rep2; - else - { - distance = rep3; - rep3 = rep2; - } - rep2 = rep1; - } - rep1 = rep0; - rep0 = distance; - } - len = LzmaLenDecode(p + RepLenCoder, &rd, posState); - state = state < 7 ? 8 : 11; - } - else - { - int posSlot; - rep3 = rep2; - rep2 = rep1; - rep1 = rep0; - state = state < 7 ? 7 : 10; - len = LzmaLenDecode(p + LenCoder, &rd, posState); - posSlot = RangeDecoderBitTreeDecode(p + PosSlot + - ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << - kNumPosSlotBits), kNumPosSlotBits, &rd); - if (posSlot >= kStartPosModelIndex) - { - int numDirectBits = ((posSlot >> 1) - 1); - rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits); - if (posSlot < kEndPosModelIndex) - { - rep0 += RangeDecoderReverseBitTreeDecode( - p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd); - } - else - { - rep0 += RangeDecoderDecodeDirectBits(&rd, - numDirectBits - kNumAlignBits) << kNumAlignBits; - rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd); - } - } - else - rep0 = posSlot; - rep0++; - } - if (rep0 == (UInt32)(0)) - { - /* it's for stream version */ - len = -1; - break; - } - if (rep0 > nowPos - #ifdef _LZMA_OUT_READ - + globalPos - #endif - ) - { - return LZMA_RESULT_DATA_ERROR; - } - len += kMatchMinLen; - do - { - #ifdef _LZMA_OUT_READ - UInt32 pos = dictionaryPos - rep0; - if (pos >= dictionarySize) - pos += dictionarySize; - previousByte = dictionary[pos]; - dictionary[dictionaryPos] = previousByte; - if (++dictionaryPos == dictionarySize) - dictionaryPos = 0; - #else - previousByte = outStream[nowPos - rep0]; - #endif - outStream[nowPos++] = previousByte; - len--; - } - while(len > 0 && nowPos < outSize); - } - } - - #ifdef _LZMA_OUT_READ - vs->RangeDecoder = rd; - vs->DictionaryPos = dictionaryPos; - vs->GlobalPos = globalPos + nowPos; - vs->Reps[0] = rep0; - vs->Reps[1] = rep1; - vs->Reps[2] = rep2; - vs->Reps[3] = rep3; - vs->State = state; - vs->PreviousIsMatch = previousIsMatch; - vs->RemainLen = len; - #endif - - *outSizeProcessed = nowPos; - return LZMA_RESULT_OK; -} diff --git a/target/tools/lzma-loader/src/LzmaDecode.h b/target/tools/lzma-loader/src/LzmaDecode.h deleted file mode 100644 index f58944e3c..000000000 --- a/target/tools/lzma-loader/src/LzmaDecode.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - LzmaDecode.h - LZMA Decoder interface - - LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25) - http://www.7-zip.org/ - - LZMA SDK is licensed under two licenses: - 1) GNU Lesser General Public License (GNU LGPL) - 2) Common Public License (CPL) - It means that you can select one of these two licenses and - follow rules of that license. - - SPECIAL EXCEPTION: - Igor Pavlov, as the author of this code, expressly permits you to - statically or dynamically link your code (or bind by name) to the - interfaces of this file without subjecting your linked code to the - terms of the CPL or GNU LGPL. Any modifications or additions - to this file, however, are subject to the LGPL or CPL terms. -*/ - -#ifndef __LZMADECODE_H -#define __LZMADECODE_H - -/* #define _LZMA_IN_CB */ -/* Use callback for input data */ - -/* #define _LZMA_OUT_READ */ -/* Use read function for output data */ - -/* #define _LZMA_PROB32 */ -/* It can increase speed on some 32-bit CPUs, - but memory usage will be doubled in that case */ - -/* #define _LZMA_LOC_OPT */ -/* Enable local speed optimizations inside code */ - -#ifndef UInt32 -#ifdef _LZMA_UINT32_IS_ULONG -#define UInt32 unsigned long -#else -#define UInt32 unsigned int -#endif -#endif - -#ifdef _LZMA_PROB32 -#define CProb UInt32 -#else -#define CProb unsigned short -#endif - -#define LZMA_RESULT_OK 0 -#define LZMA_RESULT_DATA_ERROR 1 -#define LZMA_RESULT_NOT_ENOUGH_MEM 2 - -#ifdef _LZMA_IN_CB -typedef struct _ILzmaInCallback -{ - int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize); -} ILzmaInCallback; -#endif - -#define LZMA_BASE_SIZE 1846 -#define LZMA_LIT_SIZE 768 - -/* -bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb) -bufferSize += 100 in case of _LZMA_OUT_READ -by default CProb is unsigned short, -but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int) -*/ - -#ifdef _LZMA_OUT_READ -int LzmaDecoderInit( - unsigned char *buffer, UInt32 bufferSize, - int lc, int lp, int pb, - unsigned char *dictionary, UInt32 dictionarySize, - #ifdef _LZMA_IN_CB - ILzmaInCallback *inCallback - #else - unsigned char *inStream, UInt32 inSize - #endif -); -#endif - -int LzmaDecode( - unsigned char *buffer, - #ifndef _LZMA_OUT_READ - UInt32 bufferSize, - int lc, int lp, int pb, - #ifdef _LZMA_IN_CB - ILzmaInCallback *inCallback, - #else - unsigned char *inStream, UInt32 inSize, - #endif - #endif - unsigned char *outStream, UInt32 outSize, - UInt32 *outSizeProcessed); - -#endif diff --git a/target/tools/lzma-loader/src/LzmaDecode.o b/target/tools/lzma-loader/src/LzmaDecode.o deleted file mode 100644 index 3d7be3f4d..000000000 Binary files a/target/tools/lzma-loader/src/LzmaDecode.o and /dev/null differ diff --git a/target/tools/lzma-loader/src/Makefile b/target/tools/lzma-loader/src/Makefile deleted file mode 100644 index f5d780c2b..000000000 --- a/target/tools/lzma-loader/src/Makefile +++ /dev/null @@ -1,78 +0,0 @@ -# -# Makefile for Broadcom BCM947XX boards -# -# Copyright 2001-2003, Broadcom Corporation -# All Rights Reserved. -# -# THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY -# KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM -# SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE. -# -# Copyright 2004 Manuel Novoa III -# Modified to support bzip'd kernels. -# Of course, it would be better to integrate bunzip capability into CFE. -# -# Copyright 2005 Oleg I. Vdovikin -# Cleaned up, modified for lzma support, removed from kernel -# - -TEXT_START := 0x80001000 -BZ_TEXT_START := 0x80400000 - -OBJCOPY := $(CROSS_COMPILE)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S - -CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \ - -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 -mno-abicalls -fno-pic \ - -ffunction-sections -pipe -mlong-calls -fno-common \ - -mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap -CFLAGS += -DLOADADDR=$(TEXT_START) -D_LZMA_IN_CB -CFLAGS += $(INCLUDE) - -ASFLAGS = $(CFLAGS) -D__ASSEMBLY__ -DBZ_TEXT_START=$(BZ_TEXT_START) - -SEDFLAGS := s/BZ_TEXT_START/$(BZ_TEXT_START)/;s/TEXT_START/$(TEXT_START)/ - -OBJECTS := head.o data.o - -all: loader.gz loader.elf - -# Don't build dependencies, this may die if $(CC) isn't gcc -dep: - -install: - -loader.gz: loader - gzip -nc9 $< > $@ - -loader.elf: loader.o - cp $< $@ - -loader: loader.o - $(OBJCOPY) $< $@ - -loader.o: loader.lds $(OBJECTS) - $(LD) -static --gc-sections -no-warn-mismatch -T loader.lds -o $@ $(OBJECTS) - -loader.lds: loader.lds.in Makefile - @sed "$(SEDFLAGS)" < $< > $@ - -data.o: data.lds decompress.image - $(LD) -no-warn-mismatch -T data.lds -r -o $@ -b binary decompress.image -b elf32-tradlittlemips - -data.lds: - @echo "SECTIONS { .data : { code_start = .; *(.data) code_stop = .; }}" > $@ - -decompress.image: decompress - $(OBJCOPY) $< $@ - -decompress: decompress.lds decompress.o LzmaDecode.o - $(LD) -static --gc-sections -no-warn-mismatch -T decompress.lds -o $@ decompress.o LzmaDecode.o - -decompress.lds: decompress.lds.in Makefile - @sed "$(SEDFLAGS)" < $< > $@ - -mrproper: clean - -clean: - rm -f loader.gz loader decompress *.lds *.o *.image diff --git a/target/tools/lzma-loader/src/README b/target/tools/lzma-loader/src/README deleted file mode 100644 index 16649e950..000000000 --- a/target/tools/lzma-loader/src/README +++ /dev/null @@ -1,55 +0,0 @@ -/* - * LZMA compressed kernel decompressor for bcm947xx boards - * - * Copyright (C) 2005 by Oleg I. Vdovikin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -The code is intended to decompress kernel, being compressed using lzma utility -build using 7zip LZMA SDK. This utility is located in the LZMA_Alone directory - -decompressor code expects that your .trx file consist of three partitions: - -1) decompressor itself (this is gziped code which pmon/cfe will extract and run -on boot-up instead of real kernel) -2) LZMA compressed kernel (both streamed and regular modes are supported now) -3) Root filesystem - -Please be sure to apply the following patch for use this new trx layout (it will -allow using both new and old trx files for root filesystem lookup code) - ---- linuz/arch/mips/brcm-boards/bcm947xx/setup.c 2005-01-23 19:24:27.503322896 +0300 -+++ linux/arch/mips/brcm-boards/bcm947xx/setup.c 2005-01-23 19:29:05.237100944 +0300 -@@ -221,7 +221,9 @@ - /* Try looking at TRX header for rootfs offset */ - if (le32_to_cpu(trx->magic) == TRX_MAGIC) { - bcm947xx_parts[1].offset = off; -- if (le32_to_cpu(trx->offsets[1]) > off) -+ if (le32_to_cpu(trx->offsets[2]) > off) -+ off = le32_to_cpu(trx->offsets[2]); -+ else if (le32_to_cpu(trx->offsets[1]) > off) - off = le32_to_cpu(trx->offsets[1]); - continue; - } - - -Revision history: - 0.02 Initial release - 0.03 Added Mineharu Takahara patch to pass actual - output size to decoder (stream mode compressed input is not - a requirement anymore) - 0.04 Reordered functions using lds script diff --git a/target/tools/lzma-loader/src/data.lds b/target/tools/lzma-loader/src/data.lds deleted file mode 100644 index ec48b2dfd..000000000 --- a/target/tools/lzma-loader/src/data.lds +++ /dev/null @@ -1 +0,0 @@ -SECTIONS { .data : { code_start = .; *(.data) code_stop = .; }} diff --git a/target/tools/lzma-loader/src/data.o b/target/tools/lzma-loader/src/data.o deleted file mode 100644 index 3c398909f..000000000 Binary files a/target/tools/lzma-loader/src/data.o and /dev/null differ diff --git a/target/tools/lzma-loader/src/decompress b/target/tools/lzma-loader/src/decompress deleted file mode 100755 index 9b2091e78..000000000 Binary files a/target/tools/lzma-loader/src/decompress and /dev/null differ diff --git a/target/tools/lzma-loader/src/decompress.c b/target/tools/lzma-loader/src/decompress.c deleted file mode 100644 index 05681b152..000000000 --- a/target/tools/lzma-loader/src/decompress.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * LZMA compressed kernel decompressor for bcm947xx boards - * - * Copyright (C) 2005 by Oleg I. Vdovikin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * Please note, this was code based on the bunzip2 decompressor code - * by Manuel Novoa III (mjn3@codepoet.org), although the only thing left - * is an idea and part of original vendor code - * - * - * 12-Mar-2005 Mineharu Takahara - * pass actual output size to decoder (stream mode - * compressed input is not a requirement anymore) - * - * 24-Apr-2005 Oleg I. Vdovikin - * reordered functions using lds script, removed forward decl - * - */ - -#include "LzmaDecode.h" - -#define BCM4710_FLASH 0x1fc00000 /* Flash */ - -#define KSEG0 0x80000000 -#define KSEG1 0xa0000000 - -#define KSEG1ADDR(a) ((((unsigned)(a)) & 0x1fffffffU) | KSEG1) - -#define Index_Invalidate_I 0x00 -#define Index_Writeback_Inv_D 0x01 - -#define cache_unroll(base,op) \ - __asm__ __volatile__( \ - ".set noreorder;\n" \ - ".set mips3;\n" \ - "cache %1, (%0);\n" \ - ".set mips0;\n" \ - ".set reorder\n" \ - : \ - : "r" (base), \ - "i" (op)); - -static __inline__ void blast_icache(unsigned long size, unsigned long lsize) -{ - unsigned long start = KSEG0; - unsigned long end = (start + size); - - while(start < end) { - cache_unroll(start,Index_Invalidate_I); - start += lsize; - } -} - -static __inline__ void blast_dcache(unsigned long size, unsigned long lsize) -{ - unsigned long start = KSEG0; - unsigned long end = (start + size); - - while(start < end) { - cache_unroll(start,Index_Writeback_Inv_D); - start += lsize; - } -} - -#define TRX_MAGIC 0x30524448 /* "HDR0" */ - -struct trx_header { - unsigned int magic; /* "HDR0" */ - unsigned int len; /* Length of file including header */ - unsigned int crc32; /* 32-bit CRC from flag_version to end of file */ - unsigned int flag_version; /* 0:15 flags, 16:31 version */ - 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[]; - -unsigned int offset; -unsigned char *data; - -/* flash access should be aligned, so wrapper is used */ -/* read byte from the flash, all accesses are 32-bit aligned */ -static int read_byte(void *object, unsigned char **buffer, UInt32 *bufferSize) -{ - static unsigned int val; - - if (((unsigned int)offset % 4) == 0) { - val = *(unsigned int *)data; - data += 4; - } - - *bufferSize = 1; - *buffer = ((unsigned char *)&val) + (offset++ & 3); - - return LZMA_RESULT_OK; -} - -static __inline__ unsigned char get_byte(void) -{ - unsigned char *buffer; - UInt32 fake; - - return read_byte(0, &buffer, &fake), *buffer; -} - -/* should be the first function */ -void entry(unsigned long icache_size, unsigned long icache_lsize, - unsigned long dcache_size, unsigned long dcache_lsize, - unsigned long fw_arg0, unsigned long fw_arg1, - unsigned long fw_arg2, unsigned long fw_arg3) -{ - unsigned int i; /* temp value */ - unsigned int lc; /* literal context bits */ - unsigned int lp; /* literal pos state bits */ - unsigned int pb; /* pos state bits */ - unsigned int osize; /* uncompressed size */ - - ILzmaInCallback callback; - callback.Read = read_byte; - - /* look for trx header, 32-bit data access */ - for (data = ((unsigned char *) KSEG1ADDR(BCM4710_FLASH)); - ((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]; - else - data += ((struct trx_header *)data)->offsets[1]; - - offset = 0; - - /* lzma args */ - i = get_byte(); - lc = i % 9, i = i / 9; - lp = i % 5, pb = i / 5; - - /* skip rest of the LZMA coder property */ - for (i = 0; i < 4; i++) - get_byte(); - - /* read the lower half of uncompressed size in the header */ - osize = ((unsigned int)get_byte()) + - ((unsigned int)get_byte() << 8) + - ((unsigned int)get_byte() << 16) + - ((unsigned int)get_byte() << 24); - - /* skip rest of the header (upper half of uncompressed size) */ - for (i = 0; i < 4; i++) - get_byte(); - - /* decompress kernel */ - if (LzmaDecode(workspace, ~0, lc, lp, pb, &callback, - (unsigned char*)LOADADDR, osize, &i) == LZMA_RESULT_OK) - { - blast_dcache(dcache_size, dcache_lsize); - blast_icache(icache_size, icache_lsize); - - /* Jump to load address */ - ((void (*)(unsigned long, unsigned long, unsigned long, - unsigned long)) LOADADDR)(fw_arg0, fw_arg1, fw_arg2, - fw_arg3); - } -} diff --git a/target/tools/lzma-loader/src/decompress.image b/target/tools/lzma-loader/src/decompress.image deleted file mode 100755 index b0cb1af95..000000000 Binary files a/target/tools/lzma-loader/src/decompress.image and /dev/null differ diff --git a/target/tools/lzma-loader/src/decompress.lds b/target/tools/lzma-loader/src/decompress.lds deleted file mode 100644 index 7da944d0c..000000000 --- a/target/tools/lzma-loader/src/decompress.lds +++ /dev/null @@ -1,20 +0,0 @@ -OUTPUT_ARCH(mips) -ENTRY(entry) -SECTIONS { - . = 0x80400000; - .text : { - *(.text.entry) - *(.text) - *(.rodata) - } - - .data : { - *(.data) - } - - .bss : { - *(.bss) - } - - workspace = .; -} diff --git a/target/tools/lzma-loader/src/decompress.lds.in b/target/tools/lzma-loader/src/decompress.lds.in deleted file mode 100644 index 33f56f8a0..000000000 --- a/target/tools/lzma-loader/src/decompress.lds.in +++ /dev/null @@ -1,20 +0,0 @@ -OUTPUT_ARCH(mips) -ENTRY(entry) -SECTIONS { - . = BZ_TEXT_START; - .text : { - *(.text.entry) - *(.text) - *(.rodata) - } - - .data : { - *(.data) - } - - .bss : { - *(.bss) - } - - workspace = .; -} diff --git a/target/tools/lzma-loader/src/decompress.o b/target/tools/lzma-loader/src/decompress.o deleted file mode 100644 index 483bc0b32..000000000 Binary files a/target/tools/lzma-loader/src/decompress.o and /dev/null differ diff --git a/target/tools/lzma-loader/src/head.S b/target/tools/lzma-loader/src/head.S deleted file mode 100644 index 3a33e4016..000000000 --- a/target/tools/lzma-loader/src/head.S +++ /dev/null @@ -1,160 +0,0 @@ -/* Copyright 2005 Oleg I. Vdovikin (oleg@cs.msu.su) */ -/* cache manipulation adapted from Broadcom code */ -/* idea taken from original bunzip2 decompressor code */ -/* Copyright 2004 Manuel Novoa III (mjn3@codepoet.org) */ -/* Licensed under the linux kernel's version of the GPL.*/ - -#include -#include - -#define KSEG0 0x80000000 - -#define C0_CONFIG $16 -#define C0_TAGLO $28 -#define C0_TAGHI $29 - -#define CONF1_DA_SHIFT 7 /* D$ associativity */ -#define CONF1_DA_MASK 0x00000380 -#define CONF1_DA_BASE 1 -#define CONF1_DL_SHIFT 10 /* D$ line size */ -#define CONF1_DL_MASK 0x00001c00 -#define CONF1_DL_BASE 2 -#define CONF1_DS_SHIFT 13 /* D$ sets/way */ -#define CONF1_DS_MASK 0x0000e000 -#define CONF1_DS_BASE 64 -#define CONF1_IA_SHIFT 16 /* I$ associativity */ -#define CONF1_IA_MASK 0x00070000 -#define CONF1_IA_BASE 1 -#define CONF1_IL_SHIFT 19 /* I$ line size */ -#define CONF1_IL_MASK 0x00380000 -#define CONF1_IL_BASE 2 -#define CONF1_IS_SHIFT 22 /* Instruction cache sets/way */ -#define CONF1_IS_MASK 0x01c00000 -#define CONF1_IS_BASE 64 - -#define Index_Invalidate_I 0x00 -#define Index_Writeback_Inv_D 0x01 - - .text - LEAF(startup) - .set noreorder - addi sp, -48 - sw a0, 16(sp) - sw a1, 20(sp) - sw a2, 24(sp) - sw a3, 28(sp) - - /* Copy decompressor code to the right place */ - li t2, BZ_TEXT_START - add a0, t2, 0 - la a1, code_start - la a2, code_stop -$L1: - lw t0, 0(a1) - sw t0, 0(a0) - add a1, 4 - add a0, 4 - blt a1, a2, $L1 - nop - - /* At this point we need to invalidate dcache and */ - /* icache before jumping to new code */ - -1: /* Get cache sizes */ - .set mips32 - mfc0 s0,C0_CONFIG,1 - .set mips0 - - li s1,CONF1_DL_MASK - and s1,s0 - beq s1,zero,nodc - nop - - srl s1,CONF1_DL_SHIFT - li t0,CONF1_DL_BASE - sll s1,t0,s1 /* s1 has D$ cache line size */ - - li s2,CONF1_DA_MASK - and s2,s0 - srl s2,CONF1_DA_SHIFT - addiu s2,CONF1_DA_BASE /* s2 now has D$ associativity */ - - li t0,CONF1_DS_MASK - and t0,s0 - srl t0,CONF1_DS_SHIFT - li s3,CONF1_DS_BASE - sll s3,s3,t0 /* s3 has D$ sets per way */ - - multu s2,s3 /* sets/way * associativity */ - mflo t0 /* total cache lines */ - - multu s1,t0 /* D$ linesize * lines */ - mflo s2 /* s2 is now D$ size in bytes */ - - /* Initilize the D$: */ - mtc0 zero,C0_TAGLO - mtc0 zero,C0_TAGHI - - li t0,KSEG0 /* Just an address for the first $ line */ - addu t1,t0,s2 /* + size of cache == end */ - - .set mips3 -1: cache Index_Writeback_Inv_D,0(t0) - .set mips0 - bne t0,t1,1b - addu t0,s1 - -nodc: - /* Now we get to do it all again for the I$ */ - - move s3,zero /* just in case there is no icache */ - move s4,zero - - li t0,CONF1_IL_MASK - and t0,s0 - beq t0,zero,noic - nop - - srl t0,CONF1_IL_SHIFT - li s3,CONF1_IL_BASE - sll s3,t0 /* s3 has I$ cache line size */ - - li t0,CONF1_IA_MASK - and t0,s0 - srl t0,CONF1_IA_SHIFT - addiu s4,t0,CONF1_IA_BASE /* s4 now has I$ associativity */ - - li t0,CONF1_IS_MASK - and t0,s0 - srl t0,CONF1_IS_SHIFT - li s5,CONF1_IS_BASE - sll s5,t0 /* s5 has I$ sets per way */ - - multu s4,s5 /* sets/way * associativity */ - mflo t0 /* s4 is now total cache lines */ - - multu s3,t0 /* I$ linesize * lines */ - mflo s4 /* s4 is cache size in bytes */ - - /* Initilize the I$: */ - mtc0 zero,C0_TAGLO - mtc0 zero,C0_TAGHI - - li t0,KSEG0 /* Just an address for the first $ line */ - addu t1,t0,s4 /* + size of cache == end */ - - .set mips3 -1: cache Index_Invalidate_I,0(t0) - .set mips0 - bne t0,t1,1b - addu t0,s3 - -noic: - move a0,s3 /* icache line size */ - move a1,s4 /* icache size */ - move a2,s1 /* dcache line size */ - jal t2 - move a3,s2 /* dcache size */ - - .set reorder - END(startup) diff --git a/target/tools/lzma-loader/src/head.o b/target/tools/lzma-loader/src/head.o deleted file mode 100644 index 04763fa4b..000000000 Binary files a/target/tools/lzma-loader/src/head.o and /dev/null differ diff --git a/target/tools/lzma-loader/src/loader b/target/tools/lzma-loader/src/loader deleted file mode 100755 index 871117b87..000000000 Binary files a/target/tools/lzma-loader/src/loader and /dev/null differ diff --git a/target/tools/lzma-loader/src/loader.elf b/target/tools/lzma-loader/src/loader.elf deleted file mode 100755 index 0633a0e77..000000000 Binary files a/target/tools/lzma-loader/src/loader.elf and /dev/null differ diff --git a/target/tools/lzma-loader/src/loader.gz b/target/tools/lzma-loader/src/loader.gz deleted file mode 100644 index 426c9295e..000000000 Binary files a/target/tools/lzma-loader/src/loader.gz and /dev/null differ diff --git a/target/tools/lzma-loader/src/loader.lds b/target/tools/lzma-loader/src/loader.lds deleted file mode 100644 index 9d95adbfa..000000000 --- a/target/tools/lzma-loader/src/loader.lds +++ /dev/null @@ -1,17 +0,0 @@ -OUTPUT_ARCH(mips) -ENTRY(startup) -SECTIONS { - . = 0x80001000; - .text : { - *(.text) - *(.rodata) - } - - .data : { - *(.data) - } - - .bss : { - *(.bss) - } -} diff --git a/target/tools/lzma-loader/src/loader.lds.in b/target/tools/lzma-loader/src/loader.lds.in deleted file mode 100644 index 20f2ea98e..000000000 --- a/target/tools/lzma-loader/src/loader.lds.in +++ /dev/null @@ -1,17 +0,0 @@ -OUTPUT_ARCH(mips) -ENTRY(startup) -SECTIONS { - . = TEXT_START; - .text : { - *(.text) - *(.rodata) - } - - .data : { - *(.data) - } - - .bss : { - *(.bss) - } -} diff --git a/target/tools/lzma-loader/src/loader.o b/target/tools/lzma-loader/src/loader.o deleted file mode 100755 index 0633a0e77..000000000 Binary files a/target/tools/lzma-loader/src/loader.o and /dev/null differ diff --git a/target/tools/lzma/Makefile b/target/tools/lzma/Makefile deleted file mode 100644 index 23cbc7f73..000000000 --- a/target/tools/lzma/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -# This file is part of the OpenADK project. OpenADK is copyrighted -# material, please see the LICENCE file in the top-level directory. - -include $(TOPDIR)/rules.mk - -PKG_NAME:= lzma -PKG_VERSION:= 4.65 -PKG_RELEASE:= 1 -PKG_MD5SUM:= 434e51a018b4c8ef377bf81520a53af0 -PKG_SITES:= http://downloads.openwrt.org/sources/ - -DISTFILES:= ${PKG_NAME}-${PKG_VERSION}.tar.bz2 -#WRKDIST= ${WRKDIR}/$(PKG_NAME)${PKG_VERSION} - -include ../rules.mk - -all: ${STAGING_HOST_DIR}/bin/lzma - -UTIL_DIR=$(WRKBUILD)/C/LzmaUtil -ALONE_DIR=$(WRKBUILD)/CPP/7zip/Compress/LZMA_Alone - -$(WRKBUILD)/.compiled: ${WRKDIST}/.prepared - $(MAKE) -C $(UTIL_DIR) -f makefile.gcc - $(MAKE) -C $(ALONE_DIR) -f makefile.gcc - touch $@ - -${STAGING_HOST_DIR}/bin/lzma: $(WRKBUILD)/.compiled - $(INSTALL_BIN) $(WRKBUILD)/CPP/7zip/Compress/LZMA_Alone/lzma_alone \ - $(STAGING_DIR)/bin/lzma - -include $(TOPDIR)/mk/tools.mk diff --git a/target/tools/lzma/patches/001-large_files.patch b/target/tools/lzma/patches/001-large_files.patch deleted file mode 100644 index b95fe9e90..000000000 --- a/target/tools/lzma/patches/001-large_files.patch +++ /dev/null @@ -1,13 +0,0 @@ -Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile.gcc -=================================================================== ---- lzma-4.65.orig/CPP/7zip/Compress/LZMA_Alone/makefile.gcc 2009-05-15 23:33:51.000000000 +0200 -+++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile.gcc 2009-06-01 22:00:54.000000000 +0200 -@@ -3,7 +3,7 @@ - CXX_C = gcc -O2 -Wall - LIB = -lm - RM = rm -f --CFLAGS = -c -+CFLAGS = -c -D_FILE_OFFSET_BITS=64 - - ifdef SystemDrive - IS_MINGW = 1 diff --git a/target/tools/lzma/patches/002-lzmp.patch b/target/tools/lzma/patches/002-lzmp.patch deleted file mode 100644 index 72d881cdb..000000000 --- a/target/tools/lzma/patches/002-lzmp.patch +++ /dev/null @@ -1,1059 +0,0 @@ -Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzmp.cpp -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzmp.cpp 2009-06-01 22:01:10.000000000 +0200 -@@ -0,0 +1,895 @@ -+/* -+ * LZMA command line tool similar to gzip to encode and decode LZMA files. -+ * -+ * Copyright (C) 2005 Ville Koskinen -+ * -+ * This program is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU General Public License -+ * as published by the Free Software Foundation; either version 2 -+ * of the License, or (at your option) any later version. -+ * -+ * This program is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with this program; if not, write to the Free Software -+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -+ * USA. -+ */ -+ -+#include "../../../Common/MyInitGuid.h" -+ -+#include -+using std::cout; -+using std::cerr; -+using std::endl; -+ -+#include -+#include -+#include -+ -+#include -+using std::string; -+#include -+using std::vector; -+typedef vector stringVector; -+ -+#include -+#include -+#include -+ -+#include -+#include -+#include -+#include // futimes() -+ -+// For Solaris -+#ifndef HAVE_FUTIMES -+//#define futimes(fd, tv) futimesat(fd, NULL, tv) -+#endif -+ -+#if defined(_WIN32) || defined(OS2) || defined(MSDOS) -+#include -+#include -+#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY) -+#else -+#define MY_SET_BINARY_MODE(file) -+#endif -+ -+#include "../../../7zip/Common/FileStreams.h" -+ -+#include "../../../Common/Types.h" -+ -+#include "../../../7zip/Compress/LzmaDecoder.h" -+#include "../../../7zip/Compress/LzmaEncoder.h" -+ -+#include "Exception.h" -+ -+#include "lzma_version.h" -+ -+namespace lzma { -+ -+const char *PROGRAM_VERSION = PACKAGE_VERSION; -+const char *PROGRAM_COPYRIGHT = "Copyright (C) 2006 Ville Koskinen"; -+ -+/* LZMA_Alone switches: -+ -a{N}: set compression mode - [0, 2], default: 2 (max) -+ -d{N}: set dictionary - [0,28], default: 23 (8MB) -+ -fb{N}: set number of fast bytes - [5, 255], default: 128 -+ -lc{N}: set number of literal context bits - [0, 8], default: 3 -+ -lp{N}: set number of literal pos bits - [0, 4], default: 0 -+ -pb{N}: set number of pos bits - [0, 4], default: 2 -+ -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, bt4b, pat2r, pat2, -+ pat2h, pat3h, pat4h, hc3, hc4], default: bt4 -+*/ -+ -+struct lzma_option { -+ short compression_mode; // -a -+ short dictionary; // -d -+ short fast_bytes; // -fb -+ wchar_t *match_finder; // -mf -+ short literal_context_bits; // -lc -+ short literal_pos_bits; // -lp -+ short pos_bits; // -pb -+}; -+ -+/* The following is a mapping from gzip/bzip2 style -1 .. -9 compression modes -+ * to the corresponding LZMA compression modes. Thanks, Larhzu, for coining -+ * these. */ -+const lzma_option option_mapping[] = { -+ { 0, 0, 0, NULL, 0, 0, 0}, // -0 (needed for indexing) -+ { 0, 16, 64, L"hc4", 3, 0, 2}, // -1 -+ { 0, 20, 64, L"hc4", 3, 0, 2}, // -2 -+ { 1, 19, 64, L"bt4", 3, 0, 2}, // -3 -+ { 2, 20, 64, L"bt4", 3, 0, 2}, // -4 -+ { 2, 21, 128, L"bt4", 3, 0, 2}, // -5 -+ { 2, 22, 128, L"bt4", 3, 0, 2}, // -6 -+ { 2, 23, 128, L"bt4", 3, 0, 2}, // -7 -+ { 2, 24, 255, L"bt4", 3, 0, 2}, // -8 -+ { 2, 25, 255, L"bt4", 3, 0, 2}, // -9 -+}; -+ -+struct extension_pair { -+ char *from; -+ char *to; -+}; -+ -+const extension_pair known_extensions[] = { -+ { ".lzma", "" }, -+ { ".tlz", ".tar" }, -+ { NULL, NULL } -+}; -+ -+/* Sorry, I just happen to like enumerations. */ -+enum PROGRAM_MODE { -+ PM_COMPRESS = 0, -+ PM_DECOMPRESS, -+ PM_TEST, -+ PM_HELP, -+ PM_LICENSE, -+ PM_VERSION -+}; -+ -+enum { -+ STATUS_OK = 0, -+ STATUS_ERROR = 1, -+ STATUS_WARNING = 2 -+}; -+ -+/* getopt options. */ -+/* struct option { name, has_arg, flag, val } */ -+const struct option long_options[] = { -+ { "stdout", 0, 0, 'c' }, -+ { "decompress", 0, 0, 'd' }, -+ { "compress", 0, 0, 'z' }, -+ { "keep", 0, 0, 'k' }, -+ { "force", 0, 0, 'f' }, -+ { "test", 0, 0, 't' }, -+ { "suffix", 1, 0, 'S' }, -+ { "quiet", 0, 0, 'q' }, -+ { "verbose", 0, 0, 'v' }, -+ { "help", 0, 0, 'h' }, -+ { "license", 0, 0, 'L' }, -+ { "version", 0, 0, 'V' }, -+ { "fast", 0, 0, '1' }, -+ { "best", 0, 0, '9' }, -+ { 0, 0, 0, 0 } -+}; -+ -+/* getopt option string (for the above options). */ -+const char option_string[] = "cdzkftS:qvhLV123456789A:D:F:"; -+ -+/* Defaults. */ -+PROGRAM_MODE program_mode = PM_COMPRESS; -+int verbosity = 0; -+bool stdinput = false; -+bool stdoutput = false; -+bool keep = false; -+bool force = false; -+int compression_mode = 7; -+//char *suffix = strdup(".lzma"); -+char *suffix = strdup(known_extensions[0].from); -+lzma_option advanced_options = { -1, -1, -1, NULL, -1, -1, -1 }; -+ -+void print_help(const char *const argv0) -+{ -+ // Help goes to stdout while other messages go to stderr. -+ cout << "\nlzma " << PROGRAM_VERSION -+ << " " << PROGRAM_COPYRIGHT << "\n" -+ "Based on LZMA SDK " << LZMA_SDK_VERSION_STRING << " " -+ << LZMA_SDK_COPYRIGHT_STRING -+ << "\n\nUsage: " << argv0 -+ << " [flags and input files in any order]\n" -+" -c --stdout output to standard output\n" -+" -d --decompress force decompression\n" -+" -z --compress force compression\n" -+" -k --keep keep (don't delete) input files\n" -+" -f --force force overwrite of output file and compress links\n" -+" -t --test test compressed file integrity\n" -+" -S .suf --suffix .suf use suffix .suf on compressed files\n" -+" -q --quiet suppress error messages\n" -+" -v --verbose be verbose\n" -+" -h --help print this message\n" -+" -L --license display the license information\n" -+" -V --version display version numbers of LZMA SDK and lzma\n" -+" -1 .. -2 fast compression\n" -+" -3 .. -9 good to excellent compression. -7 is the default.\n" -+" --fast alias for -1\n" -+" --best alias for -9 (usually *not* what you want)\n\n" -+" Memory usage depends a lot on the chosen compression mode -1 .. -9.\n" -+" See the man page lzma(1) for details.\n\n"; -+} -+ -+void print_license(void) -+{ -+ cout << "\n LZMA command line tool " << PROGRAM_VERSION << " - " -+ << PROGRAM_COPYRIGHT -+ << "\n LZMA SDK " << LZMA_SDK_VERSION_STRING << " - " -+ << LZMA_SDK_COPYRIGHT_STRING -+ << "\n This program is a part of the LZMA utils package.\n" -+ " http://tukaani.org/lzma/\n\n" -+" This program is free software; you can redistribute it and/or\n" -+" modify it under the terms of the GNU General Public License\n" -+" as published by the Free Software Foundation; either version 2\n" -+" of the License, or (at your option) any later version.\n" -+"\n" -+" This program is distributed in the hope that it will be useful,\n" -+" but WITHOUT ANY WARRANTY; without even the implied warranty of\n" -+" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" -+" GNU General Public License for more details.\n" -+"\n"; -+} -+ -+void print_version(void) -+{ -+ cout << "LZMA command line tool " << PROGRAM_VERSION << "\n" -+ << "LZMA SDK " << LZMA_SDK_VERSION_STRING << "\n"; -+} -+ -+short str2int (const char *str, const int &min, const int &max) -+{ -+ int value = -1; -+ char *endptr = NULL; -+ if (str == NULL || str[0] == '\0') -+ throw ArgumentException("Invalid integer option"); -+ value = strtol (str, &endptr, 10); -+ if (*endptr != '\0' || value < min || value > max) -+ throw ArgumentException("Invalid integer option"); -+ return value; -+} -+ -+void parse_options(int argc, char **argv, stringVector &filenames) -+{ -+ /* Snatched from getopt(3). */ -+ int c; -+ -+ /* Check how we were called */ -+ { -+ char *p = strrchr (argv[0], '/'); // Remove path prefix, if any -+ if (p++ == NULL) -+ p = argv[0]; -+ if (strstr (p, "un") != NULL) { -+ program_mode = PM_DECOMPRESS; -+ } else if (strstr (p, "cat") != NULL) { -+ program_mode = PM_DECOMPRESS; -+ stdoutput = true; -+ } -+ } -+ -+ while (-1 != (c = getopt_long(argc, argv, option_string, -+ long_options, NULL))) { -+ switch (c) { -+ // stdout -+ case 'c': -+ stdoutput = true; -+ break; -+ -+ // decompress -+ case 'd': -+ program_mode = PM_DECOMPRESS; -+ break; -+ -+ // compress -+ case 'z': -+ program_mode = PM_COMPRESS; -+ break; -+ -+ // keep -+ case 'k': -+ keep = true; -+ break; -+ -+ // force -+ case 'f': -+ force = true; -+ break; -+ -+ // test -+ case 't': -+ program_mode = PM_TEST; -+ break; -+ -+ // suffix -+ case 'S': -+ if (optarg) { -+ free(suffix); -+ suffix = strdup(optarg); -+ } -+ break; -+ -+ // quiet -+ case 'q': -+ verbosity = 0; -+ break; -+ -+ // verbose -+ case 'v': -+ verbosity++; -+ break; -+ -+ // help -+ case 'h': -+ program_mode = PM_HELP; -+ break; -+ -+ // license -+ case 'L': -+ program_mode = PM_LICENSE; -+ break; -+ -+ // version -+ case 'V': -+ program_mode = PM_VERSION; -+ break; -+ -+ case '1': case '2': case '3': case '4': case '5': -+ case '6': case '7': case '8': case '9': -+ compression_mode = c - '0'; -+ break; -+ -+ // Advanced options // -+ // Compression mode -+ case 'A': -+ advanced_options.compression_mode = -+ str2int (optarg, 0, 2); -+ break; -+ -+ // Dictionary size -+ case 'D': -+ advanced_options.dictionary = -+ str2int (optarg, 0, 28); -+ break; -+ -+ // Fast bytes -+ case 'F': -+ advanced_options.fast_bytes = -+ str2int (optarg, 0, 273); -+ break; -+ -+ default: -+ throw ArgumentException(""); -+ break; -+ } // switch(c) -+ } // while(1) -+ -+ for (int i = optind; i < argc; i++) { -+ if (strcmp("-", argv[i]) == 0) -+ continue; -+ filenames.push_back(argv[i]); -+ } -+} // parse_options -+ -+void set_encoder_properties(NCompress::NLzma::CEncoder *encoder, -+ lzma_option &opt) -+{ -+ /* Almost verbatim from LzmaAlone.cpp. */ -+ PROPID propIDs[] = -+ { -+ NCoderPropID::kDictionarySize, -+ NCoderPropID::kPosStateBits, -+ NCoderPropID::kLitContextBits, -+ NCoderPropID::kLitPosBits, -+ NCoderPropID::kAlgorithm, -+ NCoderPropID::kNumFastBytes, -+ NCoderPropID::kMatchFinder, -+ NCoderPropID::kEndMarker -+ }; -+ const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]); -+#define VALUE(x) (advanced_options.x >= 0 ? advanced_options.x : opt.x) -+ PROPVARIANT properties[kNumProps]; -+ for (int p = 0; p < 6; p++) -+ properties[p].vt = VT_UI4; -+ properties[0].ulVal = UInt32(1 << VALUE (dictionary)); -+ properties[1].ulVal = UInt32(VALUE (pos_bits)); -+ properties[2].ulVal = UInt32(VALUE (literal_context_bits)); -+ properties[3].ulVal = UInt32(VALUE (literal_pos_bits)); -+ properties[4].ulVal = UInt32(VALUE (compression_mode)); -+ properties[5].ulVal = UInt32(VALUE (fast_bytes)); -+#undef VALUE -+ -+ properties[6].vt = VT_BSTR; -+ properties[6].bstrVal = (BSTR)opt.match_finder; -+ -+ properties[7].vt = VT_BOOL; -+ properties[7].boolVal = stdinput ? VARIANT_TRUE : VARIANT_FALSE; -+ -+ if (encoder->SetCoderProperties(propIDs, properties, kNumProps) != S_OK) -+ throw Exception("SetCoderProperties() error"); -+} -+ -+void encode(NCompress::NLzma::CEncoder *encoderSpec, -+ CMyComPtr inStream, -+ CMyComPtr outStream, -+ lzma_option encoder_options, -+ UInt64 fileSize) -+{ -+ set_encoder_properties(encoderSpec, encoder_options); -+ -+ encoderSpec->WriteCoderProperties(outStream); -+ -+ for (int i = 0; i < 8; i++) -+ { -+ Byte b = Byte(fileSize >> (8 * i)); -+ if (outStream->Write(&b, sizeof(b), 0) != S_OK) -+ throw Exception("Write error while encoding"); -+ } -+ -+ HRESULT result = encoderSpec->Code(inStream, outStream, 0, 0, 0); -+ -+ if (result == E_OUTOFMEMORY) -+ throw Exception("Cannot allocate memory"); -+ else if (result != S_OK) { -+ char buffer[33]; -+ snprintf(buffer, 33, "%d", (unsigned int)result); -+ throw Exception(string("Encoder error: ") + buffer); -+ } -+} -+ -+void decode(NCompress::NLzma::CDecoder *decoderSpec, -+ CMyComPtr inStream, -+ CMyComPtr outStream) -+{ -+ const UInt32 kPropertiesSize = 5; -+ Byte properties[kPropertiesSize]; -+ UInt32 processedSize; -+ UInt64 fileSize = 0; -+ -+ if (inStream->Read(properties, kPropertiesSize, &processedSize) != S_OK) -+ throw Exception("Read error"); -+ if (processedSize != kPropertiesSize) -+ throw Exception("Read error"); -+ if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK) -+ throw Exception("SetDecoderProperties() error"); -+ -+ for (int i = 0; i < 8; i++) -+ { -+ Byte b; -+ -+ if (inStream->Read(&b, sizeof(b), &processedSize) != S_OK) -+ throw Exception("Read error"); -+ if (processedSize != 1) -+ throw Exception("Read error"); -+ -+ fileSize |= ((UInt64)b) << (8 * i); -+ } -+ -+ if (decoderSpec->Code(inStream, outStream, 0, &fileSize, 0) != S_OK) -+ throw Exception("Decoder error"); -+} -+ -+int open_instream(const string infile, -+ CMyComPtr &inStream, -+ UInt64 &fileSize) -+{ -+ CInFileStream *inStreamSpec = new CInFileStream; -+ inStream = inStreamSpec; -+ if (!inStreamSpec->Open(infile.c_str())) -+ throw Exception("Cannot open input file " + infile); -+ -+ inStreamSpec->File.GetLength(fileSize); -+ -+ return inStreamSpec->File.GetHandle(); -+} -+ -+int open_outstream(const string outfile, -+ CMyComPtr &outStream) -+{ -+ COutFileStream *outStreamSpec = new COutFileStream; -+ outStream = outStreamSpec; -+ -+ bool open_by_force = (program_mode == PM_TEST) | force; -+ -+ if (!outStreamSpec->Create(outfile.c_str(), open_by_force)) -+ throw Exception("Cannot open output file " + outfile); -+ -+ return outStreamSpec->File.GetHandle(); -+} -+ -+double get_ratio(int inhandle, int outhandle) -+{ -+ struct stat in_stats, out_stats; -+ fstat(inhandle, &in_stats); -+ fstat(outhandle, &out_stats); -+ -+ return (double)out_stats.st_size / (double)in_stats.st_size; -+} -+ -+mode_t get_file_mode(string filename) -+{ -+ struct stat in_stat; -+ lstat(filename.c_str(), &in_stat); -+ -+ return in_stat.st_mode; -+} -+ -+bool string_ends_with(string str, string ending) -+{ -+ return equal(ending.rbegin(), ending.rend(), str.rbegin()); -+} -+ -+bool extension_is_known(string filename) -+{ -+ bool known_format = false; -+ extension_pair extension; int i = 1; -+ -+ extension = known_extensions[0]; -+ while (extension.from != NULL) { -+ if (string_ends_with(filename, extension.from)) { -+ known_format = true; -+ break; -+ } -+ extension = known_extensions[i]; -+ i++; -+ } -+ -+ if (!known_format) { -+ if (!string_ends_with(filename, suffix)) { -+ return false; -+ } -+ } -+ -+ return true; -+} -+ -+string replace_extension(string filename) -+{ -+ int suffix_starts_at = filename.length() - strlen (suffix); -+ string from_suffix = filename.substr(suffix_starts_at, strlen (suffix)); -+ string ret = filename.substr(0, suffix_starts_at); -+ extension_pair extension; int i = 1; -+ -+ bool found_replacement = false; -+ extension = known_extensions[0]; -+ while (extension.from != NULL) { -+ if (from_suffix.compare(extension.from) == 0) { -+ ret += extension.to; -+ found_replacement = true; -+ break; -+ } -+ -+ extension = known_extensions[i]; -+ i++; -+ } -+ -+ return ret; -+} -+ -+string pretty_print_status(string filename, string output_filename, -+ string ratio) -+{ -+ string ret = ""; -+ -+ ret += filename; -+ ret += ":\t "; -+ -+ if (program_mode == PM_TEST) { -+ ret += "decoded succesfully"; -+ -+ return ret; -+ } -+ -+ if (!stdinput && !stdoutput) { -+ ret += ratio; -+ ret += " -- "; -+ } -+ -+ if (program_mode == PM_COMPRESS) { -+ if (keep) { -+ ret += "encoded succesfully"; -+ -+ return ret; -+ } -+ -+ ret += "replaced with "; -+ ret += output_filename; -+ -+ return ret; -+ } -+ -+ if (program_mode == PM_DECOMPRESS) { -+ if (keep) { -+ ret += "decoded succesfully"; -+ -+ return ret; -+ } -+ -+ ret += "replaced with "; -+ ret += output_filename; -+ -+ return ret; -+ } -+ -+ return ret; -+} -+ -+static string archive_name; // I know, it is crude, but I haven't found any other -+ // way then making a global variable to transfer filename to handler -+ -+void signal_handler (int signum) -+{ -+ unlink (archive_name.c_str()); // deleting -+ signal (signum, SIG_DFL); // we return the default function to used signal -+ kill (getpid(), signum); // and then send this signal to the process again -+} -+ -+} // namespace lzma -+ -+ -+int main(int argc, char **argv) -+{ -+ using namespace lzma; -+ using std::cerr; -+ -+ stringVector filenames; -+ -+ signal (SIGTERM,signal_handler); -+ signal (SIGHUP,signal_handler); -+ signal (SIGINT,signal_handler); -+ -+ try { -+ parse_options(argc, argv, filenames); -+ } -+ catch (...) { -+ return STATUS_ERROR; -+ } -+ -+ if (program_mode == PM_HELP) { -+ print_help(argv[0]); -+ return STATUS_OK; -+ } -+ else if (program_mode == PM_LICENSE) { -+ print_license(); -+ return STATUS_OK; -+ } -+ else if (program_mode == PM_VERSION) { -+ print_version(); -+ return STATUS_OK; -+ } -+ -+ if (filenames.empty()) { -+ stdinput = true; -+ stdoutput = true; -+ -+ /* FIXME: get rid of this */ -+ filenames.push_back("-"); -+ } -+ -+ /* Protection: always create new files with 0600 in order to prevent -+ * outsiders from reading incomplete data. */ -+ umask(0077); -+ -+ bool warning = false; -+ -+ for (int i = 0; i < filenames.size(); i++) { -+ CMyComPtr inStream; -+ CMyComPtr outStream; -+ UInt64 fileSize = 0; -+ int inhandle = 0, outhandle = 0; -+ string output_filename; -+ -+ if (stdinput) { -+ inStream = new CStdInFileStream; -+ MY_SET_BINARY_MODE(stdin); -+ fileSize = (UInt64)(Int64)-1; -+ -+ inhandle = STDIN_FILENO; -+ -+ outStream = new CStdOutFileStream; -+ MY_SET_BINARY_MODE(stdout); -+ -+ outhandle = STDOUT_FILENO; -+ } -+ else { -+ mode_t infile_mode = get_file_mode(filenames[i]); -+ if (!S_ISREG(infile_mode)) { -+ if (S_ISDIR(infile_mode)) { -+ warning = true; -+ cerr << argv[0] << ": " << filenames[i] << ": " -+ << "cowardly refusing to work on directory" -+ << endl; -+ -+ continue; -+ } -+ else if (S_ISLNK(infile_mode)) { -+ if (!stdoutput && !force) { -+ warning = true; -+ -+ cerr << argv[0] << ": " << filenames[i] << ": " -+ << "cowardly refusing to work on symbolic link " -+ << "(use --force to force encoding or decoding)" -+ << endl; -+ -+ continue; -+ } -+ } -+ else { -+ warning = true; -+ -+ cerr << argv[0] << ": " << filenames[i] << ": " -+ << "doesn't exist or is not a regular file" -+ << endl; -+ -+ continue; -+ } -+ } -+ -+ // Test if the file already ends with *suffix. -+ if (program_mode == PM_COMPRESS && !force -+ && string_ends_with(filenames[i], -+ suffix)) { -+ warning = true; -+ -+ cerr << filenames[i] << " already has " -+ << suffix << " suffix -- unchanged\n"; -+ -+ continue; -+ } -+ -+ // Test if the file extension is known. -+ if (program_mode == PM_DECOMPRESS -+ && !extension_is_known(filenames[i])) { -+ warning = true; -+ -+ cerr << filenames[i] << ": " -+ << " unknown suffix -- unchanged" -+ << endl; -+ -+ continue; -+ } -+ -+ try { -+ inhandle = open_instream(filenames[i], inStream, fileSize); -+ } -+ catch (Exception e) { -+ cerr << argv[0] << ": " << e.what() << endl; -+ return STATUS_ERROR; -+ } -+ -+ if (stdoutput) { -+ outStream = new CStdOutFileStream; -+ MY_SET_BINARY_MODE(stdout); -+ -+ outhandle = STDOUT_FILENO; -+ } -+ else { -+ /* Testing mode is nothing else but decoding -+ * and throwing away the result. */ -+ if (program_mode == PM_TEST) -+ output_filename = "/dev/null"; -+ else if (program_mode == PM_DECOMPRESS) -+ output_filename = replace_extension(filenames[i]); -+ else -+ output_filename = filenames[i] -+ + suffix; -+ archive_name = output_filename; -+ -+ try { -+ outhandle = open_outstream(output_filename, outStream); -+ } -+ catch (Exception e) { -+ cerr << argv[0] << ": " << e.what() << endl; -+ return STATUS_ERROR; -+ } -+ } -+ -+ } -+ -+ // Unless --force is specified, do not read/write compressed -+ // data from/to a terminal. -+ if (!force) { -+ if (program_mode == PM_COMPRESS && isatty(outhandle)) { -+ cerr << argv[0] << ": compressed data not " -+ "written to a terminal. Use " -+ "-f to force compression.\n" -+ << argv[0] << ": For help, type: " -+ << argv[0] << " -h\n"; -+ return STATUS_ERROR; -+ } else if (program_mode == PM_DECOMPRESS -+ && isatty(inhandle)) { -+ cerr << argv[0] << ": compressed data not " -+ "read from a terminal. Use " -+ "-f to force decompression.\n" -+ << argv[0] << ": For help, type: " -+ << argv[0] << " -h\n"; -+ return STATUS_ERROR; -+ } -+ } -+ -+ if (program_mode == PM_COMPRESS) { -+ NCompress::NLzma::CEncoder *encoderSpec = -+ new NCompress::NLzma::CEncoder; -+ -+ lzma_option options = option_mapping[compression_mode]; -+ -+ try { -+ encode(encoderSpec, inStream, outStream, options, fileSize); -+ } -+ catch (Exception e) { -+ cerr << argv[0] << ": " << e.what() << endl; -+ unlink(output_filename.c_str()); -+ delete(encoderSpec); -+ -+ return STATUS_ERROR; -+ } -+ -+ delete(encoderSpec); -+ } -+ else { // PM_DECOMPRESS | PM_TEST -+ NCompress::NLzma::CDecoder *decoderSpec = -+ new NCompress::NLzma::CDecoder; -+ -+ try { -+ decode(decoderSpec, inStream, outStream); -+ } -+ catch (Exception e) { -+ cerr << argv[0] << ": " << e.what() << endl; -+ unlink(output_filename.c_str()); -+ delete(decoderSpec); -+ -+ return STATUS_ERROR; -+ } -+ -+ delete(decoderSpec); -+ } -+ -+ /* Set permissions and owners. */ -+ if ( (program_mode == PM_COMPRESS || program_mode == PM_DECOMPRESS ) -+ && (!stdinput && !stdoutput) ) { -+ -+ int ret = 0; -+ struct stat file_stats; -+ ret = fstat(inhandle, &file_stats); -+ -+ ret = fchmod(outhandle, file_stats.st_mode); -+ ret = fchown(outhandle, file_stats.st_uid, file_stats.st_gid); -+ // We need to call fchmod() again, since otherwise the SUID bits -+ // are lost. -+ ret = fchmod(outhandle, file_stats.st_mode); -+ -+ struct timeval file_times[2]; -+ // Access time -+ file_times[0].tv_sec = file_stats.st_atime; -+ file_times[0].tv_usec = 0; -+ // Modification time -+ file_times[1].tv_sec = file_stats.st_mtime; -+ file_times[1].tv_usec = 0; -+ -+ ret = futimes(outhandle, file_times); -+ -+ if (!keep) -+ unlink(filenames[i].c_str()); -+ } -+ -+ if (verbosity > 0) { -+ if (stdoutput) { -+ cerr << filenames[i] << ":\t "; -+ cerr << "decoded succesfully" -+ << endl; -+ } -+ -+ else { -+ char buf[10] = { 0 }; -+ -+ if (program_mode == PM_DECOMPRESS) -+ snprintf(buf, 10, "%.2f%%", -+ (1 - get_ratio(outhandle, inhandle)) * 100); -+ if (program_mode == PM_COMPRESS) -+ snprintf(buf, 10, "%.2f%%", -+ (1 - get_ratio(inhandle, outhandle)) * 100); -+ -+ string ratio = buf; -+ cerr << pretty_print_status(filenames[i], output_filename, -+ ratio) -+ << endl; -+ } -+ } -+ } -+ -+ if (warning) -+ return STATUS_WARNING; -+ -+ return STATUS_OK; -+} -+ -Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/Exception.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/Exception.h 2009-06-01 22:01:10.000000000 +0200 -@@ -0,0 +1,45 @@ -+/* A couple of exceptions for lzmp. -+ * -+ * Copyright (C) 2005 Ville Koskinen -+ * -+ * This program is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU General Public License -+ * as published by the Free Software Foundation; either version 2 -+ * of the License, or (at your option) any later version. -+ * -+ * This program is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ */ -+ -+#ifndef _EXCEPTION_H_ -+#define _EXCEPTION_H_ -+ -+#include -+using std::string; -+ -+class Exception -+{ -+private: -+ string message; -+public: -+ Exception(char *what): message(what) { } -+ Exception(string what): message(what) { } -+ -+ ~Exception() { } -+ -+ string what(void) { return message; } -+}; -+ -+class ArgumentException: public Exception -+{ -+public: -+ ArgumentException(char *what): Exception(what) { } -+ ArgumentException(string what): Exception(what) { } -+ -+ ~ArgumentException() { } -+}; -+ -+#endif -+ -Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile.gcc -=================================================================== ---- lzma-4.65.orig/CPP/7zip/Compress/LZMA_Alone/makefile.gcc 2009-06-01 22:00:54.000000000 +0200 -+++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile.gcc 2009-06-01 22:06:13.000000000 +0200 -@@ -1,9 +1,10 @@ --PROG = lzma -+PROG = lzma_alone -+PROG2 = lzma - CXX = g++ -O2 -Wall - CXX_C = gcc -O2 -Wall - LIB = -lm - RM = rm -f --CFLAGS = -c -D_FILE_OFFSET_BITS=64 -+CFLAGS = -c -I ../../../ -D_FILE_OFFSET_BITS=64 -DPACKAGE_VERSION="\"4.32.0beta3\"" - - ifdef SystemDrive - IS_MINGW = 1 -@@ -45,12 +46,35 @@ - Lzma86Dec.o \ - Lzma86Enc.o \ - -+OBJS2 = \ -+ C_FileIO.o \ -+ CRC.o \ -+ Alloc.o \ -+ FileStreams.o \ -+ StreamUtils.o \ -+ InBuffer.o \ -+ OutBuffer.o \ -+ LzmaDecoder.o \ -+ StringConvert.o \ -+ StringToInt.o \ -+ LzmaEncoder.o \ -+ LzmaDec.o \ -+ LzmaEnc.o \ -+ LzFind.o \ -+ 7zCrc.o \ -+ lzmp.o - --all: $(PROG) -+all: $(PROG) $(PROG2) - - $(PROG): $(OBJS) - $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2) - -+$(PROG2): $(OBJS2) -+ $(CXX) -o $(PROG2) $(LDFLAGS) $(OBJS2) $(LIB) -+ -+lzmp.o: lzmp.cpp -+ $(CXX) $(CFLAGS) lzmp.cpp -+ - LzmaAlone.o: LzmaAlone.cpp - $(CXX) $(CFLAGS) LzmaAlone.cpp - -@@ -131,5 +153,5 @@ - $(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Enc.c - - clean: -- -$(RM) $(PROG) $(OBJS) -+ -$(RM) $(PROG) $(PROG2) $(OBJS) - -Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzma_version.h -=================================================================== ---- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzma_version.h 2009-06-01 22:01:10.000000000 +0200 -@@ -0,0 +1,31 @@ -+#ifndef LZMA_VERSION_H -+#define LZMA_VERSION_H -+ -+/* -+ Version and copyright information used by LZMA utils. -+*/ -+ -+static const char *LZMA_SDK_VERSION_STRING = "4.43"; -+ -+static const char *LZMA_SDK_COPYRIGHT_STRING = -+ "Copyright (C) 1999-2006 Igor Pavlov"; -+ -+static const char *LZMA_SDK_COPYRIGHT_INFO = -+ " See http://7-zip.org/sdk.html or the documentation of LZMA SDK for\n" -+ " the license. For reference, the version 4.43 is free software\n" -+ " licensed under the GNU LGPL."; -+ -+ -+static const char *LZMA_UTILS_VERSION_STRING = PACKAGE_VERSION; -+ -+static const char *LZMA_UTILS_COPYRIGHT_STRING = -+ "Copyright (C) 2006 Lasse Collin"; -+ -+static const char *LZMA_UTILS_COPYRIGHT_INFO = -+ "This program comes with ABSOLUTELY NO WARRANTY.\n" -+ "You may redistribute copies of this program\n" -+ "under the terms of the GNU General Public License.\n" -+ "For more information about these matters, see the file " -+ "named COPYING.\n"; -+ -+#endif /* ifndef LZMA_VERSION_H */ -Index: lzma-4.65/CPP/Common/C_FileIO.h -=================================================================== ---- lzma-4.65.orig/CPP/Common/C_FileIO.h 2009-05-15 23:33:51.000000000 +0200 -+++ lzma-4.65/CPP/Common/C_FileIO.h 2009-06-01 22:06:56.000000000 +0200 -@@ -24,6 +24,7 @@ - bool Close(); - bool GetLength(UInt64 &length) const; - off_t Seek(off_t distanceToMove, int moveMethod) const; -+ int GetHandle() const { return _handle; } - }; - - class CInFile: public CFileBase diff --git a/target/tools/lzma/patches/003-compile_fixes.patch b/target/tools/lzma/patches/003-compile_fixes.patch deleted file mode 100644 index 49ae66b9c..000000000 --- a/target/tools/lzma/patches/003-compile_fixes.patch +++ /dev/null @@ -1,26 +0,0 @@ -diff -urN lzma-4.65/CPP/7zip/Common/FileStreams.h lzma-4.65.new/CPP/7zip/Common/FileStreams.h ---- lzma-4.65/CPP/7zip/Common/FileStreams.h 2009-05-15 23:33:51.000000000 +0200 -+++ lzma-4.65.new/CPP/7zip/Common/FileStreams.h 2009-06-01 22:30:01.000000000 +0200 -@@ -72,6 +72,7 @@ - public IOutStream, - public CMyUnknownImp - { -+public: - #ifdef USE_WIN_FILE - NWindows::NFile::NIO::COutFile File; - #else -diff -urN lzma-4.65/CPP/Common/MyWindows.h lzma-4.65.new/CPP/Common/MyWindows.h ---- lzma-4.65/CPP/Common/MyWindows.h 2009-05-15 23:33:51.000000000 +0200 -+++ lzma-4.65.new/CPP/Common/MyWindows.h 2009-06-01 22:29:26.000000000 +0200 -@@ -101,8 +101,11 @@ - - #ifdef __cplusplus - -+#ifndef INITGUID -+#define INITGUID - DEFINE_GUID(IID_IUnknown, - 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); -+#endif - struct IUnknown - { - STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE; diff --git a/target/tools/lzma/patches/100-static_library.patch b/target/tools/lzma/patches/100-static_library.patch deleted file mode 100644 index 15ab4e055..000000000 --- a/target/tools/lzma/patches/100-static_library.patch +++ /dev/null @@ -1,70 +0,0 @@ ---- a/C/LzmaUtil/makefile.gcc -+++ b/C/LzmaUtil/makefile.gcc -@@ -1,44 +1,53 @@ - PROG = lzma --CXX = g++ --LIB = -+CC = gcc -+LIB = liblzma.a - RM = rm -f - CFLAGS = -c -O2 -Wall -+AR = ar -+RANLIB = ranlib - - OBJS = \ -- LzmaUtil.o \ - Alloc.o \ - LzFind.o \ - LzmaDec.o \ - LzmaEnc.o \ -+ LzmaLib.o \ - 7zFile.o \ - 7zStream.o \ - -- - all: $(PROG) - --$(PROG): $(OBJS) -- $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2) -+$(PROG): LzmaUtil.o $(LIB) -+ $(CC) -o $(PROG) $(LDFLAGS) $< $(LIB) - - LzmaUtil.o: LzmaUtil.c -- $(CXX) $(CFLAGS) LzmaUtil.c -+ $(CC) $(CFLAGS) LzmaUtil.c -+ -+$(LIB): $(OBJS) -+ rm -f $@ -+ $(AR) rcu $@ $(OBJS) -+ $(RANLIB) $@ - - Alloc.o: ../Alloc.c -- $(CXX) $(CFLAGS) ../Alloc.c -+ $(CC) $(CFLAGS) ../Alloc.c - - LzFind.o: ../LzFind.c -- $(CXX) $(CFLAGS) ../LzFind.c -+ $(CC) $(CFLAGS) ../LzFind.c - - LzmaDec.o: ../LzmaDec.c -- $(CXX) $(CFLAGS) ../LzmaDec.c -+ $(CC) $(CFLAGS) ../LzmaDec.c - - LzmaEnc.o: ../LzmaEnc.c -- $(CXX) $(CFLAGS) ../LzmaEnc.c -+ $(CC) $(CFLAGS) ../LzmaEnc.c -+ -+LzmaLib.o: ../LzmaLib.c -+ $(CC) $(CFLAGS) ../LzmaLib.c - - 7zFile.o: ../7zFile.c -- $(CXX) $(CFLAGS) ../7zFile.c -+ $(CC) $(CFLAGS) ../7zFile.c - - 7zStream.o: ../7zStream.c -- $(CXX) $(CFLAGS) ../7zStream.c -+ $(CC) $(CFLAGS) ../7zStream.c - - clean: -- -$(RM) $(PROG) $(OBJS) -+ -$(RM) $(PROG) *.o *.a diff --git a/target/tools/mkfimage/Makefile b/target/tools/mkfimage/Makefile deleted file mode 100644 index 2c6e37878..000000000 --- a/target/tools/mkfimage/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -include $(TOPDIR)/rules.mk - -all: mkfimage.c - $(CC_FOR_BUILD) ${FLAGS_FOR_BUILD} -o ${STAGING_HOST_DIR}/bin/mkfimage mkfimage.c $(MAKE_TRACE) diff --git a/target/tools/mkfimage/mkfimage.c b/target/tools/mkfimage/mkfimage.c deleted file mode 100644 index b1897fbd7..000000000 --- a/target/tools/mkfimage/mkfimage.c +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv){ - unsigned char *buffer = malloc(64 * 1024); - struct stat s; - unsigned int size_vmlinux = 0, real_size_vmlinux = 0; - const unsigned char *magic_str = "ACME_PART_MAGIC"; - unsigned int loop; - unsigned char *magic; - - if(argc != 3){ - printf("%s in out\n", argv[0]); - return 1; - } - - printf("Generating image\n"); - - FILE *vmlinux = fopen(argv[1], "r"); - FILE *vmlinux_out = fopen(argv[2], "w"); - if((!vmlinux) || (!vmlinux_out)){ - printf("Error opening a file\n"); - return 1; - } - - stat(argv[1], &s); - size_vmlinux = s.st_size; - real_size_vmlinux = (size_vmlinux & 0xffff0000) + 0x10000; - - printf("vmlinux = 0x%.08X / 0x%.08X\n", size_vmlinux, real_size_vmlinux); - - unsigned int t = fread(buffer, 1, 64 * 1024, vmlinux); - for(loop = 0; loop < (64 * 1024) - sizeof(magic_str); loop++){ - if(buffer[loop] == magic_str[0]){ - if((magic = strstr(&buffer[loop], magic_str))){ - //printf("Magic at 0x%.08X %p %p\n", magic - buffer, magic, buffer); - printf("Found Magic %X%X%X%X\n", - buffer[loop + strlen(magic_str)], - buffer[loop + strlen(magic_str) + 2], - buffer[loop + strlen(magic_str) + 1], - buffer[loop + strlen(magic_str) + 3]); - - buffer[loop + strlen(magic_str)] = real_size_vmlinux >> 24; - buffer[loop + strlen(magic_str) + 2] = (real_size_vmlinux >> 16) & 0xff; - buffer[loop + strlen(magic_str) + 1] = (real_size_vmlinux >> 8) & 0xff; - buffer[loop + strlen(magic_str) + 3] = (real_size_vmlinux) & 0xff; - - printf("Replaced with %.02X%.02X%.02X%.02X\n", - buffer[loop + strlen(magic_str)], - buffer[loop + strlen(magic_str) + 2], - buffer[loop + strlen(magic_str) + 1], - buffer[loop + strlen(magic_str) + 3]); - - } - } - } - - fwrite(buffer, 1, 64 * 1024, vmlinux_out); - real_size_vmlinux -= 64 * 1024; - do { - real_size_vmlinux -= 64 * 1024; - memset(buffer, 0, 64 * 1024); - fread(buffer, 1, 64 * 1024, vmlinux); - fwrite(buffer, 1, 64 * 1024, vmlinux_out); - } while (real_size_vmlinux); - - return 0; -} diff --git a/target/tools/mtd-utils/Makefile b/target/tools/mtd-utils/Makefile deleted file mode 100644 index 38f10de69..000000000 --- a/target/tools/mtd-utils/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# This file is part of the OpenADK project. OpenADK is copyrighted -# material, please see the LICENCE file in the top-level directory. - -include $(TOPDIR)/rules.mk - -PKG_NAME:= mtd-utils -PKG_VERSION:= 1.5.0 -PKG_RELEASE:= 1 -PKG_MD5SUM:= a4df1ad29684be79b0fa699bdae01faf -PKG_SITES:= http://openadk.org/distfiles/ - -include ../rules.mk - -all: ${STAGING_HOST_DIR}/bin/mkfs.jffs2 - -$(WRKBUILD)/.compiled: ${WRKDIST}/.prepared - ${MAKE} -C ${WRKBUILD} CC='${CC_FOR_BUILD}' CPPFLAGS='-DWITHOUT_XATTR=1 -I./include' - touch $@ - -${STAGING_HOST_DIR}/bin/mkfs.jffs2: $(WRKBUILD)/.compiled - $(INSTALL_BIN) $(WRKBUILD)/mkfs.jffs2 \ - ${STAGING_HOST_DIR}/bin - -include $(TOPDIR)/mk/tools.mk diff --git a/target/tools/mtd-utils/patches/lzo.patch b/target/tools/mtd-utils/patches/lzo.patch deleted file mode 100644 index 52f16146c..000000000 --- a/target/tools/mtd-utils/patches/lzo.patch +++ /dev/null @@ -1,88 +0,0 @@ -diff -Nur mtd-utils-1.5.0.orig/compr.c mtd-utils-1.5.0/compr.c ---- mtd-utils-1.5.0.orig/compr.c 2012-05-07 09:19:39.000000000 +0200 -+++ mtd-utils-1.5.0/compr.c 2014-02-25 21:05:20.000000000 +0100 -@@ -517,9 +517,6 @@ - #ifdef CONFIG_JFFS2_RTIME - jffs2_rtime_init(); - #endif --#ifdef CONFIG_JFFS2_LZO -- jffs2_lzo_init(); --#endif - return 0; - } - -@@ -531,8 +528,5 @@ - #ifdef CONFIG_JFFS2_ZLIB - jffs2_zlib_exit(); - #endif --#ifdef CONFIG_JFFS2_LZO -- jffs2_lzo_exit(); --#endif - return 0; - } -diff -Nur mtd-utils-1.5.0.orig/Makefile mtd-utils-1.5.0/Makefile ---- mtd-utils-1.5.0.orig/Makefile 2012-05-07 09:19:39.000000000 +0200 -+++ mtd-utils-1.5.0/Makefile 2014-02-25 21:13:03.000000000 +0100 -@@ -16,27 +16,13 @@ - - TESTS = tests - --MTD_BINS = \ -- ftl_format flash_erase nanddump doc_loadbios \ -- ftl_check mkfs.jffs2 flash_lock flash_unlock \ -- flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite nandtest \ -- jffs2dump \ -- nftldump nftl_format docfdisk \ -- rfddump rfdformat \ -- serve_image recv_image \ -- sumtool jffs2reader --UBI_BINS = \ -- ubiupdatevol ubimkvol ubirmvol ubicrc32 ubinfo ubiattach \ -- ubidetach ubinize ubiformat ubirename mtdinfo ubirsvol -+MTD_BINS = mkfs.jffs2 - - BINS = $(MTD_BINS) --BINS += mkfs.ubifs/mkfs.ubifs --BINS += $(addprefix ubi-utils/,$(UBI_BINS)) - SCRIPTS = flash_eraseall - - TARGETS = $(BINS) - TARGETS += lib/libmtd.a --TARGETS += ubi-utils/libubi.a - - OBJDEPS = $(BUILDDIR)/include/version.h - -@@ -83,12 +69,12 @@ - # - # Utils in top level - # --obj-mkfs.jffs2 = compr_rtime.o compr_zlib.o compr_lzo.o compr.o rbtree.o --LDFLAGS_mkfs.jffs2 = $(ZLIBLDFLAGS) $(LZOLDFLAGS) --LDLIBS_mkfs.jffs2 = -lz $(LZOLDLIBS) -+obj-mkfs.jffs2 = compr_rtime.o compr_zlib.o compr.o rbtree.o -+LDFLAGS_mkfs.jffs2 = $(ZLIBLDFLAGS) -+LDLIBS_mkfs.jffs2 = -lz - --LDFLAGS_jffs2reader = $(ZLIBLDFLAGS) $(LZOLDFLAGS) --LDLIBS_jffs2reader = -lz $(LZOLDLIBS) -+LDFLAGS_jffs2reader = $(ZLIBLDFLAGS) -+LDLIBS_jffs2reader = -lz - - $(foreach v,$(MTD_BINS),$(eval $(call mkdep,,$(v)))) - -@@ -103,7 +89,7 @@ - # - obj-mkfs.ubifs = crc16.o lpt.o compr.o devtable.o \ - hashtable/hashtable.o hashtable/hashtable_itr.o --LDLIBS_mkfs.ubifs = -lz -llzo2 -lm -luuid -+LDLIBS_mkfs.ubifs = -lz -lm -luuid - $(call mkdep,mkfs.ubifs/,mkfs.ubifs,,ubi-utils/libubi.a) - - # -@@ -117,6 +103,3 @@ - obj-mtdinfo = libubigen.a - obj-ubinize = libubigen.a libiniparser.a - obj-ubiformat = libubigen.a libscan.a -- --$(foreach v,libubi.a libubigen.a libiniparser.a libscan.a,$(eval $(call _mkdep,ubi-utils/,$(v)))) --$(foreach v,$(UBI_BINS),$(eval $(call mkdep,ubi-utils/,$(v),libubi.a ubiutils-common.o))) diff --git a/target/tools/rules.mk b/target/tools/rules.mk deleted file mode 100644 index a6a3684ac..000000000 --- a/target/tools/rules.mk +++ /dev/null @@ -1,7 +0,0 @@ -# This file is part of the OpenADK project. OpenADK is copyrighted -# material, please see the LICENCE file in the top-level directory. - -WRKDIR_BASE= ${TOOLS_BUILD_DIR} -WRKDIR= ${WRKDIR_BASE} - -include ${TOPDIR}/mk/buildhlp.mk diff --git a/target/tools/squashfs/Makefile b/target/tools/squashfs/Makefile deleted file mode 100644 index 94b3a0115..000000000 --- a/target/tools/squashfs/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# This file is part of the OpenADK project. OpenADK is copyrighted -# material, please see the LICENCE file in the top-level directory. - -include $(TOPDIR)/rules.mk - -PKG_NAME:= squashfs -PKG_VERSION:= 4.2 -PKG_RELEASE:= 1 -PKG_MD5SUM:= 1b7a781fb4cf8938842279bd3e8ee852 -PKG_SITES:= ${MASTER_SITE_SOURCEFORGE:=squashfs/} - -DISTFILES:= ${PKG_NAME}${PKG_VERSION}.tar.gz -WRKDIST= ${WRKDIR}/$(PKG_NAME)${PKG_VERSION} - -include ../rules.mk - -all: ${STAGING_HOST_DIR}/bin/mksquashfs - -$(WRKBUILD)/.compiled: ${WRKDIST}/.prepared - ${MAKE} -C ${WRKBUILD}/squashfs-tools CC='${CC_FOR_BUILD}' \ - XZ_SUPPORT=1 CPPFLAGS_FOR_BUILD=$(CPPFLAGS_FOR_BUILD) \ - EXTRA_LDFLAGS=$(LDFLAGS_FOR_BUILD) - touch $@ - -${STAGING_HOST_DIR}/bin/mksquashfs: $(WRKBUILD)/.compiled - $(INSTALL_BIN) $(WRKBUILD)/squashfs-tools/mksquashfs \ - ${STAGING_HOST_DIR}/bin - -include $(TOPDIR)/mk/tools.mk diff --git a/target/tools/squashfs/patches/cppflags.patch b/target/tools/squashfs/patches/cppflags.patch deleted file mode 100644 index 1432ea3cf..000000000 --- a/target/tools/squashfs/patches/cppflags.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff -Nur squashfs4.2.orig/squashfs-tools/Makefile squashfs4.2/squashfs-tools/Makefile ---- squashfs4.2.orig/squashfs-tools/Makefile 2011-02-28 21:04:15.000000000 +0100 -+++ squashfs4.2/squashfs-tools/Makefile 2013-12-27 13:49:22.000000000 +0100 -@@ -93,7 +93,7 @@ - # End of BUILD options section # - ############################################### - --INCLUDEDIR = -I. -+INCLUDEDIR = -I. $(CPPFLAGS_FOR_BUILD) - INSTALL_DIR = /usr/local/bin - - MKSQUASHFS_OBJS = mksquashfs.o read_fs.o sort.o swap.o pseudo.o compressor.o diff --git a/target/tools/srec2bin/Makefile b/target/tools/srec2bin/Makefile deleted file mode 100644 index f48f8f939..000000000 --- a/target/tools/srec2bin/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -include $(TOPDIR)/rules.mk - -all: srec2bin.c - $(CC_FOR_BUILD) $(FLAGS_FOR_BUILD) -o ${STAGING_HOST_DIR}/bin/srec2bin srec2bin.c diff --git a/target/tools/srec2bin/srec2bin.c b/target/tools/srec2bin/srec2bin.c deleted file mode 100644 index 8ba4387e6..000000000 --- a/target/tools/srec2bin/srec2bin.c +++ /dev/null @@ -1,521 +0,0 @@ -#include -#include -#include - -//Rev 0.1 Original -// 8 Jan 2001 MJH Added code to write data to Binary file -// note: outputfile is name.bin, where name is first part -// of input file. ie tmp.rec -> tmp.bin -// -// srec2bin -// -// TAG -// bit32u TAG_BIG = 0xDEADBE42; -// bit32u TAG_LITTLE = 0xFEEDFA42; -// -// File Structure -// -// TAG : 32 Bits -// [DATA RECORDS] -// -// Data Records Structure -// -// LENGTH : 32 Bits <- Length of DATA, excludes ADDRESS and CHECKSUM -// ADDRESS : 32 Bits -// DATA : 8 Bits * LENGTH -// CHECKSUM: 32 Bits <- 0 - (Sum of Length --> End of Data) -// -// Note : If Length == 0, Address will be Program Start -// -// -// -// -// - -#define MajRevNum 0 -#define MinRevNum 2 - - -#define EndianSwitch(x) ((x >> 24) | (x << 24) | ((x << 8) & (0x00FF0000)) | ((x >> 8) & (0x0000FF00)) ) - -typedef unsigned char bit8u; -typedef unsigned int bit32u; -typedef int bit32; - -#define FALSE 0 -#define TRUE (!FALSE) - - -bit32u CheckSum; -int RecStart; -int debug; -int verbose; - -FILE *OpenOutputFile( char *Name ); -FILE *fOut; -bit32u RecLength=0; - -bit32u AddressCurrent; - -bit32u gh(char *cp,int nibs); - -int BigEndian; - -int inputline; - -// char buf[16*1024]; - -char buffer[2048]; -char *cur_ptr; -int cur_line=0; -int cur_len=0; - -int s1s2s3_total=0; - -bit32u PBVal; -int PBValid; -bit32u PBAdr; - - -void dumpfTell(char *s, bit32u Value) -{ - int Length; - Length = (int) RecLength; - if (debug) - printf("[%s ] ftell()[0x%08lX] Length[0x%4X] Length[%4d] Value[0x%08x]\n", - s, ftell(fOut), Length, Length, Value); -} - -void DispHex(bit32u Hex) -{ -// printf("%X", Hex); -} - -void WaitDisplay(void) -{ - static int Count=0; - static int Index=0; - char iline[]={"-\\|/"}; - - Count++; - if ((Count % 32)==0) - { - if (verbose) - printf("%c%c",iline[Index++],8); - Index &= 3; - } -} - - -void binOut32 ( bit32u Data ) -{ -// On UNIX machine all 32bit writes need ENDIAN switched -// Data = EndianSwitch(Data); -// fwrite( &Data, sizeof(bit32u), 1, fOut); - - char sdat[4]; - int i; - - for(i=0;i<4;i++) - sdat[i]=(char)(Data>>(i*8)); - fwrite( sdat, 1, 4, fOut); - dumpfTell("Out32" , Data); -} - -// Only update RecLength on Byte Writes -// All 32 bit writes will be for Length etc - -void binOut8 ( bit8u Data ) -{ - int n; - dumpfTell("B4Data" , (bit32u) (Data & 0xFF) ); - n = fwrite( &Data, sizeof(bit8u), 1, fOut); - if (n != 1) - printf("Error in writing %X for Address 0x%8X\n", Data, AddressCurrent); - RecLength += 1; -} - -// Currently ONLY used for outputting Program Start - -void binRecStart(bit32u Address) -{ - RecLength = 0; - CheckSum = Address; - RecStart = TRUE; - - if (debug) - printf("[RecStart] CheckSum[0x%08X] Length[%4d] Address[0x%08X]\n", - CheckSum, RecLength, Address); - - - dumpfTell("RecLength", RecLength); - binOut32( RecLength ); - dumpfTell("Address", Address); - binOut32( Address ); -} - -void binRecEnd(void) -{ - long RecEnd; - - if (!RecStart) // if no record started, do not end it - { - return; - } - - RecStart = FALSE; - - - RecEnd = ftell(fOut); // Save Current position - - if (debug) - printf("[RecEnd ] CheckSum[0x%08X] Length[%4d] Length[0x%X] RecEnd[0x%08lX]\n", - CheckSum, RecLength, RecLength, RecEnd); - - fseek( fOut, -((long) RecLength), SEEK_CUR); // move back Start Of Data - - dumpfTell("Data ", -1); - - fseek( fOut, -4, SEEK_CUR); // move back Start Of Address - - dumpfTell("Address ", -1); - - fseek( fOut, -4, SEEK_CUR); // move back Start Of Length - - dumpfTell("Length ", -1); - - binOut32( RecLength ); - - fseek( fOut, RecEnd, SEEK_SET); // move to end of Record - - CheckSum += RecLength; - - CheckSum = ~CheckSum + 1; // Two's complement - - binOut32( CheckSum ); - - if (verbose) - printf("[Created Record of %d Bytes with CheckSum [0x%8X]\n", RecLength, CheckSum); -} - -void binRecOutProgramStart(bit32u Address) -{ - if (Address != (AddressCurrent+1)) - { - binRecEnd(); - binRecStart(Address); - } - AddressCurrent = Address; -} -void binRecOutByte(bit32u Address, bit8u Data) -{ - // If Address is one after Current Address, output Byte - // If not, close out last record, update Length, write checksum - // Then Start New Record, updating Current Address - - if (Address != (AddressCurrent+1)) - { - binRecEnd(); - binRecStart(Address); - } - AddressCurrent = Address; - CheckSum += Data; - binOut8( Data ); -} - -//============================================================================= -// SUPPORT FUNCTIONS -//============================================================================= -int readline(FILE *fil,char *buf,int len) -{ - int rlen; - - rlen=0; - if (len==0) return(0); - while(1) - { - if (cur_len==0) - { - cur_len=fread(buffer, 1, sizeof(buffer), fil); - if (cur_len==0) - { - if (rlen) - { - *buf=0; - return(rlen); - } - return(-1); - } - cur_ptr=buffer; - } - if (cur_len) - { - if (*cur_ptr=='\n') - { - *buf=0; - cur_ptr++; - cur_len--; - return(rlen); - } - else - { - if ((len>1)&&(*cur_ptr!='\r')) - { - *buf++=*cur_ptr++; - len--; - } - else - cur_ptr++; - - rlen++; - cur_len--; - } - } - else - { - *buf=0; - cur_ptr++; - cur_len--; - return(rlen); - } - } -} - - -int SRLerrorout(char *c1,char *c2) -{ - printf("\nERROR: %s - '%s'.",c1,c2); - return(FALSE); -} - - -int checksum(char *cp,int count) -{ - char *scp; - int cksum; - int dum; - - scp=cp; - while(*scp) - { - if (!isxdigit(*scp++)) - return(SRLerrorout("Invalid hex digits",cp)); - } - scp=cp; - - cksum=count; - - while(count) - { - cksum += gh(scp,2); - if (count == 2) - dum = ~cksum; - scp += 2; - count--; - } - cksum&=0x0ff; - // printf("\nCk:%02x",cksum); - return(cksum==0x0ff); -} - -bit32u gh(char *cp,int nibs) -{ - int i; - bit32u j; - - j=0; - - for(i=0;i='a')&&(*cp<='z')) *cp &= 0x5f; - if ((*cp>='0')&&(*cp<='9')) - j += (*cp-0x30); - else - if ((*cp>='A')&&(*cp<='F')) - j += (*cp-0x37); - else - SRLerrorout("Bad Hex char", cp); - cp++; - } - return(j); -} - - -//============================================================================= -// PROCESS SREC LINE -//============================================================================= - -int srecLine(char *pSrecLine) -{ - char *scp,ch; - int itmp,count,dat; - bit32u adr; - static bit32u RecordCounter=0; - - cur_line++; - scp=pSrecLine; - - if (*pSrecLine!='S') - return(SRLerrorout("Not an Srecord file",scp)); - pSrecLine++; - if (strlen(pSrecLine)<4) - return(SRLerrorout("Srecord too short",scp)); - - ch=*pSrecLine++; - - count=gh(pSrecLine,2); - - pSrecLine += 2; - - // if(debug) - // printf("count %d, strlen(pSrecLine) = %d, pSrecLine =[%s]\n", count, strlen(pSrecLine), pSrecLine); - RecordCounter++; - DispHex(RecordCounter); - - if ((count*2) != strlen(pSrecLine)) return(SRLerrorout("Count field larger than record",scp)); - - if (!checksum(pSrecLine, count)) return(SRLerrorout("Bad Checksum",scp)); - - switch(ch) - { - case '0': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); - itmp=gh(pSrecLine,4); pSrecLine+=4; count-=2; - if (itmp) return(SRLerrorout("Srecord 1 address not zero",scp)); - break; - case '1': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); - return(SRLerrorout("Srecord Not valid for MIPS",scp)); - break; - case '2': if (count<4) return(SRLerrorout("Invalid Srecord count field",scp)); - return(SRLerrorout("Srecord Not valid for MIPS",scp)); - break; - case '3': if (count<5) return(SRLerrorout("Invalid Srecord count field",scp)); - adr=gh(pSrecLine,8); pSrecLine+=8; count-=4; - count--; - while(count) - { - dat=gh(pSrecLine,2); pSrecLine+=2; count--; - binRecOutByte(adr, (char) (dat & 0xFF)); - adr++; - } - s1s2s3_total++; - break; - case '4': return(SRLerrorout("Invalid Srecord type",scp)); - break; - case '5': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); - itmp=gh(pSrecLine,4); pSrecLine+=4; count-=2; - if (itmp|=s1s2s3_total) return(SRLerrorout("Incorrect number of S3 Record processed",scp)); - break; - case '6': return(SRLerrorout("Invalid Srecord type",scp)); - break; - case '7': // PROGRAM START - if (count<5) return(SRLerrorout("Invalid Srecord count field",scp)); - adr=gh(pSrecLine,8); pSrecLine+=8; count-=4; - if (count!=1) return(SRLerrorout("Invalid Srecord count field",scp)); - binRecOutProgramStart(adr); - break; - case '8': if (count<4) return(SRLerrorout("Invalid Srecord count field",scp)); - return(SRLerrorout("Srecord Not valid for MIPS",scp)); - break; - case '9': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); - return(SRLerrorout("Srecord Not valid for MIPS",scp)); - break; - default: - break; - } - return(TRUE); -} - - -//============================================================================= -// MAIN LOGIC, READS IN LINE AND OUTPUTS BINARY -//============================================================================= - -int srec2bin(int argc,char *argv[],int verbose) -{ - int rlen,sts; - FILE *fp; - char buff[256]; - bit32u TAG_BIG = 0xDEADBE42; - bit32u TAG_LITTLE = 0xFEEDFA42; - - bit32u Tag; - - - if(argc < 3) - { - printf("\nError: \n\n"); - return(0); - } - - if (argc > 3) BigEndian=TRUE; else BigEndian=FALSE; - - if (BigEndian) - Tag = TAG_BIG; - else - Tag = TAG_LITTLE; - - if (verbose) - printf("\nEndian: %s, Tag is 0x%8X\n",(BigEndian)?"BIG":"LITTLE", Tag); - - fp = fopen(argv[1],"rt"); - - if (fp==NULL) - { - printf("\nError: Opening input file, %s.", argv[1]); - return(0); - } - - fOut = fopen( argv[2], "wb"); - - if (fOut==NULL) - { - printf("\nError: Opening Output file, %s.", argv[2]); - if(fp) fclose(fp); - return(0); - } - - RecStart = FALSE; - - AddressCurrent = 0xFFFFFFFFL; - - // Setup Tag - - dumpfTell("Tag", Tag); - - binOut32(Tag); - - - inputline=0; - sts=TRUE; - - rlen = readline(fp,buff,sizeof buff); - - while( (sts) && (rlen != -1)) - { - if (strlen(buff)) - { - sts &= srecLine(buff); - WaitDisplay(); - } - rlen = readline(fp,buff,sizeof buff); - } - - - // printf("PC: 0x%08X, Length 0x%08X, Tag 0x%08X\n", ProgramStart, RecLength, TAG_LITTLE); - - binRecEnd(); - - if(fp) fclose(fp); - if(fOut) fclose(fOut); - - return(1); -} - -int main(int argc, char *argv[]) -{ - debug = FALSE; - verbose = FALSE; - srec2bin(argc,argv,verbose); - return 0; -} diff --git a/target/tools/trx/Makefile b/target/tools/trx/Makefile deleted file mode 100644 index d1832ee8c..000000000 --- a/target/tools/trx/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -include $(TOPDIR)/rules.mk - -all: trx.c - $(CC_FOR_BUILD) $(FLAGS_FOR_BUILD) -o ${STAGING_HOST_DIR}/bin/trx trx.c diff --git a/target/tools/trx/trx.c b/target/tools/trx/trx.c deleted file mode 100644 index 9e4d521ca..000000000 --- a/target/tools/trx/trx.c +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Copyright (C) 2004 Manuel Novoa III - * Copyright (C) 2005 Konstantin A. Klubnichkin and Oleg I. Vdovikin - * Copyright (C) 2006 OpenWrt developers - * Copyright (C) 2011 Waldemar Brodkorb - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include -#include -#include -#include -#include -#include -#include - -uint32_t crc32buf(char *buf, size_t len); - -/**********************************************************************/ -/* from trxhdr.h */ - -#define TRX_MAGIC 0x30524448 /* "HDR0" */ -#define TRX_VERSION 1 -#define TRX_MAX_LEN 0x697800 -#define TRX_NO_HEADER 1 /* Do not write TRX header */ - -struct trx_header { - uint32_t magic; /* "HDR0" */ - uint32_t len; /* Length of file including header */ - uint32_t crc32; /* 32-bit CRC from flag_version to end of file */ - uint32_t flag_version; /* 0:15 flags, 16:31 version */ - uint32_t offsets[3]; /* Offsets of partitions from start of header */ -}; - -/**********************************************************************/ - -void usage(void) __attribute__ (( __noreturn__ )); - -void usage(void) -{ - fprintf(stderr, "Usage: trx [-p product_id] [-v version] [-o outfile] [-m maxlen] [-a align] [-b offset] -f file [-f file [-f file]]\n"); - exit(EXIT_FAILURE); -} - -int main(int argc, char **argv) -{ - FILE *out = stdout; - FILE *in; - char *ofn = NULL; - char *buf; - char *e; - int c, i; - size_t n; - uint32_t cur_len; - unsigned long maxlen = TRX_MAX_LEN; - struct trx_header *p; - - struct { - uint8_t version[4]; /* Firmware version */ - uint8_t prod_id[12]; /* Product Id */ - uint8_t comp_hw[4][4]; /* Compatible hw list maj-min min/maj-min max */ - uint8_t pad[32]; /* Padding */ - } asus = { - .version = { 1, 9, 2, 7 }, /* version is set to 1.9.2.7 by default */ - .comp_hw[0] = { 0, 2, 2, 99 } /* hardcoded hw compat list 0.02 - 2.99 */ - }; - - - if (!(buf = malloc(maxlen))) { - fprintf(stderr, "malloc failed\n"); - return EXIT_FAILURE; - } - - p = (struct trx_header *) buf; - - p->magic = TRX_MAGIC; - cur_len = sizeof(struct trx_header); - p->flag_version = (TRX_VERSION << 16); - - in = NULL; - i = 0; - - while ((c = getopt(argc, argv, "-:o:p:v:m:a:b:f:")) != -1) { - switch (c) { - case 'f': - p->offsets[i++] = cur_len; - - if (!(in = fopen(optarg, "r"))) { - fprintf(stderr, "can not open \"%s\" for reading\n", optarg); - usage(); - } - n = fread(buf + cur_len, 1, maxlen - cur_len, in); - if (!feof(in)) { - fprintf(stderr, "fread failure or file \"%s\" too large\n",optarg); - fclose(in); - return EXIT_FAILURE; - } - fclose(in); -#undef ROUND -#define ROUND 4 - if (n & (ROUND-1)) { - memset(buf + cur_len + n, 0, ROUND - (n & (ROUND-1))); - n += ROUND - (n & (ROUND-1)); - } - cur_len += n; - /* reserve space for asus footer */ - if (asus.prod_id[0]) { - cur_len += sizeof(asus); - } - break; - case 'o': - ofn = optarg; - if (ofn && !(out = fopen(ofn, "w"))) { - fprintf(stderr, "can not open \"%s\" for writing\n", ofn); - usage(); - } - - break; - case 'm': - errno = 0; - maxlen = strtoul(optarg, &e, 0); - if (errno || (e == optarg) || *e) { - fprintf(stderr, "illegal numeric string\n"); - usage(); - } -#undef ROUND -#define ROUND 0x1000 - if (maxlen & (ROUND-1)) { - maxlen += (ROUND - (maxlen & (ROUND-1))); - } - if (maxlen < ROUND) { - fprintf(stderr, "maxlen too small (or wrapped)\n"); - usage(); - } - if (maxlen > TRX_MAX_LEN) { - fprintf(stderr, "WARNING: maxlen exceeds default maximum! Beware of overwriting nvram!\n"); - } - if (!(buf = realloc(buf,maxlen))) { - fprintf(stderr, "realloc failed"); - return EXIT_FAILURE; - } - break; - case 'a': - errno = 0; - n = strtoul(optarg, &e, 0); - if (errno || (e == optarg) || *e) { - fprintf(stderr, "illegal numeric string\n"); - usage(); - } - if (cur_len & (n-1)) { - n = n - (cur_len & (n-1)); - memset(buf + cur_len, 0, n); - cur_len += n; - } - break; - case 'b': - errno = 0; - n = strtoul(optarg, &e, 0); - if (errno || (e == optarg) || *e) { - fprintf(stderr, "illegal numeric string\n"); - usage(); - } - if (n < cur_len) { - fprintf(stderr, "WARNING: current length exceeds -b %d offset\n",(int)n); - } else { - memset(buf + cur_len, 0, n - cur_len); - cur_len = n; - } - break; - case 'p': - if ((n = strlen(optarg)) > sizeof(asus.prod_id)) { - fprintf(stderr, "product id too long\n"); - usage(); - } - memset(asus.prod_id, ' ', sizeof(asus.prod_id)); - memcpy(asus.prod_id, optarg, n); - break; - case 'v': - for (n = 0; n < sizeof(asus.version) / sizeof(asus.version[0]); n++) - { - if (n != 0 && optarg[0] == '.' && optarg[1]) optarg++; - else if (n != 0) break; - - asus.version[n] = strtoul(optarg, &optarg, 10); - } - if (*optarg) - { - fprintf(stderr, "invalid version string\n"); - usage(); - } - break; - default: - usage(); - } - } - - if (!in) { - fprintf(stderr, "we require at least one filename\n"); - usage(); - } - -#undef ROUND -#define ROUND 0x1000 - n = cur_len & (ROUND-1); - if (n) { - memset(buf + cur_len, 0, ROUND - n); - cur_len += ROUND - n; - } - /* add asus footer */ - if (asus.prod_id[0]) { - memcpy(buf + cur_len - sizeof(asus), &asus, sizeof(asus)); - } - - p->crc32 = crc32buf((char *) &p->flag_version, - cur_len - offsetof(struct trx_header, flag_version)); - p->crc32 = p->crc32; - - p->len = cur_len; - - if (!fwrite(buf, cur_len, 1, out) || fflush(out)) { - fprintf(stderr, "fwrite failed\n"); - return EXIT_FAILURE; - } - - fclose(out); - - return EXIT_SUCCESS; -} - -/**********************************************************************/ -/* The following was grabbed and tweaked from the old snippets collection - * of public domain C code. */ - -/**********************************************************************\ -|* Demonstration program to compute the 32-bit CRC used as the frame *| -|* check sequence in ADCCP (ANSI X3.66, also known as FIPS PUB 71 *| -|* and FED-STD-1003, the U.S. versions of CCITT's X.25 link-level *| -|* protocol). The 32-bit FCS was added via the Federal Register, *| -|* 1 June 1982, p.23798. I presume but don't know for certain that *| -|* this polynomial is or will be included in CCITT V.41, which *| -|* defines the 16-bit CRC (often called CRC-CCITT) polynomial. FIPS *| -|* PUB 78 says that the 32-bit FCS reduces otherwise undetected *| -|* errors by a factor of 10^-5 over 16-bit FCS. *| -\**********************************************************************/ - -/* Copyright (C) 1986 Gary S. Brown. You may use this program, or - code or tables extracted from it, as desired without restriction.*/ - -/* First, the polynomial itself and its table of feedback terms. The */ -/* polynomial is */ -/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */ -/* Note that we take it "backwards" and put the highest-order term in */ -/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */ -/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */ -/* the MSB being 1. */ - -/* Note that the usual hardware shift register implementation, which */ -/* is what we're using (we're merely optimizing it by doing eight-bit */ -/* chunks at a time) shifts bits into the lowest-order term. In our */ -/* implementation, that means shifting towards the right. Why do we */ -/* do it this way? Because the calculated CRC must be transmitted in */ -/* order from highest-order term to lowest-order term. UARTs transmit */ -/* characters in order from LSB to MSB. By storing the CRC this way, */ -/* we hand it to the UART in the order low-byte to high-byte; the UART */ -/* sends each low-bit to hight-bit; and the result is transmission bit */ -/* by bit from highest- to lowest-order term without requiring any bit */ -/* shuffling on our part. Reception works similarly. */ - -/* The feedback terms table consists of 256, 32-bit entries. Notes: */ -/* */ -/* 1. The table can be generated at runtime if desired; code to do so */ -/* is shown later. It might not be obvious, but the feedback */ -/* terms simply represent the results of eight shift/xor opera- */ -/* tions for all combinations of data and CRC register values. */ -/* */ -/* 2. The CRC accumulation logic is the same for all CRC polynomials, */ -/* be they sixteen or thirty-two bits wide. You simply choose the */ -/* appropriate table. Alternatively, because the table can be */ -/* generated at runtime, you can start by generating the table for */ -/* the polynomial in question and use exactly the same "updcrc", */ -/* if your application needn't simultaneously handle two CRC */ -/* polynomials. (Note, however, that XMODEM is strange.) */ -/* */ -/* 3. For 16-bit CRCs, the table entries need be only 16 bits wide; */ -/* of course, 32-bit entries work OK if the high 16 bits are zero. */ -/* */ -/* 4. The values must be right-shifted by eight bits by the "updcrc" */ -/* logic; the shift must be unsigned (bring in zeroes). On some */ -/* hardware you could probably optimize the shift in assembler by */ -/* using byte-swap instructions. */ - -static const uint32_t crc_32_tab[] = { /* CRC polynomial 0xedb88320 */ -0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, -0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, -0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, -0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, -0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, -0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, -0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, -0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, -0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, -0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, -0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, -0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, -0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, -0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, -0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, -0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, -0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, -0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, -0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, -0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, -0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, -0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, -0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, -0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, -0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, -0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, -0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, -0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, -0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, -0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, -0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, -0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, -0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, -0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, -0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, -0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, -0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, -0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, -0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, -0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, -0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, -0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, -0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d -}; - -#define UPDC32(octet,crc) (crc_32_tab[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8)) - -uint32_t crc32buf(char *buf, size_t len) -{ - uint32_t crc; - - crc = 0xFFFFFFFF; - - for ( ; len; --len, ++buf) - { - crc = UPDC32(*buf, crc); - } - - return crc; -} diff --git a/target/tools/xz/Makefile b/target/tools/xz/Makefile deleted file mode 100644 index 6cefbb476..000000000 --- a/target/tools/xz/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -# This file is part of the OpenADK project. OpenADK is copyrighted -# material, please see the LICENCE file in the top-level directory. - -include $(TOPDIR)/rules.mk - -PKG_NAME:= xz -PKG_VERSION:= 5.0.5 -PKG_RELEASE:= 1 -PKG_MD5SUM:= 1b7a781fb4cf8938842279bd3e8ee852 -PKG_SITES:= http://tukaani.org/xz/ - -include ../rules.mk - -all: $(WRKBUILD)/.installed - -$(WRKBUILD)/.configured: ${WRKDIST}/.prepared - (cd ${WRKBUILD}; ./configure --prefix=$(STAGING_HOST_DIR)/usr) - touch $@ - -$(WRKBUILD)/.compiled: $(WRKBUILD)/.configured - ${MAKE} -C ${WRKBUILD} - touch $@ - -$(WRKBUILD)/.installed: $(WRKBUILD)/.compiled - ${MAKE} -C ${WRKBUILD} install - touch $@ - -include $(TOPDIR)/mk/tools.mk diff --git a/toolchain/gcc/Makefile b/toolchain/gcc/Makefile index 2cd720a63..57053e067 100644 --- a/toolchain/gcc/Makefile +++ b/toolchain/gcc/Makefile @@ -98,8 +98,8 @@ ifeq ($(ADK_CPU_CORTEX_A9),y) GCC_CONFOPTS+= --with-arch=armv7-a --with-tune=cortex-a9 --with-fpu=neon endif -ifneq ($(ADK_TARGET_ABI),) -GCC_CONFOPTS+= --with-abi=${ADK_TARGET_ABI} +ifneq ($(ADK_TARGET_MIPS_ABI),) +GCC_CONFOPTS+= --with-abi=${ADK_TARGET_MIPS_ABI} endif ifeq (${ADK_MAKE_PARALLEL},y) diff --git a/tools/Makefile b/tools/Makefile index 4326dd4ab..2ffa4971c 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -3,13 +3,35 @@ include $(TOPDIR)/rules.mk -TARGETS:=adk mkcrypt cpio mkimage genext2fs bc -ifeq ($(ADK_TARGET_ROOTFS_ISO),y) -TARGETS+=cdrtools syslinux +TARGETS:=adk mkcrypt cpio bc bzip2 m4 xz + +ifeq ($(ADK_HOST_NEED_GENEXT2FS),y) +TARGETS+=genext2fs +endif +ifeq ($(ADK_HOST_NEED_MKIMAGE),y) +TARGETS+=mkimage +endif +ifeq ($(ADK_HOST_NEED_MKISOFS),y) +TARGETS+=cdrtools +endif +ifeq ($(ADK_HOST_NEED_SYSLINUX),y) +TARGETS+=syslinux endif -ifeq ($(ADK_TARGET_LIB_EGLIBC),y) +ifeq ($(ADK_HOST_NEED_GPERF),y) TARGETS+=gperf endif +ifeq ($(ADK_HOST_NEED_JFFS2),y) +TARGETS+=mtd-utils +endif +ifeq ($(ADK_HOST_NEED_SQUASHFS),y) +TARGETS+=squashfs +endif +ifeq ($(ADK_HOST_NEED_LZOP),y) +TARGETS+=lzo lzop +endif +ifeq ($(ADK_HOST_NEED_LZMA),y) +TARGETS+=lzma +endif TARGETS_INSTALL:=$(patsubst %,%-install,$(TARGETS)) TARGETS_CLEAN:=$(patsubst %,%-clean,$(TARGETS)) diff --git a/tools/addpattern/Makefile b/tools/addpattern/Makefile new file mode 100644 index 000000000..10ba05933 --- /dev/null +++ b/tools/addpattern/Makefile @@ -0,0 +1,4 @@ +include $(TOPDIR)/rules.mk + +all: addpattern.c + $(CC_FOR_BUILD) $(FLAGS_FOR_BUILD) -o ${STAGING_HOST_DIR}/usr/bin/addpattern addpattern.c diff --git a/tools/addpattern/addpattern.c b/tools/addpattern/addpattern.c new file mode 100644 index 000000000..8133bf26e --- /dev/null +++ b/tools/addpattern/addpattern.c @@ -0,0 +1,252 @@ +/* + * Copyright (C) 2004 Manuel Novoa III + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* July 29, 2004 + * + * This is a hacked replacement for the 'addpattern' utility used to + * create wrt54g .bin firmware files. It isn't pretty, but it does + * the job for me. + * + * Extensions: + * -v allows setting the version string on the command line. + * -{0|1} sets the (currently ignored) hw_ver flag in the header + * to 0 or 1 respectively. + */ + +/* January 12, 2005 + * + * Modified by rodent at rodent dot za dot net + * Support added for the new WRT54G v2.2 and WRT54GS v1.1 "flags" + * Without the flags set to 0x7, the above units will refuse to flash. + * + * Extensions: + * -{0|1|2} sets {0|1} sets hw_ver flag to 0/1. {2} sets hw_ver to 1 + * and adds the new hardware "flags" for the v2.2/v1.1 units +*/ + +/* January 1, 2007 + * + * Modified by juan.i.gonzalez at subdown dot net + * Support added for the AG241v2 and similar + * + * Extensions: + * -r #.# adds revision hardware flags. AG241v2 and similar. + * + * AG241V2 firmware sets the hw_ver to 0x44. + * + * Example: -r 2.0 + * + * Convert 2.0 to 20 to be an integer, and add 0x30 to skip special ASCII + * #define HW_Version ((HW_REV * 10) + 0x30) -> from cyutils.h +*/ + +#include +#include +#include +#include +#include +#include + +/**********************************************************************/ + +#define CODE_ID "U2ND" /* from code_pattern.h */ +#define CODE_PATTERN "W54S" /* from code_pattern.h */ +#define PBOT_PATTERN "PBOT" + +#define CYBERTAN_VERSION "v3.37.2" /* from cyutils.h */ + +/* WRT54G v2.2 and WRT54GS v1.1 "flags" (from 3.37.32 firmware cyutils.h) */ +#define SUPPORT_4712_CHIP 0x0001 +#define SUPPORT_INTEL_FLASH 0x0002 +#define SUPPORT_5325E_SWITCH 0x0004 + +struct code_header { /* from cyutils.h */ + char magic[4]; + char res1[4]; /* for extra magic */ + char fwdate[3]; + char fwvern[3]; + char id[4]; /* U2ND */ + char hw_ver; /* 0: for 4702, 1: for 4712 -- new in 2.04.3 */ + char unused; + unsigned char flags[2]; /* SUPPORT_ flags new for 3.37.2 (WRT54G v2.2 and WRT54GS v1.1) */ + unsigned char res2[10]; +} ; + +/**********************************************************************/ + +void usage(void) __attribute__ (( __noreturn__ )); + +void usage(void) +{ + fprintf(stderr, "Usage: addpattern [-i trxfile] [-o binfile] [-p pattern] [-g] [-b] [-v v#.#.#] [-r #.#] [-{0|1|2|4}] -h\n"); + exit(EXIT_FAILURE); +} + +int main(int argc, char **argv) +{ + char buf[1024]; /* keep this at 1k or adjust garbage calc below */ + struct code_header *hdr; + FILE *in = stdin; + FILE *out = stdout; + char *ifn = NULL; + char *ofn = NULL; + char *pattern = CODE_PATTERN; + char *pbotpat = PBOT_PATTERN; + char *version = CYBERTAN_VERSION; + int gflag = 0; + int pbotflag = 0; + int c; + int v0, v1, v2; + size_t off, n; + time_t t; + struct tm *ptm; + + hdr = (struct code_header *) buf; + memset(hdr, 0, sizeof(struct code_header)); + + while ((c = getopt(argc, argv, "i:o:p:gbv:0124hr:")) != -1) { + switch (c) { + case 'i': + ifn = optarg; + break; + case 'o': + ofn = optarg; + break; + case 'p': + pattern = optarg; + break; + case 'g': + gflag = 1; + break; + case 'b': + pbotflag = 1; + break; + case 'v': /* extension to allow setting version */ + version = optarg; + break; + case '0': + hdr->hw_ver = 0; + break; + case '1': + hdr->hw_ver = 1; + break; + case '2': /* new 54G v2.2 and 54GS v1.1 flags */ + hdr->hw_ver = 1; + hdr->flags[0] |= SUPPORT_4712_CHIP; + hdr->flags[0] |= SUPPORT_INTEL_FLASH; + hdr->flags[0] |= SUPPORT_5325E_SWITCH; + break; + case '4': + /* V4 firmware sets the flags to 0x1f */ + hdr->hw_ver = 0; + hdr->flags[0] = 0x1f; + break; + case 'r': + hdr->hw_ver = (char)(atof(optarg)*10)+0x30; + break; + + case 'h': + default: + usage(); + } + } + + if (optind != argc || optind == 1) { + fprintf(stderr, "illegal arg \"%s\"\n", argv[optind]); + usage(); + } + + if (strlen(pattern) != 4) { + fprintf(stderr, "illegal pattern \"%s\": length != 4\n", pattern); + usage(); + } + + if (ifn && !(in = fopen(ifn, "r"))) { + fprintf(stderr, "can not open \"%s\" for reading\n", ifn); + usage(); + } + + if (ofn && !(out = fopen(ofn, "w"))) { + fprintf(stderr, "can not open \"%s\" for writing\n", ofn); + usage(); + } + + if (time(&t) == (time_t)(-1)) { + fprintf(stderr, "time call failed\n"); + return EXIT_FAILURE; + } + + ptm = localtime(&t); + + if (3 != sscanf(version, "v%d.%d.%d", &v0, &v1, &v2)) { + fprintf(stderr, "bad version string \"%s\"\n", version); + return EXIT_FAILURE; + } + + memcpy(&hdr->magic, pattern, 4); + if (pbotflag) + memcpy(&hdr->res1, pbotpat, 4); + hdr->fwdate[0] = ptm->tm_year % 100; + hdr->fwdate[1] = ptm->tm_mon + 1; + hdr->fwdate[2] = ptm->tm_mday; + hdr->fwvern[0] = v0; + hdr->fwvern[1] = v1; + hdr->fwvern[2] = v2; + memcpy(&hdr->id, CODE_ID, strlen(CODE_ID)); + + off = sizeof(struct code_header); + + fprintf(stderr, "writing firmware v%d.%d.%d on %d/%d/%d (y/m/d)\n", + v0, v1, v2, + hdr->fwdate[0], hdr->fwdate[1], hdr->fwdate[2]); + + + while ((n = fread(buf + off, 1, sizeof(buf)-off, in) + off) > 0) { + off = 0; + if (n < sizeof(buf)) { + if (ferror(in)) { + FREAD_ERROR: + fprintf(stderr, "fread error\n"); + return EXIT_FAILURE; + } + if (gflag) { + gflag = sizeof(buf) - n; + memset(buf + n, 0xff, gflag); + n = sizeof(buf); + } + } + if (!fwrite(buf, n, 1, out)) { + FWRITE_ERROR: + fprintf(stderr, "fwrite error\n"); + return EXIT_FAILURE; + } + } + + if (ferror(in)) { + goto FREAD_ERROR; + } + + if (fflush(out)) { + goto FWRITE_ERROR; + } + + fclose(in); + fclose(out); + + return EXIT_SUCCESS; +} diff --git a/tools/adk/Makefile b/tools/adk/Makefile index 60a50ffba..edd559f85 100644 --- a/tools/adk/Makefile +++ b/tools/adk/Makefile @@ -3,15 +3,15 @@ include $(TOPDIR)/rules.mk -install: ${BIN_DIR}/depmaker ${BIN_DIR}/pkgrebuild ${BIN_DIR}/dkgetsz +install: ${STAGING_HOST_DIR}/usr/bin/depmaker ${STAGING_HOST_DIR}/usr/bin/pkgrebuild ${STAGING_HOST_DIR}/usr/bin/dkgetsz -${BIN_DIR}/depmaker: depmaker.c +${STAGING_HOST_DIR}/usr/bin/depmaker: depmaker.c ${CC_FOR_BUILD} ${FLAGS_FOR_BUILD} -o $@ depmaker.c -${BIN_DIR}/pkgrebuild: pkgrebuild.c strmap.c +${STAGING_HOST_DIR}/usr/bin/pkgrebuild: pkgrebuild.c strmap.c ${CC_FOR_BUILD} ${FLAGS_FOR_BUILD} -o $@ pkgrebuild.c strmap.c -${BIN_DIR}/dkgetsz: dkgetsz.c +${STAGING_HOST_DIR}/usr/bin/dkgetsz: dkgetsz.c ${CC_FOR_BUILD} ${FLAGS_FOR_BUILD} -o $@ dkgetsz.c include $(TOPDIR)/mk/tools.mk diff --git a/tools/bc/Makefile b/tools/bc/Makefile index 8d1561049..bb3c40492 100644 --- a/tools/bc/Makefile +++ b/tools/bc/Makefile @@ -11,15 +11,15 @@ PKG_SITES:= http://ftp.gnu.org/pub/gnu/bc/ include ../rules.mk -install: ${BIN_DIR}/bc +install: ${STAGING_HOST_DIR}/usr/bin/bc $(WRKBUILD)/.compiled: ${WRKDIST}/.prepared (cd ${WRKBUILD}; ./configure) ${MAKE} -C ${WRKBUILD} CC='${CC_FOR_BUILD}' touch $@ -${BIN_DIR}/bc: $(WRKBUILD)/.compiled +${STAGING_HOST_DIR}/usr/bin/bc: $(WRKBUILD)/.compiled $(INSTALL_BIN) $(WRKBUILD)/bc/bc \ - ${BIN_DIR} + ${STAGING_HOST_DIR}/usr/bin include $(TOPDIR)/mk/tools.mk diff --git a/tools/cdrtools/Makefile b/tools/cdrtools/Makefile index 6ea90b821..6522b5760 100644 --- a/tools/cdrtools/Makefile +++ b/tools/cdrtools/Makefile @@ -11,15 +11,15 @@ PKG_SITES:= ftp://ftp.berlios.de/pub/cdrecord/ include ../rules.mk -install: ${BIN_DIR}/mkisofs +install: ${STAGING_HOST_DIR}/usr/bin/mkisofs $(WRKBUILD)/.compiled: ${WRKDIST}/.prepared #(cd ${WRKBUILD}; ./configure) ${MAKE} -C ${WRKBUILD} CC='${CC_FOR_BUILD}' touch $@ -${BIN_DIR}/mkisofs: $(WRKBUILD)/.compiled +${STAGING_HOST_DIR}/usr/bin/mkisofs: $(WRKBUILD)/.compiled $(INSTALL_BIN) $(WRKBUILD)/mkisofs/OBJ/*/mkisofs \ - ${BIN_DIR} + ${STAGING_HOST_DIR}/usr/bin include $(TOPDIR)/mk/tools.mk diff --git a/tools/cpio/Makefile b/tools/cpio/Makefile index 290eabc8b..ffccd1480 100644 --- a/tools/cpio/Makefile +++ b/tools/cpio/Makefile @@ -3,7 +3,7 @@ include $(TOPDIR)/rules.mk -install: ${BIN_DIR}/cpio +install: ${STAGING_HOST_DIR}/usr/bin/cpio SRCS:= src/ib_open.c \ src/ib_close.c \ @@ -26,7 +26,7 @@ SRCS:= src/ib_open.c \ src/nonpax.c \ src/cpio.c -${BIN_DIR}/cpio: ${SRCS} +${STAGING_HOST_DIR}/usr/bin/cpio: ${SRCS} ${CC_FOR_BUILD} ${FLAGS_FOR_BUILD} -D_GNU_SOURCE -Isrc -o $@ $^ include $(TOPDIR)/mk/tools.mk diff --git a/tools/genext2fs/Makefile b/tools/genext2fs/Makefile index b19662941..07e24d028 100644 --- a/tools/genext2fs/Makefile +++ b/tools/genext2fs/Makefile @@ -11,15 +11,15 @@ PKG_SITES:= ${MASTER_SITE_SOURCEFORGE:=genext2fs/} include ../rules.mk -install: ${BIN_DIR}/genext2fs +install: ${STAGING_HOST_DIR}/usr/bin/genext2fs $(WRKBUILD)/.compiled: ${WRKDIST}/.prepared (cd ${WRKBUILD}; ./configure) ${MAKE} -C ${WRKBUILD} CC='${CC_FOR_BUILD}' touch $@ -${BIN_DIR}/genext2fs: $(WRKBUILD)/.compiled +${STAGING_HOST_DIR}/usr/bin/genext2fs: $(WRKBUILD)/.compiled $(INSTALL_BIN) $(WRKBUILD)/genext2fs \ - ${BIN_DIR} + ${STAGING_HOST_DIR}/usr/bin include $(TOPDIR)/mk/tools.mk diff --git a/tools/gperf/Makefile b/tools/gperf/Makefile index 7b0d0af77..7f7d6466d 100644 --- a/tools/gperf/Makefile +++ b/tools/gperf/Makefile @@ -11,15 +11,15 @@ PKG_SITES:= http://ftp.gnu.org/pub/gnu/gperf/ include ../rules.mk -install: ${BIN_DIR}/gperf +install: ${STAGING_HOST_DIR}/usr/bin/gperf $(WRKBUILD)/.compiled: ${WRKDIST}/.prepared (cd ${WRKBUILD}; ./configure) ${MAKE} -C ${WRKBUILD} CC='${CC_FOR_BUILD}' touch $@ -${BIN_DIR}/gperf: $(WRKBUILD)/.compiled +${STAGING_HOST_DIR}/usr/bin/gperf: $(WRKBUILD)/.compiled $(INSTALL_BIN) $(WRKBUILD)/src/gperf \ - ${BIN_DIR} + ${STAGING_HOST_DIR}/usr/bin include $(TOPDIR)/mk/tools.mk diff --git a/tools/lzma-loader/.svn/entries b/tools/lzma-loader/.svn/entries new file mode 100644 index 000000000..2934ab892 --- /dev/null +++ b/tools/lzma-loader/.svn/entries @@ -0,0 +1,300 @@ +10 + +dir +29646 +svn://svn.openwrt.org/openwrt/trunk/target/linux/brcm47xx/image/lzma-loader/src +svn://svn.openwrt.org/openwrt + + + +2010-12-02T21:27:54.805904Z +24217 +hauke + + + + + + + + + + + + + + +3c298f89-4303-0410-b956-a3cf2f4a3e73 + +head.S +file + + + + +2011-11-10T10:12:04.000000Z +566bfb5f462e85d45d1d0c4faca0dadd +2010-06-26T20:41:49.877730Z +21945 +nbd + + + + + + + + + + + + + + + + + + + + + +3585 + +decompress.c +file + + + + +2011-11-10T10:12:04.000000Z +b9ae9d76bf7f1f35ce46b5e496a02aa1 +2010-12-02T21:27:54.805904Z +24217 +hauke + + + + + + + + + + + + + + + + + + + + + +5426 + +LzmaDecode.c +file + + + + +2011-11-10T10:12:04.000000Z +14403972ddbcfadbe017a6aeb3e8fae1 +2010-06-26T20:41:49.877730Z +21945 +nbd + + + + + + + + + + + + + + + + + + + + + +17104 + +decompress.lds.in +file + + + + +2011-11-10T10:12:04.000000Z +c80cc6ad34b26e0af3c1d764218a3a61 +2010-06-26T20:41:49.877730Z +21945 +nbd + + + + + + + + + + + + + + + + + + + + + +186 + +loader.lds.in +file + + + + +2011-11-10T10:12:04.000000Z +f06b23d31242fb56a60b864b741c1266 +2010-06-26T20:41:49.877730Z +21945 +nbd + + + + + + + + + + + + + + + + + + + + + +151 + +LzmaDecode.h +file + + + + +2011-11-10T10:12:04.000000Z +12fcb710de789e54587079c021ae5e33 +2010-06-26T20:41:49.877730Z +21945 +nbd + + + + + + + + + + + + + + + + + + + + + +2465 + +Makefile +file + + + + +2011-11-10T10:12:04.000000Z +61400e27cb7c0099046d83e2146e0053 +2010-06-26T20:41:49.877730Z +21945 +nbd + + + + + + + + + + + + + + + + + + + + + +2325 + +README +file + + + + +2011-11-10T10:12:04.000000Z +b29e81088cc18e92dede243f094c4134 +2010-06-26T20:41:49.877730Z +21945 +nbd + + + + + + + + + + + + + + + + + + + + + +2464 + diff --git a/tools/lzma-loader/.svn/text-base/LzmaDecode.c.svn-base b/tools/lzma-loader/.svn/text-base/LzmaDecode.c.svn-base new file mode 100644 index 000000000..951700bdd --- /dev/null +++ b/tools/lzma-loader/.svn/text-base/LzmaDecode.c.svn-base @@ -0,0 +1,663 @@ +/* + LzmaDecode.c + LZMA Decoder + + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25) + http://www.7-zip.org/ + + LZMA SDK is licensed under two licenses: + 1) GNU Lesser General Public License (GNU LGPL) + 2) Common Public License (CPL) + It means that you can select one of these two licenses and + follow rules of that license. + + SPECIAL EXCEPTION: + Igor Pavlov, as the author of this code, expressly permits you to + statically or dynamically link your code (or bind by name) to the + interfaces of this file without subjecting your linked code to the + terms of the CPL or GNU LGPL. Any modifications or additions + to this file, however, are subject to the LGPL or CPL terms. +*/ + +#include "LzmaDecode.h" + +#ifndef Byte +#define Byte unsigned char +#endif + +#define kNumTopBits 24 +#define kTopValue ((UInt32)1 << kNumTopBits) + +#define kNumBitModelTotalBits 11 +#define kBitModelTotal (1 << kNumBitModelTotalBits) +#define kNumMoveBits 5 + +typedef struct _CRangeDecoder +{ + Byte *Buffer; + Byte *BufferLim; + UInt32 Range; + UInt32 Code; + #ifdef _LZMA_IN_CB + ILzmaInCallback *InCallback; + int Result; + #endif + int ExtraBytes; +} CRangeDecoder; + +Byte RangeDecoderReadByte(CRangeDecoder *rd) +{ + if (rd->Buffer == rd->BufferLim) + { + #ifdef _LZMA_IN_CB + UInt32 size; + rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size); + rd->BufferLim = rd->Buffer + size; + if (size == 0) + #endif + { + rd->ExtraBytes = 1; + return 0xFF; + } + } + return (*rd->Buffer++); +} + +/* #define ReadByte (*rd->Buffer++) */ +#define ReadByte (RangeDecoderReadByte(rd)) + +void RangeDecoderInit(CRangeDecoder *rd, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback + #else + Byte *stream, UInt32 bufferSize + #endif + ) +{ + int i; + #ifdef _LZMA_IN_CB + rd->InCallback = inCallback; + rd->Buffer = rd->BufferLim = 0; + #else + rd->Buffer = stream; + rd->BufferLim = stream + bufferSize; + #endif + rd->ExtraBytes = 0; + rd->Code = 0; + rd->Range = (0xFFFFFFFF); + for(i = 0; i < 5; i++) + rd->Code = (rd->Code << 8) | ReadByte; +} + +#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code; +#define RC_FLUSH_VAR rd->Range = range; rd->Code = code; +#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; } + +UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits) +{ + RC_INIT_VAR + UInt32 result = 0; + int i; + for (i = numTotalBits; i > 0; i--) + { + /* UInt32 t; */ + range >>= 1; + + result <<= 1; + if (code >= range) + { + code -= range; + result |= 1; + } + /* + t = (code - range) >> 31; + t &= 1; + code -= range & (t - 1); + result = (result + result) | (1 - t); + */ + RC_NORMALIZE + } + RC_FLUSH_VAR + return result; +} + +int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd) +{ + UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob; + if (rd->Code < bound) + { + rd->Range = bound; + *prob += (kBitModelTotal - *prob) >> kNumMoveBits; + if (rd->Range < kTopValue) + { + rd->Code = (rd->Code << 8) | ReadByte; + rd->Range <<= 8; + } + return 0; + } + else + { + rd->Range -= bound; + rd->Code -= bound; + *prob -= (*prob) >> kNumMoveBits; + if (rd->Range < kTopValue) + { + rd->Code = (rd->Code << 8) | ReadByte; + rd->Range <<= 8; + } + return 1; + } +} + +#define RC_GET_BIT2(prob, mi, A0, A1) \ + UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \ + if (code < bound) \ + { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \ + else \ + { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \ + RC_NORMALIZE + +#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;) + +int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd) +{ + int mi = 1; + int i; + #ifdef _LZMA_LOC_OPT + RC_INIT_VAR + #endif + for(i = numLevels; i > 0; i--) + { + #ifdef _LZMA_LOC_OPT + CProb *prob = probs + mi; + RC_GET_BIT(prob, mi) + #else + mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd); + #endif + } + #ifdef _LZMA_LOC_OPT + RC_FLUSH_VAR + #endif + return mi - (1 << numLevels); +} + +int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd) +{ + int mi = 1; + int i; + int symbol = 0; + #ifdef _LZMA_LOC_OPT + RC_INIT_VAR + #endif + for(i = 0; i < numLevels; i++) + { + #ifdef _LZMA_LOC_OPT + CProb *prob = probs + mi; + RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i)) + #else + int bit = RangeDecoderBitDecode(probs + mi, rd); + mi = mi + mi + bit; + symbol |= (bit << i); + #endif + } + #ifdef _LZMA_LOC_OPT + RC_FLUSH_VAR + #endif + return symbol; +} + +Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd) +{ + int symbol = 1; + #ifdef _LZMA_LOC_OPT + RC_INIT_VAR + #endif + do + { + #ifdef _LZMA_LOC_OPT + CProb *prob = probs + symbol; + RC_GET_BIT(prob, symbol) + #else + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd); + #endif + } + while (symbol < 0x100); + #ifdef _LZMA_LOC_OPT + RC_FLUSH_VAR + #endif + return symbol; +} + +Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte) +{ + int symbol = 1; + #ifdef _LZMA_LOC_OPT + RC_INIT_VAR + #endif + do + { + int bit; + int matchBit = (matchByte >> 7) & 1; + matchByte <<= 1; + #ifdef _LZMA_LOC_OPT + { + CProb *prob = probs + ((1 + matchBit) << 8) + symbol; + RC_GET_BIT2(prob, symbol, bit = 0, bit = 1) + } + #else + bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd); + symbol = (symbol << 1) | bit; + #endif + if (matchBit != bit) + { + while (symbol < 0x100) + { + #ifdef _LZMA_LOC_OPT + CProb *prob = probs + symbol; + RC_GET_BIT(prob, symbol) + #else + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd); + #endif + } + break; + } + } + while (symbol < 0x100); + #ifdef _LZMA_LOC_OPT + RC_FLUSH_VAR + #endif + return symbol; +} + +#define kNumPosBitsMax 4 +#define kNumPosStatesMax (1 << kNumPosBitsMax) + +#define kLenNumLowBits 3 +#define kLenNumLowSymbols (1 << kLenNumLowBits) +#define kLenNumMidBits 3 +#define kLenNumMidSymbols (1 << kLenNumMidBits) +#define kLenNumHighBits 8 +#define kLenNumHighSymbols (1 << kLenNumHighBits) + +#define LenChoice 0 +#define LenChoice2 (LenChoice + 1) +#define LenLow (LenChoice2 + 1) +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) +#define kNumLenProbs (LenHigh + kLenNumHighSymbols) + +int LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState) +{ + if(RangeDecoderBitDecode(p + LenChoice, rd) == 0) + return RangeDecoderBitTreeDecode(p + LenLow + + (posState << kLenNumLowBits), kLenNumLowBits, rd); + if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0) + return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid + + (posState << kLenNumMidBits), kLenNumMidBits, rd); + return kLenNumLowSymbols + kLenNumMidSymbols + + RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd); +} + +#define kNumStates 12 + +#define kStartPosModelIndex 4 +#define kEndPosModelIndex 14 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) + +#define kNumPosSlotBits 6 +#define kNumLenToPosStates 4 + +#define kNumAlignBits 4 +#define kAlignTableSize (1 << kNumAlignBits) + +#define kMatchMinLen 2 + +#define IsMatch 0 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) +#define IsRepG0 (IsRep + kNumStates) +#define IsRepG1 (IsRepG0 + kNumStates) +#define IsRepG2 (IsRepG1 + kNumStates) +#define IsRep0Long (IsRepG2 + kNumStates) +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) +#define LenCoder (Align + kAlignTableSize) +#define RepLenCoder (LenCoder + kNumLenProbs) +#define Literal (RepLenCoder + kNumLenProbs) + +#if Literal != LZMA_BASE_SIZE +StopCompilingDueBUG +#endif + +#ifdef _LZMA_OUT_READ + +typedef struct _LzmaVarState +{ + CRangeDecoder RangeDecoder; + Byte *Dictionary; + UInt32 DictionarySize; + UInt32 DictionaryPos; + UInt32 GlobalPos; + UInt32 Reps[4]; + int lc; + int lp; + int pb; + int State; + int PreviousIsMatch; + int RemainLen; +} LzmaVarState; + +int LzmaDecoderInit( + unsigned char *buffer, UInt32 bufferSize, + int lc, int lp, int pb, + unsigned char *dictionary, UInt32 dictionarySize, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback + #else + unsigned char *inStream, UInt32 inSize + #endif + ) +{ + LzmaVarState *vs = (LzmaVarState *)buffer; + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState)); + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp)); + UInt32 i; + if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState)) + return LZMA_RESULT_NOT_ENOUGH_MEM; + vs->Dictionary = dictionary; + vs->DictionarySize = dictionarySize; + vs->DictionaryPos = 0; + vs->GlobalPos = 0; + vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1; + vs->lc = lc; + vs->lp = lp; + vs->pb = pb; + vs->State = 0; + vs->PreviousIsMatch = 0; + vs->RemainLen = 0; + dictionary[dictionarySize - 1] = 0; + for (i = 0; i < numProbs; i++) + p[i] = kBitModelTotal >> 1; + RangeDecoderInit(&vs->RangeDecoder, + #ifdef _LZMA_IN_CB + inCallback + #else + inStream, inSize + #endif + ); + return LZMA_RESULT_OK; +} + +int LzmaDecode(unsigned char *buffer, + unsigned char *outStream, UInt32 outSize, + UInt32 *outSizeProcessed) +{ + LzmaVarState *vs = (LzmaVarState *)buffer; + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState)); + CRangeDecoder rd = vs->RangeDecoder; + int state = vs->State; + int previousIsMatch = vs->PreviousIsMatch; + Byte previousByte; + UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3]; + UInt32 nowPos = 0; + UInt32 posStateMask = (1 << (vs->pb)) - 1; + UInt32 literalPosMask = (1 << (vs->lp)) - 1; + int lc = vs->lc; + int len = vs->RemainLen; + UInt32 globalPos = vs->GlobalPos; + + Byte *dictionary = vs->Dictionary; + UInt32 dictionarySize = vs->DictionarySize; + UInt32 dictionaryPos = vs->DictionaryPos; + + if (len == -1) + { + *outSizeProcessed = 0; + return LZMA_RESULT_OK; + } + + while(len > 0 && nowPos < outSize) + { + UInt32 pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos]; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + len--; + } + if (dictionaryPos == 0) + previousByte = dictionary[dictionarySize - 1]; + else + previousByte = dictionary[dictionaryPos - 1]; +#else + +int LzmaDecode( + Byte *buffer, UInt32 bufferSize, + int lc, int lp, int pb, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback, + #else + unsigned char *inStream, UInt32 inSize, + #endif + unsigned char *outStream, UInt32 outSize, + UInt32 *outSizeProcessed) +{ + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp)); + CProb *p = (CProb *)buffer; + CRangeDecoder rd; + UInt32 i; + int state = 0; + int previousIsMatch = 0; + Byte previousByte = 0; + UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; + UInt32 nowPos = 0; + UInt32 posStateMask = (1 << pb) - 1; + UInt32 literalPosMask = (1 << lp) - 1; + int len = 0; + if (bufferSize < numProbs * sizeof(CProb)) + return LZMA_RESULT_NOT_ENOUGH_MEM; + for (i = 0; i < numProbs; i++) + p[i] = kBitModelTotal >> 1; + RangeDecoderInit(&rd, + #ifdef _LZMA_IN_CB + inCallback + #else + inStream, inSize + #endif + ); +#endif + + *outSizeProcessed = 0; + while(nowPos < outSize) + { + int posState = (int)( + (nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + & posStateMask); + #ifdef _LZMA_IN_CB + if (rd.Result != LZMA_RESULT_OK) + return rd.Result; + #endif + if (rd.ExtraBytes != 0) + return LZMA_RESULT_DATA_ERROR; + if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0) + { + CProb *probs = p + Literal + (LZMA_LIT_SIZE * + ((( + (nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + & literalPosMask) << lc) + (previousByte >> (8 - lc)))); + + if (state < 4) state = 0; + else if (state < 10) state -= 3; + else state -= 6; + if (previousIsMatch) + { + Byte matchByte; + #ifdef _LZMA_OUT_READ + UInt32 pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + matchByte = dictionary[pos]; + #else + matchByte = outStream[nowPos - rep0]; + #endif + previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte); + previousIsMatch = 0; + } + else + previousByte = LzmaLiteralDecode(probs, &rd); + outStream[nowPos++] = previousByte; + #ifdef _LZMA_OUT_READ + dictionary[dictionaryPos] = previousByte; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + #endif + } + else + { + previousIsMatch = 1; + if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1) + { + if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0) + { + if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0) + { + #ifdef _LZMA_OUT_READ + UInt32 pos; + #endif + if ( + (nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + == 0) + return LZMA_RESULT_DATA_ERROR; + state = state < 7 ? 9 : 11; + #ifdef _LZMA_OUT_READ + pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + previousByte = dictionary[pos]; + dictionary[dictionaryPos] = previousByte; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + #else + previousByte = outStream[nowPos - rep0]; + #endif + outStream[nowPos++] = previousByte; + continue; + } + } + else + { + UInt32 distance; + if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0) + distance = rep1; + else + { + if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0) + distance = rep2; + else + { + distance = rep3; + rep3 = rep2; + } + rep2 = rep1; + } + rep1 = rep0; + rep0 = distance; + } + len = LzmaLenDecode(p + RepLenCoder, &rd, posState); + state = state < 7 ? 8 : 11; + } + else + { + int posSlot; + rep3 = rep2; + rep2 = rep1; + rep1 = rep0; + state = state < 7 ? 7 : 10; + len = LzmaLenDecode(p + LenCoder, &rd, posState); + posSlot = RangeDecoderBitTreeDecode(p + PosSlot + + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << + kNumPosSlotBits), kNumPosSlotBits, &rd); + if (posSlot >= kStartPosModelIndex) + { + int numDirectBits = ((posSlot >> 1) - 1); + rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits); + if (posSlot < kEndPosModelIndex) + { + rep0 += RangeDecoderReverseBitTreeDecode( + p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd); + } + else + { + rep0 += RangeDecoderDecodeDirectBits(&rd, + numDirectBits - kNumAlignBits) << kNumAlignBits; + rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd); + } + } + else + rep0 = posSlot; + rep0++; + } + if (rep0 == (UInt32)(0)) + { + /* it's for stream version */ + len = -1; + break; + } + if (rep0 > nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + { + return LZMA_RESULT_DATA_ERROR; + } + len += kMatchMinLen; + do + { + #ifdef _LZMA_OUT_READ + UInt32 pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + previousByte = dictionary[pos]; + dictionary[dictionaryPos] = previousByte; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + #else + previousByte = outStream[nowPos - rep0]; + #endif + outStream[nowPos++] = previousByte; + len--; + } + while(len > 0 && nowPos < outSize); + } + } + + #ifdef _LZMA_OUT_READ + vs->RangeDecoder = rd; + vs->DictionaryPos = dictionaryPos; + vs->GlobalPos = globalPos + nowPos; + vs->Reps[0] = rep0; + vs->Reps[1] = rep1; + vs->Reps[2] = rep2; + vs->Reps[3] = rep3; + vs->State = state; + vs->PreviousIsMatch = previousIsMatch; + vs->RemainLen = len; + #endif + + *outSizeProcessed = nowPos; + return LZMA_RESULT_OK; +} diff --git a/tools/lzma-loader/.svn/text-base/LzmaDecode.h.svn-base b/tools/lzma-loader/.svn/text-base/LzmaDecode.h.svn-base new file mode 100644 index 000000000..f58944e3c --- /dev/null +++ b/tools/lzma-loader/.svn/text-base/LzmaDecode.h.svn-base @@ -0,0 +1,100 @@ +/* + LzmaDecode.h + LZMA Decoder interface + + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25) + http://www.7-zip.org/ + + LZMA SDK is licensed under two licenses: + 1) GNU Lesser General Public License (GNU LGPL) + 2) Common Public License (CPL) + It means that you can select one of these two licenses and + follow rules of that license. + + SPECIAL EXCEPTION: + Igor Pavlov, as the author of this code, expressly permits you to + statically or dynamically link your code (or bind by name) to the + interfaces of this file without subjecting your linked code to the + terms of the CPL or GNU LGPL. Any modifications or additions + to this file, however, are subject to the LGPL or CPL terms. +*/ + +#ifndef __LZMADECODE_H +#define __LZMADECODE_H + +/* #define _LZMA_IN_CB */ +/* Use callback for input data */ + +/* #define _LZMA_OUT_READ */ +/* Use read function for output data */ + +/* #define _LZMA_PROB32 */ +/* It can increase speed on some 32-bit CPUs, + but memory usage will be doubled in that case */ + +/* #define _LZMA_LOC_OPT */ +/* Enable local speed optimizations inside code */ + +#ifndef UInt32 +#ifdef _LZMA_UINT32_IS_ULONG +#define UInt32 unsigned long +#else +#define UInt32 unsigned int +#endif +#endif + +#ifdef _LZMA_PROB32 +#define CProb UInt32 +#else +#define CProb unsigned short +#endif + +#define LZMA_RESULT_OK 0 +#define LZMA_RESULT_DATA_ERROR 1 +#define LZMA_RESULT_NOT_ENOUGH_MEM 2 + +#ifdef _LZMA_IN_CB +typedef struct _ILzmaInCallback +{ + int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize); +} ILzmaInCallback; +#endif + +#define LZMA_BASE_SIZE 1846 +#define LZMA_LIT_SIZE 768 + +/* +bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb) +bufferSize += 100 in case of _LZMA_OUT_READ +by default CProb is unsigned short, +but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int) +*/ + +#ifdef _LZMA_OUT_READ +int LzmaDecoderInit( + unsigned char *buffer, UInt32 bufferSize, + int lc, int lp, int pb, + unsigned char *dictionary, UInt32 dictionarySize, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback + #else + unsigned char *inStream, UInt32 inSize + #endif +); +#endif + +int LzmaDecode( + unsigned char *buffer, + #ifndef _LZMA_OUT_READ + UInt32 bufferSize, + int lc, int lp, int pb, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback, + #else + unsigned char *inStream, UInt32 inSize, + #endif + #endif + unsigned char *outStream, UInt32 outSize, + UInt32 *outSizeProcessed); + +#endif diff --git a/tools/lzma-loader/.svn/text-base/Makefile.svn-base b/tools/lzma-loader/.svn/text-base/Makefile.svn-base new file mode 100644 index 000000000..3320e565d --- /dev/null +++ b/tools/lzma-loader/.svn/text-base/Makefile.svn-base @@ -0,0 +1,77 @@ +# +# Makefile for Broadcom BCM947XX boards +# +# Copyright 2001-2003, Broadcom Corporation +# All Rights Reserved. +# +# THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY +# KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM +# SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE. +# +# Copyright 2004 Manuel Novoa III +# Modified to support bzip'd kernels. +# Of course, it would be better to integrate bunzip capability into CFE. +# +# Copyright 2005 Oleg I. Vdovikin +# Cleaned up, modified for lzma support, removed from kernel +# + +TEXT_START := 0x80001000 +BZ_TEXT_START := 0x80400000 + +OBJCOPY := $(CROSS_COMPILE)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S + +CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \ + -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 -mno-abicalls -fno-pic \ + -ffunction-sections -pipe -mlong-calls -fno-common \ + -mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap +CFLAGS += -DLOADADDR=$(TEXT_START) -D_LZMA_IN_CB + +ASFLAGS = $(CFLAGS) -D__ASSEMBLY__ -DBZ_TEXT_START=$(BZ_TEXT_START) + +SEDFLAGS := s/BZ_TEXT_START/$(BZ_TEXT_START)/;s/TEXT_START/$(TEXT_START)/ + +OBJECTS := head.o data.o + +all: loader.gz loader.elf + +# Don't build dependencies, this may die if $(CC) isn't gcc +dep: + +install: + +loader.gz: loader + gzip -nc9 $< > $@ + +loader.elf: loader.o + cp $< $@ + +loader: loader.o + $(OBJCOPY) $< $@ + +loader.o: loader.lds $(OBJECTS) + $(LD) -static --gc-sections -no-warn-mismatch -T loader.lds -o $@ $(OBJECTS) + +loader.lds: loader.lds.in Makefile + @sed "$(SEDFLAGS)" < $< > $@ + +data.o: data.lds decompress.image + $(LD) -no-warn-mismatch -T data.lds -r -o $@ -b binary decompress.image -b elf32-tradlittlemips + +data.lds: + @echo "SECTIONS { .data : { code_start = .; *(.data) code_stop = .; }}" > $@ + +decompress.image: decompress + $(OBJCOPY) $< $@ + +decompress: decompress.lds decompress.o LzmaDecode.o + $(LD) -static --gc-sections -no-warn-mismatch -T decompress.lds -o $@ decompress.o LzmaDecode.o + +decompress.lds: decompress.lds.in Makefile + @sed "$(SEDFLAGS)" < $< > $@ + +mrproper: clean + +clean: + rm -f loader.gz loader decompress *.lds *.o *.image diff --git a/tools/lzma-loader/.svn/text-base/README.svn-base b/tools/lzma-loader/.svn/text-base/README.svn-base new file mode 100644 index 000000000..16649e950 --- /dev/null +++ b/tools/lzma-loader/.svn/text-base/README.svn-base @@ -0,0 +1,55 @@ +/* + * LZMA compressed kernel decompressor for bcm947xx boards + * + * Copyright (C) 2005 by Oleg I. Vdovikin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +The code is intended to decompress kernel, being compressed using lzma utility +build using 7zip LZMA SDK. This utility is located in the LZMA_Alone directory + +decompressor code expects that your .trx file consist of three partitions: + +1) decompressor itself (this is gziped code which pmon/cfe will extract and run +on boot-up instead of real kernel) +2) LZMA compressed kernel (both streamed and regular modes are supported now) +3) Root filesystem + +Please be sure to apply the following patch for use this new trx layout (it will +allow using both new and old trx files for root filesystem lookup code) + +--- linuz/arch/mips/brcm-boards/bcm947xx/setup.c 2005-01-23 19:24:27.503322896 +0300 ++++ linux/arch/mips/brcm-boards/bcm947xx/setup.c 2005-01-23 19:29:05.237100944 +0300 +@@ -221,7 +221,9 @@ + /* Try looking at TRX header for rootfs offset */ + if (le32_to_cpu(trx->magic) == TRX_MAGIC) { + bcm947xx_parts[1].offset = off; +- if (le32_to_cpu(trx->offsets[1]) > off) ++ if (le32_to_cpu(trx->offsets[2]) > off) ++ off = le32_to_cpu(trx->offsets[2]); ++ else if (le32_to_cpu(trx->offsets[1]) > off) + off = le32_to_cpu(trx->offsets[1]); + continue; + } + + +Revision history: + 0.02 Initial release + 0.03 Added Mineharu Takahara patch to pass actual + output size to decoder (stream mode compressed input is not + a requirement anymore) + 0.04 Reordered functions using lds script diff --git a/tools/lzma-loader/.svn/text-base/decompress.c.svn-base b/tools/lzma-loader/.svn/text-base/decompress.c.svn-base new file mode 100644 index 000000000..05681b152 --- /dev/null +++ b/tools/lzma-loader/.svn/text-base/decompress.c.svn-base @@ -0,0 +1,186 @@ +/* + * LZMA compressed kernel decompressor for bcm947xx boards + * + * Copyright (C) 2005 by Oleg I. Vdovikin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Please note, this was code based on the bunzip2 decompressor code + * by Manuel Novoa III (mjn3@codepoet.org), although the only thing left + * is an idea and part of original vendor code + * + * + * 12-Mar-2005 Mineharu Takahara + * pass actual output size to decoder (stream mode + * compressed input is not a requirement anymore) + * + * 24-Apr-2005 Oleg I. Vdovikin + * reordered functions using lds script, removed forward decl + * + */ + +#include "LzmaDecode.h" + +#define BCM4710_FLASH 0x1fc00000 /* Flash */ + +#define KSEG0 0x80000000 +#define KSEG1 0xa0000000 + +#define KSEG1ADDR(a) ((((unsigned)(a)) & 0x1fffffffU) | KSEG1) + +#define Index_Invalidate_I 0x00 +#define Index_Writeback_Inv_D 0x01 + +#define cache_unroll(base,op) \ + __asm__ __volatile__( \ + ".set noreorder;\n" \ + ".set mips3;\n" \ + "cache %1, (%0);\n" \ + ".set mips0;\n" \ + ".set reorder\n" \ + : \ + : "r" (base), \ + "i" (op)); + +static __inline__ void blast_icache(unsigned long size, unsigned long lsize) +{ + unsigned long start = KSEG0; + unsigned long end = (start + size); + + while(start < end) { + cache_unroll(start,Index_Invalidate_I); + start += lsize; + } +} + +static __inline__ void blast_dcache(unsigned long size, unsigned long lsize) +{ + unsigned long start = KSEG0; + unsigned long end = (start + size); + + while(start < end) { + cache_unroll(start,Index_Writeback_Inv_D); + start += lsize; + } +} + +#define TRX_MAGIC 0x30524448 /* "HDR0" */ + +struct trx_header { + unsigned int magic; /* "HDR0" */ + unsigned int len; /* Length of file including header */ + unsigned int crc32; /* 32-bit CRC from flag_version to end of file */ + unsigned int flag_version; /* 0:15 flags, 16:31 version */ + 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[]; + +unsigned int offset; +unsigned char *data; + +/* flash access should be aligned, so wrapper is used */ +/* read byte from the flash, all accesses are 32-bit aligned */ +static int read_byte(void *object, unsigned char **buffer, UInt32 *bufferSize) +{ + static unsigned int val; + + if (((unsigned int)offset % 4) == 0) { + val = *(unsigned int *)data; + data += 4; + } + + *bufferSize = 1; + *buffer = ((unsigned char *)&val) + (offset++ & 3); + + return LZMA_RESULT_OK; +} + +static __inline__ unsigned char get_byte(void) +{ + unsigned char *buffer; + UInt32 fake; + + return read_byte(0, &buffer, &fake), *buffer; +} + +/* should be the first function */ +void entry(unsigned long icache_size, unsigned long icache_lsize, + unsigned long dcache_size, unsigned long dcache_lsize, + unsigned long fw_arg0, unsigned long fw_arg1, + unsigned long fw_arg2, unsigned long fw_arg3) +{ + unsigned int i; /* temp value */ + unsigned int lc; /* literal context bits */ + unsigned int lp; /* literal pos state bits */ + unsigned int pb; /* pos state bits */ + unsigned int osize; /* uncompressed size */ + + ILzmaInCallback callback; + callback.Read = read_byte; + + /* look for trx header, 32-bit data access */ + for (data = ((unsigned char *) KSEG1ADDR(BCM4710_FLASH)); + ((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]; + else + data += ((struct trx_header *)data)->offsets[1]; + + offset = 0; + + /* lzma args */ + i = get_byte(); + lc = i % 9, i = i / 9; + lp = i % 5, pb = i / 5; + + /* skip rest of the LZMA coder property */ + for (i = 0; i < 4; i++) + get_byte(); + + /* read the lower half of uncompressed size in the header */ + osize = ((unsigned int)get_byte()) + + ((unsigned int)get_byte() << 8) + + ((unsigned int)get_byte() << 16) + + ((unsigned int)get_byte() << 24); + + /* skip rest of the header (upper half of uncompressed size) */ + for (i = 0; i < 4; i++) + get_byte(); + + /* decompress kernel */ + if (LzmaDecode(workspace, ~0, lc, lp, pb, &callback, + (unsigned char*)LOADADDR, osize, &i) == LZMA_RESULT_OK) + { + blast_dcache(dcache_size, dcache_lsize); + blast_icache(icache_size, icache_lsize); + + /* Jump to load address */ + ((void (*)(unsigned long, unsigned long, unsigned long, + unsigned long)) LOADADDR)(fw_arg0, fw_arg1, fw_arg2, + fw_arg3); + } +} diff --git a/tools/lzma-loader/.svn/text-base/decompress.lds.in.svn-base b/tools/lzma-loader/.svn/text-base/decompress.lds.in.svn-base new file mode 100644 index 000000000..33f56f8a0 --- /dev/null +++ b/tools/lzma-loader/.svn/text-base/decompress.lds.in.svn-base @@ -0,0 +1,20 @@ +OUTPUT_ARCH(mips) +ENTRY(entry) +SECTIONS { + . = BZ_TEXT_START; + .text : { + *(.text.entry) + *(.text) + *(.rodata) + } + + .data : { + *(.data) + } + + .bss : { + *(.bss) + } + + workspace = .; +} diff --git a/tools/lzma-loader/.svn/text-base/head.S.svn-base b/tools/lzma-loader/.svn/text-base/head.S.svn-base new file mode 100644 index 000000000..3a33e4016 --- /dev/null +++ b/tools/lzma-loader/.svn/text-base/head.S.svn-base @@ -0,0 +1,160 @@ +/* Copyright 2005 Oleg I. Vdovikin (oleg@cs.msu.su) */ +/* cache manipulation adapted from Broadcom code */ +/* idea taken from original bunzip2 decompressor code */ +/* Copyright 2004 Manuel Novoa III (mjn3@codepoet.org) */ +/* Licensed under the linux kernel's version of the GPL.*/ + +#include +#include + +#define KSEG0 0x80000000 + +#define C0_CONFIG $16 +#define C0_TAGLO $28 +#define C0_TAGHI $29 + +#define CONF1_DA_SHIFT 7 /* D$ associativity */ +#define CONF1_DA_MASK 0x00000380 +#define CONF1_DA_BASE 1 +#define CONF1_DL_SHIFT 10 /* D$ line size */ +#define CONF1_DL_MASK 0x00001c00 +#define CONF1_DL_BASE 2 +#define CONF1_DS_SHIFT 13 /* D$ sets/way */ +#define CONF1_DS_MASK 0x0000e000 +#define CONF1_DS_BASE 64 +#define CONF1_IA_SHIFT 16 /* I$ associativity */ +#define CONF1_IA_MASK 0x00070000 +#define CONF1_IA_BASE 1 +#define CONF1_IL_SHIFT 19 /* I$ line size */ +#define CONF1_IL_MASK 0x00380000 +#define CONF1_IL_BASE 2 +#define CONF1_IS_SHIFT 22 /* Instruction cache sets/way */ +#define CONF1_IS_MASK 0x01c00000 +#define CONF1_IS_BASE 64 + +#define Index_Invalidate_I 0x00 +#define Index_Writeback_Inv_D 0x01 + + .text + LEAF(startup) + .set noreorder + addi sp, -48 + sw a0, 16(sp) + sw a1, 20(sp) + sw a2, 24(sp) + sw a3, 28(sp) + + /* Copy decompressor code to the right place */ + li t2, BZ_TEXT_START + add a0, t2, 0 + la a1, code_start + la a2, code_stop +$L1: + lw t0, 0(a1) + sw t0, 0(a0) + add a1, 4 + add a0, 4 + blt a1, a2, $L1 + nop + + /* At this point we need to invalidate dcache and */ + /* icache before jumping to new code */ + +1: /* Get cache sizes */ + .set mips32 + mfc0 s0,C0_CONFIG,1 + .set mips0 + + li s1,CONF1_DL_MASK + and s1,s0 + beq s1,zero,nodc + nop + + srl s1,CONF1_DL_SHIFT + li t0,CONF1_DL_BASE + sll s1,t0,s1 /* s1 has D$ cache line size */ + + li s2,CONF1_DA_MASK + and s2,s0 + srl s2,CONF1_DA_SHIFT + addiu s2,CONF1_DA_BASE /* s2 now has D$ associativity */ + + li t0,CONF1_DS_MASK + and t0,s0 + srl t0,CONF1_DS_SHIFT + li s3,CONF1_DS_BASE + sll s3,s3,t0 /* s3 has D$ sets per way */ + + multu s2,s3 /* sets/way * associativity */ + mflo t0 /* total cache lines */ + + multu s1,t0 /* D$ linesize * lines */ + mflo s2 /* s2 is now D$ size in bytes */ + + /* Initilize the D$: */ + mtc0 zero,C0_TAGLO + mtc0 zero,C0_TAGHI + + li t0,KSEG0 /* Just an address for the first $ line */ + addu t1,t0,s2 /* + size of cache == end */ + + .set mips3 +1: cache Index_Writeback_Inv_D,0(t0) + .set mips0 + bne t0,t1,1b + addu t0,s1 + +nodc: + /* Now we get to do it all again for the I$ */ + + move s3,zero /* just in case there is no icache */ + move s4,zero + + li t0,CONF1_IL_MASK + and t0,s0 + beq t0,zero,noic + nop + + srl t0,CONF1_IL_SHIFT + li s3,CONF1_IL_BASE + sll s3,t0 /* s3 has I$ cache line size */ + + li t0,CONF1_IA_MASK + and t0,s0 + srl t0,CONF1_IA_SHIFT + addiu s4,t0,CONF1_IA_BASE /* s4 now has I$ associativity */ + + li t0,CONF1_IS_MASK + and t0,s0 + srl t0,CONF1_IS_SHIFT + li s5,CONF1_IS_BASE + sll s5,t0 /* s5 has I$ sets per way */ + + multu s4,s5 /* sets/way * associativity */ + mflo t0 /* s4 is now total cache lines */ + + multu s3,t0 /* I$ linesize * lines */ + mflo s4 /* s4 is cache size in bytes */ + + /* Initilize the I$: */ + mtc0 zero,C0_TAGLO + mtc0 zero,C0_TAGHI + + li t0,KSEG0 /* Just an address for the first $ line */ + addu t1,t0,s4 /* + size of cache == end */ + + .set mips3 +1: cache Index_Invalidate_I,0(t0) + .set mips0 + bne t0,t1,1b + addu t0,s3 + +noic: + move a0,s3 /* icache line size */ + move a1,s4 /* icache size */ + move a2,s1 /* dcache line size */ + jal t2 + move a3,s2 /* dcache size */ + + .set reorder + END(startup) diff --git a/tools/lzma-loader/.svn/text-base/loader.lds.in.svn-base b/tools/lzma-loader/.svn/text-base/loader.lds.in.svn-base new file mode 100644 index 000000000..20f2ea98e --- /dev/null +++ b/tools/lzma-loader/.svn/text-base/loader.lds.in.svn-base @@ -0,0 +1,17 @@ +OUTPUT_ARCH(mips) +ENTRY(startup) +SECTIONS { + . = TEXT_START; + .text : { + *(.text) + *(.rodata) + } + + .data : { + *(.data) + } + + .bss : { + *(.bss) + } +} diff --git a/tools/lzma-loader/Makefile b/tools/lzma-loader/Makefile new file mode 100644 index 000000000..ad4a531b6 --- /dev/null +++ b/tools/lzma-loader/Makefile @@ -0,0 +1,5 @@ +include $(TOPDIR)/rules.mk + +all: + $(MAKE) -C src CC="$(TARGET_CC)" LD="$(TARGET_CROSS)ld" CROSS_COMPILE="$(TARGET_CROSS)" \ + INCLUDE="-I$(LINUX_DIR)/arch/mips/include" diff --git a/tools/lzma-loader/src/LzmaDecode.c b/tools/lzma-loader/src/LzmaDecode.c new file mode 100644 index 000000000..951700bdd --- /dev/null +++ b/tools/lzma-loader/src/LzmaDecode.c @@ -0,0 +1,663 @@ +/* + LzmaDecode.c + LZMA Decoder + + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25) + http://www.7-zip.org/ + + LZMA SDK is licensed under two licenses: + 1) GNU Lesser General Public License (GNU LGPL) + 2) Common Public License (CPL) + It means that you can select one of these two licenses and + follow rules of that license. + + SPECIAL EXCEPTION: + Igor Pavlov, as the author of this code, expressly permits you to + statically or dynamically link your code (or bind by name) to the + interfaces of this file without subjecting your linked code to the + terms of the CPL or GNU LGPL. Any modifications or additions + to this file, however, are subject to the LGPL or CPL terms. +*/ + +#include "LzmaDecode.h" + +#ifndef Byte +#define Byte unsigned char +#endif + +#define kNumTopBits 24 +#define kTopValue ((UInt32)1 << kNumTopBits) + +#define kNumBitModelTotalBits 11 +#define kBitModelTotal (1 << kNumBitModelTotalBits) +#define kNumMoveBits 5 + +typedef struct _CRangeDecoder +{ + Byte *Buffer; + Byte *BufferLim; + UInt32 Range; + UInt32 Code; + #ifdef _LZMA_IN_CB + ILzmaInCallback *InCallback; + int Result; + #endif + int ExtraBytes; +} CRangeDecoder; + +Byte RangeDecoderReadByte(CRangeDecoder *rd) +{ + if (rd->Buffer == rd->BufferLim) + { + #ifdef _LZMA_IN_CB + UInt32 size; + rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size); + rd->BufferLim = rd->Buffer + size; + if (size == 0) + #endif + { + rd->ExtraBytes = 1; + return 0xFF; + } + } + return (*rd->Buffer++); +} + +/* #define ReadByte (*rd->Buffer++) */ +#define ReadByte (RangeDecoderReadByte(rd)) + +void RangeDecoderInit(CRangeDecoder *rd, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback + #else + Byte *stream, UInt32 bufferSize + #endif + ) +{ + int i; + #ifdef _LZMA_IN_CB + rd->InCallback = inCallback; + rd->Buffer = rd->BufferLim = 0; + #else + rd->Buffer = stream; + rd->BufferLim = stream + bufferSize; + #endif + rd->ExtraBytes = 0; + rd->Code = 0; + rd->Range = (0xFFFFFFFF); + for(i = 0; i < 5; i++) + rd->Code = (rd->Code << 8) | ReadByte; +} + +#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code; +#define RC_FLUSH_VAR rd->Range = range; rd->Code = code; +#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; } + +UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits) +{ + RC_INIT_VAR + UInt32 result = 0; + int i; + for (i = numTotalBits; i > 0; i--) + { + /* UInt32 t; */ + range >>= 1; + + result <<= 1; + if (code >= range) + { + code -= range; + result |= 1; + } + /* + t = (code - range) >> 31; + t &= 1; + code -= range & (t - 1); + result = (result + result) | (1 - t); + */ + RC_NORMALIZE + } + RC_FLUSH_VAR + return result; +} + +int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd) +{ + UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob; + if (rd->Code < bound) + { + rd->Range = bound; + *prob += (kBitModelTotal - *prob) >> kNumMoveBits; + if (rd->Range < kTopValue) + { + rd->Code = (rd->Code << 8) | ReadByte; + rd->Range <<= 8; + } + return 0; + } + else + { + rd->Range -= bound; + rd->Code -= bound; + *prob -= (*prob) >> kNumMoveBits; + if (rd->Range < kTopValue) + { + rd->Code = (rd->Code << 8) | ReadByte; + rd->Range <<= 8; + } + return 1; + } +} + +#define RC_GET_BIT2(prob, mi, A0, A1) \ + UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \ + if (code < bound) \ + { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \ + else \ + { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \ + RC_NORMALIZE + +#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;) + +int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd) +{ + int mi = 1; + int i; + #ifdef _LZMA_LOC_OPT + RC_INIT_VAR + #endif + for(i = numLevels; i > 0; i--) + { + #ifdef _LZMA_LOC_OPT + CProb *prob = probs + mi; + RC_GET_BIT(prob, mi) + #else + mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd); + #endif + } + #ifdef _LZMA_LOC_OPT + RC_FLUSH_VAR + #endif + return mi - (1 << numLevels); +} + +int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd) +{ + int mi = 1; + int i; + int symbol = 0; + #ifdef _LZMA_LOC_OPT + RC_INIT_VAR + #endif + for(i = 0; i < numLevels; i++) + { + #ifdef _LZMA_LOC_OPT + CProb *prob = probs + mi; + RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i)) + #else + int bit = RangeDecoderBitDecode(probs + mi, rd); + mi = mi + mi + bit; + symbol |= (bit << i); + #endif + } + #ifdef _LZMA_LOC_OPT + RC_FLUSH_VAR + #endif + return symbol; +} + +Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd) +{ + int symbol = 1; + #ifdef _LZMA_LOC_OPT + RC_INIT_VAR + #endif + do + { + #ifdef _LZMA_LOC_OPT + CProb *prob = probs + symbol; + RC_GET_BIT(prob, symbol) + #else + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd); + #endif + } + while (symbol < 0x100); + #ifdef _LZMA_LOC_OPT + RC_FLUSH_VAR + #endif + return symbol; +} + +Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte) +{ + int symbol = 1; + #ifdef _LZMA_LOC_OPT + RC_INIT_VAR + #endif + do + { + int bit; + int matchBit = (matchByte >> 7) & 1; + matchByte <<= 1; + #ifdef _LZMA_LOC_OPT + { + CProb *prob = probs + ((1 + matchBit) << 8) + symbol; + RC_GET_BIT2(prob, symbol, bit = 0, bit = 1) + } + #else + bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd); + symbol = (symbol << 1) | bit; + #endif + if (matchBit != bit) + { + while (symbol < 0x100) + { + #ifdef _LZMA_LOC_OPT + CProb *prob = probs + symbol; + RC_GET_BIT(prob, symbol) + #else + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd); + #endif + } + break; + } + } + while (symbol < 0x100); + #ifdef _LZMA_LOC_OPT + RC_FLUSH_VAR + #endif + return symbol; +} + +#define kNumPosBitsMax 4 +#define kNumPosStatesMax (1 << kNumPosBitsMax) + +#define kLenNumLowBits 3 +#define kLenNumLowSymbols (1 << kLenNumLowBits) +#define kLenNumMidBits 3 +#define kLenNumMidSymbols (1 << kLenNumMidBits) +#define kLenNumHighBits 8 +#define kLenNumHighSymbols (1 << kLenNumHighBits) + +#define LenChoice 0 +#define LenChoice2 (LenChoice + 1) +#define LenLow (LenChoice2 + 1) +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits)) +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits)) +#define kNumLenProbs (LenHigh + kLenNumHighSymbols) + +int LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState) +{ + if(RangeDecoderBitDecode(p + LenChoice, rd) == 0) + return RangeDecoderBitTreeDecode(p + LenLow + + (posState << kLenNumLowBits), kLenNumLowBits, rd); + if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0) + return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid + + (posState << kLenNumMidBits), kLenNumMidBits, rd); + return kLenNumLowSymbols + kLenNumMidSymbols + + RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd); +} + +#define kNumStates 12 + +#define kStartPosModelIndex 4 +#define kEndPosModelIndex 14 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) + +#define kNumPosSlotBits 6 +#define kNumLenToPosStates 4 + +#define kNumAlignBits 4 +#define kAlignTableSize (1 << kNumAlignBits) + +#define kMatchMinLen 2 + +#define IsMatch 0 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax)) +#define IsRepG0 (IsRep + kNumStates) +#define IsRepG1 (IsRepG0 + kNumStates) +#define IsRepG2 (IsRepG1 + kNumStates) +#define IsRep0Long (IsRepG2 + kNumStates) +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax)) +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex) +#define LenCoder (Align + kAlignTableSize) +#define RepLenCoder (LenCoder + kNumLenProbs) +#define Literal (RepLenCoder + kNumLenProbs) + +#if Literal != LZMA_BASE_SIZE +StopCompilingDueBUG +#endif + +#ifdef _LZMA_OUT_READ + +typedef struct _LzmaVarState +{ + CRangeDecoder RangeDecoder; + Byte *Dictionary; + UInt32 DictionarySize; + UInt32 DictionaryPos; + UInt32 GlobalPos; + UInt32 Reps[4]; + int lc; + int lp; + int pb; + int State; + int PreviousIsMatch; + int RemainLen; +} LzmaVarState; + +int LzmaDecoderInit( + unsigned char *buffer, UInt32 bufferSize, + int lc, int lp, int pb, + unsigned char *dictionary, UInt32 dictionarySize, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback + #else + unsigned char *inStream, UInt32 inSize + #endif + ) +{ + LzmaVarState *vs = (LzmaVarState *)buffer; + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState)); + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp)); + UInt32 i; + if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState)) + return LZMA_RESULT_NOT_ENOUGH_MEM; + vs->Dictionary = dictionary; + vs->DictionarySize = dictionarySize; + vs->DictionaryPos = 0; + vs->GlobalPos = 0; + vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1; + vs->lc = lc; + vs->lp = lp; + vs->pb = pb; + vs->State = 0; + vs->PreviousIsMatch = 0; + vs->RemainLen = 0; + dictionary[dictionarySize - 1] = 0; + for (i = 0; i < numProbs; i++) + p[i] = kBitModelTotal >> 1; + RangeDecoderInit(&vs->RangeDecoder, + #ifdef _LZMA_IN_CB + inCallback + #else + inStream, inSize + #endif + ); + return LZMA_RESULT_OK; +} + +int LzmaDecode(unsigned char *buffer, + unsigned char *outStream, UInt32 outSize, + UInt32 *outSizeProcessed) +{ + LzmaVarState *vs = (LzmaVarState *)buffer; + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState)); + CRangeDecoder rd = vs->RangeDecoder; + int state = vs->State; + int previousIsMatch = vs->PreviousIsMatch; + Byte previousByte; + UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3]; + UInt32 nowPos = 0; + UInt32 posStateMask = (1 << (vs->pb)) - 1; + UInt32 literalPosMask = (1 << (vs->lp)) - 1; + int lc = vs->lc; + int len = vs->RemainLen; + UInt32 globalPos = vs->GlobalPos; + + Byte *dictionary = vs->Dictionary; + UInt32 dictionarySize = vs->DictionarySize; + UInt32 dictionaryPos = vs->DictionaryPos; + + if (len == -1) + { + *outSizeProcessed = 0; + return LZMA_RESULT_OK; + } + + while(len > 0 && nowPos < outSize) + { + UInt32 pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos]; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + len--; + } + if (dictionaryPos == 0) + previousByte = dictionary[dictionarySize - 1]; + else + previousByte = dictionary[dictionaryPos - 1]; +#else + +int LzmaDecode( + Byte *buffer, UInt32 bufferSize, + int lc, int lp, int pb, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback, + #else + unsigned char *inStream, UInt32 inSize, + #endif + unsigned char *outStream, UInt32 outSize, + UInt32 *outSizeProcessed) +{ + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp)); + CProb *p = (CProb *)buffer; + CRangeDecoder rd; + UInt32 i; + int state = 0; + int previousIsMatch = 0; + Byte previousByte = 0; + UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; + UInt32 nowPos = 0; + UInt32 posStateMask = (1 << pb) - 1; + UInt32 literalPosMask = (1 << lp) - 1; + int len = 0; + if (bufferSize < numProbs * sizeof(CProb)) + return LZMA_RESULT_NOT_ENOUGH_MEM; + for (i = 0; i < numProbs; i++) + p[i] = kBitModelTotal >> 1; + RangeDecoderInit(&rd, + #ifdef _LZMA_IN_CB + inCallback + #else + inStream, inSize + #endif + ); +#endif + + *outSizeProcessed = 0; + while(nowPos < outSize) + { + int posState = (int)( + (nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + & posStateMask); + #ifdef _LZMA_IN_CB + if (rd.Result != LZMA_RESULT_OK) + return rd.Result; + #endif + if (rd.ExtraBytes != 0) + return LZMA_RESULT_DATA_ERROR; + if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0) + { + CProb *probs = p + Literal + (LZMA_LIT_SIZE * + ((( + (nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + & literalPosMask) << lc) + (previousByte >> (8 - lc)))); + + if (state < 4) state = 0; + else if (state < 10) state -= 3; + else state -= 6; + if (previousIsMatch) + { + Byte matchByte; + #ifdef _LZMA_OUT_READ + UInt32 pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + matchByte = dictionary[pos]; + #else + matchByte = outStream[nowPos - rep0]; + #endif + previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte); + previousIsMatch = 0; + } + else + previousByte = LzmaLiteralDecode(probs, &rd); + outStream[nowPos++] = previousByte; + #ifdef _LZMA_OUT_READ + dictionary[dictionaryPos] = previousByte; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + #endif + } + else + { + previousIsMatch = 1; + if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1) + { + if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0) + { + if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0) + { + #ifdef _LZMA_OUT_READ + UInt32 pos; + #endif + if ( + (nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + == 0) + return LZMA_RESULT_DATA_ERROR; + state = state < 7 ? 9 : 11; + #ifdef _LZMA_OUT_READ + pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + previousByte = dictionary[pos]; + dictionary[dictionaryPos] = previousByte; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + #else + previousByte = outStream[nowPos - rep0]; + #endif + outStream[nowPos++] = previousByte; + continue; + } + } + else + { + UInt32 distance; + if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0) + distance = rep1; + else + { + if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0) + distance = rep2; + else + { + distance = rep3; + rep3 = rep2; + } + rep2 = rep1; + } + rep1 = rep0; + rep0 = distance; + } + len = LzmaLenDecode(p + RepLenCoder, &rd, posState); + state = state < 7 ? 8 : 11; + } + else + { + int posSlot; + rep3 = rep2; + rep2 = rep1; + rep1 = rep0; + state = state < 7 ? 7 : 10; + len = LzmaLenDecode(p + LenCoder, &rd, posState); + posSlot = RangeDecoderBitTreeDecode(p + PosSlot + + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << + kNumPosSlotBits), kNumPosSlotBits, &rd); + if (posSlot >= kStartPosModelIndex) + { + int numDirectBits = ((posSlot >> 1) - 1); + rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits); + if (posSlot < kEndPosModelIndex) + { + rep0 += RangeDecoderReverseBitTreeDecode( + p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd); + } + else + { + rep0 += RangeDecoderDecodeDirectBits(&rd, + numDirectBits - kNumAlignBits) << kNumAlignBits; + rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd); + } + } + else + rep0 = posSlot; + rep0++; + } + if (rep0 == (UInt32)(0)) + { + /* it's for stream version */ + len = -1; + break; + } + if (rep0 > nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + { + return LZMA_RESULT_DATA_ERROR; + } + len += kMatchMinLen; + do + { + #ifdef _LZMA_OUT_READ + UInt32 pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + previousByte = dictionary[pos]; + dictionary[dictionaryPos] = previousByte; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + #else + previousByte = outStream[nowPos - rep0]; + #endif + outStream[nowPos++] = previousByte; + len--; + } + while(len > 0 && nowPos < outSize); + } + } + + #ifdef _LZMA_OUT_READ + vs->RangeDecoder = rd; + vs->DictionaryPos = dictionaryPos; + vs->GlobalPos = globalPos + nowPos; + vs->Reps[0] = rep0; + vs->Reps[1] = rep1; + vs->Reps[2] = rep2; + vs->Reps[3] = rep3; + vs->State = state; + vs->PreviousIsMatch = previousIsMatch; + vs->RemainLen = len; + #endif + + *outSizeProcessed = nowPos; + return LZMA_RESULT_OK; +} diff --git a/tools/lzma-loader/src/LzmaDecode.h b/tools/lzma-loader/src/LzmaDecode.h new file mode 100644 index 000000000..f58944e3c --- /dev/null +++ b/tools/lzma-loader/src/LzmaDecode.h @@ -0,0 +1,100 @@ +/* + LzmaDecode.h + LZMA Decoder interface + + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25) + http://www.7-zip.org/ + + LZMA SDK is licensed under two licenses: + 1) GNU Lesser General Public License (GNU LGPL) + 2) Common Public License (CPL) + It means that you can select one of these two licenses and + follow rules of that license. + + SPECIAL EXCEPTION: + Igor Pavlov, as the author of this code, expressly permits you to + statically or dynamically link your code (or bind by name) to the + interfaces of this file without subjecting your linked code to the + terms of the CPL or GNU LGPL. Any modifications or additions + to this file, however, are subject to the LGPL or CPL terms. +*/ + +#ifndef __LZMADECODE_H +#define __LZMADECODE_H + +/* #define _LZMA_IN_CB */ +/* Use callback for input data */ + +/* #define _LZMA_OUT_READ */ +/* Use read function for output data */ + +/* #define _LZMA_PROB32 */ +/* It can increase speed on some 32-bit CPUs, + but memory usage will be doubled in that case */ + +/* #define _LZMA_LOC_OPT */ +/* Enable local speed optimizations inside code */ + +#ifndef UInt32 +#ifdef _LZMA_UINT32_IS_ULONG +#define UInt32 unsigned long +#else +#define UInt32 unsigned int +#endif +#endif + +#ifdef _LZMA_PROB32 +#define CProb UInt32 +#else +#define CProb unsigned short +#endif + +#define LZMA_RESULT_OK 0 +#define LZMA_RESULT_DATA_ERROR 1 +#define LZMA_RESULT_NOT_ENOUGH_MEM 2 + +#ifdef _LZMA_IN_CB +typedef struct _ILzmaInCallback +{ + int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize); +} ILzmaInCallback; +#endif + +#define LZMA_BASE_SIZE 1846 +#define LZMA_LIT_SIZE 768 + +/* +bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb) +bufferSize += 100 in case of _LZMA_OUT_READ +by default CProb is unsigned short, +but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int) +*/ + +#ifdef _LZMA_OUT_READ +int LzmaDecoderInit( + unsigned char *buffer, UInt32 bufferSize, + int lc, int lp, int pb, + unsigned char *dictionary, UInt32 dictionarySize, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback + #else + unsigned char *inStream, UInt32 inSize + #endif +); +#endif + +int LzmaDecode( + unsigned char *buffer, + #ifndef _LZMA_OUT_READ + UInt32 bufferSize, + int lc, int lp, int pb, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback, + #else + unsigned char *inStream, UInt32 inSize, + #endif + #endif + unsigned char *outStream, UInt32 outSize, + UInt32 *outSizeProcessed); + +#endif diff --git a/tools/lzma-loader/src/LzmaDecode.o b/tools/lzma-loader/src/LzmaDecode.o new file mode 100644 index 000000000..3d7be3f4d Binary files /dev/null and b/tools/lzma-loader/src/LzmaDecode.o differ diff --git a/tools/lzma-loader/src/Makefile b/tools/lzma-loader/src/Makefile new file mode 100644 index 000000000..f5d780c2b --- /dev/null +++ b/tools/lzma-loader/src/Makefile @@ -0,0 +1,78 @@ +# +# Makefile for Broadcom BCM947XX boards +# +# Copyright 2001-2003, Broadcom Corporation +# All Rights Reserved. +# +# THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY +# KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM +# SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE. +# +# Copyright 2004 Manuel Novoa III +# Modified to support bzip'd kernels. +# Of course, it would be better to integrate bunzip capability into CFE. +# +# Copyright 2005 Oleg I. Vdovikin +# Cleaned up, modified for lzma support, removed from kernel +# + +TEXT_START := 0x80001000 +BZ_TEXT_START := 0x80400000 + +OBJCOPY := $(CROSS_COMPILE)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S + +CFLAGS = -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -Os \ + -fno-strict-aliasing -fno-common -fomit-frame-pointer -G 0 -mno-abicalls -fno-pic \ + -ffunction-sections -pipe -mlong-calls -fno-common \ + -mabi=32 -march=mips32 -Wa,-32 -Wa,-march=mips32 -Wa,-mips32 -Wa,--trap +CFLAGS += -DLOADADDR=$(TEXT_START) -D_LZMA_IN_CB +CFLAGS += $(INCLUDE) + +ASFLAGS = $(CFLAGS) -D__ASSEMBLY__ -DBZ_TEXT_START=$(BZ_TEXT_START) + +SEDFLAGS := s/BZ_TEXT_START/$(BZ_TEXT_START)/;s/TEXT_START/$(TEXT_START)/ + +OBJECTS := head.o data.o + +all: loader.gz loader.elf + +# Don't build dependencies, this may die if $(CC) isn't gcc +dep: + +install: + +loader.gz: loader + gzip -nc9 $< > $@ + +loader.elf: loader.o + cp $< $@ + +loader: loader.o + $(OBJCOPY) $< $@ + +loader.o: loader.lds $(OBJECTS) + $(LD) -static --gc-sections -no-warn-mismatch -T loader.lds -o $@ $(OBJECTS) + +loader.lds: loader.lds.in Makefile + @sed "$(SEDFLAGS)" < $< > $@ + +data.o: data.lds decompress.image + $(LD) -no-warn-mismatch -T data.lds -r -o $@ -b binary decompress.image -b elf32-tradlittlemips + +data.lds: + @echo "SECTIONS { .data : { code_start = .; *(.data) code_stop = .; }}" > $@ + +decompress.image: decompress + $(OBJCOPY) $< $@ + +decompress: decompress.lds decompress.o LzmaDecode.o + $(LD) -static --gc-sections -no-warn-mismatch -T decompress.lds -o $@ decompress.o LzmaDecode.o + +decompress.lds: decompress.lds.in Makefile + @sed "$(SEDFLAGS)" < $< > $@ + +mrproper: clean + +clean: + rm -f loader.gz loader decompress *.lds *.o *.image diff --git a/tools/lzma-loader/src/README b/tools/lzma-loader/src/README new file mode 100644 index 000000000..16649e950 --- /dev/null +++ b/tools/lzma-loader/src/README @@ -0,0 +1,55 @@ +/* + * LZMA compressed kernel decompressor for bcm947xx boards + * + * Copyright (C) 2005 by Oleg I. Vdovikin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +The code is intended to decompress kernel, being compressed using lzma utility +build using 7zip LZMA SDK. This utility is located in the LZMA_Alone directory + +decompressor code expects that your .trx file consist of three partitions: + +1) decompressor itself (this is gziped code which pmon/cfe will extract and run +on boot-up instead of real kernel) +2) LZMA compressed kernel (both streamed and regular modes are supported now) +3) Root filesystem + +Please be sure to apply the following patch for use this new trx layout (it will +allow using both new and old trx files for root filesystem lookup code) + +--- linuz/arch/mips/brcm-boards/bcm947xx/setup.c 2005-01-23 19:24:27.503322896 +0300 ++++ linux/arch/mips/brcm-boards/bcm947xx/setup.c 2005-01-23 19:29:05.237100944 +0300 +@@ -221,7 +221,9 @@ + /* Try looking at TRX header for rootfs offset */ + if (le32_to_cpu(trx->magic) == TRX_MAGIC) { + bcm947xx_parts[1].offset = off; +- if (le32_to_cpu(trx->offsets[1]) > off) ++ if (le32_to_cpu(trx->offsets[2]) > off) ++ off = le32_to_cpu(trx->offsets[2]); ++ else if (le32_to_cpu(trx->offsets[1]) > off) + off = le32_to_cpu(trx->offsets[1]); + continue; + } + + +Revision history: + 0.02 Initial release + 0.03 Added Mineharu Takahara patch to pass actual + output size to decoder (stream mode compressed input is not + a requirement anymore) + 0.04 Reordered functions using lds script diff --git a/tools/lzma-loader/src/data.lds b/tools/lzma-loader/src/data.lds new file mode 100644 index 000000000..ec48b2dfd --- /dev/null +++ b/tools/lzma-loader/src/data.lds @@ -0,0 +1 @@ +SECTIONS { .data : { code_start = .; *(.data) code_stop = .; }} diff --git a/tools/lzma-loader/src/data.o b/tools/lzma-loader/src/data.o new file mode 100644 index 000000000..3c398909f Binary files /dev/null and b/tools/lzma-loader/src/data.o differ diff --git a/tools/lzma-loader/src/decompress b/tools/lzma-loader/src/decompress new file mode 100755 index 000000000..9b2091e78 Binary files /dev/null and b/tools/lzma-loader/src/decompress differ diff --git a/tools/lzma-loader/src/decompress.c b/tools/lzma-loader/src/decompress.c new file mode 100644 index 000000000..05681b152 --- /dev/null +++ b/tools/lzma-loader/src/decompress.c @@ -0,0 +1,186 @@ +/* + * LZMA compressed kernel decompressor for bcm947xx boards + * + * Copyright (C) 2005 by Oleg I. Vdovikin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * + * Please note, this was code based on the bunzip2 decompressor code + * by Manuel Novoa III (mjn3@codepoet.org), although the only thing left + * is an idea and part of original vendor code + * + * + * 12-Mar-2005 Mineharu Takahara + * pass actual output size to decoder (stream mode + * compressed input is not a requirement anymore) + * + * 24-Apr-2005 Oleg I. Vdovikin + * reordered functions using lds script, removed forward decl + * + */ + +#include "LzmaDecode.h" + +#define BCM4710_FLASH 0x1fc00000 /* Flash */ + +#define KSEG0 0x80000000 +#define KSEG1 0xa0000000 + +#define KSEG1ADDR(a) ((((unsigned)(a)) & 0x1fffffffU) | KSEG1) + +#define Index_Invalidate_I 0x00 +#define Index_Writeback_Inv_D 0x01 + +#define cache_unroll(base,op) \ + __asm__ __volatile__( \ + ".set noreorder;\n" \ + ".set mips3;\n" \ + "cache %1, (%0);\n" \ + ".set mips0;\n" \ + ".set reorder\n" \ + : \ + : "r" (base), \ + "i" (op)); + +static __inline__ void blast_icache(unsigned long size, unsigned long lsize) +{ + unsigned long start = KSEG0; + unsigned long end = (start + size); + + while(start < end) { + cache_unroll(start,Index_Invalidate_I); + start += lsize; + } +} + +static __inline__ void blast_dcache(unsigned long size, unsigned long lsize) +{ + unsigned long start = KSEG0; + unsigned long end = (start + size); + + while(start < end) { + cache_unroll(start,Index_Writeback_Inv_D); + start += lsize; + } +} + +#define TRX_MAGIC 0x30524448 /* "HDR0" */ + +struct trx_header { + unsigned int magic; /* "HDR0" */ + unsigned int len; /* Length of file including header */ + unsigned int crc32; /* 32-bit CRC from flag_version to end of file */ + unsigned int flag_version; /* 0:15 flags, 16:31 version */ + 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[]; + +unsigned int offset; +unsigned char *data; + +/* flash access should be aligned, so wrapper is used */ +/* read byte from the flash, all accesses are 32-bit aligned */ +static int read_byte(void *object, unsigned char **buffer, UInt32 *bufferSize) +{ + static unsigned int val; + + if (((unsigned int)offset % 4) == 0) { + val = *(unsigned int *)data; + data += 4; + } + + *bufferSize = 1; + *buffer = ((unsigned char *)&val) + (offset++ & 3); + + return LZMA_RESULT_OK; +} + +static __inline__ unsigned char get_byte(void) +{ + unsigned char *buffer; + UInt32 fake; + + return read_byte(0, &buffer, &fake), *buffer; +} + +/* should be the first function */ +void entry(unsigned long icache_size, unsigned long icache_lsize, + unsigned long dcache_size, unsigned long dcache_lsize, + unsigned long fw_arg0, unsigned long fw_arg1, + unsigned long fw_arg2, unsigned long fw_arg3) +{ + unsigned int i; /* temp value */ + unsigned int lc; /* literal context bits */ + unsigned int lp; /* literal pos state bits */ + unsigned int pb; /* pos state bits */ + unsigned int osize; /* uncompressed size */ + + ILzmaInCallback callback; + callback.Read = read_byte; + + /* look for trx header, 32-bit data access */ + for (data = ((unsigned char *) KSEG1ADDR(BCM4710_FLASH)); + ((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]; + else + data += ((struct trx_header *)data)->offsets[1]; + + offset = 0; + + /* lzma args */ + i = get_byte(); + lc = i % 9, i = i / 9; + lp = i % 5, pb = i / 5; + + /* skip rest of the LZMA coder property */ + for (i = 0; i < 4; i++) + get_byte(); + + /* read the lower half of uncompressed size in the header */ + osize = ((unsigned int)get_byte()) + + ((unsigned int)get_byte() << 8) + + ((unsigned int)get_byte() << 16) + + ((unsigned int)get_byte() << 24); + + /* skip rest of the header (upper half of uncompressed size) */ + for (i = 0; i < 4; i++) + get_byte(); + + /* decompress kernel */ + if (LzmaDecode(workspace, ~0, lc, lp, pb, &callback, + (unsigned char*)LOADADDR, osize, &i) == LZMA_RESULT_OK) + { + blast_dcache(dcache_size, dcache_lsize); + blast_icache(icache_size, icache_lsize); + + /* Jump to load address */ + ((void (*)(unsigned long, unsigned long, unsigned long, + unsigned long)) LOADADDR)(fw_arg0, fw_arg1, fw_arg2, + fw_arg3); + } +} diff --git a/tools/lzma-loader/src/decompress.image b/tools/lzma-loader/src/decompress.image new file mode 100755 index 000000000..b0cb1af95 Binary files /dev/null and b/tools/lzma-loader/src/decompress.image differ diff --git a/tools/lzma-loader/src/decompress.lds b/tools/lzma-loader/src/decompress.lds new file mode 100644 index 000000000..7da944d0c --- /dev/null +++ b/tools/lzma-loader/src/decompress.lds @@ -0,0 +1,20 @@ +OUTPUT_ARCH(mips) +ENTRY(entry) +SECTIONS { + . = 0x80400000; + .text : { + *(.text.entry) + *(.text) + *(.rodata) + } + + .data : { + *(.data) + } + + .bss : { + *(.bss) + } + + workspace = .; +} diff --git a/tools/lzma-loader/src/decompress.lds.in b/tools/lzma-loader/src/decompress.lds.in new file mode 100644 index 000000000..33f56f8a0 --- /dev/null +++ b/tools/lzma-loader/src/decompress.lds.in @@ -0,0 +1,20 @@ +OUTPUT_ARCH(mips) +ENTRY(entry) +SECTIONS { + . = BZ_TEXT_START; + .text : { + *(.text.entry) + *(.text) + *(.rodata) + } + + .data : { + *(.data) + } + + .bss : { + *(.bss) + } + + workspace = .; +} diff --git a/tools/lzma-loader/src/decompress.o b/tools/lzma-loader/src/decompress.o new file mode 100644 index 000000000..483bc0b32 Binary files /dev/null and b/tools/lzma-loader/src/decompress.o differ diff --git a/tools/lzma-loader/src/head.S b/tools/lzma-loader/src/head.S new file mode 100644 index 000000000..3a33e4016 --- /dev/null +++ b/tools/lzma-loader/src/head.S @@ -0,0 +1,160 @@ +/* Copyright 2005 Oleg I. Vdovikin (oleg@cs.msu.su) */ +/* cache manipulation adapted from Broadcom code */ +/* idea taken from original bunzip2 decompressor code */ +/* Copyright 2004 Manuel Novoa III (mjn3@codepoet.org) */ +/* Licensed under the linux kernel's version of the GPL.*/ + +#include +#include + +#define KSEG0 0x80000000 + +#define C0_CONFIG $16 +#define C0_TAGLO $28 +#define C0_TAGHI $29 + +#define CONF1_DA_SHIFT 7 /* D$ associativity */ +#define CONF1_DA_MASK 0x00000380 +#define CONF1_DA_BASE 1 +#define CONF1_DL_SHIFT 10 /* D$ line size */ +#define CONF1_DL_MASK 0x00001c00 +#define CONF1_DL_BASE 2 +#define CONF1_DS_SHIFT 13 /* D$ sets/way */ +#define CONF1_DS_MASK 0x0000e000 +#define CONF1_DS_BASE 64 +#define CONF1_IA_SHIFT 16 /* I$ associativity */ +#define CONF1_IA_MASK 0x00070000 +#define CONF1_IA_BASE 1 +#define CONF1_IL_SHIFT 19 /* I$ line size */ +#define CONF1_IL_MASK 0x00380000 +#define CONF1_IL_BASE 2 +#define CONF1_IS_SHIFT 22 /* Instruction cache sets/way */ +#define CONF1_IS_MASK 0x01c00000 +#define CONF1_IS_BASE 64 + +#define Index_Invalidate_I 0x00 +#define Index_Writeback_Inv_D 0x01 + + .text + LEAF(startup) + .set noreorder + addi sp, -48 + sw a0, 16(sp) + sw a1, 20(sp) + sw a2, 24(sp) + sw a3, 28(sp) + + /* Copy decompressor code to the right place */ + li t2, BZ_TEXT_START + add a0, t2, 0 + la a1, code_start + la a2, code_stop +$L1: + lw t0, 0(a1) + sw t0, 0(a0) + add a1, 4 + add a0, 4 + blt a1, a2, $L1 + nop + + /* At this point we need to invalidate dcache and */ + /* icache before jumping to new code */ + +1: /* Get cache sizes */ + .set mips32 + mfc0 s0,C0_CONFIG,1 + .set mips0 + + li s1,CONF1_DL_MASK + and s1,s0 + beq s1,zero,nodc + nop + + srl s1,CONF1_DL_SHIFT + li t0,CONF1_DL_BASE + sll s1,t0,s1 /* s1 has D$ cache line size */ + + li s2,CONF1_DA_MASK + and s2,s0 + srl s2,CONF1_DA_SHIFT + addiu s2,CONF1_DA_BASE /* s2 now has D$ associativity */ + + li t0,CONF1_DS_MASK + and t0,s0 + srl t0,CONF1_DS_SHIFT + li s3,CONF1_DS_BASE + sll s3,s3,t0 /* s3 has D$ sets per way */ + + multu s2,s3 /* sets/way * associativity */ + mflo t0 /* total cache lines */ + + multu s1,t0 /* D$ linesize * lines */ + mflo s2 /* s2 is now D$ size in bytes */ + + /* Initilize the D$: */ + mtc0 zero,C0_TAGLO + mtc0 zero,C0_TAGHI + + li t0,KSEG0 /* Just an address for the first $ line */ + addu t1,t0,s2 /* + size of cache == end */ + + .set mips3 +1: cache Index_Writeback_Inv_D,0(t0) + .set mips0 + bne t0,t1,1b + addu t0,s1 + +nodc: + /* Now we get to do it all again for the I$ */ + + move s3,zero /* just in case there is no icache */ + move s4,zero + + li t0,CONF1_IL_MASK + and t0,s0 + beq t0,zero,noic + nop + + srl t0,CONF1_IL_SHIFT + li s3,CONF1_IL_BASE + sll s3,t0 /* s3 has I$ cache line size */ + + li t0,CONF1_IA_MASK + and t0,s0 + srl t0,CONF1_IA_SHIFT + addiu s4,t0,CONF1_IA_BASE /* s4 now has I$ associativity */ + + li t0,CONF1_IS_MASK + and t0,s0 + srl t0,CONF1_IS_SHIFT + li s5,CONF1_IS_BASE + sll s5,t0 /* s5 has I$ sets per way */ + + multu s4,s5 /* sets/way * associativity */ + mflo t0 /* s4 is now total cache lines */ + + multu s3,t0 /* I$ linesize * lines */ + mflo s4 /* s4 is cache size in bytes */ + + /* Initilize the I$: */ + mtc0 zero,C0_TAGLO + mtc0 zero,C0_TAGHI + + li t0,KSEG0 /* Just an address for the first $ line */ + addu t1,t0,s4 /* + size of cache == end */ + + .set mips3 +1: cache Index_Invalidate_I,0(t0) + .set mips0 + bne t0,t1,1b + addu t0,s3 + +noic: + move a0,s3 /* icache line size */ + move a1,s4 /* icache size */ + move a2,s1 /* dcache line size */ + jal t2 + move a3,s2 /* dcache size */ + + .set reorder + END(startup) diff --git a/tools/lzma-loader/src/head.o b/tools/lzma-loader/src/head.o new file mode 100644 index 000000000..04763fa4b Binary files /dev/null and b/tools/lzma-loader/src/head.o differ diff --git a/tools/lzma-loader/src/loader b/tools/lzma-loader/src/loader new file mode 100755 index 000000000..871117b87 Binary files /dev/null and b/tools/lzma-loader/src/loader differ diff --git a/tools/lzma-loader/src/loader.elf b/tools/lzma-loader/src/loader.elf new file mode 100755 index 000000000..0633a0e77 Binary files /dev/null and b/tools/lzma-loader/src/loader.elf differ diff --git a/tools/lzma-loader/src/loader.gz b/tools/lzma-loader/src/loader.gz new file mode 100644 index 000000000..426c9295e Binary files /dev/null and b/tools/lzma-loader/src/loader.gz differ diff --git a/tools/lzma-loader/src/loader.lds b/tools/lzma-loader/src/loader.lds new file mode 100644 index 000000000..9d95adbfa --- /dev/null +++ b/tools/lzma-loader/src/loader.lds @@ -0,0 +1,17 @@ +OUTPUT_ARCH(mips) +ENTRY(startup) +SECTIONS { + . = 0x80001000; + .text : { + *(.text) + *(.rodata) + } + + .data : { + *(.data) + } + + .bss : { + *(.bss) + } +} diff --git a/tools/lzma-loader/src/loader.lds.in b/tools/lzma-loader/src/loader.lds.in new file mode 100644 index 000000000..20f2ea98e --- /dev/null +++ b/tools/lzma-loader/src/loader.lds.in @@ -0,0 +1,17 @@ +OUTPUT_ARCH(mips) +ENTRY(startup) +SECTIONS { + . = TEXT_START; + .text : { + *(.text) + *(.rodata) + } + + .data : { + *(.data) + } + + .bss : { + *(.bss) + } +} diff --git a/tools/lzma-loader/src/loader.o b/tools/lzma-loader/src/loader.o new file mode 100755 index 000000000..0633a0e77 Binary files /dev/null and b/tools/lzma-loader/src/loader.o differ diff --git a/tools/lzma/Makefile b/tools/lzma/Makefile new file mode 100644 index 000000000..3ca257783 --- /dev/null +++ b/tools/lzma/Makefile @@ -0,0 +1,30 @@ +# This file is part of the OpenADK project. OpenADK is copyrighted +# material, please see the LICENCE file in the top-level directory. + +include $(TOPDIR)/rules.mk + +PKG_NAME:= lzma +PKG_VERSION:= 4.65 +PKG_RELEASE:= 1 +PKG_MD5SUM:= 434e51a018b4c8ef377bf81520a53af0 +PKG_SITES:= http://downloads.openwrt.org/sources/ + +DISTFILES:= ${PKG_NAME}-${PKG_VERSION}.tar.bz2 + +include ../rules.mk + +install: ${STAGING_HOST_DIR}/usr/bin/lzma + +UTIL_DIR=$(WRKBUILD)/C/LzmaUtil +ALONE_DIR=$(WRKBUILD)/CPP/7zip/Compress/LZMA_Alone + +$(WRKBUILD)/.compiled: ${WRKDIST}/.prepared + $(MAKE) -C $(UTIL_DIR) -f makefile.gcc + $(MAKE) -C $(ALONE_DIR) -f makefile.gcc + touch $@ + +${STAGING_HOST_DIR}/usr/bin/lzma: $(WRKBUILD)/.compiled + $(INSTALL_BIN) $(WRKBUILD)/CPP/7zip/Compress/LZMA_Alone/lzma_alone \ + $(STAGING_DIR)/usr/bin/lzma + +include $(TOPDIR)/mk/tools.mk diff --git a/tools/lzma/patches/001-large_files.patch b/tools/lzma/patches/001-large_files.patch new file mode 100644 index 000000000..b95fe9e90 --- /dev/null +++ b/tools/lzma/patches/001-large_files.patch @@ -0,0 +1,13 @@ +Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile.gcc +=================================================================== +--- lzma-4.65.orig/CPP/7zip/Compress/LZMA_Alone/makefile.gcc 2009-05-15 23:33:51.000000000 +0200 ++++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile.gcc 2009-06-01 22:00:54.000000000 +0200 +@@ -3,7 +3,7 @@ + CXX_C = gcc -O2 -Wall + LIB = -lm + RM = rm -f +-CFLAGS = -c ++CFLAGS = -c -D_FILE_OFFSET_BITS=64 + + ifdef SystemDrive + IS_MINGW = 1 diff --git a/tools/lzma/patches/002-lzmp.patch b/tools/lzma/patches/002-lzmp.patch new file mode 100644 index 000000000..72d881cdb --- /dev/null +++ b/tools/lzma/patches/002-lzmp.patch @@ -0,0 +1,1059 @@ +Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzmp.cpp +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzmp.cpp 2009-06-01 22:01:10.000000000 +0200 +@@ -0,0 +1,895 @@ ++/* ++ * LZMA command line tool similar to gzip to encode and decode LZMA files. ++ * ++ * Copyright (C) 2005 Ville Koskinen ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License ++ * as published by the Free Software Foundation; either version 2 ++ * of the License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, ++ * USA. ++ */ ++ ++#include "../../../Common/MyInitGuid.h" ++ ++#include ++using std::cout; ++using std::cerr; ++using std::endl; ++ ++#include ++#include ++#include ++ ++#include ++using std::string; ++#include ++using std::vector; ++typedef vector stringVector; ++ ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include // futimes() ++ ++// For Solaris ++#ifndef HAVE_FUTIMES ++//#define futimes(fd, tv) futimesat(fd, NULL, tv) ++#endif ++ ++#if defined(_WIN32) || defined(OS2) || defined(MSDOS) ++#include ++#include ++#define MY_SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY) ++#else ++#define MY_SET_BINARY_MODE(file) ++#endif ++ ++#include "../../../7zip/Common/FileStreams.h" ++ ++#include "../../../Common/Types.h" ++ ++#include "../../../7zip/Compress/LzmaDecoder.h" ++#include "../../../7zip/Compress/LzmaEncoder.h" ++ ++#include "Exception.h" ++ ++#include "lzma_version.h" ++ ++namespace lzma { ++ ++const char *PROGRAM_VERSION = PACKAGE_VERSION; ++const char *PROGRAM_COPYRIGHT = "Copyright (C) 2006 Ville Koskinen"; ++ ++/* LZMA_Alone switches: ++ -a{N}: set compression mode - [0, 2], default: 2 (max) ++ -d{N}: set dictionary - [0,28], default: 23 (8MB) ++ -fb{N}: set number of fast bytes - [5, 255], default: 128 ++ -lc{N}: set number of literal context bits - [0, 8], default: 3 ++ -lp{N}: set number of literal pos bits - [0, 4], default: 0 ++ -pb{N}: set number of pos bits - [0, 4], default: 2 ++ -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, bt4b, pat2r, pat2, ++ pat2h, pat3h, pat4h, hc3, hc4], default: bt4 ++*/ ++ ++struct lzma_option { ++ short compression_mode; // -a ++ short dictionary; // -d ++ short fast_bytes; // -fb ++ wchar_t *match_finder; // -mf ++ short literal_context_bits; // -lc ++ short literal_pos_bits; // -lp ++ short pos_bits; // -pb ++}; ++ ++/* The following is a mapping from gzip/bzip2 style -1 .. -9 compression modes ++ * to the corresponding LZMA compression modes. Thanks, Larhzu, for coining ++ * these. */ ++const lzma_option option_mapping[] = { ++ { 0, 0, 0, NULL, 0, 0, 0}, // -0 (needed for indexing) ++ { 0, 16, 64, L"hc4", 3, 0, 2}, // -1 ++ { 0, 20, 64, L"hc4", 3, 0, 2}, // -2 ++ { 1, 19, 64, L"bt4", 3, 0, 2}, // -3 ++ { 2, 20, 64, L"bt4", 3, 0, 2}, // -4 ++ { 2, 21, 128, L"bt4", 3, 0, 2}, // -5 ++ { 2, 22, 128, L"bt4", 3, 0, 2}, // -6 ++ { 2, 23, 128, L"bt4", 3, 0, 2}, // -7 ++ { 2, 24, 255, L"bt4", 3, 0, 2}, // -8 ++ { 2, 25, 255, L"bt4", 3, 0, 2}, // -9 ++}; ++ ++struct extension_pair { ++ char *from; ++ char *to; ++}; ++ ++const extension_pair known_extensions[] = { ++ { ".lzma", "" }, ++ { ".tlz", ".tar" }, ++ { NULL, NULL } ++}; ++ ++/* Sorry, I just happen to like enumerations. */ ++enum PROGRAM_MODE { ++ PM_COMPRESS = 0, ++ PM_DECOMPRESS, ++ PM_TEST, ++ PM_HELP, ++ PM_LICENSE, ++ PM_VERSION ++}; ++ ++enum { ++ STATUS_OK = 0, ++ STATUS_ERROR = 1, ++ STATUS_WARNING = 2 ++}; ++ ++/* getopt options. */ ++/* struct option { name, has_arg, flag, val } */ ++const struct option long_options[] = { ++ { "stdout", 0, 0, 'c' }, ++ { "decompress", 0, 0, 'd' }, ++ { "compress", 0, 0, 'z' }, ++ { "keep", 0, 0, 'k' }, ++ { "force", 0, 0, 'f' }, ++ { "test", 0, 0, 't' }, ++ { "suffix", 1, 0, 'S' }, ++ { "quiet", 0, 0, 'q' }, ++ { "verbose", 0, 0, 'v' }, ++ { "help", 0, 0, 'h' }, ++ { "license", 0, 0, 'L' }, ++ { "version", 0, 0, 'V' }, ++ { "fast", 0, 0, '1' }, ++ { "best", 0, 0, '9' }, ++ { 0, 0, 0, 0 } ++}; ++ ++/* getopt option string (for the above options). */ ++const char option_string[] = "cdzkftS:qvhLV123456789A:D:F:"; ++ ++/* Defaults. */ ++PROGRAM_MODE program_mode = PM_COMPRESS; ++int verbosity = 0; ++bool stdinput = false; ++bool stdoutput = false; ++bool keep = false; ++bool force = false; ++int compression_mode = 7; ++//char *suffix = strdup(".lzma"); ++char *suffix = strdup(known_extensions[0].from); ++lzma_option advanced_options = { -1, -1, -1, NULL, -1, -1, -1 }; ++ ++void print_help(const char *const argv0) ++{ ++ // Help goes to stdout while other messages go to stderr. ++ cout << "\nlzma " << PROGRAM_VERSION ++ << " " << PROGRAM_COPYRIGHT << "\n" ++ "Based on LZMA SDK " << LZMA_SDK_VERSION_STRING << " " ++ << LZMA_SDK_COPYRIGHT_STRING ++ << "\n\nUsage: " << argv0 ++ << " [flags and input files in any order]\n" ++" -c --stdout output to standard output\n" ++" -d --decompress force decompression\n" ++" -z --compress force compression\n" ++" -k --keep keep (don't delete) input files\n" ++" -f --force force overwrite of output file and compress links\n" ++" -t --test test compressed file integrity\n" ++" -S .suf --suffix .suf use suffix .suf on compressed files\n" ++" -q --quiet suppress error messages\n" ++" -v --verbose be verbose\n" ++" -h --help print this message\n" ++" -L --license display the license information\n" ++" -V --version display version numbers of LZMA SDK and lzma\n" ++" -1 .. -2 fast compression\n" ++" -3 .. -9 good to excellent compression. -7 is the default.\n" ++" --fast alias for -1\n" ++" --best alias for -9 (usually *not* what you want)\n\n" ++" Memory usage depends a lot on the chosen compression mode -1 .. -9.\n" ++" See the man page lzma(1) for details.\n\n"; ++} ++ ++void print_license(void) ++{ ++ cout << "\n LZMA command line tool " << PROGRAM_VERSION << " - " ++ << PROGRAM_COPYRIGHT ++ << "\n LZMA SDK " << LZMA_SDK_VERSION_STRING << " - " ++ << LZMA_SDK_COPYRIGHT_STRING ++ << "\n This program is a part of the LZMA utils package.\n" ++ " http://tukaani.org/lzma/\n\n" ++" This program is free software; you can redistribute it and/or\n" ++" modify it under the terms of the GNU General Public License\n" ++" as published by the Free Software Foundation; either version 2\n" ++" of the License, or (at your option) any later version.\n" ++"\n" ++" This program is distributed in the hope that it will be useful,\n" ++" but WITHOUT ANY WARRANTY; without even the implied warranty of\n" ++" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" ++" GNU General Public License for more details.\n" ++"\n"; ++} ++ ++void print_version(void) ++{ ++ cout << "LZMA command line tool " << PROGRAM_VERSION << "\n" ++ << "LZMA SDK " << LZMA_SDK_VERSION_STRING << "\n"; ++} ++ ++short str2int (const char *str, const int &min, const int &max) ++{ ++ int value = -1; ++ char *endptr = NULL; ++ if (str == NULL || str[0] == '\0') ++ throw ArgumentException("Invalid integer option"); ++ value = strtol (str, &endptr, 10); ++ if (*endptr != '\0' || value < min || value > max) ++ throw ArgumentException("Invalid integer option"); ++ return value; ++} ++ ++void parse_options(int argc, char **argv, stringVector &filenames) ++{ ++ /* Snatched from getopt(3). */ ++ int c; ++ ++ /* Check how we were called */ ++ { ++ char *p = strrchr (argv[0], '/'); // Remove path prefix, if any ++ if (p++ == NULL) ++ p = argv[0]; ++ if (strstr (p, "un") != NULL) { ++ program_mode = PM_DECOMPRESS; ++ } else if (strstr (p, "cat") != NULL) { ++ program_mode = PM_DECOMPRESS; ++ stdoutput = true; ++ } ++ } ++ ++ while (-1 != (c = getopt_long(argc, argv, option_string, ++ long_options, NULL))) { ++ switch (c) { ++ // stdout ++ case 'c': ++ stdoutput = true; ++ break; ++ ++ // decompress ++ case 'd': ++ program_mode = PM_DECOMPRESS; ++ break; ++ ++ // compress ++ case 'z': ++ program_mode = PM_COMPRESS; ++ break; ++ ++ // keep ++ case 'k': ++ keep = true; ++ break; ++ ++ // force ++ case 'f': ++ force = true; ++ break; ++ ++ // test ++ case 't': ++ program_mode = PM_TEST; ++ break; ++ ++ // suffix ++ case 'S': ++ if (optarg) { ++ free(suffix); ++ suffix = strdup(optarg); ++ } ++ break; ++ ++ // quiet ++ case 'q': ++ verbosity = 0; ++ break; ++ ++ // verbose ++ case 'v': ++ verbosity++; ++ break; ++ ++ // help ++ case 'h': ++ program_mode = PM_HELP; ++ break; ++ ++ // license ++ case 'L': ++ program_mode = PM_LICENSE; ++ break; ++ ++ // version ++ case 'V': ++ program_mode = PM_VERSION; ++ break; ++ ++ case '1': case '2': case '3': case '4': case '5': ++ case '6': case '7': case '8': case '9': ++ compression_mode = c - '0'; ++ break; ++ ++ // Advanced options // ++ // Compression mode ++ case 'A': ++ advanced_options.compression_mode = ++ str2int (optarg, 0, 2); ++ break; ++ ++ // Dictionary size ++ case 'D': ++ advanced_options.dictionary = ++ str2int (optarg, 0, 28); ++ break; ++ ++ // Fast bytes ++ case 'F': ++ advanced_options.fast_bytes = ++ str2int (optarg, 0, 273); ++ break; ++ ++ default: ++ throw ArgumentException(""); ++ break; ++ } // switch(c) ++ } // while(1) ++ ++ for (int i = optind; i < argc; i++) { ++ if (strcmp("-", argv[i]) == 0) ++ continue; ++ filenames.push_back(argv[i]); ++ } ++} // parse_options ++ ++void set_encoder_properties(NCompress::NLzma::CEncoder *encoder, ++ lzma_option &opt) ++{ ++ /* Almost verbatim from LzmaAlone.cpp. */ ++ PROPID propIDs[] = ++ { ++ NCoderPropID::kDictionarySize, ++ NCoderPropID::kPosStateBits, ++ NCoderPropID::kLitContextBits, ++ NCoderPropID::kLitPosBits, ++ NCoderPropID::kAlgorithm, ++ NCoderPropID::kNumFastBytes, ++ NCoderPropID::kMatchFinder, ++ NCoderPropID::kEndMarker ++ }; ++ const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]); ++#define VALUE(x) (advanced_options.x >= 0 ? advanced_options.x : opt.x) ++ PROPVARIANT properties[kNumProps]; ++ for (int p = 0; p < 6; p++) ++ properties[p].vt = VT_UI4; ++ properties[0].ulVal = UInt32(1 << VALUE (dictionary)); ++ properties[1].ulVal = UInt32(VALUE (pos_bits)); ++ properties[2].ulVal = UInt32(VALUE (literal_context_bits)); ++ properties[3].ulVal = UInt32(VALUE (literal_pos_bits)); ++ properties[4].ulVal = UInt32(VALUE (compression_mode)); ++ properties[5].ulVal = UInt32(VALUE (fast_bytes)); ++#undef VALUE ++ ++ properties[6].vt = VT_BSTR; ++ properties[6].bstrVal = (BSTR)opt.match_finder; ++ ++ properties[7].vt = VT_BOOL; ++ properties[7].boolVal = stdinput ? VARIANT_TRUE : VARIANT_FALSE; ++ ++ if (encoder->SetCoderProperties(propIDs, properties, kNumProps) != S_OK) ++ throw Exception("SetCoderProperties() error"); ++} ++ ++void encode(NCompress::NLzma::CEncoder *encoderSpec, ++ CMyComPtr inStream, ++ CMyComPtr outStream, ++ lzma_option encoder_options, ++ UInt64 fileSize) ++{ ++ set_encoder_properties(encoderSpec, encoder_options); ++ ++ encoderSpec->WriteCoderProperties(outStream); ++ ++ for (int i = 0; i < 8; i++) ++ { ++ Byte b = Byte(fileSize >> (8 * i)); ++ if (outStream->Write(&b, sizeof(b), 0) != S_OK) ++ throw Exception("Write error while encoding"); ++ } ++ ++ HRESULT result = encoderSpec->Code(inStream, outStream, 0, 0, 0); ++ ++ if (result == E_OUTOFMEMORY) ++ throw Exception("Cannot allocate memory"); ++ else if (result != S_OK) { ++ char buffer[33]; ++ snprintf(buffer, 33, "%d", (unsigned int)result); ++ throw Exception(string("Encoder error: ") + buffer); ++ } ++} ++ ++void decode(NCompress::NLzma::CDecoder *decoderSpec, ++ CMyComPtr inStream, ++ CMyComPtr outStream) ++{ ++ const UInt32 kPropertiesSize = 5; ++ Byte properties[kPropertiesSize]; ++ UInt32 processedSize; ++ UInt64 fileSize = 0; ++ ++ if (inStream->Read(properties, kPropertiesSize, &processedSize) != S_OK) ++ throw Exception("Read error"); ++ if (processedSize != kPropertiesSize) ++ throw Exception("Read error"); ++ if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK) ++ throw Exception("SetDecoderProperties() error"); ++ ++ for (int i = 0; i < 8; i++) ++ { ++ Byte b; ++ ++ if (inStream->Read(&b, sizeof(b), &processedSize) != S_OK) ++ throw Exception("Read error"); ++ if (processedSize != 1) ++ throw Exception("Read error"); ++ ++ fileSize |= ((UInt64)b) << (8 * i); ++ } ++ ++ if (decoderSpec->Code(inStream, outStream, 0, &fileSize, 0) != S_OK) ++ throw Exception("Decoder error"); ++} ++ ++int open_instream(const string infile, ++ CMyComPtr &inStream, ++ UInt64 &fileSize) ++{ ++ CInFileStream *inStreamSpec = new CInFileStream; ++ inStream = inStreamSpec; ++ if (!inStreamSpec->Open(infile.c_str())) ++ throw Exception("Cannot open input file " + infile); ++ ++ inStreamSpec->File.GetLength(fileSize); ++ ++ return inStreamSpec->File.GetHandle(); ++} ++ ++int open_outstream(const string outfile, ++ CMyComPtr &outStream) ++{ ++ COutFileStream *outStreamSpec = new COutFileStream; ++ outStream = outStreamSpec; ++ ++ bool open_by_force = (program_mode == PM_TEST) | force; ++ ++ if (!outStreamSpec->Create(outfile.c_str(), open_by_force)) ++ throw Exception("Cannot open output file " + outfile); ++ ++ return outStreamSpec->File.GetHandle(); ++} ++ ++double get_ratio(int inhandle, int outhandle) ++{ ++ struct stat in_stats, out_stats; ++ fstat(inhandle, &in_stats); ++ fstat(outhandle, &out_stats); ++ ++ return (double)out_stats.st_size / (double)in_stats.st_size; ++} ++ ++mode_t get_file_mode(string filename) ++{ ++ struct stat in_stat; ++ lstat(filename.c_str(), &in_stat); ++ ++ return in_stat.st_mode; ++} ++ ++bool string_ends_with(string str, string ending) ++{ ++ return equal(ending.rbegin(), ending.rend(), str.rbegin()); ++} ++ ++bool extension_is_known(string filename) ++{ ++ bool known_format = false; ++ extension_pair extension; int i = 1; ++ ++ extension = known_extensions[0]; ++ while (extension.from != NULL) { ++ if (string_ends_with(filename, extension.from)) { ++ known_format = true; ++ break; ++ } ++ extension = known_extensions[i]; ++ i++; ++ } ++ ++ if (!known_format) { ++ if (!string_ends_with(filename, suffix)) { ++ return false; ++ } ++ } ++ ++ return true; ++} ++ ++string replace_extension(string filename) ++{ ++ int suffix_starts_at = filename.length() - strlen (suffix); ++ string from_suffix = filename.substr(suffix_starts_at, strlen (suffix)); ++ string ret = filename.substr(0, suffix_starts_at); ++ extension_pair extension; int i = 1; ++ ++ bool found_replacement = false; ++ extension = known_extensions[0]; ++ while (extension.from != NULL) { ++ if (from_suffix.compare(extension.from) == 0) { ++ ret += extension.to; ++ found_replacement = true; ++ break; ++ } ++ ++ extension = known_extensions[i]; ++ i++; ++ } ++ ++ return ret; ++} ++ ++string pretty_print_status(string filename, string output_filename, ++ string ratio) ++{ ++ string ret = ""; ++ ++ ret += filename; ++ ret += ":\t "; ++ ++ if (program_mode == PM_TEST) { ++ ret += "decoded succesfully"; ++ ++ return ret; ++ } ++ ++ if (!stdinput && !stdoutput) { ++ ret += ratio; ++ ret += " -- "; ++ } ++ ++ if (program_mode == PM_COMPRESS) { ++ if (keep) { ++ ret += "encoded succesfully"; ++ ++ return ret; ++ } ++ ++ ret += "replaced with "; ++ ret += output_filename; ++ ++ return ret; ++ } ++ ++ if (program_mode == PM_DECOMPRESS) { ++ if (keep) { ++ ret += "decoded succesfully"; ++ ++ return ret; ++ } ++ ++ ret += "replaced with "; ++ ret += output_filename; ++ ++ return ret; ++ } ++ ++ return ret; ++} ++ ++static string archive_name; // I know, it is crude, but I haven't found any other ++ // way then making a global variable to transfer filename to handler ++ ++void signal_handler (int signum) ++{ ++ unlink (archive_name.c_str()); // deleting ++ signal (signum, SIG_DFL); // we return the default function to used signal ++ kill (getpid(), signum); // and then send this signal to the process again ++} ++ ++} // namespace lzma ++ ++ ++int main(int argc, char **argv) ++{ ++ using namespace lzma; ++ using std::cerr; ++ ++ stringVector filenames; ++ ++ signal (SIGTERM,signal_handler); ++ signal (SIGHUP,signal_handler); ++ signal (SIGINT,signal_handler); ++ ++ try { ++ parse_options(argc, argv, filenames); ++ } ++ catch (...) { ++ return STATUS_ERROR; ++ } ++ ++ if (program_mode == PM_HELP) { ++ print_help(argv[0]); ++ return STATUS_OK; ++ } ++ else if (program_mode == PM_LICENSE) { ++ print_license(); ++ return STATUS_OK; ++ } ++ else if (program_mode == PM_VERSION) { ++ print_version(); ++ return STATUS_OK; ++ } ++ ++ if (filenames.empty()) { ++ stdinput = true; ++ stdoutput = true; ++ ++ /* FIXME: get rid of this */ ++ filenames.push_back("-"); ++ } ++ ++ /* Protection: always create new files with 0600 in order to prevent ++ * outsiders from reading incomplete data. */ ++ umask(0077); ++ ++ bool warning = false; ++ ++ for (int i = 0; i < filenames.size(); i++) { ++ CMyComPtr inStream; ++ CMyComPtr outStream; ++ UInt64 fileSize = 0; ++ int inhandle = 0, outhandle = 0; ++ string output_filename; ++ ++ if (stdinput) { ++ inStream = new CStdInFileStream; ++ MY_SET_BINARY_MODE(stdin); ++ fileSize = (UInt64)(Int64)-1; ++ ++ inhandle = STDIN_FILENO; ++ ++ outStream = new CStdOutFileStream; ++ MY_SET_BINARY_MODE(stdout); ++ ++ outhandle = STDOUT_FILENO; ++ } ++ else { ++ mode_t infile_mode = get_file_mode(filenames[i]); ++ if (!S_ISREG(infile_mode)) { ++ if (S_ISDIR(infile_mode)) { ++ warning = true; ++ cerr << argv[0] << ": " << filenames[i] << ": " ++ << "cowardly refusing to work on directory" ++ << endl; ++ ++ continue; ++ } ++ else if (S_ISLNK(infile_mode)) { ++ if (!stdoutput && !force) { ++ warning = true; ++ ++ cerr << argv[0] << ": " << filenames[i] << ": " ++ << "cowardly refusing to work on symbolic link " ++ << "(use --force to force encoding or decoding)" ++ << endl; ++ ++ continue; ++ } ++ } ++ else { ++ warning = true; ++ ++ cerr << argv[0] << ": " << filenames[i] << ": " ++ << "doesn't exist or is not a regular file" ++ << endl; ++ ++ continue; ++ } ++ } ++ ++ // Test if the file already ends with *suffix. ++ if (program_mode == PM_COMPRESS && !force ++ && string_ends_with(filenames[i], ++ suffix)) { ++ warning = true; ++ ++ cerr << filenames[i] << " already has " ++ << suffix << " suffix -- unchanged\n"; ++ ++ continue; ++ } ++ ++ // Test if the file extension is known. ++ if (program_mode == PM_DECOMPRESS ++ && !extension_is_known(filenames[i])) { ++ warning = true; ++ ++ cerr << filenames[i] << ": " ++ << " unknown suffix -- unchanged" ++ << endl; ++ ++ continue; ++ } ++ ++ try { ++ inhandle = open_instream(filenames[i], inStream, fileSize); ++ } ++ catch (Exception e) { ++ cerr << argv[0] << ": " << e.what() << endl; ++ return STATUS_ERROR; ++ } ++ ++ if (stdoutput) { ++ outStream = new CStdOutFileStream; ++ MY_SET_BINARY_MODE(stdout); ++ ++ outhandle = STDOUT_FILENO; ++ } ++ else { ++ /* Testing mode is nothing else but decoding ++ * and throwing away the result. */ ++ if (program_mode == PM_TEST) ++ output_filename = "/dev/null"; ++ else if (program_mode == PM_DECOMPRESS) ++ output_filename = replace_extension(filenames[i]); ++ else ++ output_filename = filenames[i] ++ + suffix; ++ archive_name = output_filename; ++ ++ try { ++ outhandle = open_outstream(output_filename, outStream); ++ } ++ catch (Exception e) { ++ cerr << argv[0] << ": " << e.what() << endl; ++ return STATUS_ERROR; ++ } ++ } ++ ++ } ++ ++ // Unless --force is specified, do not read/write compressed ++ // data from/to a terminal. ++ if (!force) { ++ if (program_mode == PM_COMPRESS && isatty(outhandle)) { ++ cerr << argv[0] << ": compressed data not " ++ "written to a terminal. Use " ++ "-f to force compression.\n" ++ << argv[0] << ": For help, type: " ++ << argv[0] << " -h\n"; ++ return STATUS_ERROR; ++ } else if (program_mode == PM_DECOMPRESS ++ && isatty(inhandle)) { ++ cerr << argv[0] << ": compressed data not " ++ "read from a terminal. Use " ++ "-f to force decompression.\n" ++ << argv[0] << ": For help, type: " ++ << argv[0] << " -h\n"; ++ return STATUS_ERROR; ++ } ++ } ++ ++ if (program_mode == PM_COMPRESS) { ++ NCompress::NLzma::CEncoder *encoderSpec = ++ new NCompress::NLzma::CEncoder; ++ ++ lzma_option options = option_mapping[compression_mode]; ++ ++ try { ++ encode(encoderSpec, inStream, outStream, options, fileSize); ++ } ++ catch (Exception e) { ++ cerr << argv[0] << ": " << e.what() << endl; ++ unlink(output_filename.c_str()); ++ delete(encoderSpec); ++ ++ return STATUS_ERROR; ++ } ++ ++ delete(encoderSpec); ++ } ++ else { // PM_DECOMPRESS | PM_TEST ++ NCompress::NLzma::CDecoder *decoderSpec = ++ new NCompress::NLzma::CDecoder; ++ ++ try { ++ decode(decoderSpec, inStream, outStream); ++ } ++ catch (Exception e) { ++ cerr << argv[0] << ": " << e.what() << endl; ++ unlink(output_filename.c_str()); ++ delete(decoderSpec); ++ ++ return STATUS_ERROR; ++ } ++ ++ delete(decoderSpec); ++ } ++ ++ /* Set permissions and owners. */ ++ if ( (program_mode == PM_COMPRESS || program_mode == PM_DECOMPRESS ) ++ && (!stdinput && !stdoutput) ) { ++ ++ int ret = 0; ++ struct stat file_stats; ++ ret = fstat(inhandle, &file_stats); ++ ++ ret = fchmod(outhandle, file_stats.st_mode); ++ ret = fchown(outhandle, file_stats.st_uid, file_stats.st_gid); ++ // We need to call fchmod() again, since otherwise the SUID bits ++ // are lost. ++ ret = fchmod(outhandle, file_stats.st_mode); ++ ++ struct timeval file_times[2]; ++ // Access time ++ file_times[0].tv_sec = file_stats.st_atime; ++ file_times[0].tv_usec = 0; ++ // Modification time ++ file_times[1].tv_sec = file_stats.st_mtime; ++ file_times[1].tv_usec = 0; ++ ++ ret = futimes(outhandle, file_times); ++ ++ if (!keep) ++ unlink(filenames[i].c_str()); ++ } ++ ++ if (verbosity > 0) { ++ if (stdoutput) { ++ cerr << filenames[i] << ":\t "; ++ cerr << "decoded succesfully" ++ << endl; ++ } ++ ++ else { ++ char buf[10] = { 0 }; ++ ++ if (program_mode == PM_DECOMPRESS) ++ snprintf(buf, 10, "%.2f%%", ++ (1 - get_ratio(outhandle, inhandle)) * 100); ++ if (program_mode == PM_COMPRESS) ++ snprintf(buf, 10, "%.2f%%", ++ (1 - get_ratio(inhandle, outhandle)) * 100); ++ ++ string ratio = buf; ++ cerr << pretty_print_status(filenames[i], output_filename, ++ ratio) ++ << endl; ++ } ++ } ++ } ++ ++ if (warning) ++ return STATUS_WARNING; ++ ++ return STATUS_OK; ++} ++ +Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/Exception.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/Exception.h 2009-06-01 22:01:10.000000000 +0200 +@@ -0,0 +1,45 @@ ++/* A couple of exceptions for lzmp. ++ * ++ * Copyright (C) 2005 Ville Koskinen ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License ++ * as published by the Free Software Foundation; either version 2 ++ * of the License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ */ ++ ++#ifndef _EXCEPTION_H_ ++#define _EXCEPTION_H_ ++ ++#include ++using std::string; ++ ++class Exception ++{ ++private: ++ string message; ++public: ++ Exception(char *what): message(what) { } ++ Exception(string what): message(what) { } ++ ++ ~Exception() { } ++ ++ string what(void) { return message; } ++}; ++ ++class ArgumentException: public Exception ++{ ++public: ++ ArgumentException(char *what): Exception(what) { } ++ ArgumentException(string what): Exception(what) { } ++ ++ ~ArgumentException() { } ++}; ++ ++#endif ++ +Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile.gcc +=================================================================== +--- lzma-4.65.orig/CPP/7zip/Compress/LZMA_Alone/makefile.gcc 2009-06-01 22:00:54.000000000 +0200 ++++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/makefile.gcc 2009-06-01 22:06:13.000000000 +0200 +@@ -1,9 +1,10 @@ +-PROG = lzma ++PROG = lzma_alone ++PROG2 = lzma + CXX = g++ -O2 -Wall + CXX_C = gcc -O2 -Wall + LIB = -lm + RM = rm -f +-CFLAGS = -c -D_FILE_OFFSET_BITS=64 ++CFLAGS = -c -I ../../../ -D_FILE_OFFSET_BITS=64 -DPACKAGE_VERSION="\"4.32.0beta3\"" + + ifdef SystemDrive + IS_MINGW = 1 +@@ -45,12 +46,35 @@ + Lzma86Dec.o \ + Lzma86Enc.o \ + ++OBJS2 = \ ++ C_FileIO.o \ ++ CRC.o \ ++ Alloc.o \ ++ FileStreams.o \ ++ StreamUtils.o \ ++ InBuffer.o \ ++ OutBuffer.o \ ++ LzmaDecoder.o \ ++ StringConvert.o \ ++ StringToInt.o \ ++ LzmaEncoder.o \ ++ LzmaDec.o \ ++ LzmaEnc.o \ ++ LzFind.o \ ++ 7zCrc.o \ ++ lzmp.o + +-all: $(PROG) ++all: $(PROG) $(PROG2) + + $(PROG): $(OBJS) + $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2) + ++$(PROG2): $(OBJS2) ++ $(CXX) -o $(PROG2) $(LDFLAGS) $(OBJS2) $(LIB) ++ ++lzmp.o: lzmp.cpp ++ $(CXX) $(CFLAGS) lzmp.cpp ++ + LzmaAlone.o: LzmaAlone.cpp + $(CXX) $(CFLAGS) LzmaAlone.cpp + +@@ -131,5 +153,5 @@ + $(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Enc.c + + clean: +- -$(RM) $(PROG) $(OBJS) ++ -$(RM) $(PROG) $(PROG2) $(OBJS) + +Index: lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzma_version.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ lzma-4.65/CPP/7zip/Compress/LZMA_Alone/lzma_version.h 2009-06-01 22:01:10.000000000 +0200 +@@ -0,0 +1,31 @@ ++#ifndef LZMA_VERSION_H ++#define LZMA_VERSION_H ++ ++/* ++ Version and copyright information used by LZMA utils. ++*/ ++ ++static const char *LZMA_SDK_VERSION_STRING = "4.43"; ++ ++static const char *LZMA_SDK_COPYRIGHT_STRING = ++ "Copyright (C) 1999-2006 Igor Pavlov"; ++ ++static const char *LZMA_SDK_COPYRIGHT_INFO = ++ " See http://7-zip.org/sdk.html or the documentation of LZMA SDK for\n" ++ " the license. For reference, the version 4.43 is free software\n" ++ " licensed under the GNU LGPL."; ++ ++ ++static const char *LZMA_UTILS_VERSION_STRING = PACKAGE_VERSION; ++ ++static const char *LZMA_UTILS_COPYRIGHT_STRING = ++ "Copyright (C) 2006 Lasse Collin"; ++ ++static const char *LZMA_UTILS_COPYRIGHT_INFO = ++ "This program comes with ABSOLUTELY NO WARRANTY.\n" ++ "You may redistribute copies of this program\n" ++ "under the terms of the GNU General Public License.\n" ++ "For more information about these matters, see the file " ++ "named COPYING.\n"; ++ ++#endif /* ifndef LZMA_VERSION_H */ +Index: lzma-4.65/CPP/Common/C_FileIO.h +=================================================================== +--- lzma-4.65.orig/CPP/Common/C_FileIO.h 2009-05-15 23:33:51.000000000 +0200 ++++ lzma-4.65/CPP/Common/C_FileIO.h 2009-06-01 22:06:56.000000000 +0200 +@@ -24,6 +24,7 @@ + bool Close(); + bool GetLength(UInt64 &length) const; + off_t Seek(off_t distanceToMove, int moveMethod) const; ++ int GetHandle() const { return _handle; } + }; + + class CInFile: public CFileBase diff --git a/tools/lzma/patches/003-compile_fixes.patch b/tools/lzma/patches/003-compile_fixes.patch new file mode 100644 index 000000000..49ae66b9c --- /dev/null +++ b/tools/lzma/patches/003-compile_fixes.patch @@ -0,0 +1,26 @@ +diff -urN lzma-4.65/CPP/7zip/Common/FileStreams.h lzma-4.65.new/CPP/7zip/Common/FileStreams.h +--- lzma-4.65/CPP/7zip/Common/FileStreams.h 2009-05-15 23:33:51.000000000 +0200 ++++ lzma-4.65.new/CPP/7zip/Common/FileStreams.h 2009-06-01 22:30:01.000000000 +0200 +@@ -72,6 +72,7 @@ + public IOutStream, + public CMyUnknownImp + { ++public: + #ifdef USE_WIN_FILE + NWindows::NFile::NIO::COutFile File; + #else +diff -urN lzma-4.65/CPP/Common/MyWindows.h lzma-4.65.new/CPP/Common/MyWindows.h +--- lzma-4.65/CPP/Common/MyWindows.h 2009-05-15 23:33:51.000000000 +0200 ++++ lzma-4.65.new/CPP/Common/MyWindows.h 2009-06-01 22:29:26.000000000 +0200 +@@ -101,8 +101,11 @@ + + #ifdef __cplusplus + ++#ifndef INITGUID ++#define INITGUID + DEFINE_GUID(IID_IUnknown, + 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); ++#endif + struct IUnknown + { + STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE; diff --git a/tools/lzma/patches/100-static_library.patch b/tools/lzma/patches/100-static_library.patch new file mode 100644 index 000000000..15ab4e055 --- /dev/null +++ b/tools/lzma/patches/100-static_library.patch @@ -0,0 +1,70 @@ +--- a/C/LzmaUtil/makefile.gcc ++++ b/C/LzmaUtil/makefile.gcc +@@ -1,44 +1,53 @@ + PROG = lzma +-CXX = g++ +-LIB = ++CC = gcc ++LIB = liblzma.a + RM = rm -f + CFLAGS = -c -O2 -Wall ++AR = ar ++RANLIB = ranlib + + OBJS = \ +- LzmaUtil.o \ + Alloc.o \ + LzFind.o \ + LzmaDec.o \ + LzmaEnc.o \ ++ LzmaLib.o \ + 7zFile.o \ + 7zStream.o \ + +- + all: $(PROG) + +-$(PROG): $(OBJS) +- $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2) ++$(PROG): LzmaUtil.o $(LIB) ++ $(CC) -o $(PROG) $(LDFLAGS) $< $(LIB) + + LzmaUtil.o: LzmaUtil.c +- $(CXX) $(CFLAGS) LzmaUtil.c ++ $(CC) $(CFLAGS) LzmaUtil.c ++ ++$(LIB): $(OBJS) ++ rm -f $@ ++ $(AR) rcu $@ $(OBJS) ++ $(RANLIB) $@ + + Alloc.o: ../Alloc.c +- $(CXX) $(CFLAGS) ../Alloc.c ++ $(CC) $(CFLAGS) ../Alloc.c + + LzFind.o: ../LzFind.c +- $(CXX) $(CFLAGS) ../LzFind.c ++ $(CC) $(CFLAGS) ../LzFind.c + + LzmaDec.o: ../LzmaDec.c +- $(CXX) $(CFLAGS) ../LzmaDec.c ++ $(CC) $(CFLAGS) ../LzmaDec.c + + LzmaEnc.o: ../LzmaEnc.c +- $(CXX) $(CFLAGS) ../LzmaEnc.c ++ $(CC) $(CFLAGS) ../LzmaEnc.c ++ ++LzmaLib.o: ../LzmaLib.c ++ $(CC) $(CFLAGS) ../LzmaLib.c + + 7zFile.o: ../7zFile.c +- $(CXX) $(CFLAGS) ../7zFile.c ++ $(CC) $(CFLAGS) ../7zFile.c + + 7zStream.o: ../7zStream.c +- $(CXX) $(CFLAGS) ../7zStream.c ++ $(CC) $(CFLAGS) ../7zStream.c + + clean: +- -$(RM) $(PROG) $(OBJS) ++ -$(RM) $(PROG) *.o *.a diff --git a/tools/mkcrypt/Makefile b/tools/mkcrypt/Makefile index c36ec2a5a..089c6ad7b 100644 --- a/tools/mkcrypt/Makefile +++ b/tools/mkcrypt/Makefile @@ -3,9 +3,9 @@ include $(TOPDIR)/rules.mk -install: ${BIN_DIR}/mkcrypt +install: ${STAGING_HOST_DIR}/usr/bin/mkcrypt -${BIN_DIR}/mkcrypt: +${STAGING_HOST_DIR}/usr/bin/mkcrypt: $(CC_FOR_BUILD) ${FLAGS_FOR_BUILD} -o $@ mkcrypt.c include $(TOPDIR)/mk/tools.mk diff --git a/tools/mkfimage/Makefile b/tools/mkfimage/Makefile new file mode 100644 index 000000000..195614f2b --- /dev/null +++ b/tools/mkfimage/Makefile @@ -0,0 +1,4 @@ +include $(TOPDIR)/rules.mk + +all: mkfimage.c + $(CC_FOR_BUILD) ${FLAGS_FOR_BUILD} -o ${STAGING_HOST_DIR}/usr/bin/mkfimage mkfimage.c $(MAKE_TRACE) diff --git a/tools/mkfimage/mkfimage.c b/tools/mkfimage/mkfimage.c new file mode 100644 index 000000000..b1897fbd7 --- /dev/null +++ b/tools/mkfimage/mkfimage.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv){ + unsigned char *buffer = malloc(64 * 1024); + struct stat s; + unsigned int size_vmlinux = 0, real_size_vmlinux = 0; + const unsigned char *magic_str = "ACME_PART_MAGIC"; + unsigned int loop; + unsigned char *magic; + + if(argc != 3){ + printf("%s in out\n", argv[0]); + return 1; + } + + printf("Generating image\n"); + + FILE *vmlinux = fopen(argv[1], "r"); + FILE *vmlinux_out = fopen(argv[2], "w"); + if((!vmlinux) || (!vmlinux_out)){ + printf("Error opening a file\n"); + return 1; + } + + stat(argv[1], &s); + size_vmlinux = s.st_size; + real_size_vmlinux = (size_vmlinux & 0xffff0000) + 0x10000; + + printf("vmlinux = 0x%.08X / 0x%.08X\n", size_vmlinux, real_size_vmlinux); + + unsigned int t = fread(buffer, 1, 64 * 1024, vmlinux); + for(loop = 0; loop < (64 * 1024) - sizeof(magic_str); loop++){ + if(buffer[loop] == magic_str[0]){ + if((magic = strstr(&buffer[loop], magic_str))){ + //printf("Magic at 0x%.08X %p %p\n", magic - buffer, magic, buffer); + printf("Found Magic %X%X%X%X\n", + buffer[loop + strlen(magic_str)], + buffer[loop + strlen(magic_str) + 2], + buffer[loop + strlen(magic_str) + 1], + buffer[loop + strlen(magic_str) + 3]); + + buffer[loop + strlen(magic_str)] = real_size_vmlinux >> 24; + buffer[loop + strlen(magic_str) + 2] = (real_size_vmlinux >> 16) & 0xff; + buffer[loop + strlen(magic_str) + 1] = (real_size_vmlinux >> 8) & 0xff; + buffer[loop + strlen(magic_str) + 3] = (real_size_vmlinux) & 0xff; + + printf("Replaced with %.02X%.02X%.02X%.02X\n", + buffer[loop + strlen(magic_str)], + buffer[loop + strlen(magic_str) + 2], + buffer[loop + strlen(magic_str) + 1], + buffer[loop + strlen(magic_str) + 3]); + + } + } + } + + fwrite(buffer, 1, 64 * 1024, vmlinux_out); + real_size_vmlinux -= 64 * 1024; + do { + real_size_vmlinux -= 64 * 1024; + memset(buffer, 0, 64 * 1024); + fread(buffer, 1, 64 * 1024, vmlinux); + fwrite(buffer, 1, 64 * 1024, vmlinux_out); + } while (real_size_vmlinux); + + return 0; +} diff --git a/tools/mkimage/Makefile b/tools/mkimage/Makefile index 66d058370..db2e42c3f 100644 --- a/tools/mkimage/Makefile +++ b/tools/mkimage/Makefile @@ -3,9 +3,9 @@ include $(TOPDIR)/rules.mk -install: ${BIN_DIR}/mkimage +install: ${STAGING_HOST_DIR}/usr/bin/mkimage -${BIN_DIR}/mkimage: mkimage.c crc32.c +${STAGING_HOST_DIR}/usr/bin/mkimage: mkimage.c crc32.c $(CC_FOR_BUILD) ${FLAGS_FOR_BUILD} -o $@ mkimage.c crc32.c include $(TOPDIR)/mk/tools.mk diff --git a/tools/mtd-utils/Makefile b/tools/mtd-utils/Makefile new file mode 100644 index 000000000..0152a41ac --- /dev/null +++ b/tools/mtd-utils/Makefile @@ -0,0 +1,24 @@ +# This file is part of the OpenADK project. OpenADK is copyrighted +# material, please see the LICENCE file in the top-level directory. + +include $(TOPDIR)/rules.mk + +PKG_NAME:= mtd-utils +PKG_VERSION:= 1.5.0 +PKG_RELEASE:= 1 +PKG_MD5SUM:= a4df1ad29684be79b0fa699bdae01faf +PKG_SITES:= http://openadk.org/distfiles/ + +include ../rules.mk + +install: ${STAGING_HOST_DIR}/usr/bin/mkfs.jffs2 + +$(WRKBUILD)/.compiled: ${WRKDIST}/.prepared + ${MAKE} -C ${WRKBUILD} CC='${CC_FOR_BUILD}' CPPFLAGS='-DWITHOUT_XATTR=1 -I./include' + touch $@ + +${STAGING_HOST_DIR}/usr/bin/mkfs.jffs2: $(WRKBUILD)/.compiled + $(INSTALL_BIN) $(WRKBUILD)/mkfs.jffs2 \ + ${STAGING_HOST_DIR}/usr/bin + +include $(TOPDIR)/mk/tools.mk diff --git a/tools/mtd-utils/patches/lzo.patch b/tools/mtd-utils/patches/lzo.patch new file mode 100644 index 000000000..52f16146c --- /dev/null +++ b/tools/mtd-utils/patches/lzo.patch @@ -0,0 +1,88 @@ +diff -Nur mtd-utils-1.5.0.orig/compr.c mtd-utils-1.5.0/compr.c +--- mtd-utils-1.5.0.orig/compr.c 2012-05-07 09:19:39.000000000 +0200 ++++ mtd-utils-1.5.0/compr.c 2014-02-25 21:05:20.000000000 +0100 +@@ -517,9 +517,6 @@ + #ifdef CONFIG_JFFS2_RTIME + jffs2_rtime_init(); + #endif +-#ifdef CONFIG_JFFS2_LZO +- jffs2_lzo_init(); +-#endif + return 0; + } + +@@ -531,8 +528,5 @@ + #ifdef CONFIG_JFFS2_ZLIB + jffs2_zlib_exit(); + #endif +-#ifdef CONFIG_JFFS2_LZO +- jffs2_lzo_exit(); +-#endif + return 0; + } +diff -Nur mtd-utils-1.5.0.orig/Makefile mtd-utils-1.5.0/Makefile +--- mtd-utils-1.5.0.orig/Makefile 2012-05-07 09:19:39.000000000 +0200 ++++ mtd-utils-1.5.0/Makefile 2014-02-25 21:13:03.000000000 +0100 +@@ -16,27 +16,13 @@ + + TESTS = tests + +-MTD_BINS = \ +- ftl_format flash_erase nanddump doc_loadbios \ +- ftl_check mkfs.jffs2 flash_lock flash_unlock \ +- flash_otp_info flash_otp_dump mtd_debug flashcp nandwrite nandtest \ +- jffs2dump \ +- nftldump nftl_format docfdisk \ +- rfddump rfdformat \ +- serve_image recv_image \ +- sumtool jffs2reader +-UBI_BINS = \ +- ubiupdatevol ubimkvol ubirmvol ubicrc32 ubinfo ubiattach \ +- ubidetach ubinize ubiformat ubirename mtdinfo ubirsvol ++MTD_BINS = mkfs.jffs2 + + BINS = $(MTD_BINS) +-BINS += mkfs.ubifs/mkfs.ubifs +-BINS += $(addprefix ubi-utils/,$(UBI_BINS)) + SCRIPTS = flash_eraseall + + TARGETS = $(BINS) + TARGETS += lib/libmtd.a +-TARGETS += ubi-utils/libubi.a + + OBJDEPS = $(BUILDDIR)/include/version.h + +@@ -83,12 +69,12 @@ + # + # Utils in top level + # +-obj-mkfs.jffs2 = compr_rtime.o compr_zlib.o compr_lzo.o compr.o rbtree.o +-LDFLAGS_mkfs.jffs2 = $(ZLIBLDFLAGS) $(LZOLDFLAGS) +-LDLIBS_mkfs.jffs2 = -lz $(LZOLDLIBS) ++obj-mkfs.jffs2 = compr_rtime.o compr_zlib.o compr.o rbtree.o ++LDFLAGS_mkfs.jffs2 = $(ZLIBLDFLAGS) ++LDLIBS_mkfs.jffs2 = -lz + +-LDFLAGS_jffs2reader = $(ZLIBLDFLAGS) $(LZOLDFLAGS) +-LDLIBS_jffs2reader = -lz $(LZOLDLIBS) ++LDFLAGS_jffs2reader = $(ZLIBLDFLAGS) ++LDLIBS_jffs2reader = -lz + + $(foreach v,$(MTD_BINS),$(eval $(call mkdep,,$(v)))) + +@@ -103,7 +89,7 @@ + # + obj-mkfs.ubifs = crc16.o lpt.o compr.o devtable.o \ + hashtable/hashtable.o hashtable/hashtable_itr.o +-LDLIBS_mkfs.ubifs = -lz -llzo2 -lm -luuid ++LDLIBS_mkfs.ubifs = -lz -lm -luuid + $(call mkdep,mkfs.ubifs/,mkfs.ubifs,,ubi-utils/libubi.a) + + # +@@ -117,6 +103,3 @@ + obj-mtdinfo = libubigen.a + obj-ubinize = libubigen.a libiniparser.a + obj-ubiformat = libubigen.a libscan.a +- +-$(foreach v,libubi.a libubigen.a libiniparser.a libscan.a,$(eval $(call _mkdep,ubi-utils/,$(v)))) +-$(foreach v,$(UBI_BINS),$(eval $(call mkdep,ubi-utils/,$(v),libubi.a ubiutils-common.o))) diff --git a/tools/squashfs/Makefile b/tools/squashfs/Makefile new file mode 100644 index 000000000..423008ff8 --- /dev/null +++ b/tools/squashfs/Makefile @@ -0,0 +1,29 @@ +# This file is part of the OpenADK project. OpenADK is copyrighted +# material, please see the LICENCE file in the top-level directory. + +include $(TOPDIR)/rules.mk + +PKG_NAME:= squashfs +PKG_VERSION:= 4.2 +PKG_RELEASE:= 1 +PKG_MD5SUM:= 1b7a781fb4cf8938842279bd3e8ee852 +PKG_SITES:= ${MASTER_SITE_SOURCEFORGE:=squashfs/} + +DISTFILES:= ${PKG_NAME}${PKG_VERSION}.tar.gz +WRKDIST= ${WRKDIR}/$(PKG_NAME)${PKG_VERSION} + +include ../rules.mk + +install: ${STAGING_HOST_DIR}/usr/bin/mksquashfs + +$(WRKBUILD)/.compiled: ${WRKDIST}/.prepared + ${MAKE} -C ${WRKBUILD}/squashfs-tools CC='${CC_FOR_BUILD}' \ + XZ_SUPPORT=1 CPPFLAGS_FOR_BUILD=$(CPPFLAGS_FOR_BUILD) \ + EXTRA_LDFLAGS=$(LDFLAGS_FOR_BUILD) + @touch $@ + +${STAGING_HOST_DIR}/usr/bin/mksquashfs: $(WRKBUILD)/.compiled + $(INSTALL_BIN) $(WRKBUILD)/squashfs-tools/mksquashfs \ + ${STAGING_HOST_DIR}/usr/bin + +include $(TOPDIR)/mk/tools.mk diff --git a/tools/squashfs/patches/cppflags.patch b/tools/squashfs/patches/cppflags.patch new file mode 100644 index 000000000..1432ea3cf --- /dev/null +++ b/tools/squashfs/patches/cppflags.patch @@ -0,0 +1,12 @@ +diff -Nur squashfs4.2.orig/squashfs-tools/Makefile squashfs4.2/squashfs-tools/Makefile +--- squashfs4.2.orig/squashfs-tools/Makefile 2011-02-28 21:04:15.000000000 +0100 ++++ squashfs4.2/squashfs-tools/Makefile 2013-12-27 13:49:22.000000000 +0100 +@@ -93,7 +93,7 @@ + # End of BUILD options section # + ############################################### + +-INCLUDEDIR = -I. ++INCLUDEDIR = -I. $(CPPFLAGS_FOR_BUILD) + INSTALL_DIR = /usr/local/bin + + MKSQUASHFS_OBJS = mksquashfs.o read_fs.o sort.o swap.o pseudo.o compressor.o diff --git a/tools/srec2bin/Makefile b/tools/srec2bin/Makefile new file mode 100644 index 000000000..01021c8ff --- /dev/null +++ b/tools/srec2bin/Makefile @@ -0,0 +1,4 @@ +include $(TOPDIR)/rules.mk + +all: srec2bin.c + $(CC_FOR_BUILD) $(FLAGS_FOR_BUILD) -o ${STAGING_HOST_DIR}/usr/bin/srec2bin srec2bin.c diff --git a/tools/srec2bin/srec2bin.c b/tools/srec2bin/srec2bin.c new file mode 100644 index 000000000..8ba4387e6 --- /dev/null +++ b/tools/srec2bin/srec2bin.c @@ -0,0 +1,521 @@ +#include +#include +#include + +//Rev 0.1 Original +// 8 Jan 2001 MJH Added code to write data to Binary file +// note: outputfile is name.bin, where name is first part +// of input file. ie tmp.rec -> tmp.bin +// +// srec2bin +// +// TAG +// bit32u TAG_BIG = 0xDEADBE42; +// bit32u TAG_LITTLE = 0xFEEDFA42; +// +// File Structure +// +// TAG : 32 Bits +// [DATA RECORDS] +// +// Data Records Structure +// +// LENGTH : 32 Bits <- Length of DATA, excludes ADDRESS and CHECKSUM +// ADDRESS : 32 Bits +// DATA : 8 Bits * LENGTH +// CHECKSUM: 32 Bits <- 0 - (Sum of Length --> End of Data) +// +// Note : If Length == 0, Address will be Program Start +// +// +// +// +// + +#define MajRevNum 0 +#define MinRevNum 2 + + +#define EndianSwitch(x) ((x >> 24) | (x << 24) | ((x << 8) & (0x00FF0000)) | ((x >> 8) & (0x0000FF00)) ) + +typedef unsigned char bit8u; +typedef unsigned int bit32u; +typedef int bit32; + +#define FALSE 0 +#define TRUE (!FALSE) + + +bit32u CheckSum; +int RecStart; +int debug; +int verbose; + +FILE *OpenOutputFile( char *Name ); +FILE *fOut; +bit32u RecLength=0; + +bit32u AddressCurrent; + +bit32u gh(char *cp,int nibs); + +int BigEndian; + +int inputline; + +// char buf[16*1024]; + +char buffer[2048]; +char *cur_ptr; +int cur_line=0; +int cur_len=0; + +int s1s2s3_total=0; + +bit32u PBVal; +int PBValid; +bit32u PBAdr; + + +void dumpfTell(char *s, bit32u Value) +{ + int Length; + Length = (int) RecLength; + if (debug) + printf("[%s ] ftell()[0x%08lX] Length[0x%4X] Length[%4d] Value[0x%08x]\n", + s, ftell(fOut), Length, Length, Value); +} + +void DispHex(bit32u Hex) +{ +// printf("%X", Hex); +} + +void WaitDisplay(void) +{ + static int Count=0; + static int Index=0; + char iline[]={"-\\|/"}; + + Count++; + if ((Count % 32)==0) + { + if (verbose) + printf("%c%c",iline[Index++],8); + Index &= 3; + } +} + + +void binOut32 ( bit32u Data ) +{ +// On UNIX machine all 32bit writes need ENDIAN switched +// Data = EndianSwitch(Data); +// fwrite( &Data, sizeof(bit32u), 1, fOut); + + char sdat[4]; + int i; + + for(i=0;i<4;i++) + sdat[i]=(char)(Data>>(i*8)); + fwrite( sdat, 1, 4, fOut); + dumpfTell("Out32" , Data); +} + +// Only update RecLength on Byte Writes +// All 32 bit writes will be for Length etc + +void binOut8 ( bit8u Data ) +{ + int n; + dumpfTell("B4Data" , (bit32u) (Data & 0xFF) ); + n = fwrite( &Data, sizeof(bit8u), 1, fOut); + if (n != 1) + printf("Error in writing %X for Address 0x%8X\n", Data, AddressCurrent); + RecLength += 1; +} + +// Currently ONLY used for outputting Program Start + +void binRecStart(bit32u Address) +{ + RecLength = 0; + CheckSum = Address; + RecStart = TRUE; + + if (debug) + printf("[RecStart] CheckSum[0x%08X] Length[%4d] Address[0x%08X]\n", + CheckSum, RecLength, Address); + + + dumpfTell("RecLength", RecLength); + binOut32( RecLength ); + dumpfTell("Address", Address); + binOut32( Address ); +} + +void binRecEnd(void) +{ + long RecEnd; + + if (!RecStart) // if no record started, do not end it + { + return; + } + + RecStart = FALSE; + + + RecEnd = ftell(fOut); // Save Current position + + if (debug) + printf("[RecEnd ] CheckSum[0x%08X] Length[%4d] Length[0x%X] RecEnd[0x%08lX]\n", + CheckSum, RecLength, RecLength, RecEnd); + + fseek( fOut, -((long) RecLength), SEEK_CUR); // move back Start Of Data + + dumpfTell("Data ", -1); + + fseek( fOut, -4, SEEK_CUR); // move back Start Of Address + + dumpfTell("Address ", -1); + + fseek( fOut, -4, SEEK_CUR); // move back Start Of Length + + dumpfTell("Length ", -1); + + binOut32( RecLength ); + + fseek( fOut, RecEnd, SEEK_SET); // move to end of Record + + CheckSum += RecLength; + + CheckSum = ~CheckSum + 1; // Two's complement + + binOut32( CheckSum ); + + if (verbose) + printf("[Created Record of %d Bytes with CheckSum [0x%8X]\n", RecLength, CheckSum); +} + +void binRecOutProgramStart(bit32u Address) +{ + if (Address != (AddressCurrent+1)) + { + binRecEnd(); + binRecStart(Address); + } + AddressCurrent = Address; +} +void binRecOutByte(bit32u Address, bit8u Data) +{ + // If Address is one after Current Address, output Byte + // If not, close out last record, update Length, write checksum + // Then Start New Record, updating Current Address + + if (Address != (AddressCurrent+1)) + { + binRecEnd(); + binRecStart(Address); + } + AddressCurrent = Address; + CheckSum += Data; + binOut8( Data ); +} + +//============================================================================= +// SUPPORT FUNCTIONS +//============================================================================= +int readline(FILE *fil,char *buf,int len) +{ + int rlen; + + rlen=0; + if (len==0) return(0); + while(1) + { + if (cur_len==0) + { + cur_len=fread(buffer, 1, sizeof(buffer), fil); + if (cur_len==0) + { + if (rlen) + { + *buf=0; + return(rlen); + } + return(-1); + } + cur_ptr=buffer; + } + if (cur_len) + { + if (*cur_ptr=='\n') + { + *buf=0; + cur_ptr++; + cur_len--; + return(rlen); + } + else + { + if ((len>1)&&(*cur_ptr!='\r')) + { + *buf++=*cur_ptr++; + len--; + } + else + cur_ptr++; + + rlen++; + cur_len--; + } + } + else + { + *buf=0; + cur_ptr++; + cur_len--; + return(rlen); + } + } +} + + +int SRLerrorout(char *c1,char *c2) +{ + printf("\nERROR: %s - '%s'.",c1,c2); + return(FALSE); +} + + +int checksum(char *cp,int count) +{ + char *scp; + int cksum; + int dum; + + scp=cp; + while(*scp) + { + if (!isxdigit(*scp++)) + return(SRLerrorout("Invalid hex digits",cp)); + } + scp=cp; + + cksum=count; + + while(count) + { + cksum += gh(scp,2); + if (count == 2) + dum = ~cksum; + scp += 2; + count--; + } + cksum&=0x0ff; + // printf("\nCk:%02x",cksum); + return(cksum==0x0ff); +} + +bit32u gh(char *cp,int nibs) +{ + int i; + bit32u j; + + j=0; + + for(i=0;i='a')&&(*cp<='z')) *cp &= 0x5f; + if ((*cp>='0')&&(*cp<='9')) + j += (*cp-0x30); + else + if ((*cp>='A')&&(*cp<='F')) + j += (*cp-0x37); + else + SRLerrorout("Bad Hex char", cp); + cp++; + } + return(j); +} + + +//============================================================================= +// PROCESS SREC LINE +//============================================================================= + +int srecLine(char *pSrecLine) +{ + char *scp,ch; + int itmp,count,dat; + bit32u adr; + static bit32u RecordCounter=0; + + cur_line++; + scp=pSrecLine; + + if (*pSrecLine!='S') + return(SRLerrorout("Not an Srecord file",scp)); + pSrecLine++; + if (strlen(pSrecLine)<4) + return(SRLerrorout("Srecord too short",scp)); + + ch=*pSrecLine++; + + count=gh(pSrecLine,2); + + pSrecLine += 2; + + // if(debug) + // printf("count %d, strlen(pSrecLine) = %d, pSrecLine =[%s]\n", count, strlen(pSrecLine), pSrecLine); + RecordCounter++; + DispHex(RecordCounter); + + if ((count*2) != strlen(pSrecLine)) return(SRLerrorout("Count field larger than record",scp)); + + if (!checksum(pSrecLine, count)) return(SRLerrorout("Bad Checksum",scp)); + + switch(ch) + { + case '0': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); + itmp=gh(pSrecLine,4); pSrecLine+=4; count-=2; + if (itmp) return(SRLerrorout("Srecord 1 address not zero",scp)); + break; + case '1': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); + return(SRLerrorout("Srecord Not valid for MIPS",scp)); + break; + case '2': if (count<4) return(SRLerrorout("Invalid Srecord count field",scp)); + return(SRLerrorout("Srecord Not valid for MIPS",scp)); + break; + case '3': if (count<5) return(SRLerrorout("Invalid Srecord count field",scp)); + adr=gh(pSrecLine,8); pSrecLine+=8; count-=4; + count--; + while(count) + { + dat=gh(pSrecLine,2); pSrecLine+=2; count--; + binRecOutByte(adr, (char) (dat & 0xFF)); + adr++; + } + s1s2s3_total++; + break; + case '4': return(SRLerrorout("Invalid Srecord type",scp)); + break; + case '5': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); + itmp=gh(pSrecLine,4); pSrecLine+=4; count-=2; + if (itmp|=s1s2s3_total) return(SRLerrorout("Incorrect number of S3 Record processed",scp)); + break; + case '6': return(SRLerrorout("Invalid Srecord type",scp)); + break; + case '7': // PROGRAM START + if (count<5) return(SRLerrorout("Invalid Srecord count field",scp)); + adr=gh(pSrecLine,8); pSrecLine+=8; count-=4; + if (count!=1) return(SRLerrorout("Invalid Srecord count field",scp)); + binRecOutProgramStart(adr); + break; + case '8': if (count<4) return(SRLerrorout("Invalid Srecord count field",scp)); + return(SRLerrorout("Srecord Not valid for MIPS",scp)); + break; + case '9': if (count<3) return(SRLerrorout("Invalid Srecord count field",scp)); + return(SRLerrorout("Srecord Not valid for MIPS",scp)); + break; + default: + break; + } + return(TRUE); +} + + +//============================================================================= +// MAIN LOGIC, READS IN LINE AND OUTPUTS BINARY +//============================================================================= + +int srec2bin(int argc,char *argv[],int verbose) +{ + int rlen,sts; + FILE *fp; + char buff[256]; + bit32u TAG_BIG = 0xDEADBE42; + bit32u TAG_LITTLE = 0xFEEDFA42; + + bit32u Tag; + + + if(argc < 3) + { + printf("\nError: \n\n"); + return(0); + } + + if (argc > 3) BigEndian=TRUE; else BigEndian=FALSE; + + if (BigEndian) + Tag = TAG_BIG; + else + Tag = TAG_LITTLE; + + if (verbose) + printf("\nEndian: %s, Tag is 0x%8X\n",(BigEndian)?"BIG":"LITTLE", Tag); + + fp = fopen(argv[1],"rt"); + + if (fp==NULL) + { + printf("\nError: Opening input file, %s.", argv[1]); + return(0); + } + + fOut = fopen( argv[2], "wb"); + + if (fOut==NULL) + { + printf("\nError: Opening Output file, %s.", argv[2]); + if(fp) fclose(fp); + return(0); + } + + RecStart = FALSE; + + AddressCurrent = 0xFFFFFFFFL; + + // Setup Tag + + dumpfTell("Tag", Tag); + + binOut32(Tag); + + + inputline=0; + sts=TRUE; + + rlen = readline(fp,buff,sizeof buff); + + while( (sts) && (rlen != -1)) + { + if (strlen(buff)) + { + sts &= srecLine(buff); + WaitDisplay(); + } + rlen = readline(fp,buff,sizeof buff); + } + + + // printf("PC: 0x%08X, Length 0x%08X, Tag 0x%08X\n", ProgramStart, RecLength, TAG_LITTLE); + + binRecEnd(); + + if(fp) fclose(fp); + if(fOut) fclose(fOut); + + return(1); +} + +int main(int argc, char *argv[]) +{ + debug = FALSE; + verbose = FALSE; + srec2bin(argc,argv,verbose); + return 0; +} diff --git a/tools/syslinux/Makefile b/tools/syslinux/Makefile index 5543813d5..1344538d1 100644 --- a/tools/syslinux/Makefile +++ b/tools/syslinux/Makefile @@ -12,27 +12,26 @@ PKG_SITES:= http://www.kernel.org/pub/linux/utils/boot/syslinux/ include ../rules.mk WRKINST:= ${WRKBUILD}/openadk_installroot -install: ${BIN_DIR}/extlinux ${STAGING_HOST_DIR}/usr/share/syslinux/.installed +install: ${STAGING_HOST_DIR}/usr/bin/extlinux ${STAGING_HOST_DIR}/usr/share/syslinux/.installed $(WRKBUILD)/.compiled: ${WRKDIST}/.prepared - #(cd ${WRKBUILD}; ./configure) ${MAKE} -C ${WRKBUILD} CC='${CC_FOR_BUILD}' bios installer - touch $@ + @touch $@ $(WRKBUILD)/.installed: ${WRKBUILD}/.compiled mkdir -p ${WRKINST} ${MAKE} -C ${WRKBUILD} CC='${CC_FOR_BUILD}' \ INSTALLROOT='${WRKINST}' \ bios install - touch $@ + @touch $@ -${BIN_DIR}/extlinux: $(WRKBUILD)/.installed +${STAGING_HOST_DIR}/usr/bin/extlinux: $(WRKBUILD)/.installed $(INSTALL_BIN) ${WRKINST}/sbin/extlinux \ - ${BIN_DIR} + ${STAGING_HOST_DIR}/usr/bin ${STAGING_HOST_DIR}/usr/share/syslinux/.installed: ${WRKBUILD}/.installed mkdir -p ${STAGING_HOST_DIR}/usr/share ${CP} ${WRKINST}/usr/share/syslinux ${STAGING_HOST_DIR}/usr/share - touch ${STAGING_HOST_DIR}/usr/share/syslinux/.installed + @touch ${STAGING_HOST_DIR}/usr/share/syslinux/.installed include $(TOPDIR)/mk/tools.mk diff --git a/tools/trx/Makefile b/tools/trx/Makefile new file mode 100644 index 000000000..25e2b02db --- /dev/null +++ b/tools/trx/Makefile @@ -0,0 +1,4 @@ +include $(TOPDIR)/rules.mk + +all: trx.c + $(CC_FOR_BUILD) $(FLAGS_FOR_BUILD) -o ${STAGING_HOST_DIR}/usr/bin/trx trx.c diff --git a/tools/trx/trx.c b/tools/trx/trx.c new file mode 100644 index 000000000..9e4d521ca --- /dev/null +++ b/tools/trx/trx.c @@ -0,0 +1,366 @@ +/* + * Copyright (C) 2004 Manuel Novoa III + * Copyright (C) 2005 Konstantin A. Klubnichkin and Oleg I. Vdovikin + * Copyright (C) 2006 OpenWrt developers + * Copyright (C) 2011 Waldemar Brodkorb + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include +#include +#include +#include +#include +#include +#include + +uint32_t crc32buf(char *buf, size_t len); + +/**********************************************************************/ +/* from trxhdr.h */ + +#define TRX_MAGIC 0x30524448 /* "HDR0" */ +#define TRX_VERSION 1 +#define TRX_MAX_LEN 0x697800 +#define TRX_NO_HEADER 1 /* Do not write TRX header */ + +struct trx_header { + uint32_t magic; /* "HDR0" */ + uint32_t len; /* Length of file including header */ + uint32_t crc32; /* 32-bit CRC from flag_version to end of file */ + uint32_t flag_version; /* 0:15 flags, 16:31 version */ + uint32_t offsets[3]; /* Offsets of partitions from start of header */ +}; + +/**********************************************************************/ + +void usage(void) __attribute__ (( __noreturn__ )); + +void usage(void) +{ + fprintf(stderr, "Usage: trx [-p product_id] [-v version] [-o outfile] [-m maxlen] [-a align] [-b offset] -f file [-f file [-f file]]\n"); + exit(EXIT_FAILURE); +} + +int main(int argc, char **argv) +{ + FILE *out = stdout; + FILE *in; + char *ofn = NULL; + char *buf; + char *e; + int c, i; + size_t n; + uint32_t cur_len; + unsigned long maxlen = TRX_MAX_LEN; + struct trx_header *p; + + struct { + uint8_t version[4]; /* Firmware version */ + uint8_t prod_id[12]; /* Product Id */ + uint8_t comp_hw[4][4]; /* Compatible hw list maj-min min/maj-min max */ + uint8_t pad[32]; /* Padding */ + } asus = { + .version = { 1, 9, 2, 7 }, /* version is set to 1.9.2.7 by default */ + .comp_hw[0] = { 0, 2, 2, 99 } /* hardcoded hw compat list 0.02 - 2.99 */ + }; + + + if (!(buf = malloc(maxlen))) { + fprintf(stderr, "malloc failed\n"); + return EXIT_FAILURE; + } + + p = (struct trx_header *) buf; + + p->magic = TRX_MAGIC; + cur_len = sizeof(struct trx_header); + p->flag_version = (TRX_VERSION << 16); + + in = NULL; + i = 0; + + while ((c = getopt(argc, argv, "-:o:p:v:m:a:b:f:")) != -1) { + switch (c) { + case 'f': + p->offsets[i++] = cur_len; + + if (!(in = fopen(optarg, "r"))) { + fprintf(stderr, "can not open \"%s\" for reading\n", optarg); + usage(); + } + n = fread(buf + cur_len, 1, maxlen - cur_len, in); + if (!feof(in)) { + fprintf(stderr, "fread failure or file \"%s\" too large\n",optarg); + fclose(in); + return EXIT_FAILURE; + } + fclose(in); +#undef ROUND +#define ROUND 4 + if (n & (ROUND-1)) { + memset(buf + cur_len + n, 0, ROUND - (n & (ROUND-1))); + n += ROUND - (n & (ROUND-1)); + } + cur_len += n; + /* reserve space for asus footer */ + if (asus.prod_id[0]) { + cur_len += sizeof(asus); + } + break; + case 'o': + ofn = optarg; + if (ofn && !(out = fopen(ofn, "w"))) { + fprintf(stderr, "can not open \"%s\" for writing\n", ofn); + usage(); + } + + break; + case 'm': + errno = 0; + maxlen = strtoul(optarg, &e, 0); + if (errno || (e == optarg) || *e) { + fprintf(stderr, "illegal numeric string\n"); + usage(); + } +#undef ROUND +#define ROUND 0x1000 + if (maxlen & (ROUND-1)) { + maxlen += (ROUND - (maxlen & (ROUND-1))); + } + if (maxlen < ROUND) { + fprintf(stderr, "maxlen too small (or wrapped)\n"); + usage(); + } + if (maxlen > TRX_MAX_LEN) { + fprintf(stderr, "WARNING: maxlen exceeds default maximum! Beware of overwriting nvram!\n"); + } + if (!(buf = realloc(buf,maxlen))) { + fprintf(stderr, "realloc failed"); + return EXIT_FAILURE; + } + break; + case 'a': + errno = 0; + n = strtoul(optarg, &e, 0); + if (errno || (e == optarg) || *e) { + fprintf(stderr, "illegal numeric string\n"); + usage(); + } + if (cur_len & (n-1)) { + n = n - (cur_len & (n-1)); + memset(buf + cur_len, 0, n); + cur_len += n; + } + break; + case 'b': + errno = 0; + n = strtoul(optarg, &e, 0); + if (errno || (e == optarg) || *e) { + fprintf(stderr, "illegal numeric string\n"); + usage(); + } + if (n < cur_len) { + fprintf(stderr, "WARNING: current length exceeds -b %d offset\n",(int)n); + } else { + memset(buf + cur_len, 0, n - cur_len); + cur_len = n; + } + break; + case 'p': + if ((n = strlen(optarg)) > sizeof(asus.prod_id)) { + fprintf(stderr, "product id too long\n"); + usage(); + } + memset(asus.prod_id, ' ', sizeof(asus.prod_id)); + memcpy(asus.prod_id, optarg, n); + break; + case 'v': + for (n = 0; n < sizeof(asus.version) / sizeof(asus.version[0]); n++) + { + if (n != 0 && optarg[0] == '.' && optarg[1]) optarg++; + else if (n != 0) break; + + asus.version[n] = strtoul(optarg, &optarg, 10); + } + if (*optarg) + { + fprintf(stderr, "invalid version string\n"); + usage(); + } + break; + default: + usage(); + } + } + + if (!in) { + fprintf(stderr, "we require at least one filename\n"); + usage(); + } + +#undef ROUND +#define ROUND 0x1000 + n = cur_len & (ROUND-1); + if (n) { + memset(buf + cur_len, 0, ROUND - n); + cur_len += ROUND - n; + } + /* add asus footer */ + if (asus.prod_id[0]) { + memcpy(buf + cur_len - sizeof(asus), &asus, sizeof(asus)); + } + + p->crc32 = crc32buf((char *) &p->flag_version, + cur_len - offsetof(struct trx_header, flag_version)); + p->crc32 = p->crc32; + + p->len = cur_len; + + if (!fwrite(buf, cur_len, 1, out) || fflush(out)) { + fprintf(stderr, "fwrite failed\n"); + return EXIT_FAILURE; + } + + fclose(out); + + return EXIT_SUCCESS; +} + +/**********************************************************************/ +/* The following was grabbed and tweaked from the old snippets collection + * of public domain C code. */ + +/**********************************************************************\ +|* Demonstration program to compute the 32-bit CRC used as the frame *| +|* check sequence in ADCCP (ANSI X3.66, also known as FIPS PUB 71 *| +|* and FED-STD-1003, the U.S. versions of CCITT's X.25 link-level *| +|* protocol). The 32-bit FCS was added via the Federal Register, *| +|* 1 June 1982, p.23798. I presume but don't know for certain that *| +|* this polynomial is or will be included in CCITT V.41, which *| +|* defines the 16-bit CRC (often called CRC-CCITT) polynomial. FIPS *| +|* PUB 78 says that the 32-bit FCS reduces otherwise undetected *| +|* errors by a factor of 10^-5 over 16-bit FCS. *| +\**********************************************************************/ + +/* Copyright (C) 1986 Gary S. Brown. You may use this program, or + code or tables extracted from it, as desired without restriction.*/ + +/* First, the polynomial itself and its table of feedback terms. The */ +/* polynomial is */ +/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */ +/* Note that we take it "backwards" and put the highest-order term in */ +/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */ +/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */ +/* the MSB being 1. */ + +/* Note that the usual hardware shift register implementation, which */ +/* is what we're using (we're merely optimizing it by doing eight-bit */ +/* chunks at a time) shifts bits into the lowest-order term. In our */ +/* implementation, that means shifting towards the right. Why do we */ +/* do it this way? Because the calculated CRC must be transmitted in */ +/* order from highest-order term to lowest-order term. UARTs transmit */ +/* characters in order from LSB to MSB. By storing the CRC this way, */ +/* we hand it to the UART in the order low-byte to high-byte; the UART */ +/* sends each low-bit to hight-bit; and the result is transmission bit */ +/* by bit from highest- to lowest-order term without requiring any bit */ +/* shuffling on our part. Reception works similarly. */ + +/* The feedback terms table consists of 256, 32-bit entries. Notes: */ +/* */ +/* 1. The table can be generated at runtime if desired; code to do so */ +/* is shown later. It might not be obvious, but the feedback */ +/* terms simply represent the results of eight shift/xor opera- */ +/* tions for all combinations of data and CRC register values. */ +/* */ +/* 2. The CRC accumulation logic is the same for all CRC polynomials, */ +/* be they sixteen or thirty-two bits wide. You simply choose the */ +/* appropriate table. Alternatively, because the table can be */ +/* generated at runtime, you can start by generating the table for */ +/* the polynomial in question and use exactly the same "updcrc", */ +/* if your application needn't simultaneously handle two CRC */ +/* polynomials. (Note, however, that XMODEM is strange.) */ +/* */ +/* 3. For 16-bit CRCs, the table entries need be only 16 bits wide; */ +/* of course, 32-bit entries work OK if the high 16 bits are zero. */ +/* */ +/* 4. The values must be right-shifted by eight bits by the "updcrc" */ +/* logic; the shift must be unsigned (bring in zeroes). On some */ +/* hardware you could probably optimize the shift in assembler by */ +/* using byte-swap instructions. */ + +static const uint32_t crc_32_tab[] = { /* CRC polynomial 0xedb88320 */ +0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, +0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, +0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, +0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, +0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, +0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, +0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, +0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, +0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, +0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, +0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, +0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, +0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, +0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, +0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, +0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, +0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, +0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, +0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, +0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, +0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, +0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, +0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, +0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, +0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, +0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, +0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, +0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, +0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, +0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, +0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, +0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, +0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, +0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, +0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, +0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, +0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, +0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, +0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, +0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, +0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, +0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, +0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +#define UPDC32(octet,crc) (crc_32_tab[((crc) ^ (octet)) & 0xff] ^ ((crc) >> 8)) + +uint32_t crc32buf(char *buf, size_t len) +{ + uint32_t crc; + + crc = 0xFFFFFFFF; + + for ( ; len; --len, ++buf) + { + crc = UPDC32(*buf, crc); + } + + return crc; +} diff --git a/tools/xz/Makefile b/tools/xz/Makefile new file mode 100644 index 000000000..fa4c51f92 --- /dev/null +++ b/tools/xz/Makefile @@ -0,0 +1,28 @@ +# This file is part of the OpenADK project. OpenADK is copyrighted +# material, please see the LICENCE file in the top-level directory. + +include $(TOPDIR)/rules.mk + +PKG_NAME:= xz +PKG_VERSION:= 5.0.5 +PKG_RELEASE:= 1 +PKG_MD5SUM:= 1b7a781fb4cf8938842279bd3e8ee852 +PKG_SITES:= http://tukaani.org/xz/ + +include ../rules.mk + +install: $(WRKBUILD)/.installed + +$(WRKBUILD)/.configured: ${WRKDIST}/.prepared + (cd ${WRKBUILD}; ./configure --prefix=$(STAGING_HOST_DIR)/usr) + @touch $@ + +$(WRKBUILD)/.compiled: $(WRKBUILD)/.configured + ${MAKE} -C ${WRKBUILD} + @touch $@ + +$(WRKBUILD)/.installed: $(WRKBUILD)/.compiled + ${MAKE} -C ${WRKBUILD} install + @touch $@ + +include $(TOPDIR)/mk/tools.mk -- cgit v1.2.3