{"id":20113796,"url":"https://github.com/mkj/rpi-flipflop","last_synced_at":"2025-07-29T19:36:25.039Z","repository":{"id":30175911,"uuid":"33726342","full_name":"mkj/rpi-flipflop","owner":"mkj","description":"Raspberry Pi Boot Flipflop","archived":false,"fork":false,"pushed_at":"2019-03-01T14:55:27.000Z","size":21,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-06T12:38:07.156Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-10T12:02:46.000Z","updated_at":"2024-10-04T01:13:44.000Z","dependencies_parsed_at":"2022-08-17T19:50:58.091Z","dependency_job_id":null,"html_url":"https://github.com/mkj/rpi-flipflop","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkj%2Frpi-flipflop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkj%2Frpi-flipflop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkj%2Frpi-flipflop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkj%2Frpi-flipflop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkj","download_url":"https://codeload.github.com/mkj/rpi-flipflop/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkj%2Frpi-flipflop/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258339177,"owners_count":22685544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T18:26:00.333Z","updated_at":"2025-06-16T05:12:17.769Z","avatar_url":"https://github.com/mkj.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raspberry Pi Flipflop\n\nThis is a replacement for the old kernel\\_emergency.img that old Raspberry Pi \nfirmwares used, see http://elinux.org/RPI_safe_mode .\n\nIt lets you toggle booting two different partitions (kernels/distros/images)\ndepending on the state of GPIO pin 3.\n\nYou specify a \"normal partition\" and a \"safe partition\". Usually the Raspberry Pi\nwill boot the normal partion. If GPIO pin 3 (pin 5 on the physical header) is\nheld to ground it will boot the safe partition. \n\nI am using this in conjunction with a hardware watchdog that toggles the \"safe boot\"\nGPIO pin every few hours https://github.com/mkj/pihelp . That ensures that I \ncan access the device even if I break one of the partitions - I have a fallback\nrescue partition.\n\nAt the time of writing (April 2015) this has been tested on a 512MB Raspberry Pi B (not +) with Linux 3.18.7\n\nMatt Johnston \u003cmatt@ucc.asn.au\u003e\n\n## Installing\n\n- Get `flipflop.initramfs`. There's a prebuilt binary at \n  https://matt.ucc.asn.au/rpi-flipflop/flipflop.initramfs or \n  build flipflop by running `make`. I've been cross-compiling from a \n  x86 Ubuntu box, I assume building on the Raspberry Pi itself should work too. \n\n- Partition and set up a SD card\n - mmcblk0p1 - vfat, perhaps 40MB. This is only used by flipflop. \n   I'll call this the \"first boot partition\", it has \n   a Linux kernel and the flipflop initramfs (and other boot files).\n\n - \"normal boot\" partition, has all the boot files for the normal distro (eg /boot from raspbian)\n - \"safe\" partition, also has all the boot files but for the safe distro. Its \n   cmdline.txt probably points at a different root partition to normal.\n - The root partitions for each of the normal/safe partitions\n - Anything else (perhaps config file partition, see below)\n\n- Set up a vfat mmcblk0p1 partition with the contents of \n  https://github.com/raspberrypi/firmware/tree/master/boot \n  or /boot from recent Raspbian. \n```\nCOPYING.linux           cmdline.txt         issue.txt \nLICENCE.broadcom        config.txt          kernel.img \nLICENSE.oracle          fixup.dat           kernel7.img \nbcm2708-rpi-b-plus.dtb  fixup_cd.dat        overlays/\nbcm2708-rpi-b.dtb       fixup_x.dat         start.elf \nbcm2709-rpi-2-b.dtb     flipflop.initramfs  start_cd.elf \nbootcode.bin            start_x.elf         flipflop.txt\n```\n\n- Copy `flipflop.initramfs` to the first boot partition. Edit config.txt and add a line\n```\ninitramfs flipflop.initramfs followkernel\n```\n\n- Create a file `flipflop.txt` on the first boot partition to customise the config. \n  An example to boot mmcblk0p5 in normal mode or mmcblk0p8 in safe mode\n```\nnormal_bootpart 5\nsafe_bootpart 8\n```\n  You can also point it at further config files to parse - this is useful if you want\n  an editable config file on a different partition to avoid ever editing your\n  mmcblk0p1 for safety.\n```\nnormal_nextconf mmcblk0p2:vfat:nextconf.txt\nsafe_nextconf mmcblk0p2:vfat:flipflop.txt\n```\n  The default configuration is hardcoded near the top of [flipflop.c](flipflop.c)\n\n- Install normal distros to your normal and safe partitions. It should now work.\n\n## How it works\n\nFlipflop boots a Linux kernel that runs flipflop as /init in an initramfs.\nIt looks at the GPIO pins then sets the Raspberry Pi's reboot parameter \n`/sys/module/bcm2708/parameters/reboot_part` as appropriate. \nThen it reboots and the device boots whichever partition you chose. It adds a few seconds\nto the boot time.\n\nThis works the same as [NOOBS](https://github.com/raspberrypi/noobs) - it uses the same\nparameter to automatically boot the installed distro if the \"safe mode\" pin isn't held. \nThe \"separate config partition\" idea came from NOOBS too.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkj%2Frpi-flipflop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkj%2Frpi-flipflop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkj%2Frpi-flipflop/lists"}