Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
reform-boundary-uboot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jack Humbert
reform-boundary-uboot
Commits
88d52c6a
Commit
88d52c6a
authored
12 years ago
by
Lei Wen
Committed by
Tom Rini
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
lib: add gzip lib function callback
Signed-off-by:
Lei Wen
<
leiwen@marvell.com
>
parent
869c2abb
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/common.h
+7
-0
7 additions, 0 deletions
include/common.h
lib/Makefile
+1
-0
1 addition, 0 deletions
lib/Makefile
lib/gzip.c
+142
-0
142 additions, 0 deletions
lib/gzip.c
with
150 additions
and
0 deletions
include/common.h
+
7
−
0
View file @
88d52c6a
...
...
@@ -829,6 +829,13 @@ void fputc(int file, const char c);
int
ftstc
(
int
file
);
int
fgetc
(
int
file
);
/* lib/gzip.c */
int
gzip
(
void
*
dst
,
unsigned
long
*
lenp
,
unsigned
char
*
src
,
unsigned
long
srclen
);
int
zzip
(
void
*
dst
,
unsigned
long
*
lenp
,
unsigned
char
*
src
,
unsigned
long
srclen
,
int
stoponerr
,
int
(
*
func
)(
unsigned
long
,
unsigned
long
));
/* lib/net_utils.c */
#include
<net.h>
static
inline
IPaddr_t
getenv_IPaddr
(
char
*
var
)
...
...
This diff is collapsed.
Click to expand it.
lib/Makefile
+
1
−
0
View file @
88d52c6a
...
...
@@ -42,6 +42,7 @@ COBJS-y += errno.o
COBJS-$(CONFIG_OF_CONTROL)
+=
fdtdec.o
COBJS-$(CONFIG_TEST_FDTDEC)
+=
fdtdec_test.o
COBJS-$(CONFIG_GZIP)
+=
gunzip.o
COBJS-$(CONFIG_GZIP_COMPRESSED)
+=
gzip.o
COBJS-y
+=
hashtable.o
COBJS-$(CONFIG_LMB)
+=
lmb.o
COBJS-y
+=
ldiv.o
...
...
This diff is collapsed.
Click to expand it.
lib/gzip.c
0 → 100644
+
142
−
0
View file @
88d52c6a
/*
* (C) Copyright 2012
* Lei Wen <leiwen@marvell.com>, Marvell Inc.
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include
<common.h>
#include
<watchdog.h>
#include
<command.h>
#include
<image.h>
#include
<malloc.h>
#include
<u-boot/zlib.h>
#include
"zlib/zutil.h"
#ifndef CONFIG_GZIP_COMPRESS_DEF_SZ
#define CONFIG_GZIP_COMPRESS_DEF_SZ 0x200
#endif
#define ZALLOC_ALIGNMENT 16
static
void
*
zalloc
(
void
*
x
,
unsigned
items
,
unsigned
size
)
{
void
*
p
;
size
*=
items
;
size
=
(
size
+
ZALLOC_ALIGNMENT
-
1
)
&
~
(
ZALLOC_ALIGNMENT
-
1
);
p
=
malloc
(
size
);
return
(
p
);
}
static
void
zfree
(
void
*
x
,
void
*
addr
,
unsigned
nb
)
{
free
(
addr
);
}
int
gzip
(
void
*
dst
,
unsigned
long
*
lenp
,
unsigned
char
*
src
,
unsigned
long
srclen
)
{
return
zzip
(
dst
,
lenp
,
src
,
srclen
,
1
,
NULL
);
}
/*
* Compress blocks with zlib
*/
int
zzip
(
void
*
dst
,
unsigned
long
*
lenp
,
unsigned
char
*
src
,
unsigned
long
srclen
,
int
stoponerr
,
int
(
*
func
)(
unsigned
long
,
unsigned
long
))
{
z_stream
s
;
int
r
,
flush
,
orig
,
window
;
unsigned
long
comp_len
,
left_len
;
if
(
!
srclen
)
return
0
;
#ifndef CONFIG_GZIP
window
=
MAX_WBITS
;
#else
window
=
2
*
MAX_WBITS
;
#endif
orig
=
*
lenp
;
s
.
zalloc
=
zalloc
;
s
.
zfree
=
zfree
;
s
.
opaque
=
Z_NULL
;
r
=
deflateInit2_
(
&
s
,
Z_BEST_SPEED
,
Z_DEFLATED
,
window
,
DEF_MEM_LEVEL
,
Z_DEFAULT_STRATEGY
,
ZLIB_VERSION
,
sizeof
(
z_stream
));
if
(
r
!=
Z_OK
)
{
printf
(
"Error: deflateInit2_() returned %d
\n
"
,
r
);
return
-
1
;
}
while
(
srclen
>
0
)
{
comp_len
=
(
srclen
>
CONFIG_GZIP_COMPRESS_DEF_SZ
)
?
CONFIG_GZIP_COMPRESS_DEF_SZ
:
srclen
;
s
.
next_in
=
src
;
s
.
avail_in
=
comp_len
;
flush
=
(
srclen
>
CONFIG_GZIP_COMPRESS_DEF_SZ
)
?
Z_NO_FLUSH
:
Z_FINISH
;
do
{
left_len
=
(
*
lenp
>
CONFIG_GZIP_COMPRESS_DEF_SZ
)
?
CONFIG_GZIP_COMPRESS_DEF_SZ
:
*
lenp
;
s
.
next_out
=
dst
;
s
.
avail_out
=
left_len
;
r
=
deflate
(
&
s
,
flush
);
if
(
r
==
Z_STREAM_ERROR
&&
stoponerr
==
1
)
{
printf
(
"Error: deflate() returned %d
\n
"
,
r
);
r
=
-
1
;
goto
bail
;
}
if
(
!
func
)
{
dst
+=
(
left_len
-
s
.
avail_out
);
*
lenp
-=
(
left_len
-
s
.
avail_out
);
}
else
if
(
left_len
-
s
.
avail_out
>
0
)
{
r
=
func
((
unsigned
long
)
dst
,
left_len
-
s
.
avail_out
);
if
(
r
<
0
)
goto
bail
;
}
}
while
(
s
.
avail_out
==
0
&&
(
*
lenp
>
0
));
if
(
s
.
avail_in
)
{
printf
(
"Deflate failed to consume %u bytes"
,
s
.
avail_in
);
r
=
-
1
;
goto
bail
;
}
if
(
*
lenp
==
0
)
{
printf
(
"Deflate need more space to compress "
"left %lu bytes
\n
"
,
srclen
);
r
=
-
1
;
goto
bail
;
}
srclen
-=
comp_len
;
src
+=
comp_len
;
}
r
=
0
;
bail:
deflateEnd
(
&
s
);
*
lenp
=
orig
-
*
lenp
;
return
r
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment