Commit 4fe428f
committed
image-hd: add support for overridding optional fields of the MBR
The 'holes' property allows to describe holes in an image, for example
to allow writing an image that spans accross the MBR partition
table. The image-hd code creates a fake partition spanning from 440
bytes to 512 bytes to protect the area used by the partition table.
However, it turns out that the Amlogic SoCs have a bootloader that is
precisely written accross the partition table, with some bits before
the partition table and some bits after. But those Amlogic SoCs use
the first 444 bytes, instead of just the first 440 bytes (see [1]).
This is possible because the first 2 fields of the MBR are optional
fields (see [2]). The first optional field is the disk signature (4
bytes), the second optional field is the "copy protect" field (2
bytes).
Therefore, to write a bootloader image for the Amlogic SoCs, we need
to write something like:
image fip/u-boot.bin.sd.bin {
file {
holes = {"(444; 512)"}
}
}
But that isn't accepted because it overlaps with the fake MBR
partition that starts at offset 440.
In order to allow this, the present commit adds a new
'mbr-skip-optionals' property, which tells genimage that we would like
to skip writing those optional fields, allowing the full 446 bytes to
be used, as is needed for Amlogic SoC bootloader images.
Implementation note: we would have preferred to write:
mbr_data += sizeof(struct mbr_tail_optionals);
but genimage has chosen to not allow arithmetic on void* pointers, so
instead we have chosen to use:
mbr_data = &mbr.part_entry[0];
when adjusting the start of the MBR data that have to be inserted
into the image.
This commit also adds two test cases for this new feature:
- One positive test case, where we verify that we can write an image
where the hole is (444, 512) and the mbr-skip-optionals = "true"
option is passed
- One negative test case, where we verify that we are not allowed to
write an image where the hole is (444, 512) when mbr-skip-optionals
= "false".
[1] http://docs.khadas.com/products/sbc/vim3/development/create-bootable-tf-card
[2] https://wiki.osdev.org/MBR_(x86)
Co-Developed-by: Romain Naour <[email protected]>
Signed-off-by: Thomas Petazzoni <[email protected]>1 parent 00009af commit 4fe428f
File tree
5 files changed
+71
-5
lines changed- test
5 files changed
+71
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
428 | 431 | | |
429 | 432 | | |
430 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
70 | 76 | | |
71 | 77 | | |
72 | 78 | | |
| |||
141 | 147 | | |
142 | 148 | | |
143 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
144 | 153 | | |
145 | 154 | | |
146 | 155 | | |
| |||
150 | 159 | | |
151 | 160 | | |
152 | 161 | | |
153 | | - | |
| 162 | + | |
154 | 163 | | |
155 | 164 | | |
156 | 165 | | |
| |||
192 | 201 | | |
193 | 202 | | |
194 | 203 | | |
195 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
196 | 214 | | |
197 | 215 | | |
198 | 216 | | |
| |||
968 | 986 | | |
969 | 987 | | |
970 | 988 | | |
| 989 | + | |
971 | 990 | | |
972 | 991 | | |
973 | 992 | | |
| |||
1029 | 1048 | | |
1030 | 1049 | | |
1031 | 1050 | | |
1032 | | - | |
1033 | | - | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
1034 | 1064 | | |
1035 | 1065 | | |
1036 | 1066 | | |
| |||
1215 | 1245 | | |
1216 | 1246 | | |
1217 | 1247 | | |
| 1248 | + | |
1218 | 1249 | | |
1219 | 1250 | | |
1220 | 1251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
162 | 176 | | |
163 | 177 | | |
164 | 178 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
0 commit comments