bootloader_mem.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <stdbool.h>
  15. #include "xtensa/config/core.h"
  16. #include "hal/cpu_hal.h"
  17. #include "hal/mpu_hal.h"
  18. #include "hal/mpu_types.h"
  19. #include "soc/mpu_caps.h"
  20. #include "bootloader_mem.h"
  21. #include "xt_instr_macros.h"
  22. #include "xtensa/config/specreg.h"
  23. static inline void cpu_configure_region_protection(void)
  24. {
  25. /* Currently, the only supported chips esp32 and esp32s2
  26. * have the same configuration. Move this to the port layer once
  27. * more chips with different configurations are supported.
  28. *
  29. * Both chips have the address space divided into 8 regions, 512MB each.
  30. */
  31. const int illegal_regions[] = {0, 4, 5, 6, 7}; // 0x00000000, 0x80000000, 0xa0000000, 0xc0000000, 0xe0000000
  32. for (int i = 0; i < sizeof(illegal_regions) / sizeof(illegal_regions[0]); ++i) {
  33. mpu_hal_set_region_access(illegal_regions[i], MPU_REGION_ILLEGAL);
  34. }
  35. mpu_hal_set_region_access(1, MPU_REGION_RW); // 0x20000000
  36. }
  37. void bootloader_init_mem(void)
  38. {
  39. cpu_hal_init_hwloop();
  40. // protect memory region
  41. cpu_configure_region_protection();
  42. }