Commit 4ceb4355c2e5ad7e361497f7ec56cb478a9ef636
1 parent
92e4cc082e
Exists in
smarc_8mq_lf_v2020.04
and in
4 other branches
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> (cherry picked from commit 097bf5dcf79a3fc461c3e27102113cac7372afcf)
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 <env.h> | 11 | #include <env.h> |
| 12 | #include <env_internal.h> | 12 | #include <env_internal.h> |
| 13 | #include <linux/stddef.h> | 13 | #include <linux/stddef.h> |
| 14 | #include <errno.h> | 14 | #include <errno.h> |
| 15 | #include <memalign.h> | 15 | #include <memalign.h> |
| 16 | #include <sata.h> | 16 | #include <sata.h> |
| 17 | #include <search.h> | 17 | #include <search.h> |
| 18 | #ifdef CONFIG_DM_SCSI | ||
| 19 | #include <scsi.h> | ||
| 20 | #endif | ||
| 18 | 21 | ||
| 19 | #if defined(CONFIG_ENV_OFFSET_REDUND) | 22 | #if defined(CONFIG_ENV_OFFSET_REDUND) |
| 20 | #error ENV REDUND not supported | 23 | #error ENV REDUND not supported |
| 21 | #endif | 24 | #endif |
| 22 | 25 | ||
| 23 | #if !defined(CONFIG_ENV_OFFSET) || !defined(CONFIG_ENV_SIZE) | 26 | #if !defined(CONFIG_ENV_OFFSET) || !defined(CONFIG_ENV_SIZE) |
| 24 | #error CONFIG_ENV_OFFSET or CONFIG_ENV_SIZE not defined | 27 | #error CONFIG_ENV_OFFSET or CONFIG_ENV_SIZE not defined |
| 25 | #endif | 28 | #endif |
| 26 | 29 | ||
| 27 | __weak int sata_get_env_dev(void) | 30 | __weak int sata_get_env_dev(void) |
| 28 | { | 31 | { |
| 29 | return CONFIG_SYS_SATA_ENV_DEV; | 32 | return CONFIG_SYS_SATA_ENV_DEV; |
| 30 | } | 33 | } |
| 31 | 34 | ||
| 32 | #ifdef CONFIG_CMD_SAVEENV | 35 | #ifdef CONFIG_CMD_SAVEENV |
| 33 | static inline int write_env(struct blk_desc *sata, unsigned long size, | 36 | static inline int write_env(struct blk_desc *sata, unsigned long size, |
| 34 | unsigned long offset, void *buffer) | 37 | unsigned long offset, void *buffer) |
| 35 | { | 38 | { |
| 36 | uint blk_start, blk_cnt, n; | 39 | uint blk_start, blk_cnt, n; |
| 37 | 40 | ||
| 38 | blk_start = ALIGN(offset, sata->blksz) / sata->blksz; | 41 | blk_start = ALIGN(offset, sata->blksz) / sata->blksz; |
| 39 | blk_cnt = ALIGN(size, sata->blksz) / sata->blksz; | 42 | blk_cnt = ALIGN(size, sata->blksz) / sata->blksz; |
| 40 | 43 | ||
| 41 | n = blk_dwrite(sata, blk_start, blk_cnt, buffer); | 44 | n = blk_dwrite(sata, blk_start, blk_cnt, buffer); |
| 42 | 45 | ||
| 43 | return (n == blk_cnt) ? 0 : -1; | 46 | return (n == blk_cnt) ? 0 : -1; |
| 44 | } | 47 | } |
| 45 | 48 | ||
| 46 | static int env_sata_save(void) | 49 | static int env_sata_save(void) |
| 47 | { | 50 | { |
| 48 | ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); | 51 | ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1); |
| 49 | struct blk_desc *sata = NULL; | 52 | struct blk_desc *sata = NULL; |
| 50 | int env_sata, ret; | 53 | int env_sata, ret; |
| 51 | 54 | ||
| 55 | #ifndef CONFIG_DM_SCSI | ||
| 52 | if (sata_initialize()) | 56 | if (sata_initialize()) |
| 53 | return 1; | 57 | return 1; |
| 54 | 58 | ||
| 55 | env_sata = sata_get_env_dev(); | 59 | env_sata = sata_get_env_dev(); |
| 56 | 60 | ||
| 57 | sata = sata_get_dev(env_sata); | 61 | sata = sata_get_dev(env_sata); |
| 62 | #else | ||
| 63 | scsi_scan(false); | ||
| 64 | env_sata = sata_get_env_dev(); | ||
| 65 | |||
| 66 | sata = blk_get_dev("scsi", env_sata); | ||
| 67 | #endif | ||
| 58 | if (sata == NULL) { | 68 | if (sata == NULL) { |
| 59 | printf("Unknown SATA(%d) device for environment!\n", | 69 | printf("Unknown SATA(%d) device for environment!\n", |
| 60 | env_sata); | 70 | env_sata); |
| 61 | return 1; | 71 | return 1; |
| 62 | } | 72 | } |
| 63 | 73 | ||
| 64 | ret = env_export(env_new); | 74 | ret = env_export(env_new); |
| 65 | if (ret) | 75 | if (ret) |
| 66 | return 1; | 76 | return 1; |
| 67 | 77 | ||
| 68 | printf("Writing to SATA(%d)...", env_sata); | 78 | printf("Writing to SATA(%d)...", env_sata); |
| 69 | if (write_env(sata, CONFIG_ENV_SIZE, env_get_offset(CONFIG_ENV_OFFSET), (u_char *)env_new)) { | 79 | if (write_env(sata, CONFIG_ENV_SIZE, env_get_offset(CONFIG_ENV_OFFSET), (u_char *)env_new)) { |
| 70 | puts("failed\n"); | 80 | puts("failed\n"); |
| 71 | return 1; | 81 | return 1; |
| 72 | } | 82 | } |
| 73 | 83 | ||
| 74 | puts("done\n"); | 84 | puts("done\n"); |
| 75 | return 0; | 85 | return 0; |
| 76 | } | 86 | } |
| 77 | #endif /* CONFIG_CMD_SAVEENV */ | 87 | #endif /* CONFIG_CMD_SAVEENV */ |
| 78 | 88 | ||
| 79 | static inline int read_env(struct blk_desc *sata, unsigned long size, | 89 | static inline int read_env(struct blk_desc *sata, unsigned long size, |
| 80 | unsigned long offset, void *buffer) | 90 | unsigned long offset, void *buffer) |
| 81 | { | 91 | { |
| 82 | uint blk_start, blk_cnt, n; | 92 | uint blk_start, blk_cnt, n; |
| 83 | 93 | ||
| 84 | blk_start = ALIGN(offset, sata->blksz) / sata->blksz; | 94 | blk_start = ALIGN(offset, sata->blksz) / sata->blksz; |
| 85 | blk_cnt = ALIGN(size, sata->blksz) / sata->blksz; | 95 | blk_cnt = ALIGN(size, sata->blksz) / sata->blksz; |
| 86 | 96 | ||
| 87 | n = blk_dread(sata, blk_start, blk_cnt, buffer); | 97 | n = blk_dread(sata, blk_start, blk_cnt, buffer); |
| 88 | 98 | ||
| 89 | return (n == blk_cnt) ? 0 : -1; | 99 | return (n == blk_cnt) ? 0 : -1; |
| 90 | } | 100 | } |
| 91 | 101 | ||
| 92 | static int env_sata_load(void) | 102 | static int env_sata_load(void) |
| 93 | { | 103 | { |
| 94 | ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); | 104 | ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); |
| 95 | struct blk_desc *sata = NULL; | 105 | struct blk_desc *sata = NULL; |
| 96 | int env_sata; | 106 | int env_sata; |
| 97 | 107 | ||
| 108 | #ifndef CONFIG_DM_SCSI | ||
| 98 | if (sata_initialize()) | 109 | if (sata_initialize()) |
| 99 | return -EIO; | 110 | return -EIO; |
| 100 | 111 | ||
| 101 | env_sata = sata_get_env_dev(); | 112 | env_sata = sata_get_env_dev(); |
| 102 | 113 | ||
| 103 | sata = sata_get_dev(env_sata); | 114 | sata = sata_get_dev(env_sata); |
| 115 | #else | ||
| 116 | scsi_scan(false); | ||
| 117 | env_sata = sata_get_env_dev(); | ||
| 118 | |||
| 119 | sata = blk_get_dev("scsi", env_sata); | ||
| 120 | #endif | ||
| 121 | |||
| 104 | if (sata == NULL) { | 122 | if (sata == NULL) { |
| 105 | printf("Unknown SATA(%d) device for environment!\n", env_sata); | 123 | printf("Unknown SATA(%d) device for environment!\n", env_sata); |
| 106 | return -EIO; | 124 | return -EIO; |
| 107 | } | 125 | } |
| 108 | 126 | ||
| 109 | if (read_env(sata, CONFIG_ENV_SIZE, env_get_offset(CONFIG_ENV_OFFSET), buf)) { | 127 | if (read_env(sata, CONFIG_ENV_SIZE, env_get_offset(CONFIG_ENV_OFFSET), buf)) { |
| 110 | env_set_default(NULL, 0); | 128 | env_set_default(NULL, 0); |
| 111 | return -EIO; | 129 | return -EIO; |
| 112 | } | 130 | } |
| 113 | 131 | ||
| 114 | return env_import(buf, 1); | 132 | return env_import(buf, 1); |
| 115 | } | 133 | } |
| 116 | 134 | ||
| 117 | U_BOOT_ENV_LOCATION(sata) = { | 135 | U_BOOT_ENV_LOCATION(sata) = { |
| 118 | .location = ENVL_ESATA, | 136 | .location = ENVL_ESATA, |
| 119 | ENV_NAME("SATA") | 137 | ENV_NAME("SATA") |
| 120 | .load = env_sata_load, | 138 | .load = env_sata_load, |
| 121 | .save = env_save_ptr(env_sata_save), | 139 | .save = env_save_ptr(env_sata_save), |
| 122 | }; | 140 | }; |
| 123 | 141 |