aboutsummaryrefslogtreecommitdiff
path: root/octedit/Makefile
blob: d318811e9f3a490e08c72c776ca1aa73dec565c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
PICO = /dev/disk/by-label/RPI-RP2

octedit.uf2: octedit.bin
	echo -ne "\x55\x46\x32\x0A" > octedit.uf2  # Magic 0
	echo -ne "\x57\x51\x5D\x9E" >> octedit.uf2 # Magic 1
	echo -ne "\x00\x20\x00\x00" >> octedit.uf2 # Flags
	echo -ne "\x00\x00\x00\x10" >> octedit.uf2 # Load address
	echo -ne "\x00\x01\x00\x00" >> octedit.uf2 # Data size
	echo -ne "\x00\x00\x00\x00" >> octedit.uf2 # Block number
	echo -ne "\x01\x00\x00\x00" >> octedit.uf2 # Number of blocks
	echo -ne "\x56\xFF\x8B\xE4" >> octedit.uf2 # RP2040 family ID
	cat octedit.bin >> octedit.uf2             # Data
	printf %220s | tr " " "\0" >> octedit.uf2  # 0 padding
	echo -ne "\x30\x6F\xB1\x0A" >> octedit.uf2 # Magic end

octedit.bin: octedit.elf crc32
	arm-none-eabi-objcopy -O binary octedit.elf octedit.bin
	./crc32 < octedit.bin >> octedit.bin

objects = setup.o octedit.o uart.o

octedit.elf: $(objects) pico_persist.ld
	arm-none-eabi-ld -T pico_persist.ld -o octedit.elf $(objects)

$(objects): %.o: %.s
	arm-none-eabi-as -o $@ $<

.PHONY: clean
clean:
	rm octedit.elf octedit.bin octedit.uf2 *.o crc32

.PHONY: flash
flash: $(PICO) octedit.uf2
	cat octedit.uf2 > $(PICO)

.PHONY: check
check: $(PICO)
	@echo Ready to flash

$(PICO):
	@echo "RPI-RP2 bootloader drive not found"
	@echo Connect the pico with USB cable while holding bootsel button
	@false