18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * arch/h8300/boot/compressed/misc.c 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * This is a collection of several routines from gzip-1.0.3 68c2ecf20Sopenharmony_ci * adapted for Linux. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Adapted for h8300 by Yoshinori Sato 2006 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* 168c2ecf20Sopenharmony_ci * gzip declarations 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define OF(args) args 208c2ecf20Sopenharmony_ci#define STATIC static 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#undef memset 238c2ecf20Sopenharmony_ci#undef memcpy 248c2ecf20Sopenharmony_ci#define memzero(s, n) memset((s), (0), (n)) 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciextern int _end; 278c2ecf20Sopenharmony_cistatic unsigned long free_mem_ptr; 288c2ecf20Sopenharmony_cistatic unsigned long free_mem_end_ptr; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ciextern char input_data[]; 318c2ecf20Sopenharmony_ciextern int input_len; 328c2ecf20Sopenharmony_ciextern char output[]; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define HEAP_SIZE 0x10000 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#ifdef CONFIG_KERNEL_GZIP 378c2ecf20Sopenharmony_ci#include "../../../../lib/decompress_inflate.c" 388c2ecf20Sopenharmony_ci#endif 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#ifdef CONFIG_KERNEL_LZO 418c2ecf20Sopenharmony_ci#include "../../../../lib/decompress_unlzo.c" 428c2ecf20Sopenharmony_ci#endif 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_civoid *memset(void *s, int c, size_t n) 458c2ecf20Sopenharmony_ci{ 468c2ecf20Sopenharmony_ci int i; 478c2ecf20Sopenharmony_ci char *ss = (char *)s; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci for (i = 0; i < n; i++) 508c2ecf20Sopenharmony_ci ss[i] = c; 518c2ecf20Sopenharmony_ci return s; 528c2ecf20Sopenharmony_ci} 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_civoid *memcpy(void *dest, const void *src, size_t n) 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci int i; 578c2ecf20Sopenharmony_ci char *d = (char *)dest, *s = (char *)src; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci for (i = 0; i < n; i++) 608c2ecf20Sopenharmony_ci d[i] = s[i]; 618c2ecf20Sopenharmony_ci return dest; 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistatic void error(char *x) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci while (1) 678c2ecf20Sopenharmony_ci ; /* Halt */ 688c2ecf20Sopenharmony_ci} 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_civoid decompress_kernel(void) 718c2ecf20Sopenharmony_ci{ 728c2ecf20Sopenharmony_ci free_mem_ptr = (unsigned long)&_end; 738c2ecf20Sopenharmony_ci free_mem_end_ptr = free_mem_ptr + HEAP_SIZE; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci __decompress(input_data, input_len, NULL, NULL, output, 0, NULL, error); 768c2ecf20Sopenharmony_ci} 77