From patchwork Wed Feb 25 22:56:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dileep Katta X-Patchwork-Id: 45154 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A85FE20502 for ; Wed, 25 Feb 2015 22:57:02 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id h11sf5676869wiw.1 for ; Wed, 25 Feb 2015 14:57:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:cc:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=uNZRpVpSJO2i+NrTXVnxPfP9yZhnygxqH/RV01+ot8I=; b=PRCzdA+fM429ZzyCRvaY8+D1MHHjNBEnFZHHvMmOgDtZs3eriWOmKKdYh6fcdoF9i4 arQ54z6I/S+V2HPS3fNSuskVxO3oMQMAr6uczhY/HcJ+UmRi0b95R3Dva/0g2NKy1zA7 KSCRL6eMTxQDD3fC42DSYhSfMqG8xU2kw+xy28TqE50hXvP2WLNAU/53XHC6LNpnBEcq ScDC+Vv8g+EEqviRDy0nB9cVROBOlYMKzQRvVfbr5iKFyrZ4NhFxYX4fzBzOBDz/4uMC 4Rz2H9W0+7ZXyRyeL+YwJPzUDETbIk+EhlaqxCa4aM77LjEDgVhqYd1IFo2dx0YhnwNQ 5tsQ== X-Gm-Message-State: ALoCoQktQQsMDUcULRRzorXWpA9BtIIoxiVxhuEJn7oLBfNUfLwEarSMSd/hYFirftP3pDEAwbOb X-Received: by 10.194.239.41 with SMTP id vp9mr844330wjc.5.1424905021944; Wed, 25 Feb 2015 14:57:01 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.71 with SMTP id r7ls794452lag.42.gmail; Wed, 25 Feb 2015 14:57:01 -0800 (PST) X-Received: by 10.112.154.199 with SMTP id vq7mr4665602lbb.99.1424905021711; Wed, 25 Feb 2015 14:57:01 -0800 (PST) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id r3si31906533lbo.9.2015.02.25.14.57.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Feb 2015 14:57:01 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbdu14 with SMTP id u14so7223902lbd.1 for ; Wed, 25 Feb 2015 14:57:01 -0800 (PST) X-Received: by 10.112.118.211 with SMTP id ko19mr4964793lbb.19.1424905021531; Wed, 25 Feb 2015 14:57:01 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp2934100lbj; Wed, 25 Feb 2015 14:57:01 -0800 (PST) X-Received: by 10.180.89.238 with SMTP id br14mr11065840wib.68.1424905020765; Wed, 25 Feb 2015 14:57:00 -0800 (PST) Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id kc3si30271176wjc.123.2015.02.25.14.56.59; Wed, 25 Feb 2015 14:57:00 -0800 (PST) Received-SPF: none (google.com: u-boot-bounces@lists.denx.de does not designate permitted sender hosts) client-ip=85.214.87.163; Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9D6A34A02A; Wed, 25 Feb 2015 23:56:58 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OOmpT1pIDwf3; Wed, 25 Feb 2015 23:56:58 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 00CBD4A01C; Wed, 25 Feb 2015 23:56:58 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CD53E4A01C for ; Wed, 25 Feb 2015 23:56:53 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Gy14LKCCJWjz for ; Wed, 25 Feb 2015 23:56:53 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by theia.denx.de (Postfix) with ESMTPS id 513D24A01B for ; Wed, 25 Feb 2015 23:56:51 +0100 (CET) Received: by padfa1 with SMTP id fa1so8846571pad.2 for ; Wed, 25 Feb 2015 14:56:49 -0800 (PST) X-Received: by 10.66.124.164 with SMTP id mj4mr9475068pab.83.1424905009212; Wed, 25 Feb 2015 14:56:49 -0800 (PST) Received: from localhost.localdomain ([106.51.142.94]) by mx.google.com with ESMTPSA id pa6sm33445747pac.45.2015.02.25.14.56.46 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Feb 2015 14:56:48 -0800 (PST) From: Dileep Katta To: u-boot@lists.denx.de, robherring2@gmail.com, trini@ti.com, rob.herring@linaro.org, srae@broadcom.com, l.majewski@samsung.com, angelabaker@ti.com Date: Thu, 26 Feb 2015 04:26:21 +0530 Message-Id: <1424904981-12339-1-git-send-email-dileep.katta@linaro.org> X-Mailer: git-send-email 1.8.3.2 Cc: Dileep Katta Subject: [U-Boot] [PATCH v1 1/1] fastboot: Add support for flashing zImage X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: dileep.katta@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This patch adds support to flash zImage to the boot partition on eMMC. Usage: fastboot flash zImage Signed-off-by: Angela Stegmaier Signed-off-by: Dileep Katta --- drivers/usb/gadget/f_fastboot.c | 152 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 310175a..d3d16c0 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -23,6 +23,7 @@ #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV #include #endif +#include #define FASTBOOT_VERSION "0.4" @@ -492,6 +493,152 @@ static void cb_continue(struct usb_ep *ep, struct usb_request *req) } #ifdef CONFIG_FASTBOOT_FLASH +static int fastboot_update_zimage(void); + +static u32 fastboot_get_boot_ptn(struct andr_img_hdr *hdr, char *response, + block_dev_desc_t *dev_desc) +{ + u32 hdr_sectors = 0; + u32 sector_size; + int status = 0; + strcpy(response, "OKAY"); + disk_partition_t info; + + status = get_partition_info_efi_by_name(dev_desc, "boot", &info); + if (status) { + strcpy(response, "FAILCannot find boot partition"); + goto out; + } + + /* Read the boot image header */ + sector_size = info.blksz; + hdr_sectors = (sizeof(struct andr_img_hdr)/sector_size) + 1; + status = dev_desc->block_read(dev_desc->dev, info.start, + hdr_sectors, (void *)hdr); + + if (status < 0) { + strcpy(response, "FAILCannot read hdr from boot partition"); + goto out; + } + if (android_image_check_header(hdr) != 0) { + printf("bad boot image magic\n"); + strcpy(response, "FAILBoot partition not initialized"); + goto out; + } + + return hdr_sectors; + +out: + strcpy(response, "INFO"); + fastboot_tx_write_str(response); + + return -1; +} + +#define CEIL(a, b) (((a) / (b)) + ((a % b) > 0 ? 1 : 0)) + +static int fastboot_update_zimage(void) +{ + struct andr_img_hdr *hdr = NULL; + u8 *ramdisk_buffer; + u32 ramdisk_sector_start, ramdisk_sectors; + u32 kernel_sector_start, kernel_sectors; + u32 hdr_sectors = 0; + u32 sectors_per_page = 0; + int ret = 0; + block_dev_desc_t *dev_desc; + disk_partition_t info; + char response[RESPONSE_LEN]; + u32 addr = CONFIG_USB_FASTBOOT_BUF_ADDR; + + strcpy(response, "OKAY"); + printf("Flashing zImage...%d bytes\n", download_bytes); + + dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); + if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { + sprintf(response + strlen(response), + "FAILInvalid mmc device"); + ret = -1; + goto out; + } + + addr += CEIL(download_bytes, 0x1000) * 0x1000; + hdr = (struct andr_img_hdr *)addr; + + hdr_sectors = fastboot_get_boot_ptn(hdr, response, dev_desc); + if (hdr_sectors <= 0) { + sprintf(response + strlen(response), + "FAILInvalid number of boot sectors %d", hdr_sectors); + ret = -1; + goto out; + } + ret = get_partition_info_efi_by_name(dev_desc, "boot", &info); + if (ret) { + strcpy(response, "FAILCannot find boot partition"); + ret = -1; + goto out; + } + + /* Extract ramdisk location and read it into local buffer */ + sectors_per_page = hdr->page_size / info.blksz; + ramdisk_sector_start = info.start + sectors_per_page; + ramdisk_sector_start += CEIL(hdr->kernel_size, hdr->page_size)* + sectors_per_page; + ramdisk_sectors = CEIL(hdr->ramdisk_size, hdr->page_size)* + sectors_per_page; + + ramdisk_buffer = (u8 *)hdr; + ramdisk_buffer += (hdr_sectors * info.blksz); + ret = dev_desc->block_read(dev_desc->dev, ramdisk_sector_start, + ramdisk_sectors, ramdisk_buffer); + if (ret < 0) { + sprintf(response, "FAILCannot read ramdisk from 'boot'"); + ret = -1; + goto out; + } + + /* Change the boot img hdr */ + hdr->kernel_size = download_bytes; + ret = dev_desc->block_write(dev_desc->dev, info.start, + hdr_sectors, (void *)hdr); + if (ret < 0) { + sprintf(response, "FAILCannot writeback boot img hdr"); + ret = -1; + goto out; + } + + /* Write the new downloaded kernel*/ + kernel_sector_start = info.start + sectors_per_page; + kernel_sectors = CEIL(hdr->kernel_size, hdr->page_size)* + sectors_per_page; + ret = dev_desc->block_write(dev_desc->dev, kernel_sector_start, + kernel_sectors, + (const void *)CONFIG_USB_FASTBOOT_BUF_ADDR); + if (ret < 0) { + sprintf(response, "FAILCannot write new kernel"); + ret = -1; + goto out; + } + + /* Write the saved Ramdisk back */ + ramdisk_sector_start = info.start + sectors_per_page; + ramdisk_sector_start += CEIL(hdr->kernel_size, hdr->page_size)* + sectors_per_page; + ret = dev_desc->block_write(dev_desc->dev, ramdisk_sector_start, + ramdisk_sectors, ramdisk_buffer); + if (ret < 0) { + sprintf(response, "FAILCannot write back original ramdisk"); + ret = -1; + goto out; + } + fastboot_tx_write_str(response); + return 0; + +out: + fastboot_tx_write_str(response); + return ret; +} + static void cb_flash(struct usb_ep *ep, struct usb_request *req) { char *cmd = req->buf; @@ -505,6 +652,11 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req) } strcpy(response, "FAILno flash device defined"); + + if (!strcmp(cmd, "zImage") || !strcmp(cmd, "zimage")) { + fastboot_update_zimage(); + return; + } #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV fb_mmc_flash_write(cmd, (void *)CONFIG_USB_FASTBOOT_BUF_ADDR, download_bytes, response);