Method, device and equipment for protecting debugging port of electronic control unit and medium
Patent Information
- Application Number
- CN202311376764.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-23
- Publication Date
- 2026-09-04
- Estimated Expiration
- 2043-10-23
AI Technical Summary
[0003]在电子控制单元产品开发的过程中,为了便于对电子控制单元产品软件的开发、测试及调试,基本上都会保留有一些调试端口,如JTAG(Joint Test Action Group,联合测试工作组)调试端口,Ethernet(以太网)调试端口,UART(Universal Asynchronous,通用异步收发传输器)调试端口等,并且为了便于后期对市场上的售后件进行问题分析,在电子控制单元产品SOP(Standard Operating Procedure,标准作业程序)时虽然会将对应连接器进行移除,但是会保留这些调试端口焊盘,攻击者还是可以通过这些暴露的焊盘去进行飞线,然后再对电子控制单元进行攻击
[0034] As can be seen, this application proposes a debug port protection method for an electronic control unit, applied to the processor chip within the electronic control unit, comprising: receiving a target debug port locking command sent by a diagnostic device, and parsing the target debug port locking command to obtain a target locking command, a target magic number, and target key data; writing the target magic number to a target sector address in flash memory, and locking the target sector address using the target key data; if the locking is successful, generating a first locking response command for the target debug port locking command, and sending the first locking response command to the diagnostic device; wherein, the first locking response command is generated based on the target locking command and the corresponding successful locking result; during the restart process of the electronic control unit, determining whether the target magic number in the target sector address is consistent with a preset magic number, and if they are consistent, enabling the debug port protection function. In summary, this application first writes the target magic number into the target sector address in the flash memory, and then locks the target magic number and the target sector address based on the target key data. Thus, after successful locking, write protection is achieved for the target magic number and the target sector address, preventing modification of the data within them. Furthermore, during the restart process of the electronic control unit, this application determines whether the target magic number in the target sector address matches a preset magic number. This preset magic number is the magic number preset by this application to enable debug port protection. If they match, it indicates that debug port protection should be enabled. In other words, this application prevents attackers from attempting to access the debug port by modifying the target magic number by locking the target magic number. At the same time, after enabling the debug port protection function, external access to the internal electronic control unit is impossible through the debug port. Therefore, this application solves the problem of related technologies attempting to make flying wires through exposed pads, enhancing the protection capability of the debug port. In addition, compared with traditional technologies that require setting up a security chip for data protection, this application does not require an additional separate security chip, reducing costs and improving efficiency.
Smart Images

Figure CN117421788B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of safe debugging technology, and in particular to a method, apparatus, device and medium for protecting the debugging port of an electronic control unit. Background Technology
[0002] The introduction of regulations and standards related to automotive information security has imposed mandatory requirements on automobiles to address information security risks, mainly in the cloud, road, and vehicle. Among these, in the vehicle, with the continuous development of the four new trends in automobiles (electrification, connectivity, intelligence, and sharing), the number of electronic control units (ECUs) in vehicles is increasing rapidly.
[0003] During the development of electronic control unit (ECU) products, some debugging ports are typically retained to facilitate the development, testing, and debugging of the ECU software. These include JTAG (Joint Test Action Group) debugging ports, Ethernet debugging ports, and UART (Universal Asynchronous Receiver / Transmitter) debugging ports. Furthermore, to facilitate later troubleshooting of aftermarket parts, although the corresponding connectors are removed during the ECU product's Standard Operating Procedure (SOP), these debugging port pads are retained. Attackers can still use these exposed pads to make jumper wires and then attack the ECU.
[0004] Therefore, there is an urgent need for a method to protect the debugging port of the electronic control unit that can solve the above problems. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a method, apparatus, device, and medium for protecting the debug port of an electronic control unit, which can enhance the protection capability of the debug port and prevent attackers from launching attacks on the electronic control unit through the debug port. The specific solution is as follows:
[0006] In a first aspect, this application discloses a method for protecting the debug port of an electronic control unit, applied to a processor chip within the electronic control unit, comprising:
[0007] Receive the target debug port lock command sent by the diagnostic device, and parse the target debug port lock command to obtain the target lock command, target magic number and target key data;
[0008] Write the target magic number to the target sector address in the flash memory, and lock the target sector address using the target key data;
[0009] If the locking is successful, a first locking response instruction is generated for the locking command of the target debug port, and the first locking response instruction is sent to the diagnostic device; wherein, the first locking response instruction is generated based on the target locking command and the corresponding locking success result;
[0010] During the restart process of the electronic control unit, it is determined whether the target magic number in the target sector address is consistent with the preset magic number. If they are consistent, the debug port protection function is enabled.
[0011] Optionally, if the locking is successful, a first locking response instruction is generated for the locking instruction of the target debug port, including:
[0012] If the first preset value in the target register in the flash memory is obtained, it indicates that the lock is successfully acquired, and the first lock response instruction for the lock instruction of the target debug port is generated.
[0013] Optionally, after writing the target magic number to the target sector address in the flash memory and locking the target sector address using the target key data, the method further includes:
[0014] If locking fails, a second locking response instruction is generated for the locking command of the target debug port, and the second locking response instruction is sent to the diagnostic device; wherein, the second locking response instruction is generated based on the target locking command and the corresponding locking failure result.
[0015] Optionally, if locking fails, a second locking response instruction is generated for the locking instruction of the target debug port, including:
[0016] If the second preset value is obtained from the target register in the flash memory, it indicates that the locking has failed, and a second locking response instruction for the locking instruction of the target debug port is generated.
[0017] Optionally, after determining whether the target magic number in the target sector address matches the preset magic number, and enabling the debug port protection function if they match, the method further includes:
[0018] The system receives a target debug port unlock command sent by the diagnostic device and parses the target debug port unlock command to obtain the target unlock command and the target key data.
[0019] The target sector address is unlocked using the target key data, and the newly generated magic number is written to the target sector address to overwrite the target magic number;
[0020] If unlocking is successful, a first unlock response instruction is generated for the target debug port unlock command, and the first unlock response instruction is sent to the diagnostic device; wherein, the first unlock response instruction is generated based on the target unlock command and the corresponding unlock success result;
[0021] During the restart process of the electronic control unit, it is determined whether the current magic number in the target sector address is consistent with the preset magic number. If they are inconsistent, the debug port protection function is disabled.
[0022] Optionally, after unlocking the target sector address using the target key data, the method further includes:
[0023] If unlocking fails, a second unlocking response instruction is generated for the target debug port unlocking command, and the second unlocking response instruction is sent to the diagnostic device; wherein, the second unlocking response instruction is generated based on the target unlocking command and the corresponding unlocking failure result.
[0024] Optionally, the processor chip may include a microcontroller unit or a system-on-a-chip.
[0025] Secondly, this application discloses a debug port protection device for an electronic control unit, applied to a processor chip within the electronic control unit, comprising:
[0026] The parsing module is used to receive the target debugging port locking command sent by the diagnostic device, and parse the target debugging port locking command to obtain the target locking command, the target magic number and the target key data;
[0027] The locking module is used to write the target magic number to the target sector address in the flash memory and lock the target sector address using the target key data;
[0028] The lock response instruction sending module is used to generate a first lock response instruction for the lock command of the target debugging port if the lock is successful, and send the first lock response instruction to the diagnostic device; wherein, the first lock response instruction is generated based on the target lock command and the corresponding lock success result;
[0029] The debug port protection module is used to determine whether the target magic number in the target sector address is consistent with the preset magic number during the restart process of the electronic control unit. If they are consistent, the debug port protection function is enabled.
[0030] Thirdly, this application discloses an electronic device, comprising:
[0031] Memory, used to store computer programs;
[0032] A processor is used to execute the computer program to implement the aforementioned method for protecting the debug port of the electronic control unit.
[0033] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned method for protecting the debug port of an electronic control unit.
[0034] As can be seen, this application proposes a debug port protection method for an electronic control unit, applied to the processor chip within the electronic control unit, comprising: receiving a target debug port locking command sent by a diagnostic device, and parsing the target debug port locking command to obtain a target locking command, a target magic number, and target key data; writing the target magic number to a target sector address in flash memory, and locking the target sector address using the target key data; if the locking is successful, generating a first locking response command for the target debug port locking command, and sending the first locking response command to the diagnostic device; wherein, the first locking response command is generated based on the target locking command and the corresponding successful locking result; during the restart process of the electronic control unit, determining whether the target magic number in the target sector address is consistent with a preset magic number, and if they are consistent, enabling the debug port protection function. In summary, this application first writes the target magic number into the target sector address in the flash memory, and then locks the target magic number and the target sector address based on the target key data. Thus, after successful locking, write protection is achieved for the target magic number and the target sector address, preventing modification of the data within them. Furthermore, during the restart process of the electronic control unit, this application determines whether the target magic number in the target sector address matches a preset magic number. This preset magic number is the magic number preset by this application to enable debug port protection. If they match, it indicates that debug port protection should be enabled. In other words, this application prevents attackers from attempting to access the debug port by modifying the target magic number by locking the target magic number. At the same time, after enabling the debug port protection function, external access to the internal electronic control unit is impossible through the debug port. Therefore, this application solves the problem of related technologies attempting to make flying wires through exposed pads, enhancing the protection capability of the debug port. In addition, compared with traditional technologies that require setting up a security chip for data protection, this application does not require an additional separate security chip, reducing costs and improving efficiency. Attached Figure Description
[0035] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0036] Figure 1 This is a flowchart of a debugging port protection method for an electronic control unit disclosed in this application;
[0037] Figure 2 This is a schematic diagram illustrating the connection between a specific electronic control unit and a diagnostic device disclosed in this application;
[0038] Figure 3 This is a flowchart of a specific electronic control unit debugging port protection method disclosed in this application;
[0039] Figure 4 This is a flowchart of another specific electronic control unit debugging port protection method disclosed in this application;
[0040] Figure 5 This is a flowchart of another specific method for protecting the debugging port of an electronic control unit disclosed in this application;
[0041] Figure 6 This is a schematic diagram of the structure of a debugging port protection device for an electronic control unit disclosed in this application;
[0042] Figure 7 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0043] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0044] During the development of electronic control unit (ECU) products, some debugging ports are usually retained to facilitate the development, testing, and debugging of the ECU product software. In order to facilitate the analysis of problems with aftermarket parts in the later stage, although the corresponding connectors are removed during the ECU product's Standard Operating Procedure (SOP), these debugging port pads are left. Attackers can still use these exposed pads to make jumper wires and then attack the ECU.
[0045] Therefore, this application proposes a protection scheme for the debugging port of an electronic control unit, which can enhance the protection capability of the debugging port and prevent attackers from launching attacks on the electronic control unit through the debugging port.
[0046] This application discloses a method for protecting the debug port of an electronic control unit, applied to the processor chip within the electronic control unit. See also... Figure 1 As shown, the method includes:
[0047] Step S11: Receive the target debug port lock command sent by the diagnostic device, and parse the target debug port lock command to obtain the target lock command, target magic number and target key data.
[0048] First, the connection between the diagnostic equipment and the electronic control unit will be explained: See [link to documentation]. Figure 2 As shown, the diagnostic device and the electronic control unit are connected via physical communication methods, including CAN / FD (CAN with Flexible Data-Rate) communication or Ethernet communication lines. CAN (Controller Area Network) represents the controller area network bus. Furthermore, the electronic control unit can be the electronic control unit of an Advanced Driving Assistance System (ADAS), and the diagnostic device is a diagnostic tool. The electronic control unit internally includes an MCU / SOC (Microcontroller Unit / System-on-a-Chip), flash memory, and debug ports, etc. The MCU / SOC is also known as a processor chip.
[0049] In this embodiment, there are no restrictions on the specific models of the MCU / SOC, flash memory, and debug port. The debug port includes, but is not limited to, JTAG debug port, Ethernet debug port, and UART debug port. The flash memory is used to store the firmware and other data required for the MCU / SOC to run, and the flash memory should have specific sector encryption protection function. The MCU / SOC and the flash memory are connected through physical lines and interact with each other through communication methods such as SPI (Serial Peripheral interface). The MCU / SOC and the debug port are connected through physical lines and interact with the outside world through JTAG and / or Ethernet and / or UART.
[0050] Furthermore, a target debug port locking instruction is generated in the diagnostic device. The target debug port locking instruction includes a target locking command, target magic numbers, and target key data. In this embodiment, the target debug port locking instruction is obtained through the processor chip and parsed to obtain the target locking command, the target magic numbers, and the target key data.
[0051] Step S12: Write the target magic number to the target sector address in the flash memory, and lock the target sector address using the target key data.
[0052] In this embodiment, the target magic number is written to the target sector address in the flash memory, and the target key data is written to the flash memory to lock the target sector address. It should be noted that encryption refers to encrypting the protected data into ciphertext. Unlike encryption, this embodiment locks the target sector address where the target magic number is located, that is, it protects the target sector address by writing it with a cipher.
[0053] Step S13: If locking is successful, generate a first locking response instruction for the target debugging port locking command and send the first locking response instruction to the diagnostic device; wherein, the first locking response instruction is generated based on the target locking command and the corresponding locking success result.
[0054] In this embodiment, if a first preset value is obtained from the target register in the flash memory, it indicates successful locking. A first locking response instruction for the target debug port locking command is generated based on the target locking command and the corresponding successful locking result, and then the first locking response instruction is sent to the diagnostic device. For example, assuming a target register value of 1 indicates successful locking, this embodiment determines successful locking when the first preset value (i.e., 1) is obtained. Further, if a second preset value is obtained from the target register in the flash memory, it indicates locking failure, and a second locking response instruction for the target debug port locking command is generated, and then the second locking response instruction is sent to the diagnostic device. For example, assuming a target register value of 0 indicates locking failure, this embodiment determines locking failure when the second preset value (i.e., 0) is obtained.
[0055] Step S14: During the restart process of the electronic control unit, determine whether the target magic number in the target sector address is consistent with the preset magic number. If they are consistent, enable the debug port protection function.
[0056] In this embodiment, the electronic control unit (ECU) is restarted. During the restart process, the MCU / SOC within the ECU reads the target magic number of the target sector address in the flash memory. If the read target magic number matches the preset magic number, the debug port protection function is enabled. After enabling the debug port protection function, the MCU / SOC within the ECU cannot be accessed externally through the debug port.
[0057] In summary, this embodiment effectively protects the debug port. The following example illustrates the specific process of protecting the debug port. (See attached image.) Figure 3 As shown:
[0058] S1. The diagnostic device generates a target debug port lock command, including a target lock command, a target magic number, and target key data for implementing debug port protection, and sends it to the electronic control unit. The format of the target debug port lock command is: target lock command + target magic number + target key data. In one specific implementation, the target lock command is 31 01 74 0G 01, the target magic number is 0x10101010, and the target key data is an 8-byte data set. It should be noted that the value of the target key data depends on the key requirements of the flash memory specific sector encryption protection function.
[0059] S2. The diagnostic device sends the target debugging port lock command to the electronic control unit via the CAN bus;
[0060] S3. After receiving the target debug port lock command, the MCU / SOC in the electronic control unit parses the target debug port lock command to obtain the target lock command, target magic number and target key data.
[0061] S4. The MCU / SOC in the electronic control unit writes the acquired target magic number to the target sector address in the flash memory. In one specific implementation, the target sector address is: 0x001C0000.
[0062] S5. The MCU / SOC in the electronic control unit writes the acquired target key data into the flash memory to encrypt and write-protect the target sector address written with the target magic number in S4.
[0063] S6. The MCU / SOC in the electronic control unit obtains the value in the target register in the flash memory to determine whether the write protection of the above target sector address has been successfully set.
[0064] S7, (1) If the MCU / SOC in the electronic control unit detects that the write protection of the target sector address in the flash memory is successful, the MCU / SOC in the electronic control unit generates a first debug port lock response instruction, including the target lock command and the lock success result, and sends the first debug port lock response instruction to the diagnostic device. The format of the first debug port lock response instruction is: the target lock command + the lock success result. In a specific implementation, the target lock command is 31 01 74 0G 01, which is consistent with the above. The lock success result is represented by 0x00.
[0065] When the electronic control unit is restarted, the MCU / SOC inside the electronic control unit will read the target magic number in the target sector address in the flash memory during the restart process. When the target magic number in the target sector address is detected to be consistent with the preset magic number, the external debug port protection function is enabled. After the external debug port protection function is enabled, external devices will not be able to establish communication with the MCU / SOC inside the electronic control unit through the debug port, and thus will not be able to access the MCU / SOC inside the electronic control unit through the external debug port.
[0066] (2) If the MCU / SOC in the electronic control unit detects a failure to write-protect the target sector address in the flash memory, the MCU / SOC generates a second debug port lock response instruction, including the target lock command and the lock failure result, and sends it to the diagnostic device. The format of the second debug port lock response instruction is: the target lock command + the lock failure result. In one specific implementation, the target lock command is 31 01 74 0G01, consistent with the above, and the lock failure result is represented by 0x01. If the lock fails, the above process needs to be repeated until the write protection of the debug port is successfully set, that is, the lock is successful.
[0067] This application can prevent attackers from using the external debugging port of the electronic control unit to launch internal attacks, privilege escalation operations, and obtain internal core data, which is of great significance for the safe debugging of automotive electronic control units.
[0068] As can be seen, this application proposes a debug port protection method for an electronic control unit, applied to the processor chip within the electronic control unit, comprising: receiving a target debug port locking command sent by a diagnostic device, and parsing the target debug port locking command to obtain a target locking command, a target magic number, and target key data; writing the target magic number to a target sector address in flash memory, and locking the target sector address using the target key data; if the locking is successful, generating a first locking response command for the target debug port locking command, and sending the first locking response command to the diagnostic device; wherein, the first locking response command is generated based on the target locking command and the corresponding successful locking result; during the restart process of the electronic control unit, determining whether the target magic number in the target sector address is consistent with a preset magic number, and if they are consistent, enabling the debug port protection function. In summary, this application first writes the target magic number into the target sector address in the flash memory, and then locks the target magic number and the target sector address based on the target key data. Thus, after successful locking, write protection is achieved for the target magic number and the target sector address, preventing modification of the data within them. Furthermore, during the restart process of the electronic control unit, this application determines whether the target magic number in the target sector address matches a preset magic number. This preset magic number is the magic number preset by this application to enable debug port protection. If they match, it indicates that debug port protection should be enabled. In other words, this application prevents attackers from attempting to access the debug port by modifying the target magic number by locking the target magic number. At the same time, after enabling the debug port protection function, external access to the internal electronic control unit is impossible through the debug port. Therefore, this application solves the problem of related technologies attempting to make flying wires through exposed pads, enhancing the protection capability of the debug port. In addition, compared with traditional technologies that require setting up a security chip for data protection, this application does not require an additional separate security chip, reducing costs and improving efficiency.
[0069] This application discloses a specific method for protecting the debug port of an electronic control unit. Compared to the previous embodiment, this embodiment further explains and optimizes how to deprotect the debug port of the electronic control unit. See also... Figure 4 As shown, it specifically includes:
[0070] Step S21: Receive the target debug port unlock command sent by the diagnostic device, and parse the target debug port unlock command to obtain the target unlock command and the target key data.
[0071] In this embodiment, the target debugging port unlocking command sent by the diagnostic device is parsed to obtain the target unlocking command and the target key data.
[0072] Step S22: Unlock the target sector address using the target key data, and write the newly generated magic number to the target sector address to overwrite the target magic number.
[0073] In this embodiment, the target key data is written to the flash memory, and the newly generated magic number is written to the target sector address to overwrite the target magic number. In this way, the write protection of the target sector address where the target magic number is written is removed, that is, the unlocking operation is realized.
[0074] Step S23: If unlocking is successful, a first unlock response instruction is generated for the target debug port unlock command, and the first unlock response instruction is sent to the diagnostic device; wherein, the first unlock response instruction is generated based on the target unlock command and the corresponding unlock success result.
[0075] Understandably, if unlocking is successful, a first unlock response instruction for the target debug port unlock command is generated based on the target unlock command and the corresponding unlock success result, and the first unlock response instruction is sent to the diagnostic device. If unlocking fails, a second unlock response instruction for the target debug port unlock command is generated based on the target unlock command and the corresponding unlock failure result, and the second unlock response instruction is sent to the diagnostic device.
[0076] Step S24: During the restart process of the electronic control unit, determine whether the current magic number in the target sector address is consistent with the preset magic number. If they are inconsistent, disable the debug port protection function.
[0077] In this embodiment, the electronic control unit (ECU) is restarted. During the restart process, the MCU / SOC within the ECU reads the current magic number of the target sector address in the flash memory. If the read magic number does not match the preset magic number, the debug port protection function is disabled. After disabling the debug port protection function, the MCU / SOC within the ECU can be accessed externally through the debug port.
[0078] In summary, this embodiment achieves the removal of protection for the debug port. The following example illustrates the specific process of removing protection for the debug port. (See attached image.) Figure 5 As shown:
[0079] S1. The diagnostic device generates a target debug port unlock command, including a target unlock command and target key data for implementing debug port protection, and sends it to the electronic control unit. The format of the target debug port unlock command is: target unlock command + target key data. In a specific implementation, the target unlock command is 31 01 74 0G 02, and the target key data is a data with a length of 8 bytes. It should be noted that the value of the target key data depends on the key requirements of the flash memory specific sector encryption protection function, and this value must be consistent with the target key data in the process of protecting the external debug port.
[0080] S2. The diagnostic device sends the target debug port unlock command to the electronic control unit via the CAN bus;
[0081] S3. After receiving the target debug port unlock command, the MCU / SOC in the electronic control unit parses the target debug port unlock command to obtain the target unlock command and target key data.
[0082] S4. The MCU / SOC in the electronic control unit writes the acquired target key data into the flash memory to remove the write protection of the target sector address where the target magic number is written.
[0083] S5. The MCU / SOC in the electronic control unit generates a new magic number that is different from the previous target magic number, and writes the new magic number to the target sector address in the flash memory to overwrite the previous target magic number. In one specific implementation, the target sector address is: 0x001C0000.
[0084] S6. The MCU / SOC in the electronic control unit obtains the value in the target register in the flash memory to determine whether the write protection of the above target sector address has been successfully removed.
[0085] S7, (1) If the MCU / SOC in the electronic control unit detects that the write protection of the target sector address in the flash memory has been successfully removed, the MCU / SOC in the electronic control unit generates a first debug port unlock response instruction, including a target unlock command and an unlock success result, and sends the first debug port unlock response instruction to the diagnostic device. The format of the first debug port unlock response instruction is: target unlock command + unlock success result. In a specific implementation, the target unlock command is 31 01 74 0G 02, which is consistent with the above. The unlock success result is represented by 0x00.
[0086] When the electronic control unit is restarted, the MCU / SOC inside the electronic control unit will read the current magic number in the target sector address in the flash memory during the restart process. When it is detected that the current magic number in the target sector address is inconsistent with the preset magic number, the external debug port protection function is disabled. After the external debug port protection function is disabled, external devices can establish communication with the MCU / SOC inside the electronic control unit through the debug port, thereby accessing the MCU / SOC inside the electronic control unit through the external debug port.
[0087] (2) If the MCU / SOC in the electronic control unit detects a failure to remove the write protection from the target sector address in the flash memory, the MCU / SOC generates a second debug port unlock response instruction, including a target unlock command and an unlock failure result, and sends it to the diagnostic device. The format of the second debug port unlock response instruction is: the target unlock command + unlock failure result. In one specific implementation, the target unlock command is 31 01 74 0G02, consistent with the above, and the unlock failure result is represented by 0x01. If unlocking fails, the above process needs to be repeated until the write protection of the debug port is successfully removed, i.e., unlocking is successful.
[0088] Accordingly, this application also discloses a debug port protection device for an electronic control unit, applied to the processor chip within the electronic control unit. See [link to relevant documentation]. Figure 6 As shown, the device includes:
[0089] The parsing module 11 is used to receive the target debugging port locking command sent by the diagnostic device, and parse the target debugging port locking command to obtain the target locking command, the target magic number and the target key data;
[0090] The locking module 12 is used to write the target magic number to the target sector address in the flash memory, and lock the target sector address using the target key data;
[0091] The lock response instruction sending module 13 is used to generate a first lock response instruction for the lock command of the target debugging port if the lock is successful, and send the first lock response instruction to the diagnostic device; wherein, the first lock response instruction is generated based on the target lock command and the corresponding lock success result;
[0092] The debug port protection module 14 is used to determine whether the target magic number in the target sector address is consistent with the preset magic number during the restart process of the electronic control unit. If they are consistent, the debug port protection function is enabled.
[0093] For more detailed information on the working process of each of the above modules, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.
[0094] As can be seen, this application proposes a debug port protection method for an electronic control unit, applied to the processor chip within the electronic control unit, comprising: receiving a target debug port locking command sent by a diagnostic device, and parsing the target debug port locking command to obtain a target locking command, a target magic number, and target key data; writing the target magic number to a target sector address in flash memory, and locking the target sector address using the target key data; if the locking is successful, generating a first locking response command for the target debug port locking command, and sending the first locking response command to the diagnostic device; wherein, the first locking response command is generated based on the target locking command and the corresponding successful locking result; during the restart process of the electronic control unit, determining whether the target magic number in the target sector address is consistent with a preset magic number, and if they are consistent, enabling the debug port protection function. In summary, this application first writes the target magic number into the target sector address in the flash memory, and then locks the target magic number and the target sector address based on the target key data. Thus, after successful locking, write protection is achieved for the target magic number and the target sector address, preventing modification of the data within them. Furthermore, during the restart process of the electronic control unit, this application determines whether the target magic number in the target sector address matches a preset magic number. This preset magic number is the magic number preset by this application to enable debug port protection. If they match, it indicates that debug port protection should be enabled. In other words, this application prevents attackers from attempting to access the debug port by modifying the target magic number by locking the target magic number. At the same time, after enabling the debug port protection function, external access to the internal electronic control unit is impossible through the debug port. Therefore, this application solves the problem of related technologies attempting to make flying wires through exposed pads, enhancing the protection capability of the debug port. In addition, compared with traditional technologies that require setting up a security chip for data protection, this application does not require an additional separate security chip, reducing costs and improving efficiency.
[0095] Furthermore, embodiments of this application also provide an electronic device. Figure 7 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.
[0096] Figure 7This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. Specifically, the electronic device 20 may include: at least one processor 21, at least one memory 22, a display screen 23, an input / output interface 24, a communication interface 25, a power supply 26, and a communication bus 27. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the debug port protection method for the electronic control unit disclosed in any of the foregoing embodiments. Alternatively, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0097] In this embodiment, the power supply 26 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 25 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 24 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0098] Furthermore, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk, or optical disk, etc. The resources stored thereon may include computer programs 221, and the storage method may be temporary storage or permanent storage. The computer programs 221 may include, in addition to computer programs capable of performing the debug port protection method for the electronic control unit executed by the electronic device 20 as disclosed in any of the foregoing embodiments, computer programs capable of performing other specific tasks.
[0099] Furthermore, embodiments of this application also disclose a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned method for protecting the debug port of an electronic control unit.
[0100] For the specific steps of this method, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.
[0101] The various embodiments in this application are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. For the same or similar parts between the various embodiments, refer to each other. As for the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple, and relevant parts can be referred to in the method section.
[0102] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0103] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0104] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0105] The above provides a detailed description of the debugging port protection method, apparatus, device, and storage medium for an electronic control unit provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for protecting the debugging port of an electronic control unit, characterized in that, The processor chip used in the electronic control unit includes: Receive the target debug port lock command sent by the diagnostic device, and parse the target debug port lock command to obtain the target lock command, target magic number and target key data; Write the target magic number to the target sector address in the flash memory, and lock the target sector address using the target key data; If the locking is successful, a first locking response instruction is generated for the locking command of the target debugging port, and the first locking response instruction is sent to the diagnostic device; wherein, the first locking response instruction is generated based on the target locking command and the corresponding locking success result; During the restart process of the electronic control unit, it is determined whether the target magic number in the target sector address is consistent with the preset magic number. If they are consistent, the debug port protection function is enabled.
2. The method for protecting the debugging port of the electronic control unit according to claim 1, characterized in that, If the locking is successful, a first locking response instruction is generated for the locking instruction of the target debugging port, including: If the first preset value in the target register in the flash memory is obtained, it indicates that the lock is successfully acquired, and the first lock response instruction for the lock instruction of the target debug port is generated.
3. The method for protecting the debugging port of the electronic control unit according to claim 1, characterized in that, After writing the target magic number to the target sector address in the flash memory and locking the target sector address using the target key data, the method further includes: If locking fails, a second locking response instruction is generated for the locking command of the target debug port, and the second locking response instruction is sent to the diagnostic device; wherein, the second locking response instruction is generated based on the target locking command and the corresponding locking failure result.
4. The method for protecting the debugging port of the electronic control unit according to claim 3, characterized in that, If locking fails, a second locking response instruction is generated for the target debug port locking instruction, including: If the second preset value is obtained from the target register in the flash memory, it indicates that the locking has failed, and a second locking response instruction for the locking instruction of the target debug port is generated.
5. The method for protecting the debugging port of the electronic control unit according to claim 1, characterized in that, After determining whether the target magic number in the target sector address matches the preset magic number, and enabling the debug port protection function if they match, the method further includes: The system receives a target debug port unlock command sent by the diagnostic device and parses the target debug port unlock command to obtain the target unlock command and the target key data. The target sector address is unlocked using the target key data, and the newly generated magic number is written to the target sector address to overwrite the target magic number; If unlocking is successful, a first unlock response instruction is generated for the target debug port unlock command, and the first unlock response instruction is sent to the diagnostic device; wherein, the first unlock response instruction is generated based on the target unlock command and the corresponding unlock success result; During the restart process of the electronic control unit, it is determined whether the current magic number in the target sector address is consistent with the preset magic number. If they are inconsistent, the debug port protection function is disabled.
6. The method for protecting the debugging port of the electronic control unit according to claim 5, characterized in that, After unlocking the target sector address using the target key data, the method further includes: If unlocking fails, a second unlocking response instruction is generated for the target debug port unlocking command, and the second unlocking response instruction is sent to the diagnostic device; wherein, the second unlocking response instruction is generated based on the target unlocking command and the corresponding unlocking failure result.
7. The method for protecting the debugging port of an electronic control unit according to any one of claims 1 to 6, characterized in that, The processor chip includes a microcontroller unit or a system-on-a-chip.
8. A protection device for the debugging port of an electronic control unit, characterized in that, The processor chip used in the electronic control unit includes: The parsing module is used to receive the target debugging port locking command sent by the diagnostic device, and parse the target debugging port locking command to obtain the target locking command, the target magic number and the target key data; The locking module is used to write the target magic number to the target sector address in the flash memory and lock the target sector address using the target key data; The lock response instruction sending module is used to generate a first lock response instruction for the lock command of the target debugging port if the lock is successful, and send the first lock response instruction to the diagnostic device; wherein, the first lock response instruction is generated based on the target lock command and the corresponding lock success result; The debug port protection module is used to determine whether the target magic number in the target sector address is consistent with the preset magic number during the restart process of the electronic control unit. If they are consistent, the debug port protection function is enabled.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the debug port protection method for the electronic control unit as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, Used to store computer programs; wherein, when the computer programs are executed by a processor, they implement the debug port protection method of the electronic control unit as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Method and circuit for realizing safety of MCU (micro controller unit)
CN104777761A
Electronic control unit, apparatus for performing control operation on electronic control unit, and corresponding method and computer program
CN115087976A