]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Beep n times for n-th entry
authorJan Janssen <medhefgo@web.de>
Sun, 16 Jan 2022 14:57:38 +0000 (15:57 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 17 Jan 2022 00:05:35 +0000 (00:05 +0000)
man/loader.conf.xml
src/boot/efi/boot.c
src/boot/efi/util.c
src/boot/efi/util.h

index 844bd631fc014978b080c41e0719e662717b2154..caff44aa1e6ab9722f32649bf7be5c794cfc003e 100644 (file)
       <varlistentry>
         <term>beep</term>
 
-        <listitem><para>Beep once as soon as the boot menu is shown (default disabled). Currently,
-        only x86 is supported, where it uses the PC speaker.</para></listitem>
+        <listitem><para>Beep n times when the n-th entry in the boot menu is shown (default disabled).
+        Currently, only x86 is supported, where it uses the PC speaker.</para></listitem>
       </varlistentry>
 
       <varlistentry>
index a128b38b9c6eeb64b73c7410b728f5bc46d0dd0e..f49bd9e5f856ef8404d331ca693cf126561b9616 100644 (file)
@@ -590,7 +590,7 @@ static BOOLEAN menu_run(
         _cleanup_freepool_ CHAR16 *clearline = NULL, *status = NULL;
         UINT32 timeout_efivar_saved = config->timeout_sec_efivar;
         UINT32 timeout_remain = config->timeout_sec == TIMEOUT_MENU_FORCE ? 0 : config->timeout_sec;
-        BOOLEAN exit = FALSE, run = TRUE, firmware_setup = FALSE, do_beep = config->beep;
+        BOOLEAN exit = FALSE, run = TRUE, firmware_setup = FALSE;
         INT64 console_mode_initial = ST->ConOut->Mode->Mode, console_mode_efivar_saved = config->console_mode_efivar;
         UINTN default_efivar_saved = config->idx_default_efivar;
 
@@ -727,10 +727,9 @@ static BOOLEAN menu_run(
                         ST->ConOut->OutputString(ST->ConOut, clearline + 1 + x + len);
                 }
 
-                if (do_beep) {
-                        beep();
-                        do_beep = FALSE;
-                }
+                /* Beep several times so that the selected entry can be distinguished. */
+                if (config->beep)
+                        beep(idx_highlight + 1);
 
                 err = console_key_read(&key, timeout_remain > 0 ? 1000 * 1000 : UINT64_MAX);
                 if (err == EFI_TIMEOUT) {
index 42c28badbf4d9db8b8b1290e64f60970ad7ee1f9..e023b97d2f0915b436b83d5a1f0f688a606afda0 100644 (file)
@@ -769,10 +769,11 @@ static inline void outb(UINT16 port, UINT8 value) {
         asm volatile("outb %0, %1" : : "a"(value), "Nd"(port));
 }
 
-void beep(void) {
+void beep(UINTN beep_count) {
         enum {
                 PITCH                = 500,
-                DURATION_USEC        = 100 * 1000,
+                BEEP_DURATION_USEC   = 100 * 1000,
+                WAIT_DURATION_USEC   = 400 * 1000,
 
                 PIT_FREQUENCY        = 0x1234dd,
                 SPEAKER_CONTROL_PORT = 0x61,
@@ -788,15 +789,22 @@ void beep(void) {
         outb(TIMER_CONTROL2_PORT, counter & 0xFF);
         outb(TIMER_CONTROL2_PORT, (counter >> 8) & 0xFF);
 
-        /* Turn speaker on. */
         UINT8 value = inb(SPEAKER_CONTROL_PORT);
-        value |= SPEAKER_ON_MASK;
-        outb(SPEAKER_CONTROL_PORT, value);
 
-        BS->Stall(DURATION_USEC);
+        while (beep_count > 0) {
+                /* Turn speaker on. */
+                value |= SPEAKER_ON_MASK;
+                outb(SPEAKER_CONTROL_PORT, value);
 
-        /* Turn speaker off. */
-        value &= ~SPEAKER_ON_MASK;
-        outb(SPEAKER_CONTROL_PORT, value);
+                BS->Stall(BEEP_DURATION_USEC);
+
+                /* Turn speaker off. */
+                value &= ~SPEAKER_ON_MASK;
+                outb(SPEAKER_CONTROL_PORT, value);
+
+                beep_count--;
+                if (beep_count > 0)
+                        BS->Stall(WAIT_DURATION_USEC);
+        }
 }
 #endif
index 8cee20885e52278a7da1c1560ec9c1e8099e708f..b60814b4919e87789a17b020ee9c7d569d3baa40 100644 (file)
@@ -171,7 +171,7 @@ extern UINT8 _text, _data;
 #endif
 
 #if defined(__i386__) || defined(__x86_64__)
-void beep(void);
+void beep(UINTN beep_count);
 #else
-static inline void beep(void) {}
+static inline void beep(UINTN beep_count) {}
 #endif