|
| 1 | +/* imx_rt.h |
| 2 | + * |
| 3 | + * Support routines for the i.MX RT HAL, kept free of NXP MCUXpresso SDK |
| 4 | + * dependencies so they can be exercised directly in the host unit tests. |
| 5 | + * |
| 6 | + * Copyright (C) 2026 wolfSSL Inc. |
| 7 | + * |
| 8 | + * This file is part of wolfBoot. |
| 9 | + * |
| 10 | + * wolfBoot is free software; you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU General Public License as published by |
| 12 | + * the Free Software Foundation; either version 3 of the License, or |
| 13 | + * (at your option) any later version. |
| 14 | + * |
| 15 | + * wolfBoot is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU General Public License for more details. |
| 19 | + * |
| 20 | + * You should have received a copy of the GNU General Public License |
| 21 | + * along with this program; if not, write to the Free Software |
| 22 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 23 | + */ |
| 24 | +#ifndef IMX_RT_H |
| 25 | +#define IMX_RT_H |
| 26 | + |
| 27 | +#include <stdint.h> |
| 28 | + |
| 29 | +/* Flash is memory mapped, so after a program/erase, the affected range must |
| 30 | + * be invalidated in the data cache to ensure coherency. The cache line size |
| 31 | + * is 32 bytes, so both the address and length passed to |
| 32 | + * DCACHE_InvalidateByRange() must be 32-byte aligned: the address is rounded |
| 33 | + * down, and the length is rounded up by the same down-alignment offset plus |
| 34 | + * "len", so that the invalidated range always fully covers |
| 35 | + * [address, address + len). */ |
| 36 | +static inline void hal_flash_cache_align_range(uint32_t address, uint32_t len, |
| 37 | + uint32_t *aligned_address, uint32_t *aligned_len) |
| 38 | +{ |
| 39 | + uint32_t start = address - (address % 32); |
| 40 | + uint32_t unaligned_len = len + (address - start); |
| 41 | + |
| 42 | + *aligned_address = start; |
| 43 | + *aligned_len = unaligned_len + ((32 - (unaligned_len % 32)) % 32); |
| 44 | +} |
| 45 | + |
| 46 | +#endif /* IMX_RT_H */ |
0 commit comments