Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright (C) 2024 PHYTEC Messtechnik GmbH |
| 4 | * Author: Wadim Egorov <w.egorov@phytec.de> |
| 5 | */ |
| 6 | |
| 7 | #include <env_internal.h> |
| 8 | #include <spl.h> |
| 9 | #include <asm/arch/hardware.h> |
| 10 | |
| 11 | #if IS_ENABLED(CONFIG_ENV_IS_IN_FAT) || IS_ENABLED(CONFIG_ENV_IS_IN_MMC) |
| 12 | int mmc_get_env_dev(void) |
| 13 | { |
| 14 | u32 boot_device = get_boot_device(); |
| 15 | |
| 16 | switch (boot_device) { |
| 17 | case BOOT_DEVICE_MMC1: |
| 18 | return 0; |
| 19 | case BOOT_DEVICE_MMC2: |
| 20 | return 1; |
| 21 | }; |
| 22 | |
| 23 | return CONFIG_SYS_MMC_ENV_DEV; |
| 24 | } |
| 25 | #endif |
| 26 | |
| 27 | enum env_location env_get_location(enum env_operation op, int prio) |
| 28 | { |
| 29 | u32 boot_device = get_boot_device(); |
| 30 | |
| 31 | if (prio) |
| 32 | return ENVL_UNKNOWN; |
| 33 | |
| 34 | switch (boot_device) { |
| 35 | case BOOT_DEVICE_MMC1: |
| 36 | case BOOT_DEVICE_MMC2: |
| 37 | if (CONFIG_IS_ENABLED(ENV_IS_IN_FAT)) |
| 38 | return ENVL_FAT; |
| 39 | if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC)) |
| 40 | return ENVL_MMC; |
| 41 | case BOOT_DEVICE_SPI: |
| 42 | if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH)) |
| 43 | return ENVL_SPI_FLASH; |
| 44 | default: |
| 45 | return ENVL_NOWHERE; |
| 46 | }; |
| 47 | } |
| 48 | |
| 49 | #if IS_ENABLED(CONFIG_BOARD_LATE_INIT) |
| 50 | int board_late_init(void) |
| 51 | { |
| 52 | u32 boot_device = get_boot_device(); |
| 53 | |
| 54 | switch (boot_device) { |
| 55 | case BOOT_DEVICE_MMC1: |
| 56 | env_set_ulong("mmcdev", 0); |
| 57 | env_set("boot", "mmc"); |
| 58 | break; |
| 59 | case BOOT_DEVICE_MMC2: |
| 60 | env_set_ulong("mmcdev", 1); |
| 61 | env_set("boot", "mmc"); |
| 62 | break; |
| 63 | case BOOT_DEVICE_SPI: |
| 64 | env_set("boot", "spi"); |
| 65 | break; |
| 66 | case BOOT_DEVICE_ETHERNET: |
| 67 | env_set("boot", "net"); |
| 68 | break; |
| 69 | }; |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | #endif |