Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ Every change is a commit on top of the official base (`git log ebea824..main`).
a signed int into the sign bit, which UBSan flags.

**OpenCore (`Library/OcMainLib`, `Include`)**
- The F2 editor, config chooser and kexts screen (`OpenCoreEditor.c`, `OpenCoreConfigSelect.c`,
- The F2 editor, config chooser and kexts screen (`OpenCoreEditor*.c`, one file per screen,
`OpenCoreConfigSelect.c`,
`OpenCoreKextOrder.c`, `OpenCoreEditPlist.c`, `OpenCoreNvram.c`) come from Illia Haidai's two
commits. On top of them I changed the title and the drawing layer below.
- `OpenCoreEditorUi.c`: the editor draws through a small interface (`OC_EDITOR_CANVAS` in
Expand All @@ -110,9 +111,11 @@ Every change is a commit on top of the official base (`git log ebea824..main`).
**Tests and tools**
- `Utilities/TestCanopy` (new): runs the real OpenCanopy on a Mac with a fake 1920×1080 screen and
scripted keys and dumps the frames. It can also replay what the editor drew and draw it on the sheet.
- `Utilities/TestPickerEditor` and `Utilities/TestEditPlist`: 1193 checks for the editor and 84455 for
- `Utilities/TestPickerEditor` and `Utilities/TestEditPlist`: 1669 checks for the editor (also at 80x25, 100x30, 128x40 and 240x67 consoles, with very long names and broken configs) and 84455 for
the plist writer. They run plain and with ASan/UBSan through `DrogaBox/run-tests.sh`.
- `DrogaBox/update-base.sh`: moves the fork to a newer OpenCore (see below).
- [`DrogaBox/WRITES.md`](../DrogaBox/WRITES.md): what each save writes to the disk, and what a power cut
at each step would leave.

## Install

Expand Down
2 changes: 1 addition & 1 deletion DrogaBox/BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ for the build, `nasm` and `mtoc` in `PATH`.
## Tests and build

```
DrogaBox/run-tests.sh # TestPickerEditor (1193 checks) and TestEditPlist (84455), plain and SANITIZE=1
DrogaBox/run-tests.sh # TestPickerEditor (1669 checks) and TestEditPlist (84455), plain and SANITIZE=1
ARCHS=X64 TARGETS=RELEASE,DEBUG TOOLCHAINS=XCODE5 ./build_oc.tool
```

Expand Down
53 changes: 53 additions & 0 deletions DrogaBox/WRITES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# What the editor writes, and what a power cut would leave

Checked 2026-11-24 against `main` (after the split into one file per screen). Read from the code; none
of it has been tried with a real power cut.

## Choosing a config (`OcMiscSetConfigChoice`, `OpenCoreConfigSelect.c`)

It deletes `config.choice` and writes a new one: the name on the first line, `keep` or `once` on the
second.

- Cut after the delete: no choice, the next start uses `config.plist`. Safe.
- Cut halfway through the write: the name is cut short or empty. `ConfigReadChoice` only takes a name
that passes `OcMiscIsConfigName`, so a cut name is dropped (and the file deleted) and `config.plist` is
used. A cut `keep` reads as a choice for one start. Safe.
- A choice that points to a config that later breaks: `OcMiscLoadConfig` falls back to `config.plist`
and the menu says so. Safe.

## Saving `config.plist` (`EdWriteConfig`, `OpenCoreEditor.c`)

Used by every save in the editor (config tree, boot flags saved to the config, kexts and the other lists,
quirks) and by putting the backup back. The steps:

1. Delete `config.plist.bak`, write the file being replaced into it, read it back and compare.
If that fails, stop: `config.plist` has not been touched.
2. Delete `config.plist`, write the new one, read it back and compare. If that fails, write the old
one back.

Before step 1 the new text has already been parsed, and it is refused if it has more problems than the
file it replaces.

- Cut during step 1: `config.plist` is untouched. Safe; `config.plist.bak` may be missing or cut.
- **Cut during step 2, between the delete and the end of the write: `config.plist` is missing or cut.**
At the next start `OcMiscLoadConfig` fails and OpenCore stops in `CpuDeadLoop`
(`OpenCoreMisc.c`, after `OcMiscLoadConfig`). The machine hangs before the picker. The previous file
is whole in `config.plist.bak`, but only another boot disk (the USB stick) can put it back.
- The read-back in steps 1 and 2 may come from the firmware's cache rather than the disk, so it shows
that the write was accepted, not that it reached the disk.

## Proposal (not done: it needs the owner's yes)

Two parts, either one helps:

1. **At boot**, in `OcMiscLoadConfig`: if `config.plist` cannot be loaded, try `config.plist.bak` before
stopping, and show "started with the backup" in the editor's main menu, the way a failed chosen
config is shown today. This closes the gap completely, but it changes the code that runs on every
start, which stage 2 said it would leave alone.
2. **In the editor**: write the new file as `config.plist.new`, check it, then delete `config.plist` and
rename `config.plist.new` to `config.plist` (`SetInfo` with the new name). The window shrinks from a
whole write to one rename. If the firmware's FAT driver refuses the rename, it falls back to the
current steps. It cannot close the window on its own: FAT cannot rename over an existing file.

Both can be tested on the Mac by making the harness's fake file system stop after the n-th write, for
every n, and checking that the next start finds a config it can load.
6 changes: 4 additions & 2 deletions DrogaBox/tools/render-screen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import UniformTypeIdentifiers
let args = CommandLine.arguments
let text = try! String(contentsOfFile: args[1], encoding: .utf8)
let lines = text.components(separatedBy: "\n")
// Optional console size after the two paths: columns and rows (80 25 by default).
let cols = args.count > 4 ? Int(args[3])! : 80, rows = args.count > 4 ? Int(args[4])! : 25
let font = CTFontCreateWithName("Menlo-Regular" as CFString, 22, nil)
let cw: CGFloat = 13.25, ch: CGFloat = 28, pad: CGFloat = 24
let w = Int(cw * 80 + pad * 2), h = Int(ch * 25 + pad * 2)
let w = Int(cw * CGFloat(cols) + pad * 2), h = Int(ch * CGFloat(rows) + pad * 2)
let cs = CGColorSpace(name: CGColorSpace.sRGB)!
let ctx = CGContext(data: nil, width: w, height: h, bitsPerComponent: 8, bytesPerRow: 0, space: cs, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!
ctx.setFillColor(CGColor(red: 0, green: 0, blue: 0, alpha: 1)); ctx.fill(CGRect(x: 0, y: 0, width: w, height: h))
let fg = CGColor(red: 0.78, green: 0.78, blue: 0.78, alpha: 1)
for (i, l) in lines.prefix(25).enumerated() {
for (i, l) in lines.prefix(rows).enumerated() {
for (j, c) in l.enumerated() where c != " " {
let a = NSAttributedString(string: String(c), attributes: [NSAttributedString.Key(kCTFontAttributeName as String): font, NSAttributedString.Key(kCTForegroundColorAttributeName as String): fg])
let line = CTLineCreateWithAttributedString(a)
Expand Down
7 changes: 7 additions & 0 deletions Library/OcMainLib/OcMainLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@
OpenCoreConfigSelect.c
OpenCoreDevProps.c
OpenCoreEditor.c
OpenCoreEditorBootArgs.c
OpenCoreEditorBrowser.c
OpenCoreEditorConfigs.c
OpenCoreEditorLists.c
OpenCoreEditorInternal.h
OpenCoreEditorPrivate.h
OpenCoreEditorQuirks.c
OpenCoreEditorText.c
OpenCoreEditorUi.c
OpenCoreEditorUi.h
OpenCoreEditPlist.c
Expand Down
Loading
Loading