From patchwork Wed Nov 5 03:51:03 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiafu Gao X-Patchwork-Id: 7283 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 7B0FCDDF73 for ; Wed, 5 Nov 2008 14:51:14 +1100 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from web35601.mail.mud.yahoo.com (web35601.mail.mud.yahoo.com [66.163.179.140]) by ozlabs.org (Postfix) with SMTP id 3B525DDDEC for ; Wed, 5 Nov 2008 14:51:05 +1100 (EST) Received: (qmail 90946 invoked by uid 60001); 5 Nov 2008 03:51:03 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:References:Date:From:Subject:To:MIME-Version:Content-Type:Message-ID; b=3U3L+KLYgRJVnkIEmzf6U/ToPws2WIIE7OdkqV/37JI+DlfDW65Kh2FEYYwF3YBWb0br1i0maJ7ru5E4u0xW7nlZ89oSJOvRJu9k9jlMJ+K52okyhJndk9IOOwF9MWGieDyOFO2c2rGlhz51chA4vRMIx5CZ6atXjSyPbpL3eiQ=; X-YMail-OSG: 4yB6I84VM1nQ.f.6XdNUAgzLd7aJtN6X9A00yAcLclSLBL.aWWWagNZhX3QnqpYKB_qzDqEfDdv8BKb75v12Ge0S6h5YvTSAiQ6r9obkLWHVDKfyAqm0IinjFLgPFlfvuQeP2YNIx.kc7GcvCIoRv.zodgE67u.qAPnZi5nr7Qo6Nlbs3Xds1MLNOjM- Received: from [76.109.43.27] by web35601.mail.mud.yahoo.com via HTTP; Tue, 04 Nov 2008 19:51:03 PST X-Mailer: YahooMailRC/1155.20 YahooMailWebService/0.7.260.1 References: <403557.68834.qm@web35602.mail.mud.yahoo.com> <200808151314.15570.jk@ozlabs.org> Date: Tue, 4 Nov 2008 19:51:03 -0800 (PST) From: Jiafu Gao To: cbe-oss-dev@ozlabs.org MIME-Version: 1.0 Message-ID: <583206.90742.qm@web35601.mail.mud.yahoo.com> Subject: [Cbe-oss-dev] ps3-utils performance issue X-BeenThere: cbe-oss-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Discussion about Open Source Software for the Cell Broadband Engine List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Hi, One of the handy tool in ps3-utils [0] is ps3-dump-bootloader. It is implemented as a shell script using dd util. The main command is: dd if=/dev/ps3flash bs=1 skip=$ldr_offset count=$ldr_size Note that the parameter bs=1. Trying to dump the boot loader under Ubuntu Intrepid (size of 3M: 3037844), it takes more than 6 minutes. I am not sure the reason, but I guess it could be dd is not using read/write buffer when bs is set to 1. This translate to 3M reads and writes. Also notes that read from flash is in the form of block. There are several solutions: 1. change bs to a reasonable size, say 1024. Then we have an issue of leftover that is not multiple of 1024. We can either read this left over separately by set bs=1 or read an extra block and truncate the file to the proper size. 2. add an option to ps3-flash-util to dump boot loader. The implementation is really simple: just read /dev/ps3flash and write in reasonable blocks. I've came up a quick patch (attached) to do this. Both methods only take under 1 second. Geoff, I've leave to you to decide which method to use. Use the patch if you like. Thanks for your attention. [0] http://www.kernel.org/pub/linux/kernel/people/geoff/cell/ps3-utils/, version 2.3 --- ps3-utils-2.3/ps3-flash-util.c 2008-10-31 18:18:11.000000000 -0400 +++ ps3-utils-2.3-new/ps3-flash-util.c 2008-11-04 22:26:49.000000000 -0500 @@ -118,6 +118,7 @@ "SYNOPSIS\n" " ps3-flash-util [-d, --device flash-dev] [-s, --show-settings]\n" " [-w, --write-image image-file]\n" +" [-b, --backup-image iamge-file]\n" " [-g, --set-game-os | -o, --set-other-os]\n" " [-r, --set-raw | -z, --set-gzip] [-t, --game-time]\n" " [-T, --db-test] [-F, --db-format]\n" @@ -137,6 +138,8 @@ " the OS area header with information for the new image. This is\n" " the option to use to write a new bootloader image to flash mem-\n" " ory. Use ’-’ for data on stdin.\n" +" -b, --backup-image image-file\n" +" Backup Other OS image from flash memory to image-file\n" " -g, --set-game-os\n" " Set the system boot flag to Game OS.\n" " -o, --set-other-os\n" @@ -189,6 +192,7 @@ {"device", required_argument, NULL, 'd'}, {"show-settings", no_argument, NULL, 's'}, {"write-image", required_argument, NULL, 'w'}, + {"backup-image", required_argument, NULL, 'b'}, {"set-game-os", no_argument, NULL, 'g'}, {"set-other-os", no_argument, NULL, 'o'}, {"set-raw", no_argument, NULL, 'r'}, @@ -234,6 +238,7 @@ struct db_op_entry* db_op_list; const char *device; const char *image; + const char *backup_image; }; static void show_settings(const struct os_area_header *h, @@ -280,6 +285,42 @@ return result; } +static int backup_image(FILE* dev, struct os_area_header* h, const char* image) +{ +#define BUF_SIZE 1024 + int left, offset, size; + char buf[BUF_SIZE]; + + FILE* img = fopen(image, "w"); + if (!img) { + DBG("%s:%d: fopen failed.\n", __func__,__LINE__); + perror(image); + return -1; + } + + offset = 512*h->ldr_area_offset; + size = h->ldr_size; + if (offset>0) + if (fseek(dev,offset,SEEK_SET)) + return -1; + left = size; + while (left>=BUF_SIZE) { + if (fread(buf, BUF_SIZE, 1, dev)!=1) + return -1; + if (fwrite(buf, BUF_SIZE, 1, img)!=1) + return -1; + left -= BUF_SIZE; + } + if (left>0) { + if (fread(buf,left,1,dev)!=1) + return -1; + if (fwrite(buf,left,1,img)!=1) + return -1; + } + + return 0; +} + static void db_list_owners(void) { char s[2048]; @@ -408,6 +449,10 @@ opts->image = optarg; got_work++; break; + case 'b': + opts->backup_image = optarg; + got_work++; + break; case 'g': opts->boot_other_os = opt_no; got_work++; @@ -662,6 +707,14 @@ exit(1); } } + + if (opts.backup_image) { + result = backup_image(dev,&header,opts.backup_image); + if (result) { + fprintf(stderr, "%s:%d: backup_image failed\n", __func__,__LINE__); + exit(1); + } + } if (opts.compressed_image) { result = os_area_set_ldr_format(&header, dev,