Smart card operating system upgrading method, apparatus and device, storage medium and product
Patent Information
- Application Number
- PCT/CN2025/140446
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2025-04-14
- Filing Date
- 2025-12-05
- Publication Date
- 2026-10-22
Smart Images

Figure CN2025140446_22102026_PF_FP_ABST
Abstract
Description
Smart card operating system upgrade methods, devices, equipment, storage media and products
[0001] Cross-references to related applications
[0002] This application is based on and claims priority to Chinese Patent Application No. 202510462798.X, filed on April 14, 2025, the entire contents of which are incorporated herein by reference. Technical Field
[0003] This application relates to the field of smart card technology, and in particular to a smart card operating system upgrade method, apparatus, device, storage medium, and product. Background Technology
[0004] Smart card software consists of two parts: the smart card operating system (COS) software and application software. Existing smart card COS upgrades mainly include two schemes: full upgrade and differential upgrade.
[0005] (1) Full upgrade. The COS upgrade package is a full package, which contains the complete set of COS software functions. It can be used directly after being downloaded to the smart card. Therefore, the full package requires more storage resources.
[0006] (2) Differential Upgrade. The COS upgrade package is made using a differential algorithm. The COS differential upgrade package is not the complete set of COS software functions. The upgrade file downloaded to the smart card needs to be differentially restored with the old version of COS firmware before it can be used. Differential restoration needs to be completed in Random Access Memory (RAM). Therefore, the differential upgrade process will consume a certain amount of RAM resources. Summary of the Invention
[0007] This application provides a method, apparatus, device, storage medium, and product for upgrading a smart card operating system, in order to solve the problems of existing technologies that require a large amount of storage resources and consume a certain amount of RAM resources.
[0008] To achieve the above objectives, embodiments of this application provide a smart card operating system upgrade method, including:
[0009] The incremental package is downloaded to the incremental space within the smart card; wherein the incremental space is located within the firmware area of the smart card;
[0010] Upgrade using the incremental package.
[0011] As an improvement to the above solution, the upgrade using the incremental package includes:
[0012] For each instruction in each packet of the incremental packet:
[0013] If the instruction is an internal reference, then the instruction is executed according to the offset address in the instruction;
[0014] If the instruction is an external reference, then based on a preset reference table, the instruction is linked according to the offset address in the instruction to obtain a new instruction; and the new instruction is executed according to the reference table.
[0015] The reference table is used to directly or indirectly represent the mapping relationship between the actual address of the data segment in the incremental space and the reference value, wherein the length of the reference value is less than or equal to a preset number of bytes.
[0016] As an improvement to the above scheme, the step of linking the instructions based on the offset address in the instructions according to the preset reference table to obtain new instructions includes:
[0017] Based on the offset address in the instruction, the target actual address of the target data segment indicated by the offset address is obtained;
[0018] Based on a preset reference table, the reference value corresponding to the actual address of the target is obtained;
[0019] The reference value corresponding to the actual target address is overwritten to the offset address to obtain a new instruction.
[0020] As an improvement to the above scheme, the reference table is used to indirectly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space;
[0021] The process of obtaining the reference value corresponding to the actual address of the target based on a preset reference table includes:
[0022] The actual address of the target is found in the reference table to obtain the position of the actual address of the target in the reference table;
[0023] The location is encoded to obtain the reference value corresponding to the actual address of the target.
[0024] As an improvement to the above scheme, the position includes the sub-table position and the sub-table entry position;
[0025] Encoding the location to obtain the reference value corresponding to the actual target address includes:
[0026] The positions of the sub-tables are encoded to obtain a first encoded value;
[0027] The position of the sub-table entry is encoded to obtain a second encoded value;
[0028] Based on the first encoded value and the second encoded value, the reference value corresponding to the actual address of the target is obtained.
[0029] As an improvement to the above scheme, obtaining the target actual address of the target data segment indicated by the offset address based on the offset address in the instruction includes:
[0030] Based on the offset address in the instruction, the target index value of the external package indicated by the offset address is obtained;
[0031] Based on a preset packet registry, the base address of the target data segment indicated by the offset address is obtained according to the target index value; the target data segment is the data segment of the external packet.
[0032] Based on the base address and the offset address, the target actual address of the target data segment indicated by the offset address is obtained.
[0033] As an improvement to the above scheme, executing the new instructions according to the reference table includes:
[0034] Based on the reference table, the target actual address corresponding to the reference value in the new instruction is obtained according to the reference value in the new instruction;
[0035] Execute the new instruction based on the actual address of the target.
[0036] As an improvement to the above scheme, the reference table is used to indirectly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space;
[0037] The step of obtaining the target actual address corresponding to the reference value in the new instruction based on the reference table includes:
[0038] Decode the reference value in the new instruction to obtain the position of the actual target address corresponding to the reference value in the reference table;
[0039] The location is searched in the reference table to obtain the actual address of the location record, which is used as the target actual address corresponding to the reference value in the new instruction.
[0040] As an improvement to the above scheme, the reference table records at least the actual address of the data segment within the incremental space, and the data segment includes at least one of the following: exported segment, class segment, method segment, and static field segment.
[0041] To achieve the above objectives, embodiments of this application also provide a smart card operating system upgrade device, comprising:
[0042] A download module is used to download incremental packages to the incremental space within the smart card; wherein the incremental space is located within the firmware area of the smart card;
[0043] An upgrade module is used to perform upgrades using the incremental package.
[0044] To achieve the above objectives, this application also provides a smart card operating system upgrade device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements the smart card operating system upgrade method as described above.
[0045] To achieve the above objectives, embodiments of this application also provide a computer-readable storage medium, the computer-readable storage medium including a stored computer program; wherein, when the computer program is executed, it controls the device of the computer-readable storage medium to perform the smart card operating system upgrade method as described above.
[0046] To achieve the above objectives, embodiments of this application also provide a computer program product, including a computer program / instructions, which, when executed by a processor, implements the smart card operating system upgrade method as described above.
[0047] Compared with the prior art, the smart card operating system upgrade method, apparatus, device, storage medium, and product provided in this application have the following beneficial effects.
[0048] (1) The incremental packet size is small, saving smart card storage resources;
[0049] (2) Incremental package download time is short, saving data traffic;
[0050] (3) The time required to transmit incremental packets to smart cards is shortened, and the upgrade speed is faster;
[0051] (4) The incremental package can be used directly after being downloaded to the smart card without differential restoration, and will not consume RAM resources, resulting in a better upgrade experience;
[0052] (5) Because it uses an incremental space that is independent of the original COS firmware area, it will not brick the smart card operating system, making the upgrade safer;
[0053] (6) By adding an independent incremental space within the smart card, the original COS firmware functions can remain unchanged while new function code is added to the incremental space, enabling the smart card COS software to be upgraded with new functions quickly. The upgrade process is more efficient, safe, and reliable. Attached Figure Description
[0054] Figure 1 is a flowchart of a smart card operating system upgrade method provided in an embodiment of this application;
[0055] Figure 2 is a general flowchart of a smart card operating system upgrade method provided in an embodiment of this application;
[0056] Figure 3 is a schematic diagram of a smart card storage space layout provided in an embodiment of this application;
[0057] Figure 4 is another schematic diagram of a smart card storage space layout provided in an embodiment of this application;
[0058] Figure 5 is a software architecture diagram of a smart card provided in an embodiment of this application;
[0059] Figure 6 is a schematic diagram of an in-card virtual machine and packet structure provided in an embodiment of this application;
[0060] Figure 7 is a flowchart of a package generation method provided in an embodiment of this application;
[0061] Figure 8 is a schematic diagram of a general instruction format;
[0062] Figure 9 is a schematic diagram of an instruction format using an offset address as an operand provided in an embodiment of this application;
[0063] Figure 10 is a schematic diagram of an instruction format that uses a reference value to overwrite the original offset address according to an embodiment of this application;
[0064] Figure 11 is a schematic diagram of a reference value format provided in an embodiment of this application;
[0065] Figure 12 is another schematic diagram of a reference value format provided in an embodiment of this application;
[0066] Figure 13 is a schematic diagram of a main table format provided in an embodiment of this application;
[0067] Figure 14 is a schematic diagram of a sub-table entry format provided in an embodiment of this application;
[0068] Figure 15 is a schematic diagram of a sub-table format provided in an embodiment of this application;
[0069] Figure 16 is a diagram showing the relationship between a main table and a sub-table provided in an embodiment of this application.
[0070] Figure 17 is a schematic diagram of a package registry format provided in an embodiment of this application;
[0071] Figure 18 is a flowchart of a registration package address information provided in an embodiment of this application;
[0072] Figure 19 is a structural block diagram of a smart card operating system upgrade device provided in an embodiment of this application;
[0073] Figure 20 is a structural block diagram of a smart card operating system upgrade device provided in an embodiment of this application. Detailed Implementation
[0074] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0075] Referring to Figure 1, which is a flowchart of a smart card operating system upgrade method provided in an embodiment of this application, the smart card operating system upgrade method includes:
[0076] S1. Download the incremental package to the incremental space within the smart card; wherein the incremental space is located within the firmware area of the smart card;
[0077] S2. Upgrade using the incremental package.
[0078] It is worth noting that the embodiments of this application are applied to an incremental upgrade system, which includes four parts: a COS upgrade server, a terminal device, a smart card, and a virtual machine within the card.
[0079] COS upgrade server: Responsible for functions such as incremental package (also known as COS incremental upgrade file) configuration and release, upgrade session initiation and maintenance, smart card on-site data collection and analysis, incremental package parsing and adaptation, establishment and maintenance of secure links, card writing script generation and sending, etc.
[0080] Terminal equipment: Responsible for establishing a secure link with the COS upgrade server, establishing a secure communication channel through the cellular mobile communication network, and obtaining incremental packets from the COS upgrade server. It establishes a device-card channel with the smart card through physical interfaces such as ISO 7816, and transmits the incremental packets to the smart card via APDU commands.
[0081] Smart Card: Responsible for providing secure communication capabilities, receiving and parsing incremental packets from the COS upgrade server, and completing COS maintenance and management tasks, including initiating and maintaining secure links, switching card states, initiating and exiting COS upgrade sessions, receiving and storing COS upgrade packets, and verifying the integrity and validity of COS upgrade packets.
[0082] In-card virtual machine: A lightweight Java Virtual Machine within the smart card, responsible for interpreting and executing Java applications within the smart card, and providing the runtime environment for Java applications.
[0083] Figure 2 is a general flowchart of a smart card operating system upgrade method provided in an embodiment of this application. Before downloading the incremental package to the incremental space within the smart card, the method further includes: the COS developer completing the development and verification of the incremental package and releasing it to the COS upgrade server. This enables the COS upgrade server to remotely send the incremental package to the smart card after determining that the smart card needs a COS software incremental upgrade, allowing the smart card to download the incremental package to its incremental space. Before using the incremental package for upgrade, the method further includes: the smart card verifying the incremental package. This allows the COS software incremental upgrade to be performed after verification.
[0084] The firmware area of the smart card described in this application includes at least an incremental space, which is used for storing incremental packets. Furthermore, the firmware area of the smart card may also include a full space, using a combination of full and incremental spaces for storage. The incremental space is used to store incremental packets, while the full space is used to store full packets.
[0085] If the smart card storage space layout adopts a single firmware area design, it needs to include at least one incremental space, as shown in Figure 3, which includes a full space and an incremental space.
[0086] If the smart card storage space layout adopts a dual-partition design (A and B), an incremental space needs to be designed for each firmware partition, resulting in at least two incremental spaces in total, as shown in Figure 4. This includes two full spaces (full space A and full space B) and two incremental spaces (incremental space A and incremental space B). After the smart card operating system boots, only one firmware partition should be active. During upgrades, the incremental package is downloaded to the incremental space corresponding to the currently active firmware partition. For example, if the currently active firmware partition is firmware partition A, the incremental package is downloaded to incremental space A; if the currently active firmware partition is firmware partition B, the incremental package is downloaded to incremental space B.
[0087] In the smart card storage space layout described in this application, the functions of each partition are as follows:
[0088] System area: Responsible for handling smart card operating system reset commands, guiding the firmware area into activation mode, and storing the currently running COS information. After system startup, control is transferred to the activated firmware area or firmware partition.
[0089] Data area: This area stores the file system, applications, and application data. Updating this area is prohibited during the upgrade process.
[0090] Firmware Area: This area stores the COS code. At any given time after system startup, only one firmware area or partition is active. If the smart card uses a dual firmware partition design, during an incremental COS upgrade, the upgrade command should be sent to the currently active firmware, which will then update the data in the incremental space corresponding to the currently active firmware partition. During a full COS upgrade, the code in the incremental space will become invalid, and the corresponding functions will be handled by the full COS upgrade firmware.
[0091] Full space: Used to store all COS firmware functions during a full COS upgrade.
[0092] Incremental space: An area for storing new feature code while keeping the original firmware functionality unchanged. Within each firmware area, the full space also has its corresponding incremental space.
[0093] Figure 5 shows the software architecture of a smart card integrating an on-card virtual machine. The on-card virtual machine described in this application consists of three parts: an execution engine, a runtime environment (RTE), and an application programming interface (API).
[0094] In the smart card described in this application, the COS software provides capability call support to the application software through an API interface. The API described in this application is divided into multiple modules according to different functional sets. Each functional module represents a set of functions, such as the Global Platform (GP) and Universal Integrated Circuit Card (UICC) modules commonly used in smart cards. From a software implementation perspective, one functional module corresponds to one package in the COS software. In the card's virtual machine, a package is a collection of multiple classes or interfaces. A class contains multiple methods and fields, with methods and fields responsible for encapsulating the class's methods and data, respectively. Furthermore, in the smart card described in this application, the executable file of the subsequently downloaded and installed application software also exists in the form of packages, i.e., each package in the incremental package. Each package provides the code implementation of all the classes, interfaces, methods, and data required by that package. The card's virtual machine described in this application is responsible for interpreting and executing the above code and providing capabilities such as smart card authentication, identity recognition, and encryption / decryption.
[0095] The in-card virtual machine and package structure described in this application are shown in Figure 6. The COS software described in this application provides the following support to application software through the in-card virtual machine and a series of packages:
[0096] (1) Runtime support provides the software environment required for application software to run. It mainly defines the behavior of smart card runtime, including the life cycle of virtual machine in card, life cycle of application software in card, logical channel and application selection, temporary objects, application isolation and object sharing, transaction mechanism and atomic operation, etc.
[0097] (2) If the smart card COS software provides user-mode and kernel-mode isolation, it provides application software running in user mode with the function of calling kernel capabilities (such as system calls);
[0098] (3) Other capabilities required by the application software, such as GP, UICC, etc.
[0099] The package described in this application is generated by compiling and transforming Java source code using a compiler and transformation tool in the smart card toolchain. The process of generating the package is shown in Figure 7.
[0100] The package described in this application consists of the following data segments:
[0101] Import section: Information about referenced packages, providing information about other packages referenced by this package;
[0102] Exported section: Static methods and static fields provided by this package for reference by other packages (optional; if the executable does not provide any methods and fields for external reference, the exported section can be deleted);
[0103] Class segment: Classes and interfaces within this package, storing information about all classes and interfaces declared within the package;
[0104] Method segment: This segment contains descriptions of the methods within the package, storing all methods and interfaces declared within the package. Methods use indexes to reference classes, methods, and fields.
[0105] Static fields: Store the values of all static fields defined in this package;
[0106] Constant reference segment: Stores information about all classes, methods, and fields referenced by the method segment, and is divided into class, instance field, virtual method, parent method, static field, and static method;
[0107] Reference location segment: Stores the offset of the index in the method segment.
[0108] The smart card described in this application ultimately needs to retain four data segments: Method, Class, StaticField, and Export.
[0109] The package described in this application may need to reference methods and data fields in external packages (also known as imported packages), and may also need to provide methods and data fields to external packages for reference by external packages. There are two data segments in the package that involve providing reference information to external packages: the exported segment and the class segment. The exported segment is mainly used to expose all static methods and static fields of this package to the outside world, while the class segment is mainly used to expose all public methods of this package to the outside world.
[0110] In one optional embodiment, the upgrade using the incremental package includes:
[0111] For each instruction in each packet of the incremental packet:
[0112] If the instruction is an internal reference, then the instruction is executed according to the offset address in the instruction;
[0113] If the instruction is an external reference, then based on a preset reference table, the instruction is linked according to the offset address in the instruction to obtain a new instruction; and the new instruction is executed according to the reference table.
[0114] The reference table is used to directly or indirectly represent the mapping relationship between the actual address of the data segment in the incremental space and the reference value, wherein the length of the reference value is less than or equal to a preset number of bytes.
[0115] The COS software described in this application supports code instructions consisting of an opcode and operands. Generally, an instruction includes a one-byte opcode and zero or more operands, as shown in Figure 8. These operands represent the values to be operated on by the instruction.
[0116] The code stored in the data segment described in this application mainly refers to bytecode in smart card Java application software. During compilation, the actual address of the operand within the smart card cannot be determined. Furthermore, in the design of on-card virtual machine instructions, such as those using 16-bit registers, the operand's 2-byte length cannot directly store the actual address of the code (3 to 4 bytes). Therefore, the "offset address" within the data segment is generally used as the operand. For example, during a method call, the offset address of the method within the method segment is used as the operand. The instruction format using the offset address is shown in Figure 9.
[0117] The package references described in this application mainly fall into the following two categories:
[0118] 1. Internal references (package references): Instructions are accessed using an offset address within the same package during execution, and no linking is required. This offset address refers to the instruction reference within the same Java Package, relative to the package's base address (i.e., the starting address). In this case, this offset address does not need to be replaced.
[0119] 2. External references (referencing external packages), such as import xx.xx.Package, require linking.
[0120] Generally, after the smart card package is downloaded, if the application software needs to call a method in the package (taking accessing a method in an external package as an example), the following operations are required:
[0121] (1) The virtual machine in the card obtains the offset address of the method to be called;
[0122] (2) The virtual machine in the card is responsible for parsing the import segment of the application software package and finding the import package identifier to which the calling method belongs;
[0123] (3) Locate the imported package in the package address management information by using the imported package identifier;
[0124] (4) Locate the class information in the import package to which the called method belongs, obtain the class segment information, and find the base address of the class;
[0125] (5) Add the base address of operation (4) and the offset address of operation (1) to obtain the actual address of the method in the smart card;
[0126] (6) Access the above actual address to execute the code of the above calling method.
[0127] The aforementioned access and invocation methods involve numerous operations and are time-consuming. To improve the execution efficiency of smart card application code, after a new packet is downloaded to the incremental space, the virtual machine within the card is notified to link it. In some embodiments, based on a preset reference table, the instructions are linked according to the offset address in the instructions to obtain new instructions. After linking is complete, the new instructions are executed according to the reference table.
[0128] The reference table is used to directly or indirectly represent the mapping relationship between the actual address and reference value of the data segment in the incremental space, so that subsequent new instructions can find their corresponding actual address and access and execute them through the reference table. Optionally, the preset byte is 2 bytes.
[0129] In one optional embodiment, the step of linking the instructions based on the offset address in the instructions according to a preset reference table to obtain new instructions includes:
[0130] Based on the offset address in the instruction, the target actual address of the target data segment indicated by the offset address is obtained;
[0131] Based on a preset reference table, the reference value corresponding to the actual address of the target is obtained;
[0132] The reference value corresponding to the actual target address is overwritten to the offset address to obtain a new instruction.
[0133] In this embodiment, the linking process includes: First, the target actual address of the target data segment indicated by the offset address is obtained based on the offset address in the instruction. Since the initially stored offset address is 2 bytes, and the calculated actual address is 3-4 bytes, it cannot be directly replaced in place (insufficient storage length). Therefore, a reference table is created to directly or indirectly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space. Next, based on the reference table, the reference value corresponding to the target actual address is obtained. Finally, the reference value corresponding to the target actual address is overwritten to the offset address to obtain a new instruction. This facilitates the subsequent execution of new instructions by looking up the corresponding target actual address in the reference table using the reference value in the new instruction and accessing and executing it. That is, after linking, the code only needs to "look up the table once" to access the target actual address where the code is located, improving code execution efficiency. After the above linking is completed, the instruction format is shown in Figure 10.
[0134] For example, an incremental package includes two packages, JavaA and JavaB. The JavaA package contains an instruction OPCODE OP_DATA, which is the offset address of the method segment of another package, JavaB. In other words, the target data segment indicated by the offset address OP_DATA is the data segment of JavaB. In this case, JavaB is the import package relative to JavaA.
[0135] When compiling outside the card, the compiler will write this offset address to the position of this operand.
[0136] For the instruction OPCODE OP_DATA, during linking, the actual address of the JavaB method on the card is found based on this offset address OP_DATA, i.e., the target actual address; based on the preset reference table, the reference value REF corresponding to the target actual address is obtained. The reference value REF is written into the JavaA instruction, generating a new instruction OPCODE REF.
[0137] In other words, during linking, the reference value is written as a symbol of the target's actual address to the location of the original operand of the instruction, while the target's actual address is stored in the reference table. When the instruction is actually executed, the target's actual address is obtained by directly looking up the table or by calculating the reference value in the instruction.
[0138] In an optional embodiment, the reference table is used to directly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space;
[0139] The process of obtaining the reference value corresponding to the actual address of the target based on a preset reference table includes:
[0140] The actual address of the target is looked up in the reference table to obtain the reference value corresponding to the actual address of the target.
[0141] In this embodiment of the application, the reference table directly records the actual address and reference value of the data segment in the incremental space. That is, the reference table records the mapping relationship between the actual address and reference value of the data segment in the incremental space. By looking up the table, the reference value corresponding to the target actual address can be obtained directly.
[0142] In one optional embodiment, the reference table is used to indirectly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space;
[0143] The process of obtaining the reference value corresponding to the actual address of the target based on a preset reference table includes:
[0144] The actual address of the target is found in the reference table to obtain the position of the actual address of the target in the reference table;
[0145] The location is encoded to obtain the reference value corresponding to the actual address of the target.
[0146] In this embodiment, the reference table does not directly record the actual address and reference value of the data segment in the incremental space, but only records the actual address of the data segment. By looking up the table, the position of the target actual address in the reference table is obtained, and then the position is encoded to obtain the reference value corresponding to the target actual address, thereby improving flexibility.
[0147] In one optional embodiment, the location includes a sub-table location and a sub-table entry location;
[0148] Encoding the location to obtain the reference value corresponding to the actual target address includes:
[0149] The positions of the sub-tables are encoded to obtain a first encoded value;
[0150] The position of the sub-table entry is encoded to obtain a second encoded value;
[0151] Based on the first encoded value and the second encoded value, the reference value corresponding to the actual address of the target is obtained.
[0152] It is understood that the reference table described in the embodiments of this application includes several sub-tables, such as sub-table 1, sub-table 2, etc. Each sub-table has several entries, hereinafter referred to as sub-table entries, such as sub-table entry 1, sub-table entry 2, etc. For example, if the actual address of the target is located in sub-table 1 and sub-table entry 1, it means that the actual address of the target is recorded at entry 1 of sub-table 1.
[0153] By encoding the sub-table positions and sub-table entry positions respectively, a first encoded value and a second encoded value are obtained. Generally, sub-table positions and sub-table entry positions are represented by decimal numbers. Therefore, the numbers of the sub-table positions and the numbers of the sub-table entry positions are encoded in binary to obtain the first encoded value and the second encoded value.
[0154] Based on the first encoded value and the second encoded value, a reference value corresponding to the target actual address is obtained. For example, the first encoded value and the second encoded value can be directly concatenated to obtain the reference value corresponding to the target actual address; furthermore, the concatenated encoded value is combined with the instruction type to obtain the reference value corresponding to the target actual address, such that the reference value conforms to a length of 2 bytes.
[0155] For example, the reference values described in this application occupy a total length of 2 bytes and have the following two different definition formats:
[0156] The first reference value format is shown in Figure 11. The maximum value of the sub-table entries is set to 128. At this time, there can be 256 sub-tables (numbered 0-255), and each sub-table stores 128 entries (numbered 0-127).
[0157] The second reference value format is shown in Figure 12. The maximum value of the sub-table entries is set to 256. At this time, there can be 128 sub-tables (numbered 0-127), and each sub-table has 256 entries (numbered 0-255).
[0158] To distinguish between internal and external references, the highest bit (MSB) of the reference value is used as a "packet reference flag" to determine the instruction type. A packet reference flag of 0 indicates an internal reference, while a packet reference flag of 1 indicates an external reference. Apart from the packet reference flag, the remaining lower 15 bits (Bit[14:0]) of the reference value are used to represent the sub-table position and sub-table entry position in the reference table.
[0159] Here's an example to help you understand: Suppose the target's actual address is located in the 10th entry of the 3rd sub-table. During the initial compilation, a "reference value" will be generated and placed in the instruction. The process of generating this reference value is as follows:
[0160] For the first reference value format (the maximum value of the sub-table entry is set to 128):
[0161] Encode position 3 of the sub-table in binary. The resulting first encoded value belongs to bits 7 to 14 of the reference value (Bit[14:7]), and its value is 00000011. Encode position 10 of the sub-table entry in binary. The resulting second encoded value belongs to bits 0 to 6 of the reference value (Bit[6:0]), and its value is 0001010. Concatenate the first and second encoded values to obtain the total encoded value. Combined with the instruction type, the reference value 1000000110001010 is obtained.
[0162] For the second reference value format (the maximum value of the sub-table item is set to 256):
[0163] Encode position 3 of the sub-table in binary. The first encoded value belongs to bits 8 to 4 of the reference value (Bit[14:8]), and its value is 0000011. Encode position 10 of the sub-table in binary. The second encoded value belongs to bits 0 to 7 of the reference value (Bit[7:0]), and its value is 00001010. Concatenate the first and second encoded values to obtain the total encoded value. Combined with the instruction type, the reference value is 1000001100001010.
[0164] Optionally, the reference table can also include a master table to store the storage locations of sub-tables. That is, the reference table adopts a "master table + sub-table" design, where the master table stores the storage locations of sub-tables, and the sub-tables store the actual addresses of data segments. The master table uses a fixed address in the data area of the smart card's storage space, and this address can be accessed by the virtual machine within the card; this address remains unchanged after a COS upgrade. The master table stores the storage locations of sub-tables, with each 4-byte entry representing the storage address of a sub-table. The master table structure is shown in Figure 13, assuming a maximum sub-table entry value of 256 and a maximum sub-table size of 128.
[0165] Optionally, the sub-table also stores the packet index value (PKG_ID). For example, a sub-table entry is designed to be 4 bytes, and the format of a sub-table entry is shown in Figure 14. In the sub-table entry, 1 byte is used to represent the packet index value (PKG_ID), and 3 bytes are used to represent the actual address (ADDR). Each packet ID corresponds to one sub-table, and a main table can manage a maximum of 256 sub-tables (due to the limitations of the reference value format design, the typical number of sub-tables is generally set to 256 or 128).
[0166] A sub-table consists of sub-table entries, and its format is shown in Figure 15. Sub-tables require contiguous memory addresses for storage, but different sub-tables can use either contiguous or non-contiguous address storage. The sub-table addresses are stored in the main table. The relationship between the main table and sub-tables is shown in Figure 16.
[0167] In one optional embodiment, obtaining the target actual address of the target data segment indicated by the offset address based on the offset address in the instruction includes:
[0168] Based on the offset address in the instruction, the target index value of the external package indicated by the offset address is obtained;
[0169] Based on a preset packet registry, the base address of the target data segment indicated by the offset address is obtained according to the target index value; the target data segment is the data segment of the external packet.
[0170] Based on the base address and the offset address, the target actual address of the target data segment indicated by the offset address is obtained.
[0171] In this embodiment, the system further includes a packet registry for storing the base addresses of data segments within a packet. After a new packet is downloaded, the on-card virtual machine adds the base addresses of the data segments within the packet to the packet registry and sets an index value (e.g., 1-255) for each packet. This index value should be different from existing index values on the card. The packet registry and reference table are stored at fixed addresses in the data area of the smart card's storage space. These storage addresses are accessible to the on-card virtual machine, and the addresses remain unchanged after a COS upgrade.
[0172] In some embodiments, the target index value of the external packet indicated by the offset address in the instruction is found, i.e., the index value of the packet to which the offset address belongs; a search is performed in the packet registry based on the target index value to obtain the base address of the target data segment where the called method corresponding to the offset address is located; the base address and the offset address are added together to obtain the actual address. Here, the offset address indicates the target data segment of the external packet.
[0173] The overall design of the package registry described in this application is shown in Figure 17. During package download, the smart card operating system is responsible for package management. The system allocates an index value for each newly downloaded package. This application uses this index value as the package identifier, also called the Package ID (PKG_ID, with a value range of 1-255). The operating system is responsible for creating a new data node in the package registry to record the address of the newly downloaded package. The package address mainly includes the base addresses of four data segments: class segment, method segment, static field segment, and exported segment. The base addresses of these four segments are uniformly managed by the smart card operating system. During package download, the virtual machine on the card requests storage space from the incremental space and records the package address information in the package registry. After the package download is completed, the virtual machine on the card can query the package address information in the package registry using the package index value (PKG_ID). Figure 18 shows a flowchart of the registration package address information provided in this embodiment of the application. The virtual machine in the card requests storage space for the incremental package in the incremental space, allocates an index value (PKG_ID) for each package in the incremental package, allocates storage space for the data segment for each package in the incremental package, writes the incremental package sent by the COS upgrade server into the incremental space, and registers the address information (class segment, method segment, exported segment, static segment address and size) of the incremental package with the package registry so that the virtual machine in the card can be notified to execute the linking for external reference instructions.
[0174] In one alternative embodiment, executing the new instruction according to the reference table includes:
[0175] Based on the reference table, the target actual address corresponding to the reference value in the new instruction is obtained according to the reference value in the new instruction;
[0176] Execute the new instruction based on the actual address of the target.
[0177] In this embodiment of the application, after the linking is completed, the code only needs to "look up the table once" to access the actual address of the target where the code is located, thus improving the code execution efficiency.
[0178] In an optional embodiment, the reference table is used to directly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space;
[0179] The step of obtaining the target actual address corresponding to the reference value in the new instruction based on the reference table includes:
[0180] The reference value in the new instruction is searched in the reference table to obtain the target actual address corresponding to the reference value in the new instruction.
[0181] In this embodiment of the application, the reference table directly records the actual address and reference value of the data segment in the incremental space. That is, the reference table records the mapping relationship between the actual address and reference value of the data segment in the incremental space. By looking up the table, the target actual address corresponding to the reference value in the new instruction can be obtained directly.
[0182] In one optional embodiment, the reference table is used to indirectly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space;
[0183] The step of obtaining the target actual address corresponding to the reference value in the new instruction based on the reference table includes:
[0184] Decode the reference value in the new instruction to obtain the position of the actual target address corresponding to the reference value in the reference table;
[0185] The location is searched in the reference table to obtain the actual address of the location record, which is used as the target actual address corresponding to the reference value in the new instruction.
[0186] In this embodiment, the reference table does not directly record the actual address and reference value of the data segment within the incremental space; instead, it only records the actual address of the data segment. First, by decoding, the position of the target actual address corresponding to the reference value in the new instruction within the reference table is obtained. Then, by looking up the table, the actual address recorded at that position is found to be the target actual address corresponding to the reference value in the new instruction, thus improving flexibility.
[0187] For example, in conjunction with the above embodiments, the smart card operating system described in this application can calculate the reference table sub-table number and sub-table entry number using the 15-bit reference value excluding the highest bit (i.e., the total code value obtained by concatenating the first code value and the second code value). The calculation method is as follows:
[0188] Sub-table position = (reference value Bit[14:0]) / (maximum value of sub-table entry);
[0189] Sub-table entry position = (reference value Bit[14:0])%(sub-table entry maximum value).
[0190] In some embodiments, for the first reference value format (the maximum value of the sub-table entry is set to 128): the total encoding value is 00000011000101, which is converted to hexadecimal to obtain the reference value 018A; sub-table position = 018A (hexadecimal) / 128 (decimal) = 394 / 128 = 3; sub-table entry position = 0A03%128 = 10.
[0191] For the second reference value format (the maximum value of the sub-table entry is set to 256): the total code value is 000001100001010, which is converted to hexadecimal to get 030A; sub-table position = 030A (hexadecimal) / 256 (decimal) = 3; sub-table entry position = 030A (hexadecimal) % 256 (decimal) = 10.
[0192] In one optional embodiment, the reference table records at least the actual addresses of data segments within the incremental space, the data segments including at least one of exported segments, class segments, method segments, and static field segments.
[0193] Understandably, the data segment of a package includes export segments, class segments, method segments, and static field segments. After the package is downloaded to the incremental space, the base address of the data segment is recorded in the package registry so that the corresponding base address can be obtained during linking, and then a reference value can be generated.
[0194] The exported segment described in this application is mainly used to expose all static methods and static fields of this package to the outside world, excluding public methods. It mainly consists of three parts: class offset, static methods, and static fields. Among them, the class offset mainly solves the overwriting of the offset address of all classes in the class segment that this package provides for reference by other packages. The detailed description is as follows: In the exported segment, the offset of all classes (class description information) exposed by this package to the outside world in the class segment is recorded. The class description information is represented by a fixed data structure, which is referred to as "class information" in this application. When downloading to an incremental package, the actual address of the "class information" is first calculated based on the offset address of the "class information" in the class segment and the base address of the class segment. This actual address is equal to the "base address of the class segment + the offset address of the class information", representing the actual address where the "class information" data structure is located. This actual address is added to the sub-table entry of the reference table so that when other packages need to call the interface (method) of this class in this package, the virtual machine in the card generates a reference value and uses the reference value to overwrite the class offset address in the exported segment. Similarly, the process is similar for static methods, static fields, class segments, method segments, and static field segments in the exported segment, and will not be described in detail here.
[0195] The class segments described in this application mainly involve two aspects: first, the content of other packages referenced by this package; and second, the public methods provided by this package for reference by other packages. The class segments mainly include the following aspects: (1) package reference, which resolves the links between the current package and other packages; (2) exposure to external packages, which resolves the links between the public methods provided by this package for use by other packages.
[0196] Compared with the prior art, the smart card operating system upgrade method provided in this application has the following beneficial effects:
[0197] (1) The incremental packet size is small, saving smart card storage resources;
[0198] (2) Incremental package download time is short, saving data traffic;
[0199] (3) The time required to transmit incremental packets to smart cards is shortened, and the upgrade speed is faster;
[0200] (4) The incremental package can be used directly after being downloaded to the smart card without differential restoration or RAM consumption, resulting in a better upgrade experience;
[0201] (5) Because it uses an incremental space that is independent of the original COS firmware area, it will not brick the smart card operating system, making the upgrade safer;
[0202] (6) By adding an independent incremental space within the smart card, the original COS firmware functions can remain unchanged while new function code is added to the incremental space, enabling the smart card COS software to be upgraded with new functions quickly. The upgrade process is more efficient, safe, and reliable.
[0203] Referring to Figure 19, which is a structural block diagram of a smart card operating system upgrade device 10 provided in an embodiment of this application, the smart card operating system upgrade device 10 includes:
[0204] Download module 11 is used to download incremental packages to the incremental space within the smart card; wherein the incremental space is located within the firmware area of the smart card;
[0205] Upgrade module 12 is used to perform upgrades using the incremental package.
[0206] Optionally, the upgrade module 12 includes:
[0207] The first upgrade unit is configured to execute the instruction based on the offset address in the instruction for each instruction in each package of the incremental package if the instruction is an internal reference.
[0208] The second upgrade unit is used to, for each instruction in each package of the incremental package, if the instruction is an external reference, link the instruction according to the offset address in the instruction based on a preset reference table to obtain a new instruction; and execute the new instruction according to the reference table.
[0209] The reference table is used to directly or indirectly represent the mapping relationship between the actual address of the data segment in the incremental space and the reference value, wherein the length of the reference value is less than or equal to a preset number of bytes.
[0210] Optionally, the second upgrade unit is further configured to:
[0211] Based on the offset address in the instruction, the target actual address of the target data segment indicated by the offset address is obtained;
[0212] Based on a preset reference table, the reference value corresponding to the actual address of the target is obtained;
[0213] The reference value corresponding to the actual target address is overwritten to the offset address to obtain a new instruction.
[0214] Optionally, the reference table is used to indirectly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space;
[0215] The second upgrade unit is further configured to: look up the target actual address in the reference table to obtain the position of the target actual address in the reference table; and encode the position to obtain the reference value corresponding to the target actual address.
[0216] Optionally, the location includes the sub-table location and the sub-table entry location;
[0217] The second upgrade unit is further configured to: encode the sub-table position to obtain a first encoding value; encode the sub-table entry position to obtain a second encoding value; and obtain the reference value corresponding to the target actual address based on the first encoding value and the second encoding value.
[0218] Optionally, the second upgrade unit is further configured to:
[0219] Based on the offset address in the instruction, the target index value of the external package indicated by the offset address is obtained;
[0220] Based on a preset packet registry, the base address of the target data segment indicated by the offset address is obtained according to the target index value; the target data segment is the data segment of the external packet.
[0221] Based on the base address and the offset address, the target actual address of the target data segment indicated by the offset address is obtained.
[0222] Optionally, the second upgrade unit is further configured to:
[0223] Based on the reference table, the target actual address corresponding to the reference value in the new instruction is obtained according to the reference value in the new instruction;
[0224] Execute the new instruction based on the actual address of the target.
[0225] Optionally, the reference table is used to indirectly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space;
[0226] The second upgrade unit is further configured to: decode the reference value in the new instruction to obtain the position of the target actual address corresponding to the reference value in the reference table; search the reference table for the position to obtain the actual address recorded at the position, and use it as the target actual address corresponding to the reference value in the new instruction.
[0227] Optionally, the reference table records at least the actual addresses of data segments within the incremental space, and the data segments include at least one of the following: exported segment, class segment, method segment, and static field segment.
[0228] It is worth noting that the working process of each module in the smart card operating system upgrade device 10 described in this application embodiment can refer to the working process of the smart card operating system upgrade method described in the above embodiment, and will not be repeated here.
[0229] Furthermore, this application also provides a computer-readable storage medium, which includes a stored computer program; wherein, when the computer program is executed, it controls the device of the computer-readable storage medium to perform the smart card operating system upgrade method as described in any of the above embodiments.
[0230] Furthermore, this application also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the smart card operating system upgrade method as described in any of the above embodiments.
[0231] Referring to Figure 20, which is a structural block diagram of a smart card operating system upgrade device 20 provided in an embodiment of this application, the smart card operating system upgrade device 20 includes: a processor 21, a memory 22, and a computer program stored in the memory 22 and executable on the processor 21. When the processor 21 executes the computer program, it implements the operations described in the above-described smart card operating system upgrade method embodiments. Alternatively, when the processor 21 executes the computer program, it implements the functions of each module / unit in the above-described device embodiments.
[0232] For example, the computer program may be divided into one or more modules / units, which are stored in the memory 22 and executed by the processor 21 to complete this application. The one or more modules / units may be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the smart card operating system upgrade device 20.
[0233] The smart card operating system upgrade device 20 may include, but is not limited to, a processor 21 and a memory 22. Those skilled in the art will understand that the schematic diagram is merely an example of the smart card operating system upgrade device 20 and does not constitute a limitation on the smart card operating system upgrade device 20. It may include more or fewer components than illustrated, or combine certain components, or use different components. For example, the smart card operating system upgrade device 20 may also include input / output devices, network access devices, buses, etc.
[0234] The processor 21 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor. The processor 21 is the control center of the smart card operating system upgrade device 20, connecting various parts of the smart card operating system upgrade device 20 via various interfaces and lines.
[0235] The memory 22 can be used to store the computer programs and / or modules. The processor 21 implements various functions of the smart card operating system upgrade device 20 by running or executing the computer programs and / or modules stored in the memory 22 and calling the data stored in the memory 22. The memory 22 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory 22 may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0236] If the modules / units integrated in the smart card operating system upgrade device 20 are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by the processor 21, it can implement the operations of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc.
[0237] It should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, in the accompanying drawings of the device embodiments provided in this application, the connection relationships between modules indicate that they have communication connections, which can be specifically implemented as one or more communication buses or signal lines. Those skilled in the art can understand and implement this without any creative effort.
[0238] The above description is the preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications are also considered to be within the scope of protection of this application.
Claims
1. A method for upgrading a smart card operating system, comprising: The incremental package is downloaded to the incremental space within the smart card; wherein the incremental space is located within the firmware area of the smart card; Upgrade using the incremental package.
2. The smart card operating system upgrade method as described in claim 1, wherein, The upgrade using the incremental package includes: For each instruction in each packet of the incremental packet: If the instruction is an internal reference, then the instruction is executed according to the offset address in the instruction; If the instruction is an external reference, then based on a preset reference table, the instruction is linked according to the offset address in the instruction to obtain a new instruction; and the new instruction is executed according to the reference table. The reference table is used to directly or indirectly represent the mapping relationship between the actual address of the data segment in the incremental space and the reference value, wherein the length of the reference value is less than or equal to a preset number of bytes.
3. The smart card operating system upgrade method as described in claim 2, wherein, The instruction includes an opcode of one byte length and zero or more operands, the operands representing the values to be operated on by the instruction.
4. The smart card operating system upgrade method as described in claim 2, wherein, The method of linking instructions based on a preset reference table and the offset address in the instruction to obtain a new instruction includes: Based on the offset address in the instruction, the target actual address of the target data segment indicated by the offset address is obtained; Based on the preset reference table, the reference value corresponding to the actual address of the target is obtained; The reference value corresponding to the actual target address is overwritten to the offset address to obtain a new instruction.
5. The smart card operating system upgrade method as described in claim 4, wherein, The reference table is used to indirectly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space; The step of obtaining the reference value corresponding to the actual address of the target based on the preset reference table includes: The actual address of the target is found in the reference table to obtain the position of the actual address of the target in the reference table; The location is encoded to obtain the reference value corresponding to the actual address of the target.
6. The smart card operating system upgrade method as described in claim 5, wherein, The location includes the sub-table location and the sub-table entry location; Encoding the location to obtain the reference value corresponding to the actual target address includes: The positions of the sub-tables are encoded to obtain a first encoded value; The position of the sub-table entry is encoded to obtain a second encoded value; Based on the first encoded value and the second encoded value, the reference value corresponding to the actual address of the target is obtained.
7. The smart card operating system upgrade method as described in claim 4, wherein, The reference table is used to directly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space; The step of obtaining the reference value corresponding to the actual address of the target based on the preset reference table includes: The actual address of the target is looked up in the reference table to obtain the reference value corresponding to the actual address of the target.
8. The smart card operating system upgrade method as described in claim 4, wherein, The step of obtaining the target actual address of the target data segment indicated by the offset address according to the offset address in the instruction includes: Based on the offset address in the instruction, the target index value of the external package indicated by the offset address is obtained; Based on a preset packet registry, the base address of the target data segment indicated by the offset address is obtained according to the target index value; the target data segment is the data segment of the external packet. Based on the base address and the offset address, the target actual address of the target data segment indicated by the offset address is obtained.
9. The smart card operating system upgrade method as described in claim 4, wherein, The step of obtaining the target actual address of the target data segment indicated by the offset address according to the offset address in the instruction includes: Find the target index value of the external packet indicated by the offset address in the instruction; The target index value is used to search the packet registry to obtain the base address of the target data segment where the calling method corresponding to the offset address is located; and The actual address is obtained by adding the base address and the offset address; The offset address indicates the target data segment of the external packet.
10. The smart card operating system upgrade method as described in claim 2, wherein, The step of executing the new instruction according to the reference table includes: Based on the reference table, the target actual address corresponding to the reference value in the new instruction is obtained according to the reference value in the new instruction; Execute the new instruction based on the actual address of the target.
11. The smart card operating system upgrade method as described in claim 10, wherein, The reference table is used to indirectly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space; The step of obtaining the target actual address corresponding to the reference value in the new instruction based on the reference table includes: Decode the reference value in the new instruction to obtain the position of the actual target address corresponding to the reference value in the reference table; The location is searched in the reference table to obtain the actual address of the location record, which is used as the target actual address corresponding to the reference value in the new instruction.
12. The smart card operating system upgrade method as described in claim 10, wherein, The reference table is used to directly represent the mapping relationship between the actual address and the reference value of the data segment in the incremental space; The step of obtaining the target actual address corresponding to the reference value in the new instruction based on the reference table includes: The reference value in the new instruction is searched in the reference table to obtain the target actual address corresponding to the reference value in the new instruction.
13. The smart card operating system upgrade method as described in claim 2, wherein, The reference table records at least the actual addresses of data segments within the incremental space, and the data segments include at least one of the following: exported segment, class segment, method segment, and static field segment.
14. The smart card operating system upgrade method as described in claim 13, wherein, After downloading the incremental package to the incremental space within the smart card, the method includes: Record the base address of the data segment in the packet registry; The reference value is generated based on the base address, which is obtained during the linking process.
15. The smart card operating system upgrade method as described in claim 1, wherein, Before downloading the incremental package to the incremental space within the smart card, the method further includes: The developer of the smart card operating system completes the development and verification of the incremental package and releases the incremental package to the upgrade server of the smart card operating system. The smart card verifies the incremental packet.
16. The smart card operating system upgrade method as described in claim 1, wherein, The firmware area of the smart card also has full space. The incremental space is used to store the incremental packet, and the full space is used to store the full packet.
17. A smart card operating system upgrade device, comprising: A download module is used to download incremental packages to the incremental space within the smart card; wherein the incremental space is located within the firmware area of the smart card; An upgrade module is used to perform upgrades using the incremental package.
18. A smart card operating system upgrade device, comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor, when executing the computer program, implements the smart card operating system upgrade method as described in any one of claims 1 to 16.
19. A computer-readable storage medium comprising a stored computer program; wherein, When the computer program is run, it controls the device on the computer-readable storage medium to perform the smart card operating system upgrade method as described in any one of claims 1 to 16.
20. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the smart card operating system upgrade method as described in any one of claims 1 to 16.