From patchwork Tue Jun 23 03:22:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 487469 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 836E7140157 for ; Tue, 23 Jun 2015 13:24:08 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 688C11A0F93 for ; Tue, 23 Jun 2015 13:24:08 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e23smtp05.au.ibm.com (e23smtp05.au.ibm.com [202.81.31.147]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 60F321A0F72 for ; Tue, 23 Jun 2015 13:23:56 +1000 (AEST) Received: from /spool/local by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 23 Jun 2015 13:23:56 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp05.au.ibm.com (202.81.31.211) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 23 Jun 2015 13:23:54 +1000 X-Helo: d23dlp02.au.ibm.com X-MailFrom: cyril.bur@au1.ibm.com X-RcptTo: skiboot@lists.ozlabs.org Received: from d23relay06.au.ibm.com (d23relay06.au.ibm.com [9.185.63.219]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 0FBCF2BB004D for ; Tue, 23 Jun 2015 13:23:54 +1000 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t5N3Nj4r66453660 for ; Tue, 23 Jun 2015 13:23:53 +1000 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t5N3NLOq004875 for ; Tue, 23 Jun 2015 13:23:21 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t5N3NLqj004205 for ; Tue, 23 Jun 2015 13:23:21 +1000 Received: from camb691.ozlabs.ibm.com (unknown [9.192.254.114]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 5403AA03C2 for ; Tue, 23 Jun 2015 13:22:46 +1000 (AEST) From: Cyril Bur To: skiboot@lists.ozlabs.org Date: Tue, 23 Jun 2015 13:22:12 +1000 Message-Id: <1435029734-27908-6-git-send-email-cyril.bur@au1.ibm.com> X-Mailer: git-send-email 2.4.4 In-Reply-To: <1435029734-27908-1-git-send-email-cyril.bur@au1.ibm.com> References: <1435029734-27908-1-git-send-email-cyril.bur@au1.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15062303-0017-0000-0000-0000016B6513 Subject: [Skiboot] [PATCH V3 5/7] libflash: Delete file_file.[ch] files X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The new backend for blocklevel does this in a much neater way as much this hacky code is no longer needed. Reviewed-By: Alistair Popple Signed-off-by: Cyril Bur --- libflash/file_flash.c | 224 -------------------------------------------------- libflash/file_flash.h | 11 --- 2 files changed, 235 deletions(-) delete mode 100644 libflash/file_flash.c delete mode 100644 libflash/file_flash.h diff --git a/libflash/file_flash.c b/libflash/file_flash.c deleted file mode 100644 index d902672..0000000 --- a/libflash/file_flash.c +++ /dev/null @@ -1,224 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "file_flash.h" - -/* The caller is going to have to supply this */ -struct file_flash_priv { - int fd; -}; - -/* - * Unfortunately not all file descriptors are created equal... - * Here we check to see if the file descriptor is to an MTD device, in which - * case we have to get the size of it differently. - */ -int file_setup(struct spi_flash_ctrl *ctrl, uint32_t *tsize) -{ - struct mtd_info_user mtd_info; - struct file_flash_priv *file_flash_data; - struct stat sbuf; - - if (!ctrl || !ctrl->priv) - return -1; - - file_flash_data = (struct file_flash_priv *)ctrl->priv; - - if (fstat(file_flash_data->fd, &sbuf) == -1) - return -1; - - if (S_ISCHR(sbuf.st_mode)) { - if (ioctl(file_flash_data->fd, MEMGETINFO, &mtd_info) == -1) - return -1; - - ctrl->finfo->size = mtd_info.size; - - } else if (S_ISREG(sbuf.st_mode)) { - ctrl->finfo->size = sbuf.st_size; - - } else { - /* Not going to be able to work with anything else */ - return -1; - } - - if (tsize) - *tsize = ctrl->finfo->size; - - return 0; -} - -int file_set4b(struct spi_flash_ctrl *ctrl, bool enable) -{ - /* Always report success no matter what, this isn't relevent for files */ - return 0; -} - -int file_chipid(struct spi_flash_ctrl *ctrl, uint8_t *id_buf, - uint32_t *id_size) -{ - if (!ctrl || !ctrl->priv || !id_size || *id_size < 3) - return -1; - - id_buf[0] = 'M'; - id_buf[1] = 'T'; - id_buf[2] = 'D'; - - *id_size = 3; - return 0; -} - -int file_read(struct spi_flash_ctrl *ctrl, uint32_t addr, void *buf, - uint32_t size) -{ - int rc; - struct file_flash_priv *file_flash_data; - - if (!ctrl || !ctrl->priv) - return -1; - - file_flash_data = (struct file_flash_priv *)ctrl->priv; - - rc = lseek(file_flash_data->fd, addr, SEEK_SET); - if ((off_t )rc == (off_t )-1) - return -1; - - rc = read(file_flash_data->fd, buf, size); - if (rc == -1) - return -1; - /* TODO Perhaps deal with short reads */ - - return 0; -} - -int file_write(struct spi_flash_ctrl *ctrl, uint32_t addr, - const void *buf, uint32_t size) -{ - size_t rc; - struct file_flash_priv *file_flash_data; - - if (!ctrl || !ctrl->priv) - return -1; - - file_flash_data = (struct file_flash_priv *)ctrl->priv; - - rc = lseek(file_flash_data->fd, addr, SEEK_SET); - if ((off_t )rc == (off_t )-1) - return -1; - - rc = write(file_flash_data->fd, buf, size); - if (rc != size) - return -1; - /* TODO Perhaps deal with short writes */ - - return 0; -} - -int file_erase(struct spi_flash_ctrl *ctrl, uint32_t addr, - uint32_t size) -{ - struct stat sbuf; - struct file_flash_priv *file_flash_data; - uint32_t esize; - - if (!ctrl || !ctrl->priv) - return -1; - - /* - * Input params addr = 0 and size = 0xffffffff mean libflash is telling us - * to erase the entire thing. - */ - file_flash_data = (struct file_flash_priv *)ctrl->priv; - - esize = (size == 0xffffffff && addr == 0) ? ctrl->finfo->size : size; - if (esize > ctrl->finfo->size) - return -1; - - if (fstat(file_flash_data->fd, &sbuf) == -1) - return -1; - - /* - * If we're dealing with an MTD device then its possible that there is a - * real flash device somewhere (as opposed to a regular file where the - * assumption is that there is not). - * In that case lets try to represerve that idea and use the erase ioctl. - */ - if (S_ISCHR(sbuf.st_mode)) { - struct erase_info_user erase_info = { - .start = addr, - .length = esize - }; - - if (ioctl(file_flash_data->fd, MEMERASE, erase_info) == -1) - return -1; - - } else if (S_ISREG(sbuf.st_mode)) { - /* Regular file, erase is just write zeros */ - char *section; - - section = mmap(NULL, sbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, file_flash_data->fd, 0); - if (section == (void *)-1) - return -1; - bzero(section + addr, esize); - if (munmap(section, sbuf.st_size) == -1) - return -1; - - } else { - return -1; - } - - return 0; -} - -/* To be called by tools wanting to use the libflash/libffs APIs */ -struct spi_flash_ctrl *build_flash_ctrl(int fd) -{ - struct spi_flash_ctrl *ctrl; - struct file_flash_priv *data; - - ctrl = calloc(1, sizeof(struct spi_flash_ctrl)); - if (!ctrl) - return NULL; - - data = calloc(1, sizeof(struct file_flash_priv)); - if (!data) { - free(ctrl); - return NULL; - } - - data->fd = fd; - - /* - * Don't implement the low level interfaces because we aren't flash. This - * will also force libflash to only call us with the high level interface. - */ - ctrl->cmd_rd = NULL; - ctrl->cmd_wr = NULL; - - /* - * Do implement everything else. - */ - ctrl->erase = &file_erase; - ctrl->write = &file_write; - ctrl->read = &file_read; - ctrl->chip_id = &file_chipid; - ctrl->set_4b = &file_set4b; - ctrl->setup = &file_setup; - - ctrl->priv = data; - - return ctrl; -} - -void free_flash_ctrl(struct spi_flash_ctrl *flash_ctrl) -{ - free(flash_ctrl->priv); - free(flash_ctrl); -} diff --git a/libflash/file_flash.h b/libflash/file_flash.h deleted file mode 100644 index dc6b5d7..0000000 --- a/libflash/file_flash.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __FILE_FLASH_H -#define __FILE_FLASH_H - -#include -#include - -struct spi_flash_ctrl *build_flash_ctrl(int fd); - -void free_flash_ctrl(struct spi_flash_ctrl *flash_ctrl); - -#endif /* __FILE_FLASH_H */