From patchwork Tue Mar 5 13:11:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amar X-Patchwork-Id: 15236 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 9A9C923E00 for ; Tue, 5 Mar 2013 12:57:04 +0000 (UTC) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by fiordland.canonical.com (Postfix) with ESMTP id 27E55A1945E for ; Tue, 5 Mar 2013 12:57:04 +0000 (UTC) Received: by mail-ve0-f173.google.com with SMTP id oz10so5756837veb.32 for ; Tue, 05 Mar 2013 04:57:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-auditid:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-brightmail-tracker:x-brightmail-tracker :dlp-filter:x-mtr:x-cfilter-loop:x-gm-message-state; bh=KsU9zFB2lhHbJLI8Io17XhRkHZ309320RWMYUdBu1pE=; b=kalYTSpVVNZTlYt+CfM+Eo3L6K5i9FA+7U7kZhSB7BHsRe2BTMG5MMZKqJuBnLPH8B MobGk+DHGSeOofIMQPed1oTwfo40jPlZF+9z68sFvhSrC+oQUSeURMcR3u7aa9+EVI/o VR2ieI0Iq16E0r0A1J+dJGri8IDQlyXUPfFk1edf8Yn4OiAFbYKOMlF8FYguKi0fZUsU tNccDRmE7NpzeAZdhnJadREK3bMXunEdzltrFc5qtzNHxVti8MWfKJ+vDmoNU6I2t1rC loThoFawbI4b6S4QHWfhAwSbadMxQEm6gfNOjZeuOy+KOzEp+ixAgUht0b/TTbQ48lD9 aBlQ== X-Received: by 10.58.188.48 with SMTP id fx16mr9727813vec.22.1362488223536; Tue, 05 Mar 2013 04:57:03 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp109956veb; Tue, 5 Mar 2013 04:57:02 -0800 (PST) X-Received: by 10.68.42.39 with SMTP id k7mr36758088pbl.138.1362488221897; Tue, 05 Mar 2013 04:57:01 -0800 (PST) Received: from mailout3.samsung.com (mailout3.samsung.com. [203.254.224.33]) by mx.google.com with ESMTP id xm3si27032838pbc.136.2013.03.05.04.57.01; Tue, 05 Mar 2013 04:57:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of amarendra.xt@samsung.com designates 203.254.224.33 as permitted sender) client-ip=203.254.224.33; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of amarendra.xt@samsung.com designates 203.254.224.33 as permitted sender) smtp.mail=amarendra.xt@samsung.com Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MJ600LIFUN0ZI20@mailout3.samsung.com>; Tue, 05 Mar 2013 21:57:00 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.126]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id 99.06.25214.C9BE5315; Tue, 05 Mar 2013 21:57:00 +0900 (KST) X-AuditID: cbfee68e-b7fa46d00000627e-78-5135eb9c432f Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id F3.2A.03918.B9BE5315; Tue, 05 Mar 2013 21:57:00 +0900 (KST) Received: from chrome-ubuntu.sisodomain.com ([107.108.73.106]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MJ600GDUUCXH840@mmp1.samsung.com>; Tue, 05 Mar 2013 21:56:59 +0900 (KST) From: Amar To: u-boot@lists.denx.de Cc: patches@linaro.org, sjg@chromium.org, mk7.kang@samsung.com, chander.kashyap@linaro.org, afleming@gmail.com, jh80.chung@samsung.com Subject: [PATCH V7 07/10] MMC: APIs to support resize of EMMC boot partition Date: Tue, 05 Mar 2013 08:11:27 -0500 Message-id: <1362489090-7745-8-git-send-email-amarendra.xt@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1362489090-7745-1-git-send-email-amarendra.xt@samsung.com> References: <1362489090-7745-1-git-send-email-amarendra.xt@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJLMWRmVeSWpSXmKPExsWyRsSkTnfOa9NAg9Vv+S0err/JYjHl8BcW ByaPO9f2sAUwRnHZpKTmZJalFunbJXBlrF/wgK1ggVnFh+fL2RsYZ2l3MXJwSAiYSPyZYtXF yAlkiklcuLeerYuRi0NIYCmjxOMpjawQCROJTx2rWSESixglLty6DFXVyyTRMOsyE8gkNgFV iV+L7UEaRAQkJH71X2UEqWEW6GCU2DFxMyNIQljAR2LazM/MIPUsQPVHFseAhHkF3CWenN7J CLFMTuLDnkfsIDangIfEos8LmUFsIaCaSz2LWEBmSgjcZ5No/jIVrIhFQEDi2+RDLBDfyEps OsAMMUdS4uCKGywTGIUXMDKsYhRNLUguKE5KLzLSK07MLS7NS9dLzs/dxAgMxtP/nvXtYLx5 wPoQYzLQuInMUqLJ+cBgziuJNzQ2MTc1NjUzsrS0NCVNWEmcV/6STKCQQHpiSWp2ampBalF8 UWlOavEhRiYOTqkGRlkN9QX9msWGnj8DPYqMlh+3YtJx0dj+oI/92/fJLn+T1gW82RB85sJ2 iQ/1nSf0EwKEzJ54xN6Lfe6vY5f0aENUEqvj3AsdE1TnTpt1vU7LcclyDcE7v4t/CC0VdOfS rIplip20cDqD9NYyfvHwe6enheRWlf17kLixpHP6c2XTjDlS6jlflViKMxINtZiLihMBJt8f elwCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGIsWRmVeSWpSXmKPExsVy+t9jAd05r00DDTorLR6uv8liMeXwFxYH Jo871/awBTBGNTDaZKQmpqQWKaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoqufgE 6Lpl5gCNVlIoS8wpBQoFJBYXK+nbYZoQGuKmawHTGKHrGxIE12NkgAYS1jBmrF/wgK1ggVnF h+fL2RsYZ2l3MXJySAiYSHzqWM0KYYtJXLi3nq2LkYtDSGARo8SFW5ehnF4miYZZl5m6GDk4 2ARUJX4ttgdpEBGQkPjVf5URpIZZoINRYsfEzYwgCWEBH4lpMz8zg9SzANUfWRwDEuYVcJd4 cnonI8QyOYkPex6xg9icAh4Siz4vZAaxhYBqLvUsYpnAyLuAkWEVo2hqQXJBcVJ6rqFecWJu cWleul5yfu4mRnCoP5PawbiyweIQowAHoxIPL8NRk0Ah1sSy4srcQ4wSHMxKIrw7n5oGCvGm JFZWpRblxxeV5qQWH2JMBjpqIrOUaHI+MA7zSuINjU3MTY1NLU0sTMwsSRNWEudlPPUkQEgg PbEkNTs1tSC1CGYLEwenVANjzqFstYsOnvd9a1fskkhtfnTwkviOuZdEbudtqBbRP1ldefDD 0YdmWm7zDtp8eLL2at5NlrUvoj0e3RA0nfCm+wTPgWN7Fk76519w2v+klF0qu/X0edGx62T2 /K/OE+Hy4BTRPSU6KXlnj9+SPpvv9+/sOymx9HaE3ffN27mWbpNwl1sb97teSomlOCPRUIu5 qDgRAE9Ev2O5AgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQkVCVtJJarRZ8XtbF0paOnxoHwQOY/jNeZMLkqMlCpy0OH3k7kdnNBvnsLA19widmVy9qWs This patch adds APIs to access(open / close) and to resize boot partiton of EMMC. Signed-off-by: Amar Acked-by: Simon Glass --- Changes since V1: New patch. Changes since V2: 1)Updation of commit message and resubmition of proper patch set. Changes since V3: No change. Changes since V4: 1)Replaced the functions mmc_boot_open() & mmc_boot_close() with a single function mmc_boot_part_access(). Changes since V5: 1)Updated in response to review comments. Changes since V6: 1)Added spaces around << operator, in response to review comments. drivers/mmc/mmc.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/mmc.h | 26 +++++++++++ 2 files changed, 158 insertions(+) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 72e8ce6..d3e4bf7 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1327,3 +1327,135 @@ int mmc_initialize(bd_t *bis) return 0; } + +/* + * This function changes the size of boot partition and the size of rpmb + * partition present on EMMC devices. + * + * Input Parameters: + * struct *mmc: pointer for the mmc device strcuture + * bootsize: size of boot partition + * rpmbsize: size of rpmb partition + * + * Returns 0 on success. + */ + +int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize, + unsigned long rpmbsize) +{ + int err; + struct mmc_cmd cmd; + + /* Only use this command for raw EMMC moviNAND. Enter backdoor mode */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = MMC_CMD62_ARG1; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error1 = %d\n", err); + return err; + } + + /* Boot partition changing mode */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = MMC_CMD62_ARG2; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error2 = %d\n", err); + return err; + } + /* boot partition size is multiple of 128KB */ + bootsize = (bootsize * 1024) / 128; + + /* Arg: boot partition size */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = bootsize; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error3 = %d\n", err); + return err; + } + /* RPMB partition size is multiple of 128KB */ + rpmbsize = (rpmbsize * 1024) / 128; + /* Arg: RPMB partition size */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = rpmbsize; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error4 = %d\n", err); + return err; + } + return 0; +} + +/* + * This function shall form and send the commands to open / close the + * boot partition specified by user. + * + * Input Parameters: + * ack: 0x0 - No boot acknowledge sent (default) + * 0x1 - Boot acknowledge sent during boot operation + * part_num: User selects boot data that will be sent to master + * 0x0 - Device not boot enabled (default) + * 0x1 - Boot partition 1 enabled for boot + * 0x2 - Boot partition 2 enabled for boot + * access: User selects partitions to access + * 0x0 : No access to boot partition (default) + * 0x1 : R/W boot partition 1 + * 0x2 : R/W boot partition 2 + * 0x3 : R/W Replay Protected Memory Block (RPMB) + * + * Returns 0 on success. + */ +int mmc_boot_part_access(struct mmc *mmc, u32 ack, u32 part_num, u32 access) +{ + int err; + struct mmc_cmd cmd; + + /* Boot ack enable, boot partition enable , boot partition access */ + cmd.cmdidx = MMC_CMD_SWITCH; + cmd.resp_type = MMC_RSP_R1b; + + cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | + (EXT_CSD_PART_CONF << 16) | + ((EXT_CSD_BOOT_ACK(ack) | + EXT_CSD_BOOT_PART_NUM(part_num) | + EXT_CSD_PARTITION_ACCESS(access)) << 8); + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + if (access) { + debug("mmc boot partition#%d open failure:" + "Error1 = %d\n", part_num, err); + } else { + debug("mmc boot partition#%d close failure:" + "Error = %d\n", part_num, err); + } + return err; + } + + if (access) { + /* 4bit transfer mode at booting time. */ + cmd.cmdidx = MMC_CMD_SWITCH; + cmd.resp_type = MMC_RSP_R1b; + + cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | + (EXT_CSD_BOOT_BUS_WIDTH << 16) | + ((1 << 0) << 8); + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc boot partition#%d open failure:" + "Error2 = %d\n", part_num, err); + return err; + } + } + return 0; +} diff --git a/include/mmc.h b/include/mmc.h index a13e2bd..cbbe02d 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -86,6 +86,11 @@ #define MMC_CMD_APP_CMD 55 #define MMC_CMD_SPI_READ_OCR 58 #define MMC_CMD_SPI_CRC_ON_OFF 59 +#define MMC_CMD_RES_MAN 62 + +#define MMC_CMD62_ARG1 0xefac62ec +#define MMC_CMD62_ARG2 0xcbaea7 + #define SD_CMD_SEND_RELATIVE_ADDR 3 #define SD_CMD_SWITCH_FUNC 6 @@ -153,6 +158,7 @@ */ #define EXT_CSD_PARTITIONING_SUPPORT 160 /* RO */ #define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ +#define EXT_CSD_BOOT_BUS_WIDTH 177 #define EXT_CSD_PART_CONF 179 /* R/W */ #define EXT_CSD_BUS_WIDTH 183 /* R/W */ #define EXT_CSD_HS_TIMING 185 /* R/W */ @@ -177,6 +183,16 @@ #define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */ #define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */ +#define EXT_CSD_BOOT_ACK_ENABLE (1 << 6) +#define EXT_CSD_BOOT_PARTITION_ENABLE (1 << 3) +#define EXT_CSD_PARTITION_ACCESS_ENABLE (1 << 0) +#define EXT_CSD_PARTITION_ACCESS_DISABLE (0 << 0) + +#define EXT_CSD_BOOT_ACK(x) (x << 6) +#define EXT_CSD_BOOT_PART_NUM(x) (x << 3) +#define EXT_CSD_PARTITION_ACCESS(x) (x << 0) + + #define R1_ILLEGAL_COMMAND (1 << 22) #define R1_APP_CMD (1 << 5) @@ -201,6 +217,11 @@ #define PART_ACCESS_MASK (0x7) #define PART_SUPPORT (0x1) +/* The number of MMC physical partitions. These consist of: + * boot partitions (2), general purpose partitions (4) in MMC v4.4. + */ +#define MMC_NUM_BOOT_PARTITION 2 + struct mmc_cid { unsigned long psn; unsigned short oid; @@ -275,6 +296,11 @@ int board_mmc_getcd(struct mmc *mmc); int mmc_switch_part(int dev_num, unsigned int part_num); int mmc_getcd(struct mmc *mmc); void spl_mmc_load(void) __noreturn; +/* Function to change the size of boot partition and rpmb partitions */ +int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize, + unsigned long rpmbsize); +/* Function to send commands to open/close the specified boot partition */ +int mmc_boot_part_access(struct mmc *mmc, u32 ack, u32 part_num, u32 access); #ifdef CONFIG_GENERIC_MMC #define mmc_host_is_spi(mmc) ((mmc)->host_caps & MMC_MODE_SPI)