From patchwork Mon May 14 11:25:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 912875 X-Patchwork-Delegate: david.oberhollenzer@sigma-star.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NruWtb4g"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40kzBz1SGkz9s0W for ; Mon, 14 May 2018 21:35:07 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=/crDL2GbfWsWooIawC9fezuJQKG4NXwkX6IKCXvGuq8=; b=NruWtb4gpjJzgcJ2ncc2YetB3g 92crc3ZPtmODgF8KB46zs9h4iiw/pq6iA7vjuGQYlqlCwUxq1nIDD0mgNXyv+/ovyvIL+B2B7EhyD 5dXvRdcE74QKFuNw4MMoDDLJsTAYke367oXf9p2uvYHKsG98kXU3tkbj43KmoCxq8QpOMBxs3ddHi tfwOiO5H4TFR5ryHbGswGZkOedXB3IAwPPA3di5nxzTuRDC+bd/YzzXk5LBxNZt3AmvYFl5w7vCMF Kg91lbh+0VeG+diC4zvcdmF/+vxEUcQyF7BBP8N/CtDPdSTfTJ3tkbvVjrSn3cFUi+i0oaJ/KAs2n guAZsTFQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIBkm-00029T-40; Mon, 14 May 2018 11:34:56 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIBbw-0005Kr-F0 for linux-mtd@lists.infradead.org; Mon, 14 May 2018 11:25:53 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id B95D9181A2F1F; Mon, 14 May 2018 13:25:40 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 4/5] libubigen: Maintain a eraseblock association table Date: Mon, 14 May 2018 13:25:27 +0200 Message-Id: <20180514112528.24092-5-richard@nod.at> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180514112528.24092-1-richard@nod.at> References: <20180514112528.24092-1-richard@nod.at> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180514_042548_731522_47AD70D7 X-CRM114-Status: GOOD ( 16.26 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , linux-kernel@vger.kernel.org, goliath@sigma-star.at MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The EBA is needed later for preseeded fastmap support. Signed-off-by: Richard Weinberger --- include/libubigen.h | 1 + lib/libubigen.c | 14 ++++++++++++++ ubi-utils/ubinize.c | 2 ++ 3 files changed, 17 insertions(+) diff --git a/include/libubigen.h b/include/libubigen.h index 8084d0ecddb2..6073a2d72e05 100644 --- a/include/libubigen.h +++ b/include/libubigen.h @@ -92,6 +92,7 @@ struct ubigen_vol_info uint8_t flags; const char *image_file; size_t image_file_len; + int *eba; }; /** diff --git a/lib/libubigen.c b/lib/libubigen.c index 900c984229fb..f509d4d072bd 100644 --- a/lib/libubigen.c +++ b/lib/libubigen.c @@ -176,6 +176,10 @@ int ubigen_write_volume(const struct ubigen_info *ui, long long bytes = vi->image_file_len; char *inbuf, *outbuf; + for (lnum = 0; lnum < vi->used_ebs; lnum++) + vi->eba[lnum] = -1; + + if (vi->id >= ui->max_volumes) { errmsg("too high volume id %d, max. volumes is %d", vi->id, ui->max_volumes); @@ -203,6 +207,7 @@ int ubigen_write_volume(const struct ubigen_info *ui, memset(outbuf, 0xFF, ui->data_offs); ubigen_init_ec_hdr(ui, (struct ubi_ec_hdr *)outbuf, ec); + lnum = 0; while (bytes) { int l; struct ubi_vid_hdr *vid_hdr; @@ -229,6 +234,12 @@ int ubigen_write_volume(const struct ubigen_info *ui, memset(outbuf + ui->data_offs + len, 0xFF, ui->peb_size - ui->data_offs - len); + vi->eba[lnum] = lseek(out, 0, SEEK_CUR) / ui->peb_size; + if (vi->eba[lnum] == -1) { + sys_errmsg("cannot get offset of output file"); + goto out_free1; + } + if (write(out, outbuf, ui->peb_size) != ui->peb_size) { sys_errmsg("cannot write %d bytes to the output file", ui->peb_size); goto out_free1; @@ -285,6 +296,7 @@ int ubigen_write_layout_vol(const struct ubigen_info *ui, int peb1, int peb2, sys_errmsg("cannot seek output file"); goto out_free; } + vi->eba[0] = peb1; ubigen_init_ec_hdr(ui, (struct ubi_ec_hdr *)outbuf, ec1); ubigen_init_vid_hdr(ui, &vi, vid_hdr, 0, NULL, 0); @@ -299,6 +311,8 @@ int ubigen_write_layout_vol(const struct ubigen_info *ui, int peb1, int peb2, sys_errmsg("cannot seek output file"); goto out_free; } + vi->eba[1] = peb2; + ubigen_init_ec_hdr(ui, (struct ubi_ec_hdr *)outbuf, ec2); ubigen_init_vid_hdr(ui, &vi, vid_hdr, 1, NULL, 0); ret = write(fd, outbuf, ui->peb_size); diff --git a/ubi-utils/ubinize.c b/ubi-utils/ubinize.c index bffb66ebcbd9..62ddd7b85296 100644 --- a/ubi-utils/ubinize.c +++ b/ubi-utils/ubinize.c @@ -398,6 +398,7 @@ static int read_section(const struct ubigen_info *ui, const char *sname, else vi->used_ebs = (st.st_size + vi->usable_leb_size - 1) / vi->usable_leb_size; vi->compat = 0; + vi->eba = xcalloc(vi->used_ebs, sizeof(int)); return 0; } @@ -563,6 +564,7 @@ int main(int argc, char * const argv[]) verbose(args.verbose, "done"); + free(vi->eba); free(vi); iniparser_freedict(args.dict); free(vtbl);