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 | |
Daniel Schultz | 80677cb | 2024-05-21 23:18:26 -0700 | [diff] [blame] | 11 | #include "../am6_som_detection.h" |
| 12 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 13 | #if IS_ENABLED(CONFIG_ENV_IS_IN_FAT) || IS_ENABLED(CONFIG_ENV_IS_IN_MMC) |
| 14 | int mmc_get_env_dev(void) |
| 15 | { |
| 16 | u32 boot_device = get_boot_device(); |
| 17 | |
| 18 | switch (boot_device) { |
| 19 | case BOOT_DEVICE_MMC1: |
| 20 | return 0; |
| 21 | case BOOT_DEVICE_MMC2: |
| 22 | return 1; |
| 23 | }; |
| 24 | |
| 25 | return CONFIG_SYS_MMC_ENV_DEV; |
| 26 | } |
| 27 | #endif |
| 28 | |
| 29 | enum env_location env_get_location(enum env_operation op, int prio) |
| 30 | { |
| 31 | u32 boot_device = get_boot_device(); |
| 32 | |
| 33 | if (prio) |
| 34 | return ENVL_UNKNOWN; |
| 35 | |
| 36 | switch (boot_device) { |
| 37 | case BOOT_DEVICE_MMC1: |
| 38 | case BOOT_DEVICE_MMC2: |
| 39 | if (CONFIG_IS_ENABLED(ENV_IS_IN_FAT)) |
| 40 | return ENVL_FAT; |
| 41 | if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC)) |
| 42 | return ENVL_MMC; |
| 43 | case BOOT_DEVICE_SPI: |
| 44 | if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH)) |
| 45 | return ENVL_SPI_FLASH; |
| 46 | default: |
| 47 | return ENVL_NOWHERE; |
| 48 | }; |
| 49 | } |
| 50 | |
| 51 | #if IS_ENABLED(CONFIG_BOARD_LATE_INIT) |
| 52 | int board_late_init(void) |
| 53 | { |
| 54 | u32 boot_device = get_boot_device(); |
| 55 | |
| 56 | switch (boot_device) { |
| 57 | case BOOT_DEVICE_MMC1: |
| 58 | env_set_ulong("mmcdev", 0); |
| 59 | env_set("boot", "mmc"); |
| 60 | break; |
| 61 | case BOOT_DEVICE_MMC2: |
| 62 | env_set_ulong("mmcdev", 1); |
| 63 | env_set("boot", "mmc"); |
| 64 | break; |
| 65 | case BOOT_DEVICE_SPI: |
| 66 | env_set("boot", "spi"); |
| 67 | break; |
| 68 | case BOOT_DEVICE_ETHERNET: |
| 69 | env_set("boot", "net"); |
| 70 | break; |
| 71 | }; |
| 72 | |
Daniel Schultz | 80677cb | 2024-05-21 23:18:26 -0700 | [diff] [blame] | 73 | if (IS_ENABLED(CONFIG_PHYTEC_SOM_DETECTION_BLOCKS)) { |
| 74 | struct phytec_api3_element *block_element; |
| 75 | struct phytec_eeprom_data data; |
| 76 | int ret; |
| 77 | |
| 78 | ret = phytec_eeprom_data_setup(&data, 0, EEPROM_ADDR); |
| 79 | if (ret || !data.valid) |
| 80 | return 0; |
| 81 | |
| 82 | PHYTEC_API3_FOREACH_BLOCK(block_element, &data) { |
| 83 | switch (block_element->block_type) { |
| 84 | case PHYTEC_API3_BLOCK_MAC: |
| 85 | phytec_blocks_add_mac_to_env(block_element); |
| 86 | break; |
| 87 | default: |
| 88 | debug("%s: Unknown block type %i\n", __func__, |
| 89 | block_element->block_type); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 94 | return 0; |
| 95 | } |
| 96 | #endif |