diff options
48 files changed, 2368 insertions, 7614 deletions
diff --git a/target/linux/realtek/Makefile b/target/linux/realtek/Makefile index b2d7fc865..2fad85649 100644 --- a/target/linux/realtek/Makefile +++ b/target/linux/realtek/Makefile @@ -23,14 +23,6 @@ define Target/Description Build firmware images for RTL8xxx based routers endef -define Kernel/CompileImage/Default - $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),,rm -f $(TARGET_DIR)/init) - +$(MAKE) $(KERNEL_MAKEOPTS) $(KERNELNAME) - $(MAKE) $(KERNEL_MAKEOPTS) -C rtkload - $(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL) - $(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux.elf -endef - $(eval $(call BuildTarget)) diff --git a/target/linux/realtek/files/rtkload/COPYING b/target/linux/realtek/files/rtkload/COPYING deleted file mode 100644 index 60549be51..000000000 --- a/target/linux/realtek/files/rtkload/COPYING +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) 19yy <name of author> - - 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 - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19yy name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - <signature of Ty Coon>, 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/target/linux/realtek/files/rtkload/Makefile b/target/linux/realtek/files/rtkload/Makefile deleted file mode 100644 index 235673bc7..000000000 --- a/target/linux/realtek/files/rtkload/Makefile +++ /dev/null @@ -1,282 +0,0 @@ -# The kernel tree you do builds in. -# Uncomment if you're building for the emulator -include ../.config -include ../../.config # to check toolchain CONFIG_RSDK_rsdk-1.5.4-5281-EB-2.6.30-0.9.30.3-uls-101110 -DOQUIET = false -#DOQUIET = true -#EMULATOR = true -#KERNEL_ROOT = /home/john/RealTek/linux-2.5/linux -KERNEL_ROOT = .. -ifeq ($(wildcard $(DIR_USERS)/boa/tools/cvimg),) -ifeq ($(wildcard $(DIR_USERS)/goahead-2.1.1/LINUX/cvimg),) -CVIMG=./cvimg -else -CVIMG=$(DIR_USERS)/goahead-2.1.1/LINUX/cvimg -endif -.NOTPARALLEL : all -else -CVIMG=$(DIR_USERS)/boa/tools/cvimg -endif -# ---- shouldn't need to modify below this line. - -ifdef EMULATOR -EMUOPTS = -DEMULATOR -LDSCRIPT = ld-emu.script -else -EMUOPTS = -LDSCRIPT = ld.script -endif - -COPTIONS = -DROM_MEMORY -DCOMPRESSED_KERNEL -D__KERNEL__ - -#SOURCES = vsprintf.c string.c ctype.c prom_printf.c misc.c hfload.c start.S read_memory.c -ifdef BZ2_COMPRESS - SOURCES = misc.c hfload.c start.S cache.c -else -ifdef GZIP_COMPRESS - SOURCES = string.c ctype.c misc.c hfload.c start.S read_memory.c cache.c -else - SOURCES = string.c ctype.c misc.c hfload.c start.S read_memory.c cache.c LzmaDecode.c -endif -endif - -LOADER_FILES = hfload.o read_memory.o -#LOADER_FILES = hfload.o -ifdef BZ2_COMPRESS - SUPPORT_FILES = misc.o cache.o -else -ifdef GZIP_COMPRESS - SUPPORT_FILES = vsprintf.o prom_printf.o string.o ctype.o misc.o cache.o -else -ifeq ($(strip $(DOQUIET)),true) - SUPPORT_FILES = string.o ctype.o misc.o cache.o LzmaDecode.o -else - SUPPORT_FILES = vsprintf.o prom_printf.o string.o ctype.o misc.o cache.o LzmaDecode.o -endif -endif -endif - -CFLAGS =-Os -g -fno-pic -mno-abicalls $(EMUOPTS) -ifeq ($(strip $(DOQUIET)),true) -CFLAGS += $(WARNINGS) -D__DO_QUIET__ -endif -CFLAGS += -DEMBEDDED -I$(KERNEL_ROOT)/include/linux -I$(KERNEL_ROOT)/include -I$(KERNEL_ROOT)/lib $(COPTIONS) -G 0 -CFLAGS += -I$(KERNEL_ROOT)/arch/rlx/bsp -I$(KERNEL_ROOT)/arch/rlx/include -I$(KERNEL_ROOT)/arch/rlx/include/asm/mach-generic -#ASFLAGS = -g $(EMUOPTS) -DEMBEDDED -I$(KERNEL_ROOT)/include -I$(KERNEL_ROOT)/arch/rlx/include -#CFLAGS += -I$(KERNEL_ROOT)/arch/mips/include -I$(KERNEL_ROOT)/arch/mips/include/asm/mach-generic -#ASFLAGS = -g $(EMUOPTS) -DEMBEDDED -I$(KERNEL_ROOT)/include -I$(KERNEL_ROOT)/arch/mips/include -ASFLAGS = -g -fno-pic -mno-abicalls $(EMUOPTS) -DEMBEDDED -I$(KERNEL_ROOT)/include -I$(KERNEL_ROOT)/arch/rlx/include - -LDFLAGS=-static -nostdlib - -ifdef BZ2_COMPRESS -CFLAGS += -DBZ2_COMPRESS -ASFLAGS += -DBZ2_COMPRESS -else -ifndef GZIP_COMPRESS -CFLAGS += -DLZMA_COMPRESS -ASFLAGS += -DLZMA_COMPRESS -endif -endif - -START_FILE = start.o - - -#RTL_819X normal LOAD_START_ADDR and FLASH_OFFSET -ifdef CONFIG_RTL_819X -LOAD_START_ADDR=0x80500000 -FLASH_OFFSET=30000 -endif - -ifdef CONFIG_RTL_8196B_GW -ifdef CONFIG_MTD_RTL_8196_SPI -LOAD_START_ADDR=0x80A00000 -else -LOAD_START_ADDR=0x80500000 -endif -ifdef CONFIG_RTL_8196B_GW_8M -FLASH_OFFSET=10000 -else -ifeq ($(CONFIG_RTL_FLASH_MAPPING_ENABLE),y) -ifeq ($(CONFIG_RTL_LINUX_IMAGE_OFFSET),) -FLASH_OFFSET=30000 -else -FLASH_OFFSET=$(CONFIG_RTL_LINUX_IMAGE_OFFSET) -endif -else -FLASH_OFFSET=30000 -endif -endif -endif - -ifdef CONFIG_RTL_8198_GW -ifdef CONFIG_MTD_RTL_8196_SPI -LOAD_START_ADDR=0x80A00000 -else -LOAD_START_ADDR=0x80500000 -endif -ifdef CONFIG_RTL_8196B_GW_8M -FLASH_OFFSET=10000 -else -FLASH_OFFSET=30000 -endif -endif - -ifdef CONFIG_RTL_8196B_ICT -LOAD_START_ADDR=0x80500000 -FLASH_OFFSET=30000 -endif - -ifdef CONFIG_RTL_865X_PANAHOST -LOAD_START_ADDR=0x80500000 -FLASH_OFFSET=20000 -endif - -ifdef CONFIG_RTL_8197B_PANA -LOAD_START_ADDR=0x80700000 -FLASH_OFFSET=30000 -endif - -ifdef CONFIG_RTL_8196B_AP_ROOT -LOAD_START_ADDR=0x80500000 -FLASH_OFFSET=30000 -endif - -ifeq ($(CONFIG_RTL_FLASH_MAPPING_ENABLE),y) -ifeq ($(CONFIG_RTL_LINUX_IMAGE_OFFSET),) -FLASH_OFFSET=20000 -else -FLASH_OFFSET=$(CONFIG_RTL_LINUX_IMAGE_OFFSET) -endif -else -FLASH_OFFSET=20000 -endif - -ifdef CONFIG_RTK_VOIP_BOARD -LOAD_START_ADDR=0x80C00000 -endif - -CV_SIGNATURE= -ifdef CONFIG_RTL_8197B_PANA -#CV_OPTION=linux -CV_OPTION=signature -CV_SIGNATURE=csys -else -ifdef CONFIG_SQUASHFS -CV_OPTION=linux-ro -else -CV_OPTION=linux -endif -endif - -ifdef CONFIG_RTL_8198_NFBI_BOARD -LOAD_START_ADDR=0x80700000 -FLASH_OFFSET=30000 -CV_OPTION=signature -CV_SIGNATURE=csys -endif - -#ifdef CONFIG_RTL_8196C_iNIC -#LOAD_START_ADDR=0x80500000 -#FLASH_OFFSET=30000 -#CV_OPTION=signature -#CV_SIGNATURE=cs6c -#endif - -CROSS_COMPILE ?= rsdk-linux- - -LD=$(CROSS_COMPILE)ld -CC=$(CROSS_COMPILE)gcc -CPP=$(CROSS_COMPILE)gcc -STRIP=$(CROSS_COMPILE)strip -AS=$(CROSS_COMPILE)as -NM=$(CROSS_COMPILE)nm -OBJCOPY=$(CROSS_COMPILE)objcopy - -SEDFLAGS = s/LOAD_ADDR/$(LOAD_START_ADDR)/; - -ifdef CONFIG_RTK_VOIP_BOARD -STRIP-OPTIONS-$(CONFIG_RSDK_rsdk-1.5.4-5281-EB-2.6.30-0.9.30.3-uls-101110) = --remove-section=.bss -endif - -# jffs2 related definitions -DIR_ROMFS_BOOT = $(DIR_ROMFS)/boot/ -MKJFFS2 = ./mkfs.jffs2 -MKIMAGE_UBOOT = ./mkimage-uboot - -O_TARGET := rtk -obj-y := vmlinux_img.o $(START_FILE) $(LOADER_FILES) $(SUPPORT_FILES) - -ifdef CONFIG_ROOTFS_JFFS2 -all: rtk-clean rtk-vmlinux_img vmlinux_img.gzip.uboot.jffs2 -else -all: rtk-clean rtk-vmlinux_img $(START_FILE) $(LOADER_FILES) $(SUPPORT_FILES) -endif - -#memload-partial -ifdef CONFIG_ROOTFS_JFFS2 -jffs2_no_this: -endif - $(CC) -fno-pic -mno-abicalls -Os -fomit-frame-pointer -D__KERNEL__ -c vmlinux_img.c -o vmlinux_img.o - $(OBJCOPY) --add-section .vmlinux=vmlinux_img.gz vmlinux_img.o - @sed "$(SEDFLAGS)" < ld.script.in > $(LDSCRIPT) - $(LD) $(LDFLAGS) -G 0 -T $(LDSCRIPT) -o memload-partial $(START_FILE) $(LOADER_FILES) $(SUPPORT_FILES) vmlinux_img.o - $(NM) memload-partial | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aU] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > system.map - - cp memload-partial memload-full - $(OBJCOPY) -Obinary memload-full nfjrom - $(CVIMG) $(CV_OPTION) nfjrom linux.bin $(LOAD_START_ADDR) $(FLASH_OFFSET) $(CV_SIGNATURE) -# @./size_chk vmlinux_img $(LOAD_START_ADDR) - @$(CVIMG) size_chk vmlinux_img $(LOAD_START_ADDR) || exit $$? -ifeq ($(CONFIG_BLK_DEV_INITRD),y) - @echo "RAMFS no need to check flash size" -else -ifeq ($(CONFIG_RTL_FLASH_MAPPING_ENABLE),y) - @$(CVIMG) flash_size_chk linux.bin || exit $$? -endif -endif - -rtk-clean: - rm -f *.o memload system.map nfjrom memload-partial memload-full vmlinux_img.gz target target.img strip1 linux.bin vmlinux-stripped $(LDSCRIPT) vmlinux_img vmlinux_img.gzip.uboot.jffs2 - -rtk-vmlinux_img: - cp $(KERNEL_ROOT)/vmlinux vmlinux-stripped - $(STRIP) vmlinux-stripped $(STRIP-OPTIONS-y) - $(OBJCOPY) -Obinary vmlinux-stripped vmlinux_img - rm -f vmlinux_img.gz -ifndef CONFIG_ROOTFS_JFFS2 -ifdef BZ2_COMPRESS - cat vmlinux_img | bzip2 -9v > vmlinux_img.gz -else -ifdef GZIP_COMPRESS - cat vmlinux_img | gzip -9v > vmlinux_img.gz -else - ./lzma e vmlinux_img vmlinux_img.gz -endif -endif - $(CVIMG) vmlinuxhdr vmlinux_img.gz vmlinux_img.gz $(KERNEL_ROOT)/vmlinux -endif # CONFIG_ROOTFS_JFFS2 - -target: nfjrom $(BOOT_CODE) $(EXT2_IMG) -# Pading boot code to 512 bytes long (but only 256 bytes are allowed, 512 is to make it page alignment) - $(OBJCOPY) -Obinary --pad-to=0x80000200 $(BOOT_CODE) bootcode - $(OBJCOPY) -Obinary --remove-section=.bss --remove-section=.data --remove-section=.mdebug --pad-to=0x806FFE00 memload-full nandrom - $(LD) -G0 -Ttarget.script -o target -bbinary bootcode -bbinary nandrom -bbinary $(EXT2_IMG) - $(OBJCOPY) -Obinary target target.img - cp -f ./target.img /tftpboot -depend: - rm -f .depend - $(CC) $(CFLAGS) -MM $(SOURCES) >.depend - -bz2: - @make BZ2_COMPRESS=1 - -gzip: - @make GZIP_COMPRESS=1 - -vmlinux_img.gzip.uboot.jffs2: - cat vmlinux_img | gzip -9v > vmlinux_img.gzip - mkdir -p $(DIR_ROMFS_BOOT) - $(MKIMAGE_UBOOT) -A mips -O linux -T kernel -C gzip -a 80000000 -e 80000000 -n 8954c_kernel -d vmlinux_img.gzip $(DIR_ROMFS_BOOT)/vmlinux_img.gzip.uboot - $(MKJFFS2) -n -p -b -e $(CONFIG_JFFS2_ERASE_SIZE) -o $(DIR_IMAGE)/vmlinux_img.gzip.uboot.jffs2 -d $(DIR_ROMFS) - diff --git a/target/linux/realtek/files/rtkload/README b/target/linux/realtek/files/rtkload/README deleted file mode 100644 index 236e144a1..000000000 --- a/target/linux/realtek/files/rtkload/README +++ /dev/null @@ -1,115 +0,0 @@ -hfload is a simple, second stage ELF bootloader for the VTech Helio. -It is probably generalizable to other Philips R3912 devices with a -friendly boot rom and flash. - -It works on both real Helio hardware and the Helio emulator. - -LEGAL STUFF -=========== - -This software is subject to the terms and conditions of the GNU -General Public License. See the file "COPYING" in the main directory -of this archive for more details. - -Copyright (C) 2000 by Jay Carlson. - -Many files originated in the Linux kernel. - -Note that my intent is that the last two stages of the build process -(production of the ELF memory image, and conversion to a raw ROM -image) are "mere aggregation [...] on a volume of a storage or -distribution medium" in the sense of the last paragraph of section 2 -of the GPL. If necessary, I will arrange that the aggregation -mechanism is "/bin/cat" or a simple C program, if anyone has a problem -with my use of a "linker" to throw together files in a single box. No -real linking is done at this stage; the Linux kernel is treated as -pure data. - -QUICK START -=========== - -Point the Makefile at your kernel build directory. If building for -the emulator, uncomment the EMULATOR line in the Makefile. - -If you don't have a romdisk image, touch romdisk. - -Put the first 64K of a 2M VT-OS rom image in "vtboot"; if you're -building for the real hardware you can fake it with "make fake-vtboot". - -"make" produces "tryrom" and "linux.bin". tryrom is a full 2M ROM -image for the emulator containing the VTOS bootloader, hfload, a -compressed stripped copy of your vmlinux, and the contents of romdisk. -linux.bin is a 2M-128k OS upgrade image without the VTOS bootloader, -suitable for use with the VTech "dt.exe" flash programming tool. - -WHAT IT DOES -============ - -On startup, the VT-OS bootroom sets up the hardware a little, installs -a 4k stack, and jumps to 0x9fc10000 in ROM. hfload begins here. - -Setup ------ - -start.S zeroes the hfload bss area. It moves the stack to somewhere -more spacious (paranoia), and jumps to main(). (It should turn on the -serial port too.) - -main() immediately prints a message on serial port A. (It used to try -to initialize the Helio LCD hardware, but that's commented out now.) - -Decompression -------------- - -The contents of the input_data-input_data_end region are gunzip'd from -flash to the 4M mark in memory, at the start of the second DRAM bank. - -input_data typically points to a gzip'd stripped Linux kernel. - -ELF load --------- - -main() reads in the ELF header from the decompressed data. -(Currently, the only error checking is verification that the declared -sizes of structures match the expected sizes; this catches most -errors.) The ELF image is copied to its destinations declared in the -program headers, and excess memory is properly zeroed. - -Kernel start ------------- - -main() hands the ELF entry address to start.S:start_kernel. -start_kernel places the address of the romdisk area at 0x80030000, -restores the stack, and calls entry_address(0,0,0). - -WHY THE IMAGE READ FUNCTIONS ARE SO UGLY -======================================== - -I originally debugged this application as a userland binary, reading -the image from a file descriptor. I then realized I could mmap() the -kernel image. The restrictions on read_struct, copy_to_region, and -seek_forward came out of this. As it turns out, the "can only seek -forward, must be aligned" characteristics may be useful in the future. -There's no reason why the entire kernel has to be uncompressed as a -big blob; the stream reading functions could be rewritten to process -the 32k decompressed windows as a coroutine to the decompression -process. ELF images over about 2M are going to need this. - -WHY THIS WHOLE APP IS SO UGLY -============================= - -Most of this will be rewritten once I understand better what I'm -trying to do. Why make throwaway code pretty? - -VTBOOT -====== - -The file "vtboot" is not included with this distribution. It is an -image of the VTech VT-OS bootloader that's hardwired into real Helio -devices. It's the first 64k of a full VT-OS rom image. Given such a -rom image, it can be extracted by: - - dd if=VTOS-1-1-03.rom of=vtboot bs=64k count=1 - -If you're building for the real hardware, you don't need this file. -"make fake-vtboot" produces 64k of zeroes. diff --git a/target/linux/realtek/files/rtkload/cache.c b/target/linux/realtek/files/rtkload/cache.c deleted file mode 100644 index 8e4ca57d8..000000000 --- a/target/linux/realtek/files/rtkload/cache.c +++ /dev/null @@ -1,197 +0,0 @@ -/* - * This file is subject to the terms and conditions of the GNU General Public - * License. See the file "COPYING" in the main directory of this archive - * for more details. - * - * Copyright (C) 1994 - 1999 by Ralf Baechle - * Modified for R3000 by Paul M. Antoine, 1995, 1996 - * Complete output from die() by Ulf Carlsson, 1998 - * Copyright (C) 1999 Silicon Graphics, Inc. - */ -//#include <linux/config.h> -#include <linux/autoconf.h> -#include <linux/linkage.h> -#include <asm/ptrace.h> -//#include <asm/mipsregs.h> -#include <asm/rlxregs.h> -#include <asm/addrspace.h> -//#include <asm/system.h> - -#if defined(CONFIG_RTL_819X) -/* For Realtek RTL865XC Network platform series */ -#define _ICACHE_SIZE (16 * 1024) /* 16K bytes */ -#define _DCACHE_SIZE (8 * 1024) /* 8K bytes */ -#define _CACHE_LINE_SIZE 4 /* 4 words */ -#endif - -#define PROM_DEBUG - -#ifdef PROM_DEBUG -extern int prom_printf(char *, ...); -#endif - -/*Cyrus Tsai*/ -void flush_cache(void); -void flush_icache(unsigned int start, unsigned int end); -void flush_dcache(unsigned int start, unsigned int end); -/*Cyrus Tsai*/ - - -void flush_cache(void) -{ -#ifdef CONFIG_RTL_EB8186 - flush_dcache(0,0); - flush_icache(0,0); -#endif -#if defined(CONFIG_RTL_819X) - flush_dcache(KSEG0, KSEG0+_DCACHE_SIZE); - flush_icache(KSEG0, KSEG0+_ICACHE_SIZE); -#endif -} - - -/*Cyrus Tsai*/ -void flush_icache(unsigned int start, unsigned int end) -{ -#if defined(CONFIG_RTL_819X) - /* - Flush data cache at first in write-back platform. - - Ghhuang (2007/3/9): - - RD-Center suggest that we need to flush D-cache entries which - might match to same address as I-cache ... when we flush - I-cache. - ( Maybe some data is treated as data/instruction, both. ) - */ - flush_dcache(start, end); - - /*Invalidate I-Cache*/ - __asm__ volatile( - "mtc0 $0,$20\n\t" - "nop\n\t" - "li $8,2\n\t" - "mtc0 $8,$20\n\t" - "nop\n\t" - "nop\n\t" - "mtc0 $0,$20\n\t" - "nop" - : /* no output */ - : /* no input */ - ); - -#endif - -#ifdef CONFIG_RTL_EB8186 - unsigned long flags; - volatile unsigned int reg; - save_flags(flags);cli(); - reg=read_32bit_cp0_register(CP0_XCONTEXT); - __asm__ volatile("nop"); - __asm__ volatile("nop"); - write_32bit_cp0_register(CP0_XCONTEXT, (reg &(~0x2))); //write '0' to bit 0,1 - __asm__ volatile("nop"); - __asm__ volatile("nop"); - write_32bit_cp0_register(CP0_XCONTEXT, (reg | 0x2)); //wirte '1' to bit 0, 1 - __asm__ volatile("nop"); - __asm__ volatile("nop"); - restore_flags(flags); -#endif -} - -void flush_dcache(unsigned int start, unsigned int end) -{ -#ifdef CONFIG_RTL_EB8186 - unsigned long flags; - volatile unsigned int reg; - save_flags(flags);cli(); - reg=read_32bit_cp0_register(CP0_XCONTEXT); - __asm__ volatile("nop"); - __asm__ volatile("nop"); - write_32bit_cp0_register(CP0_XCONTEXT, (reg & (~0x1))); //write '0' to bit 0,1 - __asm__ volatile("nop"); - __asm__ volatile("nop"); - write_32bit_cp0_register(CP0_XCONTEXT, (reg | 0x1)); //wirte '1' to bit 0, 1 - __asm__ volatile("nop"); - __asm__ volatile("nop"); - restore_flags(flags); -#endif - -#if defined(CONFIG_RTL_819X) - /* Flush D-Cache using its range */ - unsigned char *p; - unsigned int size; - unsigned int flags; - unsigned int i; - - size = end - start; - - /* correctness check : flush all if any parameter is illegal */ -// david -// if ( (size >= dcache_size) || - if ((size >= _DCACHE_SIZE) || (KSEGX(start) != KSEG0) ) - { - /* - * ghhguang - * => For Realtek Lextra CPU, - * the cache would NOT be flushed only if the Address to-be-flushed - * is the EXPLICIT address ( which is really stored in that cache line ). - * For the aliasd addresses, the cache entry would NOT be flushed even - * it matchs same cache-index. - * - * => This is different from traditional MIPS-based CPU's configuration. - * So if we want to flush ALL-cache entries, we would need to use "mtc0" - * instruction instead of simply modifying the "size" to "dcache_size" - * and "start" to "KSEG0". - * - */ - __asm__ volatile( - "mtc0 $0,$20\n\t" - "nop\n\t" - "li $8,512\n\t" - "mtc0 $8,$20\n\t" - "nop\n\t" - "nop\n\t" - "mtc0 $0,$20\n\t" - "nop" - : /* no output */ - : /* no input */ - ); - } -#if 1 - else - { - /* Start to isolate cache space */ - p = (char *)start; - - flags = read_c0_status(); - - /* isolate cache space */ - write_c0_status( (ST0_ISC | flags) &~ ST0_IEC ); - - for (i = 0; i < size; i += 0x040) - { - asm ( - #ifdef OPEN_RSDK_RTL865x - ".word 0xbc750000\n\t" - ".word 0xbc750010\n\t" - ".word 0xbc750020\n\t" - ".word 0xbc750030\n\t" - #endif - "cache 0x15, 0x000(%0)\n\t" - "cache 0x15, 0x010(%0)\n\t" - "cache 0x15, 0x020(%0)\n\t" - "cache 0x15, 0x030(%0)\n\t" - : /* No output registers */ - :"r"(p) /* input : 'p' as %0 */ - ); - p += 0x040; - } - - write_c0_status(flags); - } -#endif -#endif - -} -/*Cyrus Tsai*/ diff --git a/target/linux/realtek/files/rtkload/ctype.c b/target/linux/realtek/files/rtkload/ctype.c deleted file mode 100644 index 604f341ee..000000000 --- a/target/linux/realtek/files/rtkload/ctype.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * linux/lib/ctype.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - -#define _ctype ctype_hideme -#include <linux/ctype.h> -#undef _ctype - -const unsigned char _ctype[] = { -_C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ -_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ -_C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ -_C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ -_S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ -_P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ -_D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ -_D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ -_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ -_U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ -_U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ -_U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ -_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ -_L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ -_L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ -_L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ -_S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 160-175 */ -_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P, /* 176-191 */ -_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U, /* 192-207 */ -_U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L, /* 208-223 */ -_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L, /* 224-239 */ -_L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L}; /* 240-255 */ - - diff --git a/target/linux/realtek/files/rtkload/cvimg b/target/linux/realtek/files/rtkload/cvimg Binary files differdeleted file mode 100755 index 668feb76f..000000000 --- a/target/linux/realtek/files/rtkload/cvimg +++ /dev/null diff --git a/target/linux/realtek/files/rtkload/hfload.c b/target/linux/realtek/files/rtkload/hfload.c deleted file mode 100644 index 05bdb4772..000000000 --- a/target/linux/realtek/files/rtkload/hfload.c +++ /dev/null @@ -1,117 +0,0 @@ -/* hfload.c - * - * This file is subject to the terms and conditions of the GNU - * General Public License. See the file "COPYING" in the main - * directory of this archive for more details. - * - * Copyright (C) 2000, Jay Carlson - */ - -/* - * Boot loader main program. - */ -//#include <linux/config.h> -#include <linux/autoconf.h> - -#include <unistd.h> -//#include <linux/elf.h> -#include "hfload.h" - -#define REG32(reg) (*(volatile unsigned int *)((unsigned int)reg)) - -#if defined(CONFIG_RTL_819X) - #define BASE_ADDR 0xB8000000 - #define set_io_port_base(base) \ - do { * (unsigned long *) &mips_io_port_base = (base); } while (0) - - const unsigned long mips_io_port_base; -#endif - -int file_offset; -unsigned long kernelStartAddr; -/* -int old_stack_pointer; - -#define MAX_PHDRS_SIZE 8 - -Elf32_Ehdr header; -Elf32_Phdr phdrs[MAX_PHDRS_SIZE]; -*/ -extern void flush_cache(void); - -/* -void -zero_region(char *start, char *end) -{ - char *addr; - int count; - - count = end - start; -#ifndef __DO_QUIET__ - printf("zeroing from %08x to to %08x, 0x%x bytes\n", start, end, count); -#endif - -#ifndef FAKE_COPYING - memset(start, 0, count); -#endif -} - -void -load_phdr(Elf32_Phdr *phdr) -{ - char *addr, *end; - - seek_forward(phdr->p_offset); - - addr = (char *)phdr->p_vaddr; - end = ((char *)addr) + phdr->p_memsz; - - copy_to_region(addr, phdr->p_filesz); - - addr = ((char *)addr) + phdr->p_filesz; - - zero_region(addr, end); -} -*/ - -int main(unsigned long stack_start_addr) -{ - int i; - //Elf32_Ehdr *pHdr; - - file_offset = 0; - -#if defined(CONFIG_RTL_819X) - set_io_port_base(BASE_ADDR); -#endif - -#ifndef __DO_QUIET__ - printf("decompressing kernel:\n"); -#endif - -#ifdef CONFIG_RTL8197B_PANA - extern int is_vmlinux_checksum_ok(); - - REG32(0xB801900C) = REG32(0xB801900C) & (~0x0400); //SYSSR, AllSoftwareReady=0 - if (!is_vmlinux_checksum_ok()) { - printf("Linux image corrupted!\n"); - for (;;); - } -#endif - -#ifndef BZ2_COMPRESS - decompress_kernel(UNCOMPRESS_OUT, stack_start_addr+4096, FREEMEM_END, 0); -#else - decompress_kernel(UNCOMPRESS_OUT, stack_start_addr+4096, FREEMEM_END, 0); -#endif - -#ifndef __DO_QUIET__ - printf("done decompressing kernel.\n"); -#endif - - flush_cache(); - - printf("start address: 0x%08x\n", kernelStartAddr); - start_kernel(kernelStartAddr); - //start_kernel(0x80000000); -} diff --git a/target/linux/realtek/files/rtkload/hfload.h b/target/linux/realtek/files/rtkload/hfload.h deleted file mode 100644 index 6d15ec670..000000000 --- a/target/linux/realtek/files/rtkload/hfload.h +++ /dev/null @@ -1,63 +0,0 @@ -/* hfload.h - * - * This file is subject to the terms and conditions of the GNU - * General Public License. See the file "COPYING" in the main - * directory of this archive for more details. - * - * Copyright (C) 2000, Jay Carlson - */ - -#ifndef HELLOAD_H -#define HELLOAD_H - -//sc_yang -//#include <linux/config.h> -#include <linux/autoconf.h> -#ifdef EMBEDDED -#include <linux/string.h> -#define printf prom_printf -#else -#include <string.h> -#endif - - -#ifdef LANGUAGE_C -extern int file_offset; -#endif - - -#ifdef COMPRESSED_KERNEL - #define UNCOMPRESS_OUT 0x80000000 -#if 0 -#ifndef boot32 - #define FREEMEM_START 0x80680000 - #define FREEMEM_END 0x80800000 -#else - #define FREEMEM_START 0x80a00000 - #define FREEMEM_END 0x81000000 -#endif -#endif //sc_yang -//Brad comment, since rtl865x platform use 16M && define CONFIG_RTL_GW_8M -//#if (defined(CONFIG_RTL8186_AP) || defined(CONFIG_RTL8186_GW_8M) || defined(CONFIG_RTL8186_KB)) -#if (defined(CONFIG_RTL8186_AP) || defined(CONFIG_RTL8186_KB) || defined(CONFIG_RTL865X_PANAHOST)) - #define FREEMEM_END 0x80800000 -#else - #define FREEMEM_END 0x81000000 -#endif -#endif - -#ifdef CONFIG_RTK_VOIP - #undef FREEMEM_END - #define FREEMEM_END 0x82000000 -#endif - -// david ----------------- -#ifdef BZ2_COMPRESS - #define prom_printf - #undef FREEMEM_START - #define FREEMEM_START 0x80500000 -#endif -//----------------------- - -#endif - diff --git a/target/linux/realtek/files/rtkload/inflate.c b/target/linux/realtek/files/rtkload/inflate.c deleted file mode 100644 index 6db6e98d1..000000000 --- a/target/linux/realtek/files/rtkload/inflate.c +++ /dev/null @@ -1,1212 +0,0 @@ -#define DEBG(x) -#define DEBG1(x) -/* inflate.c -- Not copyrighted 1992 by Mark Adler - version c10p1, 10 January 1993 */ - -/* - * Adapted for booting Linux by Hannu Savolainen 1993 - * based on gzip-1.0.3 - * - * Nicolas Pitre <nico@cam.org>, 1999/04/14 : - * Little mods for all variable to reside either into rodata or bss segments - * by marking constant variables with 'const' and initializing all the others - * at run-time only. This allows for the kernel uncompressor to run - * directly from Flash or ROM memory on embedded systems. - */ - -/* - Inflate deflated (PKZIP's method 8 compressed) data. The compression - method searches for as much of the current string of bytes (up to a - length of 258) in the previous 32 K bytes. If it doesn't find any - matches (of at least length 3), it codes the next byte. Otherwise, it - codes the length of the matched string and its distance backwards from - the current position. There is a single Huffman code that codes both - single bytes (called "literals") and match lengths. A second Huffman - code codes the distance information, which follows a length code. Each - length or distance code actually represents a base value and a number - of "extra" (sometimes zero) bits to get to add to the base value. At - the end of each deflated block is a special end-of-block (EOB) literal/ - length code. The decoding process is basically: get a literal/length - code; if EOB then done; if a literal, emit the decoded byte; if a - length then get the distance and emit the referred-to bytes from the - sliding window of previously emitted data. - - There are (currently) three kinds of inflate blocks: stored, fixed, and - dynamic. The compressor deals with some chunk of data at a time, and - decides which method to use on a chunk-by-chunk basis. A chunk might - typically be 32 K or 64 K. If the chunk is incompressible, then the - "stored" method is used. In this case, the bytes are simply stored as - is, eight bits per byte, with none of the above coding. The bytes are - preceded by a count, since there is no longer an EOB code. - - If the data is compressible, then either the fixed or dynamic methods - are used. In the dynamic method, the compressed data is preceded by - an encoding of the literal/length and distance Huffman codes that are - to be used to decode this block. The representation is itself Huffman - coded, and so is preceded by a description of that code. These code - descriptions take up a little space, and so for small blocks, there is - a predefined set of codes, called the fixed codes. The fixed method is - used if the block codes up smaller that way (usually for quite small - chunks), otherwise the dynamic method is used. In the latter case, the - codes are customized to the probabilities in the current block, and so - can code it much better than the pre-determined fixed codes. - - The Huffman codes themselves are decoded using a multi-level table - lookup, in order to maximize the speed of decoding plus the speed of - building the decoding tables. See the comments below that precede the - lbits and dbits tuning parameters. - */ - - -/* - Notes beyond the 1.93a appnote.txt: - - 1. Distance pointers never point before the beginning of the output - stream. - 2. Distance pointers can point back across blocks, up to 32k away. - 3. There is an implied maximum of 7 bits for the bit length table and - 15 bits for the actual data. - 4. If only one code exists, then it is encoded using one bit. (Zero - would be more efficient, but perhaps a little confusing.) If two - codes exist, they are coded using one bit each (0 and 1). - 5. There is no way of sending zero distance codes--a dummy must be - sent if there are none. (History: a pre 2.0 version of PKZIP would - store blocks with no distance codes, but this was discovered to be - too harsh a criterion.) Valid only for 1.93a. 2.04c does allow - zero distance codes, which is sent as one code of zero bits in - length. - 6. There are up to 286 literal/length codes. Code 256 represents the - end-of-block. Note however that the static length tree defines - 288 codes just to fill out the Huffman codes. Codes 286 and 287 - cannot be used though, since there is no length base or extra bits - defined for them. Similarly, there are up to 30 distance codes. - However, static trees define 32 codes (all 5 bits) to fill out the - Huffman codes, but the last two had better not show up in the data. - 7. Unzip can check dynamic Huffman blocks for complete code sets. - The exception is that a single code would not be complete (see #4). - 8. The five bits following the block type is really the number of - literal codes sent minus 257. - 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits - (1+6+6). Therefore, to output three times the length, you output - three codes (1+1+1), whereas to output four times the same length, - you only need two codes (1+3). Hmm. - 10. In the tree reconstruction algorithm, Code = Code + Increment - only if BitLength(i) is not zero. (Pretty obvious.) - 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19) - 12. Note: length code 284 can represent 227-258, but length code 285 - really is 258. The last length deserves its own, short code - since it gets used a lot in very redundant files. The length - 258 is special since 258 - 3 (the min match length) is 255. - 13. The literal/length and distance code bit lengths are read as a - single stream of lengths. It is possible (and advantageous) for - a repeat code (16, 17, or 18) to go across the boundary between - the two sets of lengths. - */ -#include <linux/compiler.h> - -#ifdef RCSID -static char rcsid[] = "#Id: inflate.c,v 0.14 1993/06/10 13:27:04 jloup Exp #"; -#endif - -#ifndef STATIC - -#if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H) -# include <sys/types.h> -# include <stdlib.h> -#endif - -#include "gzip.h" -#define STATIC -#endif /* !STATIC */ - -#ifndef INIT -#define INIT -#endif - -#define slide window - -/* Huffman code lookup table entry--this entry is four bytes for machines - that have 16-bit pointers (e.g. PC's in the small or medium model). - Valid extra bits are 0..13. e == 15 is EOB (end of block), e == 16 - means that v is a literal, 16 < e < 32 means that v is a pointer to - the next table, which codes e - 16 bits, and lastly e == 99 indicates - an unused code. If a code with e == 99 is looked up, this implies an - error in the data. */ -struct huft { - uch e; /* number of extra bits or operation */ - uch b; /* number of bits in this code or subcode */ - union { - ush n; /* literal, length base, or distance base */ - struct huft *t; /* pointer to next level of table */ - } v; -}; - - -/* Function prototypes */ -STATIC int INIT huft_build OF((unsigned *, unsigned, unsigned, - const ush *, const ush *, struct huft **, int *)); -STATIC int INIT huft_free OF((struct huft *)); -STATIC int INIT inflate_codes OF((struct huft *, struct huft *, int, int)); -STATIC int INIT inflate_stored OF((void)); -STATIC int INIT inflate_fixed OF((void)); -STATIC int INIT inflate_dynamic OF((void)); -STATIC int INIT inflate_block OF((int *)); -STATIC int INIT inflate OF((void)); - - -/* The inflate algorithm uses a sliding 32 K byte window on the uncompressed - stream to find repeated byte strings. This is implemented here as a - circular buffer. The index is updated simply by incrementing and then - ANDing with 0x7fff (32K-1). */ -/* It is left to other modules to supply the 32 K area. It is assumed - to be usable as if it were declared "uch slide[32768];" or as just - "uch *slide;" and then malloc'ed in the latter case. The definition - must be in unzip.h, included above. */ -/* unsigned wp; current position in slide */ -#define wp outcnt -#define flush_output(w) (wp=(w),flush_window()) - -/* Tables for deflate from PKZIP's appnote.txt. */ -static const unsigned border[] = { /* Order of the bit length code lengths */ - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; -static const ush cplens[] = { /* Copy lengths for literal codes 257..285 */ - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; - /* note: see note #13 above about the 258 in this list. */ -static const ush cplext[] = { /* Extra bits for literal codes 257..285 */ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */ -static const ush cpdist[] = { /* Copy offsets for distance codes 0..29 */ - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577}; -static const ush cpdext[] = { /* Extra bits for distance codes */ - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, - 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, - 12, 12, 13, 13}; - - - -/* Macros for inflate() bit peeking and grabbing. - The usage is: - - NEEDBITS(j) - x = b & mask_bits[j]; - DUMPBITS(j) - - where NEEDBITS makes sure that b has at least j bits in it, and - DUMPBITS removes the bits from b. The macros use the variable k - for the number of bits in b. Normally, b and k are register - variables for speed, and are initialized at the beginning of a - routine that uses these macros from a global bit buffer and count. - - If we assume that EOB will be the longest code, then we will never - ask for bits with NEEDBITS that are beyond the end of the stream. - So, NEEDBITS should not read any more bytes than are needed to - meet the request. Then no bytes need to be "returned" to the buffer - at the end of the last block. - - However, this assumption is not true for fixed blocks--the EOB code - is 7 bits, but the other literal/length codes can be 8 or 9 bits. - (The EOB code is shorter than other codes because fixed blocks are - generally short. So, while a block always has an EOB, many other - literal/length codes have a significantly lower probability of - showing up at all.) However, by making the first table have a - lookup of seven bits, the EOB code will be found in that first - lookup, and so will not require that too many bits be pulled from - the stream. - */ - -STATIC ulg bb; /* bit buffer */ -STATIC unsigned bk; /* bits in bit buffer */ - -STATIC const ush mask_bits[] = { - 0x0000, - 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, - 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff -}; - -#define NEXTBYTE() ({ int v = get_byte(); if (v < 0) goto underrun; (uch)v; }) -#define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}} -#define DUMPBITS(n) {b>>=(n);k-=(n);} - - -/* - Huffman code decoding is performed using a multi-level table lookup. - The fastest way to decode is to simply build a lookup table whose - size is determined by the longest code. However, the time it takes - to build this table can also be a factor if the data being decoded - is not very long. The most common codes are necessarily the - shortest codes, so those codes dominate the decoding time, and hence - the speed. The idea is you can have a shorter table that decodes the - shorter, more probable codes, and then point to subsidiary tables for - the longer codes. The time it costs to decode the longer codes is - then traded against the time it takes to make longer tables. - - This results of this trade are in the variables lbits and dbits - below. lbits is the number of bits the first level table for literal/ - length codes can decode in one step, and dbits is the same thing for - the distance codes. Subsequent tables are also less than or equal to - those sizes. These values may be adjusted either when all of the - codes are shorter than that, in which case the longest code length in - bits is used, or when the shortest code is *longer* than the requested - table size, in which case the length of the shortest code in bits is - used. - - There are two different values for the two tables, since they code a - different number of possibilities each. The literal/length table - codes 286 possible values, or in a flat code, a little over eight - bits. The distance table codes 30 possible values, or a little less - than five bits, flat. The optimum values for speed end up being - about one bit more than those, so lbits is 8+1 and dbits is 5+1. - The optimum values may differ though from machine to machine, and - possibly even between compilers. Your mileage may vary. - */ - - -STATIC const int lbits = 9; /* bits in base literal/length lookup table */ -STATIC const int dbits = 6; /* bits in base distance lookup table */ - - -/* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ -#define BMAX 16 /* maximum bit length of any code (16 for explode) */ -#define N_MAX 288 /* maximum number of codes in any set */ - - -STATIC unsigned hufts; /* track memory usage */ - - -STATIC int INIT huft_build( - unsigned *b, /* code lengths in bits (all assumed <= BMAX) */ - unsigned n, /* number of codes (assumed <= N_MAX) */ - unsigned s, /* number of simple-valued codes (0..s-1) */ - const ush *d, /* list of base values for non-simple codes */ - const ush *e, /* list of extra bits for non-simple codes */ - struct huft **t, /* result: starting table */ - int *m /* maximum lookup bits, returns actual */ - ) -/* Given a list of code lengths and a maximum table size, make a set of - tables to decode that set of codes. Return zero on success, one if - the given code set is incomplete (the tables are still built in this - case), two if the input is invalid (all zero length codes or an - oversubscribed set of lengths), and three if not enough memory. */ -{ - unsigned a; /* counter for codes of length k */ - unsigned c[BMAX+1]; /* bit length count table */ - unsigned f; /* i repeats in table every f entries */ - int g; /* maximum code length */ - int h; /* table level */ - register unsigned i; /* counter, current code */ - register unsigned j; /* counter */ - register int k; /* number of bits in current code */ - int l; /* bits per table (returned in m) */ - register unsigned *p; /* pointer into c[], b[], or v[] */ - register struct huft *q; /* points to current table */ - struct huft r; /* table entry for structure assignment */ - struct huft *u[BMAX]; /* table stack */ - unsigned v[N_MAX]; /* values in order of bit length */ - register int w; /* bits before this table == (l * h) */ - unsigned x[BMAX+1]; /* bit offsets, then code stack */ - unsigned *xp; /* pointer into x */ - int y; /* number of dummy codes added */ - unsigned z; /* number of entries in current table */ - -DEBG("huft1 "); - - /* Generate counts for each bit length */ - memzero(c, sizeof(c)); - p = b; i = n; - do { - Tracecv(*p, (stderr, (n-i >= ' ' && n-i <= '~' ? "%c %d\n" : "0x%x %d\n"), - n-i, *p)); - c[*p]++; /* assume all entries <= BMAX */ - p++; /* Can't combine with above line (Solaris bug) */ - } while (--i); - if (c[0] == n) /* null input--all zero length codes */ - { - *t = (struct huft *)NULL; - *m = 0; - return 2; - } - -DEBG("huft2 "); - - /* Find minimum and maximum length, bound *m by those */ - l = *m; - for (j = 1; j <= BMAX; j++) - if (c[j]) - break; - k = j; /* minimum code length */ - if ((unsigned)l < j) - l = j; - for (i = BMAX; i; i--) - if (c[i]) - break; - g = i; /* maximum code length */ - if ((unsigned)l > i) - l = i; - *m = l; - -DEBG("huft3 "); - - /* Adjust last length count to fill out codes, if needed */ - for (y = 1 << j; j < i; j++, y <<= 1) - if ((y -= c[j]) < 0) - return 2; /* bad input: more codes than bits */ - if ((y -= c[i]) < 0) - return 2; - c[i] += y; - -DEBG("huft4 "); - - /* Generate starting offsets into the value table for each length */ - x[1] = j = 0; - p = c + 1; xp = x + 2; - while (--i) { /* note that i == g from above */ - *xp++ = (j += *p++); - } - -DEBG("huft5 "); - - /* Make a table of values in order of bit lengths */ - p = b; i = 0; - do { - if ((j = *p++) != 0) - v[x[j]++] = i; - } while (++i < n); - n = x[g]; /* set n to length of v */ - -DEBG("h6 "); - - /* Generate the Huffman codes and for each, make the table entries */ - x[0] = i = 0; /* first Huffman code is zero */ - p = v; /* grab values in bit order */ - h = -1; /* no tables yet--level -1 */ - w = -l; /* bits decoded == (l * h) */ - u[0] = (struct huft *)NULL; /* just to keep compilers happy */ - q = (struct huft *)NULL; /* ditto */ - z = 0; /* ditto */ -DEBG("h6a "); - - /* go through the bit lengths (k already is bits in shortest code) */ - for (; k <= g; k++) - { -DEBG("h6b "); - a = c[k]; - while (a--) - { -DEBG("h6b1 "); - /* here i is the Huffman code of length k bits for value *p */ - /* make tables up to required level */ - while (k > w + l) - { -DEBG1("1 "); - h++; - w += l; /* previous table always l bits */ - - /* compute minimum size table less than or equal to l bits */ - z = (z = g - w) > (unsigned)l ? l : z; /* upper limit on table size */ - if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */ - { /* too few codes for k-w bit table */ -DEBG1("2 "); - f -= a + 1; /* deduct codes from patterns left */ - xp = c + k; - if (j < z) - while (++j < z) /* try smaller tables up to z bits */ - { - if ((f <<= 1) <= *++xp) - break; /* enough codes to use up j bits */ - f -= *xp; /* else deduct codes from patterns */ - } - } -DEBG1("3 "); - z = 1 << j; /* table entries for j-bit table */ - - /* allocate and link in new table */ - if ((q = (struct huft *)malloc((z + 1)*sizeof(struct huft))) == - (struct huft *)NULL) - { - if (h) - huft_free(u[0]); - return 3; /* not enough memory */ - } -DEBG1("4 "); - hufts += z + 1; /* track memory usage */ - *t = q + 1; /* link to list for huft_free() */ - *(t = &(q->v.t)) = (struct huft *)NULL; - u[h] = ++q; /* table starts after link */ - -DEBG1("5 "); - /* connect to last table, if there is one */ - if (h) - { - x[h] = i; /* save pattern for backing up */ - r.b = (uch)l; /* bits to dump before this table */ - r.e = (uch)(16 + j); /* bits in this table */ - r.v.t = q; /* pointer to this table */ - j = i >> (w - l); /* (get around Turbo C bug) */ - u[h-1][j] = r; /* connect to last table */ - } -DEBG1("6 "); - } -DEBG("h6c "); - - /* set up table entry in r */ - r.b = (uch)(k - w); - if (p >= v + n) - r.e = 99; /* out of values--invalid code */ - else if (*p < s) - { - r.e = (uch)(*p < 256 ? 16 : 15); /* 256 is end-of-block code */ - r.v.n = (ush)(*p); /* simple code is just the value */ - p++; /* one compiler does not like *p++ */ - } - else - { - r.e = (uch)e[*p - s]; /* non-simple--look up in lists */ - r.v.n = d[*p++ - s]; - } -DEBG("h6d "); - - /* fill code-like entries with r */ - f = 1 << (k - w); - for (j = i >> w; j < z; j += f) - q[j] = r; - - /* backwards increment the k-bit code i */ - for (j = 1 << (k - 1); i & j; j >>= 1) - i ^= j; - i ^= j; - - /* backup over finished tables */ - while ((i & ((1 << w) - 1)) != x[h]) - { - h--; /* don't need to update q */ - w -= l; - } -DEBG("h6e "); - } -DEBG("h6f "); - } - -DEBG("huft7 "); - - /* Return true (1) if we were given an incomplete table */ - return y != 0 && g != 1; -} - - - -STATIC int INIT huft_free( - struct huft *t /* table to free */ - ) -/* Free the malloc'ed tables built by huft_build(), which makes a linked - list of the tables it made, with the links in a dummy first entry of - each table. */ -{ - register struct huft *p, *q; - - - /* Go through linked list, freeing from the malloced (t[-1]) address. */ - p = t; - while (p != (struct huft *)NULL) - { - q = (--p)->v.t; - free((char*)p); - p = q; - } - return 0; -} - - -STATIC int INIT inflate_codes( - struct huft *tl, /* literal/length decoder tables */ - struct huft *td, /* distance decoder tables */ - int bl, /* number of bits decoded by tl[] */ - int bd /* number of bits decoded by td[] */ - ) -/* inflate (decompress) the codes in a deflated (compressed) block. - Return an error code or zero if it all goes ok. */ -{ - register unsigned e; /* table entry flag/number of extra bits */ - unsigned n, d; /* length and index for copy */ - unsigned w; /* current window position */ - struct huft *t; /* pointer to table entry */ - unsigned ml, md; /* masks for bl and bd bits */ - register ulg b; /* bit buffer */ - register unsigned k; /* number of bits in bit buffer */ - - - /* make local copies of globals */ - b = bb; /* initialize bit buffer */ - k = bk; - w = wp; /* initialize window position */ - - /* inflate the coded data */ - ml = mask_bits[bl]; /* precompute masks for speed */ - md = mask_bits[bd]; - for (;;) /* do until end of block */ - { - NEEDBITS((unsigned)bl) - if ((e = (t = tl + ((unsigned)b & ml))->e) > 16) - do { - if (e == 99) - return 1; - DUMPBITS(t->b) - e -= 16; - NEEDBITS(e) - } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16); - DUMPBITS(t->b) - if (e == 16) /* then it's a literal */ - { - slide[w++] = (uch)t->v.n; - Tracevv((stderr, "%c", slide[w-1])); - if (w == WSIZE) - { - flush_output(w); - w = 0; - } - } - else /* it's an EOB or a length */ - { - /* exit if end of block */ - if (e == 15) - break; - - /* get length of block to copy */ - NEEDBITS(e) - n = t->v.n + ((unsigned)b & mask_bits[e]); - DUMPBITS(e); - - /* decode distance of block to copy */ - NEEDBITS((unsigned)bd) - if ((e = (t = td + ((unsigned)b & md))->e) > 16) - do { - if (e == 99) - return 1; - DUMPBITS(t->b) - e -= 16; - NEEDBITS(e) - } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16); - DUMPBITS(t->b) - NEEDBITS(e) - d = w - t->v.n - ((unsigned)b & mask_bits[e]); - DUMPBITS(e) - Tracevv((stderr,"\\[%d,%d]", w-d, n)); - - /* do the copy */ - do { - n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e); -#if !defined(NOMEMCPY) && !defined(DEBUG) - if (w - d >= e) /* (this test assumes unsigned comparison) */ - { - memcpy(slide + w, slide + d, e); - w += e; - d += e; - } - else /* do it slow to avoid memcpy() overlap */ -#endif /* !NOMEMCPY */ - do { - slide[w++] = slide[d++]; - Tracevv((stderr, "%c", slide[w-1])); - } while (--e); - if (w == WSIZE) - { - flush_output(w); - w = 0; - } - } while (n); - } - } - - - /* restore the globals from the locals */ - wp = w; /* restore global window pointer */ - bb = b; /* restore global bit buffer */ - bk = k; - - /* done */ - return 0; - - underrun: - return 4; /* Input underrun */ -} - - - -STATIC int INIT inflate_stored(void) -/* "decompress" an inflated type 0 (stored) block. */ -{ - unsigned n; /* number of bytes in block */ - unsigned w; /* current window position */ - register ulg b; /* bit buffer */ - register unsigned k; /* number of bits in bit buffer */ - -DEBG("<stor"); - - /* make local copies of globals */ - b = bb; /* initialize bit buffer */ - k = bk; - w = wp; /* initialize window position */ - - - /* go to byte boundary */ - n = k & 7; - DUMPBITS(n); - - - /* get the length and its complement */ - NEEDBITS(16) - n = ((unsigned)b & 0xffff); - DUMPBITS(16) - NEEDBITS(16) - if (n != (unsigned)((~b) & 0xffff)) - return 1; /* error in compressed data */ - DUMPBITS(16) - - - /* read and output the compressed data */ - while (n--) - { - NEEDBITS(8) - slide[w++] = (uch)b; - if (w == WSIZE) - { - flush_output(w); - w = 0; - } - DUMPBITS(8) - } - - - /* restore the globals from the locals */ - wp = w; /* restore global window pointer */ - bb = b; /* restore global bit buffer */ - bk = k; - - DEBG(">"); - return 0; - - underrun: - return 4; /* Input underrun */ -} - - -/* - * We use `noinline' here to prevent gcc-3.5 from using too much stack space - */ -STATIC int noinline INIT inflate_fixed(void) -/* decompress an inflated type 1 (fixed Huffman codes) block. We should - either replace this with a custom decoder, or at least precompute the - Huffman tables. */ -{ - int i; /* temporary variable */ - struct huft *tl; /* literal/length code table */ - struct huft *td; /* distance code table */ - int bl; /* lookup bits for tl */ - int bd; /* lookup bits for td */ - unsigned l[288]; /* length list for huft_build */ - -DEBG("<fix"); - - /* set up literal table */ - for (i = 0; i < 144; i++) - l[i] = 8; - for (; i < 256; i++) - l[i] = 9; - for (; i < 280; i++) - l[i] = 7; - for (; i < 288; i++) /* make a complete, but wrong code set */ - l[i] = 8; - bl = 7; - if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0) - return i; - - - /* set up distance table */ - for (i = 0; i < 30; i++) /* make an incomplete code set */ - l[i] = 5; - bd = 5; - if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1) - { - huft_free(tl); - - DEBG(">"); - return i; - } - - - /* decompress until an end-of-block code */ - if (inflate_codes(tl, td, bl, bd)) - return 1; - - - /* free the decoding tables, return */ - huft_free(tl); - huft_free(td); - return 0; -} - - -/* - * We use `noinline' here to prevent gcc-3.5 from using too much stack space - */ -STATIC int noinline INIT inflate_dynamic(void) -/* decompress an inflated type 2 (dynamic Huffman codes) block. */ -{ - int i; /* temporary variables */ - unsigned j; - unsigned l; /* last length */ - unsigned m; /* mask for bit lengths table */ - unsigned n; /* number of lengths to get */ - struct huft *tl; /* literal/length code table */ - struct huft *td; /* distance code table */ - int bl; /* lookup bits for tl */ - int bd; /* lookup bits for td */ - unsigned nb; /* number of bit length codes */ - unsigned nl; /* number of literal/length codes */ - unsigned nd; /* number of distance codes */ -#ifdef PKZIP_BUG_WORKAROUND - unsigned ll[288+32]; /* literal/length and distance code lengths */ -#else - unsigned ll[286+30]; /* literal/length and distance code lengths */ -#endif - register ulg b; /* bit buffer */ - register unsigned k; /* number of bits in bit buffer */ - -DEBG("<dyn"); - - /* make local bit buffer */ - b = bb; - k = bk; - - - /* read in table lengths */ - NEEDBITS(5) - nl = 257 + ((unsigned)b & 0x1f); /* number of literal/length codes */ - DUMPBITS(5) - NEEDBITS(5) - nd = 1 + ((unsigned)b & 0x1f); /* number of distance codes */ - DUMPBITS(5) - NEEDBITS(4) - nb = 4 + ((unsigned)b & 0xf); /* number of bit length codes */ - DUMPBITS(4) -#ifdef PKZIP_BUG_WORKAROUND - if (nl > 288 || nd > 32) -#else - if (nl > 286 || nd > 30) -#endif - return 1; /* bad lengths */ - -DEBG("dyn1 "); - - /* read in bit-length-code lengths */ - for (j = 0; j < nb; j++) - { - NEEDBITS(3) - ll[border[j]] = (unsigned)b & 7; - DUMPBITS(3) - } - for (; j < 19; j++) - ll[border[j]] = 0; - -DEBG("dyn2 "); - - /* build decoding table for trees--single level, 7 bit lookup */ - bl = 7; - if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0) - { - if (i == 1) - huft_free(tl); - return i; /* incomplete code set */ - } - -DEBG("dyn3 "); - - /* read in literal and distance code lengths */ - n = nl + nd; - m = mask_bits[bl]; - i = l = 0; - while ((unsigned)i < n) - { - NEEDBITS((unsigned)bl) - j = (td = tl + ((unsigned)b & m))->b; - DUMPBITS(j) - j = td->v.n; - if (j < 16) /* length of code in bits (0..15) */ - ll[i++] = l = j; /* save last length in l */ - else if (j == 16) /* repeat last length 3 to 6 times */ - { - NEEDBITS(2) - j = 3 + ((unsigned)b & 3); - DUMPBITS(2) - if ((unsigned)i + j > n) - return 1; - while (j--) - ll[i++] = l; - } - else if (j == 17) /* 3 to 10 zero length codes */ - { - NEEDBITS(3) - j = 3 + ((unsigned)b & 7); - DUMPBITS(3) - if ((unsigned)i + j > n) - return 1; - while (j--) - ll[i++] = 0; - l = 0; - } - else /* j == 18: 11 to 138 zero length codes */ - { - NEEDBITS(7) - j = 11 + ((unsigned)b & 0x7f); - DUMPBITS(7) - if ((unsigned)i + j > n) - return 1; - while (j--) - ll[i++] = 0; - l = 0; - } - } - -DEBG("dyn4 "); - - /* free decoding table for trees */ - huft_free(tl); - -DEBG("dyn5 "); - - /* restore the global bit buffer */ - bb = b; - bk = k; - -DEBG("dyn5a "); - - /* build the decoding tables for literal/length and distance codes */ - bl = lbits; - if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0) - { -DEBG("dyn5b "); - if (i == 1) { - error("incomplete literal tree"); - huft_free(tl); - } - return i; /* incomplete code set */ - } -DEBG("dyn5c "); - bd = dbits; - if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0) - { -DEBG("dyn5d "); - if (i == 1) { - error("incomplete distance tree"); -#ifdef PKZIP_BUG_WORKAROUND - i = 0; - } -#else - huft_free(td); - } - huft_free(tl); - return i; /* incomplete code set */ -#endif - } - -DEBG("dyn6 "); - - /* decompress until an end-of-block code */ - if (inflate_codes(tl, td, bl, bd)) - return 1; - -DEBG("dyn7 "); - - /* free the decoding tables, return */ - huft_free(tl); - huft_free(td); - - DEBG(">"); - return 0; - - underrun: - return 4; /* Input underrun */ -} - - - -STATIC int INIT inflate_block( - int *e /* last block flag */ - ) -/* decompress an inflated block */ -{ - unsigned t; /* block type */ - register ulg b; /* bit buffer */ - register unsigned k; /* number of bits in bit buffer */ - - DEBG("<blk"); - - /* make local bit buffer */ - b = bb; - k = bk; - - - /* read in last block bit */ - NEEDBITS(1) - *e = (int)b & 1; - DUMPBITS(1) - - - /* read in block type */ - NEEDBITS(2) - t = (unsigned)b & 3; - DUMPBITS(2) - - - /* restore the global bit buffer */ - bb = b; - bk = k; - - /* inflate that block type */ - if (t == 2) - return inflate_dynamic(); - if (t == 0) - return inflate_stored(); - if (t == 1) - return inflate_fixed(); - - DEBG(">"); - - /* bad block type */ - return 2; - - underrun: - return 4; /* Input underrun */ -} - - - -STATIC int INIT inflate(void) -/* decompress an inflated entry */ -{ - int e; /* last block flag */ - int r; /* result code */ - unsigned h; /* maximum struct huft's malloc'ed */ - void *ptr; - - /* initialize window, bit buffer */ - wp = 0; - bk = 0; - bb = 0; - - - /* decompress until the last block */ - h = 0; - do { - hufts = 0; - gzip_mark(&ptr); - if ((r = inflate_block(&e)) != 0) { - gzip_release(&ptr); - return r; - } - gzip_release(&ptr); - if (hufts > h) - h = hufts; - } while (!e); - - /* Undo too much lookahead. The next read will be byte aligned so we - * can discard unused bits in the last meaningful byte. - */ - while (bk >= 8) { - bk -= 8; - inptr--; - } - - /* flush out slide */ - flush_output(wp); - - - /* return success */ -#ifdef DEBUG - fprintf(stderr, "<%u> ", h); -#endif /* DEBUG */ - return 0; -} - -/********************************************************************** - * - * The following are support routines for inflate.c - * - **********************************************************************/ - -static ulg crc_32_tab[256]; -static ulg crc; /* initialized in makecrc() so it'll reside in bss */ -#define CRC_VALUE (crc ^ 0xffffffffUL) - -/* - * Code to compute the CRC-32 table. Borrowed from - * gzip-1.0.3/makecrc.c. - */ - -static void INIT -makecrc(void) -{ -/* Not copyrighted 1990 Mark Adler */ - - unsigned long c; /* crc shift register */ - unsigned long e; /* polynomial exclusive-or pattern */ - int i; /* counter for all possible eight bit values */ - int k; /* byte being shifted into crc apparatus */ - - /* terms of polynomial defining this crc (except x^32): */ - static const int p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; - - /* Make exclusive-or pattern from polynomial */ - e = 0; - for (i = 0; i < sizeof(p)/sizeof(int); i++) - e |= 1L << (31 - p[i]); - - crc_32_tab[0] = 0; - - for (i = 1; i < 256; i++) - { - c = 0; - for (k = i | 256; k != 1; k >>= 1) - { - c = c & 1 ? (c >> 1) ^ e : c >> 1; - if (k & 1) - c ^= e; - } - crc_32_tab[i] = c; - } - - /* this is initialized here so this code could reside in ROM */ - crc = (ulg)0xffffffffUL; /* shift register contents */ -} - -/* gzip flag byte */ -#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */ -#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ -#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ -#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ -#define COMMENT 0x10 /* bit 4 set: file comment present */ -#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ -#define RESERVED 0xC0 /* bit 6,7: reserved */ - -/* - * Do the uncompression! - */ -static int INIT gunzip(void) -{ - uch flags; - unsigned char magic[2]; /* magic header */ - char method; - ulg orig_crc = 0; /* original crc */ - ulg orig_len = 0; /* original uncompressed length */ - int res; - - magic[0] = NEXTBYTE(); - magic[1] = NEXTBYTE(); - method = NEXTBYTE(); - - if (magic[0] != 037 || - ((magic[1] != 0213) && (magic[1] != 0236))) { - error("bad gzip magic numbers"); - return -1; - } - - /* We only support method #8, DEFLATED */ - if (method != 8) { - error("internal error, invalid method"); - return -1; - } - - flags = (uch)get_byte(); - if ((flags & ENCRYPTED) != 0) { - error("Input is encrypted"); - return -1; - } - if ((flags & CONTINUATION) != 0) { - error("Multi part input"); - return -1; - } - if ((flags & RESERVED) != 0) { - error("Input has invalid flags"); - return -1; - } - NEXTBYTE(); /* Get timestamp */ - NEXTBYTE(); - NEXTBYTE(); - NEXTBYTE(); - - (void)NEXTBYTE(); /* Ignore extra flags for the moment */ - (void)NEXTBYTE(); /* Ignore OS type for the moment */ - - if ((flags & EXTRA_FIELD) != 0) { - unsigned len = (unsigned)NEXTBYTE(); - len |= ((unsigned)NEXTBYTE())<<8; - while (len--) (void)NEXTBYTE(); - } - - /* Get original file name if it was truncated */ - if ((flags & ORIG_NAME) != 0) { - /* Discard the old name */ - while (NEXTBYTE() != 0) /* null */ ; - } - - /* Discard file comment if any */ - if ((flags & COMMENT) != 0) { - while (NEXTBYTE() != 0) /* null */ ; - } - - /* Decompress */ - if ((res = inflate())) { - switch (res) { - case 0: - break; - case 1: - error("invalid compressed format (err=1)"); - break; - case 2: - error("invalid compressed format (err=2)"); - break; - case 3: - error("out of memory"); - break; - case 4: - error("out of input data"); - break; - default: - error("invalid compressed format (other)"); - } - return -1; - } - - /* Get the crc and original length */ - /* crc32 (see algorithm.doc) - * uncompressed input size modulo 2^32 - */ - orig_crc = (ulg) NEXTBYTE(); - orig_crc |= (ulg) NEXTBYTE() << 8; - orig_crc |= (ulg) NEXTBYTE() << 16; - orig_crc |= (ulg) NEXTBYTE() << 24; - - orig_len = (ulg) NEXTBYTE(); - orig_len |= (ulg) NEXTBYTE() << 8; - orig_len |= (ulg) NEXTBYTE() << 16; - orig_len |= (ulg) NEXTBYTE() << 24; - - /* Validate decompression */ - if (orig_crc != CRC_VALUE) { - error("crc error"); - return -1; - } - if (orig_len != bytes_out) { - error("length error"); - return -1; - } - return 0; - - underrun: /* NEXTBYTE() goto's here if needed */ - error("out of input data"); - return -1; -} - - diff --git a/target/linux/realtek/files/rtkload/ld-emu.script b/target/linux/realtek/files/rtkload/ld-emu.script deleted file mode 100644 index f152a18a2..000000000 --- a/target/linux/realtek/files/rtkload/ld-emu.script +++ /dev/null @@ -1,56 +0,0 @@ -/* ld.script - * - * This file is subject to the terms and conditions of the GNU - * General Public License. See the file "COPYING" in the main - * directory of this archive for more details. - * - * Copyright (C) 2000, Jay Carlson - */ - -OUTPUT_FORMAT("elf32-littlemips") -OUTPUT_ARCH(mips) -ENTRY(__start) - -/* Someday I'll figure out how this works */ -/* MEMORY { vtboot : ORIGIN = 0x9fc00000, LENGTH = 64k } */ -/* MEMORY { rom : ORIGIN = 0x9fc00000, LENGTH = 2M } */ - - -SECTIONS -{ - /* VT-OS boot rom lives here in real hardware */ - . = 0x9fc00000 ; - vtboot : { vtboot* } - - /* The loader itself */ - . = 0x9fc10000 ; - .text : { *(.text) } - .rodata : { *(.rodata) } - - . = ALIGN(4); - /* Compressed kernel ELF image */ - input_data = . ; - source_memory_start = . ; - vmlinux : { vmlinux-stripped.gz* } - input_data_end = . ; - - . = ALIGN(4); - /* Romdisk, if any. An empty file is OK. */ - romdisk_start = . ; - romdisk : { romdisk* } - romdisk_end = . ; - - - /* . = 0x80700000 ; */ - /* Oops, second 4M is in the second DRAM bank. Put our BSS at the 7M mark. */ - . = 0x82300000 ; /* emulator */ - /* . = 0x82500000 ; */ /* real hardware */ - .bss : { _bstart = . ; *(.bss) ; *(.sbss) ; *(COMMON) ; _bend = . ; } - - /* /DISCARD/ : { *(.reginfo) ; *(.mdebug) ; *(.note) ; *(.comment) *(__ex_table) ; } */ - /DISCARD/ : { *(.reginfo) ; *(.note) ; *(.comment) *(__ex_table) ; } - - /* .filler : */ -} - - diff --git a/target/linux/realtek/files/rtkload/ld.script.in b/target/linux/realtek/files/rtkload/ld.script.in deleted file mode 100644 index 719f3f4d7..000000000 --- a/target/linux/realtek/files/rtkload/ld.script.in +++ /dev/null @@ -1,49 +0,0 @@ -/* ld.script - * - * This file is subject to the terms and conditions of the GNU - * General Public License. See the file "COPYING" in the main - * directory of this archive for more details. - * - * Copyright (C) 2000, Jay Carlson - */ - -OUTPUT_ARCH(mips) -ENTRY(__start) - -/* Someday I'll figure out how this works */ -/* MEMORY { vtboot : ORIGIN = 0x80400000, LENGTH = 64k } */ -/* MEMORY { rom : ORIGIN = 0x80410000, LENGTH = 2M } */ - - -SECTIONS -{ - /* The loader itself */ - . = LOAD_ADDR; - .text : { *(.text) } - .rodata : { *(.rodata) } - - . = ALIGN(4); - /* Compressed kernel ELF image */ - - - .data : - { - _fdata = . ; - *(.data) - . = ALIGN(1024); - __vmlinux_start = .; - *(.vmlinux) - __vmlinux_end = .; - . = ALIGN(1024); - CONSTRUCTORS - } - - .bss : { _bstart = . ; *(.bss) ; *(.sbss) ; *(COMMON) ; _bend = . ; } - - /* /DISCARD/ : { *(.reginfo) ; *(.mdebug) ; *(.note) ; *(.comment) *(__ex_table) ; } */ - /DISCARD/ : { *(.reginfo) ; *(.note) ; *(.comment) *(__ex_table) ; } - - /* .filler : */ -} - - diff --git a/target/linux/realtek/files/rtkload/linux.bin b/target/linux/realtek/files/rtkload/linux.bin Binary files differdeleted file mode 100644 index 634a47ba2..000000000 --- a/target/linux/realtek/files/rtkload/linux.bin +++ /dev/null diff --git a/target/linux/realtek/files/rtkload/lzma b/target/linux/realtek/files/rtkload/lzma deleted file mode 100755 index 91f2500d1..000000000 --- a/target/linux/realtek/files/rtkload/lzma +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -LINUX_VERSION=`uname -r | grep 2.4` - -echo "$LINUX_VERSION" -if [ "$LINUX_VERSION" = "" ]; then -./lzma-26 $1 $2 $3 -elif [ "$LINUX_VERSION" != "" ]; then -./lzma-24 $1 $2 $3 -else -echo "can not find LZMA" -fi - diff --git a/target/linux/realtek/files/rtkload/lzma-24 b/target/linux/realtek/files/rtkload/lzma-24 Binary files differdeleted file mode 100755 index 239ce0de9..000000000 --- a/target/linux/realtek/files/rtkload/lzma-24 +++ /dev/null diff --git a/target/linux/realtek/files/rtkload/lzma-26 b/target/linux/realtek/files/rtkload/lzma-26 Binary files differdeleted file mode 100755 index 719c6c3f0..000000000 --- a/target/linux/realtek/files/rtkload/lzma-26 +++ /dev/null diff --git a/target/linux/realtek/files/rtkload/misc.c b/target/linux/realtek/files/rtkload/misc.c deleted file mode 100644 index 11bc20830..000000000 --- a/target/linux/realtek/files/rtkload/misc.c +++ /dev/null @@ -1,387 +0,0 @@ -/* - * misc.c - * - * This is a collection of several routines from gzip-1.0.3 - * adapted for Linux. - * - * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994 - * - * Modified for ARM Linux by Russell King - * - * Nicolas Pitre <nico@visuaide.com> 1999/04/14 : - * For this code to run directly from Flash, all constant variables must - * be marked with 'const' and all other variables initialized at run-time - * only. This way all non constant variables will end up in the bss segment, - * which should point to addresses in RAM and cleared to 0 on start. - * This allows for a much quicker boot time. - * - * Stolen for mips loader to handle decompression by Jay Carlson - * <nop@nop.com> 2000/04/17 - */ -#include <linux/autoconf.h> - -// david ------------------ -#ifdef BZ2_COMPRESS -#define __DO_QUIET__ -#endif -//------------------------- - -extern unsigned long kernelStartAddr; -unsigned int __machine_arch_type; - -#ifndef __DO_QUIET__ -#define puts prom_printf -#else -#define puts -#endif -#define arch_decomp_wdog() -#define arch_decomp_setup() -#define proc_decomp_setup() /* this is where cache flushing, clock, etc lived */ - -#define memzero(d, count) (memset((d), 0, (count))) - -#define __ptr_t void * -#define NULL ((void *) 0) - -typedef unsigned long __u32; -#define ___swab32(x) \ - ({ \ - __u32 __x = (x); \ - ((__u32)( \ - (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | \ - (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | \ - (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | \ - (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); \ - }) - -#define le32_to_cpu(x) ___swab32(x) - - -/* - * gzip declarations - */ -#define OF(args) args -#define STATIC static - -typedef unsigned char uch; -typedef unsigned short ush; -typedef unsigned long ulg; - -#define WSIZE 0x8000 /* Window size must be at least 32k, */ - /* and a power of two */ - -static uch *inbuf; /* input buffer */ -static uch window[WSIZE]; /* Sliding window buffer */ -static unsigned insize; /* valid bytes in inbuf */ -static unsigned inptr; /* index of next byte to be processed in inbuf */ -static unsigned outcnt; /* bytes in output buffer */ - -/* gzip flag byte */ -#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ -#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ -#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ -#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ -#define COMMENT 0x10 /* bit 4 set: file comment present */ -#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ -#define RESERVED 0xC0 /* bit 6,7: reserved */ - -#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf()) - -/* Diagnostic functions */ -#ifdef DEBUG -# define Assert(cond,msg) {if(!(cond)) error(msg);} -# define Trace(x) fprintf x -# define Tracev(x) {if (verbose) fprintf x ;} -# define Tracevv(x) {if (verbose>1) fprintf x ;} -# define Tracec(c,x) {if (verbose && (c)) fprintf x ;} -# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;} -#else -# define Assert(cond,msg) -# define Trace(x) -# define Tracev(x) -# define Tracevv(x) -# define Tracec(c,x) -# define Tracecv(c,x) -#endif - -static int fill_inbuf(void); -static void flush_window(void); -static void error(char *m); -static void gzip_mark(void **); -static void gzip_release(void **); - -extern char __vmlinux_start[]; -extern char __vmlinux_end[]; - -static uch *output_data; -static ulg output_ptr; -static ulg bytes_out; - -static void *malloc(int size); -static void free(void *where); -static void error(char *m); -static void gzip_mark(void **); -static void gzip_release(void **); - -/* static void puts(const char *); */ - -/* extern int end; */ -static ulg free_mem_ptr; -static ulg free_mem_ptr_end; - -#define HEAP_SIZE 0x2000 - -/* #include "../../../../lib/inflate.c" */ -/* #include "../lib/inflate.c"*/ - -// david ---------------- -//#include <inflate.c> - -#ifndef BZ2_COMPRESS -#include "inflate.c" -#else -#include "../lib/bzip2_inflate.c" -#endif -//---------------------- - -#ifdef CONFIG_RTL8197B_PANA -int is_vmlinux_checksum_ok(void) -{ - unsigned long sum = 0; - //unsigned long *buf = (unsigned long *)(((long)__vmlinux_start)+4); - //unsigned long image_len = (unsigned long)(__vmlinux_end -__vmlinux_start-4); - unsigned long *buf = (unsigned long *)(((long)__vmlinux_start)+8); - unsigned long image_len = (unsigned long)(__vmlinux_end -__vmlinux_start-8); - - for (; ((unsigned long)buf)<((unsigned long)__vmlinux_end); buf++) - sum += *buf; - - return ((sum == 0) ? 1 : 0); -} -#endif - -#ifndef STANDALONE_DEBUG -static void *malloc(int size) -{ - void *p; - - if (size <0) error("Malloc error\n"); - if (free_mem_ptr <= 0) error("Memory error\n"); - - free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */ - - p = (void *)free_mem_ptr; - free_mem_ptr += size; - - if (free_mem_ptr >= free_mem_ptr_end) - error("Out of memory"); - return p; -} - -static void free(void *where) -{ /* gzip_mark & gzip_release do the free */ -} - -static void gzip_mark(void **ptr) -{ - arch_decomp_wdog(); - *ptr = (void *) free_mem_ptr; -} - -static void gzip_release(void **ptr) -{ - arch_decomp_wdog(); - free_mem_ptr = (long) *ptr; -} -#else -static void gzip_mark(void **ptr) -{ -} - -static void gzip_release(void **ptr) -{ -} -#endif - -// david -#ifndef BZ2_COMPRESS -/* =========================================================================== - * Fill the input buffer. This is called only when the buffer is empty - * and at least one byte is really needed. - */ -int fill_inbuf(void) -{ - if (insize != 0) - error("ran out of input data\n"); - - inbuf = __vmlinux_start; - insize = &__vmlinux_end[0] - &__vmlinux_start[0]; - - inptr = 1; - return inbuf[0]; -} - -/* =========================================================================== - * Write the output window window[0..outcnt-1] and update crc and bytes_out. - * (Used for the decompressed data only.) - */ -void flush_window(void) -{ - ulg c = crc; - unsigned n; - uch *in, *out, ch; - - in = window; - out = &output_data[output_ptr]; - for (n = 0; n < outcnt; n++) { - ch = *out++ = *in++; - c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8); - } - crc = c; - bytes_out += (ulg)outcnt; - output_ptr += (ulg)outcnt; - outcnt = 0; - //puts("."); -} -#endif // BZ2_COMPRESS, david - - -static void error(char *x) -{ - int ptr; - - puts("\n\n"); - puts(x); - puts("\n\n -- System halted"); - - while(1); /* Halt */ -} - -#ifndef STANDALONE_DEBUG - -ulg -decompress_kernel(ulg output_start, ulg free_mem_ptr_p, ulg free_mem_ptr_end_p, - int arch_id) -{ - output_data = (uch *)output_start; /* Points to kernel start */ - free_mem_ptr = free_mem_ptr_p; - free_mem_ptr_end = free_mem_ptr_end_p; - __machine_arch_type = arch_id; - - proc_decomp_setup(); - arch_decomp_setup(); - -// david -// makecrc(); - puts("Uncompressing Linux..."); -// david --------------------------------- -// gunzip(); -#ifdef LZMA_COMPRESS -{ - #include "LzmaDecode.h" - - unsigned char *startBuf=__vmlinux_start; - unsigned char *outBuf = (unsigned char *)output_start; - unsigned int inLen=__vmlinux_end - __vmlinux_start; - - SizeT compressedSize; - unsigned char *inStream; - UInt32 outSize = 0; - UInt32 outSizeHigh = 0; - SizeT outSizeFull; - int res; - SizeT inProcessed; - SizeT outProcessed; - char tmpbuf[100]; - CLzmaDecoderState state; /* it's about 24-80 bytes structure, if int is 32-bit */ - unsigned char properties[LZMA_PROPERTIES_SIZE]; - -//#ifdef CONFIG_RTL8197B_PANA -// unsigned long pending_len = *((unsigned long *)__vmlinux_start); -// startBuf += 4; -// inLen -= (4+pending_len); -//#else - unsigned long pending_len = *((unsigned long *)__vmlinux_start); - kernelStartAddr = *((unsigned long *)(startBuf+4)); - startBuf += 8; - inLen -= (8+pending_len); -//#endif - - compressedSize = (SizeT)(inLen - (LZMA_PROPERTIES_SIZE + 8)); - - memcpy(properties, startBuf, sizeof(properties)); - startBuf += sizeof(properties); - - memcpy((char *)&outSize, startBuf, 4); - outSize = le32_to_cpu(outSize); - - memcpy((char *)&outSizeHigh, startBuf+4, 4); - outSizeHigh = le32_to_cpu(outSizeHigh); - - outSizeFull = (SizeT)outSize; - if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize) { - puts("LZMA: Too big uncompressed stream\n"); - return 0; - } - startBuf += 8; - - /* Decode LZMA properties and allocate memory */ - if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK) { - puts("LZMA: Incorrect stream properties\n"); - return 0; - } - state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb)); - - res = LzmaDecode(&state, startBuf, compressedSize, &inProcessed, - outBuf, outSizeFull, &outProcessed); - if (res != 0) { -#ifndef __DO_QUIET__ - sprintf(tmpbuf, "LZMA: Decoding error = %d\n", res); -#else - memcpy(tmpbuf, "LZMA: Decoding error = ", 23); - memcpy((tmpbuf+23), &res, 4); -#endif - puts(tmpbuf); - return 0; - } -} - -#else // !LZMA_COMPRESS -#ifndef BZ2_COMPRESS - makecrc(); - gunzip(); -#else - -// david ------------ -{ - unsigned char *startBuf=__vmlinux_start; - unsigned char *outBuf = (unsigned char *)output_start; - unsigned int inLen=__vmlinux_end - __vmlinux_start; - int outLen=-1; - - BZ2_bzBuffToBuffDecompress(outBuf, &outLen, startBuf, inLen, 0, 0); -} -#endif // BZ2_COMPRESS -//---------------------------------------- - -#endif // LZMA_COMPRESS - - puts(" done, booting the kernel.\n"); - return output_ptr; -} -#else - -char output_buffer[1500*1024]; - -int main() -{ - output_data = output_buffer; - - makecrc(); - puts("Uncompressing Linux..."); - gunzip(); - puts("done.\n"); - return 0; -} -#endif - diff --git a/target/linux/realtek/files/rtkload/prom_printf.c b/target/linux/realtek/files/rtkload/prom_printf.c deleted file mode 100644 index 7bf58cdb3..000000000 --- a/target/linux/realtek/files/rtkload/prom_printf.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Borrowed from arch/mips/r39xx/prom/init.c - * - */ - -/* - * init.c: early initialisation code for R39XX Class PDAs - * - * Copyright (C) 1999 Harald Koerfgen - * - * $Id: prom_printf.c,v 1.2 2008/08/04 08:54:44 michael Exp $ - */ - - - -#define CONFIG_SERIAL - -#include <stdarg.h> - -//#include <linux/config.h> -#include <linux/autoconf.h> - -#ifdef CONFIG_RTL_EB8186 -#include <asm/rtl8181.h> -#endif - -#if 1 - //#define __KERNEL__ - - //#include <asm/types.h> - //#include <asm/serial.h> - #include <asm/io.h> - - #define UART_THR 0x2000 - #define UART_LSR 0x2014 - - #define rtl_outb(port,val) outb(val,port) - #define rtl_inb(port) inb(port) -#endif - -void serial_outc(char c) -{ - int i=0; - while (1) - { - i++; - if (i >=0x6000) - break; - - if (rtl_inb(UART_LSR) & 0x20) - break; - } - rtl_outb(UART_THR, c); -} - - -/* - * Helpful for debugging :-) - */ -int prom_printf(const char * fmt, ...) -{ -#ifdef CONFIG_SERIAL - //extern void serial_outc(char); - static char buf[1024]; - va_list args; - char c; - int i = 0; - - /* - * Printing messages via serial port - */ - va_start(args, fmt); - vsprintf(buf, fmt, args); - va_end(args); - - for (i = 0; buf[i] != '\0'; i++) { - c = buf[i]; - if (c == '\n') - serial_outc('\r'); - serial_outc(c); - } - - return i; -#else - return 0; -#endif -} diff --git a/target/linux/realtek/files/rtkload/read_fd.c b/target/linux/realtek/files/rtkload/read_fd.c deleted file mode 100644 index bf40fb30e..000000000 --- a/target/linux/realtek/files/rtkload/read_fd.c +++ /dev/null @@ -1,69 +0,0 @@ -/* This file has not been tested for ages. */ - -#include "hfload.h" - -#include <sys/stat.h> -#include <sys/mman.h> -#include <unistd.h> - -void -read_struct(void *s, ssize_t size) -{ - ssize_t real; - - real = read(0, s, size); - if (size != real) { - printf("trying to read %d, got %d; dying.\n", size, real); - exit(1); - } - file_offset += real; -} - -void -seek_forward(int offset) { - int dummy, i; - ssize_t real; - - if (offset % 4 != 0) { - printf("Can't seek by a non-word aligned amount\n"); - exit(1); - } - - if (offset < file_offset) { - printf("can't seek backwards\n"); - exit(1); - } - - for (; offset < file_offset; file_offset += 4) { - real = read(0, &dummy, 4); - if (real != 4) { - printf("error seeking forward at offset %d\n", file_offset); - exit(1); - } - } -} - -void -copy_to_region(int *addr, ssize_t size) { - int i, dummy, real; - - printf("copying %x bytes from file offset %x to address %08x\n", - size, file_offset, addr); - -#ifdef FAKE_COPYING - for (i = 0; i < size; i += 4) { - read_struct(&dummy, sizeof(int)); - } -#else - real = read(0, addr, size); - if (real != size) { - printf("failed to read %d bytes, exiting\n"); - exit(1); - } - file_offset += real; -#endif -} - -void -init_read() { -} diff --git a/target/linux/realtek/files/rtkload/read_memory.c b/target/linux/realtek/files/rtkload/read_memory.c deleted file mode 100644 index 2596911e9..000000000 --- a/target/linux/realtek/files/rtkload/read_memory.c +++ /dev/null @@ -1,124 +0,0 @@ -/* read_memory.c - * - * This file is subject to the terms and conditions of the GNU - * General Public License. See the file "COPYING" in the main - * directory of this archive for more details. - * - * Copyright (C) 2000, Jay Carlson - */ - -/* read_memory is the memory-based back end for the image-reading - * functions. - * - * Support for non-compressed kernels has probably rotted. - */ - - -#include <linux/types.h> -#include "hfload.h" - -#ifndef EMBEDDED -#include <unistd.h> -#include <sys/mman.h> -#include <sys/stat.h> -#endif - -char *source_memory; - -#ifdef EMBEDDED -#ifndef COMPRESSED_KERNEL -extern char source_memory_start; -#endif -#endif - -// david ----------------------- -//#include <linux/config.h> -#include <linux/autoconf.h> - -//#ifdef BZ2_COMPRESS //sc_yang -void * memcpy(void * dest,const void *src,size_t count) -{ - char *tmp = (char *) dest, *s = (char *) src; - - while (count--) - *tmp++ = *s++; - - return dest; -} -#if 0 -void * memset(void * s, int c, size_t count) -{ - char *xs = (char *) s; - - while (count--) - *xs++ = (char) c; - - return s; -} -#endif // CONFIG_NINO_8MB -//------------------------------ - - -void -read_struct(void *s, ssize_t size) -{ - memcpy(s, source_memory+file_offset, size); - file_offset += size; -} - -void -seek_forward(int offset) { - if (offset % 4 != 0) { - #ifndef __DO_QUIET__ - printf("Can't seek by a non-word aligned amount\n"); - #endif - exit(1); - } - - if (offset < file_offset) { - #ifndef __DO_QUIET__ - printf("can't seek backwards\n"); - #endif - exit(1); - } - - file_offset = offset; -} - -void -copy_to_region(int *addr, ssize_t size) { - int i, dummy; - - int *source, *dest; -#ifndef __DO_QUIET__ - printf("copying 0x%x bytes from file offset 0x%x to address 0x%08x\n", - size, file_offset, addr); -#endif -#ifndef FAKE_COPYING - memcpy(addr, source_memory+file_offset, size); -#endif - - file_offset += size; -} - -void -init_read() { -#ifndef EMBEDDED - struct stat buf; - if (fstat(0, &buf)) { - perror("stat"); - exit(1); - } - source_memory = mmap(0, buf.st_size & ~(4095), PROT_READ, MAP_PRIVATE, 0, 0); - if (!source_memory) { - perror("mmap"); - exit(1); - } -#else -#ifdef COMPRESSED_KERNEL - source_memory = (char *)UNCOMPRESS_OUT; -#else - source_memory = &source_memory_start; -#endif -#endif -} diff --git a/target/linux/realtek/files/rtkload/start.S b/target/linux/realtek/files/rtkload/start.S deleted file mode 100644 index 32df1f6f7..000000000 --- a/target/linux/realtek/files/rtkload/start.S +++ /dev/null @@ -1,263 +0,0 @@ -//#include <linux/config.h> -#include <linux/autoconf.h> -#include <asm/asm.h> -#include <asm/regdef.h> -//#include <asm/mipsregs.h> - -#if defined(CONFIG_RTL_819X) -#define CONFIG_DONOT_ADJUST_SYSCLK_MEMSP -#endif - -#include "start.h" -#ifndef boot32 -#define NEWSTACK (0x80670000) -#else -#define NEWSTACK (0x809FFF00) -#endif - .globl old_stack_pointer - - .extern __start_dram - - .text - .globl __start -__start: - -#ifdef CONFIG_DONOT_ADJUST_SYSCLK_MEMSP - nop -#else - // Set PLLMNR and SYSCLKR - jal hfclock_setting - nop -#endif - - move s0, zero - mtc0 s0, $12 - nop - nop - -#if 0 - /* Clock */ - li a0,0xbd010108 - li a1,0x0000000b - sw a1,0(a0) - nop - nop - nop - nop -#endif - -#ifdef CONFIG_RTL_EB8186 - /* Memory Controllor */ - li a0,0xbd011008 - li a1,0x00000884 - li a1,0x000008c7 - li a1,0x00000cda - li a1,0x00000886 - li a1,0x000008c7 // <victor> for 187/124 - /*sw a1,0(a0) */ - nop - nop - nop - nop - - - - - /*--- initialize and start COP3*/ - mfc0 $8,$12 - nop - nop - or $8,0x80000000 - mtc0 $8,$12 - nop - nop - - -#if 1 - la a0, 0x90000000 - mtc0 a0, $12 - nop - nop - mfc0 t0, $20 - nop - nop - ori t0, 0x1 - mtc0 t0, $20 - nop - nop -#if 0 - la a0, 0x10000000 - mtc3 a0, $4 - la a0, 0x10000fff - nop - mtc3 a0, $5 - nop - la a0, 0x90000000 - sw zero, 0(a0) - lw t0, 0(a0) - nop - la a0, 0x90000fff - sb zero, 0(a0) - lb t0, 0(a0) -#endif -#endif -#endif // CONFIG_RTL_EB8186 - - - nop - - -#if 0 - /*la t0, __start_dram */ - /*and t0, 0x0fffffff*/ # translate to physical address - la t0, 0x81000000 - and t0, 0x0fffffff # translate to physical address - mtc3 t0, $4 # $4: d-ram base - nop - addi t0, t0, 0x1000 - 1 # total 2k bytes used//2003-07-04//TKIP_encryption - mtc3 t0, $5 # $5: d-ram top - nop -#endif - - - - la s0, _bstart - la s1, _bend - - move t0, s0 - -1: - sw zero, 0(t0) - addi t0, 4 - bne t0, s1, 1b - - //sw sp, old_stack_pointer -// david ------------------------ -// li sp, NEWSTACK -//sc_yang -//#ifndef BZ2_COMPRESS -// li sp, NEWSTACK -//#else - move t0, s1 - addi t0, t0, 4096 - move sp, t0 - move a0, t0 -//#endif -//------------------------------- - - j main - nop - - .globl exit -exit: - j exit - nop - - .globl start_kernel -start_kernel: - move t0, a0 - li a0, 0 - li a1, 0 - li a2, 0 - jr t0 - nop - - -hfclock_setting: - // Check chip version to set divider register - li t1, REG_REVISION - lw t0, 0(t1) - li t1, 0xf0000000 - and t0, t0, t1 - srl t0, t0, 0x1c // Right shift 28 bits - - beq t0, VERSION_D, version_8186_C //set D cut keep 108MHz - nop - -// bne t0, VERSION_D, 1f -// nop -// j ra // 8186 D cut doesn't need watch dog reset. -// nop - -1: - beq t0, VERSION_C, version_8186_C - nop - - -version_8186_B: - // Check PLLMNR and SYSCLKR Registers. - la a0, REG_PLLMNR - lw t0, 0(a0) - and t0, t0, 0x3FFFF //You must mask other bits!! - li t1, VAL_PLLMNR_8186B - bne t0, t1, set_B - nop - - la a0, REG_SYSCLKR - lw t0, 0(a0) - and t0, t0, 0xFFF //You must mask other bits!! - li t1, VAL_SYSCLKR_8186B - bne t0, t1, set_B - nop - - j ra //PLLMNR and SYSCLKR are set already. - nop - -set_B: - // Set CPU/MEM Clock and Watch Dog Reset. - li t0, VAL_PLLMNR_8186B - la a0, REG_PLLMNR - sw t0, 0(a0) - - li t0, VAL_SYSCLKR_8186B - la a0, REG_SYSCLKR - sw t0, 0(a0) - - j start_watch_dog - nop - -version_8186_C: - // Check PLLMNR and SYSCLKR Registers. - la a0, REG_PLLMNR - lw t0, 0(a0) - and t0, t0, 0x3FFFF //You must mask other bits!! - li t1, VAL_PLLMNR_8186C - bne t0, t1, set_C - nop - - la a0, REG_SYSCLKR - lw t0, 0(a0) - and t0, t0, 0xFFF //You must mask other bits!! - li t1, VAL_SYSCLKR_8186C - bne t0, t1, set_C - nop - - j ra - nop - -set_C: - // Set CPU/MEM Clock and Watch Dog Reset. - li t0, VAL_PLLMNR_8186C - la a0, REG_PLLMNR - sw t0, 0(a0) - - li t0, VAL_SYSCLKR_8186C - la a0, REG_SYSCLKR - sw t0, 0(a0) - - j start_watch_dog - nop - -start_watch_dog: - // start WDTDOG - la a0, REG_CDBR - la t0, 0x2 - sw t0, 0(a0) - la t0, 0x100 - la a0, REG_WDTCNR - sw t0, 0(a0) -1: - b 1b - nop - - diff --git a/target/linux/realtek/files/rtkload/start.h b/target/linux/realtek/files/rtkload/start.h deleted file mode 100644 index c5397d2b9..000000000 --- a/target/linux/realtek/files/rtkload/start.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef __RTL_START_H__
-#define __RTL_START_H__
- -//#include <linux/config.h>
-#include <linux/autoconf.h> -
-//----- System Registers ------------------------------------------------
-#define REG_REVISION 0xbd01010c
-#define REG_PLLMNR 0xbd010104
-#define REG_SYSCLKR 0xbd010108
-#define REG_GPEFDIR 0xbd010144
-#define REG_GPEFDATA 0xbd010140
-#define REG_MTCR0 0xbd011004
-#define REG_MCR 0xbd011000
-#define REG_MTCR1 0xbd011008
-#define REG_TKNR 0xbd010110
-#define REG_GISR 0xbd010004
-#define REG_WDTCNR 0xbd01005c
-#define REG_CDBR 0xbd010058
-
-//----- Revision bit ----------------------------------------------------
-#define VERSION_B 0x0 //0000
-#define VERSION_C 0x8 //1000
-#define VERSION_D 0x4 //0100
-
-//----- DPLL and Clock Setting ------------------------------------------
-#define VAL_PLLMNR_8186B 0x36704 // 160/128
-#define VAL_SYSCLKR_8186B 0xa0b // CPU=320/2 MEM=320/2.5
-
-#define VAL_PLLMNR_8186C 0x35a03 // 180/108
-#define VAL_SYSCLKR_8186C 0x090b // CPU=270/1.5 MEM=270/2.5
-
-//----- Memory Setting --------------------------------------------------
-#define VAL_FLASH_TIMING 0x88880000
-//#define VAL_FLASH_TIMING 0x33330000 //high speed.
-
-
-#if (defined(CONFIG_SKIP_ADJUST_SYSCLK) ) - #define CONFIG_DONOT_ADJUST_SYSCLK_MEMSP -#endif
-//----- Others ----------------------------------------------------------
-#define PCI_LOW_COUNTER 0xFFFF
-#define BOOT_ADDR 0x80100000
-
-#endif
-
diff --git a/target/linux/realtek/files/rtkload/string.c b/target/linux/realtek/files/rtkload/string.c deleted file mode 100644 index 6f787844e..000000000 --- a/target/linux/realtek/files/rtkload/string.c +++ /dev/null @@ -1,382 +0,0 @@ -/* - * linux/lib/string.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - -/* - * stupid library routines.. The optimized versions should generally be found - * as inline code in <asm-xx/string.h> - * - * These are buggy as well.. - * - * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de> - * - Added strsep() which will replace strtok() soon (because strsep() is - * reentrant and should be faster). Use only strsep() in new code, please. - */ - -#include <linux/types.h> -#include <linux/string.h> -#include <linux/ctype.h> - -#ifndef __HAVE_ARCH_STRNICMP -int strnicmp(const char *s1, const char *s2, size_t len) -{ - /* Yes, Virginia, it had better be unsigned */ - unsigned char c1, c2; - - c1 = 0; c2 = 0; - if (len) { - do { - c1 = *s1; c2 = *s2; - s1++; s2++; - if (!c1) - break; - if (!c2) - break; - if (c1 == c2) - continue; - c1 = tolower(c1); - c2 = tolower(c2); - if (c1 != c2) - break; - } while (--len); - } - return (int)c1 - (int)c2; -} -#endif - -/* char * ___strtok = NULL; */ -char * ___strtok; /* live in BSS, please */ - -#ifndef __HAVE_ARCH_STRCPY -char * strcpy(char * dest,const char *src) -{ - char *tmp = dest; - - while ((*dest++ = *src++) != '\0') - /* nothing */; - return tmp; -} -#endif - -#ifndef __HAVE_ARCH_STRNCPY -char * strncpy(char * dest,const char *src,size_t count) -{ - char *tmp = dest; - - while (count-- && (*dest++ = *src++) != '\0') - /* nothing */; - - return tmp; -} -#endif - -#ifndef __HAVE_ARCH_STRCAT -char * strcat(char * dest, const char * src) -{ - char *tmp = dest; - - while (*dest) - dest++; - while ((*dest++ = *src++) != '\0') - ; - - return tmp; -} -#endif - -#ifndef __HAVE_ARCH_STRNCAT -char * strncat(char *dest, const char *src, size_t count) -{ - char *tmp = dest; - - if (count) { - while (*dest) - dest++; - while ((*dest++ = *src++)) { - if (--count == 0) { - *dest = '\0'; - break; - } - } - } - - return tmp; -} -#endif - -#ifndef __HAVE_ARCH_STRCMP -int strcmp(const char * cs,const char * ct) -{ - register signed char __res; - - while (1) { - if ((__res = *cs - *ct++) != 0 || !*cs++) - break; - } - - return __res; -} -#endif - -#ifndef __HAVE_ARCH_STRNCMP -int strncmp(const char * cs,const char * ct,size_t count) -{ - register signed char __res = 0; - - while (count) { - if ((__res = *cs - *ct++) != 0 || !*cs++) - break; - count--; - } - - return __res; -} -#endif - -#ifndef __HAVE_ARCH_STRCHR -char * strchr(const char * s, int c) -{ - for(; *s != (char) c; ++s) - if (*s == '\0') - return NULL; - return (char *) s; -} -#endif - -#ifndef __HAVE_ARCH_STRRCHR -char * strrchr(const char * s, int c) -{ - const char *p = s + strlen(s); - do { - if (*p == (char)c) - return (char *)p; - } while (--p >= s); - return NULL; -} -#endif - -#ifndef __HAVE_ARCH_STRLEN -size_t strlen(const char * s) -{ - const char *sc; - - for (sc = s; *sc != '\0'; ++sc) - /* nothing */; - return sc - s; -} -#endif - -#ifndef __HAVE_ARCH_STRNLEN -size_t strnlen(const char * s, size_t count) -{ - const char *sc; - - for (sc = s; count-- && *sc != '\0'; ++sc) - /* nothing */; - return sc - s; -} -#endif - -#ifndef __HAVE_ARCH_STRSPN -size_t strspn(const char *s, const char *accept) -{ - const char *p; - const char *a; - size_t count = 0; - - for (p = s; *p != '\0'; ++p) { - for (a = accept; *a != '\0'; ++a) { - if (*p == *a) - break; - } - if (*a == '\0') - return count; - ++count; - } - - return count; -} -#endif - -#ifndef __HAVE_ARCH_STRPBRK -char * strpbrk(const char * cs,const char * ct) -{ - const char *sc1,*sc2; - - for( sc1 = cs; *sc1 != '\0'; ++sc1) { - for( sc2 = ct; *sc2 != '\0'; ++sc2) { - if (*sc1 == *sc2) - return (char *) sc1; - } - } - return NULL; -} -#endif - -#ifndef __HAVE_ARCH_STRTOK -char * strtok(char * s,const char * ct) -{ - char *sbegin, *send; - - sbegin = s ? s : ___strtok; - if (!sbegin) { - return NULL; - } - sbegin += strspn(sbegin,ct); - if (*sbegin == '\0') { - ___strtok = NULL; - return( NULL ); - } - send = strpbrk( sbegin, ct); - if (send && *send != '\0') - *send++ = '\0'; - ___strtok = send; - return (sbegin); -} -#endif - -#ifndef __HAVE_ARCH_STRSEP - -char * strsep(char **s, const char * ct) -{ - char *sbegin=*s; - if (!sbegin) - return NULL; - - sbegin += strspn(sbegin,ct); - if (*sbegin == '\0') - return NULL; - - *s = strpbrk( sbegin, ct); - if (*s && **s != '\0') - **s++ = '\0'; - return (sbegin); -} -#endif - -#ifndef __HAVE_ARCH_MEMSET -void * memset(void * s, int c, size_t count) -{ - char *xs = (char *) s; - - while (count--) - *xs++ = (char) c; - - return s; -} -#endif - -/* -#ifndef __HAVE_ARCH_BCOPY -char * bcopy(const char * src, char * dest, int count) -{ - char *tmp = dest; - - while (count--) - *tmp++ = *src++; - - return dest; -} -#endif -*/ - -#ifndef __HAVE_ARCH_MEMCPY -void * memcpy(void * dest,const void *src,size_t count) -{ - char *tmp = (char *) dest, *s = (char *) src; - - while (count--) - *tmp++ = *s++; - - return dest; -} -#endif - -#ifndef __HAVE_ARCH_MEMMOVE -void * memmove(void * dest,const void *src,size_t count) -{ - char *tmp, *s; - - if (dest <= src) { - tmp = (char *) dest; - s = (char *) src; - while (count--) - *tmp++ = *s++; - } - else { - tmp = (char *) dest + count; - s = (char *) src + count; - while (count--) - *--tmp = *--s; - } - - return dest; -} -#endif - -#ifndef __HAVE_ARCH_MEMCMP -int memcmp(const void * cs,const void * ct,size_t count) -{ - const unsigned char *su1, *su2; - signed char res = 0; - - for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) - if ((res = *su1 - *su2) != 0) - break; - return res; -} -#endif - -/* - * find the first occurrence of byte 'c', or 1 past the area if none - */ -#ifndef __HAVE_ARCH_MEMSCAN -void * memscan(void * addr, int c, size_t size) -{ - unsigned char * p = (unsigned char *) addr; - unsigned char * e = p + size; - - while (p != e) { - if (*p == c) - return (void *) p; - p++; - } - - return (void *) p; -} -#endif - -#ifndef __HAVE_ARCH_STRSTR -char * strstr(const char * s1,const char * s2) -{ - int l1, l2; - - l2 = strlen(s2); - if (!l2) - return (char *) s1; - l1 = strlen(s1); - while (l1 >= l2) { - l1--; - if (!memcmp(s1,s2,l2)) - return (char *) s1; - s1++; - } - return NULL; -} -#endif - -#ifndef __HAVE_ARCH_MEMCHR -void *memchr(const void *s, int c, size_t n) -{ - const unsigned char *p = s; - while (n-- != 0) { - if ((unsigned char)c == *p++) { - return (void *)(p-1); - } - } - return NULL; -} - -#endif diff --git a/target/linux/realtek/files/rtkload/target.script b/target/linux/realtek/files/rtkload/target.script deleted file mode 100644 index a62023f89..000000000 --- a/target/linux/realtek/files/rtkload/target.script +++ /dev/null @@ -1,27 +0,0 @@ -/* ld.script - * - * This file is subject to the terms and conditions of the GNU - * General Public License. See the file "COPYING" in the main - * directory of this archive for more details. - * - * Copyright (C) 2000, Jay Carlson - */ - -OUTPUT_FORMAT("elf32-littlemips") -OUTPUT_ARCH(mips) - -/* Someday I'll figure out how this works */ -/* MEMORY { bootcode : ORIGIN = 0x80000000, LENGTH = 512 bytes } */ -/* MEMORY { nandjrom : ORIGIN = 0x80000200, LENGTH = 2M - 512 bytes } */ -/* MEMORY { ext2n : ORIGIN = 0x80200000, LENGTH = 2M bytes } */ - -SECTIONS -{ - . = 0x80000000 ; - BOOTCODE : { bootcode* } - NANDJROM : { nandrom* } - EXT2N : { ext2n* } - -} - - diff --git a/target/linux/realtek/files/rtkload/vmlinux_img.c b/target/linux/realtek/files/rtkload/vmlinux_img.c deleted file mode 100644 index 163a1ac1c..000000000 --- a/target/linux/realtek/files/rtkload/vmlinux_img.c +++ /dev/null @@ -1,8 +0,0 @@ - -void vmlinux_entry(void); - -void vmlinux_entry(void) -{ - - -} diff --git a/target/linux/realtek/files/rtkload/vmlinux_img.gz b/target/linux/realtek/files/rtkload/vmlinux_img.gz Binary files differdeleted file mode 100644 index d273b3177..000000000 --- a/target/linux/realtek/files/rtkload/vmlinux_img.gz +++ /dev/null diff --git a/target/linux/realtek/files/rtkload/vsprintf.c b/target/linux/realtek/files/rtkload/vsprintf.c deleted file mode 100644 index 501a05985..000000000 --- a/target/linux/realtek/files/rtkload/vsprintf.c +++ /dev/null @@ -1,366 +0,0 @@ -/* - * linux/lib/vsprintf.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - -/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ -/* - * Wirzenius wrote this portably, Torvalds fucked it up :-) - */ - -#include <stdarg.h> -#include <linux/types.h> -#include <linux/string.h> -#include <linux/ctype.h> - -#include <asm/div64.h> - -#if 1 -/* Not needed on 64bit architectures */ -//#if BITS_PER_LONG == 32 -//porting from linux-2.6.30/lib/div64.c -uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base) -{ - uint64_t rem = *n; - uint64_t b = base; - uint64_t res, d = 1; - uint32_t high = rem >> 32; - - /* Reduce the thing a bit first */ - res = 0; - if (high >= base) { - high /= base; - res = (uint64_t) high << 32; - rem -= (uint64_t) (high*base) << 32; - } - - while ((int64_t)b > 0 && b < rem) { - b = b+b; - d = d+d; - } - - do { - if (rem >= b) { - rem -= b; - res += d; - } - b >>= 1; - d >>= 1; - } while (d); - - *n = res; - return rem; -} -//#endif /* BITS_PER_LONG == 32 */ -#endif - -unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) -{ - unsigned long result = 0,value; - - if (!base) { - base = 10; - if (*cp == '0') { - base = 8; - cp++; - if ((*cp == 'x') && isxdigit(cp[1])) { - cp++; - base = 16; - } - } - } - while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) - ? toupper(*cp) : *cp)-'A'+10) < base) { - result = result*base + value; - cp++; - } - if (endp) - *endp = (char *)cp; - return result; -} - -long simple_strtol(const char *cp,char **endp,unsigned int base) -{ - if(*cp=='-') - return -simple_strtoul(cp+1,endp,base); - return simple_strtoul(cp,endp,base); -} - -/* we use this so that we can do without the ctype library */ -#define is_digit(c) ((c) >= '0' && (c) <= '9') - -static int skip_atoi(const char **s) -{ - int i=0; - - while (is_digit(**s)) - i = i*10 + *((*s)++) - '0'; - return i; -} - -#define ZEROPAD 1 /* pad with zero */ -#define SIGN 2 /* unsigned/signed long */ -#define PLUS 4 /* show plus */ -#define SPACE 8 /* space if plus */ -#define LEFT 16 /* left justified */ -#define SPECIAL 32 /* 0x */ -#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ - -//static char * number(char * str, long long num, int base, int size, int precision, int type) -static char * number(char * str, uint64_t num, int base, int size, int precision, int type) -{ - char c,sign,tmp[66]; - const char *digits="0123456789abcdefghijklmnopqrstuvwxyz"; - int i; - - if (type & LARGE) - digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - if (type & LEFT) - type &= ~ZEROPAD; - if (base < 2 || base > 36) - return 0; - c = (type & ZEROPAD) ? '0' : ' '; - sign = 0; - if (type & SIGN) { - if (num < 0) { - sign = '-'; - num = -num; - size--; - } else if (type & PLUS) { - sign = '+'; - size--; - } else if (type & SPACE) { - sign = ' '; - size--; - } - } - if (type & SPECIAL) { - if (base == 16) - size -= 2; - else if (base == 8) - size--; - } - i = 0; - if (num == 0) - tmp[i++]='0'; - else while (num != 0) - tmp[i++] = digits[do_div(num,base)]; - if (i > precision) - precision = i; - size -= precision; - if (!(type&(ZEROPAD+LEFT))) - while(size-->0) - *str++ = ' '; - if (sign) - *str++ = sign; - if (type & SPECIAL) { - if (base==8) - *str++ = '0'; - else if (base==16) { - *str++ = '0'; - *str++ = digits[33]; - } - } - if (!(type & LEFT)) - while (size-- > 0) - *str++ = c; - while (i < precision--) - *str++ = '0'; - while (i-- > 0) - *str++ = tmp[i]; - while (size-- > 0) - *str++ = ' '; - return str; -} - -/* Forward decl. needed for IP address printing stuff... */ -int sprintf(char * buf, const char *fmt, ...); - -int vsprintf(char *buf, const char *fmt, va_list args) -{ - int len; - unsigned long long num; - int i, base; - char * str; - const char *s; - - int flags; /* flags to number() */ - - int field_width; /* width of output field */ - int precision; /* min. # of digits for integers; max - number of chars for from string */ - int qualifier; /* 'h', 'l', or 'L' for integer fields */ - /* 'z' support added 23/7/1999 S.H. */ - /* 'z' changed to 'Z' --davidm 1/25/99 */ - - - for (str=buf ; *fmt ; ++fmt) { - if (*fmt != '%') { - *str++ = *fmt; - continue; - } - - /* process flags */ - flags = 0; - repeat: - ++fmt; /* this also skips first '%' */ - switch (*fmt) { - case '-': flags |= LEFT; goto repeat; - case '+': flags |= PLUS; goto repeat; - case ' ': flags |= SPACE; goto repeat; - case '#': flags |= SPECIAL; goto repeat; - case '0': flags |= ZEROPAD; goto repeat; - } - - /* get field width */ - field_width = -1; - if (is_digit(*fmt)) - field_width = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - field_width = va_arg(args, int); - if (field_width < 0) { - field_width = -field_width; - flags |= LEFT; - } - } - - /* get the precision */ - precision = -1; - if (*fmt == '.') { - ++fmt; - if (is_digit(*fmt)) - precision = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - precision = va_arg(args, int); - } - if (precision < 0) - precision = 0; - } - - /* get the conversion qualifier */ - qualifier = -1; - if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt =='Z') { - qualifier = *fmt; - ++fmt; - } - - /* default base */ - base = 10; - - switch (*fmt) { - case 'c': - if (!(flags & LEFT)) - while (--field_width > 0) - *str++ = ' '; - *str++ = (unsigned char) va_arg(args, int); - while (--field_width > 0) - *str++ = ' '; - continue; - - case 's': - s = va_arg(args, char *); - if (!s) - s = "<NULL>"; - - len = strnlen(s, precision); - - if (!(flags & LEFT)) - while (len < field_width--) - *str++ = ' '; - for (i = 0; i < len; ++i) - *str++ = *s++; - while (len < field_width--) - *str++ = ' '; - continue; - - case 'p': - if (field_width == -1) { - field_width = 2*sizeof(void *); - flags |= ZEROPAD; - } - str = number(str, - (unsigned long) va_arg(args, void *), 16, - field_width, precision, flags); - continue; - - - case 'n': - if (qualifier == 'l') { - long * ip = va_arg(args, long *); - *ip = (str - buf); - } else if (qualifier == 'Z') { - size_t * ip = va_arg(args, size_t *); - *ip = (str - buf); - } else { - int * ip = va_arg(args, int *); - *ip = (str - buf); - } - continue; - - case '%': - *str++ = '%'; - continue; - - /* integer number formats - set up the flags and "break" */ - case 'o': - base = 8; - break; - - case 'X': - flags |= LARGE; - case 'x': - base = 16; - break; - - case 'd': - case 'i': - flags |= SIGN; - case 'u': - break; - - default: - *str++ = '%'; - if (*fmt) - *str++ = *fmt; - else - --fmt; - continue; - } - if (qualifier == 'L') - num = va_arg(args, long long); - else if (qualifier == 'l') { - num = va_arg(args, unsigned long); - if (flags & SIGN) - num = (signed long) num; - } else if (qualifier == 'Z') { - num = va_arg(args, size_t); - } else if (qualifier == 'h') { - num = (unsigned short) va_arg(args, int); - if (flags & SIGN) - num = (signed short) num; - } else { - num = va_arg(args, unsigned int); - if (flags & SIGN) - num = (signed int) num; - } - str = number(str, num, base, field_width, precision, flags); - } - *str = '\0'; - return str-buf; -} - -int sprintf(char * buf, const char *fmt, ...) -{ - va_list args; - int i; - - va_start(args, fmt); - i=vsprintf(buf,fmt,args); - va_end(args); - return i; -} diff --git a/target/linux/realtek/image/Makefile b/target/linux/realtek/image/Makefile index f5f1c4f56..d0dc6ab7e 100644 --- a/target/linux/realtek/image/Makefile +++ b/target/linux/realtek/image/Makefile @@ -7,76 +7,72 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/image.mk -#DROP_SECTIONS := .reginfo .mdebug .comment .note .pdr .options .MIPS.options -#OBJCOPY_BIN := $(TARGET_CROSS)objcopy -S -O bin $(addprefix --remove-section=,$(DROP_SECTIONS)) +JFFS2_BLOCKSIZE=4k -TCC=$(TARGET_CROSS)cc -TOBJCOPY=$(TARGET_CROSS)objcopy -TLD=$(TARGET_CROSS)ld +#OBJCOPY=$(TARGET_CROSS)objcopy +# define subtarget, should be replaced with $(SUBTARGET) when more chips will be introduced +STARGET=rtl8196c -JFFS2_BLOCKSIZE=4k +COMMA:=, +define mkcmdline +$(if $(1),board=$(1) )$(if $(2),console=$(2)$(COMMA)$(3)) +endef define Image/Prepare - gzip -9 < $(KDIR)/vmlinux > $(KDIR)/vmlinux.gz +# $(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL) +# $(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux.elf2 + lzma e $(KDIR)/vmlinux -lc1 -lp2 -pb2 $(KDIR)/vmlinux.lzma endef define Image/BuildKernel - cp $(KDIR)/vmlinux.gz $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz - cp $(LINUX_DIR)/rtkload/linux.bin $(BIN_DIR)/$(IMG_PREFIX)-kernel.bin + $(call Image/BuildLoader,loader-$(STARGET),bin,$(call mkcmdline,$(PROFILE),ttyS0,38400) root=/dev/mtdblock2,${CONFIG_REALTEK_KERNEL_LOAD_ADDRESS},$(shell dd if=$(KDIR)/vmlinux.elf skip=24 bs=1 count=4 conv=swab 2>/dev/null | hexdump -v -e '"0x" 2/2 "%X"')) + cvimg linux $(KDIR)/loader-$(STARGET).bin \ + $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-kernel.bin \ + ${CONFIG_REALTEK_KERNEL_LOAD_ADDRESS} \ + ${CONFIG_REALTEK_KERNEL_OFFSET} endef define Image/Build/jffs2-4k - dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-$(1).img bs=4k conv=sync - cvimg root $(BIN_DIR)/$(IMG_PREFIX)-$(1).img $(BIN_DIR)/$(IMG_PREFIX)-$(1).bin F0000 ${CONFIG_REALTEK_ROOTFS_OFFSET} + dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-$(1).img bs=4k conv=sync + cvimg root $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-$(1).img \ + $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-$(1).bin \ + ${CONFIG_REALTEK_ROOTFS_OFFSET} \ + ${CONFIG_REALTEK_ROOTFS_OFFSET} endef -BS_KERNEL=$$$$((`printf %d 0x${CONFIG_REALTEK_ROOTFS_OFFSET}`-`printf %d 0x${CONFIG_REALTEK_KERNEL_OFFSET}`)) -BS_ROOTFS=$$$$((`printf %d ${CONFIG_REALTEK_FLASH_SIZE}`-`printf %d 0x${CONFIG_REALTEK_ROOTFS_OFFSET}`)) define Image/Build/squashfs $(call prepare_generic_squashfs,$(KDIR)/root.squashfs) - dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-$(1).img bs=128k conv=sync - cvimg root $(BIN_DIR)/$(IMG_PREFIX)-$(1).img $(BIN_DIR)/$(IMG_PREFIX)-$(1).bin F0000 ${CONFIG_REALTEK_ROOTFS_OFFSET} - echo "BS_KERNEL=$(BS_KERNEL)" - echo "BS_ROOTFS=$(BS_ROOTFS)" - ( \ - dd if=$(BIN_DIR)/$(IMG_PREFIX)-kernel.bin bs=$(BS_KERNEL) conv=sync; \ - dd if=$(BIN_DIR)/$(IMG_PREFIX)-$(1).img bs=$(BS_ROOTFS) conv=sync; \ - ) > $(BIN_DIR)/$(IMG_PREFIX)-$(1)-sysupgrade.img + dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-$(1).img bs=4k conv=sync + cvimg root $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-$(1).img \ + $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-$(1).bin \ + ${CONFIG_REALTEK_ROOTFS_OFFSET} \ + ${CONFIG_REALTEK_ROOTFS_OFFSET} endef - #need to fix this mess - JMM - # - #bixutil pack $(KDIR)/vmlinux.gz $(BIN_DIR)/kernel-$(BOARD)-$(KERNEL).bix - #cat $(KDIR)/vmlinux.gz \ - # $(KDIR)/root.$(1) \ - # > $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-$(1).bin - # - # - # - #echo "void vmlinux_entry(void) { }" > vmlinux_img.c - #$(TCC) -fno-pic -mno-abicalls -Os -fomit-frame-pointer -D__KERNEL__ -c vmlinux_img.c -o vmlinux_img.o - #$(TOBJCOPY) --add-section .vmlinux=vmlinux_img.gz vmlinux_img.o - # - #echo "OUTPUT_ARCH(mips)" > ld.script - #echo "ENTRY(__start)" >> ld.script - #echo "SECTIONS" >> ld.script - #echo "{" >> ld.script - #echo " /* The loader itself */" >> ld.script - #echo " . = ${LOAD_STARTADDR};" >> ld.script - #echo " .text : { *(.text) }" >> ld.script - #echo " .rodata : { *(.rodata) }" >> ld.script - #echo " . = ALIGN(4);" >> ld.script - #echo " .data : { _fdata = . ; *(.data) . = ALIGN(1024); __vmlinux_start = .; *(.vmlinux) __vmlinux_end = .; . = ALIGN(1024); CONSTRUCTORS }" >> ld.script - #echo " .bss : { _bstart = . ; *(.bss) ; *(.sbss) ; *(COMMON) ; _bend = . ; }" >> ld.script - #echo " /DISCARD/ : { *(.reginfo) ; *(.note) ; *(.comment) *(__ex_table) ; }" >> ld.script - #echo "}" >> ld.script - #$(TLD) -static -nostdlib -G 0 -T ld.script -o mem $(START_FILE) $(LOADER_FILES) $(SUPPORT_FILES) vmlinux_img.o - - +BS_KERNEL=$$$$((`printf %d 0x${CONFIG_REALTEK_ROOTFS_OFFSET}`-`printf %d 0x${CONFIG_REALTEK_KERNEL_OFFSET}`)) +BS_ROOTFS=$$$$((`printf %d ${CONFIG_REALTEK_FLASH_SIZE}`-`printf %d 0x${CONFIG_REALTEK_ROOTFS_OFFSET}`)) define Image/Build $(call Image/Build/$(1),$(1)) + echo "BS_KERNEL=$(BS_KERNEL)" + echo "BS_ROOTFS=$(BS_ROOTFS)" + ( \ + dd if=$(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-kernel.bin bs=$(BS_KERNEL) conv=sync; \ + dd if=$(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-$(1).img bs=$(BS_ROOTFS) conv=sync; \ + ) > $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-$(1)-sysupgrade.img + mgbin -c -o $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-$(1)-fw.bin \ + $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-$(1).bin \ + $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-kernel.bin +endef + +LOADER_MAKE := $(NO_TRACE_MAKE) -C lzma-loader KDIR=$(KDIR) LINUX_DIR=$(LINUX_DIR) +define Image/BuildLoader + -rm -rf $(KDIR)/lzma-loader + $(LOADER_MAKE) LOADER=$(1).$(2) KERNEL_CMDLINE="$(3)" \ + LZMA_TEXT_START=$(4) LOADADDR=0x80000000 KERNELENTRY=$(5) \ + LOADER_DATA="$(KDIR)/vmlinux.lzma" BOARD="$(1)" \ + compile loader.$(2) endef $(eval $(call BuildImage)) diff --git a/target/linux/realtek/image/lzma-loader/Makefile b/target/linux/realtek/image/lzma-loader/Makefile new file mode 100644 index 000000000..82e7f9d90 --- /dev/null +++ b/target/linux/realtek/image/lzma-loader/Makefile @@ -0,0 +1,65 @@ +# +# Copyright (C) 2011 OpenWrt.org +# Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org> +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +LZMA_TEXT_START := 0x80a00000 +LOADER := loader.bin +LOADER_NAME := $(basename $(notdir $(LOADER))) +LOADER_DATA := +TARGET_DIR := +FLASH_OFFS := +FLASH_MAX := +BOARD := + +ifeq ($(TARGET_DIR),) +TARGET_DIR := $(KDIR) +endif + +LOADER_BIN := $(TARGET_DIR)/$(LOADER_NAME).bin +LOADER_GZ := $(TARGET_DIR)/$(LOADER_NAME).gz +LOADER_ELF := $(TARGET_DIR)/$(LOADER_NAME).elf + +PKG_NAME := lzma-loader +PKG_BUILD_DIR := $(KDIR)/$(PKG_NAME) + +.PHONY : loader-compile loader.bin loader.elf loader.gz + +$(PKG_BUILD_DIR)/.prepared: + mkdir $(PKG_BUILD_DIR) + $(CP) ./src/* $(PKG_BUILD_DIR)/ + touch $@ + +loader-compile: $(PKG_BUILD_DIR)/.prepared + $(MAKE) -C $(PKG_BUILD_DIR) CROSS_COMPILE="$(TARGET_CROSS)" \ + LZMA_TEXT_START=$(LZMA_TEXT_START) \ + LOADER_DATA=$(LOADER_DATA) \ + FLASH_OFFS=$(FLASH_OFFS) \ + FLASH_MAX=$(FLASH_MAX) \ + BOARD="$(BOARD)" \ + clean all + + +loader.gz: $(PKG_BUILD_DIR)/loader.bin + gzip -nc9 $< > $(LOADER_GZ) + +loader.elf: $(PKG_BUILD_DIR)/loader.elf + $(CP) $< $(LOADER_ELF) + +loader.bin: $(PKG_BUILD_DIR)/loader.bin + $(CP) $< $(LOADER_BIN) + +download: +prepare: $(PKG_BUILD_DIR)/.prepared +compile: loader-compile + +install: + +clean: + rm -rf $(PKG_BUILD_DIR) + diff --git a/target/linux/realtek/files/rtkload/LzmaDecode.c b/target/linux/realtek/image/lzma-loader/src/LzmaDecode.c index 5c9d67f71..cb8345377 100644 --- a/target/linux/realtek/files/rtkload/LzmaDecode.c +++ b/target/linux/realtek/image/lzma-loader/src/LzmaDecode.c @@ -1,588 +1,584 @@ -/*
- LzmaDecode.c
- LZMA Decoder (optimized for Speed version)
-
- LZMA SDK 4.22 Copyright (c) 1999-2005 Igor Pavlov (2005-06-10)
- 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
-
-#define RC_READ_BYTE (*Buffer++)
-
-#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \
- { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}
-
-#ifdef _LZMA_IN_CB
-
-#define RC_TEST { if (Buffer == BufferLim) \
- { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \
- BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}
-
-#define RC_INIT Buffer = BufferLim = 0; RC_INIT2
-
-#else
-
-#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }
-
-#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2
-
-#endif
-
-#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
-
-#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
-#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
-#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
-
-#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \
- { UpdateBit0(p); mi <<= 1; A0; } else \
- { UpdateBit1(p); mi = (mi + mi) + 1; A1; }
-
-#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)
-
-#define RangeDecoderBitTreeDecode(probs, numLevels, res) \
- { int i = numLevels; res = 1; \
- do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \
- res -= (1 << numLevels); }
-
-
-#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)
-
-
-#define kNumStates 12
-#define kNumLitStates 7
-
-#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
-
-int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size)
-{
- unsigned char prop0;
- if (size < LZMA_PROPERTIES_SIZE)
- return LZMA_RESULT_DATA_ERROR;
- prop0 = propsData[0];
- if (prop0 >= (9 * 5 * 5))
- return LZMA_RESULT_DATA_ERROR;
- {
- for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5));
- for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9);
- propsRes->lc = prop0;
- /*
- unsigned char remainder = (unsigned char)(prop0 / 9);
- propsRes->lc = prop0 % 9;
- propsRes->pb = remainder / 5;
- propsRes->lp = remainder % 5;
- */
- }
-
- #ifdef _LZMA_OUT_READ
- {
- int i;
- propsRes->DictionarySize = 0;
- for (i = 0; i < 4; i++)
- propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8);
- if (propsRes->DictionarySize == 0)
- propsRes->DictionarySize = 1;
- }
- #endif
- return LZMA_RESULT_OK;
-}
-
-#define kLzmaStreamWasFinishedId (-1)
-
-int LzmaDecode(CLzmaDecoderState *vs,
- #ifdef _LZMA_IN_CB
- ILzmaInCallback *InCallback,
- #else
- const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
- #endif
- unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed)
-{
- CProb *p = vs->Probs;
- SizeT nowPos = 0;
- Byte previousByte = 0;
- UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1;
- UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1;
- int lc = vs->Properties.lc;
-
- #ifdef _LZMA_OUT_READ
-
- UInt32 Range = vs->Range;
- UInt32 Code = vs->Code;
- #ifdef _LZMA_IN_CB
- const Byte *Buffer = vs->Buffer;
- const Byte *BufferLim = vs->BufferLim;
- #else
- const Byte *Buffer = inStream;
- const Byte *BufferLim = inStream + inSize;
- #endif
- int state = vs->State;
- UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
- int len = vs->RemainLen;
- UInt32 globalPos = vs->GlobalPos;
- UInt32 distanceLimit = vs->DistanceLimit;
-
- Byte *dictionary = vs->Dictionary;
- UInt32 dictionarySize = vs->Properties.DictionarySize;
- UInt32 dictionaryPos = vs->DictionaryPos;
-
- Byte tempDictionary[4];
-
- #ifndef _LZMA_IN_CB
- *inSizeProcessed = 0;
- #endif
- *outSizeProcessed = 0;
- if (len == kLzmaStreamWasFinishedId)
- return LZMA_RESULT_OK;
-
- if (dictionarySize == 0)
- {
- dictionary = tempDictionary;
- dictionarySize = 1;
- tempDictionary[0] = vs->TempDictionary[0];
- }
-
- if (len == kLzmaNeedInitId)
- {
- {
- UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
- UInt32 i;
- for (i = 0; i < numProbs; i++)
- p[i] = kBitModelTotal >> 1;
- rep0 = rep1 = rep2 = rep3 = 1;
- state = 0;
- globalPos = 0;
- distanceLimit = 0;
- dictionaryPos = 0;
- dictionary[dictionarySize - 1] = 0;
- #ifdef _LZMA_IN_CB
- RC_INIT;
- #else
- RC_INIT(inStream, inSize);
- #endif
- }
- len = 0;
- }
- 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 /* if !_LZMA_OUT_READ */
-
- int state = 0;
- UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
- int len = 0;
- const Byte *Buffer;
- const Byte *BufferLim;
- UInt32 Range;
- UInt32 Code;
-
- #ifndef _LZMA_IN_CB
- *inSizeProcessed = 0;
- #endif
- *outSizeProcessed = 0;
-
- {
- UInt32 i;
- UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp));
- for (i = 0; i < numProbs; i++)
- p[i] = kBitModelTotal >> 1;
- }
-
- #ifdef _LZMA_IN_CB
- RC_INIT;
- #else
- RC_INIT(inStream, inSize);
- #endif
-
- #endif /* _LZMA_OUT_READ */
-
- while(nowPos < outSize)
- {
- CProb *prob;
- UInt32 bound;
- int posState = (int)(
- (nowPos
- #ifdef _LZMA_OUT_READ
- + globalPos
- #endif
- )
- & posStateMask);
-
- prob = p + IsMatch + (state << kNumPosBitsMax) + posState;
- IfBit0(prob)
- {
- int symbol = 1;
- UpdateBit0(prob)
- prob = p + Literal + (LZMA_LIT_SIZE *
- (((
- (nowPos
- #ifdef _LZMA_OUT_READ
- + globalPos
- #endif
- )
- & literalPosMask) << lc) + (previousByte >> (8 - lc))));
-
- if (state >= kNumLitStates)
- {
- int matchByte;
- #ifdef _LZMA_OUT_READ
- UInt32 pos = dictionaryPos - rep0;
- if (pos >= dictionarySize)
- pos += dictionarySize;
- matchByte = dictionary[pos];
- #else
- matchByte = outStream[nowPos - rep0];
- #endif
- do
- {
- int bit;
- CProb *probLit;
- matchByte <<= 1;
- bit = (matchByte & 0x100);
- probLit = prob + 0x100 + bit + symbol;
- RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)
- }
- while (symbol < 0x100);
- }
- while (symbol < 0x100)
- {
- CProb *probLit = prob + symbol;
- RC_GET_BIT(probLit, symbol)
- }
- previousByte = (Byte)symbol;
-
- outStream[nowPos++] = previousByte;
- #ifdef _LZMA_OUT_READ
- if (distanceLimit < dictionarySize)
- distanceLimit++;
-
- dictionary[dictionaryPos] = previousByte;
- if (++dictionaryPos == dictionarySize)
- dictionaryPos = 0;
- #endif
- if (state < 4) state = 0;
- else if (state < 10) state -= 3;
- else state -= 6;
- }
- else
- {
- UpdateBit1(prob);
- prob = p + IsRep + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- rep3 = rep2;
- rep2 = rep1;
- rep1 = rep0;
- state = state < kNumLitStates ? 0 : 3;
- prob = p + LenCoder;
- }
- else
- {
- UpdateBit1(prob);
- prob = p + IsRepG0 + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;
- IfBit0(prob)
- {
- #ifdef _LZMA_OUT_READ
- UInt32 pos;
- #endif
- UpdateBit0(prob);
-
- #ifdef _LZMA_OUT_READ
- if (distanceLimit == 0)
- #else
- if (nowPos == 0)
- #endif
- return LZMA_RESULT_DATA_ERROR;
-
- state = state < kNumLitStates ? 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;
- #ifdef _LZMA_OUT_READ
- if (distanceLimit < dictionarySize)
- distanceLimit++;
- #endif
-
- continue;
- }
- else
- {
- UpdateBit1(prob);
- }
- }
- else
- {
- UInt32 distance;
- UpdateBit1(prob);
- prob = p + IsRepG1 + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- distance = rep1;
- }
- else
- {
- UpdateBit1(prob);
- prob = p + IsRepG2 + state;
- IfBit0(prob)
- {
- UpdateBit0(prob);
- distance = rep2;
- }
- else
- {
- UpdateBit1(prob);
- distance = rep3;
- rep3 = rep2;
- }
- rep2 = rep1;
- }
- rep1 = rep0;
- rep0 = distance;
- }
- state = state < kNumLitStates ? 8 : 11;
- prob = p + RepLenCoder;
- }
- {
- int numBits, offset;
- CProb *probLen = prob + LenChoice;
- IfBit0(probLen)
- {
- UpdateBit0(probLen);
- probLen = prob + LenLow + (posState << kLenNumLowBits);
- offset = 0;
- numBits = kLenNumLowBits;
- }
- else
- {
- UpdateBit1(probLen);
- probLen = prob + LenChoice2;
- IfBit0(probLen)
- {
- UpdateBit0(probLen);
- probLen = prob + LenMid + (posState << kLenNumMidBits);
- offset = kLenNumLowSymbols;
- numBits = kLenNumMidBits;
- }
- else
- {
- UpdateBit1(probLen);
- probLen = prob + LenHigh;
- offset = kLenNumLowSymbols + kLenNumMidSymbols;
- numBits = kLenNumHighBits;
- }
- }
- RangeDecoderBitTreeDecode(probLen, numBits, len);
- len += offset;
- }
-
- if (state < 4)
- {
- int posSlot;
- state += kNumLitStates;
- prob = p + PosSlot +
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
- kNumPosSlotBits);
- RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);
- if (posSlot >= kStartPosModelIndex)
- {
- int numDirectBits = ((posSlot >> 1) - 1);
- rep0 = (2 | ((UInt32)posSlot & 1));
- if (posSlot < kEndPosModelIndex)
- {
- rep0 <<= numDirectBits;
- prob = p + SpecPos + rep0 - posSlot - 1;
- }
- else
- {
- numDirectBits -= kNumAlignBits;
- do
- {
- RC_NORMALIZE
- Range >>= 1;
- rep0 <<= 1;
- if (Code >= Range)
- {
- Code -= Range;
- rep0 |= 1;
- }
- }
- while (--numDirectBits != 0);
- prob = p + Align;
- rep0 <<= kNumAlignBits;
- numDirectBits = kNumAlignBits;
- }
- {
- int i = 1;
- int mi = 1;
- do
- {
- CProb *prob3 = prob + mi;
- RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
- i <<= 1;
- }
- while(--numDirectBits != 0);
- }
- }
- else
- rep0 = posSlot;
- if (++rep0 == (UInt32)(0))
- {
- /* it's for stream version */
- len = kLzmaStreamWasFinishedId;
- break;
- }
- }
-
- len += kMatchMinLen;
- #ifdef _LZMA_OUT_READ
- if (rep0 > distanceLimit)
- #else
- if (rep0 > nowPos)
- #endif
- return LZMA_RESULT_DATA_ERROR;
-
- #ifdef _LZMA_OUT_READ
- if (dictionarySize - distanceLimit > (UInt32)len)
- distanceLimit += len;
- else
- distanceLimit = dictionarySize;
- #endif
-
- 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
- len--;
- outStream[nowPos++] = previousByte;
- }
- while(len != 0 && nowPos < outSize);
- }
- }
- RC_NORMALIZE;
-
- #ifdef _LZMA_OUT_READ
- vs->Range = Range;
- vs->Code = Code;
- vs->DictionaryPos = dictionaryPos;
- vs->GlobalPos = globalPos + (UInt32)nowPos;
- vs->DistanceLimit = distanceLimit;
- vs->Reps[0] = rep0;
- vs->Reps[1] = rep1;
- vs->Reps[2] = rep2;
- vs->Reps[3] = rep3;
- vs->State = state;
- vs->RemainLen = len;
- vs->TempDictionary[0] = tempDictionary[0];
- #endif
-
- #ifdef _LZMA_IN_CB
- vs->Buffer = Buffer;
- vs->BufferLim = BufferLim;
- #else
- *inSizeProcessed = (SizeT)(Buffer - inStream);
- #endif
- *outSizeProcessed = nowPos;
- return LZMA_RESULT_OK;
-}
+/* + LzmaDecode.c + LZMA Decoder (optimized for Speed version) + + LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01) + 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" + +#define kNumTopBits 24 +#define kTopValue ((UInt32)1 << kNumTopBits) + +#define kNumBitModelTotalBits 11 +#define kBitModelTotal (1 << kNumBitModelTotalBits) +#define kNumMoveBits 5 + +#define RC_READ_BYTE (*Buffer++) + +#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \ + { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }} + +#ifdef _LZMA_IN_CB + +#define RC_TEST { if (Buffer == BufferLim) \ + { SizeT size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \ + BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }} + +#define RC_INIT Buffer = BufferLim = 0; RC_INIT2 + +#else + +#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; } + +#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2 + +#endif + +#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; } + +#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound) +#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits; +#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits; + +#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \ + { UpdateBit0(p); mi <<= 1; A0; } else \ + { UpdateBit1(p); mi = (mi + mi) + 1; A1; } + +#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;) + +#define RangeDecoderBitTreeDecode(probs, numLevels, res) \ + { int i = numLevels; res = 1; \ + do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \ + res -= (1 << numLevels); } + + +#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) + + +#define kNumStates 12 +#define kNumLitStates 7 + +#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 + +int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size) +{ + unsigned char prop0; + if (size < LZMA_PROPERTIES_SIZE) + return LZMA_RESULT_DATA_ERROR; + prop0 = propsData[0]; + if (prop0 >= (9 * 5 * 5)) + return LZMA_RESULT_DATA_ERROR; + { + for (propsRes->pb = 0; prop0 >= (9 * 5); propsRes->pb++, prop0 -= (9 * 5)); + for (propsRes->lp = 0; prop0 >= 9; propsRes->lp++, prop0 -= 9); + propsRes->lc = prop0; + /* + unsigned char remainder = (unsigned char)(prop0 / 9); + propsRes->lc = prop0 % 9; + propsRes->pb = remainder / 5; + propsRes->lp = remainder % 5; + */ + } + + #ifdef _LZMA_OUT_READ + { + int i; + propsRes->DictionarySize = 0; + for (i = 0; i < 4; i++) + propsRes->DictionarySize += (UInt32)(propsData[1 + i]) << (i * 8); + if (propsRes->DictionarySize == 0) + propsRes->DictionarySize = 1; + } + #endif + return LZMA_RESULT_OK; +} + +#define kLzmaStreamWasFinishedId (-1) + +int LzmaDecode(CLzmaDecoderState *vs, + #ifdef _LZMA_IN_CB + ILzmaInCallback *InCallback, + #else + const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed, + #endif + unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed) +{ + CProb *p = vs->Probs; + SizeT nowPos = 0; + Byte previousByte = 0; + UInt32 posStateMask = (1 << (vs->Properties.pb)) - 1; + UInt32 literalPosMask = (1 << (vs->Properties.lp)) - 1; + int lc = vs->Properties.lc; + + #ifdef _LZMA_OUT_READ + + UInt32 Range = vs->Range; + UInt32 Code = vs->Code; + #ifdef _LZMA_IN_CB + const Byte *Buffer = vs->Buffer; + const Byte *BufferLim = vs->BufferLim; + #else + const Byte *Buffer = inStream; + const Byte *BufferLim = inStream + inSize; + #endif + int state = vs->State; + UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3]; + int len = vs->RemainLen; + UInt32 globalPos = vs->GlobalPos; + UInt32 distanceLimit = vs->DistanceLimit; + + Byte *dictionary = vs->Dictionary; + UInt32 dictionarySize = vs->Properties.DictionarySize; + UInt32 dictionaryPos = vs->DictionaryPos; + + Byte tempDictionary[4]; + + #ifndef _LZMA_IN_CB + *inSizeProcessed = 0; + #endif + *outSizeProcessed = 0; + if (len == kLzmaStreamWasFinishedId) + return LZMA_RESULT_OK; + + if (dictionarySize == 0) + { + dictionary = tempDictionary; + dictionarySize = 1; + tempDictionary[0] = vs->TempDictionary[0]; + } + + if (len == kLzmaNeedInitId) + { + { + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp)); + UInt32 i; + for (i = 0; i < numProbs; i++) + p[i] = kBitModelTotal >> 1; + rep0 = rep1 = rep2 = rep3 = 1; + state = 0; + globalPos = 0; + distanceLimit = 0; + dictionaryPos = 0; + dictionary[dictionarySize - 1] = 0; + #ifdef _LZMA_IN_CB + RC_INIT; + #else + RC_INIT(inStream, inSize); + #endif + } + len = 0; + } + 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 /* if !_LZMA_OUT_READ */ + + int state = 0; + UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; + int len = 0; + const Byte *Buffer; + const Byte *BufferLim; + UInt32 Range; + UInt32 Code; + + #ifndef _LZMA_IN_CB + *inSizeProcessed = 0; + #endif + *outSizeProcessed = 0; + + { + UInt32 i; + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + vs->Properties.lp)); + for (i = 0; i < numProbs; i++) + p[i] = kBitModelTotal >> 1; + } + + #ifdef _LZMA_IN_CB + RC_INIT; + #else + RC_INIT(inStream, inSize); + #endif + + #endif /* _LZMA_OUT_READ */ + + while(nowPos < outSize) + { + CProb *prob; + UInt32 bound; + int posState = (int)( + (nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + & posStateMask); + + prob = p + IsMatch + (state << kNumPosBitsMax) + posState; + IfBit0(prob) + { + int symbol = 1; + UpdateBit0(prob) + prob = p + Literal + (LZMA_LIT_SIZE * + ((( + (nowPos + #ifdef _LZMA_OUT_READ + + globalPos + #endif + ) + & literalPosMask) << lc) + (previousByte >> (8 - lc)))); + + if (state >= kNumLitStates) + { + int matchByte; + #ifdef _LZMA_OUT_READ + UInt32 pos = dictionaryPos - rep0; + if (pos >= dictionarySize) + pos += dictionarySize; + matchByte = dictionary[pos]; + #else + matchByte = outStream[nowPos - rep0]; + #endif + do + { + int bit; + CProb *probLit; + matchByte <<= 1; + bit = (matchByte & 0x100); + probLit = prob + 0x100 + bit + symbol; + RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break) + } + while (symbol < 0x100); + } + while (symbol < 0x100) + { + CProb *probLit = prob + symbol; + RC_GET_BIT(probLit, symbol) + } + previousByte = (Byte)symbol; + + outStream[nowPos++] = previousByte; + #ifdef _LZMA_OUT_READ + if (distanceLimit < dictionarySize) + distanceLimit++; + + dictionary[dictionaryPos] = previousByte; + if (++dictionaryPos == dictionarySize) + dictionaryPos = 0; + #endif + if (state < 4) state = 0; + else if (state < 10) state -= 3; + else state -= 6; + } + else + { + UpdateBit1(prob); + prob = p + IsRep + state; + IfBit0(prob) + { + UpdateBit0(prob); + rep3 = rep2; + rep2 = rep1; + rep1 = rep0; + state = state < kNumLitStates ? 0 : 3; + prob = p + LenCoder; + } + else + { + UpdateBit1(prob); + prob = p + IsRepG0 + state; + IfBit0(prob) + { + UpdateBit0(prob); + prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState; + IfBit0(prob) + { + #ifdef _LZMA_OUT_READ + UInt32 pos; + #endif + UpdateBit0(prob); + + #ifdef _LZMA_OUT_READ + if (distanceLimit == 0) + #else + if (nowPos == 0) + #endif + return LZMA_RESULT_DATA_ERROR; + + state = state < kNumLitStates ? 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; + #ifdef _LZMA_OUT_READ + if (distanceLimit < dictionarySize) + distanceLimit++; + #endif + + continue; + } + else + { + UpdateBit1(prob); + } + } + else + { + UInt32 distance; + UpdateBit1(prob); + prob = p + IsRepG1 + state; + IfBit0(prob) + { + UpdateBit0(prob); + distance = rep1; + } + else + { + UpdateBit1(prob); + prob = p + IsRepG2 + state; + IfBit0(prob) + { + UpdateBit0(prob); + distance = rep2; + } + else + { + UpdateBit1(prob); + distance = rep3; + rep3 = rep2; + } + rep2 = rep1; + } + rep1 = rep0; + rep0 = distance; + } + state = state < kNumLitStates ? 8 : 11; + prob = p + RepLenCoder; + } + { + int numBits, offset; + CProb *probLen = prob + LenChoice; + IfBit0(probLen) + { + UpdateBit0(probLen); + probLen = prob + LenLow + (posState << kLenNumLowBits); + offset = 0; + numBits = kLenNumLowBits; + } + else + { + UpdateBit1(probLen); + probLen = prob + LenChoice2; + IfBit0(probLen) + { + UpdateBit0(probLen); + probLen = prob + LenMid + (posState << kLenNumMidBits); + offset = kLenNumLowSymbols; + numBits = kLenNumMidBits; + } + else + { + UpdateBit1(probLen); + probLen = prob + LenHigh; + offset = kLenNumLowSymbols + kLenNumMidSymbols; + numBits = kLenNumHighBits; + } + } + RangeDecoderBitTreeDecode(probLen, numBits, len); + len += offset; + } + + if (state < 4) + { + int posSlot; + state += kNumLitStates; + prob = p + PosSlot + + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << + kNumPosSlotBits); + RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot); + if (posSlot >= kStartPosModelIndex) + { + int numDirectBits = ((posSlot >> 1) - 1); + rep0 = (2 | ((UInt32)posSlot & 1)); + if (posSlot < kEndPosModelIndex) + { + rep0 <<= numDirectBits; + prob = p + SpecPos + rep0 - posSlot - 1; + } + else + { + numDirectBits -= kNumAlignBits; + do + { + RC_NORMALIZE + Range >>= 1; + rep0 <<= 1; + if (Code >= Range) + { + Code -= Range; + rep0 |= 1; + } + } + while (--numDirectBits != 0); + prob = p + Align; + rep0 <<= kNumAlignBits; + numDirectBits = kNumAlignBits; + } + { + int i = 1; + int mi = 1; + do + { + CProb *prob3 = prob + mi; + RC_GET_BIT2(prob3, mi, ; , rep0 |= i); + i <<= 1; + } + while(--numDirectBits != 0); + } + } + else + rep0 = posSlot; + if (++rep0 == (UInt32)(0)) + { + /* it's for stream version */ + len = kLzmaStreamWasFinishedId; + break; + } + } + + len += kMatchMinLen; + #ifdef _LZMA_OUT_READ + if (rep0 > distanceLimit) + #else + if (rep0 > nowPos) + #endif + return LZMA_RESULT_DATA_ERROR; + + #ifdef _LZMA_OUT_READ + if (dictionarySize - distanceLimit > (UInt32)len) + distanceLimit += len; + else + distanceLimit = dictionarySize; + #endif + + 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 + len--; + outStream[nowPos++] = previousByte; + } + while(len != 0 && nowPos < outSize); + } + } + RC_NORMALIZE; + + #ifdef _LZMA_OUT_READ + vs->Range = Range; + vs->Code = Code; + vs->DictionaryPos = dictionaryPos; + vs->GlobalPos = globalPos + (UInt32)nowPos; + vs->DistanceLimit = distanceLimit; + vs->Reps[0] = rep0; + vs->Reps[1] = rep1; + vs->Reps[2] = rep2; + vs->Reps[3] = rep3; + vs->State = state; + vs->RemainLen = len; + vs->TempDictionary[0] = tempDictionary[0]; + #endif + + #ifdef _LZMA_IN_CB + vs->Buffer = Buffer; + vs->BufferLim = BufferLim; + #else + *inSizeProcessed = (SizeT)(Buffer - inStream); + #endif + *outSizeProcessed = nowPos; + return LZMA_RESULT_OK; +} diff --git a/target/linux/realtek/files/rtkload/LzmaDecode.h b/target/linux/realtek/image/lzma-loader/src/LzmaDecode.h index 35e37ed0d..2870eeb9c 100644 --- a/target/linux/realtek/files/rtkload/LzmaDecode.h +++ b/target/linux/realtek/image/lzma-loader/src/LzmaDecode.h @@ -1,131 +1,113 @@ -/*
- LzmaDecode.h
- LZMA Decoder interface
-
- LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)
- 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 */
-
-/* #define _LZMA_SYSTEM_SIZE_T */
-/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/
-
-#ifndef UInt32
-#ifdef _LZMA_UINT32_IS_ULONG
-#define UInt32 unsigned long
-#else
-#define UInt32 unsigned int
-#endif
-#endif
-
-#ifndef SizeT
-#ifdef _LZMA_SYSTEM_SIZE_T
-#include <stddef.h>
-#define SizeT size_t
-#else
-#define SizeT UInt32
-#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
-
-#ifdef _LZMA_IN_CB
-typedef struct _ILzmaInCallback
-{
- int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);
-} ILzmaInCallback;
-#endif
-
-#define LZMA_BASE_SIZE 1846
-#define LZMA_LIT_SIZE 768
-
-#define LZMA_PROPERTIES_SIZE 5
-
-typedef struct _CLzmaProperties
-{
- int lc;
- int lp;
- int pb;
- #ifdef _LZMA_OUT_READ
- UInt32 DictionarySize;
- #endif
-}CLzmaProperties;
-
-int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
-
-#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
-
-#define kLzmaNeedInitId (-2)
-
-typedef struct _CLzmaDecoderState
-{
- CLzmaProperties Properties;
- CProb *Probs;
-
- #ifdef _LZMA_IN_CB
- const unsigned char *Buffer;
- const unsigned char *BufferLim;
- #endif
-
- #ifdef _LZMA_OUT_READ
- unsigned char *Dictionary;
- UInt32 Range;
- UInt32 Code;
- UInt32 DictionaryPos;
- UInt32 GlobalPos;
- UInt32 DistanceLimit;
- UInt32 Reps[4];
- int State;
- int RemainLen;
- unsigned char TempDictionary[4];
- #endif
-} CLzmaDecoderState;
-
-#ifdef _LZMA_OUT_READ
-#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }
-#endif
-
-int LzmaDecode(CLzmaDecoderState *vs,
- #ifdef _LZMA_IN_CB
- ILzmaInCallback *inCallback,
- #else
- const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
- #endif
- unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);
-
-#endif
+/* + LzmaDecode.h + LZMA Decoder interface + + LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01) + 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 + +#include "LzmaTypes.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 */ + +#ifdef _LZMA_PROB32 +#define CProb UInt32 +#else +#define CProb UInt16 +#endif + +#define LZMA_RESULT_OK 0 +#define LZMA_RESULT_DATA_ERROR 1 + +#ifdef _LZMA_IN_CB +typedef struct _ILzmaInCallback +{ + int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize); +} ILzmaInCallback; +#endif + +#define LZMA_BASE_SIZE 1846 +#define LZMA_LIT_SIZE 768 + +#define LZMA_PROPERTIES_SIZE 5 + +typedef struct _CLzmaProperties +{ + int lc; + int lp; + int pb; + #ifdef _LZMA_OUT_READ + UInt32 DictionarySize; + #endif +}CLzmaProperties; + +int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size); + +#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp))) + +#define kLzmaNeedInitId (-2) + +typedef struct _CLzmaDecoderState +{ + CLzmaProperties Properties; + CProb *Probs; + + #ifdef _LZMA_IN_CB + const unsigned char *Buffer; + const unsigned char *BufferLim; + #endif + + #ifdef _LZMA_OUT_READ + unsigned char *Dictionary; + UInt32 Range; + UInt32 Code; + UInt32 DictionaryPos; + UInt32 GlobalPos; + UInt32 DistanceLimit; + UInt32 Reps[4]; + int State; + int RemainLen; + unsigned char TempDictionary[4]; + #endif +} CLzmaDecoderState; + +#ifdef _LZMA_OUT_READ +#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; } +#endif + +int LzmaDecode(CLzmaDecoderState *vs, + #ifdef _LZMA_IN_CB + ILzmaInCallback *inCallback, + #else + const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed, + #endif + unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed); + +#endif diff --git a/target/linux/realtek/image/lzma-loader/src/LzmaTypes.h b/target/linux/realtek/image/lzma-loader/src/LzmaTypes.h new file mode 100644 index 000000000..8f13553a3 --- /dev/null +++ b/target/linux/realtek/image/lzma-loader/src/LzmaTypes.h @@ -0,0 +1,45 @@ +/* +LzmaTypes.h + +Types for LZMA Decoder + +This file written and distributed to public domain by Igor Pavlov. +This file is part of LZMA SDK 4.40 (2006-05-01) +*/ + +#ifndef __LZMATYPES_H +#define __LZMATYPES_H + +#ifndef _7ZIP_BYTE_DEFINED +#define _7ZIP_BYTE_DEFINED +typedef unsigned char Byte; +#endif + +#ifndef _7ZIP_UINT16_DEFINED +#define _7ZIP_UINT16_DEFINED +typedef unsigned short UInt16; +#endif + +#ifndef _7ZIP_UINT32_DEFINED +#define _7ZIP_UINT32_DEFINED +#ifdef _LZMA_UINT32_IS_ULONG +typedef unsigned long UInt32; +#else +typedef unsigned int UInt32; +#endif +#endif + +#define _LZMA_NO_SYSTEM_SIZE_T +/* You can use it, if you don't want <stddef.h> */ + +#ifndef _7ZIP_SIZET_DEFINED +#define _7ZIP_SIZET_DEFINED +#ifdef _LZMA_NO_SYSTEM_SIZE_T +typedef UInt32 SizeT; +#else +#include <stddef.h> +typedef size_t SizeT; +#endif +#endif + +#endif diff --git a/target/linux/realtek/image/lzma-loader/src/Makefile b/target/linux/realtek/image/lzma-loader/src/Makefile new file mode 100644 index 000000000..3355d7b20 --- /dev/null +++ b/target/linux/realtek/image/lzma-loader/src/Makefile @@ -0,0 +1,117 @@ +# +# Makefile for the LZMA compressed kernel loader for +# Realtek rtl819xx based boards +# +# Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org> +# Copyright (C) 2013 Roman Yeryomin <roman@advem.lv> +# +# Some parts of this file was based on the OpenWrt specific lzma-loader +# for the BCM47xx and ADM5120 based boards: +# Copyright (C) 2004 Manuel Novoa III (mjn3@codepoet.org) +# Copyright (C) 2005 Mineharu Takahara <mtakahar@yahoo.com> +# Copyright (C) 2005 by Oleg I. Vdovikin <oleg@cs.msu.su> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 as published +# by the Free Software Foundation. +# + +LOADADDR := +KERNELENTRY := +LZMA_TEXT_START := 0x80a00000 +LOADER_DATA := +BOARD := +FLASH_OFFS := +FLASH_MAX := + +CC := $(CROSS_COMPILE)gcc +LD := $(CROSS_COMPILE)ld +OBJCOPY := $(CROSS_COMPILE)objcopy +OBJDUMP := $(CROSS_COMPILE)objdump + +BIN_FLAGS := -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 -ffreestanding -fhonour-copts -mabi=32 -Wa,-32 +CFLAGS += -D_LZMA_PROB32 +CFLAGS += -I$(LINUX_DIR)/arch/rlx/include +CFLAGS += -I$(LINUX_DIR)/include/linux +CFLAGS += -I$(LINUX_DIR)/arch/rlx/bsp +CFLAGS += -I$(LINUX_DIR)/include +CFLAGS += -I$(LINUX_DIR)/arch/rlx/include/asm/mach-generic + +ASFLAGS = $(CFLAGS) -D__ASSEMBLY__ + +LDFLAGS = -static --gc-sections -no-warn-mismatch +LDFLAGS += -e startup -T loader.lds -Ttext $(LZMA_TEXT_START) + +O_FORMAT = $(shell $(OBJDUMP) -i | head -2 | grep elf32) + +OBJECTS := head.o loader.o cache.o board.o printf.o LzmaDecode.o + +# Realtek chips have different march'es, e.g. rlx4181 and rlx5281 +ifneq ($(strip $(MARCH)),) +CFLAGS += -Wa,-march=$(MARCH) -march=$(MARCH) +else +CFLAGS += -Wa,-march=rlx4181 -march=rlx4181 +endif + +# hacky way to get/define real kernel_entry address +# see image/Makefile and loader.c for details +ifneq ($(strip $(KERNELENTRY)),) +CFLAGS += -DKERNELENTRY=$(KERNELENTRY) +endif + +ifneq ($(strip $(LOADER_DATA)),) +OBJECTS += data.o +CFLAGS += -DLZMA_WRAPPER=1 -DLOADADDR=$(LOADADDR) +endif + +ifneq ($(strip $(KERNEL_CMDLINE)),) +CFLAGS += -DCONFIG_KERNEL_CMDLINE='"$(KERNEL_CMDLINE)"' +endif + +ifneq ($(strip $(FLASH_OFFS)),) +CFLAGS += -DCONFIG_FLASH_OFFS=$(FLASH_OFFS) +endif + +ifneq ($(strip $(FLASH_MAX)),) +CFLAGS += -DCONFIG_FLASH_MAX=$(FLASH_MAX) +endif + +BOARD_DEF := $(shell echo $(strip $(BOARD)) | tr a-z A-Z | tr - _) +ifneq ($(BOARD_DEF),) +CFLAGS += -DCONFIG_BOARD_$(BOARD_DEF) +endif + +all: loader.bin + +# Don't build dependencies, this may die if $(CC) isn't gcc +dep: + +install: + +%.o : %.c + $(CC) $(CFLAGS) -c -o $@ $< + +%.o : %.S + $(CC) $(ASFLAGS) -c -o $@ $< + +data.o: $(LOADER_DATA) + $(LD) -r -b binary --oformat $(O_FORMAT) -T lzma-data.lds -o $@ $< + +loader.bin: loader.elf + $(OBJCOPY) $(BIN_FLAGS) $< $@ + +loader.elf: $(OBJECTS) + $(LD) $(LDFLAGS) -o $@ $(OBJECTS) + +mrproper: clean + +clean: + rm -f *.elf *.bin *.o + + + diff --git a/target/linux/realtek/image/lzma-loader/src/board.c b/target/linux/realtek/image/lzma-loader/src/board.c new file mode 100644 index 000000000..0533abace --- /dev/null +++ b/target/linux/realtek/image/lzma-loader/src/board.c @@ -0,0 +1,45 @@ +/* + * LZMA compressed kernel loader for Realtek 819X + * + * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + */ + +#include <stddef.h> + + +#define UART_THR 0xb8002000 +#define UART_LSR 0xb8002014 + +#define REG32(reg) (*(volatile unsigned int *)((unsigned int)reg)) + + +void serial_outc(char c) +{ + int i=0; + + while (1) + { + i++; + if (i >=0x6000) + break; + + if (REG32(UART_LSR) & 0x20000000) + break; + } + REG32(UART_THR) = (c << 24); +} + + +void board_putc(int ch) +{ + serial_outc(ch); +} + +void board_init(void) +{ + +} diff --git a/target/linux/realtek/image/lzma-loader/src/cache.c b/target/linux/realtek/image/lzma-loader/src/cache.c new file mode 100644 index 000000000..6ecb07071 --- /dev/null +++ b/target/linux/realtek/image/lzma-loader/src/cache.c @@ -0,0 +1,137 @@ +/* + * LZMA compressed kernel loader for Realtek rtl819xx + * + * Copyright (C) 2013 Roman Yeryomin <roman@advem.lv> + * + * The cache manipulation routines has been taken from + * Realtek SDK (rtlkoad utility). + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + */ +#include <linux/autoconf.h> +#include <linux/linkage.h> +#include <asm/ptrace.h> +#include <asm/rlxregs.h> +#include <asm/addrspace.h> + +/* For Realtek RTL865XC Network platform series */ +#define _ICACHE_SIZE (16 * 1024) /* 16K bytes */ +#define _DCACHE_SIZE (8 * 1024) /* 8K bytes */ +#define _CACHE_LINE_SIZE 4 /* 4 words */ + +void flush_cache(void); +static void flush_icache(unsigned int start, unsigned int end); +static void flush_dcache(unsigned int start, unsigned int end); + +void flush_cache(void) +{ + + flush_dcache(KSEG0, KSEG0+_DCACHE_SIZE); + flush_icache(KSEG0, KSEG0+_ICACHE_SIZE); + +} + +static void flush_icache(unsigned int start, unsigned int end) +{ + /* + * Flush data cache at first in write-back platform. + * + * Ghhuang (2007/3/9): + * RD-Center suggest that we need to flush D-cache entries which + * might match to same address as I-cache when we flush I-cache. + * (Maybe some data is treated as data/instruction, both.) + */ + flush_dcache(start, end); + + /* Invalidate I-Cache */ + __asm__ volatile( + "mtc0 $0,$20\n\t" + "nop\n\t" + "li $8,2\n\t" + "mtc0 $8,$20\n\t" + "nop\n\t" + "nop\n\t" + "mtc0 $0,$20\n\t" + "nop" + : /* no output */ + : /* no input */ + ); + +} + +static void flush_dcache(unsigned int start, unsigned int end) +{ + /* Flush D-Cache using its range */ + unsigned char *p; + unsigned int size; + unsigned int flags; + unsigned int i; + + size = end - start; + + /* correctness check : flush all if any parameter is illegal */ +// david +// if ((size >= dcache_size) || + if ((size >= _DCACHE_SIZE) || (KSEGX(start) != KSEG0)) + { + /* + * ghhguang: + * For Realtek Lexra CPU, + * the cache would NOT be flushed only if the Address to-be-flushed + * is the EXPLICIT address (which is really stored in that cache line). + * For the aliased addresses, the cache entry would NOT be flushed even + * if it matchs same cache-index. + * + * This is different from traditional MIPS-based CPU's configuration. + * So if we want to flush ALL-cache entries, we would need to use "mtc0" + * instruction instead of simply modifying the "size" to "dcache_size" + * and "start" to "KSEG0". + */ + __asm__ volatile( + "mtc0 $0,$20\n\t" + "nop\n\t" + "li $8,512\n\t" + "mtc0 $8,$20\n\t" + "nop\n\t" + "nop\n\t" + "mtc0 $0,$20\n\t" + "nop" + : /* no output */ + : /* no input */ + ); + } + else + { + /* Start to isolate cache space */ + p = (char *)start; + + flags = read_c0_status(); + + /* isolate cache space */ + write_c0_status( (ST0_ISC | flags) &~ ST0_IEC ); + + for (i = 0; i < size; i += 0x040) + { + asm ( + #ifdef OPEN_RSDK_RTL865x + ".word 0xbc750000\n\t" + ".word 0xbc750010\n\t" + ".word 0xbc750020\n\t" + ".word 0xbc750030\n\t" + #endif + "cache 0x15, 0x000(%0)\n\t" + "cache 0x15, 0x010(%0)\n\t" + "cache 0x15, 0x020(%0)\n\t" + "cache 0x15, 0x030(%0)\n\t" + : /* No output registers */ + :"r"(p) /* input : 'p' as %0 */ + ); + p += 0x040; + } + + write_c0_status(flags); + } +} diff --git a/target/linux/realtek/image/lzma-loader/src/head.S b/target/linux/realtek/image/lzma-loader/src/head.S new file mode 100644 index 000000000..ab43f909c --- /dev/null +++ b/target/linux/realtek/image/lzma-loader/src/head.S @@ -0,0 +1,49 @@ +/* + * LZMA compressed kernel loader for Realtek 819X + * + * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org> + * + * Some parts of this code was based on the OpenWrt specific lzma-loader + * for the BCM47xx and ADM5120 based boards: + * Copyright (C) 2004 Manuel Novoa III (mjn3@codepoet.org) + * Copyright (C) 2005 by Oleg I. Vdovikin <oleg@cs.msu.su> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + */ + +#include <asm/asm.h> +#include <asm/regdef.h> + + + .text + +LEAF(startup) + .set noreorder + +__reloc_done: + /* clear bss */ + la t0, _bss_start + la t1, _bss_end + b __bss_check + nop + +__bss_fill: + sw zero, 0(t0) + addi t0, 4 + +__bss_check: + bne t0, t1, __bss_fill + nop + + /* Setup new "C" stack */ + la sp, _stack + + /* jump to the decompressor routine */ + la t0, loader_main + jr t0 + nop + + .set reorder +END(startup) diff --git a/target/linux/realtek/image/lzma-loader/src/loader.c b/target/linux/realtek/image/lzma-loader/src/loader.c new file mode 100644 index 000000000..61bcd1a2b --- /dev/null +++ b/target/linux/realtek/image/lzma-loader/src/loader.c @@ -0,0 +1,266 @@ +/* + * LZMA compressed kernel loader for Realtek rtl819xx based boards + * + * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org> + * Copyright (C) 2013 Roman Yeryomin <roman@advem.lv> + * + * Some parts of this code was based on the OpenWrt specific lzma-loader + * for the BCM47xx and ADM5120 based boards: + * Copyright (C) 2004 Manuel Novoa III (mjn3@codepoet.org) + * Copyright (C) 2005 Mineharu Takahara <mtakahar@yahoo.com> + * Copyright (C) 2005 by Oleg I. Vdovikin <oleg@cs.msu.su> + * + * The image_header structure has been taken from the U-Boot project. + * (C) Copyright 2008 Semihalf + * (C) Copyright 2000-2005 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + */ + +#include <stddef.h> +#include <stdint.h> + +#include "printf.h" +#include "LzmaDecode.h" + +#define KSEG0 0x80000000 +#define KSEG1 0xa0000000 + +#define KSEG1ADDR(a) ((((unsigned)(a)) & 0x1fffffffU) | KSEG1) + +#undef LZMA_DEBUG + +#ifdef LZMA_DEBUG +# define DBG(f, a...) printf(f, ## a) +#else +# define DBG(f, a...) do {} while (0) +#endif + + +#define IH_NMLEN 32 /* Image Name Length */ + +typedef struct image_header { + uint32_t ih_magic; /* Image Header Magic Number */ + uint32_t ih_hcrc; /* Image Header CRC Checksum */ + uint32_t ih_time; /* Image Creation Timestamp */ + uint32_t ih_size; /* Image Data Size */ + uint32_t ih_load; /* Data Load Address */ + uint32_t ih_ep; /* Entry Point Address */ + uint32_t ih_dcrc; /* Image Data CRC Checksum */ + uint8_t ih_os; /* Operating System */ + uint8_t ih_arch; /* CPU architecture */ + uint8_t ih_type; /* Image Type */ + uint8_t ih_comp; /* Compression Type */ + uint8_t ih_name[IH_NMLEN]; /* Image Name */ +} image_header_t; + +/* beyond the image end, size not known in advance */ +extern unsigned char workspace[]; +extern void board_init(void); +void flush_cache(void); + +static CLzmaDecoderState lzma_state; +static unsigned char *lzma_data; +static unsigned long lzma_datasize; +static unsigned long lzma_outsize; +static unsigned long kernel_la; + +#ifdef CONFIG_KERNEL_CMDLINE +#define kernel_argc 1 +static const char kernel_cmdline[] = CONFIG_KERNEL_CMDLINE; +static const char *kernel_argv[] = { + kernel_cmdline, + NULL, +}; +#endif /* CONFIG_KERNEL_CMDLINE */ + +static void halt(void) +{ + printf("\nSystem halted!\n"); + for(;;); +} + +static __inline__ unsigned long get_be32(void *buf) +{ + unsigned char *p = buf; + + return (((unsigned long) p[0] << 24) + + ((unsigned long) p[1] << 16) + + ((unsigned long) p[2] << 8) + + (unsigned long) p[3]); +} + +static __inline__ unsigned char lzma_get_byte(void) +{ + unsigned char c; + + lzma_datasize--; + c = *lzma_data++; + + return c; +} + +static int lzma_init_props(void) +{ + unsigned char props[LZMA_PROPERTIES_SIZE]; + int res; + int i; + + /* read lzma properties */ + for (i = 0; i < LZMA_PROPERTIES_SIZE; i++) + props[i] = lzma_get_byte(); + + /* read the lower half of uncompressed size in the header */ + lzma_outsize = ((SizeT) lzma_get_byte()) + + ((SizeT) lzma_get_byte() << 8) + + ((SizeT) lzma_get_byte() << 16) + + ((SizeT) lzma_get_byte() << 24); + + /* skip rest of the header (upper half of uncompressed size) */ + for (i = 0; i < 4; i++) + lzma_get_byte(); + + res = LzmaDecodeProperties(&lzma_state.Properties, props, + LZMA_PROPERTIES_SIZE); + return res; +} + +static int lzma_decompress(unsigned char *outStream) +{ + SizeT ip, op; + int ret; + + lzma_state.Probs = (CProb *) workspace; + + ret = LzmaDecode(&lzma_state, lzma_data, lzma_datasize, &ip, outStream, + lzma_outsize, &op); + + if (ret != LZMA_RESULT_OK) { + int i; + + DBG("LzmaDecode error %d at %08x, osize:%d ip:%d op:%d\n", + ret, lzma_data + ip, lzma_outsize, ip, op); + + for (i = 0; i < 16; i++) + DBG("%02x ", lzma_data[ip + i]); + + DBG("\n"); + } + + return ret; +} + +#if (LZMA_WRAPPER) +static void lzma_init_data(void) +{ + extern unsigned char _lzma_data_start[]; + extern unsigned char _lzma_data_end[]; + + kernel_la = LOADADDR; + lzma_data = _lzma_data_start; + lzma_datasize = _lzma_data_end - _lzma_data_start; +} +#else +static void lzma_init_data(void) +{ + struct image_header *hdr = NULL; + unsigned char *flash_base; + unsigned long flash_ofs; + unsigned long kernel_ofs; + unsigned long kernel_size; + + flash_base = (unsigned char *) KSEG1ADDR(AR71XX_FLASH_START); + + printf("Looking for OpenWrt image... "); + + for (flash_ofs = CONFIG_FLASH_OFFS; + flash_ofs <= (CONFIG_FLASH_OFFS + CONFIG_FLASH_MAX); + flash_ofs += CONFIG_FLASH_STEP) { + unsigned long magic; + unsigned char *p; + + p = flash_base + flash_ofs; + magic = get_be32(p); + if (magic == IH_MAGIC_OKLI) { + hdr = (struct image_header *) p; + break; + } + } + + if (hdr == NULL) { + printf("not found!\n"); + halt(); + } + + printf("found at 0x%08x\n", flash_base + flash_ofs); + + kernel_ofs = sizeof(struct image_header); + kernel_size = get_be32(&hdr->ih_size); + kernel_la = get_be32(&hdr->ih_load); + + lzma_data = flash_base + flash_ofs + kernel_ofs; + lzma_datasize = kernel_size; +} +#endif /* (LZMA_WRAPPER) */ + +void loader_main(unsigned long reg_a0, unsigned long reg_a1, + unsigned long reg_a2, unsigned long reg_a3) +{ + void (*kernel_entry) (unsigned long, unsigned long, unsigned long, + unsigned long); + int res; + + board_init(); + + printf("\n\nOpenWrt kernel loader for Realtek rtl819xx\n"); + printf("Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>\n"); + printf("Copyright (C) 2013 Roman Yeryomin <roman@advem.lv>\n"); + + lzma_init_data(); + + res = lzma_init_props(); + if (res != LZMA_RESULT_OK) { + printf("Incorrect LZMA stream properties!\n"); + halt(); + } + + printf("Decompressing kernel to %08x... ", kernel_la); + + res = lzma_decompress((unsigned char *) kernel_la); + if (res != LZMA_RESULT_OK) { + printf("failed, "); + switch (res) { + case LZMA_RESULT_DATA_ERROR: + printf("data error!\n"); + break; + default: + printf("unknown error %d!\n", res); + } + halt(); + } else { + printf("done!\n"); + } + + /* flush_cache(kernel_la, lzma_outsize); */ + flush_cache(); + +#ifdef KERNELENTRY + kernel_la = KERNELENTRY; + printf("Seems kernel_entry address is different from load address, so...\n"); +#endif + printf("Starting kernel from %08x...\n\n", kernel_la); + + +#ifdef CONFIG_KERNEL_CMDLINE + reg_a0 = kernel_argc; + reg_a1 = (unsigned long) kernel_argv; + reg_a2 = 0; + reg_a3 = 0; +#endif + + kernel_entry = (void *) kernel_la; + kernel_entry(reg_a0, reg_a1, reg_a2, reg_a3); +} diff --git a/target/linux/realtek/image/lzma-loader/src/loader.lds b/target/linux/realtek/image/lzma-loader/src/loader.lds new file mode 100644 index 000000000..01ff85236 --- /dev/null +++ b/target/linux/realtek/image/lzma-loader/src/loader.lds @@ -0,0 +1,34 @@ +OUTPUT_ARCH(mips) +SECTIONS { + .text : { + _code_start = .; + *(.text) + *(.text.*) + *(.rodata) + *(.rodata.*) + *(.data.lzma) + } + + . = ALIGN(32); + .data : { + *(.data) + *(.data.*) + } + + . = ALIGN(32); + _code_end = .; + + _bss_start = .; + .bss : { + *(.bss) + *(.bss.*) + } + + . = ALIGN(32); + _bss_end = .; + + . = . + 8192; + _stack = .; + + workspace = .; +} diff --git a/target/linux/realtek/image/lzma-loader/src/lzma-data.lds b/target/linux/realtek/image/lzma-loader/src/lzma-data.lds new file mode 100644 index 000000000..abf756ba1 --- /dev/null +++ b/target/linux/realtek/image/lzma-loader/src/lzma-data.lds @@ -0,0 +1,8 @@ +OUTPUT_ARCH(mips) +SECTIONS { + .data.lzma : { + _lzma_data_start = .; + *(.data) + _lzma_data_end = .; + } +} diff --git a/target/linux/realtek/image/lzma-loader/src/printf.c b/target/linux/realtek/image/lzma-loader/src/printf.c new file mode 100644 index 000000000..7bb5a86e1 --- /dev/null +++ b/target/linux/realtek/image/lzma-loader/src/printf.c @@ -0,0 +1,350 @@ +/* + * Copyright (C) 2001 MontaVista Software Inc. + * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net + * + * 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. + * + */ + +#include "printf.h" + +extern void board_putc(int ch); + +/* this is the maximum width for a variable */ +#define LP_MAX_BUF 256 + +/* macros */ +#define IsDigit(x) ( ((x) >= '0') && ((x) <= '9') ) +#define Ctod(x) ( (x) - '0') + +/* forward declaration */ +static int PrintChar(char *, char, int, int); +static int PrintString(char *, char *, int, int); +static int PrintNum(char *, unsigned long, int, int, int, int, char, int); + +/* private variable */ +static const char theFatalMsg[] = "fatal error in lp_Print!"; + +/* -*- + * A low level printf() function. + */ +static void +lp_Print(void (*output)(void *, char *, int), + void * arg, + char *fmt, + va_list ap) +{ + +#define OUTPUT(arg, s, l) \ + { if (((l) < 0) || ((l) > LP_MAX_BUF)) { \ + (*output)(arg, (char*)theFatalMsg, sizeof(theFatalMsg)-1); for(;;); \ + } else { \ + (*output)(arg, s, l); \ + } \ + } + + char buf[LP_MAX_BUF]; + + char c; + char *s; + long int num; + + int longFlag; + int negFlag; + int width; + int prec; + int ladjust; + char padc; + + int length; + + for(;;) { + { + /* scan for the next '%' */ + char *fmtStart = fmt; + while ( (*fmt != '\0') && (*fmt != '%')) { + fmt ++; + } + + /* flush the string found so far */ + OUTPUT(arg, fmtStart, fmt-fmtStart); + + /* are we hitting the end? */ + if (*fmt == '\0') break; + } + + /* we found a '%' */ + fmt ++; + + /* check for long */ + if (*fmt == 'l') { + longFlag = 1; + fmt ++; + } else { + longFlag = 0; + } + + /* check for other prefixes */ + width = 0; + prec = -1; + ladjust = 0; + padc = ' '; + + if (*fmt == '-') { + ladjust = 1; + fmt ++; + } + + if (*fmt == '0') { + padc = '0'; + fmt++; + } + + if (IsDigit(*fmt)) { + while (IsDigit(*fmt)) { + width = 10 * width + Ctod(*fmt++); + } + } + + if (*fmt == '.') { + fmt ++; + if (IsDigit(*fmt)) { + prec = 0; + while (IsDigit(*fmt)) { + prec = prec*10 + Ctod(*fmt++); + } + } + } + + + /* check format flag */ + negFlag = 0; + switch (*fmt) { + case 'b': + if (longFlag) { + num = va_arg(ap, long int); + } else { + num = va_arg(ap, int); + } + length = PrintNum(buf, num, 2, 0, width, ladjust, padc, 0); + OUTPUT(arg, buf, length); + break; + + case 'd': + case 'D': + if (longFlag) { + num = va_arg(ap, long int); + } else { + num = va_arg(ap, int); + } + if (num < 0) { + num = - num; + negFlag = 1; + } + length = PrintNum(buf, num, 10, negFlag, width, ladjust, padc, 0); + OUTPUT(arg, buf, length); + break; + + case 'o': + case 'O': + if (longFlag) { + num = va_arg(ap, long int); + } else { + num = va_arg(ap, int); + } + length = PrintNum(buf, num, 8, 0, width, ladjust, padc, 0); + OUTPUT(arg, buf, length); + break; + + case 'u': + case 'U': + if (longFlag) { + num = va_arg(ap, long int); + } else { + num = va_arg(ap, int); + } + length = PrintNum(buf, num, 10, 0, width, ladjust, padc, 0); + OUTPUT(arg, buf, length); + break; + + case 'x': + if (longFlag) { + num = va_arg(ap, long int); + } else { + num = va_arg(ap, int); + } + length = PrintNum(buf, num, 16, 0, width, ladjust, padc, 0); + OUTPUT(arg, buf, length); + break; + + case 'X': + if (longFlag) { + num = va_arg(ap, long int); + } else { + num = va_arg(ap, int); + } + length = PrintNum(buf, num, 16, 0, width, ladjust, padc, 1); + OUTPUT(arg, buf, length); + break; + + case 'c': + c = (char)va_arg(ap, int); + length = PrintChar(buf, c, width, ladjust); + OUTPUT(arg, buf, length); + break; + + case 's': + s = (char*)va_arg(ap, char *); + length = PrintString(buf, s, width, ladjust); + OUTPUT(arg, buf, length); + break; + + case '\0': + fmt --; + break; + + default: + /* output this char as it is */ + OUTPUT(arg, fmt, 1); + } /* switch (*fmt) */ + + fmt ++; + } /* for(;;) */ + + /* special termination call */ + OUTPUT(arg, "\0", 1); +} + + +/* --------------- local help functions --------------------- */ +static int +PrintChar(char * buf, char c, int length, int ladjust) +{ + int i; + + if (length < 1) length = 1; + if (ladjust) { + *buf = c; + for (i=1; i< length; i++) buf[i] = ' '; + } else { + for (i=0; i< length-1; i++) buf[i] = ' '; + buf[length - 1] = c; + } + return length; +} + +static int +PrintString(char * buf, char* s, int length, int ladjust) +{ + int i; + int len=0; + char* s1 = s; + while (*s1++) len++; + if (length < len) length = len; + + if (ladjust) { + for (i=0; i< len; i++) buf[i] = s[i]; + for (i=len; i< length; i++) buf[i] = ' '; + } else { + for (i=0; i< length-len; i++) buf[i] = ' '; + for (i=length-len; i < length; i++) buf[i] = s[i-length+len]; + } + return length; +} + +static int +PrintNum(char * buf, unsigned long u, int base, int negFlag, + int length, int ladjust, char padc, int upcase) +{ + /* algorithm : + * 1. prints the number from left to right in reverse form. + * 2. fill the remaining spaces with padc if length is longer than + * the actual length + * TRICKY : if left adjusted, no "0" padding. + * if negtive, insert "0" padding between "0" and number. + * 3. if (!ladjust) we reverse the whole string including paddings + * 4. otherwise we only reverse the actual string representing the num. + */ + + int actualLength =0; + char *p = buf; + int i; + + do { + int tmp = u %base; + if (tmp <= 9) { + *p++ = '0' + tmp; + } else if (upcase) { + *p++ = 'A' + tmp - 10; + } else { + *p++ = 'a' + tmp - 10; + } + u /= base; + } while (u != 0); + + if (negFlag) { + *p++ = '-'; + } + + /* figure out actual length and adjust the maximum length */ + actualLength = p - buf; + if (length < actualLength) length = actualLength; + + /* add padding */ + if (ladjust) { + padc = ' '; + } + if (negFlag && !ladjust && (padc == '0')) { + for (i = actualLength-1; i< length-1; i++) buf[i] = padc; + buf[length -1] = '-'; + } else { + for (i = actualLength; i< length; i++) buf[i] = padc; + } + + + /* prepare to reverse the string */ + { + int begin = 0; + int end; + if (ladjust) { + end = actualLength - 1; + } else { + end = length -1; + } + + while (end > begin) { + char tmp = buf[begin]; + buf[begin] = buf[end]; + buf[end] = tmp; + begin ++; + end --; + } + } + + /* adjust the string pointer */ + return length; +} + +static void printf_output(void *arg, char *s, int l) +{ + int i; + + // special termination call + if ((l==1) && (s[0] == '\0')) return; + + for (i=0; i< l; i++) { + board_putc(s[i]); + if (s[i] == '\n') board_putc('\r'); + } +} + +void printf(char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + lp_Print(printf_output, 0, fmt, ap); + va_end(ap); +} diff --git a/target/linux/realtek/image/lzma-loader/src/printf.h b/target/linux/realtek/image/lzma-loader/src/printf.h new file mode 100644 index 000000000..9b1c1df23 --- /dev/null +++ b/target/linux/realtek/image/lzma-loader/src/printf.h @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2001 MontaVista Software Inc. + * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net + * + * 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. + * + */ + +#ifndef _printf_h_ +#define _printf_h_ + +#include <stdarg.h> +void printf(char *fmt, ...); + +#endif /* _printf_h_ */ diff --git a/target/linux/realtek/patches-2.6.30/006-make-image.diff b/target/linux/realtek/patches-2.6.30/006-make-image.diff deleted file mode 100644 index ce4aafd1a..000000000 --- a/target/linux/realtek/patches-2.6.30/006-make-image.diff +++ /dev/null @@ -1,377 +0,0 @@ -commit a0d28029b6ca8fe1e97fa8ef4b70cdc32f09bbc1 -Author: Roman Yeryomin <roman@advem.lv> -Date: Tue Feb 5 01:55:36 2013 +0200 - - adopt 006-make-image.diff - - Signed-off-by: Roman Yeryomin <roman@advem.lv> - -diff --git a/Makefile b/Makefile -index 674b79b..30b7100 100644 ---- a/Makefile -+++ b/Makefile -@@ -1507,6 +1507,9 @@ kernelrelease: - kernelversion: - @echo $(KERNELVERSION) - -+do_rtkload: -+ $(Q)$(MAKE) -C rtkload -+ - # Single targets - # --------------------------------------------------------------------------- - # Single targets are compatible with: -diff --git a/arch/rlx/Kconfig b/arch/rlx/Kconfig -index 14f97b8..94bf573 100644 ---- a/arch/rlx/Kconfig -+++ b/arch/rlx/Kconfig -@@ -500,3 +500,9 @@ source "security/Kconfig" - source "crypto/Kconfig" - source "lib/Kconfig" - -+config RTL_KERNEL_LOAD_ADDRESS -+ hex "kernel load address in ram" -+ default "0x80500000" -+ help -+ kernel load address in ram -+ -diff --git a/rtkload/Makefile b/rtkload/Makefile -index 235673b..4a8839e 100644 ---- a/rtkload/Makefile -+++ b/rtkload/Makefile -@@ -2,64 +2,42 @@ - # Uncomment if you're building for the emulator - include ../.config - include ../../.config # to check toolchain CONFIG_RSDK_rsdk-1.5.4-5281-EB-2.6.30-0.9.30.3-uls-101110 --DOQUIET = false --#DOQUIET = true --#EMULATOR = true --#KERNEL_ROOT = /home/john/RealTek/linux-2.5/linux -+ - KERNEL_ROOT = .. --ifeq ($(wildcard $(DIR_USERS)/boa/tools/cvimg),) --ifeq ($(wildcard $(DIR_USERS)/goahead-2.1.1/LINUX/cvimg),) --CVIMG=./cvimg --else --CVIMG=$(DIR_USERS)/goahead-2.1.1/LINUX/cvimg --endif -+ - .NOTPARALLEL : all --else --CVIMG=$(DIR_USERS)/boa/tools/cvimg --endif --# ---- shouldn't need to modify below this line. - --ifdef EMULATOR --EMUOPTS = -DEMULATOR --LDSCRIPT = ld-emu.script --else -+CVIMG=cvimg -+ -+AS = $(CROSS_COMPILE)as -+LD = $(CROSS_COMPILE)ld -+CC = $(CROSS_COMPILE)gcc -+CPP = $(CC) -E -+AR = $(CROSS_COMPILE)ar -+NM = $(CROSS_COMPILE)nm -+STRIP = $(CROSS_COMPILE)strip -+OBJCOPY = $(CROSS_COMPILE)objcopy -+OBJDUMP = $(CROSS_COMPILE)objdump -+ - EMUOPTS = - LDSCRIPT = ld.script --endif - - COPTIONS = -DROM_MEMORY -DCOMPRESSED_KERNEL -D__KERNEL__ - --#SOURCES = vsprintf.c string.c ctype.c prom_printf.c misc.c hfload.c start.S read_memory.c --ifdef BZ2_COMPRESS -- SOURCES = misc.c hfload.c start.S cache.c --else --ifdef GZIP_COMPRESS -- SOURCES = string.c ctype.c misc.c hfload.c start.S read_memory.c cache.c --else -- SOURCES = string.c ctype.c misc.c hfload.c start.S read_memory.c cache.c LzmaDecode.c --endif --endif -+#SOURCES = misc.c hfload.c start.S cache.c #bzip2 -+#SOURCES = string.c ctype.c misc.c hfload.c start.S read_memory.c cache.c #gzip -+SOURCES = string.c ctype.c misc.c hfload.c start.S read_memory.c cache.c LzmaDecode.c #lzma - - LOADER_FILES = hfload.o read_memory.o --#LOADER_FILES = hfload.o --ifdef BZ2_COMPRESS -- SUPPORT_FILES = misc.o cache.o --else --ifdef GZIP_COMPRESS -- SUPPORT_FILES = vsprintf.o prom_printf.o string.o ctype.o misc.o cache.o --else --ifeq ($(strip $(DOQUIET)),true) -- SUPPORT_FILES = string.o ctype.o misc.o cache.o LzmaDecode.o --else -- SUPPORT_FILES = vsprintf.o prom_printf.o string.o ctype.o misc.o cache.o LzmaDecode.o --endif --endif --endif -- --CFLAGS =-Os -g -fno-pic -mno-abicalls $(EMUOPTS) --ifeq ($(strip $(DOQUIET)),true) --CFLAGS += $(WARNINGS) -D__DO_QUIET__ --endif -+ -+#SUPPORT_FILES = misc.o cache.o # bzip2 -+#SUPPORT_FILES = vsprintf.o prom_printf.o string.o ctype.o misc.o cache.o #gzip -+#SUPPORT_FILES = string.o ctype.o misc.o cache.o LzmaDecode.o #quiet -+SUPPORT_FILES = vsprintf.o prom_printf.o string.o ctype.o misc.o cache.o LzmaDecode.o #lzma -+ -+CFLAGS =-Os -g -fno-pic -mno-abicalls $(EMUOPTS) -march=rlx4181 -+#CFLAGS += $(WARNINGS) -D__DO_QUIET__ #quiet -+ - CFLAGS += -DEMBEDDED -I$(KERNEL_ROOT)/include/linux -I$(KERNEL_ROOT)/include -I$(KERNEL_ROOT)/lib $(COPTIONS) -G 0 - CFLAGS += -I$(KERNEL_ROOT)/arch/rlx/bsp -I$(KERNEL_ROOT)/arch/rlx/include -I$(KERNEL_ROOT)/arch/rlx/include/asm/mach-generic - #ASFLAGS = -g $(EMUOPTS) -DEMBEDDED -I$(KERNEL_ROOT)/include -I$(KERNEL_ROOT)/arch/rlx/include -@@ -69,214 +47,57 @@ ASFLAGS = -g -fno-pic -mno-abicalls $(EMUOPTS) -DEMBEDDED -I$(KERNEL_ROOT)/inclu - - LDFLAGS=-static -nostdlib - --ifdef BZ2_COMPRESS --CFLAGS += -DBZ2_COMPRESS --ASFLAGS += -DBZ2_COMPRESS --else --ifndef GZIP_COMPRESS --CFLAGS += -DLZMA_COMPRESS --ASFLAGS += -DLZMA_COMPRESS --endif --endif -- --START_FILE = start.o -+#CFLAGS += -DBZ2_COMPRESS #bzip2 -+#ASFLAGS += -DBZ2_COMPRESS #bzip2 -+#CFLAGS += #gzip -+#ASFLAGS += #gzip -+CFLAGS += -DLZMA_COMPRESS #lzma -+ASFLAGS += -DLZMA_COMPRESS #lzma - - --#RTL_819X normal LOAD_START_ADDR and FLASH_OFFSET --ifdef CONFIG_RTL_819X --LOAD_START_ADDR=0x80500000 --FLASH_OFFSET=30000 --endif -- --ifdef CONFIG_RTL_8196B_GW --ifdef CONFIG_MTD_RTL_8196_SPI --LOAD_START_ADDR=0x80A00000 --else --LOAD_START_ADDR=0x80500000 --endif --ifdef CONFIG_RTL_8196B_GW_8M --FLASH_OFFSET=10000 --else --ifeq ($(CONFIG_RTL_FLASH_MAPPING_ENABLE),y) --ifeq ($(CONFIG_RTL_LINUX_IMAGE_OFFSET),) --FLASH_OFFSET=30000 --else --FLASH_OFFSET=$(CONFIG_RTL_LINUX_IMAGE_OFFSET) --endif --else --FLASH_OFFSET=30000 --endif --endif --endif -- --ifdef CONFIG_RTL_8198_GW --ifdef CONFIG_MTD_RTL_8196_SPI --LOAD_START_ADDR=0x80A00000 --else --LOAD_START_ADDR=0x80500000 --endif --ifdef CONFIG_RTL_8196B_GW_8M --FLASH_OFFSET=10000 --else --FLASH_OFFSET=30000 --endif --endif -- --ifdef CONFIG_RTL_8196B_ICT --LOAD_START_ADDR=0x80500000 --FLASH_OFFSET=30000 --endif -- --ifdef CONFIG_RTL_865X_PANAHOST --LOAD_START_ADDR=0x80500000 --FLASH_OFFSET=20000 --endif -- --ifdef CONFIG_RTL_8197B_PANA --LOAD_START_ADDR=0x80700000 --FLASH_OFFSET=30000 --endif -- --ifdef CONFIG_RTL_8196B_AP_ROOT --LOAD_START_ADDR=0x80500000 --FLASH_OFFSET=30000 --endif -- --ifeq ($(CONFIG_RTL_FLASH_MAPPING_ENABLE),y) --ifeq ($(CONFIG_RTL_LINUX_IMAGE_OFFSET),) --FLASH_OFFSET=20000 --else --FLASH_OFFSET=$(CONFIG_RTL_LINUX_IMAGE_OFFSET) --endif --else --FLASH_OFFSET=20000 --endif -+START_FILE = start.o - --ifdef CONFIG_RTK_VOIP_BOARD --LOAD_START_ADDR=0x80C00000 --endif - --CV_SIGNATURE= --ifdef CONFIG_RTL_8197B_PANA --#CV_OPTION=linux --CV_OPTION=signature --CV_SIGNATURE=csys --else --ifdef CONFIG_SQUASHFS - CV_OPTION=linux-ro --else --CV_OPTION=linux --endif --endif -- --ifdef CONFIG_RTL_8198_NFBI_BOARD --LOAD_START_ADDR=0x80700000 --FLASH_OFFSET=30000 --CV_OPTION=signature --CV_SIGNATURE=csys --endif -- --#ifdef CONFIG_RTL_8196C_iNIC --#LOAD_START_ADDR=0x80500000 --#FLASH_OFFSET=30000 --#CV_OPTION=signature --#CV_SIGNATURE=cs6c --#endif -- --CROSS_COMPILE ?= rsdk-linux- -- --LD=$(CROSS_COMPILE)ld --CC=$(CROSS_COMPILE)gcc --CPP=$(CROSS_COMPILE)gcc --STRIP=$(CROSS_COMPILE)strip --AS=$(CROSS_COMPILE)as --NM=$(CROSS_COMPILE)nm --OBJCOPY=$(CROSS_COMPILE)objcopy -- --SEDFLAGS = s/LOAD_ADDR/$(LOAD_START_ADDR)/; -+#CV_OPTION=linux - --ifdef CONFIG_RTK_VOIP_BOARD --STRIP-OPTIONS-$(CONFIG_RSDK_rsdk-1.5.4-5281-EB-2.6.30-0.9.30.3-uls-101110) = --remove-section=.bss --endif -+SEDFLAGS = s/LOAD_ADDR/$(CONFIG_RTL_KERNEL_LOAD_ADDRESS)/; - --# jffs2 related definitions --DIR_ROMFS_BOOT = $(DIR_ROMFS)/boot/ --MKJFFS2 = ./mkfs.jffs2 --MKIMAGE_UBOOT = ./mkimage-uboot - - O_TARGET := rtk - obj-y := vmlinux_img.o $(START_FILE) $(LOADER_FILES) $(SUPPORT_FILES) - --ifdef CONFIG_ROOTFS_JFFS2 --all: rtk-clean rtk-vmlinux_img vmlinux_img.gzip.uboot.jffs2 --else --all: rtk-clean rtk-vmlinux_img $(START_FILE) $(LOADER_FILES) $(SUPPORT_FILES) --endif -+all: linux.bin - --#memload-partial --ifdef CONFIG_ROOTFS_JFFS2 --jffs2_no_this: --endif -- $(CC) -fno-pic -mno-abicalls -Os -fomit-frame-pointer -D__KERNEL__ -c vmlinux_img.c -o vmlinux_img.o -- $(OBJCOPY) --add-section .vmlinux=vmlinux_img.gz vmlinux_img.o -- @sed "$(SEDFLAGS)" < ld.script.in > $(LDSCRIPT) -+%.o:%.S -+ ${CC} ${CFLAGS} -c -o $@ $< -+%.o:%.c -+ ${CC} ${CFLAGS} -c -o $@ $< -+ -+linux.bin: $(KERNEL_ROOT)/vmlinux $(START_FILE) $(LOADER_FILES) $(SUPPORT_FILES) -+ cp $(KERNEL_ROOT)/vmlinux vmlinux-stripped -+ $(STRIP) vmlinux-stripped $(STRIP-OPTIONS-y) -+ $(OBJCOPY) -Obinary vmlinux-stripped vmlinux_img -+ #lzma -z < vmlinux_img > vmlinux_img.squish || rm -f vmlinux_img.squish -+ lzma e vmlinux_img vmlinux_img.squish -+ #bzip2 -9 < vmlinux_img > vmlinux_img.squish || rm -f vmlinux_img.squish -+ #gzip -9 < vmlinux_img > vmlinux_img.squish || rm -f vmlinux_img.squish -+ $(CVIMG) vmlinuxhdr vmlinux_img.squish vmlinux_img.squish.hdr $(KERNEL_ROOT)/vmlinux -+ $(CC) ${CFLAGS} -D__KERNEL__ -c vmlinux_img.c -o vmlinux_img.o -+ $(OBJCOPY) --add-section .vmlinux=vmlinux_img.squish.hdr vmlinux_img.o -+ sed "$(SEDFLAGS)" < ld.script.in > $(LDSCRIPT) - $(LD) $(LDFLAGS) -G 0 -T $(LDSCRIPT) -o memload-partial $(START_FILE) $(LOADER_FILES) $(SUPPORT_FILES) vmlinux_img.o - $(NM) memload-partial | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aU] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > system.map -- - cp memload-partial memload-full - $(OBJCOPY) -Obinary memload-full nfjrom -- $(CVIMG) $(CV_OPTION) nfjrom linux.bin $(LOAD_START_ADDR) $(FLASH_OFFSET) $(CV_SIGNATURE) --# @./size_chk vmlinux_img $(LOAD_START_ADDR) -- @$(CVIMG) size_chk vmlinux_img $(LOAD_START_ADDR) || exit $$? --ifeq ($(CONFIG_BLK_DEV_INITRD),y) -- @echo "RAMFS no need to check flash size" --else --ifeq ($(CONFIG_RTL_FLASH_MAPPING_ENABLE),y) -- @$(CVIMG) flash_size_chk linux.bin || exit $$? --endif --endif -+ $(CVIMG) $(CV_OPTION) nfjrom linux.bin $(CONFIG_RTL_KERNEL_LOAD_ADDRESS) $(CONFIG_RTL_LINUX_IMAGE_OFFSET) $(CV_SIGNATURE) -+ -+clean: -+ rm -f *.o memload system.map nfjrom memload-partial memload-full vmlinux_img.squish vmlinux_img.squish.hdr target target.img strip1 linux.bin vmlinux-stripped $(LDSCRIPT) vmlinux_img vmlinux_img.gzip.uboot.jffs2 - --rtk-clean: -- rm -f *.o memload system.map nfjrom memload-partial memload-full vmlinux_img.gz target target.img strip1 linux.bin vmlinux-stripped $(LDSCRIPT) vmlinux_img vmlinux_img.gzip.uboot.jffs2 -- --rtk-vmlinux_img: -- cp $(KERNEL_ROOT)/vmlinux vmlinux-stripped -- $(STRIP) vmlinux-stripped $(STRIP-OPTIONS-y) -- $(OBJCOPY) -Obinary vmlinux-stripped vmlinux_img -- rm -f vmlinux_img.gz --ifndef CONFIG_ROOTFS_JFFS2 --ifdef BZ2_COMPRESS -- cat vmlinux_img | bzip2 -9v > vmlinux_img.gz --else --ifdef GZIP_COMPRESS -- cat vmlinux_img | gzip -9v > vmlinux_img.gz --else -- ./lzma e vmlinux_img vmlinux_img.gz --endif --endif -- $(CVIMG) vmlinuxhdr vmlinux_img.gz vmlinux_img.gz $(KERNEL_ROOT)/vmlinux --endif # CONFIG_ROOTFS_JFFS2 - --target: nfjrom $(BOOT_CODE) $(EXT2_IMG) --# Pading boot code to 512 bytes long (but only 256 bytes are allowed, 512 is to make it page alignment) -- $(OBJCOPY) -Obinary --pad-to=0x80000200 $(BOOT_CODE) bootcode -- $(OBJCOPY) -Obinary --remove-section=.bss --remove-section=.data --remove-section=.mdebug --pad-to=0x806FFE00 memload-full nandrom -- $(LD) -G0 -Ttarget.script -o target -bbinary bootcode -bbinary nandrom -bbinary $(EXT2_IMG) -- $(OBJCOPY) -Obinary target target.img -- cp -f ./target.img /tftpboot - depend: - rm -f .depend - $(CC) $(CFLAGS) -MM $(SOURCES) >.depend - --bz2: -- @make BZ2_COMPRESS=1 -- --gzip: -- @make GZIP_COMPRESS=1 -- --vmlinux_img.gzip.uboot.jffs2: -- cat vmlinux_img | gzip -9v > vmlinux_img.gzip -- mkdir -p $(DIR_ROMFS_BOOT) -- $(MKIMAGE_UBOOT) -A mips -O linux -T kernel -C gzip -a 80000000 -e 80000000 -n 8954c_kernel -d vmlinux_img.gzip $(DIR_ROMFS_BOOT)/vmlinux_img.gzip.uboot -- $(MKJFFS2) -n -p -b -e $(CONFIG_JFFS2_ERASE_SIZE) -o $(DIR_IMAGE)/vmlinux_img.gzip.uboot.jffs2 -d $(DIR_ROMFS) - diff --git a/target/linux/realtek/patches-2.6.30/0061-rsdk-2.5.2-3.2-diff-fixup-rtkload.patch b/target/linux/realtek/patches-2.6.30/0061-rsdk-2.5.2-3.2-diff-fixup-rtkload.patch deleted file mode 100644 index cb1b4ee50..000000000 --- a/target/linux/realtek/patches-2.6.30/0061-rsdk-2.5.2-3.2-diff-fixup-rtkload.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/rtkload/Makefile 2013-02-05 01:54:54.283265028 +0200 -+++ b/rtkload/Makefile 2013-02-06 02:52:53.538612082 +0200 -@@ -1,7 +1,7 @@ - # The kernel tree you do builds in. - # Uncomment if you're building for the emulator - include ../.config --include ../../.config # to check toolchain CONFIG_RSDK_rsdk-1.5.4-5281-EB-2.6.30-0.9.30.3-uls-101110 -+#include ../../.config # to check toolchain CONFIG_RSDK_rsdk-1.5.4-5281-EB-2.6.30-0.9.30.3-uls-101110 - - KERNEL_ROOT = .. - diff --git a/tools/firmware-utils/Makefile b/tools/firmware-utils/Makefile index ce9e1f7ce..c4e1623fa 100644 --- a/tools/firmware-utils/Makefile +++ b/tools/firmware-utils/Makefile @@ -62,7 +62,7 @@ define Host/Compile $(call cc, mkcameofw, -Wall) $(call cc,seama md5) $(call cc,fix-u-media-header cyg_crc32,-Wall) - $(call cc,bixutil) + $(call cc,mgbin) $(call cc,cvimg) endef diff --git a/tools/firmware-utils/src/apmib.h b/tools/firmware-utils/src/apmib.h index 0695457f9..19b971748 100644 --- a/tools/firmware-utils/src/apmib.h +++ b/tools/firmware-utils/src/apmib.h @@ -1,2035 +1,77 @@ -/* - * Header file of AP mib - * Authors: David Hsu <davidhsu@realtek.com.tw> - * - * $Id: apmib.h,v 1.54 2009/09/15 02:12:24 bradhuang Exp $ - * - */ - - -#ifndef INCLUDE_APMIB_H -#define INCLUDE_APMIB_H - -/* Forrest, 2007.11.07. - * If you want to let APMIB adopt shared memory mechanism, define it to 1. - * Or define it to 0 will go back to original local copy mechanism. - * Note: - * 1. I only use shared memory for HW Configuration (pHwSetting), Default - * Configuration (pMibDef) and Current Configuration (pMib). There is - * no shared memory for each linkchain now. - * 2. Because uClibc does not support POSIX inter-process semaphore, I have - * to use SYSTEM V semaphore and shared memory. So if you want to adopt - * shared memory mechanism, you must go to turn on CONFIG_SYSVIPC - * kernel config to support it. - */ -#ifdef CONFIG_APMIB_SHARED - #define CONFIG_APMIB_SHARED_MEMORY 1 -#else - #define CONFIG_APMIB_SHARED_MEMORY 0 -#endif - -// added by rock ///////////////////////////////////////// -#ifdef VOIP_SUPPORT -#include "voip_flash.h" -#include "voip_flash_mib.h" -#endif - -#if defined(CONFIG_DOMAIN_NAME_QUERY_SUPPORT) -//#define LOGDEBUG_ENABLED -#endif - -#define MBSSID - -//hf -#define CONFIG_RTL_BT_CLIENT - -#define COMPRESS_MIB_SETTING -#define MIB_TLV - -#ifdef MIB_TLV -#define MIB_TABLE_LIST 0x8000 -#else -#define MIB_TABLE_LIST 0x0 -#endif - -//#ifdef HOME_GATEWAY -//#define GW_QOS_ENGINE -//#endif -#ifdef ENABLE_QOS // thru makefile - #ifndef QOS_BY_BANDWIDTH - #define GW_QOS_ENGINE - #endif -#endif - -#if defined(CONFIG_RTL_92D_SUPPORT)||defined(CONFIG_RTL_DUAL_PCIESLOT_BIWLAN) -#define NUM_WLAN_INTERFACE 2 // number of wlan interface supported -#else -#define NUM_WLAN_INTERFACE 1 // number of wlan interface supported -#endif - -#if defined(CONFIG_RTL_819X) -#define NUM_WLAN_MULTIPLE_SSID 8 // number of wlan ssid support -#else -//!CONFIG_RTL_8196B => rtl8651c+rtl8190 -#define NUM_WLAN_MULTIPLE_SSID 5 // number of wlan ssid support -#endif - -#ifdef MBSSID -#define NUM_VWLAN 4 // number of virtual wlan interface supported -#else -#define NUM_VWLAN 0 -#endif - -#ifdef UNIVERSAL_REPEATER -#define NUM_VWLAN_INTERFACE NUM_VWLAN+1 -#else -#define NUM_VWLAN_INTERFACE NUM_VWLAN -#endif - -// WLAN MIB id -#define MIB_WLAN_SSID 1 -#define MIB_WLAN_CHANNEL 2 -#define MIB_WLAN_WEP 3 -#define MIB_WLAN_WEP64_KEY1 4 -#define MIB_WLAN_WEP64_KEY2 5 -#define MIB_WLAN_WEP64_KEY3 6 -#define MIB_WLAN_WEP64_KEY4 7 -#define MIB_WLAN_WEP128_KEY1 8 -#define MIB_WLAN_WEP128_KEY2 9 -#define MIB_WLAN_WEP128_KEY3 10 -#define MIB_WLAN_WEP128_KEY4 11 -#define MIB_WLAN_WEP_KEY_TYPE 12 -#define MIB_WLAN_WEP_DEFAULT_KEY 13 -#define MIB_WLAN_FRAG_THRESHOLD 14 -#define MIB_WLAN_SUPPORTED_RATES 15 -#define MIB_WLAN_BEACON_INTERVAL 16 -#define MIB_WLAN_PREAMBLE_TYPE 17 -#define MIB_WLAN_BASIC_RATES 18 -#define MIB_WLAN_RTS_THRESHOLD 19 -#define MIB_WLAN_AUTH_TYPE 20 -#define MIB_WLAN_HIDDEN_SSID 21 -#define MIB_WLAN_WLAN_DISABLED 22 -#define MIB_ELAN_MAC_ADDR 23 -#define MIB_WLAN_WLAN_MAC_ADDR 24 -#define MIB_WLAN_ENCRYPT 25 -#define MIB_WLAN_ENABLE_SUPP_NONWPA 26 -#define MIB_WLAN_SUPP_NONWPA 27 -#define MIB_WLAN_WPA_AUTH 28 -#define MIB_WLAN_WPA_CIPHER_SUITE 29 -#define MIB_WLAN_WPA_PSK 30 -#define MIB_WLAN_WPA_GROUP_REKEY_TIME 31 -#define MIB_WLAN_RS_IP 32 -#define MIB_WLAN_RS_PORT 33 -#define MIB_WLAN_RS_PASSWORD 34 -#define MIB_WLAN_ENABLE_1X 35 -#define MIB_WLAN_PSK_FORMAT 36 -#define MIB_WLAN_WPA2_PRE_AUTH 37 -#define MIB_WLAN_WPA2_CIPHER_SUITE 38 -#define MIB_WLAN_ACCOUNT_RS_ENABLED 39 -#define MIB_WLAN_ACCOUNT_RS_IP 40 -#define MIB_WLAN_ACCOUNT_RS_PORT 41 -#define MIB_WLAN_ACCOUNT_RS_PASSWORD 42 -#define MIB_WLAN_ACCOUNT_RS_UPDATE_ENABLED 43 -#define MIB_WLAN_ACCOUNT_RS_UPDATE_DELAY 44 -#define MIB_WLAN_MAC_AUTH_ENABLED 45 -#define MIB_WLAN_RS_MAXRETRY 46 -#define MIB_WLAN_RS_INTERVAL_TIME 47 -#define MIB_WLAN_ACCOUNT_RS_MAXRETRY 48 -#define MIB_WLAN_ACCOUNT_RS_INTERVAL_TIME 49 - -#define MIB_WLAN_INACTIVITY_TIME 50 -#define MIB_WLAN_RATE_ADAPTIVE_ENABLED 51 -#define MIB_WLAN_MACAC_ENABLED 52 -#define MIB_WLAN_MACAC_NUM 53 -#define MIB_WLAN_MACAC_ADDR ((MIB_WLAN_MACAC_NUM+1)|MIB_TABLE_LIST) -#define MIB_WLAN_AC_ADDR_ADD ((MIB_WLAN_MACAC_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_WLAN_AC_ADDR_DEL ((MIB_WLAN_MACAC_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_WLAN_AC_ADDR_DELALL ((MIB_WLAN_MACAC_NUM+4)|MIB_DELALL_TBL_ENTRY) -#define MIB_WLAN_DTIM_PERIOD 58 -#define MIB_WLAN_MODE 59 -#define MIB_WLAN_NETWORK_TYPE 60 -#define MIB_WLAN_DEFAULT_SSID 61 // used while configured as Ad-hoc and no any other Ad-hoc could be joined - // it will use this default SSID to start BSS -#define MIB_WLAN_IAPP_DISABLED 62 -#define MIB_WLAN_WDS_ENABLED 63 -#define MIB_WLAN_WDS_NUM 64 -#define MIB_WLAN_WDS ((MIB_WLAN_WDS_NUM+1)|MIB_TABLE_LIST) -#define MIB_WLAN_WDS_ADD ((MIB_WLAN_WDS_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_WLAN_WDS_DEL ((MIB_WLAN_WDS_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_WLAN_WDS_DELALL ((MIB_WLAN_WDS_NUM+4)|MIB_DELALL_TBL_ENTRY) -#define MIB_WLAN_WDS_ENCRYPT 69 -#define MIB_WLAN_WDS_WEP_FORMAT 70 -#define MIB_WLAN_WDS_WEP_KEY 71 -#define MIB_WLAN_WDS_PSK_FORMAT 72 -#define MIB_WLAN_WDS_PSK 73 -#define MIB_WLAN_BAND 74 -#define MIB_WLAN_FIX_RATE 75 -#define MIB_WLAN_BLOCK_RELAY 76 -#define MIB_WLAN_MACCLONE_ENABLED 77 -#define MIB_WLAN_PROTECTION_DISABLED 78 -#ifdef TLS_CLIENT -//sc_yang for client mode TLS -#define MIB_CERTROOT_TBL_NUM 79 -#define MIB_CERTROOT_TBL ((MIB_CERTROOT_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_CERTROOT_ADD ((MIB_CERTROOT_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_CERTROOT_DEL ((MIB_CERTROOT_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_CERTROOT_DELALL ((MIB_CERTROOT_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) -#define MIB_CERTUSER_TBL_NUM 84 -#define MIB_CERTUSER_TBL ((MIB_CERTUSER_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_CERTUSER_ADD ((MIB_CERTUSER_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_CERTUSER_DEL ((MIB_CERTUSER_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_CERTUSER_DELALL ((MIB_CERTUSER_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) -#endif - -// for WMM -#define MIB_WLAN_WMM_ENABLED 89 - -#ifdef WLAN_EASY_CONFIG -#define MIB_WLAN_EASYCFG_ENABLED 90 -#define MIB_WLAN_EASYCFG_MODE 91 -#define MIB_WLAN_EASYCFG_SSID 92 -#define MIB_WLAN_EASYCFG_KEY 93 -#define MIB_WLAN_EASYCFG_ALG_REQ 94 -#define MIB_WLAN_EASYCFG_ALG_SUPP 95 -#define MIB_WLAN_EASYCFG_DIGEST 96 -#define MIB_WLAN_EASYCFG_ROLE 97 -#define MIB_WLAN_EASYCFG_SCAN_SSID 98 -#define MIB_WLAN_EASYCFG_WLAN_MODE 99 -#endif // WLAN_EASY_CONFIG - -#ifdef MIB_TLV -#define MIB_ROOT (100|MIB_TABLE_LIST) -#define MIB_WLAN_ROOT (101|MIB_TABLE_LIST) -#else //etop modify -#define MIB_ROOT (100|MIB_TABLE_LIST) -#define MIB_WLAN_ROOT (101|MIB_TABLE_LIST) - -#endif -#if defined(CONFIG_RTL_8198_AP_ROOT) -#define MIB_NTP_ENABLED 151 -#define MIB_NTP_SERVER_ID 152 -#define MIB_NTP_TIMEZONE 153 -#define MIB_NTP_SERVER_IP1 154 -#define MIB_NTP_SERVER_IP2 155 -#endif - -#define MIB_WAN_MAC_ADDR 100 -#define MIB_WAN_IP_ADDR 101 -#define MIB_WAN_SUBNET_MASK 102 -#define MIB_WAN_DEFAULT_GATEWAY 103 -#define MIB_WAN_DHCP 104 -#define MIB_DNS_MODE 105 -#define MIB_PPP_USER_NAME 106 -#define MIB_PPP_PASSWORD 107 -#define MIB_PPP_IDLE_TIME 108 -#define MIB_PPP_CONNECT_TYPE 109 - -#ifdef HOME_GATEWAY - -#define MIB_PORTFW_ENABLED 110 -#define MIB_PORTFW_TBL_NUM 111 -#define MIB_PORTFW_TBL ((MIB_PORTFW_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_PORTFW_ADD ((MIB_PORTFW_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_PORTFW_DEL ((MIB_PORTFW_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_PORTFW_DELALL ((MIB_PORTFW_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) -#define MIB_IPFILTER_ENABLED 116 -#define MIB_IPFILTER_TBL_NUM 117 -#define MIB_IPFILTER_TBL ((MIB_IPFILTER_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_IPFILTER_ADD ((MIB_IPFILTER_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_IPFILTER_DEL ((MIB_IPFILTER_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_IPFILTER_DELALL ((MIB_IPFILTER_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) -#define MIB_MACFILTER_ENABLED 122 -#define MIB_MACFILTER_TBL_NUM 123 -#define MIB_MACFILTER_TBL ((MIB_MACFILTER_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_MACFILTER_ADD ((MIB_MACFILTER_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_MACFILTER_DEL ((MIB_MACFILTER_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_MACFILTER_DELALL ((MIB_MACFILTER_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) -#define MIB_PORTFILTER_ENABLED 128 -#define MIB_PORTFILTER_TBL_NUM 129 -#define MIB_PORTFILTER_TBL ((MIB_PORTFILTER_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_PORTFILTER_ADD ((MIB_PORTFILTER_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_PORTFILTER_DEL ((MIB_PORTFILTER_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_PORTFILTER_DELALL ((MIB_PORTFILTER_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) -#define MIB_TRIGGERPORT_ENABLED 134 -#define MIB_TRIGGERPORT_TBL_NUM 135 -#define MIB_TRIGGERPORT_TBL ((MIB_TRIGGERPORT_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_TRIGGERPORT_ADD ((MIB_TRIGGERPORT_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_TRIGGERPORT_DEL ((MIB_TRIGGERPORT_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_TRIGGERPORT_DELALL ((MIB_TRIGGERPORT_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) -#define MIB_DMZ_ENABLED 140 -#define MIB_DMZ_HOST 141 -#define MIB_UPNP_ENABLED 142 -#define MIB_UPNP_IGD_NAME 143 -#endif //#ifdef HOME_GATEWAY - -#define MIB_PPP_MTU_SIZE 144 -#define MIB_PPTP_IP_ADDR 145 -#define MIB_PPTP_SUBNET_MASK 146 -#define MIB_PPTP_SERVER_IP_ADDR 147 -#define MIB_PPTP_USER_NAME 148 -#define MIB_PPTP_PASSWORD 149 -#define MIB_PPTP_MTU_SIZE 150 -#define MIB_NTP_ENABLED 151 -#define MIB_NTP_SERVER_ID 152 -#define MIB_NTP_TIMEZONE 153 -#define MIB_NTP_SERVER_IP1 154 -#define MIB_NTP_SERVER_IP2 155 -#define MIB_PPTP_SECURITY_ENABLED 156 -#define MIB_FIXED_IP_MTU_SIZE 157 -#define MIB_DHCP_MTU_SIZE 158 -#define MIB_PPTP_MPPC_ENABLED 159 - -#ifdef HOME_GATEWAY - -#ifdef VPN_SUPPORT -#define MIB_IPSECTUNNEL_ENABLED 160 -#define MIB_IPSECTUNNEL_TBL_NUM 161 -#define MIB_IPSECTUNNEL_TBL ((MIB_IPSECTUNNEL_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_IPSECTUNNEL_ADD ((MIB_IPSECTUNNEL_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_IPSECTUNNEL_DEL ((MIB_IPSECTUNNEL_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_IPSECTUNNEL_DELALL ((MIB_IPSECTUNNEL_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) -#define MIB_IPSEC_NATT_ENABLED 167 -#define MIB_IPSEC_RSA_FILE 168 -#endif -#endif // HOME_GATEWAY - -#define MIB_IP_ADDR 170 -#define MIB_SUBNET_MASK 171 -#define MIB_DEFAULT_GATEWAY 172 -#define MIB_DHCP 173 -#define MIB_DHCP_CLIENT_START 174 -#define MIB_DHCP_CLIENT_END 175 -#define MIB_DNS1 176 -#define MIB_DNS2 177 -#define MIB_DNS3 178 -#define MIB_STP_ENABLED 179 -#define MIB_SUPER_NAME 180 -#define MIB_SUPER_PASSWORD 181 -#define MIB_USER_NAME 182 -#define MIB_USER_PASSWORD 183 -#define MIB_SCRLOG_ENABLED 184 -#define MIB_AUTO_DISCOVERY_ENABLED 185 -#define MIB_DEVICE_NAME 186 - -#ifdef HOME_GATEWAY -#define MIB_DDNS_ENABLED 187 -#define MIB_DDNS_TYPE 188 -#define MIB_DDNS_DOMAIN_NAME 189 -#define MIB_DDNS_USER 190 -#define MIB_DDNS_PASSWORD 191 -#endif -#define MIB_OP_MODE 192 -#define MIB_WISP_WAN_ID 193 - -#ifdef HOME_GATEWAY -#define MIB_WEB_WAN_ACCESS_ENABLED 194 -#define MIB_PING_WAN_ACCESS_ENABLED 195 -#define MIB_HOST_NAME 197 -#endif - -#define MIB_DOMAIN_NAME 198 - -#ifdef MIB_TLV -//#define MIB_TABLE_LIST 0x8000 -#define MIB_ID_MASK (0x8000-1) -#define MIB_HW_ROOT (200|MIB_TABLE_LIST) -#define MIB_HW_WLAN_ROOT (201|MIB_TABLE_LIST) -#define MIB_ADD_TBL_ENTRY 0x10000 -#define MIB_DEL_TBL_ENTRY 0x20000 -#define MIB_DELALL_TBL_ENTRY 0x40000 -#define MIB_WLAN_TBL 0x80000 -#else //etop modify :for config -//#define MIB_TABLE_LIST 0x8000 -#define MIB_ID_MASK (0x8000-1) -#define MIB_HW_ROOT (200|MIB_TABLE_LIST) -#define MIB_HW_WLAN_ROOT (201|MIB_TABLE_LIST) -#define MIB_ADD_TBL_ENTRY 0x10000 -#define MIB_DEL_TBL_ENTRY 0x20000 -#define MIB_DELALL_TBL_ENTRY 0x40000 -#define MIB_WLAN_TBL 0x80000 -#endif // #ifdef MIB_TLV - -// Hardware setting MIB -#define MIB_HW_BOARD_VER 200 -#define MIB_HW_NIC0_ADDR 201 -#define MIB_HW_NIC1_ADDR 202 -#define MIB_HW_WLAN_ADDR 203 -#define MIB_HW_REG_DOMAIN 204 -#define MIB_HW_RF_TYPE 205 -#define MIB_HW_TX_POWER_CCK 206 -#define MIB_HW_TX_POWER_OFDM 207 -#define MIB_HW_ANT_DIVERSITY 208 -#define MIB_HW_TX_ANT 209 -#define MIB_HW_CCA_MODE 210 -#define MIB_HW_PHY_TYPE 211 -#define MIB_HW_LED_TYPE 212 -#define MIB_HW_INIT_GAIN 213 - - -#ifdef TLS_CLIENT -#define MIB_ROOT_IDX 214 -#define MIB_USER_IDX 215 -#endif -#ifdef ROUTE_SUPPORT -#define MIB_STATICROUTE_ENABLED 216 -#define MIB_STATICROUTE_TBL_NUM 217 -#define MIB_STATICROUTE_TBL ((MIB_STATICROUTE_TBL_NUM+1)|MIB_TABLE_LIST) /*218*/ -#define MIB_STATICROUTE_ADD ((MIB_STATICROUTE_TBL_NUM+2) | MIB_ADD_TBL_ENTRY) -#define MIB_STATICROUTE_DEL ((MIB_STATICROUTE_TBL_NUM+3) | MIB_DEL_TBL_ENTRY) -#define MIB_STATICROUTE_DELALL ((MIB_STATICROUTE_TBL_NUM+4) | MIB_DELALL_TBL_ENTRY)/*221*/ -#define MIB_RIP_ENABLED 222 -#define MIB_RIP_LAN_TX 223 -#define MIB_RIP_LAN_RX 224 -#define MIB_RIP_WAN_TX 225 -#define MIB_RIP_WAN_RX 226 -#endif - -#define MIB_REMOTELOG_ENABLED 227 -#define MIB_REMOTELOG_SERVER 228 - -#ifdef HOME_GATEWAY -#ifdef DOS_SUPPORT -#define MIB_DOS_ENABLED 229 -#define MIB_DOS_SYSSYN_FLOOD 230 -#define MIB_DOS_SYSFIN_FLOOD 231 -#define MIB_DOS_SYSUDP_FLOOD 232 -#define MIB_DOS_SYSICMP_FLOOD 233 -#define MIB_DOS_PIPSYN_FLOOD 234 -#define MIB_DOS_PIPFIN_FLOOD 235 -#define MIB_DOS_PIPUDP_FLOOD 236 -#define MIB_DOS_PIPICMP_FLOOD 237 -#define MIB_DOS_BLOCK_TIME 238 -#endif -#define MIB_URLFILTER_ENABLED 239 -#define MIB_URLFILTER_TBL_NUM 240 -#define MIB_URLFILTER_TBL ((MIB_URLFILTER_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_URLFILTER_ADD ((MIB_URLFILTER_TBL_NUM+2) | MIB_ADD_TBL_ENTRY) -#define MIB_URLFILTER_DEL ((MIB_URLFILTER_TBL_NUM+3) | MIB_DEL_TBL_ENTRY) -#define MIB_URLFILTER_DELALL ((MIB_URLFILTER_TBL_NUM+4)| MIB_DELALL_TBL_ENTRY) - -#define MIB_VPN_PASSTHRU_IPSEC_ENABLED 245 -#define MIB_VPN_PASSTHRU_PPTP_ENABLED 246 -#define MIB_VPN_PASSTHRU_L2TP_ENABLED 247 -#define MIB_CUSTOM_PASSTHRU_ENABLED 386 -#endif - -//#ifdef SNMP_SUPPORT Keith remove -#define MIB_SNMP_RO_COMMUNITY 248 -#define MIB_SNMP_RW_COMMUNITY 249 -//#endif Keith remove -#ifdef UNIVERSAL_REPEATER -#define MIB_REPEATER_ENABLED1 250 -#define MIB_REPEATER_SSID1 251 -#define MIB_REPEATER_ENABLED2 252 -#define MIB_REPEATER_SSID2 253 -#endif - -// added by rock ///////////////////////////////////////// -#ifdef VOIP_SUPPORT -#define MIB_VOIP_CFG 254 -#endif // VOIP_SUPPORT - -#define MIB_WIFI_SPECIFIC 260 - -#define MIB_PPP_SERVICE_NAME 261 - -#define MIB_WLAN_TURBO_MODE 262 -#define MIB_WLAN_RFPOWER_SCALE 263 - -#ifdef WIFI_SIMPLE_CONFIG -#define MIB_WLAN_WSC_DISABLE 270 -#define MIB_WLAN_WSC_METHOD 271 -#define MIB_WLAN_WSC_CONFIGURED 272 -#define MIB_HW_WSC_PIN 273 -#define MIB_WLAN_WSC_AUTH 274 -#define MIB_WLAN_WSC_ENC 275 -#define MIB_WLAN_WSC_MANUAL_ENABLED 276 -#define MIB_WLAN_WSC_PSK 277 -#define MIB_WLAN_WSC_SSID 278 -#define MIB_WLAN_WSC_UPNP_ENABLED 279 -#define MIB_WLAN_WSC_REGISTRAR_ENABLED 280 -#define MIB_WLAN_WSC_CONFIGBYEXTREG 281 -#endif -//Brad addd -#define MIB_DAYLIGHT_SAVE 282 -#define MIB_IGMP_PROXY_DISABLED 283 -//Brad add for 11N -#define MIB_WLAN_CHANNEL_BONDING 284 -#define MIB_WLAN_CONTROL_SIDEBAND 285 -#define MIB_WLAN_AGGREGATION 286 -#define MIB_WLAN_SHORT_GI 287 -//Brad define -#define MIB_WLAN_WEP64_KEY 288 -#define MIB_WLAN_WEP128_KEY 289 - -#define MIB_HW_11N_XCAP 290 -#define MIB_HW_11N_RXIMR 291 -#define MIB_DHCPRSVDIP_ENABLED 292 -#define MIB_DHCPRSVDIP_TBL_NUM 293 -#define MIB_DHCPRSVDIP_TBL ((MIB_DHCPRSVDIP_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_DHCPRSVDIP_ADD ((MIB_DHCPRSVDIP_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_DHCPRSVDIP_DEL ((MIB_DHCPRSVDIP_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_DHCPRSVDIP_DELALL ((MIB_DHCPRSVDIP_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) -#define MIB_HW_11N_LOFDMPWD 298 -#define MIB_HW_11N_ANTPWD_B 299 -#define MIB_HW_11N_ANTPWD_C 300 -#define MIB_HW_11N_ANTPWD_D 301 -#define MIB_HW_11N_THER_RFIC 302 -#define MIB_HW_WLAN_ADDR1 303 -#define MIB_HW_WLAN_ADDR2 304 -#define MIB_HW_WLAN_ADDR3 305 -#define MIB_HW_WLAN_ADDR4 306 - -// GW_QOS_ENGINE -#define MIB_QOS_ENABLED 307 -#define MIB_QOS_AUTO_UPLINK_SPEED 308 -#define MIB_QOS_MANUAL_UPLINK_SPEED 309 -#define MIB_QOS_RULE_TBL_NUM 310 -#define MIB_QOS_RULE_TBL ((MIB_QOS_RULE_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_QOS_ADD ((MIB_QOS_RULE_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_QOS_DEL ((MIB_QOS_RULE_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_QOS_DELALL ((MIB_QOS_RULE_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) - -#define MIB_WLAN_ACCESS 315 -#define MIB_WLAN_PRIORITY 316 - -#define MIB_START_MP 317 - -#define MIB_SYSTIME_YEAR 321 -#define MIB_SYSTIME_MON 322 -#define MIB_SYSTIME_DAY 323 -#define MIB_SYSTIME_HOUR 324 -#define MIB_SYSTIME_MIN 325 -#define MIB_SYSTIME_SEC 326 - -/* # keith: add l2tp support. 20080515 */ -#define MIB_L2TP_IP_ADDR 331 -#define MIB_L2TP_SUBNET_MASK 332 -#define MIB_L2TP_SERVER_IP_ADDR 333 -#define MIB_L2TP_USER_NAME 334 -#define MIB_L2TP_PASSWORD 335 -#define MIB_L2TP_MTU_SIZE 336 -#define MIB_L2TP_CONNECTION_TYPE 337 -#define MIB_L2TP_IDLE_TIME 338 - -#ifdef CONFIG_IPV6 -#define MIB_IPV6_ID 380 -#define MIB_IPV6_RADVD_PARAM (MIB_IPV6_ID) -#define MIB_IPV6_DNSV6_PARAM (MIB_IPV6_ID+1) -#define MIB_IPV6_DHCPV6S_PARAM (MIB_IPV6_ID+2) -#define MIB_IPV6_ADDR_PARAM (MIB_IPV6_ID+3) -#define MIB_IPV6_TUNNEL_PARAM (MIB_IPV6_ID+4) -#endif - -// SNMP, Forrest added, 2007.10.25. -#ifdef CONFIG_SNMP -#define MIB_SNMP_ENABLED 435 -#define MIB_SNMP_NAME 436 -#define MIB_SNMP_LOCATION 437 -#define MIB_SNMP_CONTACT 438 -#define MIB_SNMP_RWCOMMUNITY 439 -#define MIB_SNMP_ROCOMMUNITY 440 -#define MIB_SNMP_TRAP_RECEIVER1 441 -#define MIB_SNMP_TRAP_RECEIVER2 442 -#define MIB_SNMP_TRAP_RECEIVER3 443 -#endif - -//### add by sen_liu 2011.3.29 TX Beamforming added to mib in 92D -#define MIB_WLAN_TX_BEAMFORMING 450 -//### end - -/*hf add for country str*/ -#define MIB_WLAN_COUNTRY_STRING 451 -/*end*/ -/* # keith: add l2tp support. 20080515 */ -#define MIB_L2TP_WAN_IP_DYNAMIC 501 -#define MIB_L2TP_GATEWAY 502 -//SCHEDULE - -#define MIB_WLAN_SCHEDULE_ENABLED 503 -#define MIB_WLAN_SCHEDULE_TBL_NUM 504 -#define MIB_WLAN_SCHEDULE_TBL ((MIB_WLAN_SCHEDULE_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_WLAN_SCHEDULE_ADD ((MIB_WLAN_SCHEDULE_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_WLAN_SCHEDULE_DEL ((MIB_WLAN_SCHEDULE_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_WLAN_SCHEDULE_DELALL ((MIB_WLAN_SCHEDULE_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) - -#define MIB_PPTP_CONNECTION_TYPE 509 -#define MIB_PPTP_IDLE_TIME 510 - - -//NewAdd For rtl8196B -#define MIB_HW_WLAN_ADDR5 511 -#define MIB_HW_WLAN_ADDR6 512 -#define MIB_HW_WLAN_ADDR7 513 - -#define MIB_HW_TX_POWER_OFDM_1S 514 -#define MIB_HW_TX_POWER_OFDM_2S 515 -#define MIB_HW_11N_LOFDMPWDA 516 -#define MIB_HW_11N_LOFDMPWDB 517 -#define MIB_HW_11N_TSSI1 518 -#define MIB_HW_11N_TSSI2 519 -#define MIB_HW_11N_THER 520 -#define MIB_HW_11N_TRSWITCH 521 //MIB_HW_11N_ESERVED1->MIB_HW_11N_TRSWITCH -#define MIB_HW_11N_TRSWPAPE_C9 522 -#define MIB_HW_11N_TRSWPAPE_CC 523 -#define MIB_HW_11N_TARGET_PWR 524 -#define MIB_HW_11N_RESERVED5 525 -#define MIB_HW_11N_RESERVED6 526 -#define MIB_HW_11N_RESERVED7 527 -#define MIB_HW_11N_RESERVED8 528 - -/*-----end-----*/ - -// SNMP maximum length of fields, Forrest added, 2007.10.25. -#ifdef CONFIG_SNMP -#define MAX_SNMP_NAME_LEN 64 -#define MAX_SNMP_LOCATION_LEN 64 -#define MAX_SNMP_CONTACT_LEN 64 -#define MAX_SNMP_COMMUNITY_LEN 64 -#endif - -//=========add for MESH========= -//#ifdef CONFIG_RTK_MESH Keith remove -#define MIB_MESH_ENABLE 644 //new feature:Mesh enable/disable -#define MIB_MESH_ROOT_ENABLE 551 -#define MIB_MESH_ID 554 -#define MIB_MESH_MAX_NEIGHTBOR 555 -#define MIB_MESH_ENCRYPT 559 -#define MIB_MESH_PSK_FORMAT 560 -#define MIB_MESH_WPA_PSK 561 -#define MIB_MESH_WPA_AUTH 562 -#define MIB_MESH_WPA2_CIPHER_SUITE 563 - -//#ifdef _MESH_ACL_ENABLE_ Keith remove -#define MIB_MESH_ACL_ENABLED 580 -#define MIB_MESH_ACL_NUM 581 -#define MIB_MESH_ACL_ADDR ((MIB_MESH_ACL_NUM+1)|MIB_TABLE_LIST) -#define MIB_MESH_ACL_ADDR_ADD ((MIB_MESH_ACL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_MESH_ACL_ADDR_DEL ((MIB_MESH_ACL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_MESH_ACL_ADDR_DELALL ((MIB_MESH_ACL_NUM+4)|MIB_DELALL_TBL_ENTRY) -//#endif Keith remove - -//#ifdef _11s_TEST_MODE_ Keith remove -#define MIB_MESH_TEST_PARAM1 600 -#define MIB_MESH_TEST_PARAM2 601 -#define MIB_MESH_TEST_PARAM3 602 -#define MIB_MESH_TEST_PARAM4 603 -#define MIB_MESH_TEST_PARAM5 604 -#define MIB_MESH_TEST_PARAM6 605 -#define MIB_MESH_TEST_PARAM7 606 -#define MIB_MESH_TEST_PARAM8 607 -#define MIB_MESH_TEST_PARAM9 608 -#define MIB_MESH_TEST_PARAMA 609 -#define MIB_MESH_TEST_PARAMB 610 -#define MIB_MESH_TEST_PARAMC 611 -#define MIB_MESH_TEST_PARAMD 612 -#define MIB_MESH_TEST_PARAME 613 -#define MIB_MESH_TEST_PARAMF 614 -#define MIB_MESH_TEST_PARAMSTR1 615 -//#endif Keith remove -//#endif // CONFIG_RTK_MESH Keith remove -//=========add for MESH========= - -#define MIB_VLANCONFIG_ENABLED 616 -#define MIB_VLANCONFIG_TBL_NUM 617 -#define MIB_VLANCONFIG_TBL ((MIB_VLANCONFIG_TBL_NUM+1)|MIB_TABLE_LIST) -#define MIB_VLANCONFIG_ADD ((MIB_VLANCONFIG_TBL_NUM+2)|MIB_ADD_TBL_ENTRY) -#define MIB_VLANCONFIG_DEL ((MIB_VLANCONFIG_TBL_NUM+3)|MIB_DEL_TBL_ENTRY) -#define MIB_VLANCONFIG_DELALL ((MIB_VLANCONFIG_TBL_NUM+4)|MIB_DELALL_TBL_ENTRY) - -//#ifdef CONFIG_RTL_WAPI_SUPPORT Keith remove -//WAPI start from 630 -#define MIB_WLAN_WAPI_PSK 630 -#define MIB_WLAN_WAPI_PSKLEN 631 -#define MIB_WLAN_WAPI_PSK_FORMAT 632 -#define MIB_WLAN_WAPI_AUTH 633 -#define MIB_WLAN_WAPI_ASIPADDR 634 -#define MIB_WLAN_WAPI_SEARCHINFO 635 -#define MIB_WLAN_WAPI_SEARCHINDEX 636 -#define MIB_WLAN_WAPI_MCASTREKEY 637 -#define MIB_WLAN_WAPI_MCAST_TIME 638 -#define MIB_WLAN_WAPI_MCAST_PACKETS 639 -#define MIB_WLAN_WAPI_UCASTREKEY 640 -#define MIB_WLAN_WAPI_UCAST_TIME 641 -#define MIB_WLAN_WAPI_UCAST_PACKETS 642 -#define MIB_WLAN_WAPI_CA_INIT 643 - -//Added to support two remote as and one local as at the same time -#define MIB_WLAN_WAPI_CERT_SEL 656 - -#define MIB_NAT_ENABLED 645 -#define MIB_WLAN_STBC_ENABLED 646 -#define MIB_WLAN_COEXIST_ENABLED 647 -#define MIB_SAMBA_ENABLED 650 - -#define MIB_MIB_VER 655 - -//#ifdef CONFIG_RTL_WAPI_SUPPORT Keith remove -#define CERTS_DATABASE "/var/myca/index.txt" -#define ONE_DAY_SECONDS 86400 -#define USER_NAME_LEN 32 -typedef struct _CertsDbEntry_ { - unsigned char userName[USER_NAME_LEN]; //user name of this user cert - unsigned long serial; //serial of this cert - unsigned short validDays; //total valid days of this cert - unsigned short validDaysLeft; //the left valid days of this cert - unsigned char certType; //0(default): X.509; others: reserved - unsigned char certStatus; //0(default): valid; 1: expired; 2: revoked -} CERTS_DB_ENTRY_T, *CERTS_DB_ENTRY_Tp; -//#endif Keith remove -//WAPI END - -// GW_QOS_ENGINE -#define MIB_QOS_AUTO_DOWNLINK_SPEED 651 -#define MIB_QOS_MANUAL_DOWNLINK_SPEED 652 - -//11n onoff TKIP -#define MIB_WLAN_11N_ONOFF_TKIP 660 - -#ifdef CONFIG_RTL_BT_CLIENT -#define MIB_BT_UPLOAD_DIR 680 -#define MIB_BT_DOWNLOAD_DIR 681 -#define MIB_BT_TOTAL_ULIMIT 682 -#define MIB_BT_TOTAL_DLIMIT 683 -#define MIB_BT_REFRESH_TIME 684 -#define MIB_BT_ENABLED 685 -#endif - -#define MIB_WLAN_ACK_TIMEOUT 686 - -/*+++++added by Jack for Tr-069 configuration+++++*/ -#ifdef CONFIG_CWMP_TR069 -#define MIB_CWMP_ID 700 //The value of CWMP_ID is ON or OFF tr069 -#define MIB_CWMP_PROVISIONINGCODE CWMP_ID + 1 //069 -#define MIB_CWMP_ACS_URL CWMP_ID + 2 //069 -#define MIB_CWMP_ACS_USERNAME CWMP_ID + 3 //069 -#define MIB_CWMP_ACS_PASSWORD CWMP_ID + 4 //069 -#define MIB_CWMP_INFORM_ENABLE CWMP_ID + 5 //069 -#define MIB_CWMP_INFORM_INTERVAL CWMP_ID + 6 //069 -#define MIB_CWMP_INFORM_TIME CWMP_ID + 7 -#define MIB_CWMP_CONREQ_USERNAME CWMP_ID + 8 -#define MIB_CWMP_CONREQ_PASSWORD CWMP_ID + 9 -#define MIB_CWMP_ACS_UPGRADESMANAGED CWMP_ID + 10 //069 -//#define MIB_CWMP_LAN_CONFIGPASSWD CWMP_ID + 11 -//#define MIB_CWMP_SERIALNUMBER CWMP_ID + 12 //069 -//#define MIB_CWMP_DHCP_SERVERCONF CWMP_ID + 13 -//#define MIB_CWMP_LAN_IPIFENABLE CWMP_ID + 14 -//#define MIB_CWMP_LAN_ETHIFENABLE CWMP_ID + 15 -//#define MIB_CWMP_WLAN_BASICENCRY CWMP_ID + 16 -//#define MIB_CWMP_WLAN_WPAENCRY CWMP_ID + 17 -#define MIB_CWMP_DL_COMMANDKEY CWMP_ID + 18 -#define MIB_CWMP_DL_STARTTIME CWMP_ID + 19 -#define MIB_CWMP_DL_COMPLETETIME CWMP_ID + 20 -#define MIB_CWMP_DL_FAULTCODE CWMP_ID + 21 -#define MIB_CWMP_INFORM_EVENTCODE CWMP_ID + 22 -#define MIB_CWMP_RB_COMMANDKEY CWMP_ID + 23 -//#define MIB_CWMP_ACS_PARAMETERKEY CWMP_ID + 24 -#define MIB_CWMP_CERT_PASSWORD CWMP_ID + 25 -#define MIB_CWMP_FLAG CWMP_ID + 26 -#define MIB_CWMP_SI_COMMANDKEY CWMP_ID + 27 /*ScheduleInform's commandkey*/ - -#ifdef _PRMT_USERINTERFACE_ /*InternetGatewayDevice.UserInterface.*/ -#define MIB_UIF_PW_REQUIRED CWMP_ID + 28 /*PasswordRequired*/ -#define MIB_UIF_PW_USER_SEL CWMP_ID + 29 /*PasswordUserSelectable*/ -#define MIB_UIF_UPGRADE CWMP_ID + 30 /*UpgradeAvailable*/ -#define MIB_UIF_WARRANTYDATE CWMP_ID + 31 /*WarrantyDate*/ -#define MIB_UIF_AUTOUPDATESERVER CWMP_ID + 32 /*AutoUpdateServer*/ -#define MIB_UIF_USERUPDATESERVER CWMP_ID + 33 /*UserUpdateServer*/ -#endif /*_PRMT_USERINTERFACE_*/ - -#define MIB_CWMP_ACS_KICKURL CWMP_ID + 74 -#define MIB_CWMP_ACS_DOWNLOADURL CWMP_ID + 75 -#define MIB_CWMP_CONREQ_PORT CWMP_ID + 76 /*port for connection request*/ -#define MIB_CWMP_CONREQ_PATH CWMP_ID + 77 /*path for connection request*/ -#define MIB_CWMP_FLAG2 CWMP_ID + 78 - -//#ifdef _PRMT_TR143_ -#define MIB_TR143_UDPECHO_ENABLE CWMP_ID + 79 -#define MIB_TR143_UDPECHO_ITFTYPE CWMP_ID + 80 -#define MIB_TR143_UDPECHO_SRCIP CWMP_ID + 81 -#define MIB_TR143_UDPECHO_PORT CWMP_ID + 82 -#define MIB_TR143_UDPECHO_PLUS CWMP_ID + 83 -//#endif //_PRMT_TR143_ -#define MIB_CWMP_MIB_END CWMP_ID + 200 /* Reserve 200 mib for tr069*/ -#endif /*CONFIG_CWMP_TR069*/ - - - - - -#define MIB_TEST_DATA 10000 - -#define MIB_DHCPRSVDIP_IPADDR 1001 -#define MIB_DHCPRSVDIP_MACADDR 1002 -#define MIB_DHCPRSVDIP_HOSTNAME 1003 - -#define MIB_SCHEDULE_TEXT 1011 -#define MIB_SCHEDULE_ECO 1012 -#define MIB_SCHEDULE_FTIME 1013 -#define MIB_SCHEDULE_TTIME 1014 -#define MIB_SCHEDULE_DAY 1015 - -#define MIB_PORTFW_IPADDR 1021 -#define MIB_PORTFW_FROMPORT 1022 -#define MIB_PORTFW_TOPORT 1023 -#define MIB_PORTFW_PROTOTYPE 1024 -#define MIB_PORTFW_COMMENT 1025 - -#define MIB_IPFILTER_IPADDR 1031 -#define MIB_IPFILTER_PROTOTYPE 1032 -#define MIB_IPFILTER_COMMENT 1033 - -#define MIB_PORTFILTER_FROMPORT 1041 -#define MIB_PORTFILTER_TOPORT 1042 -#define MIB_PORTFILTER_PROTOTYPE 1043 -#define MIB_PORTFILTER_COMMENT 1044 - -#define MIB_MACFILTER_MACADDR 1051 -#define MIB_MACFILTER_COMMENT 1052 - -#define MIB_TRIGGERPORT_TRI_FROMPORT 1061 -#define MIB_TRIGGERPORT_TRI_TOPORT 1062 -#define MIB_TRIGGERPORT_TRI_PROTOTYPE 1063 -#define MIB_TRIGGERPORT_INC_FROMPORT 1064 -#define MIB_TRIGGERPORT_INC_TOPORT 1065 -#define MIB_TRIGGERPORT_INC_PROTOTYPE 1066 -#define MIB_TRIGGERPORT_COMMENT 1067 - -#define MIB_URLFILTER_URLADDR 1071 - -#define MIB_VLANCONFIG_ENTRY_ENABLED 1081 -#define MIB_VLANCONFIG_NETIFACE 1082 -#define MIB_VLANCONFIG_TAGGED 1083 -#define MIB_VLANCONFIG_UNTAGGED 1084 -#define MIB_VLANCONFIG_PRIORITY 1085 -#define MIB_VLANCONFIG_CFI 1086 -#define MIB_VLANCONFIG_GROUPID 1087 -#define MIB_VLANCONFIG_VLANID 1088 - -#define MIB_STATICROUTE_DSTADDR 1091 -#define MIB_STATICROUTE_NETMASK 1092 -#define MIB_STATICROUTE_GATEWAY 1093 -#define MIB_STATICROUTE_INTERFACE 1094 -#define MIB_STATICROUTE_METRIC 1095 - -#define MIB_IPSECTUNNEL_TUNNELID 1101 -#define MIB_IPSECTUNNEL_AUTHTYPE 1102 -#define MIB_IPSECTUNNEL_LCTYPE 1103 -#define MIB_IPSECTUNNEL_LC_IPADDR 1104 -#define MIB_IPSECTUNNEL_LC_MASKLEN 1105 -#define MIB_IPSECTUNNEL_RTTYPE 1106 -#define MIB_IPSECTUNNEL_RT_IPADDR 1107 -#define MIB_IPSECTUNNEL_RT_MASKLEN 1108 -#define MIB_IPSECTUNNEL_RT_GWADDR 1109 -#define MIB_IPSECTUNNEL_KEYMODE 1110 -#define MIB_IPSECTUNNEL_ESPAH 1111 -#define MIB_IPSECTUNNEL_ESPENCR 1112 -#define MIB_IPSECTUNNEL_ESPAUTH 1113 -#define MIB_IPSECTUNNEL_AHAUTH 1114 -#define MIB_IPSECTUNNEL_CONTYPE 1115 -#define MIB_IPSECTUNNEL_PSKEY 1116 -#define MIB_IPSECTUNNEL_RSAKEY 1117 -#define MIB_IPSECTUNNEL_SPI 1118 -#define MIB_IPSECTUNNEL_ENCRKEY 1119 -#define MIB_IPSECTUNNEL_AUTHKEY 1120 -#define MIB_IPSECTUNNEL_ENABLE 1121 -#define MIB_IPSECTUNNEL_CONNNAME 1122 -#define MIB_IPSECTUNNEL_LCIDTYPE 1123 -#define MIB_IPSECTUNNEL_RTIDTYPE 1124 -#define MIB_IPSECTUNNEL_LCID 1125 -#define MIB_IPSECTUNNEL_RTID 1126 -#define MIB_IPSECTUNNEL_IKELIFETIME 1127 -#define MIB_IPSECTUNNEL_IKEENCR 1128 -#define MIB_IPSECTUNNEL_IKEAUTH 1129 -#define MIB_IPSECTUNNEL_IKEKEYGROUP 1130 -#define MIB_IPSECTUNNEL_IPSECLIFETIME 1131 -#define MIB_IPSECTUNNEL_IPSECPFS 1132 - -#define MIB_CERTROOT_COMMENT 1151 - -#define MIB_CERTUSER_COMMENT 1161 -#define MIB_CERTROOT_PASS 1162 - -#define MIB_QOS_ENTRY_NAME 1171 -#define MIB_QOS_ENTRY_ENABLED 1172 -#define MIB_QOS_PRIORITY 1173 -#define MIB_QOS_PROTOCOL 1174 -#define MIB_QOS_LOCAL_IP_START 1175 -#define MIB_QOS_LOCAL_IP_END 1176 -#define MIB_QOS_LOCAL_PORT_START 1177 -#define MIB_QOS_LOCAL_PORT_END 1178 -#define MIB_QOS_REMOTE_IP_START 1179 -#define MIB_QOS_REMOTE_IP_END 1180 -#define MIB_QOS_REMOTE_PORT_START 1181 -#define MIB_QOS_REMOTE_PORT_END 1182 - -#define MIB_IPQOS_ENTRY_NAME 1191 -#define MIB_IPQOS_ENABLED 1192 -#define MIB_IPQOS_MAC 1193 -#define MIB_IPQOS_MODE 1194 -#define MIB_IPQOS_LOCAL_IP_START 1195 -#define MIB_IPQOS_LOCAL_IP_END 1196 -#define MIB_IPQOS_BANDWIDTH 1197 -#define MIB_IPQOS_BANDWIDTH_DOWNLINK 1198 - -#define MIB_MECH_ACL_MACADDR 1201 -#define MIB_MECH_ACL_COMMENT 1202 - -#define MIB_WLAN_ACL_ADDR_MACADDR 1211 -#define MIB_WLAN_ACL_ADDR_COMMENT 1212 - -#define MIB_WLAN_WDS_MACADDR 1221 -#define MIB_WLAN_WDS_FIXEDTXRATE 1222 -#define MIB_WLAN_WDS_COMMENT 1223 - - -//#ifdef CONFIG_RTL_FLASH_DUAL_IMAGE_ENABLE -#define MIB_DUALBANK_ENABLED 1300 -#define MIB_WLAN_PHY_BAND_SELECT 1301 -#define MIB_WLAN_MAC_PHY_MODE 1302 -#define MIB_WLAN_BAND2G5G_SELECT 1303 -//#endif - -//MIBs for 802.1x wlan client mode -#ifdef CONFIG_RTL_802_1X_CLIENT_SUPPORT -#define MIB_WLAN_EAP_TYPE 1311 -#define MIB_WLAN_EAP_INSIDE_TYPE 1312 -#define MIB_WLAN_EAP_USER_ID 1313 -#define MIB_WLAN_RS_USER_NAME 1314 -#define MIB_WLAN_RS_USER_PASSWD 1315 -#define MIB_WLAN_RS_USER_CERT_PASSWD 1316 -#define MIB_WLAN_RS_BAND_SEL 1317 -#endif - -/* USB3G */ -#define MIB_USB3G_USER 1400 -#define MIB_USB3G_PASS 1401 -#define MIB_USB3G_PIN 1402 -#define MIB_USB3G_APN 1403 -#define MIB_USB3G_DIALNUM 1404 -#define MIB_USB3G_CONN_TYPE 1405 -#define MIB_USB3G_IDLE_TIME 1406 -#define MIB_USB3G_MTU_SIZE 1407 - - -#ifdef CONFIG_CWMP_TR069 -/* define the len of the entities */ -#define CWMP_PROVISION_CODE_LEN 64 -#define CWMP_ACS_URL_LEN 256 -#define CWMP_ACS_USERNAME_LEN 256 -#define CWMP_ACS_PASSWD_LEN 256 -#define CWMP_CONREQ_USERNAME_LEN 256 -#define CWMP_CONREQ_PASSWD_LEN 256 -#define CWMP_LANCONF_PASSWD_LEN 64 -#define CWMP_SERIALNUMBER_LEN 64 -#define CWMP_COMMAND_KEY_LEN 32 -#define CWMP_CERT_PASSWD_LEN 64 -/* define the cwmp_flag */ -#define CWMP_FLAG_DEBUG_MSG 0x01 -#define CWMP_FLAG_CERT_AUTH 0x02 -#define CWMP_FLAG_SENDGETRPC 0x04 -#define CWMP_FLAG_SKIPMREBOOT 0x08 -#define CWMP_FLAG_DELAY 0x10 -#define CWMP_FLAG_AUTORUN 0x20 - -/* define the len of the entities */ -#define CWMP_PROVISION_CODE_LEN 32 //64 in spec -#define CWMP_ACS_URL_LEN 64 //256 in spec -#define CWMP_ACS_USERNAME_LEN 32 //256 in spec -#define CWMP_ACS_PASSWD_LEN 32 //256 in spec -#define CWMP_CONREQ_USERNAME_LEN 32 //256 in spec -#define CWMP_CONREQ_PASSWD_LEN 32 //256 in spec -#define CONN_REQ_PATH_LEN 32 //32 in spec -#define CWMP_KICK_URL 32 //64 in spec -#define CWMP_DOWNLOAD_URL 32 //64 in spec -//#define CWMP_LANCONF_PASSWD_LEN 64 -//#define CWMP_SERIALNUMBER_LEN 64 -#define CWMP_COMMAND_KEY_LEN 32 -#define CWMP_CERT_PASSWD_LEN 32 //64 in spec -#define IP_ADDR_LEN 4 -/* define the cwmp_flag */ -#define CWMP_FLAG_DEBUG_MSG 0x01 -#define CWMP_FLAG_CERT_AUTH 0x02 -#define CWMP_FLAG_SENDGETRPC 0x04 -#define CWMP_FLAG_SKIPMREBOOT 0x08 -#define CWMP_FLAG_DELAY 0x10 -#define CWMP_FLAG_AUTORUN 0x20 -#define CWMP_FLAG_CTINFORMEXT 0x40 -#define CWMP_FLAG_SELFREBOOT 0x80 -/*flag for CWMP_FLAG2 setting*/ -#define CWMP_FLAG2_DIS_CONREQ_AUTH 0x01 /*disable connection request authentication*/ -#define CWMP_FLAG2_DEFAULT_WANIP_IN_INFORM 0x02 /*bring the default wan ip in the inform*/ - -/*action type for applying new values*/ -#define CWMP_NONE 0 -#define CWMP_START 1 -#define CWMP_STOP 2 -#define CWMP_RESTART 3 - -/*EC_xxxxx event must consist with those defined in cwmp_rpc.h*/ -#define EC_X_CT_COM_ACCOUNT 0x10000 /*X_CT-COM_ACCOUNTCHANGE*/ - -#endif /*CONFIG_CWMP_TR069*/ - -#if defined(CONFIG_RTL_8196C) || defined(CONFIG_RTL_8198) -/*new add since new platform rtl8196c*/ -#define MIB_HW_TX_POWER_CCK_A 901 -#define MIB_HW_TX_POWER_CCK_B 902 -#define MIB_HW_TX_POWER_HT40_1S_A 903 -#define MIB_HW_TX_POWER_HT40_1S_B 904 -#define MIB_HW_TX_POWER_DIFF_HT40_2S 905 -#define MIB_HW_TX_POWER_DIFF_HT20 906 -#define MIB_HW_TX_POWER_DIFF_OFDM 907 -#define MIB_HW_11N_RESERVED9 908 -#define MIB_HW_11N_RESERVED10 909 -#define MIB_HW_TX_POWER_5G_HT40_1S_A 910 -#define MIB_HW_TX_POWER_5G_HT40_1S_B 911 -#define MIB_HW_TX_POWER_DIFF_5G_HT40_2S 912 -#define MIB_HW_TX_POWER_DIFF_5G_HT20 913 -#define MIB_HW_TX_POWER_DIFF_5G_OFDM 914 -/*new add end*/ -#endif - -#define MAX_L2TP_BUFF_LEN 50 - -#define MIB_PPP_SESSION_NUM 940 -#define MIB_PPP_SERVER_MAC 941 -#define MIB_L2TP_PAYLOAD 942 -#define MIB_L2TP_PAYLOAD_LENGTH 943 -#define MIB_L2TP_NS 944 -#define MIB_DHCP_LEASE_TIME 945 - - -// MIB value and constant -#ifdef CONFIG_IPV6 -#define IFNAMESIZE 32 -#define MAX_PREFIX_NUM 2 -#define RR_MAX_NUM 2 -#define NAMSIZE 32 -#define MAX_DNAME_SIZE 128 -#endif -#define MAX_SSID_LEN 33 -#define WEP64_KEY_LEN 5 -#define WEP128_KEY_LEN 13 -#define MAX_NAME_LEN 31 -#define COMMENT_LEN 21 -#define MAX_CCK_CHAN_NUM 14 -#define MAX_OFDM_CHAN_NUM 162 - -#define MAX_2G_CHANNEL_NUM_MIB 14 -#define MAX_5G_CHANNEL_NUM_MIB 196 - -#define MAX_PSK_LEN 64 -#define MAX_RS_PASS_LEN 65 -#define MAX_DOMAIN_LEN 51 -#define MAX_NAME_LEN_LONG 129 - -#define TX_RATE_1M 0x01 -#define TX_RATE_2M 0x02 -#define TX_RATE_5M 0x04 -#define TX_RATE_11M 0x08 - -#define TX_RATE_6M 0x10 -#define TX_RATE_9M 0x20 -#define TX_RATE_12M 0x40 -#define TX_RATE_18M 0x80 -#define TX_RATE_24M 0x100 -#define TX_RATE_36M 0x200 -#define TX_RATE_48M 0x400 -#define TX_RATE_54M 0x800 - -#define MAX_WLAN_AC_NUM 20 - -//#if defined(CONFIG_RTK_MESH) && defined(_MESH_ACL_ENABLE_) Keith remove -#define MAX_MESH_ACL_NUM MAX_WLAN_AC_NUM -//#endif Keith remove - -#define MAX_CERTROOT_NUM 5 -#define MAX_CERTUSER_NUM 5 -#ifdef HOME_GATEWAY -#define MAX_FILTER_NUM 20 -#define MAX_URLFILTER_NUM 8 -#ifdef VPN_SUPPORT -#define MAX_TUNNEL_NUM 10 -#define MAX_RSA_FILE_LEN 2048 -#define MAX_RSA_KEY_LEN 380 -#define MAX_ENCRKEY_LEN 49 -#define MAX_AUTHKEY_LEN 41 -#define MAX_SPI_LEN 5 -#endif -#define MAX_QOS_RULE_NUM 10 -#endif -#define MAX_ROUTE_NUM 10 -#define MAX_DHCP_RSVD_IP_NUM 20 -#define MAXFNAME 60 - -//#ifdef CONFIG_RTL8196B_GW_8M -//#define MAX_WDS_NUM 4 -//#else -#define MAX_WDS_NUM 8 -//#endif - -#ifdef WLAN_EASY_CONFIG -#define MAX_ACF_KEY_LEN 64 -#define MAX_ACF_DIGEST_LEN 32 -#endif - -//#ifdef SNMP_SUPPORT Keith remove -#define MAX_SNMP_COMMUNITY_LEN 64 -//#endif Keith remove - -#ifdef WIFI_SIMPLE_CONFIG -#define PIN_LEN 8 -#endif - -#define IFNAMSIZE 16 -#if defined(CONFIG_RTL_8198_AP_ROOT) && defined(GMII_ENABLED) -#define MAX_IFACE_VLAN_CONFIG (7+5*2) /* eth0~eth6, 2*(wlanX,wlanX-va0~wlanX-va3)no wds and vxd*/ -#else -#define MAX_IFACE_VLAN_CONFIG (6+5*2) /* eth0~eth5, 2*(wlanX,wlanX-va0~wlanX-va3)no wds and vxd*/ -#endif - -#if defined(UNIVERSAL_REPEATER) -#define CONFIG_REPEATER_WPS_SUPPORT -#define CONFIG_ONLY_SUPPORT_CLIENT_REPEATER_WPS -#endif - -#define NEW_SCHEDULE_SUPPORT -#if defined(NEW_SCHEDULE_SUPPORT) -#define MAX_SCHEDULE_NUM 10 -#else -/*Brad add for schedule*/ -#define MAX_SCHEDULE_NUM 1 -#endif - -/* # keith: add l2tp support. 20080515 */ -#define MAX_PPTP_HOST_NAME_LEN 64 - -#ifdef __mips__ -#define FLASH_DEVICE_NAME ("/dev/mtdblock0") -#define FLASH_DEVICE_NAME1 ("/dev/mtdblock1") -#else -#define FLASH_DEVICE_NAME ("setting.bin") -#endif - -#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE -#define HW_SETTING_OFFSET CONFIG_RTL_HW_SETTING_OFFSET -#define DEFAULT_SETTING_OFFSET CONFIG_RTL_DEFAULT_SETTING_OFFSET -#define CURRENT_SETTING_OFFSET CONFIG_RTL_CURRENT_SETTING_OFFSET -#define WEB_PAGE_OFFSET CONFIG_RTL_WEB_PAGES_OFFSET -#define CODE_IMAGE_OFFSET CONFIG_RTL_CODE_IMAGE_OFFSET -#define ROOT_IMAGE_OFFSET CONFIG_RTL_ROOT_IMAGE_OFFSET -#else -#define HW_SETTING_OFFSET 0x6000 -#define DEFAULT_SETTING_OFFSET 0x8000 -#define CURRENT_SETTING_OFFSET 0xc000 -#define WEB_PAGE_OFFSET 0x10000 -#define CODE_IMAGE_OFFSET 0x20000 -#define ROOT_IMAGE_OFFSET 0xE0000 -#endif - -#ifdef HOME_GATEWAY - #define CERT_PAGE_OFFSET 0x3f0000 -#else - #define CERT_PAGE_OFFSET 0x1f0000 -#endif - -#ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE -#define HW_SETTING_SECTOR_LEN (CONFIG_RTL_DEFAULT_SETTING_OFFSET-CONFIG_RTL_HW_SETTING_OFFSET) -#define DEFAULT_SETTING_SECTOR_LEN (CONFIG_RTL_CURRENT_SETTING_OFFSET-CONFIG_RTL_DEFAULT_SETTING_OFFSET) -#define CURRENT_SETTING_SECTOR_LEN (CONFIG_RTL_WEB_PAGES_OFFSET-CONFIG_RTL_CURRENT_SETTING_OFFSET) -#else -#define HW_SETTING_SECTOR_LEN (0x8000-0x6000) -#define DEFAULT_SETTING_SECTOR_LEN (0xc000-0x8000) -#define CURRENT_SETTING_SECTOR_LEN (0x10000-0xc000) -#endif +#ifndef __APMIB_H +#define __APMIB_H #ifndef WIN32 -#define __PACK__ __attribute__ ((packed)) +#define __PACK__ __attribute__ ((packed)) #else #define __PACK__ #endif - -/* Config/fw image file header */ - -typedef enum { HW_SETTING=1, DEFAULT_SETTING=2, CURRENT_SETTING=4 } CONFIG_DATA_T; +#define BOOT_HEADER ((char *)"boot") #if defined(CONFIG_RTL_8196B) -// update tag -#define HW_SETTING_HEADER_TAG ((char *)"h6") -//Brad add for distinguish ap(da:default setting for ap) or gateway(dg: default setting for gateway) platform -#if (defined(HOME_GATEWAY) && defined(VPN_SUPPORT)) -#define DEFAULT_SETTING_HEADER_TAG ((char *)"6V") -#elif (defined(HOME_GATEWAY)) -#define DEFAULT_SETTING_HEADER_TAG ((char *)"6G") -#else -#define DEFAULT_SETTING_HEADER_TAG ((char *)"6A") -#endif -//Brad add for distinguish ap(ca:current setting for ap) or gateway(cg: current setting for gateway) platform -#if (defined(HOME_GATEWAY) && defined(VPN_SUPPORT)) -#define CURRENT_SETTING_HEADER_TAG ((char *)"6v") -#elif (defined(HOME_GATEWAY)) -#define CURRENT_SETTING_HEADER_TAG ((char *)"6g") -#else -#define CURRENT_SETTING_HEADER_TAG ((char *)"6a") -#endif -// force tag -#define HW_SETTING_HEADER_FORCE_TAG ((char *)"Hf") -#define DEFAULT_SETTING_HEADER_FORCE_TAG ((char *)"Df") -#define CURRENT_SETTING_HEADER_FORCE_TAG ((char *)"Cf") -// upgrade -#define HW_SETTING_HEADER_UPGRADE_TAG ((char *)"Hu") -#define DEFAULT_SETTING_HEADER_UPGRADE_TAG ((char *)"Du") -#define CURRENT_SETTING_HEADER_UPGRADE_TAG ((char *)"Cu") -#elif defined(CONFIG_RTL_8196C) || defined(CONFIG_RTL_8198) - -// update tag -#define HW_SETTING_HEADER_TAG ((char *)"H6") -#if (defined(HOME_GATEWAY) && defined(VPN_SUPPORT)) -#define DEFAULT_SETTING_HEADER_TAG ((char *)"6V") -#elif (defined(HOME_GATEWAY)) -#define DEFAULT_SETTING_HEADER_TAG ((char *)"6G") -#else -#define DEFAULT_SETTING_HEADER_TAG ((char *)"6A") -#endif -#if (defined(HOME_GATEWAY) && defined(VPN_SUPPORT)) -#define CURRENT_SETTING_HEADER_TAG ((char *)"6v") -#elif (defined(HOME_GATEWAY)) -#define CURRENT_SETTING_HEADER_TAG ((char *)"6g") -#else -#define CURRENT_SETTING_HEADER_TAG ((char *)"6a") -#endif -// force tag -#define HW_SETTING_HEADER_FORCE_TAG ((char *)"Hf") -#define DEFAULT_SETTING_HEADER_FORCE_TAG ((char *)"Df") -#define CURRENT_SETTING_HEADER_FORCE_TAG ((char *)"Cf") -// upgrade -#define HW_SETTING_HEADER_UPGRADE_TAG ((char *)"Hu") -#define DEFAULT_SETTING_HEADER_UPGRADE_TAG ((char *)"Du") -#define CURRENT_SETTING_HEADER_UPGRADE_TAG ((char *)"Cu") -#else -// update tag -#define HW_SETTING_HEADER_TAG ((char *)"hs") -#if (defined(HOME_GATEWAY) && defined(VPN_SUPPORT)) -#define DEFAULT_SETTING_HEADER_TAG ((char *)"dv") -#elif (defined(HOME_GATEWAY)) -#define DEFAULT_SETTING_HEADER_TAG ((char *)"dg") -#else -#define DEFAULT_SETTING_HEADER_TAG ((char *)"da") -#endif -#if (defined(HOME_GATEWAY) && defined(VPN_SUPPORT)) -#define CURRENT_SETTING_HEADER_TAG ((char *)"cv") -#elif (defined(HOME_GATEWAY)) -#define CURRENT_SETTING_HEADER_TAG ((char *)"cg") +#define ROOT_HEADER ((char *)"r6br") +#elif defined(CONFIG_RTL_8196C) || defined(CONFIG_RTL_8198) || defined(CONFIG_RTL_819XD) || defined(CONFIG_RTL_8196E) +#define ROOT_HEADER ((char *)"r6cr") #else -#define CURRENT_SETTING_HEADER_TAG ((char *)"ca") -#endif -// force tag -#define HW_SETTING_HEADER_FORCE_TAG ((char *)"hf") -#define DEFAULT_SETTING_HEADER_FORCE_TAG ((char *)"df") -#define CURRENT_SETTING_HEADER_FORCE_TAG ((char *)"cf") -// upgrade -#define HW_SETTING_HEADER_UPGRADE_TAG ((char *)"hu") -#define DEFAULT_SETTING_HEADER_UPGRADE_TAG ((char *)"du") -#define CURRENT_SETTING_HEADER_UPGRADE_TAG ((char *)"cu") -#endif //#if defined(CONFIG_RTL_8196B) - - -#if 0//def CONFIG_RTL8196B_GW_8M -#undef DEFAULT_SETTING_HEADER_TAG -#define DEFAULT_SETTING_HEADER_TAG ((char *)"61") - -#undef CURRENT_SETTING_HEADER_TAG -#define CURRENT_SETTING_HEADER_TAG ((char *)"62") -#endif - - -#define TAG_LEN 2 - -#if defined(CONFIG_RTL_8196B) - -#define HW_SETTING_VER 1 // hw setting version -#define DEFAULT_SETTING_VER 2 // default setting version -#define CURRENT_SETTING_VER DEFAULT_SETTING_VER // current setting version - -#elif defined(CONFIG_RTL_8196C) || defined(CONFIG_RTL_8198) -#define HW_SETTING_VER 1 // hw setting version -#define DEFAULT_SETTING_VER 1 // default setting version -#define CURRENT_SETTING_VER DEFAULT_SETTING_VER // current setting version -#else - -#define HW_SETTING_VER 3 // hw setting version -#define DEFAULT_SETTING_VER 4 // default setting version -#define CURRENT_SETTING_VER DEFAULT_SETTING_VER // current setting version - -#endif - -#if defined(CONFIG_RTL_8196B) -#define FW_HEADER_WITH_ROOT ((char *)"cr6b") -#define FW_HEADER ((char *)"cs6b") -#elif defined(CONFIG_RTL_8196C) || defined(CONFIG_RTL_8198) -#define FW_HEADER_WITH_ROOT ((char *)"cr6c") -#define FW_HEADER ((char *)"cs6c") -#else -#define FW_HEADER_WITH_ROOT ((char *)"csro") -#define FW_HEADER ((char *)"csys") +#define ROOT_HEADER ((char *)"root") #endif //#if defined(CONFIG_RTL_8196B) #if defined(CONFIG_RTL_8196B) #if (defined(HOME_GATEWAY) && defined(VPN_SUPPORT)) -#define WEB_HEADER ((char *)"w6bv") +#define WEB_HEADER ((char *)"w6bv") #elif (defined(HOME_GATEWAY)) -#define WEB_HEADER ((char *)"w6bg") +#define WEB_HEADER ((char *)"w6bg") #else -#define WEB_HEADER ((char *)"w6ba") +#define WEB_HEADER ((char *)"w6ba") #endif -#elif defined(CONFIG_RTL_8196C) || defined(CONFIG_RTL_8198) +#elif defined(CONFIG_RTL_8196C) || defined(CONFIG_RTL_8198) || defined(CONFIG_RTL_819XD) || defined(CONFIG_RTL_8196E) #if (defined(HOME_GATEWAY) && defined(VPN_SUPPORT)) -#define WEB_HEADER ((char *)"w6cv") +#define WEB_HEADER ((char *)"w6cv") #elif (defined(HOME_GATEWAY)) -#define WEB_HEADER ((char *)"w6cg") +#define WEB_HEADER ((char *)"w6cg") #else -#define WEB_HEADER ((char *)"w6ca") +#define WEB_HEADER ((char *)"w6ca") #endif #else #if (defined(HOME_GATEWAY) && defined(VPN_SUPPORT)) -#define WEB_HEADER ((char *)"webv") +#define WEB_HEADER ((char *)"webv") #elif (defined(HOME_GATEWAY)) -#define WEB_HEADER ((char *)"webg") +#define WEB_HEADER ((char *)"webg") #else -#define WEB_HEADER ((char *)"weba") +#define WEB_HEADER ((char *)"weba") #endif #endif //#if defined(CONFIG_RTL_8196B) #if defined(CONFIG_RTL_8196B) -#define ROOT_HEADER ((char *)"r6br") -#elif defined(CONFIG_RTL_8196C) || defined(CONFIG_RTL_8198) -#define ROOT_HEADER ((char *)"r6cr") -#else -#define ROOT_HEADER ((char *)"root") +#define FW_HEADER_WITH_ROOT ((char *)"cr6b") +#define FW_HEADER ((char *)"cs6b") +#elif defined(CONFIG_RTL_8196C) || defined(CONFIG_RTL_8198) || defined(CONFIG_RTL_819XD) || defined(CONFIG_RTL_8196E) +#define FW_HEADER_WITH_ROOT ((char *)"cr6c") +#define FW_HEADER ((char *)"cs6c") +#else +#define FW_HEADER_WITH_ROOT ((char *)"csro") +#define FW_HEADER ((char *)"csys") #endif //#if defined(CONFIG_RTL_8196B) -#define CERT_HEADER ((char *)"cert") -#define BOOT_HEADER ((char *)"boot") -#define ALL_HEADER ((char *)"allp") -#define SIGNATURE_LEN 4 - -/* wlan driver ioctl id */ -#define SIOCGIWRTLSTAINFO 0x8B30 // get station table information -#define SIOCGIWRTLSTANUM 0x8B31 // get the number of stations in table -#define SIOCGIWRTLSCANREQ 0x8B33 // scan request -#define SIOCGIWRTLGETBSSDB 0x8B34 // get bss data base -#define SIOCGIWRTLJOINREQ 0x8B35 // join request -#define SIOCGIWRTLJOINREQSTATUS 0x8B36 // get status of join request -#define SIOCGIWRTLGETBSSINFO 0x8B37 // get currnet bss info -#define SIOCGIWRTLGETWDSINFO 0x8B38 -#define SIOCGMISCDATA 0x8B48 // get misc data - -//=========add for MESH========= -//#ifdef CONFIG_RTK_MESH Keith remove -// by GANTOE for site survey 2008/12/26 -#define SIOCJOINMESH 0x8B94 -#define SIOCCHECKMESHLINK 0x8B95 -#define RTL8190_IOCTL_GET_MIB 0x89f2 -//#endif Keith remove -//=========add for MESH========= - -#define MAC_ADDR_LEN 6 -#define MAX_STA_NUM 64 // max support sta number +#define ALL_HEADER ((char *)"allp") -/* flag of sta info */ -#define STA_INFO_FLAG_AUTH_OPEN 0x01 -#define STA_INFO_FLAG_AUTH_WEP 0x02 -#define STA_INFO_FLAG_ASOC 0x04 -#define STA_INFO_FLAG_ASLEEP 0x08 - -// bit value for hw board id -#if 0 -// Old code and no longer used -#define ETH_PHY_TYPE 1 -#define BOOT_PORT_SELECT 2 -#define USE_ETH0_WAN 4 -#endif -#define WLAN_RF_2T2R 1 - -#ifdef WIFI_SIMPLE_CONFIG -enum { WSC_AUTH_OPEN=1, WSC_AUTH_WPAPSK=2, WSC_AUTH_SHARED=4, WSC_AUTH_WPA=8, WSC_AUTH_WPA2=0x10, WSC_AUTH_WPA2PSK=0x20, WSC_AUTH_WPA2PSKMIXED=0x22 }; -enum { WSC_ENCRYPT_NONE=1, WSC_ENCRYPT_WEP=2, WSC_ENCRYPT_TKIP=4, WSC_ENCRYPT_AES=8, WSC_ENCRYPT_TKIPAES=12 }; -enum { CONFIG_METHOD_ETH=0x2, CONFIG_METHOD_PIN=0x4, CONFIG_METHOD_PBC=0x80 }; -enum { CONFIG_BY_INTERNAL_REGISTRAR=1, CONFIG_BY_EXTERNAL_REGISTRAR=2}; -#endif -typedef enum { ENCRYPT_DISABLED=0, ENCRYPT_WEP=1, ENCRYPT_WPA=2, ENCRYPT_WPA2=4, ENCRYPT_WPA2_MIXED=6 ,ENCRYPT_WAPI=7} ENCRYPT_T; -typedef enum { WDS_ENCRYPT_DISABLED=0, WDS_ENCRYPT_WEP64=1, WDS_ENCRYPT_WEP128=2, WDS_ENCRYPT_TKIP=3, WDS_ENCRYPT_AES=4} WDS_ENCRYPT_T; -typedef enum { SUPP_NONWPA_NONE=0,SUPP_NONWPA_WEP=1,SUPP_NONWPA_1X=2} SUPP_NONWAP_T; -typedef enum { WPA_AUTH_AUTO=1, WPA_AUTH_PSK=2 } WPA_AUTH_T; -typedef enum { WAPI_AUTH_AUTO=1, WAPI_AUTH_PSK=2 } WAPI_AUTH_T; -typedef enum { WPA_CIPHER_TKIP=1, WPA_CIPHER_AES=2, WPA_CIPHER_MIXED=3 } WPA_CIPHER_T; -typedef enum { WEP_DISABLED=0, WEP64=1, WEP128=2 } WEP_T; -typedef enum { KEY_ASCII=0, KEY_HEX } KEY_TYPE_T; -typedef enum { LONG_PREAMBLE=0, SHORT_PREAMBLE=1 } PREAMBLE_T; -typedef enum { DHCP_DISABLED=0, DHCP_CLIENT=1, DHCP_SERVER=2, PPPOE=3, PPTP=4, L2TP=6, DHCP_AUTO=15 , USB3G=16 } DHCP_T; /* # keith: add l2tp support. 20080515 */ -typedef enum { DHCP_LAN_NONE=0, DHCP_LAN_CLIENT=1, DHCP_LAN_SERVER=2, DHCP_LAN_RELAY=3 } DHCP_TYPE_T; //keith add. LAN SIDE DHCP TYPE -typedef enum { GATEWAY_MODE=0, BRIDGE_MODE=1, WISP_MODE=2 } OPMODE_T; -typedef enum { DISABLE_MODE=0, RIP1_MODE=1, RIP2_MODE=2 } RIP_OPMODE_T; -typedef enum { FCC=1, IC, ETSI, SPAIN, FRANCE, MKK } REG_DOMAIN_T; -typedef enum { AUTH_OPEN=0, AUTH_SHARED, AUTH_BOTH } AUTH_TYPE_T; -typedef enum { DNS_AUTO=0, DNS_MANUAL } DNS_TYPE_T; -typedef enum { CONTINUOUS=0, CONNECT_ON_DEMAND, MANUAL } PPP_CONNECT_TYPE_T; -typedef enum { RF_INTERSIL=1, RF_RFMD=2, RF_PHILIP=3, RF_MAXIM=4, RF_GCT=5, - RF_MAXIM_AG=6, RF_ZEBRA=7, RF_8255=8 } RF_TYPE_T; -typedef enum { LED_TX_RX=0, LED_LINK_TXRX=1, LED_LINKTXRX=2 } LED_TYPE_T; - -//=========add for MESH========= -#ifdef CONFIG_RTK_MESH -typedef enum { RANN=0, PREQ=1 } TREEMECH_T; -#ifdef CONFIG_NEW_MESH_UI -typedef enum { AP_MODE=0, CLIENT_MODE=1, WDS_MODE=2, AP_WDS_MODE=3, AP_MESH_MODE=4, MESH_MODE=5} WLAN_MODE_T; -#else -typedef enum { AP_MODE=0, CLIENT_MODE=1, WDS_MODE=2, AP_WDS_MODE=3, AP_MPP_MODE=4, MPP_MODE=5, MAP_MODE=6, MP_MODE=7 } WLAN_MODE_T; -#endif -#else -typedef enum { AP_MODE=0, CLIENT_MODE=1, WDS_MODE=2, AP_WDS_MODE=3 } WLAN_MODE_T; -#endif // CONFIG_RTK_MESH -//=========add for MESH========= - -typedef enum { INFRASTRUCTURE=0, ADHOC=1 } NETWORK_TYPE_T; -typedef enum { BAND_11B=1, BAND_11G=2, BAND_11BG=3, BAND_11A=4, BAND_11N=8, BAND_5G_11AN=12 } BAND_TYPE_T; -typedef enum { DISABLED=0, A_MPDU=1, A_MSDU=2, A_MIXED=3} AGGREGATION_MODE_T; // GANTOE & epopen: DISABLED=0 original is DISABLE=0, Because conflict with ../../auth/include/1x_common.h in AP/net-snmp-5.x.x -typedef enum { PHYBAND_OFF=0, PHYBAND_2G=1, PHYBAND_5G=2 } PHYBAND_TYPE_T; -typedef enum { SMACSPHY=0, DMACSPHY=1, DMACDPHY=2 } MACPHYMODE_TYPE_T; -typedef enum { BANDMODE2G=0, BANDMODE5G=1, BANDMODEBOTH=2, BANDMODESINGLE=3 } WLANBAND2G5GMODE_TYPE_T; - -#ifdef HOME_GATEWAY -#ifdef VPN_SUPPORT -typedef enum { IKE_MODE=0, MANUAL_MODE=1} KEY_MODE_T; -typedef enum { SINGLE_ADDR=0, SUBNET_ADDR=1, ANY_ADDR=2, NATT_ADDR=3} ADDRESS_MODE_T; -typedef enum { INITIATOR=0, RESPONDER=1} CONN_TYPE_T; -typedef enum { MD5_ALGO=0, AUTH_ALGO=1} AUTH_MODE_T; -typedef enum { ESP_PROTO=0, AH_PROTO=1} IPSEC_PROTO_T; -typedef enum { TRI_DES_ALGO=0, AES_ALGO=1, NONE_ALGO=2} ENCR_MODE_T; -// DH1=768 bits, DH2=1024 bits, DH5= 1536 -typedef enum { DH1_GRP=0, DH2_GRP=1, DH5_GRP=2} KEY_GROUP_T; -#endif // VPN_SUPPORT -typedef enum { PROTO_BOTH=3, PROTO_TCP=1, PROTO_UDP=2 } PROTO_TYPE_T; -#endif // HOME_GATEWAY - -#ifdef WLAN_EASY_CONFIG -enum { MODE_BUTTON=1, MODE_QUESTION=2 }; -enum { - ACF_ALGORITHM_WEP64 = 0x01, - ACF_ALGORITHM_WEP128 = 0x02, - ACF_ALGORITHM_WPA_TKIP = 0x04, - ACF_ALGORITHM_WPA_AES = 0x08, - ACF_ALGORITHM_WPA2_TKIP = 0x10, - ACF_ALGORITHM_WPA2_AES = 0x20, -}; -enum { ROLE_SERVER=1, ROLE_CLIENT=2, ROLE_ADHOC=4}; -#endif // WLAN_EASY_CONFIG - -enum {TURBO_AUTO=0, TURBO_ON=1, TURBO_OFF=2}; - -#ifdef CONFIG_RTL_802_1X_CLIENT_SUPPORT -typedef enum { EAP_MD5=0, EAP_TLS=1, EAP_PEAP=2 } EAP_TYPE_T; -typedef enum { INSIDE_MSCHAPV2=0 } INSIDE_TYPE_T; -#define MAX_EAP_USER_ID_LEN 64 -#define MAX_RS_USER_NAME_LEN 64 -#define MAX_RS_USER_PASS_LEN 64 -#define MAX_RS_USER_CERT_PASS_LEN 64 -#define RS_USER_CERT_5G "/var/1x/client_5g.pem" -#define RS_ROOT_CERT_5G "/var/1x/ca_5g.pem" -#define RS_USER_CERT_2G "/var/1x/client_2g.pem" -#define RS_ROOT_CERT_2G "/var/1x/ca_2g.pem" -#define RS_USER_CERT_TMP "/var/1x/client_tmp.pem" -#define RS_ROOT_CERT_TMP "/var/1x/ca_tmp.pem" -#define CERT_SIZE 0x8000 //32KB, should be sync with users/auth/src/rwCertSrc/rsCertCommon.h -#endif +#define HW_SETTING_OFFSET 0x6000 +#define DEFAULT_SETTING_OFFSET 0x8000 +#define CURRENT_SETTING_OFFSET 0xc000 #define DWORD_SWAP(v) ( (((v&0xff)<<24)&0xff000000) | ((((v>>8)&0xff)<<16)&0xff0000) | \ - ((((v>>16)&0xff)<<8)&0xff00) | (((v>>24)&0xff)&0xff) ) -#define WORD_SWAP(v) ((unsigned short)(((v>>8)&0xff) | ((v<<8)&0xff00))) - -/* scramble saved configuration data */ -#define ENCODE_DATA(data,len) { \ - int i; \ - for (i=0; i<len; i++) \ - data[i] = ~ ( data[i] + 0x38); \ -} - -#define DECODE_DATA(data,len) { \ - int i; \ - for (i=0; i<len; i++) \ - data[i] = ~data[i] - 0x38; \ -} - -/* Do checksum and verification for configuration data */ -#ifndef WIN32 -static inline unsigned char CHECKSUM(unsigned char *data, int len) -#else -__inline unsigned char CHECKSUM(unsigned char *data, int len) -#endif -{ - int i; - unsigned char sum=0; - - for (i=0; i<len; i++) - sum += data[i]; - - sum = ~sum + 1; - return sum; -} -#ifndef WIN32 -static inline int CHECKSUM_OK(unsigned char *data, int len) -#else -__inline int CHECKSUM_OK(unsigned char *data, int len) -#endif -{ - int i; - unsigned char sum=0; - - for (i=0; i<len; i++) - sum += data[i]; - - if (sum == 0) - return 1; - else - return 0; -} - -/* WLAN sta info structure */ -typedef struct wlan_sta_info { - unsigned short aid; - unsigned char addr[6]; - unsigned long tx_packets; - unsigned long rx_packets; - unsigned long expired_time; // 10 msec unit - unsigned short flag; - unsigned char txOperaRates; - unsigned char rssi; - unsigned long link_time; // 1 sec unit - unsigned long tx_fail; - unsigned long tx_bytes; - unsigned long rx_bytes; - unsigned char network; - unsigned char ht_info; // bit0: 0=20M mode, 1=40M mode; bit1: 0=longGI, 1=shortGI - unsigned char resv[6]; -} WLAN_STA_INFO_T, *WLAN_STA_INFO_Tp; - -typedef struct wlan_rate{ -unsigned int id; -unsigned char rate[20]; -}WLAN_RATE_T, *WLAN_RATE_Tp; -typedef enum { - MCS0=0x80, - MCS1=0x81, - MCS2=0x82, - MCS3=0x83, - MCS4=0x84, - MCS5=0x85, - MCS6=0x86, - MCS7=0x87, - MCS8=0x88, - MCS9=0x89, - MCS10=0x8a, - MCS11=0x8b, - MCS12=0x8c, - MCS13=0x8d, - MCS14=0x8e, - MCS15=0x8f - } RATE_11N_T; - -#ifdef WIN32 -#pragma pack(1) -#endif - - -//zj: eco featrue -#define ECO_LEDDIM_MASK 0x08 -#define ECO_TIMER_MASK 0x04 -#define ECO_EVERYDAY_MASK 0x02 -#define ECO_24HOURS_MASK 0x01 - -#define ECO_DAY_MASK 0x0000007F -#define ECO_SUNDAY_MASK 0x00000001 -#define ECO_MONDAY_MASK 0x00000002 -#define ECO_TUESDAY_MASK 0x00000004 -#define ECO_WEDNESDAY_MASK 0x00000008 -#define ECO_THURSDAY_MASK 0x00000010 -#define ECO_FRIDAY_MASK 0x00000020 -#define ECO_SATURDAY_MASK 0x00000040 - -#define SCHEDULE_NAME_LEN 20 -typedef struct schedule_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_SCHEDULE_IMPORT -#include "mibdef.h" -#undef MIB_SCHEDULE_IMPORT - -#undef MIBDEF -}__PACK__ SCHEDULE_T, *SCHEDULE_Tp; - - - -typedef struct macfilter_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_MACFILTER_IMPORT -#include "mibdef.h" -#undef MIB_MACFILTER_IMPORT - -#undef MIBDEF -}__PACK__ MACFILTER_T, *MACFILTER_Tp; - -#ifdef HOME_GATEWAY -typedef struct urlfilter_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_URLFILTER_IMPORT -#include "mibdef.h" -#undef MIB_URLFILTER_IMPORT - -#undef MIBDEF -}__PACK__ URLFILTER_T, *URLFILTER_Tp; + ((((v>>16)&0xff)<<8)&0xff00) | (((v>>24)&0xff)&0xff) ) -typedef struct portfw_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_PORTFW_IMPORT -#include "mibdef.h" -#undef MIB_PORTFW_IMPORT - -#undef MIBDEF -}__PACK__ PORTFW_T, *PORTFW_Tp; - -typedef struct ipfilter_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_IPFILTER_IMPORT -#include "mibdef.h" -#undef MIB_IPFILTER_IMPORT - -#undef MIBDEF -}__PACK__ IPFILTER_T, *IPFILTER_Tp; - -typedef struct portfilter_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_PORTFILTER_IMPORT -#include "mibdef.h" -#undef MIB_PORTFILTER_IMPORT - -#undef MIBDEF -}__PACK__ PORTFILTER_T, *PORTFILTER_Tp; - -typedef struct triggerport_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_TRIGGERPORT_IMPORT -#include "mibdef.h" -#undef MIB_TRIGGERPORT_IMPORT - -#undef MIBDEF -}__PACK__ TRIGGERPORT_T, *TRIGGERPORT_Tp; - -#ifdef GW_QOS_ENGINE -#define MAX_QOS_NAME_LEN 15 -typedef struct qos_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_QOS_IMPORT -#include "mibdef.h" -#undef MIB_QOS_IMPORT - -#undef MIBDEF -}__PACK__ QOS_T, *QOS_Tp; -#endif - -#ifdef QOS_BY_BANDWIDTH -#define QOS_RESTRICT_MIN 0x01 -#define QOS_RESTRICT_MAX 0x02 -#define QOS_RESTRICT_IP 0x04 -#define QOS_RESTRICT_MAC 0x08 -#define MAX_QOS_NAME_LEN 15 - -typedef struct qos_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_IPQOS_IMPORT -#include "mibdef.h" -#undef MIB_IPQOS_IMPORT - -#undef MIBDEF -}__PACK__ IPQOS_T, *IPQOS_Tp; -#endif - -#ifdef VPN_SUPPORT -typedef struct ipsectunnel_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_IPSECTUNNEL_IMPORT -#include "mibdef.h" -#undef MIB_IPSECTUNNEL_IMPORT - -#undef MIBDEF -}__PACK__ IPSECTUNNEL_T, *IPSECTUNNEL_Tp; -#endif // VPN_SUPPORT - -#ifdef CONFIG_IPV6 -#define uint16 unsigned short -#define uint8 unsigned char -#define uint32 unsigned int -/*radvd*/ -struct AdvPrefix { - uint16 Prefix[8]; - uint8 PrefixLen; - uint8 AdvOnLinkFlag; - uint8 AdvAutonomousFlag; - uint32 AdvValidLifetime; - uint32 AdvPreferredLifetime; - - /* Mobile IPv6 extensions */ - uint8 AdvRouterAddr; - - /* 6to4 extensions */ - char if6to4[IFNAMESIZE]; - uint8 enabled; -}__PACK__; - -struct Interface { - char Name[IFNAMESIZE]; /* interface name */ - uint32 MaxRtrAdvInterval; - uint32 MinRtrAdvInterval; - uint32 MinDelayBetweenRAs; - uint8 AdvManagedFlag; - uint8 AdvOtherConfigFlag; - uint32 AdvLinkMTU; - uint32 AdvReachableTime; - uint32 AdvRetransTimer; - uint8 AdvCurHopLimit; - uint16 AdvDefaultLifetime; - char AdvDefaultPreference[IFNAMESIZE]; - uint8 AdvSourceLLAddress; - uint8 UnicastOnly; - struct AdvPrefix prefix[MAX_PREFIX_NUM]; -}__PACK__; - -typedef struct radvdCfgParam_s -{ - uint8 enabled; - /*support eth1 only*/ - struct Interface interface; -}__PACK__ radvdCfgParam_t, *radvdCfgParam_Tp; - - -/*dnsv6*/ -struct rrResource -{ - char domainName[MAX_DNAME_SIZE]; - uint16 address[8]; -}__PACK__; - -typedef struct dnsv6CfgParam_s -{ - uint8 enabled; - /*default name myrouter*/ - char routerName[NAMSIZE]; - struct rrResource rr[RR_MAX_NUM]; -}__PACK__ dnsv6CfgParam_t, *dnsv6CfgParam_Tp; - -/*dhcp6*/ -typedef struct dhcp6sCfgParam_s -{ - uint8 enabled; - char DNSaddr6[48]; - char addr6PoolS[48]; - char addr6PoolE[48]; - /*default name interface*/ - char interfaceNameds[NAMSIZE]; - -}__PACK__ dhcp6sCfgParam_t, *dhcp6sCfgParam_Tp; - -/*IPv6 Addr*/ -typedef struct addrIPv6CfgParam_s -{ - int enabled; /* 0:off 1:on */ - int prefix_len[2]; - uint16 addrIPv6[2][8]; -}__PACK__ addrIPv6CfgParam_t,*daddrIPv6CfgParam_Tp; - -/*Tunnel*/ -/*dhcp6*/ -typedef struct tunnelCfgParam_s -{ - uint8 enabled; -}__PACK__ tunnelCfgParam_t, *tunnelCfgParam_Tp; -#endif - -#endif // HOME_GATEWAY - -#ifdef TLS_CLIENT -typedef struct certroot_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_CERTROOT_IMPORT -#include "mibdef.h" -#undef MIB_CERTROOT_IMPORT - -#undef MIBDEF -}__PACK__ CERTROOT_T, *CERTROOT_Tp; -typedef struct certUser_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_CERTUSER_IMPORT -#include "mibdef.h" -#undef MIB_CERTUSER_IMPORT - -#undef MIBDEF -}__PACK__ CERTUSER_T, *CERTUSER_Tp; -#endif -#ifdef HOME_GATEWAY -#ifdef ROUTE_SUPPORT -typedef struct staticRoute_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_STATICROUTE_IMPORT -#include "mibdef.h" -#undef MIB_STATICROUTE_IMPORT - -#undef MIBDEF -}__PACK__ STATICROUTE_T, *STATICROUTE_Tp; -#endif -#endif - -typedef struct dhcpRsvdIP_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_DHCPRSVDIP_IMPORT -#include "mibdef.h" -#undef MIB_DHCPRSVDIP_IMPORT - -#undef MIBDEF -}__PACK__ DHCPRSVDIP_T, *DHCPRSVDIP_Tp; - -typedef struct wlanwds_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_WDS_IMPORT -#include "mibdef.h" -#undef MIB_WDS_IMPORT -}__PACK__ WDS_T, *WDS_Tp; - - -#if defined(HOME_GATEWAY) || defined(CONFIG_RTL_8198_AP_ROOT) -#if defined(VLAN_CONFIG_SUPPORTED) -typedef struct vlan_lanconfig_entry { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_VLAN_CONFIG_IMPORT -#include "mibdef.h" -#undef MIB_VLAN_CONFIG_IMPORT - -#undef MIBDEF -}__PACK__ VLAN_CONFIG_T, *VLAN_CONFIG_Tp; -#endif -#endif - - -typedef struct hw_wlan_setting { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_HW_WLAN_IMPORT -#include "mibdef.h" -#undef MIB_HW_WLAN_IMPORT - -#undef MIBDEF -}__PACK__ HW_WLAN_SETTING_T, *HW_WLAN_SETTING_Tp; - -typedef struct hw_setting { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_HW_IMPORT -#include "mibdef.h" -#undef MIB_HW_IMPORT - -#undef MIBDEF -}__PACK__ HW_SETTING_T, *HW_SETTING_Tp; - -typedef struct config_wlan_setting { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ - _ctype _cname _crepeat; - -#define MIB_CONFIG_WLAN_SETTING_IMPORT -#include "mibdef.h" -#undef MIB_CONFIG_WLAN_SETTING_IMPORT - -#undef MIBDEF -}__PACK__ CONFIG_WLAN_SETTING_T, *CONFIG_WLAN_SETTING_Tp; - -typedef struct config_setting { -#define MIBDEF(_ctype, _cname, _crepeat, _mib_name, _mib_type, _mib_parents_ctype, _default_value, _next_tbl ) \ -_ctype _cname _crepeat; - -#define MIB_IMPORT -#include "mibdef.h" -#undef MIB_IMPORT - -#undef MIBDEF -}__PACK__ APMIB_T, *APMIB_Tp; +#define WORD_SWAP(v) ((unsigned short)(((v>>8)&0xff) | ((v<<8)&0xff00))) -/* Config file header */ -typedef struct param_header { - unsigned char signature[SIGNATURE_LEN]; // Tag + version - unsigned short len; -}__PACK__ PARAM_HEADER_T, *PARAM_HEADER_Tp; +#define SIGNATURE_LEN 4 -/* Firmware image file header */ typedef struct img_header { - unsigned char signature[SIGNATURE_LEN]; - unsigned int startAddr; - unsigned int burnAddr; - unsigned int len; + unsigned char signature[SIGNATURE_LEN]; + unsigned int startAddr; + unsigned int burnAddr; + unsigned int len; }__PACK__ IMG_HEADER_T, *IMG_HEADER_Tp; -/* Web page file header */ -typedef IMG_HEADER_T WEB_HEADER_T; -typedef IMG_HEADER_Tp WEB_HEADER_Tp; -#ifdef TLS_CLIENT -typedef IMG_HEADER_T CERT_HEADER_T; -typedef IMG_HEADER_Tp CERT_HEADER_Tp; -#endif -typedef struct _file_entry { - char name[MAXFNAME]; - unsigned int size; -}__PACK__ FILE_ENTRY_T, *FILE_ENTRY_Tp; - -#ifdef COMPRESS_MIB_SETTING -/* Compress config setting file header */ -#if 0 -#define COMP_TRACE fprintf -#else -#define COMP_TRACE -#endif - -#define COMP_SIGNATURE_LEN 6 -#define COMP_HS_SIGNATURE "COMPHS" -#define COMP_CS_SIGNATURE "COMPCS" -#define COMP_DS_SIGNATURE "COMPDS" -typedef struct compress_mib_header { - unsigned char signature[COMP_SIGNATURE_LEN]; - unsigned short compRate; - unsigned int compLen; -}__PACK__ COMPRESS_MIB_HEADER_T, *COMPRESS_MIB_HEADER_Tp; - -#endif // #ifdef COMPRESS_MIB_SETTING - -#ifdef WIN32 -#pragma pack() #endif - - -////////////////////////////////////////////////////////// -int apmib_init_HW(void); -int apmib_init(void); -int apmib_reinit(void); -char *apmib_hwconf(void); -char *apmib_csconf(void); -char *apmib_dsconf(void); -int apmib_get(int id, void *value); -int apmib_getDef(int id, void *value); -int apmib_set(int id, void *value); -int apmib_setDef(int id, void *value); -int apmib_update(CONFIG_DATA_T type); -int apmib_updateDef(void); -int apmib_updateFlash(CONFIG_DATA_T type, char *data, int len, int force, int ver); -int update_linkchain(int fmt, void *Entry_old, void *Entry_new, int type_size); -extern APMIB_Tp pMib, pMibDef; -extern HW_SETTING_Tp pHwSetting; -extern PARAM_HEADER_T hsHeader, dsHeader, csHeader; -extern int wlan_idx; -extern int vwlan_idx; -#ifdef GW_QOS_ENGINE -extern void getVal12(char *value, char **p1, char **p2, char **p3, char **p4, char **p5, char **p6, char **p7, - char **p8, char **p9, char **p10, char **p11, char **p12); -#define QOS_FORMAT ("%d, %d, %d, %s, %s, %d, %d, %s, %s, %d, %d, %s") -#endif - -#ifdef QOS_BY_BANDWIDTH -//#define QOS_FORMAT ("%d, %s, %d, %s, %s, %d, %s") -#define QOS_FORMAT ("%d, %02x%02x%02x%02x%02x%02x, %d, %s, %s, %d, %d, %s") -#endif - -#if CONFIG_APMIB_SHARED_MEMORY == 1 -#define HWCONF_SHM_KEY 0 -#define DSCONF_SHM_KEY 1 -#define CSCONF_SHM_KEY 2 - -int apmib_sem_lock(void); -int apmib_sem_unlock(void); -int apmib_shm_free(void *shm_memory, int shm_key); -#endif - - -#ifdef CONFIG_CWMP_TR069 - -/* Keith add for tr069 --start */ -#undef mib_get -#undef mib_set -#undef mib_update - -#define mib_get(S, T) apmib_get(S, T) -#define mib_set(S, T) apmib_set(S, T) -#define mib_update(S) apmib_update(S) -#define LANDEVNAME2BR0(a) do{ if(a && (strncmp(a, "eth0", 4)==0||strncmp(a, "wlan0", 5)==0||strncmp(a, "usb0", 4)==0)) strcpy(a, "br0"); }while(0) -/* Keith add for tr069 --end */ - -#define TIME_ZONE -#define WLAN_SUPPORT -#ifdef MBSSID -#define WLAN_MBSSID -#endif -#ifdef UNIVERSAL_REPEATER -#define WLAN_REPEATER -#endif -#define MAC_FILTER -#define ENABLE_WPAAES_WPA2TKIP - -#endif //#ifdef CONFIG_CWMP_TR069 -//#if defined(CONFIG_USBDISK_UPDATE_IMAGE) -#define USB_UPLOAD_FORM_PATH "/tmp/usb/sda1/fw.bin" -//#endif -//### add by sen_liu 2011.4.21 sync the system log update (enlarge from 1 pcs to 8 pcs) to SDKv2.5 from kernel 2.4 -#define RINGLOG -#ifdef RINGLOG /* ring log */ -#define MAX_LOG_SIZE 8 /* unit is kbyte */ -#define LOG_SPLIT 7 /* can't greater than 99 */ - /* - for /var/log/message.(LOG_SPLIT-1) to /var/log/message.0 and then /var/log/message - ex: LOG_SPLIT = 7, we will have - /var/log/message.6 - ... - /var/log/message.0 - /var/log/message - */ -#endif /* ring log */ - -//### end -#endif // INCLUDE_APMIB_H diff --git a/tools/firmware-utils/src/bixutil.c b/tools/firmware-utils/src/bixutil.c deleted file mode 100644 index 6e7dcd479..000000000 --- a/tools/firmware-utils/src/bixutil.c +++ /dev/null @@ -1,188 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <time.h> -#include <fcntl.h> -#include <errno.h> - -#define RTL_PRODUCT_MAGIC1 0x59a0e842 -#define SQUASH_MAGIC 0x73717368 -#define RTL_IMAGE_VERSION 1 -#define RTL_IMAGE_TYPE_RDIR 0xb162 -#define RTL_IMAGE_TYPE_BOOT 0xea43 -#define RTL_IMAGE_TYPE_RUN 0x8dc9 -#define RTL_IMAGE_TYPE_KFS 0xd92f -#define RTL_IMAGE_TYPE_CCFG 0x2a05 -#define RTL_IMAGE_TYPE_DCFG 0x6ce8 -#define RTL_IMAGE_TYPE_LOG 0xc371 - -#define ENDIAN_SWITCH32(x) (((x) >> 24) | \ - (((x) >> 8) & 0xFF00) | \ - (((x) << 8) & 0xFF0000) | \ - (((x) << 24) &0xFF000000)) -#define ENDIAN_SWITCH16(x) ((((x) >> 8) & 0xFF) | \ - (((x) << 8) & 0xFF00)) - - -struct image_header { - u_int32_t magic1; - u_int16_t type; - u_int8_t ver; - u_int8_t align1; - u_int16_t year; - u_int8_t mon; - u_int8_t day; - u_int8_t hour; - u_int8_t min; - u_int8_t sec; - u_int8_t align2; - u_int32_t len; - u_int16_t align3; - u_int8_t icsum; - u_int8_t hcsum; -}; - -void print_header(struct image_header *h) -{ - printf("Magic1: 0x%08x\n", ENDIAN_SWITCH32(h->magic1)); - printf("Type: 0x%04x\n", ENDIAN_SWITCH16(h->type)); - printf("Version: %d\n", h->ver); - printf("Built: %04d-%02d-%02d %02d:%02d:%02d\n", - ENDIAN_SWITCH16(h->year), h->mon, h->day, h->hour, - h->min, h->sec); - printf("Length: %ld\n", ENDIAN_SWITCH32(h->len)); - printf("Checksums: 0x%02x (header), 0x%02x (image)\n", - h->hcsum, h->icsum); -} - -void *do_mmap(char *filename, int size, int readonly) -{ - int fd; - int openflags = O_RDWR | O_CREAT | O_TRUNC; - int protflags = PROT_READ | PROT_WRITE; - void *ptr; - struct stat st; - - if (readonly) { - openflags = O_RDONLY; - protflags = PROT_READ; - } - - if (!size) { - if (!readonly) - goto failed; - if (stat(filename, &st) != 0) { - perror("stat failed"); - goto failed; - } - size = st.st_size; - } - - if (!size) - goto failed; - - if ((fd = open(filename, openflags, 0644)) == -1) { - perror("open failed"); - goto failed; - } - - if (!readonly) - ftruncate(fd, size); - - ptr = mmap(0, size, protflags, MAP_SHARED, fd, 0); - if (ptr == MAP_FAILED) { - perror("mmap failed"); - goto mmap_failed; - } - - return ptr; - -mmap_failed: - close(fd); -failed: - return NULL; -} - -int write_image(char *kernel, char *outfile) -{ - unsigned char type; - unsigned long ksize, padded; - unsigned long i; - unsigned char ch, *src, *dst; - struct stat st; - struct image_header *h; - time_t tt; - struct tm *ut; - - tt = time(NULL); - ut = localtime(&tt); - - if (stat(kernel, &st) != 0) - error(-1, "stat %s failed", kernel); - ksize = st.st_size; - - padded = sizeof(struct image_header) + - ksize + ksize % 4; /* fs starts 32-bit aligned (?check) */ - - h = (struct image_header *)do_mmap(outfile, padded, 0); - if (!h) - return -1; - - memset(h, 0, sizeof(struct image_header)); - - dst = (unsigned char *)((unsigned)h + sizeof(struct image_header)); - src = (unsigned char *)do_mmap(kernel, ksize, 1); - if (!src) - return -1; - - for (i = 0; i < ksize; i++) { - dst[i] = src[i]; - h->icsum ^= src[i]; - } - - for (i = 0; i < ksize % 4; i++) - dst[ksize + i] = 0; - - munmap(src, ksize); - - h->magic1 = ENDIAN_SWITCH32(RTL_PRODUCT_MAGIC1); - h->type = ENDIAN_SWITCH16(RTL_IMAGE_TYPE_RUN); - h->ver = RTL_IMAGE_VERSION; - h->year = ENDIAN_SWITCH16(ut->tm_year + 1900); - h->mon = ut->tm_mon + 1; - h->day = ut->tm_mday; - h->hour = ut->tm_hour; - h->min = ut->tm_min; - h->sec = ut->tm_sec; - h->len = ENDIAN_SWITCH32(padded - sizeof(struct image_header)); - - for (i = 0; i < (sizeof(struct image_header) - 1); i++) - h->hcsum ^= ((unsigned char *)&h)[i]; - munmap(h, padded); - return 0; -} - -void usage(void) -{ - exit(1); -} - -int main(int argc, char *argv[]) -{ - if (argc < 3) usage(); - - printf("%d\n", sizeof(struct image_header)); - if (!strncmp(argv[1], "info", 4)) { - print_header((struct image_header *)do_mmap(argv[2], - 0, 1)); - } else if (!strncmp(argv[1], "pack", 4)) { - write_image(argv[2], argv[3]); - } else { - usage(); - } - - return 0; -} diff --git a/tools/firmware-utils/src/cvimg.c b/tools/firmware-utils/src/cvimg.c index a2b9519d5..c5599ef4c 100644 --- a/tools/firmware-utils/src/cvimg.c +++ b/tools/firmware-utils/src/cvimg.c @@ -15,21 +15,18 @@ #include <unistd.h> #include <stdlib.h> #include <string.h> -#define HOME_GATEWAY - -#define CONFIG_RTL_8196C +/* This define is needed to generate proper binary for + * rtl8196c, rtl8198, rtl819Xe and rtl8196e. + * rtl8196b is somehow different (can be fixed in bootloder?). + * See apmib.h for details. + */ +#define CONFIG_RTL_8196C #include "apmib.h" #define COMPACT_FILENAME_BUFFER -static int friendly_strcmp(const char *s1, const char *s2) -{ - if (!s1 || !s2) return (s1>s2) ? -1 : !(s1==s2); - return strcmp(s1,s2); -} - /* 32-bit ELF base types. */ typedef unsigned int Elf32_Addr; typedef unsigned short Elf32_Half; @@ -119,14 +116,14 @@ int main(int argc, char** argv) IMG_HEADER_Tp pHeader; unsigned int startAddr; unsigned int burnAddr; - unsigned short checksum; + unsigned short checksum=0; int is_vmlinux = 0; int is_vmlinuxhdr = 0; int is_signature = 0; - unsigned int lchecksum, padding_len; - unsigned int start_addr; + unsigned int lchecksum, padding_len=0; + unsigned int start_addr=0; - if (argc == 4 && !friendly_strcmp(argv[1], "size_chk")) { + if (argc == 4 && !strcmp(argv[1], "size_chk")) { unsigned int total_size; #ifdef COMPACT_FILENAME_BUFFER @@ -159,7 +156,7 @@ int main(int argc, char** argv) } #ifdef CONFIG_RTL_FLASH_MAPPING_ENABLE - if (argc == 3 && !friendly_strcmp(argv[1], "flash_size_chk")) { + if (argc == 3 && !strcmp(argv[1], "flash_size_chk")) { unsigned int total_size; #ifdef COMPACT_FILENAME_BUFFER @@ -184,7 +181,7 @@ int main(int argc, char** argv) if (status.st_size > (int)total_size) { - printf("Error!!!! : Kernel image too big will overwirte rootfs image, cur size(%d), available size(%d).\n",status.st_size, total_size); + printf("Error!!!! : Kernel image too big will overwirte rootfs image, cur size(%d), available size(%d).\n",(int)status.st_size, total_size); exit(1); } else @@ -195,15 +192,15 @@ int main(int argc, char** argv) } #endif - if (argc == 4 && !friendly_strcmp(argv[1], "vmlinux")) + if (argc == 4 && !strcmp(argv[1], "vmlinux")) is_vmlinux = 1; - if (argc == 5 && !friendly_strcmp(argv[1], "vmlinuxhdr")) { + if (argc == 5 && !strcmp(argv[1], "vmlinuxhdr")) { is_vmlinuxhdr = 1; start_addr = extractStartAddr(argv[4]); } - if (!friendly_strcmp(argv[1], "signature")) { + if (!strcmp(argv[1], "signature")) { is_signature = 1; if (argc != 7) { printf_usage(); @@ -288,15 +285,15 @@ int main(int argc, char** argv) memcpy(&buf[size-12], &lchecksum, 4); } else if (!is_vmlinux) { - if( !friendly_strcmp("root", argv[1])) + if( !strcmp("root", argv[1])) memcpy(pHeader->signature, ROOT_HEADER, SIGNATURE_LEN); - else if ( !friendly_strcmp("boot", argv[1])) + else if ( !strcmp("boot", argv[1])) memcpy(pHeader->signature, BOOT_HEADER, SIGNATURE_LEN); - else if ( !friendly_strcmp("linux", argv[1])) + else if ( !strcmp("linux", argv[1])) memcpy(pHeader->signature, FW_HEADER, SIGNATURE_LEN); - else if ( !friendly_strcmp("linux-ro", argv[1])) + else if ( !strcmp("linux-ro", argv[1])) memcpy(pHeader->signature, FW_HEADER_WITH_ROOT, SIGNATURE_LEN); - else if ( !friendly_strcmp("signature", argv[1])) + else if ( !strcmp("signature", argv[1])) memcpy(pHeader->signature, argv[6], SIGNATURE_LEN); else{ printf("not supported signature\n"); @@ -306,7 +303,7 @@ int main(int argc, char** argv) pHeader->startAddr = DWORD_SWAP(startAddr); pHeader->burnAddr = DWORD_SWAP(burnAddr); - if( !friendly_strcmp("root", argv[1])) { + if( !strcmp("root", argv[1])) { #define SIZE_OF_SQFS_SUPER_BLOCK 640 unsigned int fs_len; fs_len = DWORD_SWAP((size-sizeof(IMG_HEADER_T) - sizeof(checksum)- SIZE_OF_SQFS_SUPER_BLOCK)); @@ -323,7 +320,7 @@ int main(int argc, char** argv) } // Write image to output file - fh = open(outFile, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); + fh = open(outFile, O_RDWR|O_CREAT|O_TRUNC, 0644); if ( fh == -1 ) { printf("Create output file error! [%s]\n", outFile); free(pHeader); diff --git a/tools/firmware-utils/src/mgbin.c b/tools/firmware-utils/src/mgbin.c new file mode 100644 index 000000000..a16ef1e44 --- /dev/null +++ b/tools/firmware-utils/src/mgbin.c @@ -0,0 +1,431 @@ +/* + * utility to merge all binary into one image + * + * Authors: David Hsu <davidhsu@realtek.com.tw> + * + * $Id: mgbin.c,v 1.7 2008/11/25 15:09:22 bradhuang Exp $ + * + */ +#include <string.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdlib.h> +#include <sys/types.h> +#ifdef WIN32 + #include <io.h> +#else + #include <unistd.h> +#endif +#define __mips__ + +#define CONFIG_RTL_8196C +#include "apmib.h" + +//#define DEBUG_PRINT printf +#define DEBUG_PRINT(...) do {} while(0) +#define COMPACT_FILENAME_BUFFER + +///////////////////////////////////////////////////////////////////////////// +/* Input file type */ +typedef enum { BOOT_CODE=0, CONFIG, WEB_PAGES, SYS, ROOT, ALL, INVALID_FILE=-1 } TYPE_T; + +typedef struct _sector { + TYPE_T type; +#ifdef COMPACT_FILENAME_BUFFER + const char *filename; +#else + char filename[80]; +#endif + unsigned long offset; + unsigned long size; + int with_header; +} SECTOR_T; + +///////////////////////////////////////////////////////////////////////////// +static char *copyright="Copyright (c) Realtek Semiconductor Corp., 2007. All Rights Reserved."; +static char *version="1.0"; + +static SECTOR_T sector[ROOT+1]; +static int no_hw_config=0; + +#define BYTE_SWAP(word) (((word >> 8) &0xff) | ((((unsigned char)word)<<8)&0xff00) ) + +///////////////////////////////////////////////////////////////////////////// +static TYPE_T checkInputFile(char *filename, int *pWith_header) +{ + int fh; + char signature[6]; + +#ifdef WIN32 + fh = open(filename, O_RDONLY|O_BINARY); +#else + fh = open(filename, O_RDONLY,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); +#endif + if ( fh == -1 ) + return INVALID_FILE; + + lseek(fh, 0, SEEK_SET); + + if ( read(fh, signature, sizeof(signature)) != sizeof(signature)) { + close(fh); + return INVALID_FILE; + } + close(fh); + + *pWith_header = 1; + if ( !memcmp(signature, BOOT_HEADER, 4)) + return BOOT_CODE; + else if ( !memcmp(signature, WEB_HEADER, 3) ) + return WEB_PAGES; + + else if ( !memcmp(signature, FW_HEADER, 4) || + !memcmp(signature, FW_HEADER_WITH_ROOT, 4)) + return SYS; + + else if ( !memcmp(signature, ROOT_HEADER, 4) ) + return ROOT; + + else if ( !memcmp(signature, "h", 1) || !memcmp(signature, "COMPHS", 6)) + return CONFIG; + else if ( !memcmp(signature, "6G", 2) || !memcmp(signature, "6A", 2) || !memcmp(signature, "6g", 2) || !memcmp(signature, "6a", 2) || !memcmp(signature, "COMPDS", 6)) { + no_hw_config = 1; + return CONFIG; + } + else if ( !memcmp(signature, "\x0b\xf0\x00\x02", 4)) { + *pWith_header = 0; + return BOOT_CODE; + } + return INVALID_FILE; +} + +//////////////////////////////////////////////////////////////////////////////// +static void showHelp(void) +{ + printf("\nRTL865x utility to merge binary.\n"); + printf("%s Ver %s.\n\n", copyright, version); + printf("usage: mgbin [-s] [-c] [-a] -o outputfile bootcode config webpages linux root\n"); + printf(" -s : do byte swap\n"); + printf(" -c : cascade. May use this option to merge image for web upload\n"); + printf(" -a : add all tag in header\n"); + +} + + +//////////////////////////////////////////////////////////////////////////////// +static void do_byteswap(unsigned char *buf, int len) +{ + unsigned short wVal, *ptr; + int i=0; + + while (len > 0) { + len -= 2; + ptr = (unsigned short *)&buf[2*i]; + wVal = *ptr; + *ptr = BYTE_SWAP( wVal ); + i++; + } +} + +static unsigned short calculateChecksum(char *buf, int len, unsigned short oldv) +{ + int i, j; + unsigned short sum=oldv, tmp; + + j = (len/2)*2; + + for (i=0; i<j; i+=2) { + tmp = *((unsigned short *)(buf + i)); + sum += WORD_SWAP(tmp); + } + + if ( len % 2 ) { + tmp = buf[len-1]; + sum += WORD_SWAP(tmp); + } + return sum; +} + +//////////////////////////////////////////////////////////////////////////////// +int main(int argc, char** argv) +{ + int argNum=1; +#ifdef COMPACT_FILENAME_BUFFER + const char *outFile = NULL; +#else + char outFile[80]={0}; +#endif + TYPE_T type; + int mask=0, fh_out, fh_in, len, i, total=0; + unsigned char *buf, *buf1; + struct stat sbuf; + int byteswap=0, cascade=0, last_idx=-1, is_all=0; + int offset=0, with_header; + IMG_HEADER_Tp pHeader; + unsigned long burnAddr=0; + IMG_HEADER_T allHeader; + unsigned short checksum=0; + + memset(§or, 0, sizeof(sector)); + + while (argNum < argc) { + if ( !strcmp(argv[argNum], "-o") ) { + if (++argNum >= argc) + break; +#ifdef COMPACT_FILENAME_BUFFER + outFile = argv[argNum]; +#else + sscanf(argv[argNum], "%s", outFile); +#endif + } + else if ( !strcmp(argv[argNum], "-s") ) { + byteswap = 1; + } + else if ( !strcmp(argv[argNum], "-c") ) { + cascade = 1; + } + else if ( !strcmp(argv[argNum], "-a") ) { + is_all = 1; + memset(&allHeader, '\0', sizeof(IMG_HEADER_T)); + memcpy(allHeader.signature, ALL_HEADER, SIGNATURE_LEN); + } +#if 0 + else if ( !strcmp(argv[argNum], "-a2") ) { + is_all = 1; + memset(&allHeader, '\0', sizeof(IMG_HEADER_T)); + memcpy(allHeader.signature, ALL_HEADER2, SIGNATURE_LEN); + } +#endif + else { + if (is_all) { + if ((argNum+1) < argc) { + printf("argument error, only input file could be specified!\n"); + return -1; + } +#ifdef COMPACT_FILENAME_BUFFER + sector[0].filename = argv[argNum]; +#else + strcpy(sector[0].filename,argv[argNum]); +#endif + sector[0].type=ALL; + sector[0].with_header=0; + mask |= (1 << ALL); + } + else { + type=checkInputFile(argv[argNum], &with_header); + DEBUG_PRINT("filename=%s, type=%d\n", argv[argNum], type); + if (type == INVALID_FILE) { + printf("\nInvalid input file %s!!\n", argv[argNum]); + showHelp(); + exit(1); + } +#ifdef COMPACT_FILENAME_BUFFER + sector[type].filename = argv[argNum]; +#else + strcpy(sector[type].filename, argv[argNum]); +#endif + sector[type].with_header = with_header; + sector[type].type = type; + mask |= (1 << type); + } + } + argNum++; + } + +#ifdef COMPACT_FILENAME_BUFFER + if( outFile == NULL ) +#else + if (!outFile[0]) +#endif + { + printf("No output file specified!\n"); + showHelp(); + exit(1); + } + + if (mask == 0) { + printf("No valid input image found!\n"); + exit(1); + } + + // Create output file +#ifdef WIN32 + _chmod(outFile, S_IREAD|S_IWRITE); + fh_out = open(outFile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY); +#else + chmod(outFile, S_IREAD|S_IWRITE); + fh_out = open(outFile, O_RDWR|O_CREAT|O_TRUNC, 0644); +#endif + if (fh_out == -1) { + printf("Create output file %s error!\n", outFile); + exit(1); + } + + if (is_all) { + write(fh_out, &allHeader, sizeof(allHeader)); + total += sizeof(allHeader); + printf("\nGenerate "); + } + else + printf("\nMerge "); + + for (i=BOOT_CODE; i<=ROOT ; i++) { +#ifdef COMPACT_FILENAME_BUFFER + if (sector[i].filename) +#else + if (sector[i].filename[0]) +#endif + { + if ( stat(sector[i].filename, &sbuf) != 0 ) { + printf("Stat file %s error!\n", sector[i].filename); + exit(1); + } + buf = malloc(sbuf.st_size+1); + if (buf == NULL) { + printf("allocate buffer failed %d!\n", (int)sbuf.st_size); + exit(1); + } +#ifdef WIN32 + fh_in = open(sector[i].filename, O_RDONLY|O_BINARY); +#else + fh_in = open(sector[i].filename, O_RDONLY,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); +#endif + if (fh_in < 0) { + printf("Open file %s error!\n", sector[i].filename); + close(fh_out); + exit(1); + } + + switch(sector[i].type) { + case BOOT_CODE: + printf("BOOT-CODE "); + break; + case CONFIG: + printf("CONFIG-DATA(%s) ", (no_hw_config ? "no-hw" : "all")); + break; + case WEB_PAGES: + printf("WEB-PAGES "); + break; + case SYS: + printf("LINUX "); + break; + case ROOT: + printf("ROOT "); + break; + case ALL: + printf("ALL "); + break; + case INVALID_FILE: + break; + } + + if (read(fh_in, buf, sbuf.st_size) != sbuf.st_size) { + printf("Read file %s error!\n", sector[i].filename); + close(fh_in); + close(fh_out); + free(buf); + exit(1); + } + + if (is_all) + checksum = calculateChecksum((char *)buf, sbuf.st_size, checksum); + else { + if (sector[i].with_header) { + if (sector[i].type == CONFIG) { + if (no_hw_config == 0) + burnAddr = HW_SETTING_OFFSET; + else + burnAddr = DEFAULT_SETTING_OFFSET; + } + else { + pHeader = (IMG_HEADER_Tp)buf; + burnAddr = DWORD_SWAP(pHeader->burnAddr); + } + } + else + burnAddr = 0; + + if (byteswap) { + if (sbuf.st_size % 2) { + buf[sbuf.st_size] = '\0'; + sbuf.st_size++; + } + do_byteswap(buf, sbuf.st_size); + } + + // try to append 0 if necessary + if (!cascade && last_idx!=-1 && sector[i].with_header) { + if ((sector[last_idx].offset+sector[last_idx].size) < burnAddr) { + len = burnAddr - (sector[last_idx].offset+sector[last_idx].size); + buf1 = calloc(len, 1); + if (buf1 == NULL) { + printf("allocate buffer failed %d!\n", len); + exit(1); + } + write(fh_out, buf1, len); // pad 0 + + free(buf1); + total += len; +// printf("pad size=%d, last_idx=%d, burnAddr=%d\n", len, last_idx, burnAddr); + } + } + + // skip header if necessary + if (!cascade && sector[i].with_header && + ((sector[i].type == ROOT) || (sector[i].type == BOOT_CODE))) { + offset = sizeof(IMG_HEADER_T); +// sbuf.st_size -= sizeof(IMG_HEADER_T); + } + else + offset = 0; + } + +// printf("write offset=%d, size=%d\n", offset, sbuf.st_size); + if ( write(fh_out, buf + offset , sbuf.st_size-offset) != sbuf.st_size-offset) { + printf("Write output file %s error!\n", outFile); + close(fh_in); + close(fh_out); + free(buf); + exit(1); + } + close(fh_in); + if (burnAddr > 0) + sector[i].offset = burnAddr; + else + sector[i].offset = total; + sector[i].size = sbuf.st_size-offset; + +// printf("section[%d], offset=%d, size=%d\n", i, sector[i].offset, sector[i].size); + + total += sbuf.st_size; + free(buf); + last_idx = i; + if (is_all) + break; + } + } + + if (is_all) { + allHeader.len = DWORD_SWAP((total+2)); + checksum = calculateChecksum((char *)&allHeader, sizeof(allHeader), checksum); + checksum = WORD_SWAP((~checksum+1)); + write(fh_out, &checksum, 2); + lseek(fh_out, 0, SEEK_SET); + allHeader.len = DWORD_SWAP((total+2)); +// allHeader.startAddr = DWORD_SWAP(image_num); + write(fh_out, &allHeader, sizeof(allHeader)); + total += (2 + sizeof(allHeader)); + } + close(fh_out); + +#ifdef WIN32 + _chmod(outFile, S_IREAD); +#else + chmod(outFile, DEFFILEMODE); +#endif + + printf("=> %s ok, size=%d.\n", outFile, total); + exit(0); +} + |