Commit 097bf5dcf79a3fc461c3e27102113cac7372afcf
1 parent
764cc673d3
Exists in
smarc_8mm-imx_v2019.04_4.19.35_1.1.0
and in
1 other branch
MLK-22293-5 env: Update SATA env location driver to use SCSI
When DM SCSI is enabled with AHCI, use SCSI device to replace SATA device to access the peripheral. Signed-off-by: Ye Li <ye.li@nxp.com>
Showing 1 changed file with 18 additions and 0 deletions Inline Diff
env/sata.c
| 1 | // SPDX-License-Identifier: GPL-2.0+ | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* | 2 | /* |
| 3 | * (C) Copyright 2010-2016 Freescale Semiconductor, Inc. | 3 | * (C) Copyright 2010-2016 Freescale Semiconductor, Inc. |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | /* #define DEBUG */ | 6 | /* #define DEBUG */ |
| 7 | 7 | ||
| 8 | #include <common.h> | 8 | #include <common.h> |
| 9 | 9 | ||
| 10 | #include <command.h> | 10 | #include <command.h> |
| 11 | #include <environment.h> | 11 | #include <environment.h> |
| 12 | #include <linux/stddef.h> | 12 | #include <linux/stddef.h> |
| 13 | #include <errno.h> | 13 | #include <errno.h> |
| 14 | #include <memalign.h> | 14 | #include <memalign.h> |
| 15 | #include <sata.h> | 15 | #include <sata.h> |
| 16 | #include <search.h> | 16 | #include <search.h> |
| 17 | #ifdef CONFIG_DM_SCSI | ||
| 18 | #include <scsi.h> | ||
| 19 | #endif | ||
| 17 | 20 | ||
| 18 | #if defined(CONFIG_ENV_SIZE_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND) | 21 | #if defined(CONFIG_ENV_SIZE_REDUND) || defined(CONFIG_ENV_OFFSET_REDUND) |
| 19 | #error ENV REDUND not supported | 22 | #error ENV REDUND not supported |
| 20 | #endif | 23 | #endif |
| 21 | 24 | ||
| 22 | #if !defined(CONFIG_ENV_OFFSET) || !defined(CONFIG_ENV_SIZE) | 25 | #if !defined(CONFIG_ENV_OFFSET) || !defined(CONFIG_ENV_SIZE) |
| 23 | #error CONFIG_ENV_OFFSET or CONFIG_ENV_SIZE not defined | 26 | #error CONFIG_ENV_OFFSET or CONFIG_ENV_SIZE not defined |
| 24 | #endif | 27 | #endif |
| 25 | 28 | ||
| 26 | __weak int sata_get_env_dev(void) | 29 | __weak int sata_get_env_dev(void) |
| 27 | { | 30 | { |
| 28 | return CONFIG_SYS_SATA_ENV_DEV; | 31 | return CONFIG_SYS_SATA_ENV_DEV; |
| 29 | } | 32 | } |
| 30 | 33 | ||
| 31 | #ifdef CONFIG_CMD_SAVEENV | 34 | #ifdef CONFIG_CMD_SAVEENV |
| 32 | static inline int write_env(struct blk_desc *sata, unsigned long size, | 35 | static inline int write_env(struct blk_desc *sata, unsigned long size, |
| 33 | unsigned long offset, void *buffer) | 36 | unsigned long offset, void *buffer) |
| 34 | { | 37 | { |
| 35 | uint blk_start, blk_cnt, n; | 38 | uint blk_start, blk_cnt, n; |
| 36 | 39 | ||
| 37 | blk_start = ALIGN(offset, sata->blksz) / sata->blksz; | 40 | blk_start = ALIGN(offset, sata->blksz) / sata->blksz; |
| 38 | blk_cnt = ALIGN(size, sata->blksz) / sata->blksz; | 41 | blk_cnt = ALIGN(size, sata->blksz) / sata->blksz; |
| 39 | 42 | ||
| 40 | n = blk_dwrite(sata, blk_start, blk_cnt, buffer); | 43 | n = blk_dwrite(sata, blk_start, blk_cnt, buffer); |
| 41 | 44 | ||
| 42 | return (n == blk_cnt) ? 0 : -1; | 45 | return (n == blk_cnt) ? 0 : -1; |
| 43 | } | 46 | } |
| 44 | 47 | ||
| 45 | static int env_sata_save(void) | 48 | static int env_sata_save(void) |
| 46 | { | 49 | { |
| 47 | ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); | 50 | ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); |
| 48 | struct blk_desc *sata = NULL; | 51 | struct blk_desc *sata = NULL; |
| 49 | int env_sata, ret; | 52 | int env_sata, ret; |
| 50 | 53 | ||
| 54 | #ifndef CONFIG_DM_SCSI | ||
| 51 | if (sata_initialize()) | 55 | if (sata_initialize()) |
| 52 | return 1; | 56 | return 1; |
| 53 | 57 | ||
| 54 | env_sata = sata_get_env_dev(); | 58 | env_sata = sata_get_env_dev(); |
| 55 | 59 | ||
| 56 | sata = sata_get_dev(env_sata); | 60 | sata = sata_get_dev(env_sata); |
| 61 | #else | ||
| 62 | scsi_scan(false); | ||
| 63 | env_sata = sata_get_env_dev(); | ||
| 64 | |||
| 65 | sata = blk_get_dev("scsi", env_sata); | ||
| 66 | #endif | ||
| 57 | if (sata == NULL) { | 67 | if (sata == NULL) { |
| 58 | printf("Unknown SATA(%d) device for environment!\n", | 68 | printf("Unknown SATA(%d) device for environment!\n", |
| 59 | env_sata); | 69 | env_sata); |
| 60 | return 1; | 70 | return 1; |
| 61 | } | 71 | } |
| 62 | 72 | ||
| 63 | ret = env_export(env_new); | 73 | ret = env_export(env_new); |
| 64 | if (ret) | 74 | if (ret) |
| 65 | return 1; | 75 | return 1; |
| 66 | 76 | ||
| 67 | printf("Writing to SATA(%d)...", env_sata); | 77 | printf("Writing to SATA(%d)...", env_sata); |
| 68 | if (write_env(sata, CONFIG_ENV_SIZE, env_get_offset(CONFIG_ENV_OFFSET), (u_char *)env_new)) { | 78 | if (write_env(sata, CONFIG_ENV_SIZE, env_get_offset(CONFIG_ENV_OFFSET), (u_char *)env_new)) { |
| 69 | puts("failed\n"); | 79 | puts("failed\n"); |
| 70 | return 1; | 80 | return 1; |
| 71 | } | 81 | } |
| 72 | 82 | ||
| 73 | puts("done\n"); | 83 | puts("done\n"); |
| 74 | return 0; | 84 | return 0; |
| 75 | } | 85 | } |
| 76 | #endif /* CONFIG_CMD_SAVEENV */ | 86 | #endif /* CONFIG_CMD_SAVEENV */ |
| 77 | 87 | ||
| 78 | static inline int read_env(struct blk_desc *sata, unsigned long size, | 88 | static inline int read_env(struct blk_desc *sata, unsigned long size, |
| 79 | unsigned long offset, void *buffer) | 89 | unsigned long offset, void *buffer) |
| 80 | { | 90 | { |
| 81 | uint blk_start, blk_cnt, n; | 91 | uint blk_start, blk_cnt, n; |
| 82 | 92 | ||
| 83 | blk_start = ALIGN(offset, sata->blksz) / sata->blksz; | 93 | blk_start = ALIGN(offset, sata->blksz) / sata->blksz; |
| 84 | blk_cnt = ALIGN(size, sata->blksz) / sata->blksz; | 94 | blk_cnt = ALIGN(size, sata->blksz) / sata->blksz; |
| 85 | 95 | ||
| 86 | n = blk_dread(sata, blk_start, blk_cnt, buffer); | 96 | n = blk_dread(sata, blk_start, blk_cnt, buffer); |
| 87 | 97 | ||
| 88 | return (n == blk_cnt) ? 0 : -1; | 98 | return (n == blk_cnt) ? 0 : -1; |
| 89 | } | 99 | } |
| 90 | 100 | ||
| 91 | static int env_sata_load(void) | 101 | static int env_sata_load(void) |
| 92 | { | 102 | { |
| 93 | ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); | 103 | ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); |
| 94 | struct blk_desc *sata = NULL; | 104 | struct blk_desc *sata = NULL; |
| 95 | int env_sata; | 105 | int env_sata; |
| 96 | 106 | ||
| 107 | #ifndef CONFIG_DM_SCSI | ||
| 97 | if (sata_initialize()) | 108 | if (sata_initialize()) |
| 98 | return -EIO; | 109 | return -EIO; |
| 99 | 110 | ||
| 100 | env_sata = sata_get_env_dev(); | 111 | env_sata = sata_get_env_dev(); |
| 101 | 112 | ||
| 102 | sata = sata_get_dev(env_sata); | 113 | sata = sata_get_dev(env_sata); |
| 114 | #else | ||
| 115 | scsi_scan(false); | ||
| 116 | env_sata = sata_get_env_dev(); | ||
| 117 | |||
| 118 | sata = blk_get_dev("scsi", env_sata); | ||
| 119 | #endif | ||
| 120 | |||
| 103 | if (sata == NULL) { | 121 | if (sata == NULL) { |
| 104 | printf("Unknown SATA(%d) device for environment!\n", env_sata); | 122 | printf("Unknown SATA(%d) device for environment!\n", env_sata); |
| 105 | return -EIO; | 123 | return -EIO; |
| 106 | } | 124 | } |
| 107 | 125 | ||
| 108 | if (read_env(sata, CONFIG_ENV_SIZE, env_get_offset(CONFIG_ENV_OFFSET), buf)) { | 126 | if (read_env(sata, CONFIG_ENV_SIZE, env_get_offset(CONFIG_ENV_OFFSET), buf)) { |
| 109 | set_default_env(NULL, 0); | 127 | set_default_env(NULL, 0); |
| 110 | return -EIO; | 128 | return -EIO; |
| 111 | } | 129 | } |
| 112 | 130 | ||
| 113 | return env_import(buf, 1); | 131 | return env_import(buf, 1); |
| 114 | } | 132 | } |
| 115 | 133 | ||
| 116 | U_BOOT_ENV_LOCATION(sata) = { | 134 | U_BOOT_ENV_LOCATION(sata) = { |
| 117 | .location = ENVL_ESATA, | 135 | .location = ENVL_ESATA, |
| 118 | ENV_NAME("SATA") | 136 | ENV_NAME("SATA") |
| 119 | .load = env_sata_load, | 137 | .load = env_sata_load, |
| 120 | .save = env_save_ptr(env_sata_save), | 138 | .save = env_save_ptr(env_sata_save), |
| 121 | }; | 139 | }; |
| 122 | 140 |
-
mentioned in commit 712e77
-
mentioned in commit 712e77
-
mentioned in commit 712e77
-
mentioned in commit 712e77
-
mentioned in commit 4ceb43
-
mentioned in commit 4ceb43
-
mentioned in commit 712e77
-
mentioned in commit 4ceb43
-
mentioned in commit 4ceb43
-
mentioned in commit 4ceb43
-
mentioned in commit 4ceb43
-
mentioned in commit b663df
-
mentioned in commit b663df