[go: up one dir, main page]

CN117472808A - Data protection methods, devices and systems - Google Patents

Data protection methods, devices and systems Download PDF

Info

Publication number
CN117472808A
CN117472808A CN202311056558.7A CN202311056558A CN117472808A CN 117472808 A CN117472808 A CN 117472808A CN 202311056558 A CN202311056558 A CN 202311056558A CN 117472808 A CN117472808 A CN 117472808A
Authority
CN
China
Prior art keywords
flash memory
access
command
programmable logic
address range
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311056558.7A
Other languages
Chinese (zh)
Inventor
杨宇
陈艳
马圣平
陈飞鸣
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN202311056558.7A priority Critical patent/CN117472808A/en
Publication of CN117472808A publication Critical patent/CN117472808A/en
Priority to PCT/CN2024/080333 priority patent/WO2025039512A1/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/14Protection against unauthorised use of memory or access to memory
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F15/00Digital computers in general; Data processing equipment in general
    • G06F15/76Architectures of general purpose stored program computers
    • G06F15/78Architectures of general purpose stored program computers comprising a single central processing unit
    • G06F15/7807System on chip, i.e. computer system on a single chip; System in package, i.e. computer system on one or more chips in a single package

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Computing Systems (AREA)
  • Microelectronics & Electronic Packaging (AREA)
  • Storage Device Security (AREA)

Abstract

The application discloses a data protection method, device and system, and belongs to the technical field of computers. The method is applied to a controller, which is a flash memory controller internal to the system on chip or a programmable logic controller disposed between the system on chip and the flash memory. The controller receives an access command for the flash memory sent by the processing core, wherein the access command comprises a command word and an access address. If the command word indicates that the access type of the access command is write or erase and the access address belongs to the protection address range of the flash memory configured in the controller, the controller intercepts the access command. According to the method and the device, the protection address range of the flash memory is configured on the controller, if the processing core in the system on chip wants to modify the content corresponding to the protection address range in the flash memory, the controller prevents the modification, the data tamper-proof function of the flash memory is achieved, and the safety and the reliability of the data in the flash memory can be improved.

Description

数据保护方法、装置及系统Data protection methods, devices and systems

技术领域Technical field

本申请涉及计算机技术领域,特别涉及一种数据保护方法、装置及系统。The present application relates to the field of computer technology, and in particular to a data protection method, device and system.

背景技术Background technique

闪存(flash memory)是一种非易失性存储器,能够在断电后保持存储的数据不丢失。包含处理核和闪存控制器的片上系统(system on a chip,SoC)能够访问片外部署的闪存。但是由于闪存的访问接口速率较低,因此即使SoC在访问闪存之前完成了对闪存中数据的校验,在校验通过后到SoC成功访问闪存的过程中,还是存在被攻击的时间窗。在这个时间窗内,攻击者有可能拿到闪存的操作权进而篡改闪存中的数据,导致SoC无法访问到闪存的原有数据。目前闪存中数据的安全性和可靠性通常较低。Flash memory is a non-volatile memory that can keep stored data from being lost after a power outage. A system on a chip (SoC) containing a processing core and a flash memory controller can access flash memory deployed off-chip. However, due to the low access interface rate of flash memory, even if the SoC completes verification of the data in the flash memory before accessing the flash memory, there is still a time window for being attacked after the verification passes until the SoC successfully accesses the flash memory. During this time window, an attacker may gain access to the flash memory and tamper with the data in the flash memory, causing the SoC to be unable to access the original data in the flash memory. The security and reliability of data currently in flash memory is generally low.

发明内容Contents of the invention

本申请提供了一种数据保护方法、装置及系统。This application provides a data protection method, device and system.

第一方面,提供了一种数据保护方法,应用于片上系统。该片上系统包括处理核和闪存控制器。闪存控制器接收处理核发送的针对闪存的第一访问命令。该闪存部署于片上系统的外部。第一访问命令包括第一命令字和第一访问地址。第一命令字用于指示第一访问命令的访问类型,该访问类型包括读、写或擦除。第一访问地址用于指示第一访问命令在闪存中所访问的地址范围。如果第一命令字指示第一访问命令的访问类型为写或擦除,且第一访问地址属于闪存控制器中配置的闪存的保护地址范围,闪存控制器拦截第一访问命令。In the first aspect, a data protection method is provided, which is applied to the system-on-chip. The system-on-chip includes processing cores and flash memory controllers. The flash memory controller receives a first access command for the flash memory sent by the processing core. The flash memory is deployed external to the system-on-chip. The first access command includes a first command word and a first access address. The first command word is used to indicate the access type of the first access command, and the access type includes read, write or erase. The first access address is used to indicate the address range accessed by the first access command in the flash memory. If the first command word indicates that the access type of the first access command is write or erase, and the first access address belongs to the protection address range of the flash memory configured in the flash memory controller, the flash memory controller intercepts the first access command.

本申请通过在闪存控制器中配置闪存的保护地址范围,如果处理核想要修改闪存中该保护地址范围对应的内容,则闪存控制器阻止该修改行为,从而保护闪存中该保护地址范围对应的内容不被篡改,实现针对闪存的数据防篡改功能,能够提高闪存中数据的安全性和可靠性。This application configures the protection address range of the flash memory in the flash memory controller. If the processing core wants to modify the content corresponding to the protection address range in the flash memory, the flash memory controller prevents the modification behavior, thereby protecting the flash memory corresponding to the protection address range. The content cannot be tampered with, and the data tamper-proof function for flash memory can be realized, which can improve the security and reliability of data in flash memory.

可选地,闪存中部署有程序文件,闪存控制器中配置的闪存保护地址范围包括该程序文件的地址范围。其中,该程序文件包括代码段和数据段。这样闪存控制器能够保护闪存中的程序文件不被篡改,保证处理核能够正常运行该程序文件中的代码。Optionally, a program file is deployed in the flash memory, and the flash memory protection address range configured in the flash memory controller includes the address range of the program file. Among them, the program file includes code segments and data segments. In this way, the flash memory controller can protect the program file in the flash memory from being tampered with and ensure that the processing core can run the code in the program file normally.

可选地,闪存控制器接收处理核发送的针对闪存的第一访问命令的实现方式,包括:闪存控制器在间接访问模式下接收处理核发送的第一访问命令。Optionally, the implementation of the flash memory controller receiving the first access command sent by the processing core for the flash memory includes: the flash memory controller receiving the first access command sent by the processing core in the indirect access mode.

本申请中,闪存控制器设置有两种访问模式,包括直接访问模式和间接访问模式。当闪存控制器处于直接访问模式时,仅支持处理核对闪存的读操作。当闪存控制器处于间接访问模式时,支持处理核对闪存的读、写和擦除操作。In this application, the flash memory controller is configured with two access modes, including direct access mode and indirect access mode. When the flash controller is in direct access mode, only read operations to the flash memory are supported. Supports processing of read, write, and erase operations to flash memory when the flash controller is in indirect access mode.

可选地,闪存控制器在直接访问模式下接收处理核发送的针对闪存的第二访问命令,第二访问命令包括第二访问地址,第二访问地址用于指示第二访问命令在闪存中所访问的地址范围。如果第二访问地址不属于闪存控制器中配置的闪存的可读地址范围,闪存控制器拦截第二访问命令。Optionally, the flash memory controller receives a second access command for the flash memory sent by the processing core in the direct access mode, the second access command includes a second access address, and the second access address is used to indicate where the second access command is located in the flash memory. Accessed address range. If the second access address does not belong to the readable address range of the flash memory configured in the flash memory controller, the flash memory controller intercepts the second access command.

本申请通过在闪存控制器中配置闪存的可读地址范围,使得处理核在闪存控制器处于直接访问模式时,无法读取到闪存中该可读地址范围以外的内容,实现访问权限控制。This application configures the readable address range of the flash memory in the flash memory controller, so that when the flash memory controller is in direct access mode, the processing core cannot read content outside the readable address range in the flash memory, thereby achieving access control.

可选地,如果第二访问地址属于闪存控制器中配置的闪存的可读地址范围,闪存控制器生成第二命令字,第二命令字用于指示第二访问命令的访问类型为读。闪存控制器基于第二命令字和第二访问地址从闪存中读取第二访问地址对应的内容,并将第二访问地址对应的内容发送给处理核。Optionally, if the second access address belongs to the readable address range of the flash memory configured in the flash memory controller, the flash memory controller generates a second command word, and the second command word is used to indicate that the access type of the second access command is read. The flash memory controller reads the content corresponding to the second access address from the flash memory based on the second command word and the second access address, and sends the content corresponding to the second access address to the processing core.

可选地,闪存控制器中配置的闪存的可读地址范围与保护地址范围相同。Optionally, the readable address range of the flash memory configured in the flash memory controller is the same as the protection address range.

本申请中,通过在闪存控制器中配置相同的可读地址范围和保护地址范围,由于闪存中保护地址范围对应的内容无法被篡改,且处理核在直接访问闪存时只能读取到可读地址范围对应的内容,因此能够保证处理核通过直接访问从闪存中读取的内容是未经篡改的,从而提高处理核的运行可靠性。In this application, by configuring the same readable address range and protected address range in the flash memory controller, the content corresponding to the protected address range in the flash memory cannot be tampered with, and the processing core can only read the readable address range when directly accessing the flash memory. The content corresponding to the address range can therefore ensure that the content read from the flash memory by the processing core through direct access has not been tampered with, thereby improving the operational reliability of the processing core.

可选地,如果第一命令字指示第一访问命令的访问类型为读,闪存控制器基于第一命令字和第一访问地址从闪存中读取第一访问地址对应的内容,并将第一访问地址对应的内容发送给处理核。Optionally, if the first command word indicates that the access type of the first access command is read, the flash memory controller reads the content corresponding to the first access address from the flash memory based on the first command word and the first access address, and writes the first The content corresponding to the access address is sent to the processing core.

可选地,闪存控制器接收处理核发送的模式切换指令,该模式切换指令用于指示闪存控制器由直接访问模式切换为间接访问模式,或者由间接访问模式切换为直接访问模式。Optionally, the flash memory controller receives a mode switching instruction sent by the processing core, where the mode switching instruction is used to instruct the flash memory controller to switch from the direct access mode to the indirect access mode, or from the indirect access mode to the direct access mode.

可选地,在闪存控制器接收处理核发送的针对闪存的第一访问命令之前,处理核通过运行第一可信程序,在闪存控制器中配置保护地址范围。处理核通过运行第二可信程序,对闪存中该保护地址范围对应的内容进行校验,并确定该保护地址范围对应的内容校验通过。Optionally, before the flash memory controller receives the first access command for the flash memory sent by the processing core, the processing core configures the protection address range in the flash memory controller by running the first trusted program. The processing core verifies the content corresponding to the protected address range in the flash memory by running the second trusted program, and determines that the content corresponding to the protected address range passes the verification.

本申请中,通过先在闪存控制器中配置闪存的保护地址范围,再对闪存中该保护地址范围对应的内容进行校验。这样,在处理核对闪存中该保护地址范围对应的内容校验通过之后,如果闪存控制器接收到针对闪存中该保护地址范围对应的内容的修改指令,闪存控制器则拦截该修改指令以阻止对闪存的修改,从而能够避免处理核校验通过后到访问闪存的时间窗内闪存中经过校验的内容被篡改,提高了闪存中数据的安全性和可靠性。In this application, the protection address range of the flash memory is first configured in the flash memory controller, and then the content corresponding to the protection address range in the flash memory is verified. In this way, after the verification of the content corresponding to the protected address range in the flash memory passes, if the flash memory controller receives a modification instruction for the content corresponding to the protected address range in the flash memory, the flash memory controller intercepts the modification instruction to prevent the modification. The modification of the flash memory can prevent the verified content in the flash memory from being tampered with during the time window from when the processing core verification is passed to when the flash memory is accessed, thereby improving the security and reliability of the data in the flash memory.

可选地,上述片上系统还包括只读存储器和随机存取存储器。片上系统上电或复位后,处理核通过运行只读存储器中的第一程序文件,通过闪存控制器读取闪存中的第二程序文件以及第一签名,并将读取的第二程序文件和第一签名保存在随机存取存储器中,第一签名是基于第一私钥和第二程序文件的内容生成的。处理核采用第一私钥对应的第一公钥对第一签名进行验证。处理核在对第一签名验证通过之后,从随机存取存储器中保存的第二程序文件中获取第一可信程序和第二可信程序。Optionally, the above system on chip also includes a read-only memory and a random access memory. After the on-chip system is powered on or reset, the processing core reads the second program file and the first signature in the flash memory through the flash memory controller by running the first program file in the read-only memory, and transfers the read second program file and The first signature is stored in the random access memory and the first signature is generated based on the first private key and the contents of the second program file. The processing core uses the first public key corresponding to the first private key to verify the first signature. After passing the verification of the first signature, the processing core obtains the first trusted program and the second trusted program from the second program file stored in the random access memory.

本申请在处理核的安全启动过程中完成信任链校验,实现对闪存控制器的闪存保护功能的可信配置。This application completes the trust chain verification during the secure boot process of the processing core and realizes the trusted configuration of the flash memory protection function of the flash memory controller.

可选地,处理核通过运行第二可信程序,对闪存中保护地址范围对应的内容进行校验的实现方式,包括:处理核通过运行第二可信程序,通过闪存控制器读取闪存中保护地址范围对应的内容以及第二签名,并将读取的保护地址范围对应的内容和第二签名保存在随机存取存储器中,第二签名是基于第二私钥和保护地址范围对应的内容生成的。处理核采用第二私钥对应的第二公钥对第二签名进行验证。Optionally, the processing core verifies the content corresponding to the protected address range in the flash memory by running a second trusted program, including: the processing core reads the flash memory through the flash memory controller by running the second trusted program. The content corresponding to the protected address range and the second signature are stored in the random access memory, and the second signature is based on the second private key and the content corresponding to the protected address range. Generated. The processing core uses the second public key corresponding to the second private key to verify the second signature.

可选地,处理核通过运行第一可信程序,在闪存控制器中配置保护地址范围之后,处理核通过运行第三可信程序,锁定闪存控制器针对闪存的保护功能配置。其中,闪存控制器针对闪存的保护功能配置被锁定,是指闪存控制器中针对闪存的保护功能配置无法被修改。闪存控制器针对闪存的保护功能配置包括防篡改配置和/或访问权限控制配置。其中,防篡改配置包括在闪存控制器上配置闪存的保护地址范围,以及配置闪存控制器在间接访问模式下保护闪存中该保护地址范围对应的内容不被篡改。访问权限控制配置包括在闪存控制器上配置闪存的可读地址范围,以及配置闪存控制器在直接访问模式下只读闪存中该可读地址范围对应的内容。Optionally, after the processing core configures the protection address range in the flash memory controller by running a first trusted program, the processing core locks the protection function configuration of the flash memory controller for the flash memory by running a third trusted program. Among them, the protection function configuration of the flash memory controller for the flash memory is locked, which means that the protection function configuration of the flash memory controller for the flash memory cannot be modified. The protection function configuration of the flash memory controller for the flash memory includes anti-tampering configuration and/or access permission control configuration. Among them, the anti-tampering configuration includes configuring the protection address range of the flash memory on the flash memory controller, and configuring the flash memory controller to protect the content corresponding to the protection address range in the flash memory from being tampered with in the indirect access mode. The access control configuration includes configuring the readable address range of the flash memory on the flash memory controller, and configuring the content corresponding to the readable address range in the read-only flash memory of the flash memory controller in direct access mode.

第二方面,提供了另一种数据保护方法。可编程逻辑控制器接收片上系统发送的针对闪存的第一访问命令。可编程逻辑控制器部署在片上系统与闪存之间。第一访问命令包括第一命令字和第一访问地址。第一命令字用于指示第一访问命令的访问类型,该访问类型包括读、写或擦除。第一访问地址用于指示第一访问命令在闪存中所访问的地址范围。如果第一命令字指示第一访问命令的访问类型为写或擦除,且第一访问地址属于可编程逻辑控制器中配置的闪存的保护地址范围,可编程逻辑控制器拦截第一访问命令。The second aspect provides another method of data protection. The programmable logic controller receives the first access command for the flash memory sent by the on-chip system. The programmable logic controller is deployed between the system-on-chip and the flash memory. The first access command includes a first command word and a first access address. The first command word is used to indicate the access type of the first access command, and the access type includes read, write or erase. The first access address is used to indicate the address range accessed by the first access command in the flash memory. If the first command word indicates that the access type of the first access command is write or erase, and the first access address belongs to the protection address range of the flash memory configured in the programmable logic controller, the programmable logic controller intercepts the first access command.

本申请通过在片上系统与闪存之间部署可编程逻辑控制器,并在可编程逻辑控制器上配置闪存的保护地址范围,如果片上系统内部的处理核想要修改闪存中该保护地址范围对应的内容,则可编程逻辑控制器阻止该修改行为,从而保护闪存中该保护地址范围对应的内容不被篡改,实现针对闪存的数据防篡改功能,能够提高闪存中数据的安全性和可靠性。This application deploys a programmable logic controller between the on-chip system and the flash memory, and configures the protection address range of the flash memory on the programmable logic controller. If the processing core inside the on-chip system wants to modify the protection address range corresponding to the flash memory, content, the programmable logic controller prevents the modification behavior, thereby protecting the content corresponding to the protected address range in the flash memory from being tampered with, realizing the data anti-tampering function for the flash memory, and improving the security and reliability of the data in the flash memory.

可选地,可编程逻辑控制器接收片上系统发送的针对闪存的第一访问命令的实现方式,包括:可编程逻辑控制器在间接访问模式下接收片上系统发送的第一访问命令。Optionally, the implementation of the programmable logic controller receiving the first access command sent by the on-chip system for the flash memory includes: the programmable logic controller receives the first access command sent by the on-chip system in the indirect access mode.

本申请中,可编程逻辑控制器可以设置有两种访问模式,包括直接访问模式和间接访问模式。这种情况下,可编程逻辑控制器的访问模式与闪存控制器的访问模式保持一致。也就是说,当闪存控制器处于直接访问模式时,可编程逻辑控制器也处于直接访问模式。当闪存控制器处于间接访问模式时,可编程逻辑控制器也处于间接访问模式。In this application, the programmable logic controller can be set with two access modes, including direct access mode and indirect access mode. In this case, the access pattern of the programmable logic controller is consistent with the access pattern of the flash memory controller. That is, when the flash memory controller is in direct access mode, the programmable logic controller is also in direct access mode. When the flash controller is in indirect access mode, the programmable logic controller is also in indirect access mode.

可选地,可编程逻辑控制器在直接访问模式下接收片上系统发送的针对闪存的第二访问命令,第二访问命令包括第二命令字和第二访问地址,第二命令字用于指示第二访问命令的访问类型为读,第二访问地址用于指示第二访问命令在闪存中所访问的地址范围。如果第二访问地址不属于可编程逻辑控制器中配置的闪存的可读地址范围,可编程逻辑控制器拦截第二访问命令。Optionally, the programmable logic controller receives a second access command for the flash memory sent by the on-chip system in the direct access mode. The second access command includes a second command word and a second access address, and the second command word is used to indicate the second access command. The access type of the second access command is read, and the second access address is used to indicate the address range accessed by the second access command in the flash memory. If the second access address does not belong to the readable address range of the flash memory configured in the programmable logic controller, the programmable logic controller intercepts the second access command.

本申请通过在可编程逻辑控制器中配置闪存的可读地址范围,使得SoC在可编程逻辑控制器处于直接访问模式时,无法读取到闪存中该可读地址范围以外的内容,实现访问权限控制。This application configures the readable address range of the flash memory in the programmable logic controller, so that when the programmable logic controller is in direct access mode, the SoC cannot read content outside the readable address range in the flash memory, thereby achieving access rights. control.

可选地,如果第二访问地址属于可编程逻辑控制器中配置的闪存的可读地址范围,可编程逻辑控制器透传第二访问命令以及片上系统基于第二访问命令从闪存中读取的内容。Optionally, if the second access address belongs to the readable address range of the flash memory configured in the programmable logic controller, the programmable logic controller transparently transmits the second access command and the on-chip system reads from the flash memory based on the second access command. content.

可选地,如果第一命令字指示第一访问命令的访问类型为读,可编程逻辑控制器透传第一访问命令以及片上系统基于第一访问命令从闪存中读取的内容。Optionally, if the first command word indicates that the access type of the first access command is read, the programmable logic controller transparently transmits the first access command and the content read by the system-on-chip from the flash memory based on the first access command.

可选地,可编程逻辑控制器接收片上系统发送的模式切换指令,该模式切换指令用于指示可编程逻辑控制器由直接访问模式切换为间接访问模式,或者由间接访问模式切换为直接访问模式。Optionally, the programmable logic controller receives a mode switching instruction sent by the on-chip system. The mode switching instruction is used to instruct the programmable logic controller to switch from the direct access mode to the indirect access mode, or to switch from the indirect access mode to the direct access mode. .

可选地,在可编程逻辑控制器接收片上系统发送的针对闪存的第一访问命令之前,可编程逻辑控制器接收片上系统发送的配置命令,该配置命令包括保护地址范围。可编程逻辑控制器根据配置命令在可编程逻辑控制器中配置该保护地址范围。Optionally, before the programmable logic controller receives the first access command for the flash memory sent by the on-chip system, the programmable logic controller receives a configuration command sent by the on-chip system, and the configuration command includes the protection address range. The programmable logic controller configures the protection address range in the programmable logic controller according to the configuration command.

本申请中,由片上系统完成对可编程逻辑控制器的闪存保护功能配置。In this application, the on-chip system completes the configuration of the flash memory protection function of the programmable logic controller.

可选地,在可编程逻辑控制器根据配置命令在可编程逻辑控制器中配置保护地址范围之后,可编程逻辑控制器接收片上系统发送的锁定命令。可编程逻辑控制器根据该锁定命令锁定可编程逻辑控制器针对闪存的保护功能配置。其中,可编程逻辑控制器针对闪存的保护功能配置被锁定,是指可编程逻辑控制器中针对闪存的保护功能配置无法被修改。可编程逻辑控制器针对闪存的保护功能配置包括防篡改配置和/或访问权限控制配置。其中,防篡改配置包括在可编程逻辑控制器上配置闪存的保护地址范围,以及配置可编程逻辑控制器在间接访问模式下保护闪存中该保护地址范围对应的内容不被篡改。访问权限控制配置包括在可编程逻辑控制器上配置闪存的可读地址范围,以及配置可编程逻辑控制器在直接访问模式下只读闪存中该可读地址范围对应的内容。Optionally, after the programmable logic controller configures the protection address range in the programmable logic controller according to the configuration command, the programmable logic controller receives the lock command sent by the on-chip system. The programmable logic controller locks the protection function configuration of the programmable logic controller for the flash memory according to the lock command. Among them, the protection function configuration of the programmable logic controller for the flash memory is locked, which means that the protection function configuration of the programmable logic controller for the flash memory cannot be modified. The protection function configuration of the programmable logic controller for flash memory includes anti-tamper configuration and/or access control configuration. Among them, the anti-tampering configuration includes configuring the protection address range of the flash memory on the programmable logic controller, and configuring the programmable logic controller to protect the content corresponding to the protection address range in the flash memory from being tampered with in the indirect access mode. The access control configuration includes configuring the readable address range of the flash memory on the programmable logic controller, and configuring the content corresponding to the readable address range in the read-only flash memory of the programmable logic controller in direct access mode.

第三方面,提供了一种片上系统,包括:处理核、存储器和闪存控制器。该存储器用于存储程序指令,该处理核读取该存储器中保存的程序指令后,与闪存控制器配合实现上述第一方面及其各实施方式中的方法。In the third aspect, an on-chip system is provided, including: a processing core, a memory and a flash memory controller. The memory is used to store program instructions. After reading the program instructions stored in the memory, the processing core cooperates with the flash memory controller to implement the method in the above first aspect and each embodiment thereof.

第四方面,提供了一种可编程逻辑控制器,包括:可编程逻辑单元和可编程输入输出(input/output,IO)单元。可编程IO单元用于收发指令。可编程逻辑单元用于根据可编程IO单元接收到的指令执行逻辑功能,实现上述第二方面及其各实施方式中的方法。In a fourth aspect, a programmable logic controller is provided, including: a programmable logic unit and a programmable input/output (IO) unit. Programmable IO unit is used to send and receive instructions. The programmable logic unit is used to execute logical functions according to the instructions received by the programmable IO unit to implement the methods in the above second aspect and its various implementations.

第五方面,提供了一种数据保护系统,包括:片上系统和可编程逻辑控制器。该片上系统包括处理核和闪存控制器。可编程逻辑控制器与闪存控制器连接。In the fifth aspect, a data protection system is provided, including: a system on a chip and a programmable logic controller. The system-on-chip includes processing cores and flash memory controllers. The programmable logic controller is connected to the flash memory controller.

其中,处理核用于先通过运行第一可信程序,在可编程逻辑控制器中配置闪存的保护地址范围,再通过运行第二可信程序,对闪存中该保护地址范围对应的内容进行校验,并在确定该保护地址范围对应的内容校验通过之后,通过闪存控制器向闪存发送访问命令。可编程逻辑控制器用于在可编程逻辑控制器中配置该保护地址范围之后,实现上述第二方面及其各实施方式中的方法。Wherein, the processing core is used to first configure the protection address range of the flash memory in the programmable logic controller by running the first trusted program, and then run the second trusted program to calibrate the content corresponding to the protection address range in the flash memory. After confirming that the content corresponding to the protected address range has passed the verification, an access command is sent to the flash memory through the flash memory controller. The programmable logic controller is used to implement the method in the above second aspect and its various implementations after configuring the protection address range in the programmable logic controller.

第六方面,提供了一种计算机可读存储介质,所述计算机可读存储介质上存储有指令,当所述指令被处理器执行时,实现上述第一方面及其各实施方式中的方法或者上述第二方面及其各实施方式中的方法。In a sixth aspect, a computer-readable storage medium is provided. Instructions are stored on the computer-readable storage medium. When the instructions are executed by a processor, the methods in the above-mentioned first aspect and its various embodiments are implemented or Methods in the above-mentioned second aspect and its various embodiments.

第七方面,提供了一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时,实现上述第一方面及其各实施方式中的方法或者上述第二方面及其各实施方式中的方法。In a seventh aspect, a computer program product is provided, including a computer program. When the computer program is executed by a processor, it implements the method in the above-mentioned first aspect and its various embodiments or the above-mentioned second aspect and its various embodiments. Methods.

第八方面,提供了一种芯片,芯片包括可编程逻辑电路和/或程序指令,当芯片运行时,实现上述第一方面及其各实施方式中的方法或者上述第二方面及其各实施方式中的方法。In an eighth aspect, a chip is provided. The chip includes programmable logic circuits and/or program instructions. When the chip is running, the method in the above-mentioned first aspect and its various embodiments or the above-mentioned second aspect and its various embodiments are implemented. method in.

附图说明Description of the drawings

图1是本申请实施例提供的一种SoC的结构示意图;Figure 1 is a schematic structural diagram of an SoC provided by an embodiment of the present application;

图2是本申请实施例提供的一种应用场景示意图;Figure 2 is a schematic diagram of an application scenario provided by the embodiment of the present application;

图3是本申请实施例提供的另一种应用场景示意图;Figure 3 is a schematic diagram of another application scenario provided by the embodiment of the present application;

图4是本申请实施例提供的一种数据保护方法的流程示意图;Figure 4 is a schematic flowchart of a data protection method provided by an embodiment of the present application;

图5是本申请实施例提供的另一种数据保护方法的流程示意图;Figure 5 is a schematic flow chart of another data protection method provided by an embodiment of the present application;

图6是本申请实施例提供的一种可编程逻辑控制器的结构示意图。FIG. 6 is a schematic structural diagram of a programmable logic controller provided by an embodiment of the present application.

具体实施方式Detailed ways

为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施方式作进一步地详细描述。In order to make the purpose, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.

闪存是一种非易失性存储器。闪存支持被读取数据、写入数据和擦除数据,并且闪存能够在断电后保持存储的数据不丢失。闪存具有按块读写、读写速度慢和低成本的特点。例如相较于双倍数据速率同步动态随机存取存储器(doubledata rate synchronousdynamic random-access memory,DDR SDRAM),闪存的访问接口速率较低。NOR型闪存(英文:NOR flash,其中“NOR”取自其发明者公司的名称首字母)是目前比较常见的一种非易失性存储器,支持片上执行(execute on chip),即支持程序直接在闪存片内执行。因此在嵌入式系统中,NOR型闪存比较适合作为启动程序的存储介质。Flash memory is a type of non-volatile memory. Flash memory supports reading data, writing data and erasing data, and flash memory can keep stored data from being lost after power is turned off. Flash memory has the characteristics of reading and writing in blocks, slow reading and writing speed, and low cost. For example, compared to double data rate synchronous dynamic random-access memory (DDR SDRAM), flash memory has a lower access interface rate. NOR flash memory (English: NOR flash, where "NOR" is taken from the initials of its inventor's company) is a relatively common non-volatile memory at present. It supports on-chip execution (execute on chip), that is, it supports program direct execution. Executed within the flash memory chip. Therefore, in embedded systems, NOR flash memory is more suitable as a storage medium for startup programs.

SoC是指将包含处理核、存储器、外设接口和其它计算机组件集成到单一芯片上的一种集成电路。SoC能够处理数字信号、模拟信号或混合信号等。本申请实施例提供的SoC集成有闪存控制器,该SoC能够访问片外部署的闪存。例如,图1是本申请实施例提供的一种SoC的结构示意图。如图1所示,SoC 100包括处理核101、存储器102和闪存控制器103。处理核101、存储器102和闪存控制器103通过片上总线104连接。可选地,片上总线104包括但不限于高级可扩展接口(advanced extensible interface,AXI)总线、高级外设总线(advanced peripheral bus,APB)、高级高性能总线(advanced high-performance bus,AHB)或高级系统总线(advanced system bus,ASB)。SoC refers to an integrated circuit that integrates a processing core, memory, peripheral interfaces and other computer components onto a single chip. SoC can process digital signals, analog signals or mixed signals, etc. The SoC provided in the embodiment of this application is integrated with a flash memory controller, and the SoC can access the flash memory deployed off-chip. For example, FIG. 1 is a schematic structural diagram of an SoC provided by an embodiment of the present application. As shown in FIG. 1 , SoC 100 includes a processing core 101 , a memory 102 and a flash memory controller 103 . The processing core 101, the memory 102 and the flash memory controller 103 are connected through an on-chip bus 104. Optionally, the on-chip bus 104 includes, but is not limited to, an advanced extensible interface (AXI) bus, an advanced peripheral bus (APB), an advanced high-performance bus (AHB) or Advanced system bus (ASB).

其中,处理核101是SoC 100内部负责运算的核心单元。处理核101例如为中央处理单元(central processing unit,CPU)核心。Among them, the processing core 101 is the core unit responsible for calculation inside the SoC 100 . The processing core 101 is, for example, a central processing unit (CPU) core.

存储器102是SoC 100内部的存储介质。存储器102包括随机存取存储器(randomaccess memory,RAM)。RAM是一种易失性存储器,支持随时读取写入数据,但是一旦掉电数据就会丢失。本申请实施例中,RAM用作运行内存,用于存放处理核101所需执行的计算机程序。一个可执行的计算机程序通常部署有代码段(code segment/text segment)、数据(data)段、以符号开始的块(block started by symbol,BSS)段、栈(stack)和堆(heap)。其中代码段中的内容在计算机程序的运行过程中通常是不变的,数据段、BSS段、栈和堆中的内容在计算机程序的运行过程中会发生变化。RAM可用于存放代码段、数据段、BSS段、栈和堆等内容。Memory 102 is a storage medium within SoC 100 . Memory 102 includes random access memory (RAM). RAM is a volatile memory that supports reading and writing data at any time, but the data will be lost once the power is turned off. In the embodiment of the present application, RAM is used as a running memory to store computer programs that the processing core 101 needs to execute. An executable computer program is usually deployed with a code segment/text segment, a data segment, a block started by symbol (BSS) segment, a stack and a heap. The contents in the code segment usually remain unchanged during the running of the computer program, while the contents in the data segment, BSS segment, stack and heap will change during the running of the computer program. RAM can be used to store code segments, data segments, BSS segments, stacks, heaps, etc.

可选地,存储器102还包括只读存储器(read-only memory,ROM)和/或一次性可编程存储器(eFuse)等其它存储介质。其中,ROM是一种非易失性存储器,ROM中存储的数据会永久保存,掉电后数据也不会丢失。ROM只支持读出存储的数据,不支持写入或删除数据。本申请实施例中,ROM用于存放SoC 100上电或复位后处理核101运行所需的基本程序文件,这里的程序文件是指计算机程序运行所需的代码和数据(包括变量等),包括但不限于代码段和数据段。一次性可编程存储器通常用于存储安全相关的信息。本申请实施例中,一次性可编程存储器用于存储密钥相关信息,比如密钥或密钥的哈希值。Optionally, the memory 102 also includes other storage media such as read-only memory (ROM) and/or one-time programmable memory (eFuse). Among them, ROM is a kind of non-volatile memory. The data stored in ROM will be saved permanently and the data will not be lost after power failure. ROM only supports reading out stored data and does not support writing or deleting data. In the embodiment of the present application, the ROM is used to store the basic program files required for the operation of the processing core 101 after the SoC 100 is powered on or reset. The program files here refer to the codes and data (including variables, etc.) required for the operation of the computer program, including But not limited to code segments and data segments. One-time programmable memories are often used to store security-related information. In the embodiment of the present application, the one-time programmable memory is used to store key-related information, such as the key or the hash value of the key.

闪存控制器103是SoC 100内部用来控制片外闪存的器件。处理核101通过闪存控制器103访问片外闪存。处理核101针对闪存的访问类型包括读、写和擦除。读是指对闪存中存储的内容进行读取。写是指向闪存写入新的内容。擦除是指删除闪存中的原有内容。The flash memory controller 103 is a device inside the SoC 100 used to control off-chip flash memory. The processing core 101 accesses the off-chip flash memory through the flash memory controller 103 . The access types of the processing core 101 to the flash memory include reading, writing and erasing. Reading refers to reading the contents stored in the flash memory. Writing means writing new content to the flash memory. Erase refers to deleting the original content in flash memory.

可选地,SoC 100还包括外设接口105,外设接口105通过片上总线104与处理核101和存储器102连接。处理核101能够通过外设接口接收外部输入的命令或数据等。Optionally, the SoC 100 also includes a peripheral interface 105, which is connected to the processing core 101 and the memory 102 through the on-chip bus 104. The processing core 101 can receive externally input commands or data through a peripheral interface.

上述图1所示的SoC 100仅仅是示例性的,在实现过程中,SoC 100还可以包括其他计算机组件,本申请实施例不再一一列举。The SoC 100 shown in FIG. 1 is only exemplary. During the implementation process, the SoC 100 may also include other computer components, which will not be listed one by one in the embodiment of this application.

目前在嵌入式小型化场景下,为了节约成本,可以直接将代码部署在闪存上运行。例如对于如图1所示的SoC 100,利用SoC 100内部的RAM作为堆栈空间,处理核101直接从片外闪存中读取程序文件并执行其中的代码,而无需将读取的程序文件中的代码搬移到内存102中,这种场景称为就地执行(execute in place,XIP)。但是这种应用场景带来了一些安全风险。由于代码存储在闪存上,而闪存的访问接口速率较低,因此即使处理核在访问闪存之前完成了对闪存中代码的安全校验,在校验通过后到处理核成功访问到闪存中代码的过程中,还是存在被攻击的时间窗。在这个时间窗内,攻击者有可能拿到闪存的操作权进而篡改闪存中的代码,导致处理核无法访问到闪存中的原有代码,进而无法正常运行。Currently, in the embedded miniaturization scenario, in order to save costs, the code can be directly deployed and run on flash memory. For example, for the SoC 100 shown in Figure 1, the RAM inside the SoC 100 is used as the stack space. The processing core 101 directly reads the program file from the off-chip flash memory and executes the code therein, without the need to convert the read program file into the SoC 100. The code is moved to memory 102. This scenario is called execute in place (XIP). But this application scenario brings some security risks. Since the code is stored in the flash memory, and the access interface rate of the flash memory is low, even if the processing core completes the security verification of the code in the flash memory before accessing the flash memory, it will not be until the processing core successfully accesses the code in the flash memory after the verification passes. During the process, there is still a time window for being attacked. During this time window, an attacker may gain access to the flash memory and tamper with the code in the flash memory, causing the processing core to be unable to access the original code in the flash memory and thus unable to operate normally.

基于此,本申请提供了一种针对闪存的数据保护方法。通过在部署在处理核与闪存之间的控制器上配置针对闪存的保护功能,例如在该控制器中配置闪存的保护地址范围,如果处理核想要修改闪存中该保护地址范围对应的内容,则控制器阻止该修改行为,从而保护闪存中该保护地址范围对应的内容不被篡改,实现针对闪存的数据防篡改功能,能够提高闪存中数据的安全性和可靠性。Based on this, this application provides a data protection method for flash memory. By configuring the protection function for flash memory on the controller deployed between the processing core and the flash memory, for example, configuring the protection address range of the flash memory in the controller, if the processing core wants to modify the content corresponding to the protection address range in the flash memory, Then the controller prevents the modification behavior, thereby protecting the content corresponding to the protected address range in the flash memory from being tampered with, realizing the data anti-tampering function for the flash memory, and improving the security and reliability of the data in the flash memory.

可选地,配置有针对闪存的保护功能的上述控制器为SoC内部的闪存控制器或者是部署在SoC与闪存之间的可编程逻辑控制器。例如,图2和图3分别是本申请实施例提供的一种应用场景示意图。如图2所示,该应用场景包括SoC 100和闪存200。如图3所示,该应用场景包括SoC 100、闪存200和可编程逻辑控制器300,可编程逻辑控制器300部署在SoC 100与闪存200之间。SoC 100的结构例如参考图1。SoC 100中的处理核101能够通过闪存控制器103访问闪存200。Optionally, the above-mentioned controller configured with a protection function for flash memory is a flash memory controller inside the SoC or a programmable logic controller deployed between the SoC and the flash memory. For example, Figure 2 and Figure 3 are respectively schematic diagrams of an application scenario provided by the embodiment of the present application. As shown in Figure 2, the application scenario includes SoC 100 and flash memory 200. As shown in Figure 3, the application scenario includes SoC 100, flash memory 200 and programmable logic controller 300. The programmable logic controller 300 is deployed between SoC 100 and flash memory 200. The structure of the SoC 100 is illustrated in FIG. 1 . The processing core 101 in the SoC 100 can access the flash memory 200 through the flash memory controller 103.

闪存200支持被读取数据、写入数据和擦除数据。可选地,闪存200用于存储程序文件,程序文件包括代码段和数据段等。SoC 100中的处理核101能够通过闪存控制器103直接执行闪存200上的代码,相应的数据段、BSS段、堆和栈部署在存储器102中。闪存200还用于存储软件包、固件等其它数据。闪存200例如为NOR型闪存。The flash memory 200 supports data being read, data being written, and data being erased. Optionally, the flash memory 200 is used to store program files, which include code segments, data segments, etc. The processing core 101 in the SoC 100 can directly execute the code on the flash memory 200 through the flash memory controller 103, and the corresponding data segment, BSS segment, heap and stack are deployed in the memory 102. The flash memory 200 is also used to store software packages, firmware and other data. The flash memory 200 is, for example, a NOR type flash memory.

在如图2所示的应用场景中,SoC 100中的闪存控制器103通过片间总线400与闪存200连接。SoC100与闪存200可以分别设置在彼此独立的芯片上,也可以设置在同一块芯片上。In the application scenario shown in FIG. 2 , the flash memory controller 103 in the SoC 100 is connected to the flash memory 200 through the inter-chip bus 400 . The SoC 100 and the flash memory 200 may be installed on separate chips, or may be installed on the same chip.

在如图3所示的应用场景中,SoC 100中的闪存控制器103通过片间总线400与可编程逻辑控制器300连接,可编程逻辑控制器300与闪存200通过片间总线400连接。SoC 100、可编程逻辑控制器300与闪存200可以分别设置在彼此独立的芯片上,也可以至少部分的或者全部的设置在同一块芯片上。In the application scenario shown in FIG. 3 , the flash memory controller 103 in the SoC 100 is connected to the programmable logic controller 300 through the inter-chip bus 400 , and the programmable logic controller 300 and the flash memory 200 are connected through the inter-chip bus 400 . The SoC 100, the programmable logic controller 300 and the flash memory 200 may be respectively provided on separate chips, or may be at least partially or entirely provided on the same chip.

可选地,可编程逻辑控制器300为可编程逻辑器件(programmable logic device,PLD),包括但不限于复杂可编程逻辑器件(complex programmable logic device,CPLD),现场可编程逻辑门阵列(field-programmable gate array,FPGA),通用阵列逻辑(genericarray logic,GAL)或其任意组合。Optionally, the programmable logic controller 300 is a programmable logic device (PLD), including but not limited to a complex programmable logic device (CPLD), a field-programmable logic gate array (field-programmable logic device). programmable gate array (FPGA), general array logic (GAL) or any combination thereof.

其中,片间总线400是任何类型的、用于实现不同器件互连的通信总线,例如为系统总线。The inter-chip bus 400 is any type of communication bus used to interconnect different devices, such as a system bus.

可选地,闪存控制器103设置有两种访问模式,包括直接访问模式和间接访问模式。当闪存控制器103处于直接访问模式时,处理核101通过发送地址直接读取闪存200中该地址对应的内容。例如,处理核101的运行指针(如程序计数器(program counter,PC)指针)直接指向闪存200的某个程序地址,然后由闪存控制器103构造访问类型为读的命令字,并基于该命令字和处理核101提供的地址从闪存200中读取相应的程序文件至处理核101,由处理核101执行该程序文件中的代码。也就是说,当闪存控制器103处于直接访问模式时,处理核101无需运行软件代码即可读取到闪存200中的内容。当闪存控制器103处于间接访问模式时,处理核101通过运行软件代码构造访问闪存200的命令字,然后通过发送命令字和地址从闪存200中读取该地址对应的内容、向闪存200中的该地址写入内容或者擦除闪存200中该地址对应的内容。也就是说,当闪存控制器103处于间接访问模式时,处理核101需要运行软件代码来完成针对闪存200的读、写或擦除操作。本申请实施例中,将处理核101在闪存控制器103处于间接访问模式下对闪存200进行访问称为处理核101间接访问闪存200,将处理核101在闪存控制器103处于直接访问模式下对闪存200进行访问称为处理核101直接访问闪存200。Optionally, the flash memory controller 103 is provided with two access modes, including a direct access mode and an indirect access mode. When the flash memory controller 103 is in the direct access mode, the processing core 101 directly reads the content corresponding to the address in the flash memory 200 by sending the address. For example, the running pointer (such as a program counter (PC) pointer) of the processing core 101 directly points to a certain program address of the flash memory 200, and then the flash memory controller 103 constructs a command word with an access type of read, and based on the command word The corresponding program file is read from the flash memory 200 to the processing core 101 with the address provided by the processing core 101, and the processing core 101 executes the code in the program file. That is to say, when the flash memory controller 103 is in the direct access mode, the processing core 101 can read the contents of the flash memory 200 without running software code. When the flash memory controller 103 is in the indirect access mode, the processing core 101 constructs a command word to access the flash memory 200 by running the software code, and then reads the content corresponding to the address from the flash memory 200 by sending the command word and address, and sends the command word to the flash memory 200 . The address writes content or erases the content corresponding to the address in the flash memory 200 . That is to say, when the flash memory controller 103 is in the indirect access mode, the processing core 101 needs to run software code to complete the read, write or erase operation for the flash memory 200 . In the embodiment of the present application, the processing core 101 accessing the flash memory 200 when the flash memory controller 103 is in the indirect access mode is called the processing core 101 indirectly accessing the flash memory 200. The processing core 101 accessing the flash memory 200 when the flash memory controller 103 is in the direct access mode. Access to the flash memory 200 is called direct access by the processing core 101 to the flash memory 200 .

值得说明的是,闪存控制器103在同一时刻只能使能一种访问模式。当闪存控制器103处于直接访问模式时,仅支持处理核101对闪存200的读操作。当闪存控制器103处于间接访问模式时,支持处理核101对闪存200的读、写和擦除操作。可选地,闪存控制器103的访问模式由处理核101控制切换。比如闪存控制器103接收处理核101发送的模式切换指令,该模式切换指令用于指示闪存控制器103由直接访问模式切换为间接访问模式,或者由间接访问模式切换为直接访问模式。例如,当处理核101需要直接运行闪存200中的代码(XIP)时,处理核101控制闪存控制器103切换至直接访问模式。当处理核101需要修改闪存200中的内容时,处理核101控制闪存控制器103切换至间接访问模式。It is worth noting that the flash memory controller 103 can only enable one access mode at the same time. When the flash memory controller 103 is in the direct access mode, only the read operation of the flash memory 200 by the processing core 101 is supported. When the flash memory controller 103 is in the indirect access mode, the processing core 101 supports read, write and erase operations on the flash memory 200 . Optionally, the access mode of the flash memory controller 103 is switched under the control of the processing core 101 . For example, the flash memory controller 103 receives a mode switching instruction sent by the processing core 101. The mode switching instruction is used to instruct the flash memory controller 103 to switch from the direct access mode to the indirect access mode, or from the indirect access mode to the direct access mode. For example, when the processing core 101 needs to directly run the code (XIP) in the flash memory 200, the processing core 101 controls the flash memory controller 103 to switch to the direct access mode. When the processing core 101 needs to modify the content in the flash memory 200, the processing core 101 controls the flash memory controller 103 to switch to the indirect access mode.

本申请实施例针对上述图2和图3示出的两种应用场景,对本申请的技术方案分别进行详细说明。The embodiments of the present application provide detailed descriptions of the technical solutions of the present application for the two application scenarios shown in Figures 2 and 3 above.

本申请的第一个可选实施例应用于如图2所示的应用场景。该技术方案如下,闪存控制器接收处理核发送的针对闪存的访问命令,该访问命令包括命令字和访问地址。该命令字用于指示该访问命令的访问类型,该访问类型包括读、写或擦除。该访问地址用于指示该访问命令在闪存中所访问的地址范围。如果该命令字指示该访问命令的访问类型为写或擦除,且该访问地址属于闪存控制器中配置的闪存的保护地址范围,闪存控制器拦截该访问命令。本申请实施例中,通过在闪存控制器上配置针对闪存的保护功能,例如在闪存控制器中配置闪存的保护地址范围,如果处理核想要修改闪存中该保护地址范围对应的内容,则闪存控制器阻止该修改行为,从而保护闪存中该保护地址范围对应的内容不被篡改,实现针对闪存的数据防篡改功能,能够提高闪存中数据的安全性和可靠性。The first optional embodiment of this application is applied to the application scenario shown in Figure 2. The technical solution is as follows: the flash memory controller receives an access command for the flash memory sent by the processing core, and the access command includes a command word and an access address. The command word is used to indicate the access type of the access command, which includes read, write or erase. The access address is used to indicate the address range accessed by the access command in the flash memory. If the command word indicates that the access type of the access command is write or erase, and the access address belongs to the protected address range of the flash memory configured in the flash memory controller, the flash memory controller intercepts the access command. In the embodiment of the present application, by configuring the protection function for flash memory on the flash memory controller, for example, configuring the protection address range of the flash memory in the flash memory controller, if the processing core wants to modify the content corresponding to the protection address range in the flash memory, the flash memory The controller prevents this modification behavior, thereby protecting the content corresponding to the protected address range in the flash memory from being tampered with, realizing the data anti-tampering function for the flash memory, and improving the security and reliability of the data in the flash memory.

本申请以下实施例以闪存控制器设置有两种访问模式为例进行说明。例如,图4是本申请实施例提供的一种数据保护方法400的流程示意图。如图4所示,该方法400包括但不限于以下步骤401至步骤407。其中,步骤401至步骤403示出了闪存控制器在间接访问模式下对闪存的内容防篡改保护。步骤404至步骤407示出了闪存控制器在直接访问模式下对闪存的访问权限控制。The following embodiments of this application take the flash memory controller configured with two access modes as an example for description. For example, FIG. 4 is a schematic flowchart of a data protection method 400 provided by an embodiment of the present application. As shown in Figure 4, the method 400 includes but is not limited to the following steps 401 to 407. Among them, steps 401 to 403 show that the flash memory controller protects the contents of the flash memory from tampering in the indirect access mode. Steps 404 to 407 illustrate the access permission control of the flash memory by the flash memory controller in the direct access mode.

步骤401、闪存控制器在间接访问模式下接收处理核发送的针对闪存的访问命令11,访问命令11包括命令字11和访问地址11。Step 401: The flash memory controller receives the access command 11 for the flash memory sent by the processing core in the indirect access mode. The access command 11 includes the command word 11 and the access address 11.

命令字11用于指示访问命令11的访问类型。访问命令11的访问类型包括读、写或擦除。访问地址11用于指示访问命令11在闪存中所访问的地址范围。其中,命令字11由处理核通过运行软件代码生成。可选地,如果访问命令11的访问类型为写,则访问命令11还包括待写入内容。Command word 11 is used to indicate the access type of access command 11. The access type of access command 11 includes read, write or erase. Access address 11 is used to indicate the address range accessed by the access command 11 in the flash memory. Among them, command word 11 is generated by the processing core by running software code. Optionally, if the access type of the access command 11 is writing, the access command 11 also includes content to be written.

在此步骤401执行之前,处理核需要先确保闪存控制器处于间接访问模式下。比如,处理核先向闪存控制器发送模式切换指令11,该模式切换指令11用于指示闪存控制器由直接访问模式切换为间接访问模式,然后处理核再生成并发出访问命令11。如果闪存控制器接收到模式切换指令11时处于直接访问模式,则闪存控制器切换为间接访问模式,之后在间接访问模式下接收并处理访问命令11。Before executing step 401, the processing core needs to ensure that the flash memory controller is in indirect access mode. For example, the processing core first sends a mode switching instruction 11 to the flash memory controller. The mode switching instruction 11 is used to instruct the flash memory controller to switch from the direct access mode to the indirect access mode. Then the processing core generates and issues the access command 11. If the flash memory controller is in the direct access mode when it receives the mode switching command 11, the flash memory controller switches to the indirect access mode, and then receives and processes the access command 11 in the indirect access mode.

步骤402、如果命令字11指示访问命令11的访问类型为写或擦除,且访问地址11属于闪存控制器中配置的闪存的保护地址范围,闪存控制器拦截访问命令11。Step 402: If the command word 11 indicates that the access type of the access command 11 is write or erase, and the access address 11 belongs to the protection address range of the flash memory configured in the flash memory controller, the flash memory controller intercepts the access command 11.

命令字11指示访问命令11的访问类型为写或擦除,则表示访问命令11会修改闪存中的内容。闪存控制器在间接访问模式下接收到处理核发送的访问命令后,会根据该访问命令中的命令字和访问地址判断该访问命令是否会修改闪存控制器中配置的闪存的保护地址范围对应的内容。如果该访问命令会修改闪存中该保护地址范围对应的内容,则闪存控制器拦截该访问命令,以阻止该修改行为,从而保护闪存中该保护地址范围对应的内容不被篡改。Command word 11 indicates that the access type of access command 11 is write or erase, which means that access command 11 will modify the contents of the flash memory. After the flash memory controller receives the access command sent by the processing core in the indirect access mode, it will determine whether the access command will modify the protection address range corresponding to the flash memory configured in the flash memory controller based on the command word and access address in the access command. content. If the access command will modify the content corresponding to the protected address range in the flash memory, the flash memory controller intercepts the access command to prevent the modification, thereby protecting the content corresponding to the protected address range in the flash memory from being tampered with.

可选地,闪存控制器在确定处理核发送的访问命令会修改闪存控制器中配置的闪存的保护地址范围对应的内容之后,发出告警提示,该告警提示用于指示闪存有被篡改风险,以便运维人员及时排查攻击行为。Optionally, after determining that the access command sent by the processing core will modify the content corresponding to the protected address range of the flash memory configured in the flash memory controller, the flash memory controller issues an alarm prompt, which is used to indicate that the flash memory is at risk of being tampered with, so that Operation and maintenance personnel promptly investigate attacks.

可选地,闪存中部署有程序文件,闪存控制器中配置的闪存的保护地址范围包括闪存中程序文件的地址范围。该程序文件包括代码段和数据段。这样闪存控制器能够保护闪存中的程序文件不被篡改,保证处理核能够正常运行该程序文件中的代码。可选地,闪存还用于存储除程序文件以外的其它内容,比如软件包或固件等,闪存控制器中配置的闪存的保护地址范围还包括闪存中其它内容的地址范围,以保护该部分内容不被篡改。闪存控制器中的保护地址范围可以根据实际需求进行配置,本申请实施例对此不做限定。Optionally, a program file is deployed in the flash memory, and the protection address range of the flash memory configured in the flash memory controller includes the address range of the program file in the flash memory. The program file includes code segments and data segments. In this way, the flash memory controller can protect the program file in the flash memory from being tampered with and ensure that the processing core can run the code in the program file normally. Optionally, the flash memory is also used to store other contents besides program files, such as software packages or firmware. The protection address range of the flash memory configured in the flash memory controller also includes the address range of other contents in the flash memory to protect this part of the contents. Not tampered with. The protection address range in the flash memory controller can be configured according to actual needs, and this is not limited in the embodiments of this application.

步骤403、如果命令字11指示访问命令11的访问类型为读,闪存控制器基于命令字11和访问地址11从闪存中读取访问地址11对应的内容,并将访问地址11对应的内容发送给处理核。Step 403. If the command word 11 indicates that the access type of the access command 11 is read, the flash memory controller reads the content corresponding to the access address 11 from the flash memory based on the command word 11 and the access address 11, and sends the content corresponding to the access address 11 to Process core.

命令字11指示访问命令11的访问类型为读,则表示访问命令11不会修改闪存中的内容。如果闪存控制器在间接访问模式下接收到处理核发送的读命令,则闪存控制器直接从闪存中读取对应的内容并将读取的内容发送给处理核,以帮助处理核完成对闪存的访问。或者,如果闪存控制器在间接访问模式下接收到处理核发送的写命令或擦除命令但访问地址不属于配置的保护地址范围,则闪存控制器针对闪存执行该写命令或擦除命令。Command word 11 indicates that the access type of access command 11 is read, which means that access command 11 will not modify the contents of the flash memory. If the flash memory controller receives a read command sent by the processing core in indirect access mode, the flash memory controller directly reads the corresponding content from the flash memory and sends the read content to the processing core to help the processing core complete the processing of the flash memory. access. Alternatively, if the flash memory controller receives a write command or erase command sent by the processing core in the indirect access mode but the access address does not fall within the configured protection address range, the flash memory controller executes the write command or erase command for the flash memory.

步骤404、闪存控制器在直接访问模式下接收处理核发送的针对闪存的访问命令12,访问命令12包括访问地址12。Step 404: The flash memory controller receives the access command 12 for the flash memory sent by the processing core in the direct access mode. The access command 12 includes the access address 12.

访问地址12用于指示访问命令12在闪存中所访问的地址范围。访问命令12为读命令。在此步骤404执行之前,处理核需要先确保闪存控制器处于直接访问模式下。比如,处理核先向闪存控制器发送模式切换指令12,该模式切换指令12用于指示闪存控制器由间接访问模式切换为直接访问模式,然后处理核再发出访问命令12。如果闪存控制器接收到模式切换指令12时处于间接访问模式,则闪存控制器切换为直接访问模式,之后在直接访问模式下接收并处理访问命令12。The access address 12 is used to indicate the address range accessed by the access command 12 in the flash memory. Access command 12 is a read command. Before executing step 404, the processing core needs to ensure that the flash memory controller is in direct access mode. For example, the processing core first sends a mode switching instruction 12 to the flash memory controller. The mode switching instruction 12 is used to instruct the flash memory controller to switch from the indirect access mode to the direct access mode, and then the processing core sends the access command 12. If the flash memory controller is in the indirect access mode when it receives the mode switching command 12, the flash memory controller switches to the direct access mode, and then receives and processes the access command 12 in the direct access mode.

步骤405、如果访问地址12不属于闪存控制器中配置的闪存的可读地址范围,闪存控制器拦截访问命令12。Step 405: If the access address 12 does not belong to the readable address range of the flash memory configured in the flash memory controller, the flash memory controller intercepts the access command 12.

闪存控制器在直接访问模式下接收到处理核发送的访问命令后,会根据该访问命令中的访问地址判断该访问命令所要读取的内容是否在配置的可读地址范围内。如果该访问命令所要读取的内容不在配置的可读地址范围内,则闪存控制器拦截该访问命令,以阻止处理核的读取行为。After receiving the access command sent by the processing core in the direct access mode, the flash memory controller will determine whether the content to be read by the access command is within the configured readable address range based on the access address in the access command. If the content to be read by the access command is not within the configured readable address range, the flash memory controller intercepts the access command to prevent the reading behavior of the processing core.

可选地,闪存控制器在确定处理核发送的访问命令所要读取的内容不在配置的可读地址范围内之后,发出错误提示,该错误提示用于指示处理核的访问地址出错。Optionally, after determining that the content to be read by the access command sent by the processing core is not within the configured readable address range, the flash memory controller issues an error prompt, and the error prompt is used to indicate that the access address of the processing core is incorrect.

本申请实施例中,通过在闪存控制器中配置闪存的可读地址范围,使得处理核在闪存控制器处于直接访问模式时,只能读取到闪存中该可读地址范围对应的内容,实现访问权限控制。例如将保存在闪存上的某个程序文件的地址范围配置成可读地址范围,则处理核能够通过直接访问读取闪存中的该程序文件并运行该程序文件中的代码段。相应地,将闪存中除该程序文件的地址范围以外的其它地址配置成不可读地址范围,保证处理核无法通过直接访问读取闪存中不可读地址范围对应的内容。In the embodiment of the present application, by configuring the readable address range of the flash memory in the flash memory controller, the processing core can only read the content corresponding to the readable address range in the flash memory when the flash memory controller is in the direct access mode, realizing Access control. For example, if the address range of a program file stored in the flash memory is configured as a readable address range, the processing core can read the program file in the flash memory through direct access and run the code segment in the program file. Correspondingly, other addresses in the flash memory except the address range of the program file are configured as unreadable address ranges to ensure that the processing core cannot read the contents corresponding to the unreadable address range in the flash memory through direct access.

可选地,闪存控制器中配置的闪存的可读地址范围与配置的闪存的保护地址范围相同。Optionally, the readable address range of the flash memory configured in the flash memory controller is the same as the protected address range of the configured flash memory.

本申请实施例中,通过在闪存控制器中配置相同的可读地址范围和保护地址范围,由于闪存中保护地址范围对应的内容无法被篡改,且处理核在直接访问闪存时只能读取到可读地址范围对应的内容,因此能够保证处理核通过直接访问从闪存中读取的内容是未经篡改的,从而提高处理核的运行可靠性。比如在配置的保护地址范围和可读地址范围包括闪存中部署的程序文件的情况下,通过在闪存控制器中配置针对该程序文件的保护功能,使得该程序文件的内容不可被修改且只有该程序文件在直接访问模式下可读,即处理核只能直接运行闪存中受保护的程序文件。避免了攻击者修改了闪存中未受保护的程序文件,以及修改处理核的运行指针指向该修改过的程序文件的地址,导致处理核从闪存中读取并运行错误代码的情况。In the embodiment of this application, by configuring the same readable address range and protected address range in the flash memory controller, the content corresponding to the protected address range in the flash memory cannot be tampered with, and the processing core can only read it when directly accessing the flash memory. The content corresponding to the readable address range can ensure that the content read from the flash memory by the processing core through direct access has not been tampered with, thereby improving the operational reliability of the processing core. For example, when the configured protection address range and readable address range include a program file deployed in flash memory, by configuring the protection function for the program file in the flash memory controller, the content of the program file cannot be modified and only the program file can be modified. Program files are readable in direct access mode, that is, the processing core can only directly run protected program files in flash memory. This avoids the situation where an attacker modifies an unprotected program file in the flash memory and modifies the running pointer of the processing core to point to the address of the modified program file, causing the processing core to read and run incorrect code from the flash memory.

步骤406、如果访问地址12属于闪存控制器中配置的闪存的可读地址范围,闪存控制器生成命令字12,命令字12用于指示访问命令12的访问类型为读。Step 406: If the access address 12 belongs to the readable address range of the flash memory configured in the flash memory controller, the flash memory controller generates a command word 12. The command word 12 is used to indicate that the access type of the access command 12 is read.

步骤407、闪存控制器基于命令字12和访问地址12从闪存中读取访问地址12对应的内容,并将访问地址12对应的内容发送给处理核。Step 407: The flash memory controller reads the content corresponding to the access address 12 from the flash memory based on the command word 12 and the access address 12, and sends the content corresponding to the access address 12 to the processing core.

可选地,访问地址12对应的内容包括代码段,处理核接收到代码段之后直接运行该代码段。可选地,访问地址12对应的内容还包括数据段、BSS段、堆和栈等内容,处理核接收到数据段、BSS段、堆和栈等内容之后,将这些内容保存在SoC内部的存储器上,例如RAM上,完成片上执行的软硬件环境部署。Optionally, the content corresponding to the access address 12 includes a code segment, and the processing core directly runs the code segment after receiving the code segment. Optionally, the content corresponding to the access address 12 also includes the data segment, BSS segment, heap and stack. After the processing core receives the data segment, BSS segment, heap and stack, etc., it saves these contents in the memory inside the SoC. On, for example, RAM, the software and hardware environment deployment for on-chip execution is completed.

本申请实施例中,在上述步骤401至步骤403执行之前,需要在闪存控制器中配置闪存的保护地址范围,以供闪存控制器在间接访问模式下使用。在上述步骤404至步骤407执行之前,需要在闪存控制器中配置闪存的可读地址范围,以供闪存控制器在直接访问模式下使用。为了保证配置安全性和可靠性,可以通过可信组件配置闪存控制器。可信组件是经过校验的组件,且运行在安全环境中。本申请实施例通过SoC中的硬件隔离机制来保证组件的可信,这里的组件是指处理核运行的程序文件。例如,在上述步骤401至步骤403执行之前,执行以下步骤S11至步骤S12。In the embodiment of the present application, before the above-mentioned steps 401 to 403 are executed, the protection address range of the flash memory needs to be configured in the flash memory controller for use by the flash memory controller in the indirect access mode. Before the above steps 404 to 407 are executed, the readable address range of the flash memory needs to be configured in the flash memory controller for use by the flash memory controller in the direct access mode. To ensure configuration security and reliability, the flash controller can be configured through trusted components. Trusted components are components that have been verified and run in a secure environment. The embodiment of this application ensures the trustworthiness of components through the hardware isolation mechanism in the SoC. The components here refer to program files that process core operation. For example, before the above steps 401 to 403 are executed, the following steps S11 to S12 are executed.

在步骤S11中,处理核通过运行第一可信程序,在闪存控制器中配置闪存的保护地址范围。In step S11, the processing core configures the protection address range of the flash memory in the flash memory controller by running the first trusted program.

可选地,第一可信程序为保存在SoC内部的存储器中、且经过校验的程序。处理核在闪存控制器中配置闪存的保护地址范围用于闪存控制器在间接访问模式下闪存中该保护地址范围对应的内容不被篡改。Optionally, the first trusted program is a program that is stored in the memory inside the SoC and has been verified. The processing core configures the protection address range of the flash memory in the flash memory controller so that the contents corresponding to the protection address range in the flash memory of the flash memory controller are not tampered with in the indirect access mode.

在步骤S12中,处理核通过运行第二可信程序,对闪存中该保护地址范围对应的内容进行校验。In step S12, the processing core verifies the content corresponding to the protected address range in the flash memory by running the second trusted program.

可选地,第二可信程序为保存在SoC内部的存储器中、且经过校验的程序。处理核在确定闪存中该保护地址范围对应的内容校验通过之后,再执行上述步骤401。Optionally, the second trusted program is a program that is stored in the memory inside the SoC and has been verified. After the processing core determines that the content corresponding to the protected address range in the flash memory has passed the verification, it then executes the above step 401.

本申请实施例中,通过先在闪存控制器中配置闪存的保护地址范围,再对闪存中该保护地址范围对应的内容进行校验。这样,在处理核对闪存中该保护地址范围对应的内容校验通过之后,如果闪存控制器接收到针对闪存中该保护地址范围对应的内容的修改指令,闪存控制器则拦截该修改指令以阻止对闪存的修改,从而能够避免处理核校验通过后到访问闪存的时间窗内闪存中经过校验的内容被篡改,提高了闪存中数据的安全性和可靠性。In the embodiment of the present application, the protection address range of the flash memory is first configured in the flash memory controller, and then the content corresponding to the protection address range in the flash memory is verified. In this way, after the verification of the content corresponding to the protected address range in the flash memory passes, if the flash memory controller receives a modification instruction for the content corresponding to the protected address range in the flash memory, the flash memory controller intercepts the modification instruction to prevent the modification. The modification of the flash memory can prevent the verified content in the flash memory from being tampered with during the time window from when the processing core verification is passed to when the flash memory is accessed, thereby improving the security and reliability of the data in the flash memory.

可选地,上述步骤S11至步骤S12由处理核在安全启动过程中执行。处理核在安全启动过程中遵循“先校验,再执行”的原则完成信任链校验,即处理核当前运行的程序文件负责校验下一阶段待运行的程序文件,等到下一阶段待运行的程序文件成为处理核当前运行的程序文件后,再继续校验新的下一阶段待运行的程序文件,以此循环往复。例如,SoC包括ROM和RAM,ROM中存储有SoC上电或复位后处理核运行所需的基本程序文件,这里称为第一程序文件。可选地,SoC还包括一次性可编程存储器。一次性可编程存储器中存储有密钥的哈希值。则在上述步骤S11至步骤S12执行之前,先执行以下步骤S13至步骤S15。Optionally, the above steps S11 to S12 are executed by the processing core during the secure boot process. During the safe startup process, the processing core follows the principle of "verify first, then execute" to complete trust chain verification. That is, the program file currently running in the processing core is responsible for verifying the program file to be run in the next stage, and waits until the next stage to be run. After the program file becomes the program file currently run by the processing core, it continues to verify the new program file to be run in the next stage, and the cycle repeats. For example, the SoC includes ROM and RAM. The ROM stores the basic program files required for the processing core to run after the SoC is powered on or reset, which is called the first program file here. Optionally, the SoC also includes one-time programmable memory. The hash value of the key is stored in the one-time programmable memory. Then, before the above-mentioned steps S11 to step S12 are executed, the following steps S13 to step S15 are first executed.

在步骤S13中,SoC上电或复位后,处理核通过运行ROM中的第一程序文件,通过闪存控制器读取闪存中的第二程序文件以及第一签名,并将读取的第二程序文件和第一签名保存在RAM中。In step S13, after the SoC is powered on or reset, the processing core reads the second program file and the first signature in the flash memory through the flash memory controller by running the first program file in the ROM, and transfers the read second program file The file and first signature are saved in RAM.

其中,第一签名是基于第一私钥和第二程序文件的内容生成的。例如,第一签名是采用第一私钥对第二程序文件的内容的签名,或者,第一签名是采用第一私钥对第二程序文件的内容的哈希值的签名。可选地,第一私钥为第二程序文件的发布者的私钥,第二程序文件的发布者在向闪存写入第二程序文件之前,先根据自己的私钥和第二程序文件的内容生成第一签名,然后将自己的私钥对应的公钥(即第一公钥)、第一签名和第二程序文件打包写入闪存。ROM中的第一程序文件为可信根。Wherein, the first signature is generated based on the first private key and the contents of the second program file. For example, the first signature is a signature of the content of the second program file using the first private key, or the first signature is a signature of a hash value of the content of the second program file using the first private key. Optionally, the first private key is the private key of the publisher of the second program file. Before writing the second program file to the flash memory, the publisher first writes the second program file based on his own private key and the second program file's private key. The content generates a first signature, and then packages and writes the public key corresponding to its own private key (i.e., the first public key), the first signature, and the second program file into the flash memory. The first program file in ROM is the root of trust.

可选地,此步骤S13中,处理核在闪存控制器处于直接访问模式下读取闪存中的第二程序文件以及第一签名。也就是说,在此步骤S13执行之前,处理核需要先确保闪存控制器处于直接访问模式下。Optionally, in this step S13, the processing core reads the second program file and the first signature in the flash memory when the flash memory controller is in the direct access mode. That is to say, before executing step S13, the processing core needs to ensure that the flash memory controller is in the direct access mode.

为了便于读者理解,下面对签名和签名验证进行简单介绍。数字签名(简称签名)是一种针对发送方数据的保护手段。发送方使用私钥对消息进行签名。没有私钥的任何第三方无法伪造签名。拥有发送方所持有的私钥对应的公钥的任何第三方都可以对签名进行验签,以确认消息的来源和完整性。接收方接收到数据后,采用公钥对签名进行验证,输出一个布尔值,表明签名合法(验签通过)或不合法(验签不通过)。如果验签通过,则说明数据没有被篡改。如果验签不通过,则说明数据被篡改。签名验证能够用于验证数据的完整性(未经篡改)和数据来源的可靠性(不是虚假数据或伪造数据)。In order to facilitate readers' understanding, signature and signature verification are briefly introduced below. Digital signature (signature for short) is a means of protecting the sender's data. The sender signs the message using the private key. No third party without the private key can forge the signature. Any third party who possesses the public key corresponding to the private key held by the sender can verify the signature to confirm the source and integrity of the message. After receiving the data, the recipient uses the public key to verify the signature and outputs a Boolean value indicating that the signature is legal (passed the signature verification) or illegal (failed the signature verification). If the signature verification passes, it means that the data has not been tampered with. If the signature verification fails, it means the data has been tampered with. Signature verification can be used to verify the integrity of the data (not tampered with) and the reliability of the data source (not false data or forged data).

在步骤S14中,处理核采用第一私钥对应的第一公钥对第一签名进行验证。In step S14, the processing core uses the first public key corresponding to the first private key to verify the first signature.

可选地,一次性可编程存储器中预先存储有第一公钥的哈希值,处理核首先采用第一公钥的哈希值对第二程序文件中携带的第一公钥进行验证。处理核在对第一公钥验证通过之后,再采用第一公钥对第一签名进行验证。或者,一次性可编程存储器中存储有第一公钥,这种实现方式下,第二程序文件可以不携带第一公钥。由于一次性可编程存储器中存储的信息无法被更改,因此能够保证安全验证的可靠性。Optionally, the hash value of the first public key is pre-stored in the one-time programmable memory, and the processing core first uses the hash value of the first public key to verify the first public key carried in the second program file. After the processing core passes the verification of the first public key, it then uses the first public key to verify the first signature. Alternatively, the first public key is stored in the one-time programmable memory. In this implementation, the second program file does not need to carry the first public key. Since the information stored in the one-time programmable memory cannot be changed, the reliability of the security verification can be guaranteed.

在步骤S15中,处理核在对第一签名验证通过之后,从RAM中保存的第二程序文件中获取第一可信程序和第二可信程序。In step S15, after passing the verification of the first signature, the processing core acquires the first trusted program and the second trusted program from the second program file saved in the RAM.

处理核对第一签名验证通过后,确定保存在RAM中的第二程序文件为可信程序文件。之后,处理核从RAM中保存的第二程序文件中获取第一可信程序和第二可信程序,继续执行上述步骤S11至步骤S12。After the verification of the first signature is passed, it is determined that the second program file stored in the RAM is a trusted program file. Afterwards, the processing core acquires the first trusted program and the second trusted program from the second program file saved in the RAM, and continues to execute the above steps S11 to S12.

可选地,上述步骤S12的一种实现方式,包括:处理核通过运行第二可信程序,通过闪存控制器读取闪存中该保护地址范围对应的内容以及第二签名,并将读取的该保护地址范围对应的内容和第二签名保存在随机存取存储器中。处理核采用第二私钥对应的第二公钥对第二签名进行验证。Optionally, an implementation manner of the above step S12 includes: the processing core reads the content corresponding to the protected address range and the second signature in the flash memory through the flash memory controller by running the second trusted program, and transfers the read The content corresponding to the protected address range and the second signature are stored in the random access memory. The processing core uses the second public key corresponding to the second private key to verify the second signature.

其中,第二签名是基于第二私钥和闪存中该保护地址范围对应的内容生成的。例如,第二签名是采用第二私钥对闪存中该保护地址范围对应的内容的签名,或者,第二签名是采用第二私钥对闪存中该保护地址范围对应的内容的哈希值的签名。可选地,第二私钥为闪存中该保护地址范围对应的内容的发布者的私钥,该保护地址范围对应的内容的发布者在向闪存写入该内容之前,先根据自己的私钥和该内容生成第二签名,然后将自己的私钥对应的公钥(第二公钥)、第二签名和该内容打包写入闪存。The second signature is generated based on the second private key and the content corresponding to the protected address range in the flash memory. For example, the second signature uses the second private key to sign the content corresponding to the protected address range in the flash memory, or the second signature uses the second private key to sign the hash value of the content corresponding to the protected address range in the flash memory. sign. Optionally, the second private key is the private key of the publisher of the content corresponding to the protected address range in the flash memory. The publisher of the content corresponding to the protected address range first writes the content according to his own private key before writing the content to the flash memory. Generate a second signature with the content, and then package the public key (second public key) corresponding to your private key, the second signature, and the content into the flash memory.

可选地,第二程序文件包括第二公钥的哈希值,处理核首先采用第二公钥的哈希值对从闪存中读取的第二公钥进行验证。处理核在对第二公钥验证通过之后,再采用第二公钥对第二签名进行验证。或者,第二程序文件包括第二公钥,闪存中保护地址范围对应的内容的发布者无需将第二公钥打包写入闪存。Optionally, the second program file includes a hash value of the second public key, and the processing core first uses the hash value of the second public key to verify the second public key read from the flash memory. After the processing core passes the verification of the second public key, it then uses the second public key to verify the second signature. Alternatively, the second program file includes the second public key, and the publisher of the content corresponding to the protection address range in the flash memory does not need to package the second public key and write it into the flash memory.

在闪存控制器中配置可读地址范围的实现方式可参考上述在闪存控制器中配置保护地址范围的实现方式,本申请实施例在此不再赘述。可选地,在闪存控制器中配置的可读地址范围与保护地址范围相同的情况下,在上述步骤S11中,处理核在闪存控制器中配置闪存的保护地址范围,并使能闪存控制器中存储的该保护地址范围为可读地址范围。The implementation method of configuring the readable address range in the flash memory controller may refer to the above-mentioned implementation method of configuring the protection address range in the flash memory controller, which will not be described in detail here. Optionally, when the readable address range configured in the flash memory controller is the same as the protected address range, in the above step S11, the processing core configures the protected address range of the flash memory in the flash memory controller and enables the flash memory controller. The protected address range stored in is a readable address range.

可选地,在上述步骤S11执行之后,处理核通过运行第三可信程序,锁定闪存控制器针对闪存的保护功能配置。可选地,处理核从RAM中保存的第二程序文件中获取第三可信程序。闪存控制器针对闪存的保护功能配置被锁定,是指闪存控制器中针对闪存的保护功能配置无法被修改。闪存控制器针对闪存的保护功能配置包括防篡改配置和/或访问权限控制配置。其中,防篡改配置包括在闪存控制器上配置闪存的保护地址范围,以及配置闪存控制器在间接访问模式下保护闪存中该保护地址范围对应的内容不被篡改。访问权限控制配置包括在闪存控制器上配置闪存的可读地址范围,以及配置闪存控制器在直接访问模式下只读闪存中该可读地址范围对应的内容。也就是说,SoC内部的处理核在安全启动过程中,先在闪存控制器中配置针对闪存的保护功能,再锁定闪存控制器针对闪存的保护功能配置,然后对闪存中的受保护内容进行安全校验,这样能够保证闪存中的受保护内容在经过处理核的安全校验之后无法被篡改。Optionally, after the above step S11 is executed, the processing core locks the protection function configuration of the flash memory controller for the flash memory by running a third trusted program. Optionally, the processing core obtains the third trusted program from the second program file saved in the RAM. The flash memory controller's protection function configuration for flash memory is locked, which means that the flash memory controller's protection function configuration for flash memory cannot be modified. The protection function configuration of the flash memory controller for the flash memory includes anti-tampering configuration and/or access permission control configuration. Among them, the anti-tampering configuration includes configuring the protection address range of the flash memory on the flash memory controller, and configuring the flash memory controller to protect the content corresponding to the protection address range in the flash memory from being tampered with in the indirect access mode. The access control configuration includes configuring the readable address range of the flash memory on the flash memory controller, and configuring the content corresponding to the readable address range in the read-only flash memory of the flash memory controller in direct access mode. In other words, during the secure boot process, the processing core inside the SoC first configures the flash memory protection function in the flash memory controller, then locks the flash memory controller's flash memory protection function configuration, and then secures the protected content in the flash memory. Verification, which ensures that the protected content in the flash memory cannot be tampered with after passing the security verification of the processing core.

可选地,闪存控制器包括闪存保护功能寄存器和闪存保护锁定寄存器。闪存保护功能寄存器受闪存保护锁定寄存器保护。处理核在闪存控制器中配置闪存保护功能,例如为在闪存保护功能寄存器中配置保护地址范围和/或可读地址范围。处理核锁定闪存控制器针对闪存的保护功能配置,例如为配置闪存保护锁定寄存器。闪存保护锁定寄存器完成配置之后,在SoC复位之前,闪存保护功能寄存器的配置内容无法修改。在SoC复位后,闪存保护锁定寄存器恢复默认值(未锁定状态),此时闪存保护功能寄存器可以被修改,处理核可在闪存控制器中重新配置闪存保护功能。Optionally, the flash memory controller includes a flash memory protection function register and a flash memory protection lock register. The flash protection function register is protected by the flash protection lock register. The processing core configures the flash memory protection function in the flash memory controller, for example, configuring the protection address range and/or the readable address range in the flash memory protection function register. Processes the configuration of the core lock flash controller's protection functions for flash memory, such as configuring the flash protection lock register. After the flash protection lock register is configured, the configuration content of the flash protection function register cannot be modified before the SoC is reset. After the SoC is reset, the flash protection lock register returns to the default value (unlocked state). At this time, the flash protection function register can be modified, and the processing core can reconfigure the flash protection function in the flash memory controller.

在本申请实施例提供的数据保护方法中,通过在闪存控制器上配置针对闪存的保护功能。例如在闪存控制器中配置闪存的保护地址范围,使得处理核在闪存控制器处于间接访问模式时无法修改闪存中该保护地址范围对应的内容,从而实现闪存中该保护地址范围对应的内容不被篡改,提高了闪存中数据的安全性和可靠性。又例如在闪存控制器中配置闪存的可读地址范围,使得处理核在闪存控制器处于直接访问模式时,只能读取到闪存中该可读地址范围对应的内容,实现访问权限控制。In the data protection method provided by the embodiment of the present application, the protection function for flash memory is configured on the flash memory controller. For example, the protection address range of the flash memory is configured in the flash memory controller so that the processing core cannot modify the content corresponding to the protection address range in the flash memory when the flash memory controller is in indirect access mode, so that the content corresponding to the protection address range in the flash memory is not Tampering, improving the security and reliability of data in flash memory. Another example is configuring the readable address range of the flash memory in the flash memory controller, so that when the flash memory controller is in direct access mode, the processing core can only read the content corresponding to the readable address range in the flash memory to implement access control.

本申请实施例提供的上述数据保护方法的步骤的先后顺序能够进行适当调整,步骤也能够根据情况进行相应增减。例如上述步骤404至步骤407与上述步骤401至步骤403可单独执行,上述步骤404至步骤407与上述步骤401至步骤403不存在步骤先后关系。任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化的方法,都应涵盖在本申请的保护范围之内。例如在本申请实施例提供的发明构思下,可以实现同一闪存支持多用户代码隔离,通过一个管理员管理闪存上不同地址范围内的代码读写擦除权限,管理员切换用户时更改闪存控制器中配置的保护地址范围和可读地址范围,使得多用户都只能访问到对应地址范围的代码,实现多用户之间的代码隔离。The sequence of the steps of the above-mentioned data protection method provided by the embodiments of the present application can be adjusted appropriately, and the steps can also be increased or decreased accordingly according to the situation. For example, the above-mentioned steps 404 to 407 and the above-mentioned steps 401 to 403 can be executed independently, and there is no step sequence relationship between the above-mentioned steps 404 to 407 and the above-mentioned steps 401 to 403. Any person familiar with the technical field can easily think of modified methods within the technical scope disclosed in this application, and they should be covered by the protection scope of this application. For example, under the inventive concept provided by the embodiments of this application, the same flash memory can be implemented to support multi-user code isolation. An administrator can manage the code read, write and erase permissions in different address ranges on the flash memory. The administrator can change the flash memory controller when switching users. The protected address range and readable address range configured in , enable multiple users to only access the code in the corresponding address range, achieving code isolation between multiple users.

本申请的第二个可选实施例应用于如图3所示的应用场景。该技术方案如下,可编程逻辑控制器接收片上系统发送的针对闪存的访问命令,该访问命令包括命令字和访问地址。该命令字用于指示该访问命令的访问类型,该访问类型包括读、写或擦除。该访问地址用于指示该访问命令在闪存中所访问的地址范围。如果该命令字指示该访问命令的访问类型为写或擦除,且该访问地址属于可编程逻辑控制器中配置的闪存的保护地址范围,可编程逻辑控制器拦截该访问命令。本申请实施例中,通过在片上系统与闪存之间部署可编程逻辑控制器,并在可编程逻辑控制器上配置针对闪存的保护功能,例如在可编程逻辑控制器中配置闪存的保护地址范围,如果片上系统内部的处理核想要修改闪存中该保护地址范围对应的内容,则可编程逻辑控制器阻止该修改行为,从而保护闪存中该保护地址范围对应的内容不被篡改,实现针对闪存的数据防篡改功能,能够提高闪存中数据的安全性和可靠性。The second optional embodiment of the present application is applied to the application scenario shown in Figure 3. The technical solution is as follows. The programmable logic controller receives an access command for the flash memory sent by the on-chip system. The access command includes a command word and an access address. The command word is used to indicate the access type of the access command, which includes read, write or erase. The access address is used to indicate the address range accessed by the access command in the flash memory. If the command word indicates that the access type of the access command is write or erase, and the access address belongs to the protected address range of the flash memory configured in the programmable logic controller, the programmable logic controller intercepts the access command. In the embodiment of the present application, a programmable logic controller is deployed between the system-on-chip and the flash memory, and the protection function for the flash memory is configured on the programmable logic controller. For example, the protection address range of the flash memory is configured in the programmable logic controller. , if the processing core inside the on-chip system wants to modify the content corresponding to the protected address range in the flash memory, the programmable logic controller prevents the modification behavior, thereby protecting the content corresponding to the protected address range in the flash memory from being tampered with, realizing the goal of flash memory The data anti-tampering function can improve the security and reliability of data in flash memory.

本申请以下实施例以闪存控制器设置有两种访问模式为例进行说明。可选地,可编程逻辑控制器也设置有两种访问模式,包括直接访问模式和间接访问模式。这种情况下,可编程逻辑控制器的访问模式与闪存控制器的访问模式保持一致。也就是说,当闪存控制器处于直接访问模式时,可编程逻辑控制器也处于直接访问模式。当闪存控制器处于间接访问模式时,可编程逻辑控制器也处于间接访问模式。The following embodiments of this application take the flash memory controller configured with two access modes as an example for description. Optionally, the programmable logic controller is also set with two access modes, including direct access mode and indirect access mode. In this case, the access pattern of the programmable logic controller is consistent with the access pattern of the flash memory controller. That is, when the flash memory controller is in direct access mode, the programmable logic controller is also in direct access mode. When the flash controller is in indirect access mode, the programmable logic controller is also in indirect access mode.

可选地,可编程逻辑控制器的访问模式由处理核控制跟随闪存控制器一起切换。比如可编程逻辑控制器接收SoC发送的模式切换指令,该模式切换指令用于指示可编程逻辑控制器由直接访问模式切换为间接访问模式,或者由间接访问模式切换为直接访问模式。例如,当处理核需要直接运行闪存中的代码(XIP)时,处理核控制闪存控制器和可编程逻辑控制器切换至直接访问模式。当处理核需要修改闪存中的内容时,处理核控制闪存控制器和可编程逻辑控制器切换至间接访问模式。Optionally, the access mode of the programmable logic controller is controlled by the processing core and switched together with the flash memory controller. For example, the programmable logic controller receives a mode switching instruction sent by the SoC. The mode switching instruction is used to instruct the programmable logic controller to switch from direct access mode to indirect access mode, or from indirect access mode to direct access mode. For example, when the processing core needs to directly run code in flash memory (XIP), the processing core controls the flash memory controller and programmable logic controller to switch to direct access mode. When the processing core needs to modify the contents of the flash memory, the processing core controls the flash memory controller and the programmable logic controller to switch to the indirect access mode.

或者,可编程逻辑控制器也可以只有一种访问模式,或者说可编程逻辑控制器中可以不设置访问模式。这种情况下,无论闪存控制器处于哪种访问模式,可编程逻辑控制器采用相同的处理逻辑来处理SoC发送的针对闪存的访问命令。Alternatively, the programmable logic controller may have only one access mode, or no access mode may be set in the programmable logic controller. In this case, no matter which access mode the flash memory controller is in, the programmable logic controller uses the same processing logic to process the access command for the flash memory sent by the SoC.

本申请以下实施例以可编程逻辑控制器设置有两种访问模式为例进行说明。例如,图5是本申请实施例提供的另一种数据保护方法的流程示意图。如图5所示,该方法500包括但不限于以下步骤501至步骤506。其中,步骤501至步骤503示出了可编程逻辑控制器在间接访问模式下对闪存的内容防篡改保护。步骤504至步骤506示出了可编程逻辑控制器在直接访问模式下对闪存的访问权限控制。The following embodiments of this application take a programmable logic controller equipped with two access modes as an example for description. For example, FIG. 5 is a schematic flowchart of another data protection method provided by an embodiment of the present application. As shown in Figure 5, the method 500 includes but is not limited to the following steps 501 to 506. Among them, steps 501 to 503 show that the programmable logic controller protects the contents of the flash memory from tampering in the indirect access mode. Steps 504 to 506 illustrate the access permission control of the programmable logic controller to the flash memory in the direct access mode.

步骤501、可编程逻辑控制器在间接访问模式下接收SoC发送的针对闪存的访问命令21,访问命令21包括命令字21和访问地址21。Step 501: The programmable logic controller receives the access command 21 for the flash memory sent by the SoC in the indirect access mode. The access command 21 includes the command word 21 and the access address 21.

命令字21用于指示访问命令21的访问类型。访问命令21的访问类型包括读、写或擦除。访问地址21用于指示访问命令21在闪存中所访问的地址范围。其中,命令字21由SoC内部的处理核通过运行软件代码生成,即可编程逻辑控制器在间接访问模式下接收到的访问命令中的命令字由处理核生成。可选地,如果访问命令21的访问类型为写,则访问命令21还包括待写入内容。The command word 21 is used to indicate the access type of the access command 21. The access type of the access command 21 includes read, write or erase. The access address 21 is used to indicate the address range accessed by the access command 21 in the flash memory. Among them, the command word 21 is generated by the processing core inside the SoC by running software code, that is, the command word in the access command received by the programmable logic controller in the indirect access mode is generated by the processing core. Optionally, if the access type of the access command 21 is writing, the access command 21 also includes content to be written.

在此步骤401执行之前,SoC内部的处理核需要先确保可编程逻辑控制器处于间接访问模式下。比如,处理核先向可编程逻辑控制器发送模式切换指令21,该模式切换指令21用于指示可编程逻辑控制器由直接访问模式切换为间接访问模式,然后处理核再生成并发出访问命令21。如果可编程逻辑控制器接收到模式切换指令21时处于直接访问模式,则可编程逻辑控制器切换为间接访问模式,之后在间接访问模式下接收并处理访问命令21。Before executing step 401, the processing core inside the SoC needs to ensure that the programmable logic controller is in indirect access mode. For example, the processing core first sends a mode switching instruction 21 to the programmable logic controller. The mode switching instruction 21 is used to instruct the programmable logic controller to switch from the direct access mode to the indirect access mode. Then the processing core generates and issues the access command 21 . If the programmable logic controller is in the direct access mode when it receives the mode switching command 21, the programmable logic controller switches to the indirect access mode, and then receives and processes the access command 21 in the indirect access mode.

步骤502、如果命令字21指示访问命令21的访问类型为写或擦除,且访问地址21属于可编程逻辑控制器中配置的闪存的保护地址范围,可编程逻辑控制器拦截访问命令21。Step 502: If the command word 21 indicates that the access type of the access command 21 is write or erase, and the access address 21 belongs to the protection address range of the flash memory configured in the programmable logic controller, the programmable logic controller intercepts the access command 21.

命令字21指示访问命令21的访问类型为写或擦除,则表示访问命令21会修改闪存中的内容。可编程逻辑控制器在间接访问模式下接收到处理核发送的访问命令后,会根据该访问命令中的命令字和访问地址判断该访问命令是否会修改可编程逻辑控制器中配置的闪存的保护地址范围对应的内容。如果该访问命令会修改闪存中该保护地址范围对应的内容,则可编程逻辑控制器拦截该访问命令,以阻止该修改行为,从而保护闪存中该保护地址范围对应的内容不被篡改。The command word 21 indicates that the access type of the access command 21 is write or erase, which means that the access command 21 will modify the content in the flash memory. After the programmable logic controller receives the access command sent by the processing core in the indirect access mode, it will determine whether the access command will modify the protection of the flash memory configured in the programmable logic controller based on the command word and access address in the access command. The content corresponding to the address range. If the access command will modify the content corresponding to the protected address range in the flash memory, the programmable logic controller intercepts the access command to prevent the modification, thereby protecting the content corresponding to the protected address range in the flash memory from being tampered with.

可选地,可编程逻辑控制器在确定处理核发送的访问命令会修改可编程逻辑控制器中配置的闪存的保护地址范围对应的内容之后,发出告警提示,该告警提示用于指示闪存有被篡改风险,以便运维人员及时排查攻击行为。Optionally, after determining that the access command sent by the processing core will modify the content corresponding to the protection address range of the flash memory configured in the programmable logic controller, the programmable logic controller issues an alarm prompt, which is used to indicate that the flash memory has been accessed. Tampering risks allow operation and maintenance personnel to detect attacks in a timely manner.

可选地,闪存中部署有程序文件,可编程逻辑控制器中配置的闪存的保护地址范围包括闪存中程序文件的地址范围。该程序文件包括代码段和数据段。这样可编程逻辑控制器能够保护闪存中的程序文件不被篡改,保证SoC内部的处理核能够正常运行该程序文件中的代码。可选地,闪存还用于存储除程序文件以外的其它内容,比如软件包或固件等,可编程逻辑控制器中配置的闪存的保护地址范围还包括闪存中其它内容的地址范围,以保护该部分内容不被篡改。可编程逻辑控制器中的保护地址范围可以根据实际需求进行配置,本申请实施例对此不做限定。Optionally, a program file is deployed in the flash memory, and the protection address range of the flash memory configured in the programmable logic controller includes the address range of the program file in the flash memory. The program file includes code segments and data segments. In this way, the programmable logic controller can protect the program files in the flash memory from being tampered with and ensure that the processing core inside the SoC can normally run the code in the program file. Optionally, the flash memory is also used to store other contents besides program files, such as software packages or firmware. The protection address range of the flash memory configured in the programmable logic controller also includes the address range of other contents in the flash memory to protect the Some content has not been tampered with. The protection address range in the programmable logic controller can be configured according to actual needs, and this is not limited in the embodiments of this application.

步骤503、如果命令字21指示访问命令21的访问类型为读,可编程逻辑控制器透传访问命令21以及SoC基于访问命令21从闪存中读取的内容。Step 503: If the command word 21 indicates that the access type of the access command 21 is read, the programmable logic controller transparently transmits the access command 21 and the content read by the SoC from the flash memory based on the access command 21.

命令字21指示访问命令21的访问类型为读,则表示访问命令21不会修改闪存中的内容。可选地,如果可编程逻辑控制器在间接访问模式下接收到SoC发送的读命令,或者接收到SoC发送的写命令或擦除命令但访问地址不属于配置的保护地址范围,则可编程逻辑控制器直接向闪存透传该读命令以及向SoC透传基于该读命令从闪存读取到的内容。The command word 21 indicates that the access type of the access command 21 is read, which means that the access command 21 will not modify the content in the flash memory. Optionally, if the programmable logic controller receives a read command sent by the SoC in indirect access mode, or receives a write command or erase command sent by the SoC but the access address does not belong to the configured protection address range, the programmable logic controller The controller directly transparently transmits the read command to the flash memory and the content read from the flash memory based on the read command to the SoC.

步骤504、可编程逻辑控制器在直接访问模式下接收SoC发送的针对闪存的访问命令22,访问命令22包括命令字22和访问地址22。Step 504: The programmable logic controller receives the access command 22 for the flash memory sent by the SoC in the direct access mode. The access command 22 includes the command word 22 and the access address 22.

命令字22用于指示访问命令22的访问类型为读。访问地址22用于指示访问命令22在闪存中所访问的地址范围。其中,命令字22由SoC内部的闪存控制器生成,即可编程逻辑控制器在直接访问模式下接收到的访问命令中的命令字由闪存控制器生成。The command word 22 is used to indicate that the access type of the access command 22 is read. The access address 22 is used to indicate the address range accessed by the access command 22 in the flash memory. Among them, the command word 22 is generated by the flash memory controller inside the SoC, that is, the command word in the access command received by the programmable logic controller in the direct access mode is generated by the flash memory controller.

在此步骤504执行之前,SoC内部的处理核需要先确保可编程逻辑控制器处于直接访问模式下。比如,处理核先向可编程逻辑控制器发送模式切换指令22,该模式切换指令22用于指示可编程逻辑控制器由间接访问模式切换为直接访问模式,然后处理核再发出读命令,由闪存控制器生成命令字并继续发出访问命令22。如果可编程逻辑控制器接收到模式切换指令22时处于间接访问模式,则可编程逻辑控制器切换为直接访问模式,之后在直接访问模式下接收并处理访问命令22。Before executing step 504, the processing core inside the SoC needs to ensure that the programmable logic controller is in direct access mode. For example, the processing core first sends a mode switching instruction 22 to the programmable logic controller. The mode switching instruction 22 is used to instruct the programmable logic controller to switch from the indirect access mode to the direct access mode. Then the processing core sends a read command to the flash memory. The controller generates the command word and proceeds to issue access command 22. If the programmable logic controller is in the indirect access mode when it receives the mode switching instruction 22, the programmable logic controller switches to the direct access mode, and then receives and processes the access command 22 in the direct access mode.

步骤505、如果访问地址22不属于可编程逻辑控制器中配置的闪存的可读地址范围,可编程逻辑控制器拦截访问命令22。Step 505: If the access address 22 does not belong to the readable address range of the flash memory configured in the programmable logic controller, the programmable logic controller intercepts the access command 22.

可编程逻辑控制器在直接访问模式下接收到处理核发送的访问命令后,会根据该访问命令中的访问地址判断该访问命令所要读取的内容是否在配置的可读地址范围内。如果该访问命令所要读取的内容不在配置的可读地址范围内,则可编程逻辑控制器拦截该访问命令,以阻止SoC的读取行为。After the programmable logic controller receives the access command sent by the processing core in the direct access mode, it will determine whether the content to be read by the access command is within the configured readable address range based on the access address in the access command. If the content to be read by the access command is not within the configured readable address range, the programmable logic controller intercepts the access command to prevent the SoC from reading.

可选地,可编程逻辑控制器在确定SoC发送的访问命令所要读取的内容不在配置的可读地址范围内之后,发出错误提示,该错误提示用于指示处理核的访问地址出错。Optionally, after determining that the content to be read by the access command sent by the SoC is not within the configured readable address range, the programmable logic controller issues an error prompt, which is used to indicate that the access address of the processing core is incorrect.

本申请实施例中,通过在可编程逻辑控制器中配置闪存的可读地址范围,使得SoC在可编程逻辑控制器处于直接访问模式时,只能读取到闪存中该可读地址范围对应的内容,实现访问权限控制。例如将保存在闪存上的某个程序文件的地址范围配置成可读地址范围,则SoC内部的处理核能够通过直接访问读取闪存中的该程序文件并运行该程序文件中的代码段。相应地,将闪存中除该程序文件的地址范围以外的其它地址配置成不可读地址范围,保证处理核无法通过直接访问读取闪存中不可读地址范围对应的内容。In the embodiment of the present application, by configuring the readable address range of the flash memory in the programmable logic controller, the SoC can only read the address corresponding to the readable address range in the flash memory when the programmable logic controller is in the direct access mode. content to implement access control. For example, if the address range of a program file stored in the flash memory is configured as a readable address range, the processing core inside the SoC can read the program file in the flash memory and run the code segment in the program file through direct access. Correspondingly, other addresses in the flash memory except the address range of the program file are configured as unreadable address ranges to ensure that the processing core cannot read the contents corresponding to the unreadable address range in the flash memory through direct access.

可选地,可编程逻辑控制器中配置的闪存的可读地址范围与配置的闪存的保护地址范围相同。Optionally, the readable address range of the flash memory configured in the programmable logic controller is the same as the protected address range of the configured flash memory.

本申请实施例中,通过在可编程逻辑控制器中配置相同的可读地址范围和保护地址范围,由于闪存中保护地址范围对应的内容无法被篡改,且SoC内部的处理核在直接访问闪存时只能读取到可读地址范围对应的内容,因此能够保证处理核通过直接访问从闪存中读取的内容是未经篡改的,从而提高处理核的运行可靠性。比如在配置的保护地址范围和可读地址范围包括闪存中部署的程序文件的情况下,通过在可编程逻辑控制器中配置针对该程序文件的保护功能,使得该程序文件的内容不可被修改且只有该程序文件在直接访问模式下可读,即SoC内部的处理核只能直接运行闪存中受保护的程序文件。避免了攻击者修改了闪存中未受保护的程序文件,以及修改SoC内部的处理核的运行指针指向该修改过的程序文件的地址,导致处理核从闪存中读取并运行错误代码的情况。In the embodiment of this application, by configuring the same readable address range and protected address range in the programmable logic controller, the content corresponding to the protected address range in the flash memory cannot be tampered with, and the processing core inside the SoC cannot directly access the flash memory. Only the content corresponding to the readable address range can be read, so it can be ensured that the content read from the flash memory by the processing core through direct access has not been tampered with, thus improving the operational reliability of the processing core. For example, when the configured protection address range and readable address range include a program file deployed in flash memory, by configuring the protection function for the program file in the programmable logic controller, the content of the program file cannot be modified and Only the program file is readable in direct access mode, that is, the processing core inside the SoC can only directly run the protected program file in the flash memory. This avoids the situation where the attacker modifies unprotected program files in the flash memory and modifies the running pointer of the processing core inside the SoC to point to the address of the modified program file, causing the processing core to read and run incorrect code from the flash memory.

步骤506、如果访问地址22属于可编程逻辑控制器中配置的闪存的可读地址范围,可编程逻辑控制器透传访问命令22以及SoC基于访问命令22从闪存中读取的内容。Step 506: If the access address 22 belongs to the readable address range of the flash memory configured in the programmable logic controller, the programmable logic controller transparently transmits the access command 22 and the content read by the SoC from the flash memory based on the access command 22.

此步骤506的实现方式可参考上述步骤503的实现方式,本申请实施例在此不再赘述。The implementation of step 506 may refer to the implementation of step 503 above, which will not be described again in this embodiment of the present application.

值得说明的是,在可编程逻辑控制器只有一种访问模式的情况下,不同于上述步骤503,可编程逻辑控制器接收到SoC发送的针对闪存的读命令后,直接根据该读命令中的访问地址判断该读命令所要读取的内容是否在配置的可读地址范围内。如果该读命令所要读取的内容不在配置的可读地址范围内,则可编程逻辑控制器拦截该读命令,以阻止SoC对闪存的读取行为。也就是说,在可编程逻辑控制器只有一种访问模式的情况下,可编程逻辑控制器接收到SoC发送的针对闪存的读命令后,执行上述步骤505和步骤506。It is worth noting that when the programmable logic controller has only one access mode, different from the above step 503, after the programmable logic controller receives the read command for the flash memory sent by the SoC, it directly responds according to the read command in the read command. The access address determines whether the content to be read by the read command is within the configured readable address range. If the content to be read by the read command is not within the configured readable address range, the programmable logic controller intercepts the read command to prevent the SoC from reading the flash memory. That is to say, when the programmable logic controller has only one access mode, after the programmable logic controller receives the read command for the flash memory sent by the SoC, it executes the above steps 505 and 506.

本申请实施例中,在上述步骤501至步骤503执行之前,需要在可编程逻辑控制器中配置闪存的保护地址范围,以供可编程逻辑控制器在间接访问模式下使用。在上述步骤504至步骤506执行之前,需要在可编程逻辑控制器中配置闪存的可读地址范围,以供可编程逻辑控制器在直接访问模式下使用。为了保证配置安全性和可靠性,可以通过可信组件配置闪存控制器。可信组件是经过校验的组件,且运行在安全环境中。本申请实施例通过SoC中的硬件隔离机制来保证组件的可信,这里的组件是指处理核运行的程序文件。例如,在上述步骤501至步骤503执行之前,执行以下步骤S21至步骤S24。In the embodiment of the present application, before the above-mentioned steps 501 to 503 are executed, the protection address range of the flash memory needs to be configured in the programmable logic controller for use by the programmable logic controller in the indirect access mode. Before the above steps 504 to 506 are performed, the readable address range of the flash memory needs to be configured in the programmable logic controller for use by the programmable logic controller in the direct access mode. To ensure configuration security and reliability, the flash controller can be configured through trusted components. Trusted components are components that have been verified and run in a secure environment. The embodiment of this application ensures the trustworthiness of components through the hardware isolation mechanism in the SoC. The components here refer to program files that process core operation. For example, before the above-mentioned steps 501 to 503 are executed, the following steps S21 to step S24 are executed.

在步骤S21中,可编程逻辑控制器接收SoC发送的配置命令,该配置命令包括闪存的保护地址范围。In step S21, the programmable logic controller receives the configuration command sent by the SoC, where the configuration command includes the protection address range of the flash memory.

该配置命令由SoC内部的处理核生成并发送。例如,处理核通过运行第一可信程序,在可编程逻辑控制器中配置闪存的保护地址范围,该实现方式可参考上述步骤S11中处理核在闪存控制器在配置闪存的保护地址范围的实现过程。This configuration command is generated and sent by the processing core inside the SoC. For example, the processing core configures the protected address range of the flash memory in the programmable logic controller by running the first trusted program. This implementation may refer to the implementation of the processing core configuring the protected address range of the flash memory in the flash memory controller in step S11 above. process.

在步骤S22中,可编程逻辑控制器根据该配置命令在可编程逻辑控制器中配置该保护地址范围。In step S22, the programmable logic controller configures the protection address range in the programmable logic controller according to the configuration command.

可选地,可编程逻辑控制器完成对保护地址范围的配置之后,向SoC发送配置完成响应,之后SoC进一步对闪存中该保护地址范围对应的内容进行校验。例如,处理核在确定可编程逻辑控制器完成对闪存的保护地址范围的配置之后,通过运行第二可信程序,对闪存中该保护地址范围对应的内容进行校验,该实现方式可参考上述步骤S12。Optionally, after the programmable logic controller completes the configuration of the protection address range, it sends a configuration completion response to the SoC, and then the SoC further verifies the content corresponding to the protection address range in the flash memory. For example, after the processing core determines that the programmable logic controller has completed the configuration of the protected address range of the flash memory, it verifies the content corresponding to the protected address range in the flash memory by running the second trusted program. The implementation method can be referred to the above. Step S12.

可选地,SoC内部的处理核在安全启动过程中向可编程逻辑控制器发送配置命令以及对闪存中保护地址范围对应的内容进行校验。例如,SoC上电或复位后,SoC内部的处理核执行安全启动流程,包括但不限于以下五个步骤。第一步,处理核通过运行SoC内部的ROM中的第一程序文件,通过闪存控制器读取闪存中的第二程序文件以及第一签名,并将读取的第二程序文件和第一签名保存在SoC内部的RAM中(对应参考上述步骤S13)。第二步,处理核采用第一私钥对应的第一公钥对第一签名进行验证(对应参考上述步骤S14)。第三步,处理核在对第一签名验证通过之后,从RAM中保存的第二程序文件中获取第一可信程序和第二可信程序(对应参考上述步骤S15)。第四步,处理核通过运行第一可信程序,在可编程逻辑控制器中配置闪存的保护地址范围,具体是向可编程逻辑控制器发送包含闪存的保护地址范围的配置命令(对应参考上述步骤S21)。第五步,处理核在确定可编程逻辑控制器完成对闪存的保护地址范围的配置之后,通过运行第二可信程序,对闪存中该保护地址范围对应的内容进行校验。Optionally, the processing core inside the SoC sends configuration commands to the programmable logic controller during the secure boot process and verifies the content corresponding to the protected address range in the flash memory. For example, after the SoC is powered on or reset, the processing core inside the SoC performs a safe startup process, including but not limited to the following five steps. In the first step, the processing core runs the first program file in the ROM inside the SoC, reads the second program file and the first signature in the flash memory through the flash memory controller, and reads the second program file and the first signature. Save it in the RAM inside the SoC (corresponding to step S13 above). In the second step, the processing core uses the first public key corresponding to the first private key to verify the first signature (corresponding to the above step S14). In the third step, after the processing core passes the verification of the first signature, it obtains the first trusted program and the second trusted program from the second program file saved in the RAM (correspondingly, refer to the above-mentioned step S15). In the fourth step, the processing core configures the protection address range of the flash memory in the programmable logic controller by running the first trusted program. Specifically, it sends a configuration command containing the protection address range of the flash memory to the programmable logic controller (corresponding to the above). Step S21). In the fifth step, after determining that the programmable logic controller has completed configuring the protected address range of the flash memory, the processing core verifies the content corresponding to the protected address range in the flash memory by running the second trusted program.

本申请实施例中,通过先在可编程逻辑控制器中配置闪存的保护地址范围,再对闪存中该保护地址范围对应的内容进行校验。这样,在处理核对闪存中该保护地址范围对应的内容校验通过之后,如果可编程逻辑控制器接收到针对闪存中该保护地址范围对应的内容的修改指令,可编程逻辑控制器则拦截该修改指令以阻止对闪存的修改,从而能够避免处理核校验通过后到访问闪存的时间窗内闪存中经过校验的内容被篡改,提高了闪存中数据的安全性和可靠性。In the embodiment of the present application, the protection address range of the flash memory is first configured in the programmable logic controller, and then the content corresponding to the protection address range in the flash memory is verified. In this way, after the verification of the content corresponding to the protected address range in the flash memory passes, if the programmable logic controller receives a modification instruction for the content corresponding to the protected address range in the flash memory, the programmable logic controller intercepts the modification Instructions are used to prevent modifications to the flash memory, thereby preventing the verified content in the flash memory from being tampered with during the time window from when the processing core passes the verification to accessing the flash memory, thereby improving the security and reliability of the data in the flash memory.

在可编程逻辑控制器中配置可读地址范围的实现方式可参考上述在可编程逻辑控制器中配置保护地址范围的实现方式,本申请实施例在此不再赘述。可选地,在可编程逻辑控制器中配置的可读地址范围与保护地址范围相同的情况下,处理核在生成的配置指令携带指示,用于指示该配置指令中的地址范围为配置的保护地址范围和可读地址范围,可编程逻辑控制器接收到该配置指令之后,将该配置指令所携带的地址范围配置为保护地址范围和可读地址范围。The implementation method of configuring the readable address range in the programmable logic controller may refer to the above-mentioned implementation method of configuring the protection address range in the programmable logic controller, which will not be described in detail here. Optionally, when the readable address range configured in the programmable logic controller is the same as the protected address range, the processing core carries an indication in the generated configuration instruction to indicate that the address range in the configuration instruction is the configured protection. address range and readable address range. After receiving the configuration instruction, the programmable logic controller configures the address range carried by the configuration instruction as a protected address range and a readable address range.

可选地,在上述步骤S22执行之后,继续执行以下步骤S23至步骤S24。Optionally, after the above-mentioned step S22 is executed, the following steps S23 to S24 are continued to be executed.

在步骤S23中,可编程逻辑控制器接收SoC发送的锁定命令。In step S23, the programmable logic controller receives the lock command sent by the SoC.

在步骤S24中,可编程逻辑控制器根据锁定命令锁定该可编程逻辑控制器针对闪存的保护功能配置。In step S24, the programmable logic controller locks the protection function configuration of the programmable logic controller for the flash memory according to the lock command.

可编程逻辑控制器针对闪存的保护功能配置被锁定,是指可编程逻辑控制器中针对闪存的保护功能配置无法被修改。可编程逻辑控制器针对闪存的保护功能配置包括防篡改配置和/或访问权限控制配置。其中,防篡改配置包括在可编程逻辑控制器上配置闪存的保护地址范围,以及配置可编程逻辑控制器在间接访问模式下保护闪存中该保护地址范围对应的内容不被篡改。访问权限控制配置包括在可编程逻辑控制器上配置闪存的可读地址范围,以及配置可编程逻辑控制器在直接访问模式下只读闪存中该可读地址范围对应的内容。例如,SoC内部的处理核在安全启动过程中,先在可编程逻辑控制器中配置针对闪存的保护功能,再锁定可编程逻辑控制器针对闪存的保护功能配置,然后对闪存中的受保护内容进行安全校验,这样能够保证闪存中的受保护内容在经过处理核的安全校验之后无法被篡改。The protection function configuration of the programmable logic controller for the flash memory is locked, which means that the protection function configuration of the programmable logic controller for the flash memory cannot be modified. The protection function configuration of the programmable logic controller for flash memory includes anti-tamper configuration and/or access control configuration. Among them, the anti-tampering configuration includes configuring the protection address range of the flash memory on the programmable logic controller, and configuring the programmable logic controller to protect the content corresponding to the protection address range in the flash memory from being tampered with in the indirect access mode. The access control configuration includes configuring the readable address range of the flash memory on the programmable logic controller, and configuring the content corresponding to the readable address range in the read-only flash memory of the programmable logic controller in direct access mode. For example, during the secure boot process, the processing core inside the SoC first configures the protection function for flash memory in the programmable logic controller, then locks the protection function configuration of the programmable logic controller for flash memory, and then configures the protected content in the flash memory. Perform security verification to ensure that the protected content in the flash memory cannot be tampered with after passing the security verification of the processing core.

可选地,可编程逻辑控制器包括闪存保护功能寄存器和闪存保护锁定寄存器。闪存保护功能寄存器受闪存保护锁定寄存器保护。可编程逻辑控制器接收到SoC发送的配置指令后配置闪存保护功能,例如为在闪存保护功能寄存器中配置保护地址范围和/或可读地址范围。可编程逻辑控制器接收到SoC发送的锁定命令后锁定针对闪存的保护功能配置,例如为配置闪存保护锁定寄存器。闪存保护锁定寄存器完成配置之后,在SoC和可编程逻辑控制器复位之前,闪存保护功能寄存器的配置内容无法被修改。在SoC和可编程逻辑控制器复位后,闪存保护锁定寄存器恢复默认值(未锁定状态),此时闪存保护功能寄存器可以被修改,SoC可在可编程逻辑控制器中重新配置闪存保护功能。其中,SoC和可编程逻辑控制器复位是同步的。Optionally, the programmable logic controller includes a flash memory protection function register and a flash memory protection lock register. The flash protection function register is protected by the flash protection lock register. The programmable logic controller configures the flash memory protection function after receiving the configuration instruction sent by the SoC, for example, configuring the protection address range and/or the readable address range in the flash memory protection function register. After receiving the lock command sent by the SoC, the programmable logic controller locks the protection function configuration for the flash memory, such as configuring the flash memory protection lock register. After the flash protection lock register is configured, the configuration content of the flash protection function register cannot be modified before the SoC and programmable logic controller are reset. After the SoC and programmable logic controller are reset, the flash protection lock register returns to the default value (unlocked state). At this time, the flash protection function register can be modified, and the SoC can reconfigure the flash protection function in the programmable logic controller. Among them, SoC and programmable logic controller reset are synchronous.

在本申请实施例提供的数据保护方法中,通过在可编程逻辑控制器上配置针对闪存的保护功能。例如在可编程逻辑控制器中配置闪存的保护地址范围,使得处理核在可编程逻辑控制器处于间接访问模式时无法修改闪存中该保护地址范围对应的内容,从而实现闪存中该保护地址范围对应的内容不被篡改,提高了闪存中数据的安全性和可靠性。又例如在可编程逻辑控制器中配置闪存的可读地址范围,使得处理核在可编程逻辑控制器处于直接访问模式时,只能读取到闪存中该可读地址范围对应的内容,实现访问权限控制。In the data protection method provided by the embodiment of the present application, the protection function for flash memory is configured on the programmable logic controller. For example, the protection address range of the flash memory is configured in the programmable logic controller so that the processing core cannot modify the content corresponding to the protection address range in the flash memory when the programmable logic controller is in indirect access mode, thereby realizing the corresponding protection address range in the flash memory. The content is not tampered with, which improves the security and reliability of the data in the flash memory. Another example is configuring the readable address range of the flash memory in the programmable logic controller, so that when the programmable logic controller is in direct access mode, the processing core can only read the content corresponding to the readable address range in the flash memory to achieve access. Permission control.

本申请实施例提供的上述数据保护方法的步骤的先后顺序能够进行适当调整,步骤也能够根据情况进行相应增减。例如上述步骤504至步骤506与上述步骤501至步骤503可单独执行,上述步骤504至步骤506与上述步骤501至步骤503不存在步骤先后关系。任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化的方法,都应涵盖在本申请的保护范围之内。例如在本申请实施例提供的发明构思下,可以实现同一闪存支持多用户代码隔离,通过一个管理员管理闪存上不同地址范围内的代码读写擦除权限,管理员切换用户时更改可编程逻辑控制器中配置的保护地址范围和可读地址范围,使得多用户都只能访问到对应地址范围的代码,实现多用户之间的代码隔离。The sequence of the steps of the above-mentioned data protection method provided by the embodiments of the present application can be adjusted appropriately, and the steps can also be increased or decreased accordingly according to the situation. For example, the above-mentioned steps 504 to 506 and the above-mentioned steps 501 to 503 can be executed independently, and there is no step sequence relationship between the above-mentioned steps 504 to 506 and the above-mentioned steps 501 to 503. Any person familiar with the technical field can easily think of modified methods within the technical scope disclosed in this application, and they should be covered by the protection scope of this application. For example, under the inventive concept provided by the embodiments of this application, the same flash memory can be implemented to support multi-user code isolation. An administrator can manage the code read, write and erase permissions in different address ranges on the flash memory. The administrator can change the programmable logic when switching users. The protected address range and readable address range configured in the controller enable multiple users to only access the code in the corresponding address range, achieving code isolation between multiple users.

本申请实施例提供了一种数据保护方法,应用于片上系统。该片上系统包括处理核和闪存控制器。该方法包括以下步骤A101至步骤A102。The embodiment of the present application provides a data protection method, which is applied to a system on a chip. The system-on-chip includes processing cores and flash memory controllers. The method includes the following steps A101 to A102.

在步骤A101中,闪存控制器接收处理核发送的针对闪存的第一访问命令,该闪存部署于片上系统的外部,第一访问命令包括第一命令字和第一访问地址,第一命令字用于指示第一访问命令的访问类型,该访问类型包括读、写或擦除,第一访问地址用于指示第一访问命令在闪存中所访问的地址范围。In step A101, the flash memory controller receives a first access command for the flash memory sent by the processing core. The flash memory is deployed outside the on-chip system. The first access command includes a first command word and a first access address. The first command word is In order to indicate the access type of the first access command, the access type includes read, write or erase, and the first access address is used to indicate the address range accessed by the first access command in the flash memory.

在步骤A102中,如果第一命令字指示第一访问命令的访问类型为写或擦除,且第一访问地址属于闪存控制器中配置的闪存的保护地址范围,闪存控制器拦截第一访问命令。In step A102, if the first command word indicates that the access type of the first access command is write or erase, and the first access address belongs to the protection address range of the flash memory configured in the flash memory controller, the flash memory controller intercepts the first access command .

该方法具体用于实现上述方法400。第一访问命令例如是访问命令11,第一命令字例如是命令字11,第一访问地址例如是访问地址11。步骤A101和步骤A102的具体实现过程参考上述方法400中的步骤401至步骤402,本申请实施例在此不再赘述。This method is specifically used to implement the above method 400. The first access command is, for example, access command 11, the first command word is, for example, command word 11, and the first access address is, for example, access address 11. For the specific implementation process of step A101 and step A102, refer to step 401 to step 402 in the above-mentioned method 400, which will not be described again in this embodiment of the present application.

可选地,闪存中部署有程序文件,闪存控制器中配置的闪存保护地址范围包括该程序文件的地址范围。Optionally, a program file is deployed in the flash memory, and the flash memory protection address range configured in the flash memory controller includes the address range of the program file.

可选地,闪存控制器接收处理核发送的针对闪存的第一访问命令的实现方式,包括:闪存控制器在间接访问模式下接收处理核发送的第一访问命令。Optionally, the implementation of the flash memory controller receiving the first access command sent by the processing core for the flash memory includes: the flash memory controller receiving the first access command sent by the processing core in the indirect access mode.

可选地,闪存控制器在直接访问模式下接收处理核发送的针对闪存的第二访问命令,第二访问命令包括第二访问地址,第二访问地址用于指示第二访问命令在闪存中所访问的地址范围。如果第二访问地址不属于闪存控制器中配置的闪存的可读地址范围,闪存控制器拦截第二访问命令。第二访问命令例如是访问命令12,第二命令字例如是命令字12,第二访问地址例如是访问地址12。此步骤的具体实现过程参考上述方法400中的步骤404至步骤405,本申请实施例在此不再赘述。Optionally, the flash memory controller receives a second access command for the flash memory sent by the processing core in the direct access mode, the second access command includes a second access address, and the second access address is used to indicate where the second access command is located in the flash memory. Accessed address range. If the second access address does not belong to the readable address range of the flash memory configured in the flash memory controller, the flash memory controller intercepts the second access command. The second access command is, for example, access command 12 , the second command word is, for example, command word 12 , and the second access address is, for example, access address 12 . For the specific implementation process of this step, refer to steps 404 to 405 in the above-mentioned method 400, which will not be described again in the embodiment of the present application.

可选地,如果第二访问地址属于闪存控制器中配置的闪存的可读地址范围,闪存控制器生成第二命令字,第二命令字用于指示第二访问命令的访问类型为读。闪存控制器基于第二命令字和第二访问地址从闪存中读取第二访问地址对应的内容,并将第二访问地址对应的内容发送给处理核。此步骤的具体实现过程参考上述方法400中的步骤406至步骤407,本申请实施例在此不再赘述。Optionally, if the second access address belongs to the readable address range of the flash memory configured in the flash memory controller, the flash memory controller generates a second command word, and the second command word is used to indicate that the access type of the second access command is read. The flash memory controller reads the content corresponding to the second access address from the flash memory based on the second command word and the second access address, and sends the content corresponding to the second access address to the processing core. For the specific implementation process of this step, refer to steps 406 to 407 in the above-mentioned method 400, which will not be described again in the embodiment of the present application.

可选地,闪存控制器中配置的闪存的可读地址范围与保护地址范围相同。Optionally, the readable address range of the flash memory configured in the flash memory controller is the same as the protection address range.

可选地,如果第一命令字指示第一访问命令的访问类型为读,闪存控制器基于第一命令字和第一访问地址从闪存中读取第一访问地址对应的内容,并将第一访问地址对应的内容发送给处理核。此步骤的具体实现过程参考上述方法400中的步骤403,本申请实施例在此不再赘述。Optionally, if the first command word indicates that the access type of the first access command is read, the flash memory controller reads the content corresponding to the first access address from the flash memory based on the first command word and the first access address, and writes the first The content corresponding to the access address is sent to the processing core. For the specific implementation process of this step, refer to step 403 in the above-mentioned method 400, which will not be described again in the embodiment of the present application.

可选地,闪存控制器接收处理核发送的模式切换指令,该模式切换指令用于指示闪存控制器由直接访问模式切换为间接访问模式,或者由间接访问模式切换为直接访问模式。Optionally, the flash memory controller receives a mode switching instruction sent by the processing core, where the mode switching instruction is used to instruct the flash memory controller to switch from the direct access mode to the indirect access mode, or from the indirect access mode to the direct access mode.

可选地,在闪存控制器接收处理核发送的针对闪存的第一访问命令之前,处理核通过运行第一可信程序,在闪存控制器中配置保护地址范围。处理核通过运行第二可信程序,对闪存中该保护地址范围对应的内容进行校验,并确定该保护地址范围对应的内容校验通过。此步骤的具体实现过程参考上述步骤S11至步骤S12,本申请实施例在此不再赘述。Optionally, before the flash memory controller receives the first access command for the flash memory sent by the processing core, the processing core configures the protection address range in the flash memory controller by running the first trusted program. The processing core verifies the content corresponding to the protected address range in the flash memory by running the second trusted program, and determines that the content corresponding to the protected address range passes the verification. For the specific implementation process of this step, refer to the above steps S11 to S12, which will not be described again in the embodiment of the present application.

可选地,上述片上系统还包括只读存储器和随机存取存储器。片上系统上电或复位后,处理核通过运行只读存储器中的第一程序文件,通过闪存控制器读取闪存中的第二程序文件以及第一签名,并将读取的第二程序文件和第一签名保存在随机存取存储器中,第一签名是基于第一私钥和第二程序文件的内容生成的。处理核采用第一私钥对应的第一公钥对第一签名进行验证。处理核在对第一签名验证通过之后,从随机存取存储器中保存的第二程序文件中获取第一可信程序和第二可信程序。此步骤的具体实现过程参考上述步骤S13至步骤S15,本申请实施例在此不再赘述。Optionally, the above system on chip also includes a read-only memory and a random access memory. After the on-chip system is powered on or reset, the processing core reads the second program file and the first signature in the flash memory through the flash memory controller by running the first program file in the read-only memory, and transfers the read second program file and The first signature is stored in the random access memory and the first signature is generated based on the first private key and the contents of the second program file. The processing core uses the first public key corresponding to the first private key to verify the first signature. After passing the verification of the first signature, the processing core obtains the first trusted program and the second trusted program from the second program file stored in the random access memory. For the specific implementation process of this step, refer to the above steps S13 to S15, which will not be described again in the embodiment of the present application.

可选地,处理核通过运行第二可信程序,对闪存中保护地址范围对应的内容进行校验的实现方式,包括:处理核通过运行第二可信程序,通过闪存控制器读取闪存中保护地址范围对应的内容以及第二签名,并将读取的保护地址范围对应的内容和第二签名保存在随机存取存储器中,第二签名是基于第二私钥和保护地址范围对应的内容生成的。处理核采用第二私钥对应的第二公钥对第二签名进行验证。Optionally, the processing core verifies the content corresponding to the protected address range in the flash memory by running a second trusted program, including: the processing core reads the flash memory through the flash memory controller by running the second trusted program. The content corresponding to the protected address range and the second signature are stored in the random access memory, and the second signature is based on the second private key and the content corresponding to the protected address range. Generated. The processing core uses the second public key corresponding to the second private key to verify the second signature.

可选地,处理核通过运行第一可信程序,在闪存控制器中配置保护地址范围之后,处理核通过运行第三可信程序,锁定闪存控制器针对闪存的保护功能配置。Optionally, after the processing core configures the protection address range in the flash memory controller by running a first trusted program, the processing core locks the protection function configuration of the flash memory controller for the flash memory by running a third trusted program.

本申请实施例提供了另一种数据保护方法。该方法包括以下步骤B101至步骤B102。The embodiment of this application provides another data protection method. The method includes the following steps B101 to B102.

在步骤B101中,可编程逻辑控制器接收片上系统发送的针对闪存的第一访问命令,可编程逻辑控制器部署在片上系统与闪存之间,第一访问命令包括第一命令字和第一访问地址,第一命令字用于指示第一访问命令的访问类型,该访问类型包括读、写或擦除,第一访问地址用于指示第一访问命令在闪存中所访问的地址范围。In step B101, the programmable logic controller receives a first access command for the flash memory sent by the on-chip system. The programmable logic controller is deployed between the on-chip system and the flash memory. The first access command includes a first command word and a first access command. Address, the first command word is used to indicate the access type of the first access command, which includes read, write or erase, and the first access address is used to indicate the address range accessed by the first access command in the flash memory.

在步骤B102中,如果第一命令字指示第一访问命令的访问类型为写或擦除,且第一访问地址属于可编程逻辑控制器中配置的闪存的保护地址范围,可编程逻辑控制器拦截第一访问命令。In step B102, if the first command word indicates that the access type of the first access command is write or erase, and the first access address belongs to the protection address range of the flash memory configured in the programmable logic controller, the programmable logic controller intercepts First access command.

该方法具体用于实现上述方法500。第一访问命令例如是访问命令21,第一命令字例如是命令字21,第一访问地址例如是访问地址21。步骤B101和步骤B102的具体实现过程参考上述方法500中的步骤501至步骤502,本申请实施例在此不再赘述。This method is specifically used to implement the above method 500. The first access command is, for example, access command 21, the first command word is, for example, command word 21, and the first access address is, for example, access address 21. For the specific implementation process of step B101 and step B102, refer to step 501 to step 502 in the above-mentioned method 500, which will not be described again in the embodiment of the present application.

可选地,可编程逻辑控制器接收片上系统发送的针对闪存的第一访问命令的实现方式,包括:可编程逻辑控制器在间接访问模式下接收片上系统发送的第一访问命令。Optionally, the implementation of the programmable logic controller receiving the first access command sent by the on-chip system for the flash memory includes: the programmable logic controller receives the first access command sent by the on-chip system in the indirect access mode.

可选地,可编程逻辑控制器在直接访问模式下接收片上系统发送的针对闪存的第二访问命令,第二访问命令包括第二命令字和第二访问地址,第二命令字用于指示第二访问命令的访问类型为读,第二访问地址用于指示第二访问命令在闪存中所访问的地址范围。如果第二访问地址不属于可编程逻辑控制器中配置的闪存的可读地址范围,可编程逻辑控制器拦截第二访问命令。第二访问命令例如是访问命令22,第二命令字例如是命令字22,第二访问地址例如是访问地址22。此步骤的具体实现过程参考上述方法500中的步骤504至步骤505,本申请实施例在此不再赘述。Optionally, the programmable logic controller receives a second access command for the flash memory sent by the on-chip system in the direct access mode. The second access command includes a second command word and a second access address, and the second command word is used to indicate the second access command. The access type of the second access command is read, and the second access address is used to indicate the address range accessed by the second access command in the flash memory. If the second access address does not belong to the readable address range of the flash memory configured in the programmable logic controller, the programmable logic controller intercepts the second access command. The second access command is, for example, access command 22, the second command word is, for example, command word 22, and the second access address is, for example, access address 22. For the specific implementation process of this step, refer to steps 504 to 505 in the above-mentioned method 500, which will not be described again in the embodiment of the present application.

可选地,如果第二访问地址属于可编程逻辑控制器中配置的闪存的可读地址范围,可编程逻辑控制器透传第二访问命令以及片上系统基于第二访问命令从闪存中读取的内容。此步骤的具体实现过程参考上述方法500中的步骤506,本申请实施例在此不再赘述。Optionally, if the second access address belongs to the readable address range of the flash memory configured in the programmable logic controller, the programmable logic controller transparently transmits the second access command and the on-chip system reads from the flash memory based on the second access command. content. For the specific implementation process of this step, refer to step 506 in the above-mentioned method 500, which will not be described again in the embodiment of the present application.

可选地,如果第一命令字指示第一访问命令的访问类型为读,可编程逻辑控制器透传第一访问命令以及片上系统基于第一访问命令从闪存中读取的内容。此步骤的具体实现过程参考上述方法500中的步骤503,本申请实施例在此不再赘述。Optionally, if the first command word indicates that the access type of the first access command is read, the programmable logic controller transparently transmits the first access command and the content read by the system-on-chip from the flash memory based on the first access command. For the specific implementation process of this step, refer to step 503 in the above-mentioned method 500, which will not be described again in the embodiment of the present application.

可选地,可编程逻辑控制器接收片上系统发送的模式切换指令,该模式切换指令用于指示可编程逻辑控制器由直接访问模式切换为间接访问模式,或者由间接访问模式切换为直接访问模式。Optionally, the programmable logic controller receives a mode switching instruction sent by the on-chip system. The mode switching instruction is used to instruct the programmable logic controller to switch from the direct access mode to the indirect access mode, or to switch from the indirect access mode to the direct access mode. .

可选地,在可编程逻辑控制器接收片上系统发送的针对闪存的第一访问命令之前,可编程逻辑控制器接收片上系统发送的配置命令,该配置命令包括保护地址范围。可编程逻辑控制器根据配置命令在可编程逻辑控制器中配置该保护地址范围。此步骤的具体实现过程参考上述步骤S21至步骤S22,本申请实施例在此不再赘述。Optionally, before the programmable logic controller receives the first access command for the flash memory sent by the on-chip system, the programmable logic controller receives a configuration command sent by the on-chip system, and the configuration command includes the protection address range. The programmable logic controller configures the protection address range in the programmable logic controller according to the configuration command. For the specific implementation process of this step, refer to the above steps S21 to S22, which will not be described again in the embodiment of the present application.

可选地,在可编程逻辑控制器根据配置命令在可编程逻辑控制器中配置保护地址范围之后,可编程逻辑控制器接收片上系统发送的锁定命令。可编程逻辑控制器根据该锁定命令锁定可编程逻辑控制器针对闪存的保护功能配置。此步骤的具体实现过程参考上述步骤S23至步骤S24,本申请实施例在此不再赘述。Optionally, after the programmable logic controller configures the protection address range in the programmable logic controller according to the configuration command, the programmable logic controller receives the lock command sent by the on-chip system. The programmable logic controller locks the protection function configuration of the programmable logic controller for the flash memory according to the lock command. For the specific implementation process of this step, refer to the above steps S23 to S24, which will not be described again in the embodiment of the present application.

本申请实施例提供了一种片上系统,包括:处理核、存储器和闪存控制器。该存储器用于存储程序指令,该处理核读取该存储器中保存的程序指令后,与闪存控制器配合执行如图4所示的方法400。该片上系统的结构例如参考图1。Embodiments of the present application provide a system on a chip, including: a processing core, a memory, and a flash memory controller. The memory is used to store program instructions. After reading the program instructions saved in the memory, the processing core cooperates with the flash memory controller to execute the method 400 shown in Figure 4 . The structure of the system-on-chip is illustrated in Figure 1 .

本申请实施例提供了一种可编程逻辑控制器,包括:可编程逻辑单元和可编程IO单元。可编程IO单元用于收发指令。可编程逻辑单元用于根据可编程IO单元接收到的指令执行逻辑功能,实现如图5所示的方法500。An embodiment of the present application provides a programmable logic controller, including: a programmable logic unit and a programmable IO unit. Programmable IO unit is used to send and receive instructions. The programmable logic unit is used to execute logic functions according to instructions received by the programmable IO unit to implement method 500 as shown in Figure 5.

例如,图6是本申请实施例提供的一种可编程逻辑控制器的结构示意图。如图6所示,可编程逻辑控制器包括可编程逻辑单元601和可编程IO单元602。可编程逻辑单元601和可编程IO单元602通过可编程内部连线603连接。For example, FIG. 6 is a schematic structural diagram of a programmable logic controller provided by an embodiment of the present application. As shown in Figure 6, the programmable logic controller includes a programmable logic unit 601 and a programmable IO unit 602. The programmable logic unit 601 and the programmable IO unit 602 are connected through a programmable internal connection 603 .

其中,可编程逻辑单元601由多个可编程逻辑门组成,如与门、或门、非门等。可编程逻辑单元601负责执行特定的逻辑功能,例如布尔运算、条件判断等。本申请实施例中,通过在可编程逻辑单元601中配置闪存的保护地址范围和/或可读地址范围,使可编程逻辑单元601执行对应的逻辑功能,以实现如图5所示的方法500。例如可编程逻辑控制器为CPLD,可编程逻辑单元601由多个逻辑阵列块(logic array block,LAB)组成。The programmable logic unit 601 is composed of multiple programmable logic gates, such as AND gates, OR gates, NOT gates, etc. The programmable logic unit 601 is responsible for executing specific logic functions, such as Boolean operations, conditional judgments, etc. In the embodiment of the present application, by configuring the protected address range and/or the readable address range of the flash memory in the programmable logic unit 601, the programmable logic unit 601 executes the corresponding logic function to implement the method 500 shown in Figure 5 . For example, the programmable logic controller is a CPLD, and the programmable logic unit 601 is composed of multiple logic array blocks (LAB).

可编程IO单元602用于与外部电路或其它器件进行信号的输入和输出。本申请实施例中,可编程IO单元602例如用于接收SoC发送的针对闪存的访问命令。The programmable IO unit 602 is used for signal input and output with external circuits or other devices. In the embodiment of the present application, the programmable IO unit 602 is used, for example, to receive an access command for the flash memory sent by the SoC.

可编程内部连线603也称内部互连网络(internal interconnect network),用于连接可编程逻辑单元601和可编程IO单元602,它提供了可编程逻辑单元601与可编程IO单元602之间的信号传输路径。The programmable internal connection 603 is also called an internal interconnect network and is used to connect the programmable logic unit 601 and the programmable IO unit 602. It provides a connection between the programmable logic unit 601 and the programmable IO unit 602. signal transmission path.

可选地,可编程逻辑控制器还包括配置存储器(configuration memory)604。配置存储器604通过可编程内部连线603与可编程逻辑单元601和可编程IO单元602连接。配置存储器604用于存储可编程逻辑控制器的配置信息,例如可编程逻辑单元601的连接关系、可编程IO单元602的引脚功能设置等。配置存储器604例如为非易失性存储器或易失性存储器。Optionally, the programmable logic controller also includes a configuration memory 604. The configuration memory 604 is connected to the programmable logic unit 601 and the programmable IO unit 602 through a programmable internal connection 603 . The configuration memory 604 is used to store the configuration information of the programmable logic controller, such as the connection relationship of the programmable logic unit 601, the pin function settings of the programmable IO unit 602, etc. The configuration memory 604 is, for example, a non-volatile memory or a volatile memory.

上述图6所示的可编程逻辑控制器仅仅是示例性的,在实现过程中,可编程逻辑控制器还可以包括其他组件,本申请实施例不再一一列举。The programmable logic controller shown in FIG. 6 is only exemplary. During the implementation process, the programmable logic controller may also include other components, which will not be listed one by one in the embodiment of this application.

本申请实施例提供了一种数据保护系统,包括:片上系统和可编程逻辑控制器。该片上系统包括处理核和闪存控制器。可编程逻辑控制器与闪存控制器连接。其中,处理核用于先通过运行第一可信程序,在可编程逻辑控制器中配置闪存的保护地址范围,再通过运行第二可信程序,对闪存中该保护地址范围对应的内容进行校验,并在确定该保护地址范围对应的内容校验通过之后,通过闪存控制器向闪存发送访问命令,具体实现过程可参考上述步骤S22下,SoC上电或复位后,SoC内部的处理核执行的安全启动流程。可编程逻辑控制器用于在可编程逻辑控制器中配置该保护地址范围之后,执行如图5所示的方法500。Embodiments of the present application provide a data protection system, including: a system on a chip and a programmable logic controller. The system-on-chip includes processing cores and flash memory controllers. The programmable logic controller is connected to the flash memory controller. Wherein, the processing core is used to first configure the protection address range of the flash memory in the programmable logic controller by running the first trusted program, and then run the second trusted program to calibrate the content corresponding to the protection address range in the flash memory. After it is determined that the content corresponding to the protected address range has passed the verification, the access command is sent to the flash memory through the flash memory controller. The specific implementation process can be referred to the above step S22. After the SoC is powered on or reset, the processing core inside the SoC executes secure boot process. The programmable logic controller is used to execute the method 500 shown in Figure 5 after configuring the protection address range in the programmable logic controller.

本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质上存储有指令,当所述指令被处理器执行时,实现如图4所示的方法400或图5所示的方法500。Embodiments of the present application provide a computer-readable storage medium. Instructions are stored on the computer-readable storage medium. When the instructions are executed by a processor, the method 400 shown in Figure 4 or the method shown in Figure 5 is implemented. method 500.

本申请实施例提供了一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时,实现如图4所示的方法400或图5所示的方法500。An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the method 400 shown in Figure 4 or the method 500 shown in Figure 5 is implemented.

本申请实施例提供了一种芯片,包括可编程逻辑电路和/或程序指令,当芯片运行时,实现如图4所示的方法400或图5所示的方法500。The embodiment of the present application provides a chip, which includes a programmable logic circuit and/or program instructions. When the chip is run, the method 400 shown in Figure 4 or the method 500 shown in Figure 5 is implemented.

本领域普通技术人员可以理解实现上述实施例的全部或部分步骤可以通过硬件来完成,也可以通过程序来指令相关的硬件完成,的程序可以存储于一种计算机可读存储介质中,上述提到的存储介质可以是只读存储器,磁盘或光盘等。Those of ordinary skill in the art can understand that all or part of the steps to implement the above embodiments can be completed by hardware, or can be completed by instructing the relevant hardware through a program. The program can be stored in a computer-readable storage medium. The above-mentioned The storage medium can be read-only memory, magnetic disk or optical disk, etc.

在本申请实施例中,术语“第一”、“第二”和“第三”仅用于描述目的,而不能理解为指示或暗示相对重要性。In the embodiments of the present application, the terms "first", "second" and "third" are only used for description purposes and cannot be understood as indicating or implying relative importance.

本申请中术语“和/或”,仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,本文中字符“/”,一般表示前后关联对象是一种“或”的关系。The term "and/or" in this application is just an association relationship describing related objects, indicating that there can be three relationships, for example, A and/or B, which can mean: A alone exists, A and B exist simultaneously, alone There are three situations B. In addition, the character "/" in this article generally indicates that the related objects are an "or" relationship.

需要说明的是,本申请所涉及的信息(包括但不限于用户设备信息、用户个人信息等)、数据(包括但不限于用于分析的数据、存储的数据、展示的数据等)以及信号,均为经用户授权或者经过各方充分授权的,且相关数据的收集、使用和处理需要遵守相关国家和地区的相关法律法规和标准。It should be noted that the information (including but not limited to user equipment information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this application, All are authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.

以上仅为本申请的可选实施例,并不用以限制本申请,凡在本申请的构思和原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。The above are only optional embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the concepts and principles of the present application shall be included in the protection scope of the present application. Inside.

Claims (26)

1.一种数据保护方法,其特征在于,应用于片上系统,所述片上系统包括处理核和闪存控制器,所述方法包括:1. A data protection method, characterized in that it is applied to a system on a chip, the system on a chip includes a processing core and a flash memory controller, and the method includes: 所述闪存控制器接收所述处理核发送的针对闪存的第一访问命令,所述闪存部署于所述片上系统的外部,所述第一访问命令包括第一命令字和第一访问地址,所述第一命令字用于指示所述第一访问命令的访问类型,所述访问类型包括读、写或擦除,所述第一访问地址用于指示所述第一访问命令在所述闪存中所访问的地址范围;The flash memory controller receives a first access command for the flash memory sent by the processing core. The flash memory is deployed outside the on-chip system. The first access command includes a first command word and a first access address. The first command word is used to indicate the access type of the first access command. The access type includes read, write or erase. The first access address is used to indicate that the first access command is in the flash memory. The range of addresses visited; 如果所述第一命令字指示所述第一访问命令的访问类型为写或擦除,且所述第一访问地址属于所述闪存控制器中配置的所述闪存的保护地址范围,所述闪存控制器拦截所述第一访问命令。If the first command word indicates that the access type of the first access command is write or erase, and the first access address belongs to the protection address range of the flash memory configured in the flash memory controller, the flash memory The controller intercepts the first access command. 2.根据权利要求1所述的方法,其特征在于,所述闪存中部署有程序文件,所述保护地址范围包括所述程序文件的地址范围。2. The method according to claim 1, wherein a program file is deployed in the flash memory, and the protection address range includes the address range of the program file. 3.根据权利要求1或2所述的方法,其特征在于,所述闪存控制器接收所述处理核发送的针对闪存的第一访问命令,包括:3. The method according to claim 1 or 2, characterized in that the flash memory controller receives the first access command for the flash memory sent by the processing core, including: 所述闪存控制器在间接访问模式下接收所述处理核发送的所述第一访问命令。The flash memory controller receives the first access command sent by the processing core in the indirect access mode. 4.根据权利要求3所述的方法,其特征在于,所述方法还包括:4. The method according to claim 3, characterized in that the method further includes: 所述闪存控制器在直接访问模式下接收所述处理核发送的针对所述闪存的第二访问命令,所述第二访问命令包括第二访问地址,所述第二访问地址用于指示所述第二访问命令在所述闪存中所访问的地址范围;The flash memory controller receives a second access command for the flash memory sent by the processing core in the direct access mode, the second access command includes a second access address, and the second access address is used to indicate the The address range accessed by the second access command in the flash memory; 如果所述第二访问地址不属于所述闪存控制器中配置的所述闪存的可读地址范围,所述闪存控制器拦截所述第二访问命令。If the second access address does not belong to the readable address range of the flash memory configured in the flash memory controller, the flash memory controller intercepts the second access command. 5.根据权利要求4所述的方法,其特征在于,所述方法还包括:5. The method according to claim 4, characterized in that, the method further comprises: 如果所述第二访问地址属于所述闪存控制器中配置的所述闪存的可读地址范围,所述闪存控制器生成第二命令字,所述第二命令字用于指示所述第二访问命令的访问类型为读;If the second access address belongs to the readable address range of the flash memory configured in the flash memory controller, the flash memory controller generates a second command word, the second command word is used to indicate the second access The access type of the command is read; 所述闪存控制器基于所述第二命令字和所述第二访问地址从所述闪存中读取所述第二访问地址对应的内容,并将所述第二访问地址对应的内容发送给所述处理核。The flash memory controller reads the content corresponding to the second access address from the flash memory based on the second command word and the second access address, and sends the content corresponding to the second access address to the flash memory. Described processing core. 6.根据权利要求4或5所述的方法,其特征在于,所述可读地址范围与所述保护地址范围相同。6. The method according to claim 4 or 5, characterized in that the readable address range is the same as the protected address range. 7.根据权利要求3至6任一所述的方法,其特征在于,所述方法还包括:7. The method according to any one of claims 3 to 6, characterized in that the method further includes: 如果所述第一命令字指示所述第一访问命令的访问类型为读,所述闪存控制器基于所述第一命令字和所述第一访问地址从所述闪存中读取所述第一访问地址对应的内容,并将所述第一访问地址对应的内容发送给所述处理核。If the first command word indicates that the access type of the first access command is read, the flash memory controller reads the first data from the flash memory based on the first command word and the first access address. Access the content corresponding to the address, and send the content corresponding to the first access address to the processing core. 8.根据权利要求3至7任一所述的方法,其特征在于,所述方法还包括:8. The method according to any one of claims 3 to 7, characterized in that the method further includes: 所述闪存控制器接收所述处理核发送的模式切换指令,所述模式切换指令用于指示所述闪存控制器由直接访问模式切换为间接访问模式,或者由间接访问模式切换为直接访问模式。The flash memory controller receives a mode switching instruction sent by the processing core, and the mode switching instruction is used to instruct the flash memory controller to switch from the direct access mode to the indirect access mode, or to switch from the indirect access mode to the direct access mode. 9.根据权利要求1至8任一所述的方法,其特征在于,在所述闪存控制器接收所述处理核发送的针对闪存的第一访问命令之前,所述方法还包括:9. The method according to any one of claims 1 to 8, characterized in that, before the flash memory controller receives the first access command for the flash memory sent by the processing core, the method further includes: 所述处理核通过运行第一可信程序,在所述闪存控制器中配置所述保护地址范围;The processing core configures the protected address range in the flash memory controller by running a first trusted program; 所述处理核通过运行第二可信程序,对所述闪存中所述保护地址范围对应的内容进行校验,并确定所述保护地址范围对应的内容校验通过。The processing core verifies the content corresponding to the protected address range in the flash memory by running a second trusted program, and determines that the content corresponding to the protected address range passes the verification. 10.根据权利要求9所述的方法,其特征在于,所述片上系统还包括只读存储器和随机存取存储器,所述方法还包括:10. The method of claim 9, wherein the system-on-chip further includes a read-only memory and a random access memory, and the method further includes: 所述片上系统上电或复位后,所述处理核通过运行所述只读存储器中的第一程序文件,通过所述闪存控制器读取所述闪存中的第二程序文件以及第一签名,并将读取的所述第二程序文件和所述第一签名保存在所述随机存取存储器中,所述第一签名是基于第一私钥和所述第二程序文件的内容生成的;After the on-chip system is powered on or reset, the processing core reads the second program file and the first signature in the flash memory through the flash memory controller by running the first program file in the read-only memory, and save the read second program file and the first signature in the random access memory, where the first signature is generated based on the first private key and the content of the second program file; 所述处理核采用所述第一私钥对应的第一公钥对所述第一签名进行验证;The processing core uses the first public key corresponding to the first private key to verify the first signature; 所述处理核在对所述第一签名验证通过之后,从所述随机存取存储器中保存的所述第二程序文件中获取所述第一可信程序和所述第二可信程序。After the processing core passes the verification of the first signature, it obtains the first trusted program and the second trusted program from the second program file stored in the random access memory. 11.根据权利要求10所述的方法,其特征在于,所述处理核通过运行第二可信程序,对所述闪存中所述保护地址范围对应的内容进行校验,包括:11. The method of claim 10, wherein the processing core verifies the content corresponding to the protected address range in the flash memory by running a second trusted program, including: 所述处理核通过运行所述第二可信程序,通过所述闪存控制器读取所述闪存中所述保护地址范围对应的内容以及第二签名,并将读取的所述保护地址范围对应的内容和所述第二签名保存在所述随机存取存储器中,所述第二签名是基于第二私钥和所述保护地址范围对应的内容生成的;By running the second trusted program, the processing core reads the content corresponding to the protected address range and the second signature in the flash memory through the flash memory controller, and stores the read protected address range corresponding to The content and the second signature are stored in the random access memory, and the second signature is generated based on the content corresponding to the second private key and the protected address range; 所述处理核采用所述第二私钥对应的第二公钥对所述第二签名进行验证。The processing core uses the second public key corresponding to the second private key to verify the second signature. 12.根据权利要求9至11任一所述的方法,其特征在于,在所述处理核通过运行第一可信程序,在所述闪存控制器中配置所述保护地址范围之后,所述方法还包括:12. The method according to any one of claims 9 to 11, characterized in that after the processing core configures the protected address range in the flash memory controller by running a first trusted program, the method Also includes: 所述处理核通过运行第三可信程序,锁定所述闪存控制器针对所述闪存的保护功能配置。The processing core locks the protection function configuration of the flash memory controller for the flash memory by running a third trusted program. 13.一种数据保护方法,其特征在于,所述方法包括:13. A data protection method, characterized in that the method includes: 可编程逻辑控制器接收片上系统发送的针对闪存的第一访问命令,所述可编程逻辑控制器部署在所述片上系统与所述闪存之间,所述第一访问命令包括第一命令字和第一访问地址,所述第一命令字用于指示所述第一访问命令的访问类型,所述访问类型包括读、写或擦除,所述第一访问地址用于指示所述第一访问命令在所述闪存中所访问的地址范围;The programmable logic controller receives the first access command for the flash memory sent by the on-chip system. The programmable logic controller is deployed between the on-chip system and the flash memory. The first access command includes a first command word and A first access address, the first command word is used to indicate the access type of the first access command, the access type includes read, write or erase, the first access address is used to indicate the first access The address range accessed by the command in the flash memory; 如果所述第一命令字指示所述第一访问命令的访问类型为写或擦除,且所述第一访问地址属于所述可编程逻辑控制器中配置的所述闪存的保护地址范围,所述可编程逻辑控制器拦截所述第一访问命令。If the first command word indicates that the access type of the first access command is write or erase, and the first access address belongs to the protection address range of the flash memory configured in the programmable logic controller, then The programmable logic controller intercepts the first access command. 14.根据权利要求13所述的方法,其特征在于,所述可编程逻辑控制器接收片上系统发送的针对闪存的第一访问命令,包括:14. The method of claim 13, wherein the programmable logic controller receives the first access command for the flash memory sent by the system-on-chip, including: 所述可编程逻辑控制器在间接访问模式下接收所述片上系统发送的所述第一访问命令。The programmable logic controller receives the first access command sent by the system-on-chip in the indirect access mode. 15.根据权利要求14所述的方法,其特征在于,所述方法还包括:15. The method according to claim 14, characterized in that the method further comprises: 所述可编程逻辑控制器在直接访问模式下接收所述片上系统发送的针对所述闪存的第二访问命令,所述第二访问命令包括第二命令字和第二访问地址,所述第二命令字用于指示所述第二访问命令的访问类型为读,所述第二访问地址用于指示所述第二访问命令在所述闪存中所访问的地址范围;The programmable logic controller receives a second access command for the flash memory sent by the on-chip system in the direct access mode, the second access command includes a second command word and a second access address, and the second The command word is used to indicate that the access type of the second access command is read, and the second access address is used to indicate the address range accessed by the second access command in the flash memory; 如果所述第二访问地址不属于所述可编程逻辑控制器中配置的所述闪存的可读地址范围,所述可编程逻辑控制器拦截所述第二访问命令。If the second access address does not belong to the readable address range of the flash memory configured in the programmable logic controller, the programmable logic controller intercepts the second access command. 16.根据权利要求15所述的方法,其特征在于,所述方法还包括:16. The method according to claim 15, characterized in that, the method further comprises: 如果所述第二访问地址属于所述可编程逻辑控制器中配置的所述闪存的可读地址范围,所述可编程逻辑控制器透传所述第二访问命令以及所述片上系统基于所述第二访问命令从所述闪存中读取的内容。If the second access address belongs to the readable address range of the flash memory configured in the programmable logic controller, the programmable logic controller transparently transmits the second access command and the system-on-chip based on the The second access command reads the contents from the flash memory. 17.根据权利要求14至16任一所述的方法,其特征在于,所述方法还包括:17. The method according to any one of claims 14 to 16, characterized in that the method further comprises: 如果所述第一命令字指示所述第一访问命令的访问类型为读,所述可编程逻辑控制器透传所述第一访问命令以及所述片上系统基于所述第一访问命令从所述闪存中读取的内容。If the first command word indicates that the access type of the first access command is read, the programmable logic controller transparently transmits the first access command and the on-chip system obtains the data from the first access command based on the first access command. Contents read from flash memory. 18.根据权利要求14至17任一所述的方法,其特征在于,所述方法还包括:18. The method according to any one of claims 14 to 17, characterized in that the method further comprises: 所述可编程逻辑控制器接收所述片上系统发送的模式切换指令,所述模式切换指令用于指示所述可编程逻辑控制器由直接访问模式切换为间接访问模式,或者由间接访问模式切换为直接访问模式。The programmable logic controller receives a mode switching instruction sent by the on-chip system. The mode switching instruction is used to instruct the programmable logic controller to switch from the direct access mode to the indirect access mode, or to switch from the indirect access mode to Direct access mode. 19.根据权利要求13至18任一所述的方法,其特征在于,在所述可编程逻辑控制器接收片上系统发送的针对闪存的第一访问命令之前,所述方法还包括:19. The method according to any one of claims 13 to 18, characterized in that, before the programmable logic controller receives the first access command for the flash memory sent by the system-on-chip, the method further includes: 所述可编程逻辑控制器接收所述片上系统发送的配置命令,所述配置命令包括所述保护地址范围;The programmable logic controller receives a configuration command sent by the on-chip system, where the configuration command includes the protection address range; 所述可编程逻辑控制器根据所述配置命令在所述可编程逻辑控制器中配置所述保护地址范围。The programmable logic controller configures the protection address range in the programmable logic controller according to the configuration command. 20.根据权利要求19所述的方法,其特征在于,在所述可编程逻辑控制器根据所述配置命令在所述可编程逻辑控制器中配置所述保护地址范围之后,所述方法还包括:20. The method of claim 19, wherein after the programmable logic controller configures the protection address range in the programmable logic controller according to the configuration command, the method further includes : 所述可编程逻辑控制器接收所述片上系统发送的锁定命令;The programmable logic controller receives a lock command sent by the system-on-chip; 所述可编程逻辑控制器根据所述锁定命令锁定所述可编程逻辑控制器针对所述闪存的保护功能配置。The programmable logic controller locks the protection function configuration of the programmable logic controller for the flash memory according to the lock command. 21.一种片上系统,其特征在于,包括:处理核、存储器和闪存控制器;21. A system on a chip, characterized in that it includes: a processing core, a memory and a flash memory controller; 所述存储器用于存储程序指令,The memory is used to store program instructions, 所述处理核读取所述存储器中保存的程序指令后,与所述闪存控制器配合执行如权利要求1至12任一所述的数据保护方法。After reading the program instructions stored in the memory, the processing core cooperates with the flash memory controller to execute the data protection method according to any one of claims 1 to 12. 22.一种可编程逻辑控制器,其特征在于,包括:可编程逻辑单元和可编程输入输出单元;22. A programmable logic controller, characterized by comprising: a programmable logic unit and a programmable input and output unit; 所述可编程输入输出单元用于收发指令;The programmable input and output unit is used to send and receive instructions; 所述可编程逻辑单元用于根据所述可编程输入输出单元接收到的指令执行逻辑功能,实现如权利要求13至20任一所述的数据保护方法。The programmable logic unit is configured to execute logical functions according to instructions received by the programmable input and output unit to implement the data protection method as described in any one of claims 13 to 20. 23.一种数据保护系统,其特征在于,包括:片上系统和可编程逻辑控制器,所述片上系统包括处理核和闪存控制器,所述可编程逻辑控制器与所述闪存控制器连接;23. A data protection system, characterized in that it includes: a system on a chip and a programmable logic controller, the system on a chip includes a processing core and a flash memory controller, and the programmable logic controller is connected to the flash memory controller; 所述处理核用于先通过运行第一可信程序,在所述可编程逻辑控制器中配置闪存的保护地址范围,通过运行第二可信程序,对所述闪存中所述保护地址范围对应的内容进行校验,并在确定所述保护地址范围对应的内容校验通过之后,通过所述闪存控制器向所述闪存发送访问命令;The processing core is configured to first configure a protected address range of the flash memory in the programmable logic controller by running a first trusted program, and by running a second trusted program, configure the corresponding protected address range in the flash memory. Verify the content, and after determining that the content corresponding to the protected address range passes the verification, send an access command to the flash memory through the flash memory controller; 所述可编程逻辑控制器用于在所述可编程逻辑控制器中配置所述保护地址范围之后,执行如权利要求13至20任一所述的数据保护方法。The programmable logic controller is configured to execute the data protection method according to any one of claims 13 to 20 after configuring the protection address range in the programmable logic controller. 24.一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有指令,当所述指令被处理器执行时,实现如权利要求1至20任一所述的数据保护方法。24. A computer-readable storage medium, characterized in that instructions are stored on the computer-readable storage medium. When the instructions are executed by a processor, the data protection as claimed in any one of claims 1 to 20 is achieved. method. 25.一种计算机程序产品,其特征在于,包括计算机程序,所述计算机程序被处理器执行时,实现如权利要求1至20任一所述的数据保护方法。25. A computer program product, characterized in that it includes a computer program. When the computer program is executed by a processor, the data protection method according to any one of claims 1 to 20 is implemented. 26.一种芯片,其特征在于,包括可编程逻辑电路和/或程序指令,当芯片运行时,实现如权利要求1至20任一所述的数据保护方法。26. A chip, characterized in that it includes a programmable logic circuit and/or program instructions, and when the chip is running, the data protection method according to any one of claims 1 to 20 is implemented.
CN202311056558.7A 2023-08-21 2023-08-21 Data protection methods, devices and systems Pending CN117472808A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202311056558.7A CN117472808A (en) 2023-08-21 2023-08-21 Data protection methods, devices and systems
PCT/CN2024/080333 WO2025039512A1 (en) 2023-08-21 2024-03-06 Data protection method, apparatus and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311056558.7A CN117472808A (en) 2023-08-21 2023-08-21 Data protection methods, devices and systems

Publications (1)

Publication Number Publication Date
CN117472808A true CN117472808A (en) 2024-01-30

Family

ID=89631964

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311056558.7A Pending CN117472808A (en) 2023-08-21 2023-08-21 Data protection methods, devices and systems

Country Status (2)

Country Link
CN (1) CN117472808A (en)
WO (1) WO2025039512A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2025039512A1 (en) * 2023-08-21 2025-02-27 华为技术有限公司 Data protection method, apparatus and system

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102184366B (en) * 2011-06-07 2013-01-02 郑州信大捷安信息技术股份有限公司 External program security access architecture based on system on chip (SoC) and control method
WO2014204331A1 (en) * 2013-06-17 2014-12-24 Llc "Topcon Positioning Systems" Nand flash memory interface controller with gnss receiver firmware booting capability
US10025600B2 (en) * 2015-10-02 2018-07-17 Google Llc NAND-based verified boot
CN108062486B (en) * 2017-12-15 2020-09-15 杭州中天微系统有限公司 Storage protection device for indirect access storage controller
US11636231B2 (en) * 2020-07-24 2023-04-25 Qualcomm Incorporated Methods and apparatus for in-memory device access control
CN116204450B (en) * 2023-04-28 2023-08-18 新华三技术有限公司 Data writing method, processor, device, service board and storage medium
CN117472808A (en) * 2023-08-21 2024-01-30 华为技术有限公司 Data protection methods, devices and systems

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2025039512A1 (en) * 2023-08-21 2025-02-27 华为技术有限公司 Data protection method, apparatus and system

Also Published As

Publication number Publication date
WO2025039512A1 (en) 2025-02-27

Similar Documents

Publication Publication Date Title
US7107460B2 (en) Method and system for securing enablement access to a data security device
CN100489728C (en) Method for establishing trustable operational environment in a computer
JP5114617B2 (en) Secure terminal, program, and method for protecting private key
CN101533440B (en) Apparatus for providing a secure execution environment and method for executing secure coding
US8971144B2 (en) Hardware write-protection
CN103262092B (en) Based on the anti-Malware method and apparatus of memory driver
KR102395258B1 (en) Method of secure booting using route switchover of boot memory bus and apparatus using the same
JP6695885B2 (en) Hack resistant computer design
CN109918919A (en) Authenticate the management of variable
TWI801468B (en) Apparatus, methods, and systems for protecting the security of an electronic device, and related microcontrollers
JP2007249933A (en) Managing access to content in data processing equipment
JPH10228420A (en) Processing system security
US20230342472A1 (en) Computer System, Trusted Function Component, and Running Method
KR20190085387A (en) Semiconductor device and method for operating semiconductor device
CN111191214B (en) Embedded processor and data protection method
WO2025039512A1 (en) Data protection method, apparatus and system
KR20170102285A (en) Security Elements
US20210373891A1 (en) Enhanced protection of processors from a buffer overflow attack
CN112685802B (en) Flash chip reading control method and device and storage medium
CN114787808A (en) Secure Embedded Microcontroller Image Loading
CN115186239A (en) Authority control method and device, computing equipment and storage medium
TWI728572B (en) Rpmc flash emulation
CN114490448A (en) Method for switching execution environment and related equipment thereof
CN103164352A (en) Flash memory storage system and data protection method thereof
JP6204555B1 (en) Method, system firmware, and computer for protecting variables stored in non-volatile memory

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination