diff -Nru abootimg-0.3/abootimg.c abootimg-0.6/abootimg.c --- abootimg-0.3/abootimg.c 2010-12-08 08:45:57.000000000 +0000 +++ abootimg-0.6/abootimg.c 2011-07-14 19:18:48.000000000 +0000 @@ -1,5 +1,5 @@ /* abootimg - Manipulate (read, modify, create) Android Boot Images - * Copyright (c) 2010 Gilles Grandou + * Copyright (c) 2010-2011 Gilles Grandou * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -24,13 +24,34 @@ #include #include #include +#include + + +#ifdef __linux__ +#include +#include /* BLKGETSIZE64 */ +#endif + +#ifdef __CYGWIN__ #include -#include +#include /* BLKGETSIZE64 */ +#endif + +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#include /* DIOCGMEDIASIZE */ +#include +#endif + +#if defined(__APPLE__) +# include /* DKIOCGETBLOCKCOUNT */ +#endif + #ifdef HAS_BLKID #include #endif +#include "version.h" #include "bootimg.h" @@ -87,10 +108,33 @@ } +int blkgetsize(int fd, unsigned long long *pbsize) +{ +# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + return ioctl(fd, DIOCGMEDIASIZE, pbsize); +# elif defined(__APPLE__) + return ioctl(fd, DKIOCGETBLOCKCOUNT, pbsize); +# elif defined(__NetBSD__) + // does a suitable ioctl exist? + // return (ioctl(fd, DIOCGDINFO, &label) == -1); + return 1; +# elif defined(__linux__) || defined(__CYGWIN__) + return ioctl(fd, BLKGETSIZE64, pbsize); +# elif defined(__GNU__) + // does a suitable ioctl for HURD exist? + return 1; +# else + return 1; +# endif + +} + void print_usage(void) { printf ( " abootimg - manipulate Android Boot Images.\n" + " (c) 2010-2011 Gilles Grandou \n" + " " VERSION_STR "\n" "\n" " abootimg [-h]\n" "\n" @@ -231,24 +275,37 @@ int check_boot_img_header(t_abootimg* img) { - if (strncmp(img->header.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) + if (strncmp(img->header.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { + fprintf(stderr, "%s: no Android Magic Value\n", img->fname); return 1; + } - if (!(img->header.kernel_size)) + if (!(img->header.kernel_size)) { + fprintf(stderr, "%s: kernel size is null\n", img->fname); return 1; + } - if (!(img->header.ramdisk_size)) + if (!(img->header.ramdisk_size)) { + fprintf(stderr, "%s: ramdisk size is null\n", img->fname); return 1; + } unsigned page_size = img->header.page_size; + if (!page_size) { + fprintf(stderr, "%s: Image page size is null\n", img->fname); + return 1; + } + unsigned n = (img->header.kernel_size + page_size - 1) / page_size; unsigned m = (img->header.ramdisk_size + page_size - 1) / page_size; unsigned o = (img->header.second_size + page_size - 1) / page_size; unsigned total_size = (1+n+m+o)*page_size; - if (total_size > img->size) + if (total_size > img->size) { + fprintf(stderr, "%s: sizes mismatches in boot image\n", img->fname); return 1; + } return 0; } @@ -278,7 +335,7 @@ abort_perror(img->fname); unsigned long long bsize = 0; - if (ioctl(fd, BLKGETSIZE64, &bsize)) + if (blkgetsize(fd, &bsize)) abort_perror(img->fname); img->size = bsize; @@ -300,9 +357,8 @@ void read_header(t_abootimg* img) { - - fread(&img->header, sizeof(boot_img_hdr), 1, img->stream); - if (ferror(img->stream)) + size_t rb = fread(&img->header, sizeof(boot_img_hdr), 1, img->stream); + if ((rb!=1) || ferror(img->stream)) abort_perror(img->fname); else if (feof(img->stream)) abort_printf("%s: cannot read image header\n", img->fname); @@ -314,7 +370,8 @@ if (S_ISBLK(s.st_mode)) { unsigned long long bsize = 0; - if (ioctl(fd, BLKGETSIZE64, &bsize)) + + if (blkgetsize(fd, &bsize)) abort_perror(img->fname); img->size = bsize; img->is_blkdev = 1; @@ -409,7 +466,7 @@ printf("reading config file %s\n", img->config_fname); char* line = NULL; - unsigned len = 0; + size_t len = 0; int read; while ((read = getline(&line, &len, config_file)) != -1) { @@ -430,7 +487,7 @@ printf("reading config args\n"); char* line = NULL; - unsigned len = 0; + size_t len = 0; int read; while ((read = getline(&line, &len, config_file)) != -1) { @@ -452,6 +509,9 @@ unsigned rsize = img->header.ramdisk_size; unsigned ssize = img->header.second_size; + if (!page_size) + abort_printf("%s: Image page size is null\n", img->fname); + unsigned n = (ksize + page_size - 1) / page_size; unsigned m = (rsize + page_size - 1) / page_size; unsigned o = (ssize + page_size - 1) / page_size; @@ -471,8 +531,8 @@ char* k = malloc(ksize); if (!k) abort_perror(""); - fread(k, 1, ksize, stream); - if (ferror(stream)) + size_t rb = fread(k, ksize, 1, stream); + if ((rb!=1) || ferror(stream)) abort_perror(img->kernel_fname); else if (feof(stream)) abort_printf("%s: cannot read kernel\n", img->kernel_fname); @@ -493,8 +553,8 @@ char* r = malloc(rsize); if (!r) abort_perror(""); - fread(r, 1, rsize, stream); - if (ferror(stream)) + size_t rb = fread(r, rsize, 1, stream); + if ((rb!=1) || ferror(stream)) abort_perror(img->ramdisk_fname); else if (feof(stream)) abort_printf("%s: cannot read ramdisk\n", img->ramdisk_fname); @@ -509,8 +569,8 @@ abort_perror(""); if (fseek(img->stream, roffset, SEEK_SET)) abort_perror(img->fname); - fread(r, 1, rsize, img->stream); - if (ferror(img->stream)) + size_t rb = fread(r, rsize, 1, img->stream); + if ((rb!=1) || ferror(img->stream)) abort_perror(img->fname); else if (feof(img->stream)) abort_printf("%s: cannot read ramdisk\n", img->fname); @@ -529,8 +589,8 @@ char* s = malloc(ssize); if (!s) abort_perror(""); - fread(s, 1, ssize, stream); - if (ferror(stream)) + size_t rb = fread(s, ssize, 1, stream); + if ((rb!=1) || ferror(stream)) abort_perror(img->second_fname); else if (feof(stream)) abort_printf("%s: cannot read second stage\n", img->second_fname); @@ -545,8 +605,8 @@ abort_perror(""); if (fseek(img->stream, soffset, SEEK_SET)) abort_perror(img->fname); - fread(s, 1, ssize, img->stream); - if (ferror(img->stream)) + size_t rb = fread(s, ssize, 1, img->stream); + if ((rb!=1) || ferror(img->stream)) abort_perror(img->fname); else if (feof(img->stream)) abort_printf("%s: cannot read second stage\n", img->fname); @@ -591,16 +651,16 @@ if (ferror(img->stream)) abort_perror(img->fname); - fwrite(padding, 1, psize - sizeof(img->header), img->stream); + fwrite(padding, psize - sizeof(img->header), 1, img->stream); if (ferror(img->stream)) abort_perror(img->fname); if (img->kernel) { - fwrite(img->kernel, 1, img->header.kernel_size, img->stream); + fwrite(img->kernel, img->header.kernel_size, 1, img->stream); if (ferror(img->stream)) abort_perror(img->fname); - fwrite(padding, 1, psize - (img->header.kernel_size % psize), img->stream); + fwrite(padding, psize - (img->header.kernel_size % psize), 1, img->stream); if (ferror(img->stream)) abort_perror(img->fname); } @@ -609,11 +669,11 @@ if (fseek(img->stream, (1+n)*psize, SEEK_SET)) abort_perror(img->fname); - fwrite(img->ramdisk, 1, img->header.ramdisk_size, img->stream); + fwrite(img->ramdisk, img->header.ramdisk_size, 1, img->stream); if (ferror(img->stream)) abort_perror(img->fname); - fwrite(padding, 1, psize - (img->header.ramdisk_size % psize), img->stream); + fwrite(padding, psize - (img->header.ramdisk_size % psize), 1, img->stream); if (ferror(img->stream)) abort_perror(img->fname); } @@ -622,11 +682,11 @@ if (fseek(img->stream, (1+n+m)*psize, SEEK_SET)) abort_perror(img->fname); - fwrite(img->second, 1, img->header.second_size, img->stream); + fwrite(img->second, img->header.second_size, 1, img->stream); if (ferror(img->stream)) abort_perror(img->fname); - fwrite(padding, 1, psize - (img->header.second_size % psize), img->stream); + fwrite(padding, psize - (img->header.second_size % psize), 1, img->stream); if (ferror(img->stream)) abort_perror(img->fname); } @@ -717,8 +777,8 @@ if (fseek(img->stream, psize, SEEK_SET)) abort_perror(img->fname); - fread(k, ksize, 1, img->stream); - if (ferror(img->stream)) + size_t rb = fread(k, ksize, 1, img->stream); + if ((rb!=1) || ferror(img->stream)) abort_perror(img->fname); FILE* kernel_file = fopen(img->kernel_fname, "w"); @@ -746,15 +806,15 @@ printf ("extracting ramdisk in %s\n", img->ramdisk_fname); - void* r = malloc(ksize); + void* r = malloc(rsize); if (!r) abort_perror(NULL); if (fseek(img->stream, roffset, SEEK_SET)) abort_perror(img->fname); - fread(r, rsize, 1, img->stream); - if (ferror(img->stream)) + size_t rb = fread(r, rsize, 1, img->stream); + if ((rb!=1) || ferror(img->stream)) abort_perror(img->fname); FILE* ramdisk_file = fopen(img->ramdisk_fname, "w"); @@ -793,8 +853,8 @@ if (fseek(img->stream, soffset, SEEK_SET)) abort_perror(img->fname); - fread(s, ssize, 1, img->stream); - if (ferror(img->stream)) + size_t rb = fread(s, ssize, 1, img->stream); + if ((rb!=1) || ferror(img->stream)) abort_perror(img->fname); FILE* second_file = fopen(img->second_fname, "w"); @@ -825,6 +885,7 @@ img->second_fname = "stage2.img"; memcpy(img->header.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE); + img->header.page_size = 2048; // a sensible default page size return img; } diff -Nru abootimg-0.3/Changelog abootimg-0.6/Changelog --- abootimg-0.3/Changelog 2010-12-08 08:45:57.000000000 +0000 +++ abootimg-0.6/Changelog 2011-07-14 19:18:48.000000000 +0000 @@ -1,3 +1,21 @@ +2011/07/14 - v0.6 + + * fixes block device support, broken in v0.5 + * fixes crash if ramdisk is bigger than kernel + * version.h no longer relies on git + * build fix on GNU Hurd + +2011/05/18 - v0.5 + + * add support for freebsd, cygwin, and osx + * explains why sanity check has failed + * print version number in -help + * pack-initrd -f support + +2011/02/17 - v0.4 + + * fix when page_size is null + 2010/12/08 - v0.3 * fix when updating kernel without ramdisk diff -Nru abootimg-0.3/debian/changelog abootimg-0.6/debian/changelog --- abootimg-0.3/debian/changelog 2011-07-27 14:50:03.000000000 +0000 +++ abootimg-0.6/debian/changelog 2011-07-27 14:50:04.000000000 +0000 @@ -1,10 +1,24 @@ -abootimg (0.3-1ubuntu1) oneiric; urgency=low +abootimg (0.6-1) unstable; urgency=low - * debian/rules: Add simple-patchsys to cdbs packaging. - * debian/patches/fix_crash.patch: Fix crash on extracting when - ramdisk is larger than kernel image. Taken from upstream git. + * New upstream release - -- Jani Monoses Wed, 29 Jun 2011 12:26:47 +0300 + -- Heiko Stuebner Thu, 14 Jul 2011 20:54:33 +0200 + +abootimg (0.5+git20110704-1) unstable; urgency=low + + * New upstream snapshot + * Fix build on GNU-Hurd + * Bump standards to 3.9.2 + + -- Heiko Stuebner Mon, 04 Jul 2011 18:34:17 +0200 + +abootimg (0.5+git20110609-1) unstable; urgency=low + + * New upstream release (Closes: #631719) + * Relax packaging license (Closes: #631720) + * Install helper scripts for initramfs handling + + -- Heiko Stuebner Sat, 02 Jul 2011 12:46:35 +0200 abootimg (0.3-1) unstable; urgency=low diff -Nru abootimg-0.3/debian/control abootimg-0.6/debian/control --- abootimg-0.3/debian/control 2011-07-27 14:50:03.000000000 +0000 +++ abootimg-0.6/debian/control 2011-07-27 14:50:04.000000000 +0000 @@ -3,7 +3,7 @@ Priority: extra Maintainer: Heiko Stuebner Build-Depends: debhelper (>= 7), cdbs (>= 0.4.49), libblkid-dev -Standards-Version: 3.9.1 +Standards-Version: 3.9.2 Homepage: http://gitorious.org/ac100/abootimg Package: abootimg diff -Nru abootimg-0.3/debian/copyright abootimg-0.6/debian/copyright --- abootimg-0.3/debian/copyright 2011-07-27 14:50:03.000000000 +0000 +++ abootimg-0.6/debian/copyright 2011-07-27 14:50:04.000000000 +0000 @@ -43,4 +43,5 @@ The Debian packaging is copyright 2011, Heiko Stuebner and -is licensed under the GPL version 2, see `/usr/share/common-licenses/GPL-2'. +is licensed under the GPL version 2, or (at your option) any later version, +see `/usr/share/common-licenses/GPL-2'. diff -Nru abootimg-0.3/debian/patches/fix_crash.patch abootimg-0.6/debian/patches/fix_crash.patch --- abootimg-0.3/debian/patches/fix_crash.patch 2011-07-27 14:50:03.000000000 +0000 +++ abootimg-0.6/debian/patches/fix_crash.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,15 +0,0 @@ -## Description: add some description -## Origin/Author: http://gitorious.org/ac100/abootimg/commit/819366a97060d53a8a766ca16c81166497051c0b -## Bug: bug URL -diff -Nur -x '*.orig' -x '*~' abootimg-0.3//abootimg.c abootimg-0.3.new//abootimg.c ---- abootimg-0.3//abootimg.c 2010-12-08 10:45:57.000000000 +0200 -+++ abootimg-0.3.new//abootimg.c 2011-06-29 12:26:45.148564585 +0300 -@@ -746,7 +746,7 @@ - - printf ("extracting ramdisk in %s\n", img->ramdisk_fname); - -- void* r = malloc(ksize); -+ void* r = malloc(rsize); - if (!r) - abort_perror(NULL); - diff -Nru abootimg-0.3/debian/rules abootimg-0.6/debian/rules --- abootimg-0.3/debian/rules 2011-07-27 14:50:03.000000000 +0000 +++ abootimg-0.6/debian/rules 2011-07-27 14:50:04.000000000 +0000 @@ -2,13 +2,18 @@ include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/makefile.mk -include /usr/share/cdbs/1/rules/simple-patchsys.mk + +DEBVERS := $(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p') +VERSION := $(shell echo '$(DEBVERS)' | sed -e 's/^[[:digit:]]*://' -e 's/[~-].*//') + +configure/abootimg:: + echo '#define VERSION_STR "$(VERSION)"' > version.h binary-install/abootimg:: dh_installman $(CURDIR)/debian/abootimg.1 install $(CURDIR)/abootimg $(CURDIR)/debian/abootimg/usr/bin - install $(CURDIR)/pack-initrd $(CURDIR)/debian/abootimg/usr/share/doc/abootimg - install $(CURDIR)/unpack-initrd $(CURDIR)/debian/abootimg/usr/share/doc/abootimg + install -T $(CURDIR)/pack-initrd $(CURDIR)/debian/abootimg/usr/bin/abootimg-pack-initrd + install -T $(CURDIR)/unpack-initrd $(CURDIR)/debian/abootimg/usr/bin/abootimg-unpack-initrd clean:: rm -rf files/agtl.egg-info diff -Nru abootimg-0.3/.gitignore abootimg-0.6/.gitignore --- abootimg-0.3/.gitignore 2010-12-08 08:45:57.000000000 +0000 +++ abootimg-0.6/.gitignore 2011-07-14 19:18:48.000000000 +0000 @@ -1,2 +1,4 @@ abootimg - +version.h +*.o +*.swp diff -Nru abootimg-0.3/Makefile abootimg-0.6/Makefile --- abootimg-0.3/Makefile 2010-12-08 08:45:57.000000000 +0000 +++ abootimg-0.6/Makefile 2011-07-14 19:18:48.000000000 +0000 @@ -1,13 +1,23 @@ +CPPFLAGS=-DHAS_BLKID +CFLAGS=-O3 -Wall +LDLIBS=-lblkid + all: abootimg -abootimg: abootimg.c bootimg.h - gcc -g -O2 -Wno-unused-result -o abootimg abootimg.c -DHAS_BLKID -lblkid +version.h: + if [ ! -f version.h ]; then \ + if [ -d .git ]; then \ + echo '#define VERSION_STR "$(shell git describe --tags --abbrev=0)"' > version.h; \ + else \ + echo '#define VERSION_STR ""' > version.h; \ + fi \ + fi -clean: - rm -f abootimg abootimg-static +abootimg.o: bootimg.h version.h -archive: clean - cd ..; tar cvzf abootimg.tar.gz abootimg --exclude tests --exclude tmp\* --exclude .git +clean: + rm -f abootimg *.o version.h +.PHONY: clean all diff -Nru abootimg-0.3/pack-initrd abootimg-0.6/pack-initrd --- abootimg-0.3/pack-initrd 2010-12-08 08:45:57.000000000 +0000 +++ abootimg-0.6/pack-initrd 2011-07-14 19:18:48.000000000 +0000 @@ -1,8 +1,23 @@ #!/bin/sh # +if [ "$1" = "-f" ]; then + forcewrite=yes + shift +fi + initrd=${1:-initrd.img} ramdisk=${2:-ramdisk} +if [ ! -d $ramdisk ]; then + echo "$ramdisk does not exist." + exit 1 +fi + +if [ -f $initrd -a -z "$forcewrite" ]; then + echo "$initrd already exist." + exit 1 +fi + ( cd $ramdisk; find | sort | cpio --quiet -o -H newc ) | gzip > $initrd diff -Nru abootimg-0.3/unpack-initrd abootimg-0.6/unpack-initrd --- abootimg-0.3/unpack-initrd 2010-12-08 08:45:57.000000000 +0000 +++ abootimg-0.6/unpack-initrd 2011-07-14 19:18:48.000000000 +0000 @@ -4,6 +4,11 @@ initrd=${1:-initrd.img} ramdisk=${2:-ramdisk} +if [ ! -f $initrd ]; then + echo "$initrd does not exist." + exit 1 +fi + if [ -d $ramdisk ]; then echo "$ramdisk already exists." exit 1