The instant disclosure relates to electronic devices, and in particular, refers to an electronic device and a code patching method.
Currently, after being booted up and powered on, a system on chip first executes a boot procedure to initialize a hardware device and establish a mapping graph of a memory space, to set the software and hardware environment of the system to an appropriate state, so as to facilitate subsequent calls to the operating system core. For security reasons, codes of the boot procedure are stored in a read-only memory (ROM), to prevent the codes from being tampered with. However, if an error is found in a boot code after system on chips are manufactured, the system on chips need to be re-manufactured, which consumes a lot of time, money and other resources.
An embodiment of the instant disclosure discloses an electronic device, including a processor, a primary ROM, and a supplementary ROM memory. The primary ROM stores a boot code, and the boot code includes at least one checkpoint code segment. The processor is coupled to the primary ROM and the supplementary ROM and configured to execute the boot code of the primary ROM to execute a boot procedure of the electronic device; when the at least one checkpoint code segment is executed by the processor in a boot procedure, checks whether a patch code corresponding to the executed checkpoint code segment exists in the supplementary ROM; and when the patch code corresponding to the executed checkpoint code segment exists in the supplementary ROM, executes the patch code.
An embodiment of the instant disclosure discloses a code patching method, performed by a processor in an electronic device. The code patching method includes: reading and loading a boot code stored in a primary ROM, to execute a boot procedure of the electronic device, wherein the boot code includes at least one checkpoint code segment; and checking whether a patch code corresponding to the executed checkpoint code segment exists in a supplementary ROM when the at least one checkpoint code segment is executed by the processor in the boot procedure; and executing the corresponding patch code in the supplementary ROM when the patch code corresponding to the executed checkpoint code segment exists in the supplementary ROM.
According to the electronic device and the code patching method in some embodiments of the instant disclosure, the boot code stored in the ROM can be patched, and especially, a code segment before a hardware initialization code segment can be patched.
In some embodiments, the primary ROM 20 is a ROM.
In some embodiments, the supplementary ROM 30 is a one-time programmable (OTP) ROM.
In some embodiments, the processor 10, the primary ROM 20 and the supplementary ROM 30 are located within a system-on-chip (SOC).
Here, a code example of the foregoing checkpoint function is shown as follows, which is used for determining whether there is an address (a variable addr) corresponding to the second identifier in the supplementary ROM 30. If yes, the processor 10 obtains and jumps to the address corresponding to the second identifier for execution.
type status checkpoint(arg ID)
An example of the search_supplementory_rom function listed before is shown as follows, which is used for searching whether there is a first identifier (a variable id_supplement) corresponding to a second identifier (a variable ID) in the first storage area 31 of the supplementary ROM 30 in which the look-up table is stored. If yes, the processor 10 returns to a first address (a variable addr) corresponding to the first identifier.
int search_supplementory_rom(arg ID)
In summary, according to the electronic device and the code patching method in some embodiments of the instant disclosure, the boot code stored in the primary ROM 20 can be patched, and especially, a code segment before the hardware initialization code segment can be patched.
Number | Name | Date | Kind |
---|---|---|---|
6892297 | Aguilar | May 2005 | B1 |
9880856 | Akdemir et al. | Jan 2018 | B2 |
20140244991 | Akdemir et al. | Aug 2014 | A1 |
20170039053 | Siluvainathan | Feb 2017 | A1 |
20170371803 | Zmudzinski | Dec 2017 | A1 |
20210319107 | Dahiya | Oct 2021 | A1 |
Number | Date | Country |
---|---|---|
200741542 | Nov 2007 | TW |
WO-0049495 | Aug 2000 | WO |
Entry |
---|
Booting, Wikipedia, 2020, 17 pages, [retrieved on Jul. 31, 2023], Retrieved from the Internet: <URL:https://web.archive.org/web/20200602181536/https://en.wikipedia.org/wiki/Booting>. |
Number | Date | Country | |
---|---|---|---|
20230236827 A1 | Jul 2023 | US |