Skip to content

Commit f6fbcce

Browse files
committed
Initial commit. Build params set for Cortex-M3.
0 parents  commit f6fbcce

31 files changed

+13096
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
obj/
3+
toolpath

README

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
ZLIB DATA COMPRESSION LIBRARY
2+
3+
zlib 1.2.8 is a general purpose data compression library. All the code is
4+
thread safe. The data format used by the zlib library is described by RFCs
5+
(Request for Comments) 1950 to 1952 in the files
6+
http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and
7+
rfc1952 (gzip format).
8+
9+
All functions of the compression library are documented in the file zlib.h
10+
(volunteer to write man pages welcome, contact [email protected]). A usage example
11+
of the library is given in the file test/example.c which also tests that
12+
the library is working correctly. Another example is given in the file
13+
test/minigzip.c. The compression library itself is composed of all source
14+
files in the root directory.
15+
16+
To compile all files and run the test program, follow the instructions given at
17+
the top of Makefile.in. In short "./configure; make test", and if that goes
18+
well, "make install" should work for most flavors of Unix. For Windows, use
19+
one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use
20+
make_vms.com.
21+
22+
Questions about zlib should be sent to <[email protected]>, or to Gilles Vollant
23+
<[email protected]> for the Windows DLL version. The zlib home page is
24+
http://zlib.net/ . Before reporting a problem, please check this site to
25+
verify that you have the latest version of zlib; otherwise get the latest
26+
version and check whether the problem still exists or not.
27+
28+
PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
29+
30+
Mark Nelson <[email protected]> wrote an article about zlib for the Jan. 1997
31+
issue of Dr. Dobb's Journal; a copy of the article is available at
32+
http://marknelson.us/1997/01/01/zlib-engine/ .
33+
34+
The changes made in version 1.2.8 are documented in the file ChangeLog.
35+
36+
Unsupported third party contributions are provided in directory contrib/ .
37+
38+
zlib is available in Java using the java.util.zip package, documented at
39+
http://java.sun.com/developer/technicalArticles/Programming/compression/ .
40+
41+
A Perl interface to zlib written by Paul Marquess <[email protected]> is available
42+
at CPAN (Comprehensive Perl Archive Network) sites, including
43+
http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
44+
45+
A Python interface to zlib written by A.M. Kuchling <[email protected]> is
46+
available in Python 1.5 and later versions, see
47+
http://docs.python.org/library/zlib.html .
48+
49+
zlib is built into tcl: http://wiki.tcl.tk/4610 .
50+
51+
An experimental package to read and write files in .zip format, written on top
52+
of zlib by Gilles Vollant <[email protected]>, is available in the
53+
contrib/minizip directory of zlib.
54+
55+
56+
Notes for some targets:
57+
58+
- For Windows DLL versions, please see win32/DLL_FAQ.txt
59+
60+
- For 64-bit Irix, deflate.c must be compiled without any optimization. With
61+
-O, one libpng test fails. The test works in 32 bit mode (with the -n32
62+
compiler flag). The compiler bug has been reported to SGI.
63+
64+
- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
65+
when compiled with cc.
66+
67+
- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
68+
necessary to get gzprintf working correctly. This is done by configure.
69+
70+
- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
71+
other compilers. Use "make test" to check your compiler.
72+
73+
- gzdopen is not supported on RISCOS or BEOS.
74+
75+
- For PalmOs, see http://palmzlib.sourceforge.net/
76+
77+
78+
Acknowledgments:
79+
80+
The deflate format used by zlib was defined by Phil Katz. The deflate and
81+
zlib specifications were written by L. Peter Deutsch. Thanks to all the
82+
people who reported problems and suggested various improvements in zlib; they
83+
are too numerous to cite here.
84+
85+
Copyright notice:
86+
87+
(C) 1995-2013 Jean-loup Gailly and Mark Adler
88+
89+
This software is provided 'as-is', without any express or implied
90+
warranty. In no event will the authors be held liable for any damages
91+
arising from the use of this software.
92+
93+
Permission is granted to anyone to use this software for any purpose,
94+
including commercial applications, and to alter it and redistribute it
95+
freely, subject to the following restrictions:
96+
97+
1. The origin of this software must not be misrepresented; you must not
98+
claim that you wrote the original software. If you use this software
99+
in a product, an acknowledgment in the product documentation would be
100+
appreciated but is not required.
101+
2. Altered source versions must be plainly marked as such, and must not be
102+
misrepresented as being the original software.
103+
3. This notice may not be removed or altered from any source distribution.
104+
105+
Jean-loup Gailly Mark Adler
106+
107+
108+
If you use the zlib library in a product, we would appreciate *not* receiving
109+
lengthy legal documents to sign. The sources are provided for free but without
110+
warranty of any kind. The library has been entirely written by Jean-loup
111+
Gailly and Mark Adler; it does not include third-party code.
112+
113+
If you redistribute modified sources, we would appreciate that you include in
114+
the file ChangeLog history information documenting your changes. Please read
115+
the FAQ for more information on the distribution of modified source versions.

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Zlib for ARM Cortex M
2+
3+
This is a concise Zlib library (.a GNU gcc archive) for ARM Cortex-M (M0, M0+, M1, M3, M4)
4+
5+
The "kitchen-sink" build is about 43K of code. Real-world use and optimization will be less.
6+
Link to your final firmware with gcc option `-Wl,--gc-sections`.
7+
8+
This adheres to Zlib's license. Additions unique to this repository are released to the public domain.
9+
See README file for Zlib's license.
10+
11+
See [Zlib homepage](http://www.zlib.net/) for more info.

adler32.c

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/* adler32.c -- compute the Adler-32 checksum of a data stream
2+
* Copyright (C) 1995-2011 Mark Adler
3+
* For conditions of distribution and use, see copyright notice in zlib.h
4+
*/
5+
6+
/* @(#) $Id$ */
7+
8+
#include "zutil.h"
9+
10+
#define local static
11+
12+
local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2));
13+
14+
#define BASE 65521 /* largest prime smaller than 65536 */
15+
#define NMAX 5552
16+
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
17+
18+
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
19+
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
20+
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
21+
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
22+
#define DO16(buf) DO8(buf,0); DO8(buf,8);
23+
24+
/* use NO_DIVIDE if your processor does not do division in hardware --
25+
try it both ways to see which is faster */
26+
#ifdef NO_DIVIDE
27+
/* note that this assumes BASE is 65521, where 65536 % 65521 == 15
28+
(thank you to John Reiser for pointing this out) */
29+
# define CHOP(a) \
30+
do { \
31+
unsigned long tmp = a >> 16; \
32+
a &= 0xffffUL; \
33+
a += (tmp << 4) - tmp; \
34+
} while (0)
35+
# define MOD28(a) \
36+
do { \
37+
CHOP(a); \
38+
if (a >= BASE) a -= BASE; \
39+
} while (0)
40+
# define MOD(a) \
41+
do { \
42+
CHOP(a); \
43+
MOD28(a); \
44+
} while (0)
45+
# define MOD63(a) \
46+
do { /* this assumes a is not negative */ \
47+
z_off64_t tmp = a >> 32; \
48+
a &= 0xffffffffL; \
49+
a += (tmp << 8) - (tmp << 5) + tmp; \
50+
tmp = a >> 16; \
51+
a &= 0xffffL; \
52+
a += (tmp << 4) - tmp; \
53+
tmp = a >> 16; \
54+
a &= 0xffffL; \
55+
a += (tmp << 4) - tmp; \
56+
if (a >= BASE) a -= BASE; \
57+
} while (0)
58+
#else
59+
# define MOD(a) a %= BASE
60+
# define MOD28(a) a %= BASE
61+
# define MOD63(a) a %= BASE
62+
#endif
63+
64+
/* ========================================================================= */
65+
uLong ZEXPORT adler32(adler, buf, len)
66+
uLong adler;
67+
const Bytef *buf;
68+
uInt len;
69+
{
70+
unsigned long sum2;
71+
unsigned n;
72+
73+
/* split Adler-32 into component sums */
74+
sum2 = (adler >> 16) & 0xffff;
75+
adler &= 0xffff;
76+
77+
/* in case user likes doing a byte at a time, keep it fast */
78+
if (len == 1) {
79+
adler += buf[0];
80+
if (adler >= BASE)
81+
adler -= BASE;
82+
sum2 += adler;
83+
if (sum2 >= BASE)
84+
sum2 -= BASE;
85+
return adler | (sum2 << 16);
86+
}
87+
88+
/* initial Adler-32 value (deferred check for len == 1 speed) */
89+
if (buf == Z_NULL)
90+
return 1L;
91+
92+
/* in case short lengths are provided, keep it somewhat fast */
93+
if (len < 16) {
94+
while (len--) {
95+
adler += *buf++;
96+
sum2 += adler;
97+
}
98+
if (adler >= BASE)
99+
adler -= BASE;
100+
MOD28(sum2); /* only added so many BASE's */
101+
return adler | (sum2 << 16);
102+
}
103+
104+
/* do length NMAX blocks -- requires just one modulo operation */
105+
while (len >= NMAX) {
106+
len -= NMAX;
107+
n = NMAX / 16; /* NMAX is divisible by 16 */
108+
do {
109+
DO16(buf); /* 16 sums unrolled */
110+
buf += 16;
111+
} while (--n);
112+
MOD(adler);
113+
MOD(sum2);
114+
}
115+
116+
/* do remaining bytes (less than NMAX, still just one modulo) */
117+
if (len) { /* avoid modulos if none remaining */
118+
while (len >= 16) {
119+
len -= 16;
120+
DO16(buf);
121+
buf += 16;
122+
}
123+
while (len--) {
124+
adler += *buf++;
125+
sum2 += adler;
126+
}
127+
MOD(adler);
128+
MOD(sum2);
129+
}
130+
131+
/* return recombined sums */
132+
return adler | (sum2 << 16);
133+
}
134+
135+
/* ========================================================================= */
136+
local uLong adler32_combine_(adler1, adler2, len2)
137+
uLong adler1;
138+
uLong adler2;
139+
z_off64_t len2;
140+
{
141+
unsigned long sum1;
142+
unsigned long sum2;
143+
unsigned rem;
144+
145+
/* for negative len, return invalid adler32 as a clue for debugging */
146+
if (len2 < 0)
147+
return 0xffffffffUL;
148+
149+
/* the derivation of this formula is left as an exercise for the reader */
150+
MOD63(len2); /* assumes len2 >= 0 */
151+
rem = (unsigned)len2;
152+
sum1 = adler1 & 0xffff;
153+
sum2 = rem * sum1;
154+
MOD(sum2);
155+
sum1 += (adler2 & 0xffff) + BASE - 1;
156+
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
157+
if (sum1 >= BASE) sum1 -= BASE;
158+
if (sum1 >= BASE) sum1 -= BASE;
159+
if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
160+
if (sum2 >= BASE) sum2 -= BASE;
161+
return sum1 | (sum2 << 16);
162+
}
163+
164+
/* ========================================================================= */
165+
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
166+
uLong adler1;
167+
uLong adler2;
168+
z_off_t len2;
169+
{
170+
return adler32_combine_(adler1, adler2, len2);
171+
}
172+
173+
uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
174+
uLong adler1;
175+
uLong adler2;
176+
z_off64_t len2;
177+
{
178+
return adler32_combine_(adler1, adler2, len2);
179+
}

build.sh

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
if [ -f "toolpath" ]; then
4+
toolPath=$(cat toolpath)
5+
PATH="$toolPath:$PATH"
6+
fi
7+
8+
mcu="cortex-m3" # "cortex-m0"
9+
arch="armv7-m" # "armv6-m" for Cortex-M0/+
10+
11+
sources=`ls *.c`
12+
13+
mkdir -p obj
14+
rm obj/*
15+
16+
objs=""
17+
count=0
18+
for s in $sources; do
19+
f=$(basename $s | sed -E 's/(^.*)\.[a-zA-Z]+$/\1/')
20+
o="obj/$count-$f.$arch.o"
21+
count=$(($count + 1))
22+
23+
echo "Building $s => $o"
24+
arm-none-eabi-gcc -Wall -Wno-switch -nostdlib -nodefaultlibs -fno-exceptions \
25+
-g -Os -mthumb -march=$arch -mcpu=$mcu -Wno-attributes \
26+
--function-sections \
27+
-I . \
28+
-o $o -x c -c $s
29+
30+
if [ $? -ne 0 ]; then
31+
echo "Compiling failed."
32+
exit -1
33+
fi
34+
objs="$objs $o"
35+
done
36+
37+
echo Linking...
38+
# use single-object pre-link
39+
arm-none-eabi-ld -o obj/zlib.$arch.o -r $objs
40+
41+
if [ $? -ne 0 ]; then
42+
echo "Linking failed."
43+
exit -1
44+
fi
45+
46+
echo Archiving...
47+
arm-none-eabi-ar r obj/zlib.$arch.a obj/zlib.$arch.o
48+
49+
if [ $? -ne 0 ]; then
50+
echo "Archiving failed."
51+
exit -1
52+
fi
53+
54+
# report symbols
55+
arm-none-eabi-size obj/zlib.$arch.a > obj/zlib.$arch.report.txt
56+
arm-none-eabi-nm obj/zlib.$arch.a >> obj/zlib.$arch.report.txt
57+
arm-none-eabi-objdump -d obj/zlib.armv7-m.o >> obj/zlib.$arch.report.txt
58+
59+
cat obj/zlib.$arch.size.txt
60+
61+
# link to final firmware with -Wl,--gc-sections
62+
63+
exit 0

0 commit comments

Comments
 (0)