Skip to content

Commit

Permalink
Cleaned up build process. broke into multiple parts. switch from .jso…
Browse files Browse the repository at this point in the history
…n to .hcl packer config
  • Loading branch information
Sniffleupagus committed Oct 27, 2023
1 parent c50b47a commit 2397f6b
Show file tree
Hide file tree
Showing 6 changed files with 697 additions and 422 deletions.
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ifneq (,$(UNSHARE))
UNSHARE := $(UNSHARE) --uts
endif

all: clean install image
all: clean image

langs:
@for lang in pwnagotchi/locale/*/; do\
Expand All @@ -52,10 +52,21 @@ $(SDIST): setup.py pwnagotchi
# Building the image requires packer, but don't rebuild the image just because packer updated.
$(PWN_RELEASE).img: | $(PACKER)

base_image: ../base_raspios-bullseye-armhf.img.xz

../base_raspios-bullseye-armhf.img.xz: ../base_raspios-bullseye-armhf.img
cd ..
@mv base_raspios-bullseye-armhf.img.xz base_raspios-bullseye-armhf.img.xz~
xz -k base_raspios-bullseye-armhf.img

../base_raspios-bullseye-armhf.img: builder/base_image.json
$(PACKER) plugins install github.com/solo-io/arm-image
cd builder && $(UNSHARE) $(PACKER) build -on-error=abort -var "pwn_hostname=$(PWN_HOSTNAME)" -var "pwn_version=$(PWN_VERSION)" -only=base base_image.json

# If the packer or ansible files are updated, rebuild the image.
$(PWN_RELEASE).img: $(SDIST) builder/pwnagotchi.json builder/pwnagotchi.yml $(shell find builder/data -type f)
$(PACKER) plugins install github.com/solo-io/arm-image
cd builder && $(UNSHARE) $(PACKER) build -on-error=abort -var "pwn_hostname=$(PWN_HOSTNAME)" -var "pwn_version=$(PWN_VERSION)" pwnagotchi.json
cd builder && $(UNSHARE) $(PACKER) build -on-error=abort -var "pwn_hostname=$(PWN_HOSTNAME)" -var "pwn_version=$(PWN_VERSION)" -only=pwnagotchi pwnagotchi.json.pkr.hcl

# If any of these files are updated, rebuild the checksums.
$(PWN_RELEASE).sha256: $(PWN_RELEASE).img
Expand Down
65 changes: 65 additions & 0 deletions builder/build_install_gopkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# expects to be called with
#
# item = { name: 'resulting_binary', url: 'https://github.com/foo/bar.git' }
#

- name: Check for existance of Golang in /usr/local/go
stat: path=/usr/local/go
register: big_golang

- name: Download and install golang
when: not big_golang.stat.exists
unarchive:
src: https://go.dev/dl/go1.21.1.linux-armv6l.tar.gz
dest: /usr/local
remote_src: yes
register: big_golang

- name: 'download target {{ item.name }} from github'
git:
repo: "{{ big_target.url }}"
dest: '/usr/local/src/{{ item.name }}'
register: big_download

- name: go mod tidy
shell: "go mod tidy -x -v"
register: result
retries: 7
delay: 60
args:
executable: /bin/bash
chdir: '/usr/local/src/{{ item.name }}'
until: result is not failed
ignore_errors: true

- name: build package
shell: "make"
register: result
args:
executable: /bin/bash
chdir: '/usr/local/src/{{ item.name }}'

- name: install pwngrid 1.10.4
shell: "make install"
register: result
args:
executable: /bin/bash
chdir: '/usr/local/src/{{ item.name }}'

- name: make bin staging dir
file:
state: directory
path: "/root/staging/bin"

- name: copy built binary to staging directory
copy:
src: '/usr/local/bin/{{ item.name }}'
dest: "/root/staging/bin/"

- name: remove build folder
file:
state: absent
path: '/usr/local/src/{{ item.name }}'


168 changes: 168 additions & 0 deletions builder/nexmon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#
# Install nexmon brcmfmac firmware and drivers from source as needed
#

#vars:
# nexmon:
# repo:
# url: "https://github.com/DrSchottky/nexmon.git"

- name: "Check for staged firmware {{ item.firmware }}"
stat: path="{{ staging }}/firmware/{{ item.firmware }}"
register: firmware

- name: "Check for staged kernel module {{ item.kernel }}/brcmfmac.ko"
stat: path="{{ staging }}/modules/{{ item.kernel }}/brcmfmac.ko"
register: kmodule

- name: "Check for /lib/modules/{{ item.kernel }}/build to see if we can"
stat: path="/lib/modules/{{item.kernel}}/build"
register: kernel_headers

- name: Build nexmon as needed
when:
- not firmware.stat.exists or not kmodule.stat.exists
- kernel_headers.stat.exists
block:

- name: Check for existence of nexmon repo
stat: path="/usr/local/src/nexmon"
register: nexmongit

- name: clone nexmon repository
when: not nexmongit.stat.exists
git:
repo: "https://github.com/DrSchottky/nexmon.git"
#"{{ nexmon.repo.url }}"
dest: /usr/local/src/nexmon
register: nexmongit

- name: prepare nexmon build tree
when: nexmongit.changed
shell: "source ./setup_env.sh && make"
args:
executable: /bin/bash
chdir: /usr/local/src/nexmon/

- name: Build firmware if needed
when: not firmware.stat.exists
environment:
QEMU_UNAME: "{{ item.kernel }}"
ARCHFLAGS: "{{ item.arch_flags }}"
block:
- name: "make firmware patch {{ item.patch }}"
shell: |
source ./setup_env.sh
cd patches/{{ item.patch }}/nexmon/
make clean
make
args:
executable: /bin/bash
chdir: /usr/local/src/nexmon/

- name: make firmware staging dir
file:
state: directory
path: "{{ staging }}/firmware"

- name: 'copy firmware {{ item.firmware }} to staging directory'
copy:
src: '/usr/local/src/nexmon/patches/{{ item.patch }}/nexmon/{{ item.firmware }}'
dest: '{{ staging }}/firmware/'
follow: true

- name: Build module as needed
when: not kmodule.stat.exists
environment:
QEMU_UNAME: "{{ item.kernel }}"
ARCHFLAGS: "{{ item.arch_flags }}"
block:
- name: "make brcmfmac.ko module {{ item.kernel }}"
when: firmware.stat.exists
# if not firmware.stat.exists, then module would have been installed above
shell: |
export QEMU_UNAME={{ item.kernel }}
uname -a
source ./setup_env.sh
cd patches/{{ item.patch }}/nexmon/
make clean
make brcmfmac.ko
args:
executable: /bin/bash
chdir: /usr/local/src/nexmon/
environment:
QEMU_UNAME: "{{ item.kernel }}"
ARCHFLAGS: "{{ item.arch_flags }}"

- name: make modules staging dir
file:
state: directory
path: "{{ staging }}/modules/{{ item.kernel }}"

- name: copy modified driver to staging
copy:
src: "/usr/local/src/nexmon/patches/driver/brcmfmac_{{ kernel.min }}.y-nexmon/brcmfmac.ko"
dest: "{{ staging }}/modules/{{ item.kernel }}/brcmfmac.ko"
follow: true
register: brcmfmac_installed
# end of nexmon build block. products should now be in staging if they were not already

# check again, just to be sure
- name: "Check for staged firmware {{ item.firmware }}"
stat: path="{{ staging }}/firmware/{{ item.firmware }}"
register: firmware

# install nexmon firmware from staging directory
- name: 'install nexmon firmware {{ item.firmware }}'
when: firmware.stat.exists
block:
- name: "Install nexmon firware in /usr/lib/firmware/brcm"
copy:
src: '{{ staging }}/firmware/{{ item.firmware }}'
dest: '/usr/lib/firmware/brcm/{{ item.firmware }}'
follow: true

- name: "Check for staged kernel module {{ item.kernel }}/brcmfmac.ko"
stat: path="{{ staging }}/modules/{{ item.kernel }}/brcmfmac.ko"
register: kmodule

- name: "Install kernel module {{ item.kernel }}/brcmfmac.ko from staging"
when: kmodule.stat.exists
block:
# remove originals, and keep track
- name: "Remove old compressed kernel module (if there)"
file:
state: absent
path: "/usr/lib/modules/{{ item.kernel }}/kernel/drivers/net/wireless/broadcom/brcm80211/brcmfmac/brcmfmac.ko.xz"
register: brcmfmac_ko_xz
ignore_errors: true

- name: "Remove old uncompressed kernel module (if there)"
file:
state: absent
path: "/usr/lib/modules/{{ item.kernel }}/kernel/drivers/net/wireless/broadcom/brcm80211/brcmfmac/brcmfmac.ko"
register: brcmfmac_ko
ignore_errors: true

- name: "install nexmon kernel driver {{item.kernel}}"
copy:
src: "{{ staging }}/modules/{{ item.kernel }}/brcmfmac.ko"
dest: "/usr/lib/modules/{{ item.kernel }}/kernel/drivers/net/wireless/broadcom/brcm80211/brcmfmac/brcmfmac.ko"
follow: true
register: brcmfmac_installed

- name: "xz compress driver: {{brcmfmac_ko_xz.changed}}"
when: brcmfmac_ko_xz.changed
command: xz -k brcmfmac.ko
args:
chdir: '/usr/lib/modules/{{ item.kernel }}/kernel/drivers/net/wireless/broadcom/brcm80211/brcmfmac'

- name: "remove uncompressed driver: {{brcmfmac_ko.changed}}"
when: not brcmfmac_ko.changed
file:
state: absent
path: "/usr/lib/modules/{{ item.kernel }}/kernel/drivers/net/wireless/broadcom/brcm80211/brcmfmac/brcmfmac.ko"

- name: update module dependencies
command: "/sbin/depmod -a {{ item.kernel }}"

Loading

0 comments on commit 2397f6b

Please sign in to comment.