* Formula to calculate the GPR0 protection range as below: * Start: CSE Region Base Offset * End: Till the end of FITC sub-partition */
| 1745 | * End: Till the end of FITC sub-partition |
| 1746 | */ |
| 1747 | static int calculate_gpr0_range(char *image, int size, |
| 1748 | uint32_t *gpr0_start, uint32_t *gpr0_end) |
| 1749 | { |
| 1750 | struct frba *frba = find_frba(image, size); |
| 1751 | if (!frba) |
| 1752 | return -1; |
| 1753 | |
| 1754 | struct region region = get_region(frba, REGION_ME); |
| 1755 | if (region.size <= 0) { |
| 1756 | fprintf(stderr, "Region %s is disabled in target\n", |
| 1757 | region_name(REGION_ME)); |
| 1758 | return -1; |
| 1759 | } |
| 1760 | |
| 1761 | /* CSE Region Start */ |
| 1762 | uint32_t cse_region_start = region.base; |
| 1763 | /* Get CSE Data Partition Offset */ |
| 1764 | uint8_t cse_data_offset = get_cse_data_partition_offset(); |
| 1765 | if (cse_data_offset == 0xff) { |
| 1766 | fprintf(stderr, "Unsupported platform\n"); |
| 1767 | exit(EXIT_FAILURE); |
| 1768 | } |
| 1769 | const uint32_t *data_part_offset_ptr = (uint32_t *)(image + cse_region_start + |
| 1770 | cse_data_offset); |
| 1771 | if (!PTR_IN_RANGE(data_part_offset_ptr, image, size)) { |
| 1772 | fprintf(stderr, "Data part offset %d exceeds image size %d\n", |
| 1773 | cse_region_start + cse_data_offset, size); |
| 1774 | return -1; |
| 1775 | } |
| 1776 | uint32_t data_part_offset = *data_part_offset_ptr; |
| 1777 | |
| 1778 | /* Start reading the CSE Data Partition Table, also known as FPT */ |
| 1779 | uint32_t data_part_start = data_part_offset + cse_region_start; |
| 1780 | struct cse_fpt *fpt = (struct cse_fpt *)(image + data_part_start); |
| 1781 | if (!PTR_IN_RANGE(fpt, image, size)) { |
| 1782 | fprintf(stderr, "FPT offset %d exceeds image size %d\n", |
| 1783 | data_part_start, size); |
| 1784 | return -1; |
| 1785 | } |
| 1786 | |
| 1787 | uint32_t fitc_region_start = 0; |
| 1788 | size_t fitc_region_size = 0; |
| 1789 | /* |
| 1790 | * FPT holds entry for own FPT data structure also bunch of sub-partitions. |
| 1791 | * `FITC` is one of such sub-partition entry. |
| 1792 | */ |
| 1793 | if (parse_fitc_table(fpt, &fitc_region_start, &fitc_region_size) < 0) { |
| 1794 | fprintf(stderr, "Unable to find FITC entry\n"); |
| 1795 | return -1; |
| 1796 | } |
| 1797 | |
| 1798 | /* |
| 1799 | * GPR0 protection is configured to the following range: |
| 1800 | * start: CSE region base offset |
| 1801 | * end: Till the end of FITC sub-partition (i.e. CSE region + data partition offset + |
| 1802 | * FITC sub partition offset + FITC sub partition size) |
| 1803 | */ |
| 1804 | *gpr0_start = cse_region_start; |
no test coverage detected