Improve XSD and XML format

This commit is contained in:
Mario Hüttel 2023-01-04 14:35:34 +01:00
parent ea81d0a8fd
commit 3bd46d888d
2 changed files with 45 additions and 14 deletions

View File

@ -1,34 +1,62 @@
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="dec_hex_num">
<xs:restriction base="xs:string">
<xs:pattern value="([0-9]+|0x[0-9a-fA-F]+)"></xs:pattern>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="elfclass_type">
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="32"/>
<xs:maxInclusive value="32"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="64"/>
<xs:maxInclusive value="64"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<!-- This is in case something unsupported is encountered -->
<xs:restriction base="xs:integer">
<xs:minInclusive value="-1"/>
<xs:maxInclusive value="-1"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
<xs:element name="patchelfcrc">
<xs:complexType>
<xs:sequence>
<xs:element name="settings">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="poly"/>
<xs:element type="xs:string" name="start"/>
<xs:element type="xs:string" name="rev"/>
<xs:element type="xs:string" name="xor"/>
<xs:element type="xs:integer" name="elfclass"/>
<xs:element type="dec_hex_num" name="poly"/>
<xs:element type="dec_hex_num" name="start"/>
<xs:element type="xs:string" fixed="" name="rev" minOccurs="0" maxOccurs="1"/>
<xs:element type="dec_hex_num" name="xor"/>
<xs:element type="elfclass_type" name="elfclass"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sections">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="crc">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:extension base="dec_hex_num">
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:integer" name="index"/>
<xs:attribute type="xs:string" name="vma"/>
<xs:attribute type="xs:string" name="size"/>
<xs:attribute type="dec_hex_num" name="index"/>
<xs:attribute type="dec_hex_num" name="vma"/>
<xs:attribute type="dec_hex_num" name="size"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>

View File

@ -40,8 +40,8 @@ int xml_write_crcs_to_file(const char *path, const uint32_t *crcs, SlList *secti
goto ret_none;
}
//xmlTextWriterSetIndentString(writer, BAD_CAST "\t");
//xmlTextWriterSetIndent(writer, 1);
xmlTextWriterSetIndentString(writer, BAD_CAST "\t");
xmlTextWriterSetIndent(writer, 1);
xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
/* Generate the root node */
@ -51,7 +51,10 @@ int xml_write_crcs_to_file(const char *path, const uint32_t *crcs, SlList *secti
xmlTextWriterStartElement(writer, BAD_CAST "settings");
xmlTextWriterWriteFormatElement(writer, BAD_CAST "poly", "0x%" PRIx64, crc_params->polynomial);
xmlTextWriterWriteFormatElement(writer, BAD_CAST "start", "0x%" PRIx32, crc_params->start_value);
xmlTextWriterWriteFormatElement(writer, BAD_CAST "rev", "%s", crc_params->rev ? "true" : "false");
if (crc_params->rev) {
xmlTextWriterStartElement(writer, BAD_CAST "rev");
xmlTextWriterEndElement(writer);
}
xmlTextWriterWriteFormatElement(writer, BAD_CAST "xor", "0x%" PRIx32, crc_params->xor);
bitsize = elf_patch_get_bits(ep);
if (bitsize < 0) {