| 906 | } |
| 907 | |
| 908 | static int cbfs_add_component(const char *filename, |
| 909 | const char *name, |
| 910 | uint32_t headeroffset, |
| 911 | convert_buffer_t convert) |
| 912 | { |
| 913 | /* |
| 914 | * The steps used to determine the final placement offset in CBFS, in order: |
| 915 | * |
| 916 | * 1. If --base-address was passed, that value is used. If it was passed in the host |
| 917 | * address space, convert it to flash address space. (After that, |*offset| is always |
| 918 | * in the flash address space.) |
| 919 | * |
| 920 | * 2. The convert() function may write a location back to |offset|, usually by calling |
| 921 | * do_cbfs_locate(). In this case, it needs to ensure that the location found can fit |
| 922 | * the CBFS file in its final form (after any compression and conversion). |
| 923 | * |
| 924 | * 3. If --align was passed and the offset is still undecided at this point, |
| 925 | * do_cbfs_locate() is called to find an appropriately aligned location. |
| 926 | * |
| 927 | * 4. If |offset| is still 0 at the end, cbfs_add_entry() will find the first available |
| 928 | * location that fits. |
| 929 | */ |
| 930 | uint32_t offset = param.baseaddress_assigned ? param.baseaddress : 0; |
| 931 | size_t len_align = 0; |
| 932 | |
| 933 | if (param.alignment && param.baseaddress_assigned) { |
| 934 | ERROR("Cannot specify both alignment and base address\n"); |
| 935 | return 1; |
| 936 | } |
| 937 | |
| 938 | if (param.stage_xip && param.compression != CBFS_COMPRESS_NONE) { |
| 939 | ERROR("Cannot specify compression for XIP.\n"); |
| 940 | return 1; |
| 941 | } |
| 942 | |
| 943 | if (!filename) { |
| 944 | ERROR("You need to specify -f/--filename.\n"); |
| 945 | return 1; |
| 946 | } |
| 947 | |
| 948 | if (!name) { |
| 949 | ERROR("You need to specify -n/--name.\n"); |
| 950 | return 1; |
| 951 | } |
| 952 | |
| 953 | if (param.type == 0) { |
| 954 | ERROR("You need to specify a valid -t/--type.\n"); |
| 955 | return 1; |
| 956 | } |
| 957 | |
| 958 | struct cbfs_image image; |
| 959 | if (cbfs_image_from_buffer(&image, param.image_region, headeroffset)) |
| 960 | return 1; |
| 961 | |
| 962 | if (cbfs_get_entry(&image, name)) { |
| 963 | ERROR("'%s' already in ROM image.\n", name); |
| 964 | return 1; |
| 965 | } |
no test coverage detected